akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

const ll mod = 1e9 + 7;

int main() {
  ll N;
  cin >> N;
  ll Nmax = 1e6;

  vector<vector<ll> > to(N);
  vector<ll> par_edg_col(N, -1);
  vector<P> eds;
  unordered_map<ll, ll> col_map;

  for (ll i = 0; i < N - 1; i++) {
    ll s, t;
    cin >> s >> t;
    s--;
    t--;
    to[s].push_back(t);
    to[t].push_back(s);
    ll ss = max(s, t);
    ll tt = min(s, t);
    eds.push_back(P(ss, tt));
  }

  queue<ll> que;
  que.push(0);
  par_edg_col[0] = 0;

  ll maxcol = 0;
  while (!que.empty()) {
    ll v = que.front();
    que.pop();
    ll exc_col = par_edg_col[v];
    ll tmp_col = 0;
    for (auto u : to[v]) {
      if (par_edg_col[u] == -1) {
        que.push(u);
        tmp_col++;        
        if (tmp_col == exc_col) tmp_col++;
        par_edg_col[u] = tmp_col;
        ll uu = max(u, v);
        ll vv = min(u, v);
        col_map[uu * Nmax + vv] = tmp_col;
        
      }
    }  // u
    maxcol = max(maxcol, tmp_col);
  }

  cout << maxcol << endl;
  for (size_t i = 0; i < eds.size(); i++) {
    ll u = eds[i].first;
    ll v = eds[i].second;
    cout << col_map[u*Nmax + v] << endl;
  }

  return 0;
}


Measured memory_bytes: 13040
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

K = int(input())

# 末端桁がjの時のやつ
dp = [[] for i in range(10)]
answer = []
for j in range(1, 10):
    dp[0].append(j)
    answer.append(j)

cnt = 10
for i in range(1, 100):
    for d in dp[i - 1]:
        dd = d % 10
        for j in range(10):
            if j == dd - 1 or j == dd or j == dd + 1:
                dp[i].append(d * 10 + j)
                answer.append(d * 10 + j)
    if len(answer) > 10 ** 5:
        break
answer.sort()
print(answer[K - 1])
    

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

using namespace std;

int main() {
	
  int n; cin >> n;
  
  int x = 0;
  int y = 0;
  int t = 0;
  int td = 0;
  int dd = 0;
  string ans = "Yes";
  for(int i=0; i<n; i++){
    
    int tn; cin >> tn;
    int xn, yn; cin >> xn >> yn;
    
    td = tn - t;
    dd = abs(yn - y) + abs(xn - x);
    
    if (dd > td || (td-dd)%2==1) ans = "No";
    
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	
	cout << max(0, min(b,d)-max(a,c)) << endl;
	
	return 0;
}

Measured memory_bytes: 3528
s = input()
q = int(input())
top = ""
end = ""
count = 0
for i in range(q):
    a = input()
    if len(a) == 1:
        count += 1
    else:
        a = list(a.split())
        if (count + int(a[1])) % 2 == 0:
            end = end + a[2]
        else:
            top = a[2] + top
ans = top + s + end
if count % 2 == 1:
    ans = ans[::-1]
print(ans)

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if((A+B)>(C+D)){
    cout << "Left" << endl;
  }else if((A+B)<(C+D)){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
int find(int a){
     if(par[a]==a)return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);if(a==b)return ;
     parent[b]=a;
}*/
 
 
 
 
 
 
 

int dp[105][105];
int main()
{
     int n,m;
     cin>>n>>m;
     for(int i=0;i<=n;i++){
          for(int j=0;j<=n;j++)if(i==j)dp[i][j]=0;
          else dp[i][j]=1e9;
     }
     int a[1005],b[1005],c[1005];
     for(int i=0;i<m;i++){
          cin>>a[i]>>b[i]>>c[i];
          dp[a[i]][b[i]]=c[i];
          dp[b[i]][a[i]]=c[i];
     }
     for(int k=1;k<=n;k++){
          for(int i=1;i<=n;i++){
               for(int j=1;j<=n;j++){
                    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
               }
          }
     }
     int ans=m;
     for(int i=0;i<m;i++){
          bool shpath=false;
          for(int j=1;j<=n;j++){
               if(dp[j][a[i]]+c[i]==dp[j][b[i]])shpath=true;
          }
          if(shpath)ans-=1;
     }
     cout<<ans; 
}
























Measured memory_bytes: 3632
from math import floor, ceil
a, b = map(int, input().split())
x = max(ceil(a / 0.08), ceil(b / 0.1))
ans = -1
for y in range(x, 2000, 1):
    if a == floor(y * 0.08) and b == floor(y * 0.1):
        ans = y
        break
    elif a != floor(y * 0.08) and b != floor(y * 0.1):
        ans = -1
print(ans)


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

int main(){
	int n;
	cin>>n;
	n=n%10;
	if(n==2||n==4||n==5||n==7||n==9) cout<<"hon";
	else if(n==0||n==1||n==6||n==8) cout<<"pon";
	else cout<<"bon";
	return 0;
} 

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

int A, B, C, D;

int main(){
    cin >> A >> B >> C >> D;
    while(A >= 0 && C >= 0){
        C = C - B;
        if(C <= 0){
             cout << "Yes" << endl;
             break;
        }
        A = A - D;
        if(A <= 0){
             cout << "No" << endl;
             break;
        }
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 2e5 + 5;
const int mm = 2100;
const int mod = 11380;
#define P mod

int main() {
	//cin.sync_with_stdio(0);
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
#endif
	int a,b,c;
	cin>>a>>b>>c;
	if (a==b&&b==c) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
import sys
from math import floor, sqrt

def main():
    n = int(sys.stdin.readline().rstrip())
    m = floor(sqrt(2 * n))
    if m * (m + 1) // 2 < n:
        m += 1
    M = m + 1

    needless = M * (M - 1) // 2 - n

    res = sorted(set(range(1, m + 1)) - set([needless]))
    print(*res, sep='\n')

if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int ansOdd = 0, ansEven = 0;
  for (int i = 0; i < (int)S.size(); ++i) {
    if (i % 2 == 0){
      if (S[i] == '0') {
	ansEven++;
      } else {
	ansOdd++;
      }
    }
    if (i % 2 != 0) {
      if (S[i] == '0') {
	ansOdd++;
      } else {
	ansEven++;
      }
    }
  }
  cout << min(ansOdd, ansEven) << endl;
  return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,r;
    cin>>x>>y;
    if(x>y)
        r=x;
    else if(y>x)
        r=y;
    else
        r=0;
    if(r!=0)
        cout<<r+r-1<<endl;
    else
        cout<<2*x<<endl;
}



Measured memory_bytes: 3564
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    XY = [[] for _ in range(N)]
    for n in range(N):
        A = ii()
        xy = [[] for _ in range(A)]
        for a in range(A):
            xy[a] = il()
        XY[n] = xy

    ret = 0
    for b in range(1 << N):
        tf = [0] * N
        for i in range(N):
            if b >> i & 1:
                tf[i] = 1

        flg = True
        for j in range(N):
            if tf[j] == 0:
                continue
            for x, y in XY[j]:
                if tf[x - 1] != y:
                    flg = False

        if flg:
            ret = max(ret, sum(tf))
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3932
#49 C - Make a Rectangle
import collections 
N = int(input())
A = map(int,input().split())

cnt = collections.Counter(A)
# 2 個以上含まれる数字をリストアップ
cnt_2 = [i for i , j in cnt.items() if j>=2]
# 4 個以上含まれる数字をリストアップ
cnt_4 = [i for i, j in cnt.items() if j>=4]
# 降順にソート
cnt_2 = sorted(cnt_2,reverse = True)
cnt_4 = sorted(cnt_4,reverse = True)

ans1 = 0
ans2 = 0 
if len(cnt_2) >=2:
    ans1 = cnt_2[0]*cnt_2[1]
if len(cnt_4) >=1:
    ans2 = cnt_4[0]**2
    
print(max(ans1,ans2))

Measured memory_bytes: 28184
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int X = nextInt();
        int A = nextInt();

        println(X < A ? 0 : 10);
    }

    //最小公倍数lcm
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main ( )
{

    int d,s,t;
    cin>>d>>s>>t  ;    
    
    
   if   ( s*t>=d)
           
cout<<"Yes"<<endl ; 
else
cout<<"No"<<endl ; 

    

    return 0 ;
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  string s, t;
  cin>>s>>t;
  int n=s.size();
  int ans=0;
  REP(i, n){
    if(s[i]!=t[i]){
      ++ans;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

int main() {
    lint L;
    int N;
    std::cin >> L >> N;

    std::vector<lint> A(N);
    for (auto& a : A) std::cin >> a;

    std::vector<lint> presum(N + 1, 0);
    for (int i = 0; i < N; ++i) presum[i + 1] = presum[i] + A[i];

    // Aを左右反転させたもの
    auto B = A;
    std::reverse(B.begin(), B.end());
    for (auto& b : B) b = L - b;

    std::vector<lint> sufsum(N + 1, 0);
    for (int i = 0; i < N; ++i) sufsum[i + 1] = sufsum[i] + B[i];

    lint ans = 0;

    // 右に移動して終わるケース
    for (int r = 1; r <= N; ++r) {
        // r個の区間に右から入る
        int l = N - r;
        int step = std::min(l, r);  // 「階段」の段数

        lint left = (sufsum[l] - sufsum[l - step]) * 2;
        lint right = (presum[r] - presum[r - step]) * 2 - A[r - 1];
        if (r > l) right += (presum[r - step] - presum[r - step - 1]) * 2;
        // 右側の階段が1段増える

        ans = std::max(ans, left + right);
    }

    // 左から終わるケース
    // さっきのを全体を左右反転させてやるだけ
    for (int r = 1; r <= N; ++r) {
        int l = N - r;
        int step = std::min(l, r);

        lint left = (presum[l] - presum[l - step]) * 2;
        lint right = (sufsum[r] - sufsum[r - step]) * 2 - B[r - 1];
        if (r > l) right += (sufsum[r - step] - sufsum[r - step - 1]) * 2;

        ans = std::max(ans, left + right);
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main()
{
    int n , x , a[200005]={} ;

    cin>>n;

    for(int i=1;i<=n-1;i++){
        cin>>x;
        a[x]++;
    }

    for(int i=1;i<=n;i++) cout<<a[i]<<endl;





        return 0;
}


Measured memory_bytes: 4376
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

lint Pattern(lint top,lint bottom,lint n){
  lint result=0;
  for(lint digit=2;digit<=6;digit++){
    lint limit=std::pow(10,digit-2);
    for(lint center=0;center<=limit-1;center++){
      lint v=bottom+center*10+top*limit*10;
      if(v<=n) result++;
    }
  }
  return result;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint n;
  cin>>n;

  if(n<=9){
    cout<<n<<endl;
    return 0;
  }

  lint result=9;
  for(lint x=1;x<=9;x++){
    for(lint y=1;y<=9;y++){
      lint res_a=Pattern(x,y,n);
      lint res_b=Pattern(y,x,n);

      result+=res_a*res_b;

    }
  }
  for(lint x=1;x<=9;x++){
    lint res=Pattern(x,x,n);
    result+=res*2;
  }
  cout<<result<<endl;

  return 0;
}




Measured memory_bytes: 256
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

import scala.annotation.tailrec

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, k) = input.nextLine().split(" ").map(_.toInt)
      val xs = input.nextLine().split(" ").map(_.toInt)

      output.println(0.to(n - k).map { i =>
        val l = xs(i)
        val r = xs(i + k - 1)
        // output.println(l, r)
        (Math.abs(l) + Math.abs(r - l)).min(Math.abs(r) + Math.abs(r -  l))
      }.min)
    }


    @tailrec
    final def gcd(m: Int, n: Int): Int = {
      val (x, y) = if (m > n) (m, n) else (n, m)
      if (y != 0) gcd(y, x % y)
      else x
    }

  }

}


Measured memory_bytes: 46832
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int gc=0;
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp;
        temp=max(temp-x,x-temp);
        gc=__gcd(gc,temp);
    }
    printf("%d\n",gc);
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	count := 0
	for i := 1; i <= N; i++ {
		if N%i == 0 {
			count += N/i - 1
		} else {
			count += N / i
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1788
while True:
    n, q = map(int, raw_input().split())

    if n == 0:
        break

    m = {}

    for _ in range(n):
        d = map(int, raw_input().split())
        for i in range(1, len(d)):
            if d[i] in m:
                m[d[i]] += 1
            else:
                m[d[i]] = 1

    maxk = 0
    maxv = 0
    for k, v in m.items():
        if v >= q and maxv < v:
            maxk = k
            maxv = v

    print maxk

Measured memory_bytes: 6280
#include<stdio.h> 
#include<stdlib.h> 
  #include<bits/stdc++.h>
#define N 100005
#define K 200005
#define MOD 998244353
#define ll long long int
using namespace std;
 

int main() 
{ 
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    vector<int> dp(n,1000000005);
   dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        dp[j]=min(dp[i]+abs(h[j]-h[i]),dp[j]);
    }
    cout<<dp[n-1]<<endl;
    return 0; 
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
const int MAX_V=100000;
struct edge{int to,cost;};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
void bfs01(int s){
    deque<P> que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push_back(P(0,s));
    while(!que.empty()){
        P p=que.front();que.pop_front();
        int v=p.se;
        if(d[v]<p.fi)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;
                if(e.cost==0)que.push_front(P(d[e.to],e.to));
                else que.push_back(P(d[e.to],e.to));
            }
        }
    }
}
int main(){
    cin>>V;
    REP(i,V){
        edge t;
        t.to=(i+1)%V;
        t.cost=1;
        G[i].pb(t);
    }
    REP(i,V){
        edge t;
        t.to=(i*10)%V;
        t.cost=0;
        G[i].pb(t);
    }
    bfs01(1);
    cout<<d[0]+1<<endl;
    return 0;
}

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

int n, m, ans;

int main() {
  cin >> n >> m;
  ans = 0;
  ans += n * (n - 1) / 2;
  ans += m * (m - 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string st;
int ans;
bool flag = true;
int main(){
    cin >> st;
    int L=0,R = st.size() - 1;
    while ( L <= R ){
        if ( st[L] == st[R] ) {L++,R--;continue;}
        if ( st[L] == 'x' ) {L++,ans++;continue;}
        if ( st[R] == 'x' ) {R--,ans++;continue;}
        flag = false; break;
    }
    ans = flag ? ans : -1;  
    cout << ans ;
    return 0;
}

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

int main(){
	int n,k; cin>>n>>k;
	long double ans=0;
	for(int i=1;i<=n;++i){
		long double a=1.0l/n;
		for(int j=i;j<k;j*=2){
			a*=0.5l;
		}
		ans+=a;
	}
	cout<<fixed<<setprecision(12)<<ans<<"\n"s;
}


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

int main(){
  string s;
  map<char,bool> vip;
  vip['A']=true;
  vip['B']=false;
  vip['C']=false;
  while(cin >> s){
    bool h = vip[s[0]];
    vip[s[0]] = vip[s[2]];
    vip[s[2]] = h;
  }
  if(vip['A'])cout << "A" << endl;
  else if(vip['B'])cout << "B" << endl;
  else cout << "C" << endl;

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
//const inf=1e9;
int main()
{
  int n;
  cin>>n;
  int x[3];
  int dp[3]={0,0,0};
  int dp1[3];
  int i=0;
  while(i<n)
  {
    cin>>x[0]>>x[1]>>x[2];
    dp1[0]=x[0]+max(dp[1],dp[2]);
    dp1[1]=x[1]+max(dp[0],dp[2]);
    dp1[2]=x[2]+max(dp[0],dp[1]);
    dp[0]=dp1[0];
    dp[1]=dp1[1];
    dp[2]=dp1[2];
    i++;
  }
  cout<<max(dp[0],max(dp[1],dp[2]));
  return 0;
}

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

#define int long long 
#define pb push_back
#define sz size()
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define pii pair<int,int>
#define bg being()
#define ed end()
#define pf(x) cout << x << endl;
#define for0(n) for(int i=0;i<n;i++)
#define ln length()
#define disp(x) for(auto y:x)cout << y << ' ';cout << endl;


int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
	
    int n,x,t;
    cin >> n >> x >> t;
    
    int mul = ceil(n/(double)x);
    cout << t*mul << endl;
	
	return 0;
} 

Measured memory_bytes: 3756
#include <iostream>

using namespace std;

int main(void){
    int a,b,c,s;
    while(cin >> a >> b){
        s = a + b;
        for(c=0;c < 7;c ++){
            if(s > 0){
                s = s/10;
            }else{
                break;
            }
        }
        cout << c << endl;
    }
}



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

int main(void) {
  int N;
  int A[21];
  int B[21];
  int C[21];
  cin >> N;
  for(int i = 1; i <= N; i++) {
    cin >> A[i]; 
  }
  for(int i = 1; i <= N; i++) {
    cin >> B[i]; 
  }
  for(int i = 1; i <= N-1; i++) {
    cin >> C[i]; 
  }
  int good = 0;
  
  for(int i = 1; i <= N; i++) {
    good += B[A[i]]; 
  }
  for(int i = 1; i <= N-1; i++) {
    if(A[i]+1 == A[i+1]) {
      good += C[A[i]];
    }
  }
  cout << good;
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/


signed main(){
	int n;
	cin>>n;
	vi r(n);
	rep(i,n) cin>>r[i];

	int ans=-INF;


	int m=r[0];
	FOR(i,1,n-1){
		chmax(ans,r[i]-m);
		if(m>r[i]) m=r[i];
	}
	cout<<ans<<endl;



	return 0;
}




Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s; cin>>s;
    int n = sz(s);
    int p=2019;
    int arr[p+1];
    memset(arr, 0, sizeof(arr));
    arr[0]=1;
    int mult = 1;
    int cur = 0;
    int ans = 0;
    for(int i=n-1; i>=0; i--){
        int a = s[i]-'0';
        a *= mult;
        a %= p;
        cur += a;
        cur %= p;
        ans += arr[cur];
        arr[cur]++;
        mult *= 10;
        mult %= p;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include "queue"
#include "string.h"
using namespace std;

static const int inf=(1<<21);

int n,m[107][107];
int d[107];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	for(int i=0;i<n;i++)d[i]=inf;
	d[s]=0;
	int u;
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int v=0;v<n;v++)
		{
			if(m[u][v]==0)continue;
			if(d[v]!=inf)continue;
			d[v]=d[u]+1;
			q.push(v);
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<i+1<<" "<<((d[i]==inf)?(-1):d[i])<<endl;
	}	
		
}
int main(int argc, char *argv[]) {
	int u,k,v;
	
	cin>>n;
	memset(m, 0, sizeof(m));
	
	for(int i=0;i<n;i++)
	{
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++)
		{
			cin>>v;
			v--;
			m[u][v]=1;
		}
	}
	
	bfs(0);
	return 0;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using ll = long long;
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A > B) {
        cout << "0" << endl;
        return 0;
    }
    if (N <= 2 && A != B) {
        cout << "0" << endl;
        return 0;
    }
    ll ans = 1LL * (B - A) * (N - 2) + 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import           Control.Applicative

count :: [String] -> (Int, Int, Int, Int)
count [] = (0, 0, 0, 0)
count (x:xs)
    | x == "AC" = (ac+1, wa, tle, re)
    | x == "WA" = (ac, wa+1, tle, re)
    | x == "TLE" = (ac, wa, tle+1, re)
    | x == "RE" = (ac, wa, tle, re+1)
    | otherwise = (ac, wa, tle, re)
  where
      (ac, wa, tle, re) = count xs

main :: IO ()
main = do
    input <- count . lines <$> getContents
    sequence_ . map putStrLn . getZipList $
        (++) <$> ZipList ["AC x ", "WA x ", "TLE x ", "RE x "]
             <*> ZipList ((\(w, x, y, z) -> map show [w, x, y, z]) input)


Measured memory_bytes: 22004
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n, m;
bool red[MAXN];
int cnt[MAXN];

int main() { 

  scanf("%d %d", &n, &m);
  red[0] = true;
  for (int i = 0; i < n; i++) {
    cnt[i] = 1;
  }

  for (int i = 0; i < m; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    cnt[from]--; cnt[to]++;

    if (red[from]) {
      red[to] = true;
    }
    if (cnt[from] == 0) {
      red[from] = false;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[i] != 0 && red[i]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(void) {
        string s;
        cin >> s;

        int count = 0;
        for (int i = 0; i < 3; i++) {
                if (s[i] == 'R') {
                        count++;
                }
        }
        if (count == 2 && s[1] == 'S') {
                count = 1;
        }

        cout << count << endl;

        return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  vector<vector<int> > arr(100005);
  int A, B;
  for(int i=0;i<N;++i){
    cin>>A>>B;
    A--;
    arr[A].push_back(B);
  }
  multiset<int> st;
  auto index = st.begin();
  int ans = 0;
  for(int i=0;i<M;++i){
    for(int j=0;j<arr[i].size();++j) st.insert(arr[i][j]);
    if(st.size()==0) continue;
    index = st.end();
    index--;
    ans += *index;
    st.erase(st.find(*index));
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 10848
import sys
from collections import Counter

n, t, *a = map(int, sys.stdin.read().split())

def main():
  cand = []
  mi = a[0]
  for x in a[1:]:
    cand.append(x - mi)
    mi = min(mi, x)
  c = Counter(cand)
  ans = c[max(c.keys())]
  print(ans)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 22112
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef pair<int,int> P;
int n,ans,T[500][500],p;
bool ab[500][500];

int main(){
  P d[4]={{1,0},{0,1},{-1,0},{0,-1}};
  cin >> n;
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) T[i][j]=min(min(i,n-1-i),min(j,n-1-j));
  for(int i=0;i<n*n;i++){
    cin >> p;
    p--;
    int x=p/n,y=p%n;
    ans+=T[x][y];
    ab[x][y] = true;
    queue<P> q;
    q.push({x,y});
    while(!q.empty()){
      int vx=q.front().first,vy=q.front().second;
      q.pop();
      int a=T[vx][vy];
      if(!ab[vx][vy])a++; //!abなら(wx,wy)は(vx,vy)に嫌われる
      for(int r=0;r<4;r++){
        int wx=vx+d[r].first,wy=vy+d[r].second;
        if(wx>=0 && wx<n && wy>=0 && wy<n && T[wx][wy]>a){ //Tが更新されるときだけqにpushする
          T[wx][wy]=a;
          q.push({wx,wy});
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4812
H, W, K = map(int, input().split())
field = [list(input()) for _ in range(H)]

ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for p in range(H):
            for q in range(W):
                if (i >> p) & 1 or (j >> q) & 1:
                    continue
                else:
                    if field[p][q] == "#":
                        cnt += 1
        if cnt == K:
            ans += 1

print(ans)



Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

struct _restaurant{
   int number;
   std::string city;
   int point;
   bool operator<(const _restaurant& another) const{
      if(city != another.city) return city < another.city;
      else return point > another.point;
   }
};

int main(int argc, char** argv)
{
   int N;
   std::cin >> N;
   std::vector<_restaurant> restaurant(N);

   for(int i=0;i<N;++i){
      restaurant[i].number = i+1;
      std::cin>> restaurant[i].city >> restaurant[i].point ;
   }

   std::sort(restaurant.begin(), restaurant.end());

   for(int i=0;i<N;++i) std::cout << restaurant[i].number << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
static const ll LL_MAX = (ll)1 << 55;

int main()
{
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);

	ll ans = 0;
	ll x[100001] = {};
	repe(i, 1, n) {
		scanf("%lld", &x[i]);
		if (i >= 2) ans += min((x[i] - x[i - 1])*a, b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
//正解例
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

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

		int avarage = ((a + b + 1)/2);

		System.out.println(avarage);
	}
}

Measured memory_bytes: 21716
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, x, a[100], i, num = 0;

	cin >> n >> x;

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

	sort(a, a + n);

	for (i = 0; i < n; i++) {
		//printf("i=%d\n", i);
		if (i == n - 1 && x != a[n - 1]) {

		}else if (x >= a[i]) {
			x -= a[i];
			num++;
		}
	}
	cout << num << "\n";

	return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

ll n, a, b, c, d;
map<ll, ll> memo;
ll dp(ll n) {
    if (n == 0) return 0;
    if (n == 1) return d;
    if (memo.count(n)) return memo[n];

    ll l2 = (n / 2) * 2;
    ll l3 = (n / 3) * 3;
    ll l5 = (n / 5) * 5;
    ll r2 = ((n + 1) / 2) * 2;
    ll r3 = ((n + 2) / 3) * 3;
    ll r5 = ((n + 4) / 5) * 5;

    ll res = 1e18;
    if (n < res / d) res = n * d;
    chmin(res, abs(l2 - n) * d + a + dp(l2 / 2));
    chmin(res, abs(r2 - n) * d + a + dp(r2 / 2));
    chmin(res, abs(l3 - n) * d + b + dp(l3 / 3));
    chmin(res, abs(r3 - n) * d + b + dp(r3 / 3));
    chmin(res, abs(l5 - n) * d + c + dp(l5 / 5));
    chmin(res, abs(r5 - n) * d + c + dp(r5 / 5));

    return memo[n] = res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    rep(i, t) {
        memo.clear();
        cin >> n >> a >> b >> c >> d;
        cout << dp(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 4352
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

using i8 = std::int_least8_t;
using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u8 = std::uint_least8_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>

namespace n91 {

void main_() {
  usize n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;
  std::vector<usize> run;
  run.emplace_back(0);
  char prev = '1';
  for (const auto c : s) {
    if (c != prev) {
      prev = c;
      run.emplace_back(0);
    }
    ++run.back();
  }
  if (prev != '1') {
    run.emplace_back(0);
  }
  usize ans = 0;
  if (run.size() <= k * 2 + 1) {
    ans = n;
  } else {
    std::vector<usize> cum(run.size() + 1);
    cum[0] = 0;
    std::partial_sum(run.cbegin(), run.cend(), cum.begin() + 1);
    for (usize l = 0; l + k * 2 + 1 <= run.size(); l += 2) {
      ans = std::max(ans, cum[l + k * 2 + 1] - cum[l]);
    }
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 2036
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    fr(i, n) cin >> a[i];

    int dist = 0;
    fr(i, n-1) {
        dist = max(dist, abs(a[i] - a[i+1]));
    }
    dist = max(dist, a[0] + k - a[n-1]);
    cout << k - dist << endl;

    return 0;
}


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

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    string s[n];
    int t[n];
    map<string, int> ind;
    for(int i=0;i<n;i++) {
        cin>>s[i]>>t[i];
        ind[s[i]]=i;
    }   

    string lol;
    cin>>lol;
    int ans=0;
    for(int i=ind[lol]+1;i<n;i++) {
        ans+=t[i];
    }

    cout<<ans;

    return 0;
}

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

using namespace std;

int main() {
  int n; cin >> n;
  vector <int> a(n), used(n, 0);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(used[i] or used[a[i]]) continue;
    if(a[a[i]] == i) {
      ans++;
      used[i] = used[a[i]] = 1;
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]* N
dp[0] = 0
for j in range(1, N):
    for i in range(max(0, j-K), j):
        dp[j] = min(dp[i]+abs(h[j]-h[i]), dp[j])
print(dp[-1])

Measured memory_bytes: 55136
#!/usr/bin/env python3
S = input()
n = [S.count('a'), S.count('b'), S.count('c')]

ans = False
if len(S) == 1:
    ans = True
elif len(S) == 2 and len([x for x in n if x != 0]) == 2:
    ans = True
else:
    n.sort()
    if n[0] != 0 and n[2] - n[0] <= 1:
        ans = True
print(('NO', 'YES')[ans])


Measured memory_bytes: 3188
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

//fac[]はn! inv[]はMODにおける逆元 finv[]はinv[]とfinv[]の累積積
const long long MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算(nCkをO(1)で)
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    long long N,P;cin >> N >> P;
    vector<long long> retu(N);
    map<long long,long long> M;
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        M[retu.at(i)%2]++;
    }
    COMinit();
    long long odd = 0;
    for(long long i = 1;i<=M[1];i+=2){
        for(long long j = 0;j<=M[0];j++){
            odd += COM(M[1],i)*COM(M[0],j);
        }
    }
    /*for(long long i = 1;i<=M[0];i++){
        even += COM(M[0],i);
    }*/
    long long all = pow(2,N);
    long long even = all-odd;
    if(P == 1){
        cout << odd << endl;
    }
    else{
        cout << even << endl;
    }
}


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

int main(){
  
  string S;
  cin >> S;
  
  if (S == "Sunny") cout << "Cloudy" << endl;
  if (S == "Cloudy") cout << "Rainy" << endl;
  if (S == "Rainy") cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    A, B, K = list(map(int, input().split()))

    if K > A:
        K -= A
        A = 0
        if K > B:
            B = 0
        else:
            B -= K
    else:
        A -= K

    print(A, B)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int h, w;
vector<string> grid;
vector<vector<bool>> isVisited;

int dfs(int x, int y)
{
    isVisited[x][y] = true;

    int result = 1;
    for (int dx = -1; dx <= 1; dx++) {
        for (int dy = -1; dy <= 1; dy++) {
            if (abs(dx) + abs(dy) == 1) {
                int nx = x + dx, ny = y + dy;
                if (nx >= 0 && nx < h && ny >= 0 && ny < w && grid[nx][ny] == '#') {
                    if (!isVisited[nx][ny]) {
                        result += dfs(nx, ny);
                    }
                }
            }
        }
    }

    return result;
}

int main()
{
    cin >> h >> w;

    grid.resize(h);
    rep(i, h)
    {
        cin >> grid[i];
    }

    isVisited.resize(h, vector<bool>(w, false));
    rep(i, h) rep(j, w)
    {
        if (grid[i][j] == '#' && !isVisited[i][j]) {
            if (dfs(i, j) == 1) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 512
/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

signed main(){
	fast_io();
	string s;
	cin >> s;
	bool f = true;
	int ans = 0;
	for(int i = 0; i < s.length(); i++){
		if(f){
			ans++;
			f = false;
		}
		else{
			if(s[i] != s[i-1]){
				ans++;
			}
			else{
				i++;
				ans++;
				f = true;
			}
		}
		if(i >= s.length()) ans--;
		// cout << i << " " << ans << "\n";
	}
	cout << ans;
	return 0;
}

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

int main(void)
{
    vector<int> A(5);
    vector<int> B(5);
    for (int i = 0; i < 5; i++)
    {
        cin >> A[i];
        if (A[i] % 10 == 0)
        {
            B[i] = 100;
        }
        else
        {
            B[i] = A[i] % 10;
        }
    }
    vector<int>::iterator min = min_element(B.begin(), B.end());
    size_t min_index = distance(B.begin(), min);
    int sol = 0;
    for (int i = 0; i < 5; i++)
    {
        if (i != min_index)
        {
            if (A[i] % 10 == 0)
            {
                sol += A[i];
            }
            else
            {
                sol += A[i] + 10 - A[i] % 10;
            }
        }
        else
        {
            sol += A[i];
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 256