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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> TSK;
    int N;
    cin >>N;

    ll x,y;
    rep(i,N){
        cin>>x>>y;
        TSK.push({y,x});
    }
    ll T=0;
    bool is=true;
    while(!TSK.empty()){
        pair<ll,ll> n=TSK.top();
      //  printf("T:%d %d-%d\n",T,n.first,n.second);
        T+=n.second;
        if(n.first<T){
            is=false;
            break;
        }
        TSK.pop();
    }
    

    cout << ((is) ? "Yes" : "No") <<endl;
    return (0);
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a;
  cin >> a;
  if((a>= 'a') && (a<='z')){
    cout << "a";
  }
  else if((a>= 'A') && (a<='Z')){
    cout << "A";
  }
}

Measured memory_bytes: 3632
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read2<T: std::str::FromStr>(n: i64) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {v2.push(read());}
    v2
}

struct Element {
    left: usize,
    right: usize,
    value: i64,
    valid: bool,
}

fn main() {
    let t: Vec<i64> = read();
    let s: Vec<Vec<String>> = read2(t[0]);
    let mut buf: Vec<Element> = Vec::new();
    // add END
    buf.push(Element{left:0, right:0, value:0, valid:false});
    let mut cursor: usize = 0;
    for si in &s{
        let query: i64 = si[0].parse().unwrap();
        if query == 0 {
            // insert x
            let x: i64 = si[1].parse().unwrap();
            // println!("debug: insert {}", x);
            let left_cursor: usize = buf[cursor].left;
            let right_cursor: usize = cursor;
            buf.push(Element{left:left_cursor, right:right_cursor, value:x, valid:true});
            cursor = buf.len() - 1;
            buf[left_cursor].right = cursor;
            buf[right_cursor].left = cursor;
        } else if query == 1 {
            // move d
            let d: i64 = si[1].parse().unwrap();
            // println!("debug: move {}", d);
            if d > 0 {
                for _ in 0..d {
                    cursor = buf[cursor].right;
                }
            } else {
                for _ in 0..(-d) {
                    cursor = buf[cursor].left;
                }
            }
        } else {
            // erase
            // println!("debug: erase");
            let left_cursor: usize = buf[cursor].left;
            let right_cursor: usize = buf[cursor].right;
            buf[cursor].valid = false;
            buf[left_cursor].right = right_cursor;
            buf[right_cursor].left = left_cursor;
            cursor = right_cursor;
        }

        // DEBUG PRINT
        // let mut tmp_cursor = buf[0].right;
        // while tmp_cursor != 0 {
        //     if cursor == tmp_cursor {
        //         println!("debug: {} (cursor)", buf[tmp_cursor].value);
        //     } else {
        //         println!("debug: {}", buf[tmp_cursor].value);
        //     }
        //     tmp_cursor = buf[tmp_cursor].right;
        // }
        // if cursor == 0 {
        //     println!("debug: END (cursor)");
        // } else {
        //     println!("debug: END");
        // }

    }
    cursor = buf[0].right;
    while cursor != 0 {
        println!("{}", buf[cursor].value);
        cursor = buf[cursor].right;
    }
}



Measured memory_bytes: 71448
n,m = map(int,input().split())
INF = 10**9+7
inv = {}
inv[0] = 1
inv[1] = 1
def p(x):
    if x in inv:
        return inv[x]
    else:
        inv[x] = ((-1)* p(INF%x) * (INF//x))% INF
        return inv[x]
# n H i
l = [1] * 31
l[1] = n 
for i in range(2,31):
    l[i] = ((n+i-1)*l[i-1]*p(i))%INF
# M を素因数分解
def h(x):
    t = x
    d = {}
    for i in range(2,x):
        if i*i > x:
            break
        if t % i != 0:
            continue
        if t % i == 0:
            ind = 0
            while t % i == 0:
                t = t // i
                ind += 1
            d[i] = ind
    if t != 1:
        d[x] = 1
    return d

res = 1
for i in h(m):
    res = (res *  l[h(m)[i]]) % INF

print(res)

Measured memory_bytes: 3064
import sys

def solve():
    input = sys.stdin.readline
    K, S = map(int, input().split())
    count = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if 0 <= z <= K: count += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] + n > 'Z') {
      int x = 'Z' - s[i];
      int y = n - x;
      s[i] = 'A' + y - 1;
      continue;
    }
    s[i] = s[i] + n;
  }
  cout << s;
  return 0;
}


Measured memory_bytes: 256
H,W,K=map(int,input().split())
s=[[int(x) for x in list(input())] for _ in range(H)]
ans = H*W
for h in range(2**(H-1)):
  parts = list()
  upper = 0
  cnt = 0
  inv_flg = 0
  for j in range(H-1):
    if h >> j & 1:
      cnt += 1
      appending = [sum([s[y][x] for y in range(upper, j+1)]) for x in range(W)]
      if any([x> K for x in appending]):
        inv_flg = 1
        break
      parts.append(appending)
      upper = j+1
  else:
    appending = [sum([s[y][x] for y in range(upper, H)]) for x in range(W)]
    if any([x > K for x in appending]):
      inv_flg = 1
    else:
      parts.append(appending)
  if inv_flg:
    continue
  # 貪欲
  summary = [0]*len(parts)
  for i in range(W):
    temp_sum = [summary[j] + parts[j][i] for j in range(len(parts))]
    for ts in temp_sum:
      if ts > K:
        cnt += 1
        summary = [parts[j][i] for j in range(len(parts))]
        break
    else:
      summary = temp_sum
  ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 89616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N;
  cin>>N;
  VL A(N);
  rep(i,N) cin>>A[i];
  VL X(200001);
  rep(i,N) X[A[i]]++;
  ll ans=0;
  VL Y(200001);
  rep(i,200001) if(X[i]) Y[i]=(X[i]-1)*(X[i]-2)/2;
  rep(i,200001){
    X[i]=(X[i]*(X[i]-1)/2);
    ans+=X[i];
  }
  rep(i,N) cout<<ans-X[A[i]]+Y[A[i]]<<endl;
}

Measured memory_bytes: 7296
using System;
public class c
{
  public static void Main()
  {
    string S = Console.ReadLine();
    int count_0 = 0;
    int count_1=0;
    string s= "";
    for(int i=0;i<S.Length;i++)
    {
      if(S[i]=='0')count_0++;
      else count_1++;
    }
    if(count_1>=count_0)Console.WriteLine(count_0*2);
    else Console.WriteLine(count_1*2);
   
    
  }
}

Measured memory_bytes: 11232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  cin>>n;
  set<string>s;
  for(i=0;i<n;i++){
    string s1;
    cin>>s1;
    s.insert(s1);
  }
  cout<<s.size();

  return 0;
}

Measured memory_bytes: 19256
#include <iostream>

#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

using namespace std;

char ToUpper(char c){
    return toupper(c);
}


int main(){
    vector<string> vecstr;
    string ans;
    int count=0;
    cin>>ans;
    transform(ans.begin(),ans.end(),ans.begin(),ToUpper);
    
    while(true){
        string str;
        cin>>str;
        if(str=="END_OF_TEXT"){
            break;
        }
        transform(str.begin(),str.end(),str.begin(),ToUpper);
        vecstr.push_back(str);
    }
    
    for(int i=0;i!=vecstr.size();++i){
        if(vecstr[i]==ans){
            ++count;
        }
    }
    cout<<count<<endl;
    
 
    
}



Measured memory_bytes: 3208
//  PDF 解法2.横に切って、その後縦に切る
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();

        char[][] cake = new char[H][W];
        int[][] cutCake = new int[H][W];
        String[] str = new String[H];
        boolean hasIchigo = false;
        int a = 1;

        for (int i = 0; i < H; i++) 
        	str[i] = sc.next();

        for (int i = 0; i < H; i++) {
            String s = str[i];
            if (s.contains("#"))
            	hasIchigo = true;

            for (int j = 0; j < W; j++) {
                cake[i][j] = s.charAt(j);
  				cutCake[i][j] = a;
            }
            int k = 1;
  			while (i+k < H && !str[i+k].contains("#")) {
   				for (int l = 0; l < W; l++)
  					cutCake[i+k][l] = a;
  				k++;
  			}
  			i += k-1;
            if (hasIchigo)
            	a++;
            hasIchigo = false;
        }

        for (int i = 0; i < H; i++) {

        	String s = str[i];
        	int firstIndexOfIchigo = s.indexOf('#');
        	int lastIndexOfIchigo = s.lastIndexOf('#');
     
        	if (firstIndexOfIchigo == -1)
        		continue;

        	if (firstIndexOfIchigo == lastIndexOfIchigo)
        		continue;		

        	for (int j = 0; j < W; j++) {

        		if (j <= firstIndexOfIchigo) {

        			int k = 1;
     				while (i-k >= 0 && cutCake[i-k][j] == cutCake[i][j]) {
        				cutCake[i-k][j] = a;
        				k++;
     				}
     				k = 1;
        			while (i+k < H && cutCake[i+k][j] == cutCake[i][j]) {
        				cutCake[i+k][j] = a;
        				k++;
        			}
        			cutCake[i][j] = a;
        		}

        		if (j == firstIndexOfIchigo) {
        			if (!s.contains("#")) 
        				break;
        			s = s.replaceFirst("#", ".");
        			a++;
        			firstIndexOfIchigo = s.indexOf('#');
        			lastIndexOfIchigo = s.lastIndexOf('#');
        			if (firstIndexOfIchigo == lastIndexOfIchigo)
        				break;
        		}
        	}
        }

        for (int i = 0; i < H; i++) {
        	for (int j = 0; j < W; j++) {
        		System.out.print(cutCake[i][j] + " ");
        	}
        	System.out.println();
        }
    }
}

Measured memory_bytes: 96648
N, M = map(int,input().split())

mat = []
for n in range(N):
    buff = input()
    mat.append([int(x) for x in buff.split()])

vec = []
for m in range(M):
    vec.append(int(input()))

for n in range(N):
    ans = 0
    for m in range(M):
        ans += mat[n][m]*vec[m]
    print(ans)
    



Measured memory_bytes: 6012
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BKThCommonDivisor solver = new BKThCommonDivisor();
        solver.solve(1, in, out);
        out.close();
    }

    static class BKThCommonDivisor {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int K = in.nextInt();
            int res = solve(A, B, K);
            out.println(res);
        }

        private int solve(int a, int b, int K) {
            int cur = 0;
            for (int i = 101; i >= 1; i--) {
                if (a % i == 0 && b % i == 0) {
                    cur++;
                    if (cur == K)
                        return i;
                }
            }
            throw new RuntimeException("Impossible");
        }

    }
}



Measured memory_bytes: 21844
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var n = sc.nextBigInteger();

		System.out.println(
				BigInteger.ZERO.equals(n.mod(BigInteger.valueOf(9))) ? "Yes" : "No");
	}
}


Measured memory_bytes: 42244
def root(par, x)
  if par[x] < 0
    return x
  else
    par[x] = root(par, par[x])
    return par[x]
  end
end
def unite(par, x, y)
  rx = root(par, x)
  ry = root(par, y)
  if rx != ry
    if par[rx] > par[ry]
      rx, ry = ry, rx
    end
    par[rx] += par[ry]
    par[ry] = rx
  end
end
def size(par, x)
  return -par[root(par, x)]
end
n, m = gets.split.map(&:to_i)
par = Array.new(n, -1)
m.times do |i|
  a, b = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  unite(par, a, b)
end
max_size = 1
for i in 0...n do
  max_size = [max_size, size(par, i)].max
end
puts max_size


Measured memory_bytes: 15920
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , A[MAXN] , B[MAXN] , C[MAXN] , mark[MAXN] , ans;

int main() {
    fast_io;

    cin >> n;
    for(ll i = 1 ; i <= n ; i++)    cin >> A[i];
    for(ll i = 1 ; i <= n ; i++)    cin >> B[i];
    for(ll i = 2 ; i <= n ; i++)    cin >> C[i];

    for(ll i = 1 ; i <= n ; i++){
        ans += B[A[i]];
        if(A[i] - 1 == A[i - 1])  ans += C[A[i]];
        mark[A[i]] = 1;
    }
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 6400
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        int[] a = new int[3];
        a[0] = int.Parse(input[0]);
        a[1] = int.Parse(input[1]);
        a[2] = int.Parse(input[2]);
        if (a[0] + a[1] + a[2] >= 22) { Console.WriteLine("bust"); }
        else { Console.WriteLine("win"); }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int A[101010],B[101010];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int N; cin>>N;
  vector<pair<int,pair<int,int>>> V;
  rep(i,N){
    cin>>A[i]>>B[i];
    V.push_back({A[i],{i,0}});
    V.push_back({B[i],{i,1}});
  }
  sort(V.begin(),V.end());
  int x=V[0].second.second;
  ll sum=V[0].first;
  for(int i=1;i<N;i++){
    sum+=V[i].first;
    if(x!=V[i].second.second) x=-1;
  }
  if(x!=-1){
    cout<<sum<<endl;
    return 0;
  }
  ll ans=1e15;
  rep(i,N){
    ll tmp=sum;
    if(A[i]<=V[N-1].first) tmp-=A[i];
    if(B[i]<=V[N-1].first) tmp-=B[i];
    if((tmp+A[i]+B[i])==sum) ans=min(ans,sum);
    else{
      if(V[N].second.first!=i) ans=min(ans,tmp+1LL*V[N].first);
      else ans=min(ans,tmp+1LL*V[N+1].first);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5108
#include <iostream>

using namespace std;

int main() {
  long long int data[10][1001] = {1};
  for (int k = 0; k <= 100; ++k)
    for (int i = 9; 1 <= i; --i)
      for (int j = k; j <= 1000; ++j)
        data[i][j] += data[i-1][j-k];

  int n, s;
  while (cin >> n >> s) {
    if (n == 0)
      break;
    cout << data[n][s] << endl;
  }
}


Measured memory_bytes: 3172
a, b = map(int, input().split())
w = []
for i in range(100):
    w.append([])
for i in range(100):
    for j in range(100):
        w[i].append([])

for i in range(100):
    for j in range(100):
        if i < 50:
            w[i][j] = "."
        else:
            w[i][j] = "#"

acnt = 0
bcnt = 0
for i in range(0, 50, 2):
    for j in range(0, 100, 2):
        if bcnt == b - 1:
            break
        else:
            w[i][j] = "#"
            bcnt += 1
    else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
        continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
    break  # 外側のforを抜ける
for i in range(51, 100, 2):
    for j in range(0, 100, 2):
        if acnt == a - 1:
            break
        else:
            w[i][j] = "."
            acnt += 1
    else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
        continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
    break  # 外側のforを抜ける

print(100, 100)
for i in range(100):
    print(( ''.join(w[i])))

Measured memory_bytes: 3700
var
        a:boolean;
        m:longint;
begin
        readln(m);
        while m<>0 do
        begin
                if m mod 10=9 then
                begin
                        a:=true;
                        break;
                end;
                m:=m div 10;
        end;
        if a then write('Yes')
        else write('No');
end. 


Measured memory_bytes: 128
#include<map>
using namespace std;
#include<bits/stdc++.h>
int comp(const void* a, const void* b) 
{ return *(int*)a > *(int*)b ; } 
int gles(int sunner[], int n) 
{ 
	qsort(sunner, n, sizeof( sunner[0] ), comp); 
	int count = 0; 
	for (int i = 0; i < n - 2; ++i) 
	{ 
		int k = i + 2; 
		for (int j=i+1;j<n;++j) 
		{ 
			while(k<n&&sunner[i]+sunner[j]>sunner[k]) 
			++k; 
			if(k>j) 
			count+=k-j-1; 
		} 
	} 

	return count; 
} 
int main()
{
    int n,i,ans=0,j,count=0;
    cin>>n;
    int a[n+5];
    for(i=0;i<n;i++)
    cin>>a[i];
    cout<<gles(a,n);
    return 0;
}

Measured memory_bytes: 256
S = input()

first_b = -1
for i in range(0, len(S)):
    if S[i] == 'B':
        first_b = i
        break

last_w = len(S)
for i in range(len(S) - 1, -1, -1):
    if S[i] == 'W':
        last_w = i
        break

# all B or all W
if first_b == -1 or last_w == len(S):
    print(0)
    exit(0)

S = S[first_b:last_w + 1]
cnt_b = 0
ans = 0
for s in S:
    if s == 'B':
        cnt_b += 1
    else:
        ans += cnt_b
print(ans)


Measured memory_bytes: 41052
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [x,y] <- getIntList
    let b2 = y - 2 * x
    let a = x - b2 `div` 2
    putStrLn $ if b2 >= 0 && a >= 0 && b2 `mod` 2 == 0 then "Yes" else "No"


Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;


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

	ll n,r;
	cin>>n>>r;

	ll ans=0;
	while(n>0)
    {
        n=n/r;
        ++ans;
    }
    cout<<ans;

	return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,a) rng(i,0,a)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,a) gnr(i,0,a)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define print(x) cout<<(x)<<'\n'
using ll=long long;
using pl=pair<ll,ll>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vs=vector<string>;

void solve() {
    ll N, Q;
    cin >> N >> Q;
    dsu d(N);
    ll t, u, v;
    rep(i,Q){
        cin >> t >> u >> v;
        if(t){
            print(d.same(u, v));
        }else{
            d.merge(u, v);
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


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

using namespace std;
const int N = 1e5 + 3;
int n, freq[N][2];
int main() {
//	freopen("input.in", "r", stdin);
	
	scanf("%d", &n);
	set<pair<int, int>> st[2];
	st[0].insert({0, 0});
	st[1].insert({0, 0});
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		
		auto it = st[i % 2].find({freq[a][i % 2], a});
		if (it != st[i % 2].end()) {
			st[i % 2].erase(it);
		}
		st[i % 2].insert({++freq[a][i % 2], a});
	}
	int res = n, i = 0;
	for (auto it0 = st[0].end(); i < 2; ++i) {
		--it0;
		int j = 0;
		for (auto it1 = st[1].end(); j < 2; ++j) {
			--it1;
			if (it1->second != it0->second)
				res = min(res, n - it0->first - it1->first);
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 5760
/**
     *    author:  shashank_hire
    **/
#include <bits/stdc++.h>
using namespace std;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define ld long double
#define MOD 1000000007



int main()
{
    IOS;
    ll h, w, i, j;
    char c;
    cin>>h>>w;
    vector<vector<ll>> dp(h, vector<ll>(w, 0));
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            {
                cin>>c;
                if(c=='.')
                {
                    if(i==0 and j==0)
                        dp[i][j] = 1;
                    else if(i==0)
                        dp[i][j] = dp[i][j-1];
                    else if(j==0)
                        dp[i][j] = dp[i-1][j];
                    else
                        dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
                }
            }
    cout<<dp[h-1][w-1]<<"\n";
    
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;
int main(){
    string T;
    cin>>T;
    
    rep(i,T.size()-1){
        if(T[i]=='?'&&T[i+1]=='?'){
            T[i]='P';
            T[i+1]='D';
        }else if(T[i]=='P'&&T[i+1]=='?'){
            T[i+1]='D';
        }else if(T[i]=='?'&&T[i+1]=='D'){
            T[i]='P';
        }
    }

    rep(i,T.size()){
        if(T[i]=='?'){
            T[i]='D';
        }
    }
    
    cout<<T<<endl;
    
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vi a(n+2);
    a[0] = a[n+1] = 0;
    rep(i, n) cin >> a[i+1];

    ll sum = 0LL;
    rep(i, 1, n+2){
        sum += abs(a[i] - a[i-1]);
    }

    rep(i, 1, n+1){
        ll res = sum;
        res += abs(a[i+1] - a[i-1]);
        res -= (abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]));
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define   ll   long long int
#define   sz   200010

using namespace std;

int main()
{

    ll n,k,a,b;

    cin>>n>>k;

    a=n%k;
    b=k-a;

    cout<<min(a,b)<<endl;



   return 0;
}


Measured memory_bytes: 256
s=gets.chomp
2.upto(s.size) do |i|
  curs=s[0..-i]
  curssize=curs.size
  if curssize.even?
    if curs[0..curssize/2-1]==curs[curssize/2..-1]
      puts curssize
      exit
    end
  end
end


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using plglg = pair<ll, ll>;
using tlglglg = tuple<ll, ll, ll>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    ll n; cin >> n;
    vll a(n); REP(i, n) cin >> a[i];

    if (a[0] != 0) {
        print(-1);
        return 0;
    }

    ll ans = 0;
    ll prev = 0;
    REP(i, n) {
        if (a[i] == prev+1) {
            ans++;
        } else if (a[i] <= prev) {
            ans += a[i];
        } else {
            print(-1);
            return 0;
        }
        prev = a[i];
    }

    print(ans);

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

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

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != 0) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}
// Combination
ll modcomb(ll n, ll r)
{
  if(n < r) return 0;
  ll res = fact(n);
  (res *= ppow(fact(r), M-2)) %= M;
  (res *= ppow(fact(n-r), M-2)) %= M;
  return res;
}

//GCD and LCM
llt gcd(llt x, llt y)
{
  if(y == 0) return x;
  return gcd(y, x%y);
}
llt lcm(llt x, llt y)
{
  return (x / gcd(x, y)) * y;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find
// Find()
int parent[N], ran[N];
int find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
// Union()
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(ran[x]<ran[y])
        parent[x]=y;
    else{
        parent[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}

// Main Code
int co[27];
int main()
{
  string s;
  cin>>s;
  rep(i, 0, s.length())
  {
    co[s[i]-'a']++;
  }
  rep(i, 0, 26)
  {
    if(co[i] == 0){
      cout<<(char)(i+'a')<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}


Measured memory_bytes: 14208
#include<iostream>
using namespace std;
int main(){
	
	int a,b;
	cin>>a>>b;
	
	if(a<b){
		for(int i = 0 ; i < b ; i++){
			cout<<a;
		}
	}else{
		for(int i = 0 ; i < a ; i++){
			cout<<b;
		}
	}cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a >= 2800){
    cout << "AGC\n";
  }
  else if(a >= 1200){
    cout << "ARC\n";
  }
  else cout << "ABC\n";
}

Measured memory_bytes: 3596
def main():
    N = input()
    data = []
    pW = raw_input()
    data.append(pW)
    for i in range(N-1):
        W = raw_input()
        if pW[-1] != W[0]:
            return 'No'
        if W in data:
            return 'No'
        data.append(W)
        pW = W
    return 'Yes'

print main()

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	ll h,w; cin >> h >> w;
	ll ans;
	if(h==1||w==1)ans = 1;
	else 
	{
		ans = w * (h/2);
		if(h%2)ans += (w+1)/2;
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

ll x, a, b;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main()
{
  cin >> x;
  vector<ll> divisor_x = divisor(x);
  ll lim = floor(pow(x, 0.25));
  bool flag = false;

  REP(i, divisor_x.size()){
    ll div = divisor_x[i];
    REP(j, lim){
      a = j;
      b = j - div;
      if(pow(a, 5) - pow(b, 5) == x){
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int L, R, d;
    int ans = 0;
    cin >> L >> R >> d;
    for(int i=L; i<=R; ++i){
        if(i%d==0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n; cin>>n;
    int res=0, maxh=-1;
    for(int i=0; i<n; ++i) {
        int h; cin>>h;
        maxh=max(h, maxh);
        if (h==maxh) ++res;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

int n;
string s;

int dp[N][13];

int solve(int idx, int rem){
   if(idx >= n){
      return rem == 5;
   }

   int &ans = dp[idx][rem];
   if(~ans)
      return ans;

   ans = 0;

   if(s[idx] != '?'){
      int ch = s[idx] - '0';
      ans += solve(idx+1, ((rem*10) + ch) % 13);
      ans %= mod;
      return ans;
   }

   for (int d = 0; d < 10; ++d)
   {
      int ch = d;
      ans += solve(idx+1, ((rem*10) + ch) % 13);
      ans %= mod;
   }

   return ans;
}

int32_t main(){_

   cin >> s;

   n = sz(s);

   memset(dp, -1, sizeof dp);
   cout<<solve(0, 0);

   return 0;
}

Measured memory_bytes: 16976
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
    stack<int> S;
    string c;
    int a, b;
    while (cin >> c)
    {
        if (c == "+")
        {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b + a);
        }
        else if (c == "-")
        {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b - a);
        }
        else if (c == "*")
        {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b * a);
        }
        else
        {
            int i = atoi(c.c_str());
            S.push(i);
        }
    }
    cout << S.top() << endl;
}


Measured memory_bytes: 3080
#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>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N,M;
    cin >> N >> M;

    vector<vector<int> > E(N,vector<int>());

    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    vector<bool> used(N,false);
    vector<int> path;
    int pt = 0;
    rep(i,0,N){
        if(E[i].size() > 0){
            pt = i;
            break;
        }
    }

    while(true){
        bool cont = false;
        for(int next: E[pt]){
            if(!used[next]){
                pt = next;
                path.push_back(pt);
                used[next] = true;
                cont = true;
                break;
            }
        }
        if(!cont){
            break;
        }
    }

    pt = path[0];
    reverse(all(path));

    while(true){
        bool cont = false;
        for(int next: E[pt]){
            if(!used[next]){
                pt = next;
                path.push_back(pt);
                used[next] = true;
                cont = true;
                break;
            }
        }
        if(!cont){
            break;
        }
    }


    cout << path.size() << endl;
    rep(i,0,path.size()){
        cout << path[i] + 1;
        if(i != path.size()-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    return 0;
}


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

int main()
{
    int W,H,N;
    int x,y,a;
    cin >> W >> H >> N;
    int xmi=0,xma=W,ymi=0,yma=H;
    for(int i=0; i<N; i++){
        cin >> x >> y >> a;
        if(a == 1){
            xmi = max(xmi,x);
        }else if(a == 2){
            xma = min(xma,x);
        }else if(a == 3){
            ymi = max(ymi,y);
        }else if(a == 4){
            yma = min(yma,y);
        }
    }
    if((xma-xmi)>0 && (yma-ymi)>0){
        cout << (xma-xmi)*(yma-ymi) << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>

using ll = long long;
const ll mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

void solve(std::vector<ll> &A, int K){
  int N = A.size();
  combination comb(N + 1);
  mint maxS = 0;
  mint minS = 0;
  for(int i = K - 1; i < N; i++){
    maxS += comb.operator()(i, K - 1) * A[i];
    minS += comb.operator()(N - 1 - (i - K + 1),  K - 1) * A[i - K + 1];
  }

  std::cout << (maxS - minS).x << std::endl;
}


int main(){
  int N, K;
  scanf("%d %d%*c", &N, &K);
  std::vector<ll> A(N);
  for(int i = 0; i < N; i++){
    scanf("%lld", &A[i]);
  }

  // 例外処理
  if(K == 1){
    std::cout << 0 << std::endl;
    return 0;
  }

  // メイン
  std::sort(A.begin(), A.end());
  solve(A, K);

  return 0;
}

Measured memory_bytes: 2560
/*
    title: D.cpp
    author: Akhil
    date: 2020-09-19
    time: 17:46:12
*/

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <numeric>
#include <cmath>
#include <set>
#include <stdio.h>

using namespace std;

int mod = 998244353;

int main()
{
    int n, k; cin >> n >> k;
    vector<pair<int, int>> p(k);
    for (int i = 0; i < k; i++)
    {
        cin >> p[i].first >> p[i].second; 
    }
    sort(p.begin(), p.end());
    vector<int> dp(n + 1, 0), cum_dp(n + 1);
    dp[1] = 1;
    cum_dp[1] = 1;
    auto cum = [&cum_dp] (int i, int j)
    {
        return (cum_dp[j] - ((i >= 1) ? cum_dp[i - 1] : 0) + mod) % mod;
    };
    for (int i = 2; i <= n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            if (i - p[j].first >= 1)
            {
                dp[i] = (dp[i] + cum(i - p[j].second, i - p[j].first)) % mod;
            }
            else break;
        }
        cum_dp[i] = (cum_dp[i - 1] + dp[i]) % mod;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4836
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def std_in():
    return sys.stdin.readline().strip()


def main():
    n, d = get_ints()
    d2 = d ** 2
    counter = 0
    for i in range(n):
        x, y = get_ints()
        if d2 >= (x**2 + y**2):
            counter += 1

    print(counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9228
package main

import (
	"fmt"
	"sort"
)

func main()  {
	var n int
	fmt.Scan(&n)
	nums := ScanNums(n)
	sort.Ints(nums)
	half := len(nums) / 2
	fmt.Println(nums[half] - nums[half-1])
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 7556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var minIndex = nums[0] > nums[1] ? 1 : 0;
            Console.WriteLine(new string((char) ('0' + nums[minIndex]), nums[(minIndex + 1) % 2]));
        }

    }
}

Measured memory_bytes: 28180
s=list(input())
for i in range(int(input())):
    q=input().split()
    a,b=int(q[1]),int(q[2])
    if q[0]=="replace":
        s[a:b+1]=q[3]
    elif q[0]=="reverse":
        s[a:b+1]=reversed(s[a:b+1])
    else:print(*s[a:b+1],sep="")


Measured memory_bytes: 5736
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


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


typedef long long ll;
//const int MOD = pow(10,9)+7;
//const int MAX = 100001;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}




void dfs(int &flag, int st, int gl, vector<int> *links, int depth, int *visited){
    
    if (depth == 2 && st == gl)  {  //条件を満たすパスを発見
        flag = 1;
        return;
    }
    
    if (depth >= 2) return;
    if (flag == 1) return; ///ルートが一度発見されたらもう再帰は必要ない。
    
    
    for(auto it = links[st].begin(); it != links[st].end() ;it++){
        
        if (visited[*it] == 1) continue;
        visited[*it] = 1;
        dfs(flag,*it, gl,links,depth+1,visited);
        visited[*it] = 0;
        
    }
    
}

int main() {
    
    int N = in();
    
    vector<int> vecOdd;
    vector<int> vec2;
    vector<int> vec4;
    
    int temp;
    for(auto i = 0; i < N; i++){
        
        temp = in();
        
        if(temp%2 == 1){
            vecOdd.push_back(temp);
        }else if(temp%4 == 2){
            vec2.push_back(temp);
        }else{
            vec4.push_back(temp);
        }
        
    }
    
    if (vec2.size() == 0){
    
        if(vecOdd.size() > vec4.size()+1){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
        
    }else{
        
        if(vecOdd.size() > vec4.size()){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
        
    }
    
    
    return 0;
    
    
}









Measured memory_bytes: 1012