akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    """
    2つのリストの関係を調べる云々は「二部グラフの完全マッチング問題」というカテゴリ名で呼ばれる。
    そしてこれに対しては「Hallの定理」というのが有効らしい。高校数学の美しい物語参照。

    特に大事なのがHall条件と呼ばれる方で、一見これはAの全ての部分集合を見ないといけないが
    部分集合のサイズが大きいと即座に|A| ¥subset |¥Gamma(A)|となるケースが多いよう？

    本問ではAが同一の元のみからなるケースのみ考えればよく（maspyさんブログ参照）、
    任意のx¥in Aに対して|{i|ai == x}| + |{i|bi == x}| <= Nが成り立てば答えはYesとなる。

    実際の二部グラフの構成方法は、|{i|ai == x}| + |{i|bi == x}|が大きいxから順にペアを作れば良い。

    ここで実装の注意点として、たくさん出てくる数から優先的に処理しないといけないが、
    ここにheapqを使うと２回ポップして出てきた数同士でペアを作る発想になるものの、
    一方からポップした数がBに存在しない等の場合何度もポップしてBにその数が含まれるかチェックすることになり
    非常に非効率になる。なのでheapqは使ってはいけない。

    なのでここでは
        hist[(出てきた回数)]=(その回数A+Bから出てくる数の集合)
    としてhistはリストで管理しないといけない。

    これむずすぎん？？？必要なデータ構造多すぎて訳わからんくなる。
    """
    num_kinds = defaultdict(int)
    hist = [set() for _ in range(N + 1)]
    for x in A + B: num_kinds[x] += 1
    for x, times in num_kinds.items():
        if times > N:
            print("No")
            return
        hist[times].add(x)
    print("Yes")

    num_to_idx_A = defaultdict(set)
    num_to_idx_B = defaultdict(set)
    num_to_cnt_A = defaultdict(int)
    num_to_cnt_B = defaultdict(int)
    for i, a in enumerate(A):
        num_to_idx_A[a].add(i)
        num_to_cnt_A[a] += 1
    for i, b in enumerate(B):
        num_to_idx_B[b].add(i)
        num_to_cnt_B[b] += 1


    B_new = [0] * N
    for times in range(N, 0, -1):
        nums = list(hist[times])
        l = len(nums)
        x, y = -1, -1
        if l == 2:
            x, y = nums
            for idxA in num_to_idx_A[x]: B_new[idxA] = y
            for idxA in num_to_idx_A[y]: B_new[idxA] = x
            break
        elif l == 1:
            x = nums[0]
            if num_to_idx_A[x]:
                y = -1
                for num in num_to_cnt_B:
                    if num != x:
                        y = num
                        break
            else:
                y = x
                x = -1
                for num in num_to_cnt_A:
                    if num != y:
                        x = num
                        break
        elif l == 0:
            x = -1
            for num in num_to_cnt_A:
                x = num
                break
            y = -1
            for num in num_to_cnt_B:
                if num != x:
                    y = num
                    break

        idxA = num_to_idx_A[x].pop()
        B_new[idxA] = y
        num_to_idx_B[y].pop()

        num_to_cnt_A[x] -= 1
        num_to_cnt_B[y] -= 1
        if num_to_cnt_A[x] == 0: del num_to_cnt_A[x]
        if num_to_cnt_B[y] == 0: del num_to_cnt_B[y]

        hist[num_kinds[x]].discard(x)
        hist[num_kinds[y]].discard(y)
        num_kinds[x] -= 1
        num_kinds[y] -= 1
        hist[num_kinds[x]].add(x)
        hist[num_kinds[y]].add(y)

    print(" ".join(map(str, B_new)))



if __name__ == "__main__":
    main()


Measured memory_bytes: 300220
fun main() {
    val k = nextInt()
    if (k < 10) {
        return println(k)
    }
    val runruns = Array(k + 1) { "" }
    for (i in 0..9) {
        runruns[i] = i.toString()
    }
    var count = 9
    var start = 1
    var end = 9
    while (count < k) {
        var i = 0
        var p = start
        while (p <= end) {
            if (i > runruns[p][0] - '0' + 1 || i > 9) {
                p++
                i = runruns[p][0] - '0' - 1
                if (i < 0) {
                    i = 0
                }
            } else {
                runruns[++count] = "$i${runruns[p]}"
                if (count == k) break
                i++
            }
        }
        start = end + 1
        end = count
    }
    println(runruns[k].reversed())
}

fun rsp() = readLine()!!.split(" ")
fun rspint() = readLine()!!.split(" ").map { it.toInt() }
fun printYN(isYes: Boolean) = println(if (isYes) "Yes" else "No")
val scanner = java.util.Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt(): Int = scanner.nextInt()
fun nextLong(): Long = scanner.nextLong()

fun main(args: Array<String>) = main()

Measured memory_bytes: 40220
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

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

int main()
{
    int x;
    cin >> x;
    int n = gcd(x, 360);
    int y = x / n;
    cout << 360 * y / x << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>

int main(void){
    double w,h,x,y,area;
    int a=0;
    scanf("%lf %lf %lf %lf",&w,&h,&x,&y);
    if(x==w/2&&y==h/2){
        a=1;
    }
    printf("%f %d",(h*w)/2,a);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)


int main() {

	int card[3][3];
	for (int i = 0; i < 3; i++) {
		cin >> card[i][0] >> card[i][1] >> card[i][2];
	}

	int N;
	cin >> N;
	vector<int> nums;
	for (int i = 0; i < N; i++) {
		int num;
		cin >> num;
		nums.push_back(num);
	}

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

	bool checked[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			checked[i][j] = binary_search(nums.begin(), nums.end(), card[i][j]);
		}
	}

	for (int i = 0; i < 3; i++) {
		if (checked[i][0] && checked[i][1] && checked[i][2]) {
			cout << "Yes" << endl;
			return 0;
		}
		if (checked[0][i] && checked[1][i] && checked[2][i]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (checked[0][0] && checked[1][1] && checked[2][2]) {
		cout << "Yes" << endl;
		return 0;
	}
	if (checked[2][0] && checked[1][1] && checked[0][2]) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;

}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def Z_algorithm(s):
        n = len(s)
        z = [0]*n
        z[0] = n
        c = 1
        for i in range(1,n):
            if i+z[i-c] < c+z[c]:
                z[i] = z[i-c]
            else:
                j = max(0,c+z[c]-i)
                while i+j < n and s[j] == s[i+j]:
                    j += 1
                z[i] = j
                c = i
        return z
    s = input()
    t = input()
    z = Z_algorithm(t+s)[len(t):]
    for i in range(len(s)):
        if z[i] >= len(t):
            print(i)
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 55308
#include <bits/stdc++.h>
typedef long long LL;
LL a,b;
LL f(LL a,LL b){return b?a/b*b*2+f(b,a%b):-a;}
int main(){
    scanf("%lld%lld",&a,&b);
    printf("%lld\n",f(a-b,b)+a);
    return 0;
}

Measured memory_bytes: 256
if true then
  fh=STDIN
else
  fh=open("in0106.txt")
end
def price(n, p)
  unitVol=p[0]
  unitCost=p[1]
  discNumber=p[2]
  discRate = p[3]

  return (n / discNumber)*discNumber*unitCost*discRate + (n % discNumber)*unitCost
end

parm = {"A" =>[200,380,5,0.8],"B" =>[300,550,4,0.85],"C" =>[500,850,3,0.88]}

while fh.gets do
  x =$_.chomp.to_i
  break if x==0
  pairs = []
  na= x / parm["A"][0]
  nb= x / parm["B"][0]
  nc= x / parm["C"][0]
  0.upto(nc){|ic|
    0.upto(nb){|ib|
      0.upto(na){|ia|
        y = x - (ia*parm["A"][0] + ib*parm["B"][0] + ic*parm["C"][0])
        break if y < 0
        pairs.push [ia,ib,ic] if y==0
      }
    }
  }
  v = []
  pairs.each{|na,nb,nc|
    v.push(+price(na,parm["A"]).to_i+price(nb,parm["B"]).to_i+price(nc,parm["C"]).to_i)
  }
  puts v.min
end

Measured memory_bytes: 8768
#include<iostream>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int A=0,B=0;
        for(int i=0;i<n;i++){
            int x,y;
            cin>>x>>y;
            if(x>y)A+=x+y;
            else if(x<y)B+=x+y;
            else A+=x,B+=y;
        }
        cout<<A<<" "<<B<<endl;
    }
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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




int main() {

	ll c[4][4];

	repn(i, 3)repn(j, 3) cin >> c[i][j];

	string ans = "Yes";

	repn(i, 2)repn(j, 2) {
		if (c[i + 1][1] - c[i][1] != c[i + 1][j + 1] - c[i][j + 1]) { ans = "No"; }
		if (c[1][i + 1] - c[1][i] != c[j + 1][i + 1] - c[j + 1][i]) { ans = "No"; }
	}
	
	cout << ans;

	system("PAUSE");

	

}


Measured memory_bytes: 504
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
flag = False
for l in range(L,R):
    for r in range(l+1,R+1):
        mod = (l*r) %2019
        if mod < min_num:
            min_num = mod
            if mod == 0:
                flag =True
                break
    if flag:
        break

print(min_num)

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        for (int i = 0; i < S.length(); i++) {
            for (int j = i + 1; j < S.length(); j++) {
                if (S.charAt(i) == S.charAt(j)) {
                    System.out.println("no");
                    return;
                }
            }
        }
        System.out.println("yes");
    }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

vi G[200010];
vi flag(200010,-1);
vi dist(200010,400200);
int main() {
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<int> q;
  q.push(0);
  dist[0] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(auto v:G[u]){
      if(dist[v]>dist[u]+1){
        dist[v] = dist[u]+1;
        q.push(v);
        flag[v] = u;
        //show(flag[v]);
      }
    }
  }
  bool ok = true;
  srep(i,1,n){
    ok&=(flag[i]!=-1);
  }
  if(!ok){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  srep(i,1,n){
    cout<<flag[i]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 13768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a;
  cin>>a;
  if(a == "SUN")
  {
    cout<<7;
  }
  if(a == "SAT")
  {
    cout<<1;
  }
  if(a == "FRI")
  {
    cout<<2;
  }
  if(a == "THU")
  {
    cout<<3;
  }
  if(a == "WED")
  {
    cout<<4;
  }
  if(a == "TUE")
  {
    cout<<5;
  }
  if(a == "MON")
  {
    cout<<6;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String S = sc.nextLine();
    String T = sc.nextLine();
    String ans = "";
    boolean check = true;
    for(int i = 0; i < N; i++){
      String s1 = S.substring(0, N-1-i);
      String s2 = S.substring(N-1-i, N);
      String t1 = T.substring(0, i+1);
      String t2 = T.substring(i+1, N);
      if(s2.equals(t1)){
        ans = S+t2;
        check = false;
      }
    }
    if(check){
      ans = S+T;
    }
    
    System.out.println(ans.length());
  }
}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n,k,i,j;
    cin>>n>>k;
    map<ll,ll> mp;
    while(k--)
    {
        ll d;
        cin>>d;
        ll a;
        for(i=0;i<d;i++) cin>>a,mp[a]++;
    }
    cout<<n-sz(mp);
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll N; cin >> N;
    ll S1, S2;
    vector<int> W(N);
    ll abmi = 100;
    for (int i = 0; i < N; i++) cin >> W[i];
    for (int T = 0; T < N; T++){
        S1 = 0, S2 = 0;
        for (int i = 0; i < T + 1; i++) S1 += W[i];
        for (int i = T + 1; i < N; i++) S2 += W[i];
        abmi = min(abs(S1 - S2), abmi);
    }
    cout << abmi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
long long int F, H, I, J, K, L, M, N, S, T;

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

	string s;
	cin >> s;

	if (s.length() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < s.length(); i += 2) {
		if (s[i] != 'h' || s[i + 1] != 'i') {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

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

if N <=1 and M<=1:
    print (0)
elif N>=2 and M<=1:
    print (N*(N-1)//2)
elif N<=1 and M>=2:
    print (M*(M-1)//2)
else:
    print ((N*(N-1)//2)+(M*(M-1)//2))

Measured memory_bytes: 3060
fun main(args: Array<String>) {

    class Sieve(n: Int) {
        val f = IntArray(n + 1)
        val primes = mutableListOf<Int>()

        init {
            f[0] = -1
            f[1] = -1
            for (i in 2..n) {
                if (f[i] > 0) continue;
                primes.add(i)
                f[i] = i
                if (i.toLong() * i.toLong() > n) continue
                for (j in i * i..n step i) {
                    if (f[j] == 0) f[j] = i
                }
            }
        }

        fun factor(x: Int): MutableMap<Int, Int> {
            val r = mutableMapOf<Int, Int>()
            var x1 = x
            while (x1 != 1) {
                r[f[x1]] = r.getOrElse(f[x1]) { 0 } + 1
                x1 /= f[x1]
            }
            return r
        }
    }

    val mod = 1e9.toLong() + 7

    fun pow(base: Long, exp: Long): Long {
        if (exp == 0L) return 1L
        var a = pow(base, exp shr 1)
        a *= a
        a %= mod
        if (exp and 1L == 0L) return a
        return base * a % mod
    }

    fun inv(x: Long): Long {
        return pow(x, mod - 2)
    }

    val s = Sieve(1e6.toInt())

    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }

    val map = mutableMapOf<Int, Int>()
    for (i in 0 until n) {
        val fs = s.factor(a[i])
        for ((f, c) in fs) {
            map[f] = Math.max(c, map.getOrElse(f) { 0 })
        }
    }

    var lcm = 1L
    for ((f, c) in map) {
        repeat(c) {
            lcm *= f
            lcm %= mod
        }
    }

    println(a.map { lcm * inv(it.toLong()) % mod }.reduce { acc, l -> (acc + l) % mod })
}


Measured memory_bytes: 49664
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
//const int mod = 1000000007;
const int mod = 998244353;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

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

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

  vi freq(n);
  rep(i,n) {
    int d;
    cin >> d;
    if (i == 0 && d != 0) {
      cout << 0 << endl;
      return 0; 
    }
    if (i != 0 && d == 0) {
      cout << 0 << endl;
      return 0; 
    }
    freq[d]++;
  }

  mint ans = mint(1);
  rep(i,n-1) {
    ans *= mint(freq[i]).pow(freq[i+1]);
  }
  cout << ans.x << endl;
  return 0;
}

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

void add_sugar(int dp[], int c, int e, int f) {
    for (int i = c; i <= f; i++) {
        if (dp[i - c] < 0)
            continue;
        int m = dp[i - c] + c;
        if (100 * m - 1 <= e * (i - m))
            dp[i] = m;
    }
}

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;
    int dp[f + 1];
    fill(dp, dp + f + 1, -1);
    for (int i = 0; i <= f; i += a) {
        dp[i] = 0;
    }
    for (int i = b; i <= f; i += 100) {
        if (dp[i - b] >= 0)
            dp[i] = 0;
    }
    add_sugar(dp, c, e, f);
    add_sugar(dp, d, e, f);
    int total = a, sugar = 0;
    for (int i = 1; i <= f; i++) {
        if (dp[i] < 0)
            continue;
        if (dp[i] * total > sugar * i) {
            total = i;
            sugar = dp[i];
        }
    }
    cout << total << ' ' << sugar << endl;
    return 0;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T, class Q> lint gcde(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    lint sum = 0;
    rep(i, N) {
        rep(j, N) {
            rep(k, N) {
                sum += gcde((i + 1), gcde((j + 1), (k + 1)));
            }
        }
    }

    cou(sum);

}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine().replace("\n", "");
        sc.close();

        int total = 0;
        for (int i = 0; i < num.length(); i++) {
            total += Character.getNumericValue(num.charAt(i));
        }

        if (Integer.parseInt(num) % total == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long int gcd(long long int x, long long int y){
long long int r;
if(x < y) swap (x, y); 
while(y > 0){
r = x % y; 
x = y; 
y = r;
}
return x; 
}
int main() {
int T; 
long long int A, B, C, D; 
cin >> T; 
for (int i = 0; i < T; i++){
cin >> A >> B >> C >> D;
long long int E = A - (A - C + B - 1)/ B * B; 
if(A < B || E < 0) cout << "No" << endl; 
else if(C < B - gcd(B, D) || B > D) 
cout << "No" << endl; 
else cout << "Yes" << endl; 
}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int a, b, q;
    vector<ll> s;
    vector<ll> t;
    ll x;
    cin >> a >> b >> q;
    ll p;
    for(int i = 0; i < a; i++){
        cin >> p;
        s.push_back(p);
    }
    for(int i = 0; i < b; i++){
        cin >> p;
        t.push_back(p);
    }
    ll c1, c2, c3, c4;
    for(int i = 0; i < q; i++){
        cin >> x;
        auto it1 = lower_bound(s.begin(), s.end(), x);
        auto it2 = lower_bound(t.begin(), t.end(), x);
        if(it1-s.begin()==0 && it2-t.begin()==0){
            cout << min(abs(x-s[0])+abs(s[0]-t[0]), abs(x-t[0])+abs(t[0]-s[0])) << endl;
        }
        if(it1-s.begin()==0 && it2-t.begin()!=0){
            c1 = min(abs(x-s[0])+abs(s[0]-t[it2-t.begin()]), abs(x-t[it2-t.begin()])+abs(t[it2-t.begin()]-s[0]));
            c2 = min(abs(x-s[0])+abs(s[0]-t[it2-t.begin()-1]), abs(x-t[it2-t.begin()-1])+abs(t[it2-t.begin()-1]-s[0]));
            cout << min(c1, c2) << endl;
        }
        if(it1-s.begin()!=0 && it2-t.begin()==0){
            c1 = min(abs(x-t[0])+abs(t[0]-s[it1-s.begin()]), abs(x-s[it1-s.begin()])+abs(s[it1-s.begin()]-t[0]));
            c2 = min(abs(x-t[0])+abs(t[0]-s[it1-s.begin()-1]), abs(x-s[it1-s.begin()-1])+abs(s[it1-s.begin()-1]-t[0]));
            cout << min(c1, c2) << endl;
        }
        if(it1-s.begin()!=0 && it2-t.begin()!=0){
            c1 = min(abs(x-s[it1-s.begin()])+abs(s[it1-s.begin()]-t[it2-t.begin()]), abs(x-t[it2-t.begin()])+abs(t[it2-t.begin()]-s[it1-s.begin()]));
            c2 = min(abs(x-s[it1-s.begin()])+abs(s[it1-s.begin()]-t[it2-t.begin()-1]), abs(x-t[it2-t.begin()-1])+abs(t[it2-t.begin()-1]-s[it1-s.begin()]));
            c3 = min(abs(x-s[it1-s.begin()-1])+abs(s[it1-s.begin()-1]-t[it2-t.begin()]), abs(x-t[it2-t.begin()])+abs(t[it2-t.begin()]-s[it1-s.begin()-1]));
            c4 = min(abs(x-s[it1-s.begin()-1])+abs(s[it1-s.begin()-1]-t[it2-t.begin()-1]), abs(x-t[it2-t.begin()-1])+abs(t[it2-t.begin()-1]-s[it1-s.begin()-1]));
            cout << min({c1,c2,c3,c4}) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
#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>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
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 Per(i,sta,n) for(int i=n-1;i>=sta;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-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int h,w;
vector<string> S;

ll calc(string s,string t){
    ll dp[700][700];
    int c[700][700];
    rep(k,2*h-1){
        if (h-k-1<0 || h-k-1>=h) c[k][0]=0;
        else if (s[0]==t[h-k-1]) c[k][0]=1;
        else c[k][0]=0;
        //cout << k << " " << 0 << " " << c[k][0] << endl;
        Rep(i,1,k+1){
            if (i+h-k-1<0 || i+h-k-1>=h) c[k][i]=c[k][i-1];
            else if (s[i]==t[i+h-k-1]) c[k][i]=c[k][i-1]+1;
            else c[k][i]=c[k][i-1];
            //cout << k << " " << i << " " << c[k][i] << endl;
        }
    }
    rep(i,2*h+1){
        rep(k,h+1){
            dp[i][k]=INF;
        }
    }
    dp[0][0]=0;
    rep(i,2*h){
        Rep(k,max(0,i-h),min(i+1,h+1)){
            if (k<h){
                dp[i+1][k+1]=min(dp[i+1][k+1],dp[i][k]+c[h-1-2*k+i][h-k-1]);
            }
            if (i-k<h){
                dp[i+1][k]=min(dp[i+1][k],dp[i][k]+c[h-1-2*k+i][h-k-1]);
            }
            //cout << i << " " << k << " " << dp[i][k] << endl;
        }
    }
    return dp[2*h][h];
}

void solve(){
    cin >> h >> w;
    S.resize(w,"");
    rep(i,h){
        string a;
        cin >> a;
        rep(j,w) S[j]+=a[j];
    }
    ll ans=0;
    rep(i,w-1){
        ll t=calc(S[i],S[i+1]);
        //cout << S[i] << " " << S[i+1] << " " << t << endl;
        ans+=t;
    }
    cout << ans << endl;

}

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

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'

#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

#ifndef __LOCAL
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout); FAST;
#else
#define FILES(namein, nameout) FAST;
#endif //__LOCAL

using namespace std;
using namespace __gnu_pbds;
using python = void;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned short uss;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type> ordered_set;

const ll M = 1e9+7;
const ll N = 1e5+228;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
ll a[N][3], dp[N][3];
python solve(){
	FAST;
	ll n;
	cin >> n;
	for(ll i =1;i<=n;i++){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
		for(ll ch = 0;ch<3;ch++){
			ll ee = 0;
			for(ll kk = 0;kk<3;kk++) if(kk != ch) ee = max(ee, dp[i-1][kk]);
			dp[i][ch] = ee+a[i][ch];
		}
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

signed main(){
	FAST;
	ll q = 1;
	//cin >> q;
	while(q--){
		solve();
	}
}

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

int main(){
	int n,sum=0,p,num;
	cin>>n;
	num=n;
	
	while(num!=0){
		p=num%10;
		num/=10;
		sum+=p;
	}
	
	if(n%sum==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M=input().split(" ")

N=int(N)
M=int(M)

Ps=[]
Ss=[]

for i in range(M):
    p,s=input().split(" ")
    Ps.append(int(p))
    Ss.append(s)

#間違えたら-=1 ,正解したら=1 
cleared=[0]*(N+1)

AC_n=0
WA_n=0

for i in range(M):

    if Ss[i]=="WA":
        if not cleared[Ps[i]]==1:
            cleared[Ps[i]]-=1

    if Ss[i]=="AC":
        if cleared[Ps[i]]<=0:
            AC_n+=1
            WA_n-=cleared[Ps[i]]
            cleared[Ps[i]]=1

print(AC_n,WA_n)

Measured memory_bytes: 14188
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d, ans[2];
	for (int i = 0; i < 2; i++)
	{
		cin >> a >> b >> c >> d;
		ans[i] = a + b + c + d;
	}
	if (ans[0] > ans[1])
	{
		cout << ans[0] << endl;
	}
	if (ans[0] < ans[1])
	{
		cout << ans[1] << endl;
	}
	if (ans[0] == ans[1])
	{
		cout << ans[0] << endl;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, a, b, tc;
    string s;
    ;
    LL x, y;
    cin >> x >> y;
    if (y & 1)
    {
        cout << "No\n";
    }
    else
    {
        y /= 2;
        LL a = 2 * x - y;
        LL b = x - a;
        if (a >= 0 && b >= 0)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 3636
import java.io.*;
 
class Main {
    public static void main(String[] args) throws java.io.IOException {
 
        BufferedReader input = new BufferedReader(new InputStreamReader(
                System.in));
        StringBuilder str = new StringBuilder();
 
        int i = 0;
 
        while (true) {
            i++;
            String tmp = input.readLine();
            int x = Integer.parseInt(tmp);
 
            if (x == 0)
                break;
 
            str.append("Case " + i + ": " + x + "\n");
 
        }
 
        System.out.print(str);
 
    }
}

Measured memory_bytes: 31984
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (c <= a + b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



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

void input(int& rnLeft, int& rnRigt)
{
  cin >> rnLeft >> rnRigt;
}
  
int calcMinRemain2019(int nLeft, int nRigt)
{
  if (nLeft + 2018 <= nRigt) return 0;         // nLeft～nRigtまでの数に
                                               // 2019 で割り切れる数が存在
  int nMinRem2019 = 2018;

  for (int i = nLeft; i < nRigt; i++)
    for (int j = i + 1; j < nRigt + 1; j++)
    {
      int nRem2019 = (llong)i * j % 2019;
      nMinRem2019 = min(nMinRem2019, nRem2019);
    }

  return nMinRem2019;
}
  
int main()
{
  int nLeft, nRigt;
  input(nLeft, nRigt);
  cout << calcMinRemain2019(nLeft, nRigt) << endl;

  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int N;
string S, T;

void _main() {
    cin >> N >> S >> T;
    REP (i, N) {
        cout << S[i] << T[i];
    }
    cout << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){

  int n;
  cin >> n;

  int fib[50];
  fib[0]=1,fib[1]=1;

  for(int i=2;i<50;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }

  cout << fib[n] << endl;


}


Measured memory_bytes: 3100
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-8
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef complex<double>cp;
template<class T>inline void rread(T&num){
    num=0;T f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
    num*=f;
}
const ll inf = 1e18;
const int maxn = 2e5+10, mod = 1e9 + 7;
const int mod1 = 1e8+7,mod2 = 41;
const double pi = acos(-1);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
cp power(cp a, int n)
{cp p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
unsigned long long power(unsigned long long a, unsigned long long n)
{unsigned long long p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m;
int a[32000];
int main()
{
    int kase=1;
    //freopen("data2.out","r",stdin);
    //freopen("ans2.out","w",stdout);

   char s[100];
   while(cin>>n)
   {
       for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
       sort(a+1,a+1+n);
       a[0] = -1;
       int ans =0;
       for(int i=1;i<=n;i++)
        if(a[i]!=a[i-1])
        ans++;
       cout<<ans<<endl;
   }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define maxn 10005
#define LL long long
#define INF 0x3f3f3f3f
#define mset(p,v) memset(p,v,sizeof(p))
using namespace std;
string s;
int main()
{
    while(cin>>s)
    {
        if(s[2]==s[3]&&s[4]==s[5])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    int max_dist = 0;
    rep(i,n) {
        if (i == n-1) {
            max_dist = max(max_dist, ((k-a[i]) + a[0]));
            continue;
        }
        max_dist = max(max_dist, a[i+1] - a[i]);
    }
    cout << (k-max_dist) << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int a=0, z=0;
    int n=s.size();
    
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A'){
            a=i+1;
            break;
        }
    }
    
    reverse(s.begin(), s.end());

    for(int i=0; i<s.size(); i++){
        if(s[i] == 'Z'){
            z=n-i+1;
            break;
        }
    }
    cout << z - a << endl;
}

Measured memory_bytes: 640
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    string s,t;
    cin>>s>>t;

    t.pob();

    if(s==t)
        cout<<"Yes";
    else
        cout<<"No";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<string> a(n),b(m);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  int cnt=0;
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      int ans=0;
      for(int k=0;k<m;k++){
        for(int l=0;l<m;l++){
          if(a[i+k][j+l]!=b[k][l])ans++;
        }
      }
      if(ans==0)cnt++;
    }
  }
  if(cnt==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#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) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    if (n > 0) {
        return  n * fac(n - 1);
    }else{
        return 1;
    }
}

int main()
{
    ll n,m,p,y,cnt = 1;
    string s;
    cin >> n >> m;
    vector<pair<pair<ll, ll>, pair<ll, string>>> P(m);
    vector<string> ans(m);
    rep(i, m){
        cin >> p >> y;
        s = "00000";
        s += to_string(p);
        if (s.size() > 6) {
            s.erase(s.begin(), s.begin() + (s.size() - 6));
        }
        P[i] = make_pair(make_pair(p, y), make_pair(i + 1, s));
    }
    sort(P.begin(), P.end());
    rep(i, m){
        if (i != 0) {
            if (P[i].first.first == P[i - 1].first.first) {
                ++cnt;
            }else{
                cnt = 1;
            }
        }
        s = "00000";
        s += to_string(cnt);
        if (s.size() > 6) {
            s.erase(s.begin(), s.begin() + (s.size() - 6));
        }
        P[i].second.second += s;
        ans[P[i].second.first - 1] = P[i].second.second;
    }
    rep(i, m){
        cout << ans[i] << endl;
    }
    return 0;
}


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

inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

char s[2000007];

int main() {
  scanf("%s", s);
  int sum = 0;
  int ptr = 0;
  while (isdigit(s[ptr])) {
    sum += (s[ptr] ^ 48);
    ++ptr;
  }
  if (sum % 9 == 0) printf("Yes");
  else printf("No");
  return 0;
}


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

int main() {
   string S; cin >> S;
   if(S == "zyxwvutsrqponmlkjihgfedcba") {
      cout << -1 << endl;
   } else {
      if(S.size() < 26) {
         char c = 'a';
         while(find(S.begin(), S.end(), c) != S.end()) c++;
         S += c;
      } else {
         int i = 25;
         while(i > 0 && S[i-1] > S[i]) i--;
         i--; int j = 25;
         while(S[i] > S[j]) j--;
         swap(S[i], S[j]);
         S = S.substr(0, i+1);
      }
      cout << S << endl;
   }
}


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

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    char old_s=s[0];
    int flip=0;
    int ans=-1;
    rep(i,s.size()){
        if(s[i]!=old_s) flip++;
	else ans++;
        old_s = s[i];
    }
    
    cout << ans+min(2*k,flip) << endl;

}


Measured memory_bytes: 512
n = int(input())

data = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for _ in range(n):
    b, f, r, v = list(map(int, input().split()))
    data[b-1][f-1][r-1] += v

for b, build in enumerate(data):
    for floor in build:
        for i, man in enumerate(floor):
            if i == 9:
                print(" {}".format(man))
            else:
                print(" {}".format(man), end="")
    if b != 3:
        print("####################")



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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int inf = (int)1e9 + 5;
const int mod = (int)1e9 + 7;
const ll INF = (ll)4e18;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);
	int x, y;
	cin >> x >> y;
	int ans = 0;
	if(y == 0) {
		ans += abs(x);
		if(x > 0) ans++;
	}
	else if(x == 0) {
		ans += abs(y);
		if(y < 0) ans++;
	}
	else {
		if(x > 0 && y > 0) {
			if(x <= y) 
				ans += y - x;
			else 
				ans += x - y + 2;
		}
		else if(x < 0 && y > 0) {
			ans += abs(abs(x) - abs(y)) + 1;
		}
		else if(x > 0 && y < 0) {
			ans += abs(abs(x) - abs(y)) + 1;
		}
		else if(x < 0 && y < 0) {
			if(x > y) 
				ans += x - y + 2;
			else
				ans += y - x;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384