akhauriyash/Code-Regression huggingface dataset:
N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()

if N>=M:
    print(0)
else:
    d=[]
    for i in range(1,M):
        d.append(X[i]-X[i-1])
    d.sort()
    print(sum(d[:M-N]))

Measured memory_bytes: 20364
n = int(input())
a = list(map(int, input().split()))

sums = {}
cur = 0
cnt = 0

for i in range(n):
    cur += a[i]

    if cur == 0:
        cnt += 1
    if cur in sums:
        cnt += sums[cur]

    sums[cur] = 1 if cur not in sums else sums[cur] + 1

print(cnt)

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

using namespace std;

using int64 = long long;

constexpr int64 H = 1000000000;

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

  int64 s;
  cin >> s;

  if (s < H) {
    cout << "0 0 1 0 0 " << s << endl;
    return 0;
  }

  int64 q = s / H;
  int64 r = s % H;
  if (r == 0) {
    cout << "0 0 " << q << " 0 0 " << H << endl;
    return 0;
  }

  cout << "0 0 " << q + 1 << " " << H - r << " 1 " << H << endl;
}


Measured memory_bytes: 256
import numpy as np

N, M, X = map(int, input().split())

ca = []
for _ in range(N):
  ca.append( list(map(int, input().split())))
ca.sort(key=lambda x:x[0])
ca = np.array(ca)
#
ans = 10000000
skill = [0]*(M+1)


def DFS(n):
  global ans,skill
  if skill[0] >= ans:
    return
  if min(skill[1:]) >= X:
    ans = min(ans, skill[0])
    return
  if n >= N:
    return
  skill = skill + ca[n]
  DFS(n+1)
  skill = skill - ca[n]
  DFS(n+1)
  return
#

DFS(0)
if ans == 10000000:
  print(-1)
else:
  print(ans)
#

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

#define mod 998244353

long long dp[300001];

int a[300001];

int N;

long long f(int i) {
    stack<int> st;
    
    for(int i = 0; i < N; i++) {
        if(st.size() > 0) {
            if(st.top() % 2 == a[i] % 2) {
                st.pop();
            }else st.push(a[i]);
        }else st.push(a[i]);
    }
    long long cnt = 0;
    while(!st.empty()) {
        if(st.top() % 2) cnt++;
        st.pop();
    }
    return cnt;

}


int main() {
    // oh hi mark
    long double pw = 1;
    long double n; cin >> n;
    long long sum = 0;
    if((long long)n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    while(n > 1) {
        sum += (long long)(((long long)(n / 5)) / 2);
        n /= 5.0;
    }
    
    cout << (long long)sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.List (unfoldr)

main :: IO ()
main = do
  n <- readLn
  putStr . unlines . map show $ solve n

solve :: Int -> [Int]
solve k = take k $ unfoldr f (0, 1) where
  f (n, b) = Just (n', (n', b')) where
    n' = n + b'
    b' = if check (n + b) b then b else b * 10


s :: Int -> Int
s = sum . unfoldr f where
  f 0 = Nothing
  f x = Just (x `mod` 10, x `div` 10)

check :: Int -> Int -> Bool
check n b = n * s (n + b) <= s n * (n + b)


Measured memory_bytes: 1020
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo

void solve() {
    int a; cin >> a;
    cout << a + a * a + a * a * a;
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    int test; cin >> test;
//    for(int tt = 0; tt < test; ++tt) {
        solve();
//    }
    return 0;
}

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

bool is_written(string haystack, string needle);

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

    int num = 0;
    for (int i = 0; i < n; i++) if (is_written(rings[i], s)) num++;

    cout << num << endl;
}

bool is_written(string haystack, string needle) {
    const int len_haystack = haystack.length();
    const int len_needle = needle.length();
    for (int i = 0; i < len_haystack; i++) {
        string hay;
        if (i == 0) hay = haystack;
        else hay = haystack.substr(i, len_haystack - i)
                   + haystack.substr(0, i);
        for (int j = 0; j < len_needle; j++)
            if (hay.substr(j, len_needle) == needle) return true;
    }
    return false;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

map<int, int> cnt;

void nie(){
	cout<<"Impossible"<<endl;
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int ma=0;
	for (int i=0;i<n;i++){
		int a;
		cin>>a;
		cnt[a]++;
		ma=max(ma, a);
	}
	if (ma==1){
		if (n==2&&cnt[1]==2){
			cout<<"Possible"<<endl;
			return 0;
		}
		else{
			nie();
		}
	}
	for (auto t:cnt){
		if (t.F==ma&&t.S<2) nie();
		if (ma%2==0){
			if (t.F<ma/2) nie();
			if (t.F==ma/2&&t.S>1) nie();
		}
		else{
			if (t.F<=ma/2) nie();
			if (t.F==ma/2+1&&t.S>2) nie();
		}
	}
	for (int k=ma;;k--){
		if (ma%2==0){
			if (k<ma/2) break;
			if (k==ma/2){
				if (cnt[k]<1) nie();
			}
			else {
				if (cnt[k]<2) nie();
			}
		}
		else{
			if (k<=ma/2) break;
			if (k==ma/2+1){
				if (cnt[k]<2) nie();
			}
			else{
				if (cnt[k]<2) nie();
			}
		}
	}
	cout<<"Possible"<<endl;
}

Measured memory_bytes: 384
while True:
    a, b=map(int, input().split())
    if a==0 and b==0:
        break

    if a<b:
        print(str(a)+" "+str(b))
    elif a>b:
        print(str(b)+" "+str(a))
    else:
        print(str(a)+" "+str(b))
    

Measured memory_bytes: 7612
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define itn int
#define f(n) for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int> P;
signed main() {
	int a, b, x;
	cin >> a >> b;
	x = b;
	f(a - 1) x *= b - 1;
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

const int MAXN = 100005;

int n, sol;
int l[MAXN];

int main () {
    cin >> n;
    for (int i=1; i<=n; i++) {
        scanf("%d", &l[i]);
    }
    for (int i=1; i<=n; i++) {
        if (l[i]==i) {
            sol++;
            if (i+1<=n && l[i+1]==i+1) {
                i++;
            }
        }
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 640
num = int(input())
x = list(map(int, input().split()))
n = 0

flag = 1
while flag:
    flag = 0
    for j in range(1, num):
        if x[j] < x[j-1]:
            x[j], x[j-1] = x[j-1], x[j]
            flag = 1
            n += 1
print(' '.join([str(s) for s in x]))
print(n)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{
    ll h,w,n;
    cin>>h>>w>>n;
    ll z =max(h,w);
    ll ans=0;
    if(n%z==0)
    ans=n/z;
    else 
    ans= n/z+1;
    cout<<ans<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}





// bool prime[100000];

// // int gcdExtended(int a, int b, int *x, int *y) ;
// ll modInverse(int a, int m) 
// { 
//     int x, y; 
//     int g = gcdExtended(a, m, &x, &y); 
//     // if (g != 1) 
//     //     cout << "Inverse doesn't exist"; 
//     // else
//     // { 
//         // m is added to handle negative x 
//         int res = (x%m + m) % m; 
//         return res; 
//     // } 
// } 
  
// // // C function for extended Euclidean Algorithm 
// int gcdExtended(int a, int b, int *x, int *y) 
// { 
//     // Base Case 
//     if (a == 0) 
//     { 
//         *x = 0, *y = 1; 
//         return b; 
//     } 
  
//     int x1, y1; // To store results of recursive call 
//     int gcd = gcdExtended(b%a, a, &x1, &y1); 
  
//     // Update x and y using results of recursive 
//     // call 
//     *x = y1 - (b/a) * x1; 
//     *y = x1; 
  
//     return gcd; 
// } 
// ll modu(ll x)
// {
//     if(x<0)
//     {
//         x+=mod;
//     }
//     else 
//     {
//         x=x%mod;
//     }
//     return x;
// }

// void SieveOfEratosthenes(int n) 
// { 
//     // Create a boolean aay "prime[0..n]" and initialize 
//     // all entries it as true. A value in prime[i] will 
//     // finally be false if i is Not a prime, else true. 
     
//     memset(prime, true, sizeof(prime)); 
  
//     for (int p=2; p*p<=n; p++) 
//     { 
//         // If prime[p] is not changed, then it is a prime 
//         if (prime[p] == true) 
//         { 
//             // Update all multiples of p greater than or  
//             // equal to the square of it 
//             // numbers which are multiple of p and are 
//             // less than p^2 are already been marked.  
//             for (int i=p*p; i<=n; i += p) 
//                 prime[i] = false; 
//         } 
//     } 
//     prime[1]=false;
  
//     // Print all prime numbers 
//     // for (int p=2; p<=n; p++) 
//     //    if (prime[p]) 
//     //       cout << p << " "; 
// } 
// ll power(ll x, unsigned ll y, ll p) 
// { 
//     ll res = 1;      // Initialize result 
  
//     x = x % p;  // Update x if it is more than or  
//                 // equal to p 
  
//     while (y > 0) 
//     { 
//         // If y is odd, multiply x with result 
//         if (y & 1) 
//             res = (res*x) % p; 
  
//         // y must be even now 
//         y = y>>1; // y = y/2 
//         x = (x*x) % p;   
//     } 
//     return res; 
// } 

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

int abs(int a,int b){
	int d=a-b;
	if (d<0)return -d;
	return d;
}

int min(int a,int b){
	if (a>b)return b;
	return a;
}

int main(){
	vector <int> arr,dp;
	arr.push_back(0);
	dp.push_back(0);
	int n;
	cin>>n;
	int i,a;
	for(i=0;i<n;i++){
		cin>>a;
		arr.push_back(a);
	}
	dp.push_back(0);
	dp.push_back(abs(arr[2],arr[1]));
	for(i=3;i<n+1;i++){
		dp.push_back(min(dp[i-1]+abs(arr[i],arr[i-1]),dp[i-2]+abs(arr[i],arr[i-2])));
	}
	cout<<dp[n]<<endl;

	return 0;
}

Measured memory_bytes: 1400
def v():
 for e in iter(input,'0 0'):
  r=int(e.split()[0])
  d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
  a=0
  for m in range(1<<~-r):
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=c if c>r//2 else r-c
   if a<t:a=t
  print(a)
if'__main__'==__name__:v()


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

int main () 
{

  int  n,r;
  
  scanf("%d %d",&n,&r);
  
  if (n>=10)
  {
  	printf("%d",r);
    return 0;
  }
    
  printf("%d",r+100*(10-n));
  
 return 0;
}

Measured memory_bytes: 2108
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,A,B; cin >> N >> A >> B;
    if ((B-A) % 2 == 0) {
        cout << (B-A) / 2 << endl;
    } else {
        ll p = A + (B-A-1LL) / 2LL;
        ll q = (N - B + 1LL) + (B-A-1LL) / 2LL;
        cout << min(p,q) << endl;
    }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vll cnt(26,0LL);
    for(char c : s){
        cnt[(int)(c-'a')]++;
    }
    ll n = s.size();
    ll ans = (n)*(n-1)/2+1;
    REP(i,26){
        ans -= cnt[i]*(cnt[i]-1)/2;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 720
/* https://atcoder.jp/contests/abc074/tasks/arc083_a */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

/* {{{ Variables */
int A, B, C, D, E, F;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> A >> B >> C >> D >> E >> F;
  /* }}} */

  /* {{{ Output */
  int weight_sugar = 0;
  int weight_water_and_sugar = 100;

  for (int a = 0; a*100 <= F; a += A) {
    for (int b = 0; (a+b)*100 <= F; b += B) {
      int max_sugar = E*(a+b);
      int water = 100*(a+b);

      for (int c = 0; c <= max_sugar; c += C) {
        for (int d = 0; c + d <= max_sugar; d += D) {
          int s = c + d;
          int w_w_s = water + s;

          if (w_w_s > F) {
            break;
          }

          int x = weight_sugar*(w_w_s), y = s*(weight_water_and_sugar);

          if (x <= y) {
            weight_sugar = s;
            weight_water_and_sugar = w_w_s;
          }
        }
      }
    }
  }

  cout << weight_water_and_sugar << " " << weight_sugar << endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

bool CheckNum( int num, int drawNum, int div, int ans ){
    using namespace std;
    if( num % div != ans ){ return false; }
    cout << " " << drawNum;
    return true;
}

int main(){
    using namespace std;

    int input = 0;
    cin >> input;

    for( int i = 1; i <= input; ++i ){
        int x = i;    
        if( CheckNum( x, i, 3, 0 ) ){ continue; }
        while( x ){
            if( CheckNum( x, i, 10, 3 ) ){ break; }
            x /= 10;
        }
    }

    cout << endl;
   
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];
const int MOD = 1000000007;

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

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

    rep(i, q)
    {
        int l, r; cin >> l >> r;
        l--,r--;
        cout << s[r] - s[l] << endl;
    }
}

Measured memory_bytes: 1408
import math
import queue
import bisect
import heapq
import time
import itertools

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    s = input()
    ans = 0
    for i in range(len(s)//2):
        if s[i]!=s[len(s)-1-i]:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


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

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

	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();

	int cnt = 0;
	for (int i = a; i <= b; i++) {
	    if (c % i == 0) {
		cnt++;
	    }
	}

	System.out.println(cnt);
    }
}

Measured memory_bytes: 26132
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from math import gcd

def reduction(x,y):
    g = gcd(x,y)
    return abs(x)//g,abs(y)//g

def solve():
    mod = 10**9+7
    dplus = defaultdict(lambda: 0)
    dminus = defaultdict(lambda: 0)
    N = int(input())
    x0,y0,xy0 = 0,0,0
    for i in range(N):
        x,y = map(int, input().split())
        if x==0 and y==0:
            xy0 += 1
        elif x==0 and y!=0:
            x0 += 1
        elif y==0:
            y0 += 1
        elif x*y>0:
            dplus[reduction(x,y)] += 1
        else:
            dminus[reduction(-y,x)] += 1
    ans = pow(2,x0,mod)+pow(2,y0,mod)-1
    other = N-x0-y0-xy0
    for k,v in dplus.items():
        ans *= pow(2,dminus[k],mod)+pow(2,v,mod)-1
        other -= dminus[k]+v
    ans *= pow(2,other,mod)
    ans += xy0-1
    ans %= mod
    return ans
print(solve())

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int constexpr N = 109;
    vector<int> hd(N);
    for(int i = 2; i < N; ++i) {
        for(int j = i + i; j < N; j += i) hd[j] = i; 
    }

    vector<int> pc;
    for(int i = 2; i <= n; ++i) if(hd[i] == 0) {
        int cnt = 0;
        int j = i;
        while(n / j) {
            cnt += n / j;
            j *= i;
        }
        pc.push_back(cnt);
    }
    vector<vector<int>> dp(N, vector<int>(N, -1));
    function<int(int, int)> go = [&] (int i, int d) {
        if(d == 1) return 1;
        if(i == -1) return 0;
        if(dp[i][d] != -1) return dp[i][d];
        int& ans = dp[i][d] = 0;
        for(int j = 0; j <= pc[i]; ++j) {
            if(d % (j + 1) == 0) ans += go(i - 1, d / (j + 1));
        }
        return ans;
    };

    cout << go((int)pc.size() - 1, 75) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;

signed main() {
  vector<int>seisi(0);
  vector<int>seisiki(0);
  int k=1,t=1;
  while(k<=1000000){
    k=t*(t+1)*(t+2)/6;
    seisi.push_back(k);
    if(k%2==1) seisiki.push_back(k);
    t++;
  }

  int dpkisu[1000001],dp[1000001];
  rep(i,1000001){
    dpkisu[i]=INF;
    dp[i]=INF;
  }
  dpkisu[0]=0;
  dp[0]=0;
  for(int x=1;x<1000001;x++){
    rep(i,seisi.size()){
      if(seisi[i]<=x){
        dp[x]=min(dp[x],dp[x-seisi[i]]+1);
      }
    }
    rep(i,seisiki.size()){
      if(seisiki[i]<=x){
        dpkisu[x]=min(dpkisu[x],dpkisu[x-seisiki[i]]+1);
      }
    }

  }
  while(true){
    int l;cin>>l;
    if(l==0) exit(0);
    cout<<dp[l]<<' '<<dpkisu[l]<<endl;
  }
}



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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, M;
	cin >> N >> M;
	
	vector< int > cnt(N, 0);
	for_(i,0,M) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		++cnt[x];
		++cnt[y];
	}
	
	bool ans = true;
	for_(i,0,N) ans &= (cnt[i] % 2 == 0);
	puts(ans ? "YES" : "NO");
}

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

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

typedef unsigned long long ull;
typedef long long ll;

#define F first
#define S second
#define all(x) begin(x), end(x)

using namespace std;

vector<int> moves;
vector<bool> dp;

void exec()
{
	int n, k;
	cin >> n >> k;

	dp.resize(k + 1, 0);
	dp[0] = 0;

	moves.resize(n);
	for (int i = 0; i < n; ++i) cin >> moves[i];

	for (int i = 1; i <= k; ++i) {
		for (int k : moves) {
			if (k > i) break;
			if (!dp[i - k]) {
				dp[i] = true;
				break;
			}
		}
	}

	cout << (dp[k] ? "First" : "Second") << endl;
}

















int main()
{
	exec();

	return 0;
}

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

int main()
{
	int a, b, c;
	char op;
	
	cin >> a;
	cin >> op;
	cin >> b;
	
		if (op == '+')
			c = a + b;
		else
			c = a - b;
	
	cout << c << endl;
}


Measured memory_bytes: 256
while 1:
        n = input()
        if n == 0: break
        ns=""
        for i in range(n):
                if i == 0: ns = raw_input()
                temp = ''
                count = 1
                for j in range(len(ns)-1):
                        if ns[j] == ns[j+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[j]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int n; cin >> n;
    vint T(n);
    int sum = 0;
    rep(i,n) {
        int t; cin >> t;
        sum += t;
        T[i] = t;
    }
    int m; cin >> m;
    rep(i,m) {
        int p, x; cin >> p >> x;
        p--;
        cout << sum-T[p]+x << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int , int>
#define vi vector<int>
#define inf 1e18 //(10^18
#define pqmax priority_queue<int>
#define mii map<int , int>
#define ps(x, y) fixed<<setprecision(y)<<x
// double ans = 1.012345668992
//cout<<ps(ans , 6)
// ans = 1.012345 // 6 decimal places
#define pqmin priority_queue<int , vi , greater<int> >
#define mk(arr , n , type) type *arr = new type[n];
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
// 48->11000(4) (returns no. of zeros after first one)
#define mod 1000000007 //1e9 +7
#define w(t) int t; cin>>t;while(t--)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//shuffle(arr , arr +n , rng)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;
//pbds s;
//s.order_of_key(4);
//*s.find_by_order(4);
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);



    int n ;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i ;
        }
        // else if ( i % 3 == 0) {
        //     cout << "Fizz" << "\n";
        // }
        // else if ( i % 5 == 0) {
        //     cout << "Buzz" << "\n";
        // }
        // else {
        //     cout << "FizzBuzz" << "\n";
        // }

    }
    cout << sum << "\n";
    return 0;


}





Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	string p;
	cin >> p;
	int n = p.size();
	vector<int>a, b;
	for (int i = 0; i < n-1; i++) {
		if (p[i] != p[i] + 1) {
			if (i % 2) {
				a.push_back(i);
				b.push_back(i + 1);
			}
			else {
				a.push_back(i+1);
				b.push_back(i);
			}
		}
		
	}
	vector<int>t(n);
	int x=0;
	for (int i = 0; i < n; i++) {
		if (p[i] == 'R')x++;
		else {
			t[i] += x / 2;
			t[i - 1] += (x + 1) / 2;
			x = 0;
		}
	
	}
	reverse(t.begin(), t.end());
	reverse(p.begin(), p.end());
	for (int i = 0; i < n; i++) {
		if (p[i] == 'R')p[i] = 'L';
		else p[ i] = 'R'; 
	}
	for (int i = 0; i < n; i++) {
		if (p[i] == 'R')x++;
		else {
			t[i] += x / 2;
			t[i - 1] += (x + 1) / 2;
			x = 0;
		}

	}
	reverse(t.begin(), t.end());

	for (int i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << t[i];
	}
	cout << endl;



	return 0;


}

Measured memory_bytes: 2036
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long N,M,L,R,C[100005],cnt;
inline void solve(void){
  in(N,M);
  rep(i,M){
    in(L,R);
    C[L]++;
    C[R+1]--;
  }
  rep(i,100001){
    C[i+1]+=C[i];
  }
  rep(i,100001)if(C[i]==M)cnt++;
  out(cnt);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
char s[1005][1005];
int d[1005][1005];
int h,w;
void BFS(int sx,int sy)
{
    d[sx][sy]=0;
    deque< pair<int,int> >q;
    q.push_front(make_pair(sx,sy));
    int i,j;
    while(!q.empty())
    {
        int px,py,a,b;
        px=q.front().first;py=q.front().second;q.pop_front();
        //cout<<px<<" "<<py<<endl;
        a=px+1;b=py;
        if(a>=0 && a<h && b>=0 && b<w && s[a][b]=='.' && d[px][py]<d[a][b])
        {
            d[a][b]=d[px][py];
            q.push_front(make_pair(a,b));
        }
        a=px-1;b=py;
        if(a>=0 && a<h && b>=0 && b<w && s[a][b]=='.' && d[px][py]<d[a][b])
        {
            d[a][b]=d[px][py];
            q.push_front(make_pair(a,b));
        }
        a=px;b=py+1;
        if(a>=0 && a<h && b>=0 && b<w && s[a][b]=='.' && d[px][py]<d[a][b])
        {
            d[a][b]=d[px][py];
            q.push_front(make_pair(a,b));
        }
        a=px;b=py-1;
        if(a>=0 && a<h && b>=0 && b<w && s[a][b]=='.' && d[px][py]<d[a][b])
        {
            d[a][b]=d[px][py];
            q.push_front(make_pair(a,b));
        }
        for(i=-2;i<=2;i++)
        {
            for(j=-2;j<=2;j++)
            {
                a=px+i;b=py+j;
                if(a>=0 && a<h && b>=0 && b<w && s[a][b]=='.' && d[px][py]+1<d[a][b])
        {
            d[a][b]=d[px][py]+1;
            q.push_back(make_pair(a,b));
        }
            }
        }
    }
}
main()
{
    for(int i=0;i<=1002;i++)
    {
        for(int j=0;j<=1002;j++)
        {
            d[i][j]=1e9;
        }
    }
     int i,j,a,b,c1,d1;
     cin>>h>>w;cin>>a>>b;cin>>c1>>d1;
     a--;b--;c1--;d1--;
     for(i=0;i<h;i++)cin>>s[i];
     BFS(a,b);
     if(d[c1][d1]==1e9)
     {
         printf("-1\n");return 0;
     }
     /*for(i=0;i<4;i++)
     {
         for(j=0;j<4;j++)
         {
             cout<<d[i][j]<<" ";
         }
         cout<<endl;
     }*/
     cout<<d[c1][d1]<<endl;
}


Measured memory_bytes: 8616
#include <bits/stdc++.h>
                                            #include<iostream>
                                            #include<cstdio>
                                            #include<vector>
                                            #include<queue>
                                            #include<map>
                                            #include<cstring>
                                            #include<string>
                                            #include <math.h>
                                            #include<algorithm>
                                        //    #include <boost/multiprecision/cpp_int.hpp>
                                            #include<functional>
                               //     #define int long long
                                            #define inf  1000000007
                                            #define pa pair<int,int>
                                            #define ll long long
                                            #define pal pair<double,pa>
                                            #define ppa pair<int,int>
                                            #define ppap pair<pa,pa>
                                            #define ssa pair<string,int>
                                            #define  mp make_pair
                                            #define  pb push_back
                                            #define EPS (1e-10)
                                            #define equals(a,b) (fabs((a)-(b))<EPS)
                                      #define VI vector<int>
                                            using namespace std;
                                            
                                      class pas{
                                        	public:
                                        	int x,y;
                                        	pas(int x=0,int y=0):x(x),y(y) {}
                                        	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                        	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                        	pas operator * (int a) {return pas(x*a,y*a);}
                                        	pas operator / (int a) {return pas(x/a,y/a);}
                                        //	double absv() {return sqrt(norm());}
                                        	int norm() {return x*x+y*y;}
                                        	bool operator < (const pas &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pas &p) const{
                                        		return x==p.x && y==p.y;
                                        	}
                                        };
    int a[60];
               signed main(){
            
               	int m,n;
               cin>>a[0]>>a[1]>>a[2];
               	sort(a,a+3);
               	cout<<a[1]+a[0]<<endl;
               	
               	return 0;
               	
               	
               }

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

int main () {
    int N, ans = 0, res = 0;
    cin >> N;

    for (int i = 1; i <=  N; i++) {
        ans = 0;
        if (i % 2 != 0) {
            for (int j = 1; j <= N; j++) {
                if (i % j == 0) ans++;
            }    
        }
        if (ans == 8) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine() ?: ""
    val t = readLine() ?: ""
    val l = s.length

    var flag = false
    for (i in 0..(l - 1)) {
        for (j in 0..(l - 1)) {
            if (s[j] != t[(j + i) % l]) {
                break
            }

            if (j == l - 1) {
                flag = true
            }
        }
    }

    println(if (flag) "Yes" else "No")
}

Measured memory_bytes: 31744
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

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

    ll res = 0;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        res+=mp[i-a[i]];
        mp[i+a[i]]++;
    }
    cout<<res<<endl;
    

    
    return 0;
}


Measured memory_bytes: 21088
I = input().split()
x = int(I[0])
y = int(I[1])
while x != 0 or y != 0:
    if x < y:
        print(str(x) + ' ' + str(y))
    if x > y:
        print(str(y) + ' ' + str(x))
    if x == y:
        print(str(x) + ' ' + str(y))
    I = input().split()
    x = int(I[0])
    y = int(I[1])

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

using namespace std;

int main() {
    int n[26] = {0};
    string s;

    cin >> s;

    for (int i=0; i<s.size(); i++) {
        n[s[i]-'a']++;
    }

    for (int i=0; i<26; i++) {
        if(n[i]%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

using namespace std;
int main()
{
    int n,a;
    cin>>n;
    std::vector<int> array;

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

        cin >> a;
        array.push_back(a);
    }

    // 配列のインデックス indiecs = {0, 1, 2, 3, 4} を作成する。
    std::vector<size_t> indices(array.size());
    std::iota(indices.begin(), indices.end(), 0);

    // ソートする。
    std::sort(indices.begin(), indices.end(), [&array](size_t i1, size_t i2) {
        return array[i1] < array[i2];
    });

    int count = 0;
    for (auto v : indices)
    {
        if(count == indices[array.size()-1])
        {
            cout<<array[indices[array.size()-2]]<<endl;
        }
        else
        {
            cout<<array[indices[array.size()-1]]<<endl;  
        }
        count++;
    }
   
}

Measured memory_bytes: 4084
#include <vector>
#include <cstdio>
using namespace std;

int joseph(vector<int> &v,int d,int initial){
	int c=initial;
	for(;v.size()>1;c=(c+d)%v.size()){
		v.erase(v.begin()+c);
		c--;
	}
	return v[0];
}

int main(){
	int n,k,m;
	for(;scanf("%d%d%d",&n,&k,&m),n;){
		vector<int>v(n);
		for(int i=0;i<n;i++)v[i]=i+1;
		printf("%d\n",joseph(v,k,m-1));
	}
}

Measured memory_bytes: 1076
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.IntSummaryStatistics;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		sc.fill(a);

		IntSummaryStatistics statistics = Arrays.stream(a).summaryStatistics();

		System.out.println(statistics.getMax() - statistics.getMin());
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

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

using namespace std;

int main(){

  long long int a, b, c, d;
  cin>>a>>b>>c>>d;
  long long ans;

  if(a<0 and b>=0 and c<0 and d>=0){
    ans = max(a*c, b*d);
  }else if(a>=0 and b>=0 and c<0 and d<0){
    ans = max(a*d, b*c);
  }else if(a<0 and b<0 and c>=0 and d>=0){
    ans = max(a*d, b*c);
  }else{
    ans = max(a*c, b*d);
  }
  
  cout<<ans<<endl;
}


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

int main()
{
   
    char a[28]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    int n,len,j,i;
    string s;
    cin>>n>>s;
    len=s.length();
    for(i=0;i<len;i++){
        for(j=0;j<26;j++){
            if(s[i]==a[j]){
                j=(j+n)%26;
                break;
            }
        }

        cout<<a[j];
    }
    cout<<endl;
    return 0;
}




Measured memory_bytes: 256
int main(void)
{
    int H=1, W=1, i, j;

    

    while ((H != 0) && (W != 0))
    {
        scanf("%d %d", &H, &W);

        if ((H == 0) && (W == 0))
        {
            return 0;
        }
        else
        {
            for (j = 0;j < H;j++)
            {
                for (i = 0;i < W;i++)
                {
                    printf("#");
                }
                printf("\n");
            }
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll n, p, t, ans;
set<ll> myset;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (ll i = 2; i <= (ll)sqrt(n); i ++)
        if (n % i == 0)
        {
            p = i;
            t = n;
            while (t % p == 0)
                t /= p;
            if (t % p == 1)
                myset.insert(i);
            p = n / i;
            t = n;
            while (t % p == 0)
                t /= p;
            if (t % p == 1)
                myset.insert(n / i);
        }
    myset.insert(n);
    if (n - 1 >= 2)
        myset.insert(n - 1);
    n --;
    for (ll i = 2; i <= (ll)sqrt(n); i ++)
        if (n % i == 0)
        {
            myset.insert(i);
            myset.insert(n / i);
        }
    cout << (ll)myset.size();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	static Scanner inp= new Scanner(System.in);
	static PrintWriter out= new PrintWriter(System.out);
	public static void main(String args[]) {		    	
	   	Main g=new Main();
	   	g.main();
	   	out.close();
	}

	
	
	//Main
	void main() {
		
		int n=inp.nextInt();
		int a[]=new int[n];
		int N=(int)1e6+1;
		int sp[]=new int[N];
		sp[1]=1;
		for(int i=2;i<N;i++) {
			if(sp[i]==0) {
				for(int j=i;j<N;j+=i) {
					if(sp[j]==0) sp[j]=i;
				}
			}
		}
		for(int i=0;i<n;i++) {
			a[i]=inp.nextInt();
		}
		//for(int i=0;i<=6;i++) System.out.println(sp[i]);
		int usedIndex[]=new int[N];
		Arrays.fill(usedIndex, -1);
		boolean pairCo=true;
		loop:
		for(int i=0;i<n;i++) {
			int x=a[i];
			while(x>1) {
				if(usedIndex[sp[x]]!=-1 && usedIndex[sp[x]]!=i) {
					pairCo=false;
					break loop;
				}
				usedIndex[sp[x]]=i;
				x/=sp[x];
			}
		}
		if(pairCo) {
			System.out.println("pairwise coprime");
		}else {
			int x=a[0];
			for(int i=1;i<n;i++) {
				x=gcd(x,a[i]);
			}
			System.out.println(x==1?"setwise coprime":"not coprime");
		}
	}
    
    static int gcd(int a, int b) {
    	return b==0?a:gcd(b,a%b);
    }
		
}


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

int main()
{
	int k, n, a[200000], maxDiff = -1;
	cin >> k >> n;
	cin >> a[0];
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		if (maxDiff < a[i] - a[i-1]) maxDiff = a[i] - a[i - 1];
	}
	if (maxDiff < k - a[n-1] + a[0])  maxDiff = k - a[n-1] + a[0];
	cout << k - maxDiff << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>

template <class Tp>
Tp gcd(Tp a, Tp b, Tp& x, Tp& y) {
  x = Tp(0);
  y = Tp(1);
  for (Tp u=y, v=x; a;) {
    Tp q = b/a;
    std::swap(x-=q*u, u);
    std::swap(y-=q*v, v);
    std::swap(b-=q*a, a);
  }
  return b;
}

template <class Tp>
Tp modinv(Tp a, Tp mod) {
  Tp x, y;
  gcd(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

template <class Tp>
Tp modadd(Tp a, Tp b, Tp mod) {
  a += b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <class Tp>
Tp modadd(const std::initializer_list<Tp>& adds, Tp mod) {
  Tp res = 0;
  for (const auto& add: adds) {
    res += add % mod;
    if (res < 0) res += mod;
    if (res >= mod) res -= mod;
  }
  return res;
}

template <class Tp>
Tp modsub(Tp a, Tp b, Tp mod) {
  a -= b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <class Tp>
Tp modmul(const std::initializer_list<Tp>& muls, Tp mod) {
  Tp res = 1;
  for (const auto& mul: muls) (res *= mul) %= mod;
  return res;
}

template <class Tp>
Tp modpow(Tp base, intmax_t iexp, Tp mod) {
  Tp res = 1;
  for (Tp dbl = base; iexp; iexp >>= 1) {
    if (iexp & 1) res = res * dbl % mod;
    dbl = dbl * dbl % mod;
  }
  return res;
}

class modchoose {
  std::vector<intmax_t> fact, fact_inv;
  intmax_t mod;

public:
  modchoose(intmax_t N, intmax_t mod): mod(mod) {
    fact.resize(N+1);
    fact_inv.resize(N+1);
    fact[0] = 1;
    for (intmax_t i = 1; i <= N; ++i)
      fact[i] = fact[i-1] * i % mod;

    fact_inv[N] = modinv(fact[N], mod);
    for (intmax_t i = N; i--;)
      fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  intmax_t operator ()(intmax_t n, intmax_t r) const {
    intmax_t res = fact[n] * fact_inv[r] % mod;
    (res *= fact_inv[n-r]) %= mod;
    return res;
  }
};

constexpr intmax_t mod = 1e9+7;

int main() {
  intmax_t H, W;
  size_t N;
  scanf("%zu %zu %jd", &H, &W, &N);

  modchoose ncr(H+W+1, mod);
  std::vector<std::pair<intmax_t, intmax_t>> rc(N);
  for (auto& rci: rc) {
    scanf("%jd %jd", &rci.first, &rci.second);
    --rci.first;
    --rci.second;
  }

  rc.emplace_back(H-1, W-1);
  std::sort(rc.begin(), rc.end());

  std::vector<intmax_t> dp(N+1);

  for (size_t i = 0; i <= N; ++i) {
    intmax_t ri, ci;
    std::tie(ri, ci) = rc[i];
    dp[i] = ncr(ri+ci, ri);
    for (size_t j = 0; j < i; ++j) {
      intmax_t rj, cj;
      std::tie(rj, cj) = rc[j];
      if (!(rj <= ri && cj <= ci)) continue;
      dp[i] -= dp[j] * ncr(ri-rj+ci-cj, ri-rj) % mod;
    }
    dp[i] %= mod;
    if (dp[i] < 0) dp[i] += mod;
  }

  printf("%jd\n", dp[N]);
}


Measured memory_bytes: 3456
#include <stdio.h>
 
int main(void){

  char a,b;
  
  scanf("%c %c",&a,&b);

  if(a == 'H'){
  printf("%c\n",b);
  } else if(a == 'D' && b == 'H'){
  printf("D\n");
  } else {
  printf("H\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, m, v, p, ans;
int a[maxn];
ll presum[maxn];
int main()
{
	scanf("%d%d%d%d", &n, &m, &v, &p);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, greater<int>());
	for(int i = 1; i <= n; ++i)
		presum[i] = presum[i - 1] + a[i];
	for(int cur = 1; cur <= n; ++cur)
	{
		int pos = lower_bound(a + 1, a + n + 1, a[cur] + m, greater<int>()) - a;
		if(pos > p)
			break;
		if(v <= pos)
		{
			++ans;
		}
		else
		{
			ll ret = 1ll * (n - v) * m;
			if(p < cur)
			{
				ret += 1ll * (cur - p) * a[cur];
				ret -= presum[cur - 1] - presum[p - 1];
			}
			ans += (ret >= 0);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1408
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,i;cin>>n;
	vector<llint>a(n);
	vector<llint>b;
	for(i=0;i<n;i++){cin>>a[i];}
	sort(a.begin(),a.end());
	for(i=0;i<n-1;i++){
		if(a[i]==a[i+1]){b.pub(a[i]);i++;}
	}
	if(b.size()<2){cout<<0<<endl;return 0;}
	cout<<b[b.size()-1]*b[b.size()-2]<<endl;
	return 0;
}


Measured memory_bytes: 1660