akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8

import sys
input = sys.stdin.readline

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

N = int(input())
A = list(map(int, input().split()))

first_gcd = A[0]
for i in range(len(A)):
    first_gcd = gcd(first_gcd, A[i])

print(first_gcd)



Measured memory_bytes: 14172
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Collections;

class Main {

    static int N;
    static int M;
    static int Q;

    static int[] a;
    static int[] b;
    static int[] c;
    static int[] d;

    static int ans = 0;


    private static void printA(ArrayList<Integer> A) {
        for  (Integer i : A) {
            System.out.print(i + " ");
        }
        System.out.println();
    }

    private static void dfs(ArrayList<Integer> A) {
        if (A.size() == N + 1) {
            int now = 0;
            for (int i = 0; i < Q; i++) {
                if (A.get(b[i]) - A.get(a[i]) == c[i]) now += d[i];
            }
            ans = Math.max(ans, now);
            return;
        }

        if (A.size() > N + 1) return;

        A.add(A.get(A.size() - 1));
        while (A.get(A.size() - 1) <= M) {
            dfs(new ArrayList<Integer>(A)); // depth first search.
            Integer v = A.get(A.size() - 1);
            A.set(A.size() - 1, v + 1);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt(); // less than 10
        Q = sc.nextInt(); // less than 50

        a = new int[Q];
        b = new int[Q];
        c = new int[Q];
        d = new int[Q];
        for (int i = 0; i < Q; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        ArrayList<Integer> A = new ArrayList<Integer>();
        A.add(1);
        dfs(A);

        System.out.println(ans);
    }

}

Measured memory_bytes: 56760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		long N=sc.nextLong();
		long P=sc.nextLong();
		long max=0;
		if(N==1) {
			System.out.println(P);
			System.exit(0);
		}
		else {
			for(long i=1; i<=1000000; i++) {
				long a=np_solve(i,N);
				if(a>=1) {
					if(P%a==0) {
						max=i;
					}
				}
				else if(a<=0) {
					break;
				}
			}
		}
		System.out.println(max);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static long np_solve(long n,long p) {		//n^p mod m
		long[] amari=new long[50];
		amari[0]=n;
		for(int i=0; i<48; i++) {
			amari[i+1]=amari[i]*amari[i];
		}
		long tmp=p;
		int counter=0;
		long ans=1;
		while(tmp>0) {
			if(tmp%2==1) {
				ans=ans*amari[counter];
				tmp/=2;
				counter++;
			}
			else {
				tmp/=2;
				counter++;
			}
		}
		 return ans;
	}
}

Measured memory_bytes: 144980
n = input()
A = map(int, raw_input().split())
count = 0
for i in xrange(n):
    mini = i
    for j in xrange(i,n):
        if A[j] < A[mini]:
            mini = j
    if i < mini:
        key = A[mini]
        A[mini] = A[i]
        A[i] = key
        count += 1
print ' '.join(map(str, A))
print count

Measured memory_bytes: 4224
N, M = map(int, input().split())
pic = [list(input()) for _ in range(N)]
template = [list(input()) for _ in range(M)]

'''
for _ in pic:
    print("".join(_))

for _ in template:
    print("".join(_))
'''


def ifIncluded(start_position, pic, template):
    for t in range(M):
        for y in range(M):
            if not template[t][y] == pic[start_position[0] + t][start_position[1]+y]:
                return False
    return True


for t in range(N - M+1):
    for y in range(N - M+1):
        start_position = [t, y]
        if ifIncluded(start_position, pic, template):
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(12);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::string s;

  std::cin >> N;

  long double x, S = 0.0;

  for (int i = 0; i < N; i ++) {
    std::cin >> x >> s;

    if (s == "JPY") {
      S += x;
    }
    else {
      S += x * 380000.0;
    }
  }

  std::cout << S << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
using P = pair<ll, ll>;

struct edge { int to, cost; };
vector<vector<edge>> G;
vector<ll> d;

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) { continue; }

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	const ll INF = 1e18;
	int K;
	cin >> K;

	G.resize(K);
	d.resize(K, INF);

	for (int i = 0; i < K; ++i) {
		int to1 = (i + 1) % K;
		int to10 = (i * 10) % K;

		if (to1 != i) { G[i].push_back({to1, 1}); }
		if (to10 != i) { G[i].push_back({to10, 0}); }
	}

	dijkstra(1);

	ll res = d[0] + 1;
	cout << res << endl;

	return 0;
}


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

class Ring{
	String str1;

	Ring(String str1){
		this.str1 = str1 + str1;
	}
}

class Keyword{
	String str2;

	Keyword(String str2){
		this.str2 = str2;
	}
}

public class Main{
	public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	Ring x = new Ring(br.readLine());
	Keyword y = new Keyword(br.readLine());

		if(x.str1.contains(y.str2)){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}

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

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		String s=stdIn.next();
		char l='7';
		if(s.charAt(0)==l||s.charAt(1)==l||s.charAt(2)==l) {
			System.out.println("Yes");
		}
		else
			System.out.println("No");

	}

}


Measured memory_bytes: 35724
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
using namespace std;
const double eps = 1e-4;
const int max_v = 1e4;
struct edge {int u, v; double cost;};
bool comp(const edge &e1, const edge &e2) {
    return e1.cost > e2.cost;
}
struct Point{int x, y;};
Point p[max_v + 10];
vector <edge> es;
int n, m;
int par[max_v + 10], ranks[max_v + 10];
inline double dst(Point p1, Point p2) {
    int x1 = p1.x, y1 = p1.y;
    int x2 = p2.x, y2 = p2.y;
    int d1 = x1 - x2, d2 = y1 - y2;
    return sqrt(d1 * d1 * 1.0 + d2 * d2 * 1.0);
};
int find(int a) {
    if (par[a] == a) return a;
    int r = find(par[a]);
    par[a] = r;
    return r;
}

void unite(int a, int b) {
    int r1 = find(a);
    int r2 = find(b);
    if (r1 == r2) return ;
    if (ranks[r1] > ranks[r2]) {
        par[r2] = r1;
        ranks[r1] += ranks[r2];
    } else {
        par[r1] = r2;
        ranks[r2] += ranks[r1];
    }
}
bool same(int a, int b) {
    return find(a) == find(b);
}
double Kruskal() {
    sort(es.begin(), es.end(), comp);
    for (int i = 1; i <= n; i++) {
        par[i] = i;
        ranks[i] = 0;
    }
    double res = 0;
    for (auto e : es) {
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);
            res += e.cost;
        }    
    }
    return res;
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) 
        scanf("%d%d", &p[i].x, &p[i].y);
    
    double totW = 0;
    for (int i = 0; i < m; i++) {
        int p1, p2;
        scanf("%d%d", &p1, &p2);
        double d = dst(p[p1], p[p2]);
        es.push_back(edge{p1, p2, d});
        totW += d;
    }
    printf("%.3lf\n", totW - Kruskal());
    return 0;
}





Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2e5+5;
int n,m,hd[maxn],k,mx,S,T,dep[maxn];
struct edd{
	int nt,v;
}e[maxn*2];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline void add(int a,int b){
	e[k].v=b; e[k].nt=hd[a]; hd[a]=k++;
	e[k].v=a; e[k].nt=hd[b]; hd[b]=k++;
}

void dfs(int x,int fa){
	dep[x]=dep[fa]+1;
	if(dep[x] > dep[mx]) mx=x;
	for(rg int i=hd[x];i!=-1;i=e[i].nt){
		int v=e[i].v; if(v == fa) continue;
		dfs(v,x);
	}
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	#endif
	memset(hd,-1,sizeof(hd)); k=0;
	n=rd(); int x,y;
	go(i,n,1){
		x=rd(); y=rd();	add(x,y);
	}
	dfs(1,0);
	S=mx;
	dfs(S,0);
	T=mx;
	int d=dep[T];
	if(d == 1) puts("First");
	else if(d == 2) puts("Second");
	else{
		d-=2;
		if(d%3 == 0) puts("Second");
		else puts("First");
	}
	return 0;
}//Faze


Measured memory_bytes: 11136
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define MOD         1000000007
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)

void IO() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    //IO();
    fastio;
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll x; cin >> x;
    int cnt = 0;
    int y = 0;
    y = 100;
    while (y < x) {
    	y += y / 100;
    	cnt++;
    }
   	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3648
input()
p=1
flag=True
lst=list(map(int,input().split()))
for i in range(len(lst)):
    if i==0 and 0 in lst:
        p=0
        flag=True
        break
    p*=int(lst[i])
    if p>10**18:
        flag=False
        print(-1)
        break
if flag:
    print(p)

Measured memory_bytes: 21772
S = list(input())

#  ><は0でいいのか
#  同様に S[0]==<とS[-1]==>も0でいい
#  制約的にNlogNくらいまでは十分許容範囲だし><は0で埋めてindex保持、そこから単調増加で組むのが良さそう？

#  3回ループさせる形で実装してみる

tmp = [-1] * (len(S) + 1)

for i in range(len(S) - 1):
    if S[i] == ">" and S[i + 1] == "<":
        tmp[i + 1] = 0
        
if S[0] == "<":
    tmp[0] = 0

if S[-1] == ">":
    tmp[-1] = 0

for i in range(len(S)):
    if S[i] == "<":
        tmp[i + 1] = tmp[i] + 1
        
for i in range(len(S) - 1, -1, -1):
    if S[i] == ">":
        tmp[i] = max(tmp[i], tmp[i + 1] + 1)

print(sum(tmp))
        


Measured memory_bytes: 32460
<?php
$input = explode(' ', trim(fgets(STDIN)));

$r = (int)$input[0];
$g = (int)$input[1];
$b = (int)$input[2];
$n = (int)$input[3];

$r_max = (int)floor($n / $r);
$g_max = (int)floor($n / $g);
$b_max = (int)floor($n / $b);

$cnt = 0;
for ($rc=0; $rc <= $r_max; $rc++) { 
	for ($gc=0; $gc <= $g_max; $gc++) { 
		if (($n - $rc * $r - $gc * $g) >= 0 && ($n - $rc * $r - $gc * $g)%$b === 0) {
			// echo $rc . ' ' . $gc . PHP_EOL;
			++$cnt;
		}
	}
}

echo $cnt;

Measured memory_bytes: 4728
n,a,b = map(int,input().split())
s = input()

ab = a+b

passed = 0

Bs = 1

for i in range(len(s)):
  if s[i]=="a" and passed < ab:
    print("Yes")
    passed +=1
  elif s[i]=="b" and passed < ab and Bs<=b:
    print("Yes")
    Bs += 1
    passed += 1
  else:
    print("No")

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

using namespace std;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    int n, m, x; cin >> n >> m >> x;
    vi c(n); vvi a(n, vi(m));
    REP(i, n) {
        cin >> c[i];
        REP(j, m) cin >> a[i][j];
    }

    int ans = INF;
    REP(s, 1<<n) {
        int sum = 0;
        vi skill(m);
        REP(i, n) {
            if (s >> i & 1) {
                sum += c[i];
                REP(j, m) {
                    skill[j] += a[i][j];
                }
            }
        }
        bool valid = true;
        REP(j, m) {
            if (skill[j] < x) {
                valid = false;
            }
        }
        if (valid) {
            chmin(ans, sum);
        }
    }

    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3680
#include <stdio.h>

using namespace std;

int main(){
	int x,y;
	while(true){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0) break;
		if(x > y) printf("%d %d\n",y,x);
		else{
			printf("%d %d\n",x,y);
		}
	}
}



Measured memory_bytes: 2572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <cstdlib>
#include <iomanip>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <iterator>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <cstring>
#include <sstream>
#include <stack>
#include <random>

using namespace std;

#define vi vector<int> 
#define vvi vector<vi>
#define pi pair<int,int>
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define io ios::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(a) int((a).size()) 
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define loop(i,b) for (int i = 0; i < b; ++i)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define INF numeric_limits<int>::max()
#define LLINF numeric_limits<ll>::max()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define F first
#define S second
#define MOD 1000000007
#define cflout(x) cout << fixed << setprecision(8) << x << endl
#define setzero(x) memset(x, 0, sizeof(x))

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

random_device _random_device;
default_random_engine _generator(_random_device());
uniform_int_distribution<long long unsigned> _distribution(0, 0xFFFFFFFFFFFFFFFF);

inline long long unsigned get_random_number() {
    return _distribution(_generator);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

inline ll nxt() {
	ll x;
	cin >> x;
	return x;
}

namespace aux {	
vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) {
		v.emplace_back(x);
    }
    return v;
}
}


map<int, int> res2cnt;
int n;


int main() {
	io;

	n = nxt();
	loop(i, n) {
		int x = nxt();
		res2cnt[x]++;
		res2cnt[x-1]++;
		res2cnt[x+1]++;
	}

	int maxcnt = 0;

	for (auto p : res2cnt) {
		uax(maxcnt, p.S);
	}

	cout << maxcnt << endl;


	return 0;
}


















Measured memory_bytes: 4736
using System;
using System.Linq;

namespace ABC088
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            int[] a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(input[i]);
            }

            a = a.OrderByDescending(x => x).ToArray();

            int alicepoint = 0;
            int bobpoint = 0;

            for (int i = 0; i < N; i++)
            {
                if ((i % 2) != 0)
                {
                    bobpoint += a[i];
                }
                else
                {
                    alicepoint += a[i];
                }
            }
            Console.WriteLine(alicepoint - bobpoint);
        }
    }
}


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

int main() {
	int n;cin>>n;
	string s;cin >>s;
	int cnt=0;
	int pos=0;
	while(pos != string::npos){
		pos = s.find("ABC",pos);
		if(pos != string::npos){
			++cnt;
			++pos;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<string> s(n);
  REP(i, n) {
    cin >> s[i];
  }

  map<P, int> mp;
  ll su = 0;
  REP(i, n) {
    bool a = false;
    int nowcnt = 0;
    REP(j, SZ(s[i])-1) {
      if(s[i][j] == 'A' && s[i][j+1] == 'B') nowcnt++;
    }
    su += nowcnt;

    int v1 = s[i][0] == 'B';
    int v2 = s[i][SZ(s[i])-1] == 'A';
    mp[{v1, v2}]++;
  }
  //cout << su << endl;
  //cout << mp[{1, 1}] << ":" << mp[{1, 0}] << ":" << mp[{0, 1}] << endl;

  if(mp[{1, 1}] > 0) {
    su += mp[{1, 1}] - 1;
    if(mp[{1, 0}] > 0) {
      su++;
      mp[{1, 0}]--;
    }
    if(mp[{0, 1}] > 0) {
      su++;
      mp[{0, 1}]--;
    }
    cout << su + min(mp[{0, 1}], mp[{1, 0}]) << endl;
  } else {
    cout << su + min(mp[{1, 0}], mp[{0, 1}]) << endl;
  }


}








Measured memory_bytes: 3748
// "for if God is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
int ans = 0;
int cnt[400004];
void solve() {
	ll n, ans = 0;
	cin >> n;
	ll a[n];
	map<ll, ll>m;
	REP(i, 0, n - 1) {
		cin >> a[i];
		m[a[i]]++;
		ans += a[i];
	}
	ll q;
	cin >> q;
	while (q--) {
		ll b, c;
		cin >> b >> c;
		ll k = c - b;
		m[c] += m[b];
		ans += (k * m[b]);
		m[b] = 0;
		cout << ans << endl;
	}
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

Measured memory_bytes: 10308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> A(N+1);
    vector<int> B(N);
    REP(i,N+1)A[i] = in();
    REP(i,N)B[i] = in();
    ll sum = 0;
    REP(i,N){
        ll tmp = A[i];
        A[i] = max(A[i]-B[i],0);
        B[i] -= tmp - A[i];
        sum += tmp - A[i];
        tmp = A[i+1];
        A[i+1] = max(A[i+1]-B[i],0);
        sum += tmp - A[i+1];
    }
    cout << sum << "\n";
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 500000
#define M 2000000000
void merge(int *,int,int,int);
void mergesort(int *,int,int);
int L[(N/2)+2],R[(N/2)+2];
int cnt;

int main(){
  int A[N],n,i;
  cnt=0;
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergesort(A,0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[n-1],cnt);
  return 0;
}

void merge(int A[],int left,int mid,int right){
int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=M;
  R[n2]=M;
  i=0;
  j=0;
  for (k = left;k < right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergesort(int A[],int left,int right){
int mid;
if(left+1<right){
  mid=(left+right)/2;
  mergesort(A,left,mid);
  mergesort(A,mid,right);
  merge(A,left,mid,right);
  }
}

Measured memory_bytes: 4504
import sys
input = sys.stdin.readline

def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(3500, 0, -1):
            tmp = 4 * h * n - N * (h + n)
            if tmp > 0:
                if (N * h * n) % tmp == 0:
                    w = (N * h * n) // tmp
                    print(h, n, w)
                    return
            else:
                break


if __name__ == "__main__":
    main()

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

int X;

int solve() {
    REP (i, X) {
        int x = X - 100*i;
        if (0 <= x && x <= 5*i) return 1;
    }
    return 0;
}

int main () {
    cin >> X;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;



int32_t main()
{
    fast

   int test=1;
    //cin>>test;
  
   

  while(test--)
  {
    int n;
    cin>>n;

    vi a(n);
    forn(i,n)cin>>a[i];

   vi s(n,0);
   s[n-1]=a[n-1];
   for(int i=n-2;i>=0;i--)
   {
    s[i]=(a[i]+s[i+1])%mod;
   }

   int ans=0;
   for(int i=0;i<n-1;i++)
   {
    ans=(ans+a[i]*s[i+1])%mod;
   }

   cout<<ans;


// while ending
   }
  

return 0;
}

Measured memory_bytes: 6332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BBiteEating {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int l = in.nextInt();
            if (l >= 0) {
                int ans = n * l + (n * (n + 1) / 2) - n - l;
                out.println(ans);
                return;
            } else {
                int i = 1 - l;
                if (i <= n) {
                    int ans = n * l + (n * (n + 1) / 2) - n;
                    out.println(ans);
                    return;
                } else {
                    int ans = n * l + (n * (n + 1) / 2) - n - (l + n - 1);
                    out.println(ans);
                    return;

                }
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

constexpr ll INF = (1LL << 60);

template <typename T> 
struct LazySegmentTree {
  
  int n;
  vector<T> node, lazy;

  LazySegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
    lazy.assign(2*n, 0); /*区間加算の時は0*/
  }

  void eval (int k) {
    if (lazy[k] == 0) return ;
    node[k] += lazy[k]; /*区間加算に注意*/
    if (k < n) {
      lazy[2*k+1] += lazy[k];
      lazy[2*k+2] += lazy[k];
    }
    lazy[k] = 0;
  }

  void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
    eval(k);
    if (r < 0) r = n;
    if (b <= l || r <= a) return ;
    if (a <= l && r <= b) {
      lazy[k] = x;
      eval(k);
    } else {
      update(a, b, x, 2*k+1, l, (r+l)/2);
      update(a, b, x, 2*k+2, (r+l)/2, r);
      node[k] = node[2*k+1] + node[2*k+2];
    }
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    eval(k);
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return vl + vr;
  }

};

int main(){
  int n, d, a;
  cin >> n >> d >> a;
  vector<pair<ll, ll>> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  LazySegmentTree<ll> seg(n);
  for (int i = 0; i < n; i++) seg.update(i, i + 1, p[i].second);

  ll res = 0;

  for (int l = 0; l < n; l++) {
    ll h = seg.query(l, l + 1);
    if (h <= 0) continue;
    ll x  = p[l].first + 2 * d;
    auto r = lower_bound(p.begin(), p.end(), make_pair(x, INF)) - p.begin();
    ll cnt = (h + a - 1) / a;
    res += cnt;
    seg.update(l, r, -cnt * a);   
  } 

  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 11520
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll a[1001]; ll ca[1001];
int main() {
	vector<ll> v;
	int n; ll k; cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
		ca[i + 1] = ca[i] + a[i];
	}
	rep(i, n) {
		Rep(j, i, n) {
			ll s = ca[j+1] - ca[i];
			v.push_back(s);
			//cout << s << endl;
		}
	}
	ll out = 0;
	per(t, 41) {
		sort(v.begin(), v.end());
		int len = v.size();
		ll key = (ll)1 << t;
		int id = lower_bound(v.begin(), v.end(), key) - v.begin();
		if (len - id >= k) {
			v.erase(v.begin(), v.begin() + id);
			out += key;
			len = v.size();
		}
			rep(j, len) {
				if (v[j] & key)v[j] ^= key;
			}
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 6384
Q = int(input())
lll = []
rrr = []
for i in range(Q):
    buff = [int(i) for i in input().split()]
    lll.append(buff[0])
    rrr.append(buff[1])

def get_sieve_of_eratosthenes(n):#遅い?改善の余地あり。n以下の素数のリストを返す
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return(data)

Nmax = 10**5+5
#Nmax=10

isprime = [0 for i in range(Nmax)]
for i in get_sieve_of_eratosthenes(Nmax):
    isprime[i] = 1

cumulative_sum = [0 for i in range(Nmax)]
for i in range(1,Nmax):
    if i%2==1 and isprime[i]==1 and isprime[(i+1)//2]==1:
        cumulative_sum[i] = cumulative_sum[i-1]+1
    else:
        cumulative_sum[i] = cumulative_sum[i-1]

#print(cumulative_sum)

for l,r in zip(lll,rrr):
    #print(l,r)
    print(cumulative_sum[r]-cumulative_sum[l-1])


Measured memory_bytes: 14076
#include<stdio.h>

int main(void){
    int n;
    int a[100];
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    
    int flag=1,tmp,count=0;
    while(flag){
        flag=0;
        for(int j=n-1;j>=1;j--){
            if(a[j]<a[j-1]){
                tmp=a[j];
                a[j]=a[j-1];
                a[j-1]=tmp;
                
                flag=1;
                count++;
            }
        }
    }
    
    for(int i=0;i<n-1;i++)printf("%d ",a[i]);
    printf("%d\n%d\n",a[n-1],count);
}



Measured memory_bytes: 2092
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++)cin >> a[i];
  int count = 0;
  for(int j = 0; j < n; j++){
    if(a[j] == j+1){
      swap(a[j], a[j+1]);
      count++;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	long long int  a = 0, b = 0, x = 0;
	long long int  n = 0, ans = 0, count = 0;
	string s,t,u;
	vector<long long int> z;
	vector<long long int>::iterator position;
	bool q = false;
	cin >> s>>t>>a>>b>>u;
	if (s == u) {
		a--;
	}
	else b--;
		cout << a <<" "<<b<< endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        
        Set<Long> divA = new HashSet<Long>();
        Set<Long> divB = new HashSet<Long>();
        for (long i = 1; i*i <= Math.max(A,B); i++) {
            if (A%i == 0) {
                divA.add((long)i);
                divA.add(A/i);
            }
            if (B%i == 0) {
                divB.add((long)i);
                divB.add(B/i);
            }
        }

        List<Long> divCommon = new ArrayList<Long>();
        for (Long l : divA) {
            if (divB.contains(l)) {
                divCommon.add(l);
            }
        }

        long ans = 0;
        Collections.sort(divCommon);
        for (Long i : divCommon) {
            if (i == 1) {
                ans++;
                continue;
            }
            boolean div = false;
            for (Long j : divCommon) {
                if (i <= j) {
                    break;
                }
                if (i%j == 0 && j != 1) {
                    div = true;
                    break;
                }
            }
            if (!div) {
                ans++;
            }
        }

        //System.out.println(divCommon);
        System.out.println(ans);
    }
}


Measured memory_bytes: 27652
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int> > a(n,vector<int>());
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		a[i].resize(k);
		for(int j = 0; j < k; j++){
			cin >> a[i][j];
		}
	}

	vector<int> cnt(m);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < a[i].size(); j++){
			cnt[a[i][j]-1]++;
		}
	}

	int ans=0;
	for(int i = 0; i < m; i++){
		if(cnt[i] == n) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.length();
    int beki10 = 1;
    int i,ans=0;
    if(s.at(0)>'1') beki10=0;
    for(i=1;i<n;i++){
        if(s.at(i)>'0') beki10=0;
    }
    if(beki10) ans = 10;
    else{
        for(i=0;i<n;i++) ans += s.at(i)-'0';
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int nxt = 1, ans = 0;
    rep(i,n){
        if(nxt == a[i]){
            nxt++;
        }else{
            ans++;
        }
    }
    if(ans==n)ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
A, B, C = sorted(map(int, input().split()))

ret = 0

m = A % 2 + B % 2 + C % 2

if m == 3 or m == 0:
    pass
else:
    ret += 1
    if m == 2:
        if A % 2 == 0:
            B += 1
            C += 1
        elif B % 2 == 0:
            A += 1
            C += 1
        else:
            A += 1
            B += 1
    else:
        if A % 2 == 1:
            B += 1
            C += 1
        elif B % 2 == 1:
            A += 1
            C += 1
        else:
            A += 1
            B += 1

print(ret + (C - B) // 2 + (C - A) // 2)


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int par[200003];
int ran[200003];
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        ran[i]=0;
    }
}
int fin(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=fin(par[x]);
    }
}
void unite(int x,int y){
    x=fin(x);
    y=fin(y);
    if(x==y)return;
    if(ran[x]<ran[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}


int main(){
    init(200003);
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        unite(a,b);
    }

    int cou[200003]={0};
    for(int i=1;i<=N;i++){
        cou[fin(i)]++;
    }
    int ans=0;
    for(int i=1;i<=N;i++){
        ans=max(ans,cou[i]);
    }
    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 5476
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    ll n;
    cin >> n;
    vector<ll> a(5);
    rep(i,5) cin >> a[i];
    ll mn = *min_element(a.begin(),a.end());
    ll ans = (n+mn-1)/mn + 4;
    cout << ans << endl;
    return 0;
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u32 = read();
    let mut vv: Vec<u32> = read_vec();
    vv.sort();
    let mut ans: f64 = vv[0] as f64;
    for v in vv {
        ans = (ans + (v as f64)) / 2.0;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;

    int res = 0;
    for (int i = 0; i < n; ++i) {
        ++res;
        while (i + 1 < n && s[i + 1] == s[i]) {
            ++i;
        }
    }
    cout << res << "\n";


    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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
















int main(){
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    ll sum = 0;
    cin >> a[0];
    REP(i, n - 1){
        cin >> a[i + 1];
        sum += a[i + 1] - a[i];
    }
    sum += a[0] + (k - a[n - 1]);
    ll ans = sum - a[0] - (k - a[n - 1]);
    REP(i, n - 1){
        ans = min(ans, sum - (a[i + 1] - a[i]));
    }
    cout << ans << endl;
}

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

string a[51], b[51];
int n, m;

int main()
{
	cin>>n>>m;
	for(int i=0; i<n; ++i) cin>>a[i];
	for(int i=0; i<m; ++i) cin>>b[i];
	
	for(int i=0; i<=n-m; ++i){
		for(int j=0; j<=n-m; ++j){
			auto f = [&](){
				for(int k=0; k<m; ++k){
					if(a[i+k].substr(j, m) != b[k]) return false;
				}
				return true;
			};
			if(f()){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();

		char[] list = s.toCharArray();

		for(int i = 0; i < list.length; i++) {
			list[i] += n;

			while(list[i] > 'Z') {
				list[i] -= 26;
			}

		}

		System.out.println(list);

		sc.close();
	}

}


Measured memory_bytes: 22716
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const int MAX_N=5001;
const ll LINF=100000000000000000;

int main(){
  int n,s,l;
  cin >> n ;
  s=INF;
  l=-1;
  rep(i,n){
    int a;
    cin >> a ;
    s=min(s,a);
    l=max(l,a);
  }
  cout << l-s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll A,B,C;
    int N,M,K,X,Y,W,H;
    ll ans;
    string S;
    ll a[100010];
    int temp[100]={0};
    bool f=false;
    bool fir=true;
    ll sum[10000];

int main(){
    cin>>A>>B;
    if(A%3==0||B%3==0||(A+B)%3==0){
        cout<<"Possible";
    }else{
        cout<<"Impossible";
    }
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int k, a, b;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);

    for(int i = a;i <= b;i++){
        if(i % k == 0){
            printf("OK\n");
            return 0;
        }
    }

    printf("NG\n");

    return 0;
}

Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
std::string replaceAll(std::string &replacedStr, std::string from, std::string to) {
    unsigned int pos = replacedStr.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return replacedStr;
    }
 
    while ((pos = replacedStr.find(from, pos)) != std::string::npos) {
        replacedStr.replace(pos, from.length(), to);
        pos += toLen;
    }
    return replacedStr;
}
int main() {


//long long a,b;
//int *num=new int[4];
//char *s=new char[3];
string s;
cin >> s;
int res=0;
for(int i=0;i<s.length();i++){
if(s[i]=='x')res++;
}
if(res<=7)
cout << "YES"<<"\n";
else
cout << "NO"<<"\n";


}


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

using namespace std;

const int len = 8;

int main(void) {
    int n, x[len], a, b;
    char c;
    cin >> n;
    while (n--) {
        for (int i = 0; i < len; i++) {
            cin >> c;
            x[i] = int(c - '0');
        }
        sort(x, x + len);
        a = 0;
        for (int i = len - 1; i >= 0; i--) {
            a *= 10;
            a += x[i];
        }
        b = 0;
        for (int i = 0; i < len; i++) {
            b *= 10;
            b += x[i];
        }
        cout << (a - b) << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mod 1000000007
#define Max 1000001
#define vt vector<long long>

void func(){
    ll x;
    cin>>x;
    if(x==0)
        cout<<1<<endl;
    else{
        cout<<0<<endl;
    }
      
      
      
}

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

// 
// int t;
// cin >> t;
// for(ll i=1; i<=t; i++)
// {
    func();
//    cout<<endl;
//cout<<func()<<endl;
 
//if(func())
//    cout<<"Yes"<< endl;
//else
//    cout <<"No"<<endl; 
//cout<<"Case"<<" "<<"#"<<i<<":"<<" "<<func()<<endl;
// }
return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    bool flag = false;
    if (n % 2 == 0) {
        for (int i = 0; i < n / 2; i++) {
            if (s.at(i) == s.at(i  + n / 2)) {
                flag = true;
            }
            else if (s.at(i) != s.at(i + n / 2)) {
                flag = false;
                break;
            }
        }
    }
    if (flag) {
          cout << "Yes" << endl;
      }
      else {
          cout << "No" << endl;
      }
    return 0;
}

Measured memory_bytes: 256
let m = 1_000_000_007
let n = read_int()
let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun i -> i))

let () =
  let ans = ref 0 in
  for i = 0 to 59 do
    let b = 1 lsl i in
    let z = Array.fold_left (fun z a -> if a land b = 0 then z + 1 else z) 0 a in
    ans := (!ans + b mod m * z mod m * (n - z) mod m) mod m
  done;
  Printf.printf "%d\n" !ans


Measured memory_bytes: 8284
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
int n,a[100004];
map<int,int>mert;
long long ans=0;
int LiangJiaJun(){
    scanf("%d",&n);
    mert.clear();
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        mert[a[i]]++;
    }
    map<int,int>::iterator it;
    for(it=mert.begin();it!=mert.end();it++){
        if((it->second) == (it->first))continue;
        else if((it->second) > (it->first))ans+=((it->second) - (it->first));
        else ans += (it->second);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 5120