akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
//#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEsL 2e9
#define PIE 3.1415a926535

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main() {
    vector<pair<int, bool>> b;
    int bingo;
    rep(i, 9) {
        cin >> bingo;
        b.push_back(make_pair(bingo, false));
    }
    int n;
    cin >> n;
    int a;
    rep(i,n) {
        cin >> a;
        rep(j, 9){
            if (b[j].first == a){
                b[j].second = true;
            }
        }
    }
    bool s = false;
    if(b[0].second == true && b[1].second == true && b[2].second == true) s = true;
    if(b[3].second == true && b[4].second == true && b[5].second == true) s = true;
    if(b[6].second == true && b[7].second == true && b[8].second == true) s = true;
    if(b[0].second == true && b[3].second == true && b[6].second == true) s = true;
    if(b[1].second == true && b[4].second == true && b[7].second == true) s = true;
    if(b[2].second == true && b[5].second == true && b[8].second == true) s = true;
    if(b[0].second == true && b[4].second == true && b[8].second == true) s = true;
    if(b[2].second == true && b[4].second == true && b[6].second == true) s = true;
    if(s)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
}

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

using namespace std;

using ll = long long;

bool isPrime(ll x){
	for(int i=2;i*i<x;++i){
		if(x%i == 0) return false;
	}

	return true;
}

int main(){
	ll x;
	cin >> x;
	while(!isPrime(x)){
		++x;
	}

	cout << x << endl;

	return 0;

}


Measured memory_bytes: 256
def calc_bill(max, goal)
  0.upto(max) do |man|
    0.upto(max - man) do |gosen|
      sen = max - (man + gosen)
      if (man * 10000) + (gosen * 5000) + (sen * 1000) == goal
        return "#{man} #{gosen} #{sen}"
      end
    end
  end
  "-1 -1 -1"
end

a, b = (gets.split.map(&:to_i))
puts calc_bill(a, b)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N, 0);
    for (int i = 0; i < Q; i++) {
        int a;
        cin >> a;
        A[a - 1]++;
    }
    for (int i = 0; i < N; i++) {
        cout << (K - (Q - A[i]) > 0 ? "Yes" : "No") << '\n';
    }
    return 0;
}


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

struct node {
  int key;
  struct node *next;
};

int main() {
  int N,M;
  struct node *t, *x;
  while(cin >> N >> M) {
    if(N==0&&M==0)break;
    t = new node;
    t->key = 1;
    x = t;
    for(int i=2;i<=N;i++) {
      t->next = new node;
      t = t->next;
      t->key = i;
    }
    t->next = x;
    while(t != t->next) {
      for(int i=1;i<M;i++) t = t->next;
      x = t->next; t->next = x->next;
      delete x;
    }
    cout << t->key << endl;
  }
}

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

int main()
{
    string b;
    
    cin >> b;

	if( b == "A"){
		cout<<"T"<<endl;
	}
	if( b == "T"){
		cout<<"A"<<endl;
	}
	if( b == "C"){
		cout<<"G"<<endl;
	}
	if( b == "G"){
		cout<<"C"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
N,M=map(int,input().split())
d=[set()for _ in range(N+1)]
def f(v,h,q):
 if d[v]&q:
  l,L=[],[]
  for x in h:
   l=[x]+l
   if x in d[v]:break
  while v!=x:
   for y in l:
    if v in d[y]:
     L,v=[v]+L,y
     break
  print("\n".join(str(x)for x in[len(L)+1,x]+L));sys.exit()
 for u in d[v]:f(u,[u]+h,q|{u})
for _ in range(M):a,b=map(int,input().split());d[a].add(b)
v=0;exec("v+=1;f(v,[v],{v});"*N)
print(-1)

Measured memory_bytes: 87408
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long s,a,b;
	cin>>s>>a>>b;
	if(a==0){
		cout<<0<<endl;
		return 0;
	}
	long long ans=s/(a+b)*a;
	ans+=(s%(a+b)>=a)?a:(s%(a+b));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# 2019/09/06

n=int(input())
p=[0]+list(map(int,input().split()))

cnt=0
for i in range(1,n+1):
    if i!=p[i]:continue
    if i==n:p[i],p[i-1]=p[i-1],p[i]
    else:
        p[i],p[i+1]=p[i+1],p[i]
    cnt+=1
    
print(cnt)

Measured memory_bytes: 13880
import sys
N=int(input())
C=list()
A=list(map(int,input().split()))
B=list(map(int,input().split()))
R=0
k=0
if sum(B)>sum(A):
  print(-1)
  sys.exit()
for i in range(N):
  C.append(A[i]-B[i])
C=sorted(C)
for i in range(N):
  if C[i]<0:
    R=R+C[i]
    k=k+1
C=sorted(C,reverse=True)
for i in range(N):
  if R==0:
    print(0)
    sys.exit()
  R=R+C[i]
  if R>=0:
    print(k+i+1)
    sys.exit()

Measured memory_bytes: 18356
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N >> M;
  ;
}
void solve() {
  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return;
  }
  int ans = 1;
  rep(i, 1, N) {
    ans *= i;
    ans %= MOD;
  }
  rep(i, 1, M) {
    ans *= i;
    ans %= MOD;
  };
  if (N == M) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
std::cin >> x>>y;
std::vector<int> v(x,0);
rep(i,y){
  std::cin >> z;
  Rep(j,z){
    std::cin >> w;
    v[w-1]++;
  }
}
rep(i,x){
  if(v[i]==0)n++;
}
std::cout << n << '\n';
}


Measured memory_bytes: 3628
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline
N = I()
a = LI()
s = [0]*N
for i in range(N):
    if i-a[i]+1>=0:
        s[i-a[i]+1] += 1
ans = 0
for i in range(N):
    start = i+a[i]+1
    if start<N:
        ans += s[start]

print(ans)


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, X, Y; cin >> N >> X >> Y; X--; Y--;
  ll result[N] = {};
  rep(i,N) repr(j,i+1,N) {
    ll d1 = j-i;
    ll d2 = abs(i-X) + 1 + abs(j-Y);
    result[min(d1,d2)]++;
  }
  repr(i,1,N) cout << result[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;



int main(){
  int n, m, k;
  while(cin >> n >> m >> k && n + m + k > 0){
    double res = 0;

    vector<vector<double> > dp(n + 1,vector<double>(n * m + 1, 0.0)) ;    
    dp[0][0] = 1.0;
    
    REP(i, n){
      REP(j, n * m)REP(k, m){
        int nxt = j + k + 1;
        if(nxt <= n * m){
          // cout << nxt << endl;
          dp[i+1][nxt] += dp[i][j] / m;
        }
      }
    }
    
    for(int i = 0; i <= n * m; i++){
      res += dp[n][i] * max(1, i - k);
    }
    cout << fixed << setprecision(20) << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1484
#include <stdio.h>

int main()
{
  int A,P,S,v,b;
  scanf("%d",&A);
  scanf("%d",&P);
  scanf("%d",&S);
  v =A *P;
    b = S;
  if(v >S){
    printf("%d\n",b);
  }
    else {
        printf("%d\n",v);
    }
   return 0;
}


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

using namespace std;

int main()
{
    int b,c=0,c1=0,j,n,i,s=0;

    cin >> n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0){
            c++;
        }
        else{
            c1++;
            s+=a[i];
        }

    }
    if(s%2==0){
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (A > 0 && C > 0) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3644
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define all(v) (v).begin(),(v).end()
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=20+5;
const int N=1e4+5,M=N*2;
int n,ans,a[maxn],x;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%d",a+i);
    for(int i=0;i<n;++i){
        scanf("%d",&x);
        ans+=max(0,a[i]-x);
    }
    printf("%d\n",ans);
    re 0;
}

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

int main(void) {
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  REP(i, 0, N) cin >> w[i] >> v[i];

  const ll INF = 1LL << 60;
  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, -INF));
  dp[0][0] = 0;

  REP(i, 0, N) {
    REP(j, 0, W + 1) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j + w[i] <= W) {
        dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
      }
    }
  }

  ll ans = -INF;
  REP(i, 0, W + 1) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 80256
n = gets.to_i
t_score,h_score = [0,0]

n.times {
  t,h = gets.chomp.split
  if t > h
    t_score += 3
  elsif t < h
    h_score += 3
  else
    t_score += 1
    h_score += 1
  end
  }
puts "#{t_score} #{h_score}"


Measured memory_bytes: 6860
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 1; i < 2e6; i++){
        if((N-i) < 0 || (N-i)%i != 0 || (N-i)/i <= i) continue;
        ans += (N-i)/i;
    }
    cout << ans << endl;
}

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

import static java.lang.Math.*;

public class Main {
    class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

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

        boolean hasNext() throws IOException {
            if (tokin.hasMoreTokens()) {
                return true;
            } else {
                String s = in.readLine();
                while (s != null && s.length() == 0) {
                    s = in.readLine();
                }
                if (s == null) {
                    return false;
                } else {
                    tokin = new StringTokenizer(s);
                    return true;
                }
            }
        }
    }

    class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    void run() throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        long a = in.nextInt();
        long b = in.nextInt();
        long c = in.nextInt();
        long d = in.nextInt();
        long m1 = max(a * c, a * d);
        long m2 = max(b * c, b * d);
        out.print(max(m1, m2));
        out.close();
    }

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

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int q; cin >> q;
    rep(_,q){
        string x,y;
        cin >> x >> y;
        x = ' ' + x;
        y = ' ' + y;
        int n = x.size(), m = y.size();
        vvi dp(n, vi(m+1));
        REP(i,1,n) REP(j,1,m){
            if(x[i] == y[j]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
        cout << dp[n-1][m-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 6884
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
const double eps = 1e-9;
typedef long long ll;

double p,q,m,a;
ll sum;
void dfs(ll anow,int num,double now,int before){
  //cout << anow << "  " << num << "  " << now << "  " << before << endl;
  //cout << fabs(p/q-now) << endl;
  if(num <= m && fabs(p/q-now) < eps && anow <= a ){
    sum++;
    return;
  }
  if(a < anow || num > m || now > p/q)
    return;
  
  num++;
  
  for(int i = before;i < a;i++){
    if(anow*i > a){
      break;
    }
    dfs(anow*i,num,now+(double)1/i,i);
  }
  
}

int main(){
  vector <int> g;
  while(cin >> p >> q >> a >> m,p+q+a+m){
    sum = 0;
    dfs(1,0,0,1);
    g.push_back(sum);
    //cout << sum << endl;
  }
  REP(i,g.size()){
    cout << g[i] << endl;
    }
  return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

struct recipe{
  int dist;
  vector<int> src;
};

int main(){
  int n;
  while(cin>>n, n){
    map<string,int> mp;
    vector<int> g(n);

    REP(i,n){
      string str;
      int p;
      cin >> str >> p;
      mp[str] = i;
      g[i] = p;
    }

    int m;
    cin >> m;
    vector<recipe> r(m);
    REP(i,m){
      string str;
      int k;
      cin >> str >> k;
      r[i].dist = mp[str];
      r[i].src = vector<int>(k);
      REP(j,k){
        cin >> str;
        r[i].src[j] = mp[str];
      }
    }

    bool flag = true;
    while(flag){
      flag = false;
      REP(i,m){
        int dist = r[i].dist;
        int sum = 0;
        REP(j,r[i].src.size()){
          sum += g[r[i].src[j]];
        }
        if(sum < g[dist]){
          flag = true;
          g[dist] = sum;
        }
      }
    }

    string str;
    cin >> str;
    cout << g[mp[str]] << endl;
  }
  return 0;
}

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

using namespace std;

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

    for (int i = 0; i < q; i++) {
        long long a, b;
        cin >> a >> b;

        if (a > b) {
            swap(a, b);
        }

        long long c = 0;
        for (long long r = b; c < r; ) {
            long long m = (c + r + 1) / 2;
            if (m * m < a * b) {
                c = m;
            } else {
                r = m - 1;
            }
        }

        if (a == b || a + 1 == b) {
            cout << 2 * a - 2 << endl;
        } else if (c * (c + 1) >= a * b) {
            cout << 2 * c - 2 << endl;
        } else {
            cout << 2 * c - 1 << endl;
        }
    }
}


Measured memory_bytes: 256
a,b=map(int,input().split())
ListA = []
for i in range (a):
  ListA.append(input())
ListB = []
for i in range (b):
  ListB.append(input())
flag = False
  
def checkAB(List1,List2,aa,bb):
  for k in range(b):
    if List1[aa+k][bb:bb+b] != List2[k]:
      return False
  return True
  
for i in range(a-b+1):
  for j in range(a-b+1):
    if checkAB(ListA,ListB,i,j):
      flag = True
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9024
#include<cstdio>
using namespace std;
const int maxn=200005;
int n,a[maxn];
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",a+i);
	if (a[0]) { puts("-1"); return 0; }
	long long ans=0;
	for(int i=0;i<n;i++) {
		if (i&&a[i]>a[i-1]) {
			if (a[i]!=a[i-1]+1) { puts("-1"); return 0; }
			ans++;
		} else ans+=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int h,w;
  cin>>h>>w;
  char a[h][w];
  int dis[h][w];
  queue<pair<int,int>> q;
  rep(i,h)rep(j,w) {
    char c;
    cin>>c;
    a[i][j] = c;
    if(c=='#') {
      dis[i][j] = 0;
      q.emplace(i,j);
    } else dis[i][j] = MOD;
  }
  int dx[4] = {-1,1,0,0};
  int dy[4] = {0,0,-1,1};
  while(!q.empty()) {
    auto p = q.front();
    q.pop();
    rep(i,4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if(nx >= 0 && nx < h && ny >= 0 && ny < w) {
        if(dis[nx][ny] > dis[p.first][p.second] + 1) {
          dis[nx][ny] = dis[p.first][p.second] + 1;
          q.emplace(nx,ny);
        }
      }
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w) ans = max(ans, dis[i][j]);
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 13328
#include <cstdio>

#include <string>

#include <iostream>

using namespace std;

int main()
{
    string s,x;

    while((cin>>s))
    {
        x="";

        for(int i=0;i<s.size();i++)

        {
            if(s[i]=='0')
            {
                x+=s[i];
            }
            if(s[i]=='1')
            {
                x+=s[i];
            }
            if(s[i]=='B')
            {
                x=x.substr(0,x.size()-1);
            }
        }
        cout << x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d.at(i);
  sort(d.begin(), d.end());
  int x1 = d.at(n/2 - 1);
  int x2 = d.at(n/2);
  cerr << x1 << " " << x2 <<endl;
  int ans = x2 - x1;
  cout << ans << endl;
  
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String strA = scan.next();
    String strB = scan.next();
    int intA = Integer.parseInt(strA);
    int intB = Integer.parseInt(strB);
    if (intB%intA == 0){
    	System.out.println(intA+intB);

    }else{

    	System.out.println(intB - intA);
  }
}
  }

Measured memory_bytes: 23252
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (a % b == 0)
		return b;
	else
	{
		return gcd(b, a % b);
	}
}
string s[10005];
void solve()
{
	int n,c1=0,c2=0,c3=0,sol=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		int l = s[i].length();
		for (int j = 0; j < l-1; j++)
		{
			if (s[i][j] == 'A' && s[i][j+1] == 'B')
				sol++;
		}
		if (s[i][0] == 'B' && s[i][l - 1] == 'A')
			c1++;

		if (s[i][0] != 'B' && s[i][l - 1] == 'A')
			c2++;

		if (s[i][0] == 'B' && s[i][l - 1] != 'A')
			c3++;
	}
	if (c1 == 0)
	{
		sol = sol + min(c2, c3);
		cout << sol;
		return;
	}
	if (c1 > 0 && (c2+c3)>0)
	{
		sol = sol + c1 + min(c2, c3);
		cout << sol;
		return;
	}
	cout <<sol+ c1 - 1;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    int sx, sy;
    cin >> sx >> sy;
    --sx; --sy;
    int gx, gy;
    cin >> gx >> gy;
    --gx; --gy;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    vector<vector<int>> d(h, vector<int> (w, (int) (1e6)));
    deque<pair<int, int>> q;
    q.push_front({sx, sy});
    d[sx][sy] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        int dist = d[p.first][p.second];
        for (int dx = -2; dx <= 2; ++dx) {
            for (int dy = -2; dy <= 2; ++dy) {
                int nx = p.first + dx;
                int ny = p.second + dy;
                if (nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#') continue;
                if (abs(dx) + abs(dy) == 1) {
                    if (d[nx][ny] > dist) {
                        d[nx][ny] = dist;
                        q.push_front({nx, ny});
                    }
                } else {
                    if (d[nx][ny] > dist + 1) {
                        d[nx][ny] = dist + 1;
                        q.push_back({nx, ny});
                    }
                }
            }
        }
    }
    int ans = d[gx][gy];
    cout << (ans == (int) (1e6) ? -1 : ans) << '\n';
    return 0;
}

Measured memory_bytes: 8672
n = int(input())
a_s = list(map(int, input().split(' ')))
b_s = list(map(int, input().split(' ')))
c_s = list(map(int, input().split(' ')))

sat = 0
for a_i in range(0, n):
    i = a_s[a_i] - 1
    b = b_s[i]
    sat += b
    if a_i < n-1 and a_s[a_i] +1 == a_s[a_i+1]:
        if i >= 0:
            sat += c_s[i]
print(sat)

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

#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = (int)1e7+9;
#define REP0(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<=n;i++)
#define F first
#define S second
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define inf (int)(1e18)
#define prec(x) fixed<<setprecision(x)<<x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

void solve(){
   int x;
   cin>>x;
   if(x==1) cout<<"0";
   if(x==0) cout<<"1";
   cout<<endl;
}


int main(){
    fastio;
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    int tc = 1;
    // cin>>tc;
    for(int i=1;i<=tc;i++){
        solve();
    }
    return 0;
}


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

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> ss(h);
	for (auto &&s : ss)
	{
		cin >> s;
	}

	cout << string(w + 2, '#') << endl;
	for (auto &&s : ss)
	{
		cout << '#' << s << '#' << endl;
	}
	cout << string(w + 2, '#') << endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int) 1e9 + 7;
const double EPS = 1e-9;

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

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

int main() {
    int d,g,G;
    int P[13]={};
    int c[13]={};
    int mi = inf;
    cin >> d >> G;
    rep(i,d) cin >> P[i] >> c[i];

    for(int bit=0;bit < (1<<d);bit++){
        int g = G;
        int p[13];
        rep(i,13) p[i] = P[i];
        int sum = 0;
        int cost = 0;
        rep(i,d) if(bit&(1<<i)){
                sum += c[i];
                sum += p[i]*(i+1)*100;
                cost += p[i];
                p[i] = 0;
            }
        g-=sum;
        if(g<=0){
            chmin(mi,cost);
            continue;
        }
        rrep(i,d){
            if((i+1)*100*p[i] >= g){
                cost += (g+(i+1)*100-1)/((i+1)*100);
                g = 0;
                break;
            }else{
                g-=(i+1)*100*p[i];
                cost += p[i];
            }
        }
        if(g<=0) chmin(mi,cost);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (B <= C || D <= A) {
    cout << 0 << endl;
  }
  else {
    cout << min(B, D) - max(A, C) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3572
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp

N = gets.to_i
arr = gets.split.map(&:to_i)
cnt=0
flag=true
while flag do
    flag = false
    (N-1).downto(1) do |j|
        if arr[j] < arr[j-1]
            buf = arr[j]
            arr[j] = arr[j-1]
            arr[j-1] = buf
            cnt+=1
            flag = true
        end
    end
end

puts arr.join(" ")
puts cnt

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


using namespace std;


int main() {
	string str;
	int N = 0,max=0;
	cin >> str;
	
	for (int i = 0; i <= str.length(); i++) {
		if ((str[i] == 'A') || (str[i] == 'T') || (str[i] == 'G') || (str[i] == 'C')) {
			N++;
		}
		else {
			if (max <= N) {
				max = N;
				N = 0;
			}
		}
	}
	cout << max << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
using namespace std;
//const long long INF = numeric_limits<long long>::max();
typedef pair <int,int> P;

int main()
{
    int N;
    cin >> N;
    int a[N-1],b[N-1],c[N-1];
    for (int i=0;i<N-1;i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }
    vector <vector<P>> adj_list(N);
    bool visited[N];
    for (int i=0;i<N-1;i++){
        visited[i] = false;
        adj_list[a[i]].push_back(make_pair(b[i],c[i]));
        adj_list[b[i]].push_back(make_pair(a[i],c[i]));
    }
    visited[N-1] = false;

    int Q,K;
    cin >> Q >> K;
    K--;
    visited[K] = true;
    INT d[N];
    d[K] = 0;

    queue<P> que;
    que.push(make_pair(K,0));

    while(!que.empty()){
        P p = que.front();
        que.pop();
        vector <P> tmpvec = adj_list[p.first];
        for (int i=0;i<int(tmpvec.size());i++){
            if (!visited[tmpvec[i].first]){
                visited[tmpvec[i].first] = true;
                d[tmpvec[i].first] = d[p.first] + tmpvec[i].second;
                que.push(tmpvec[i]);
            }
        }
    }
    int x,y;
    INT ans[Q];
    for (int i=0;i<Q;i++){
        cin >> x >> y;
        x--;y--;
        ans[i] = d[x] + d[y];
    }

    for (int i=0;i<Q;i++) cout << ans[i] << "\n";

    return 0;
}

Measured memory_bytes: 11236
#include <iostream>

const int MAXN = (int)1e5 + 1;

int count[MAXN];  // count[i] = the number of 'i' in the array.

int main() {
  int n;
  std::cin >> n;
  int64_t sum = 0;
  for (int i = 0, in; i < n; ++i) {
    std::cin >> in;
    sum += in;
    ++count[in];
  }
  int q;
  std::cin >> q;
  for (int i = 0, cur, nxt; i < q; ++i) {
    std::cin >> cur >> nxt;
    sum += 1LL * count[cur] * (nxt - cur);
    std::cout << sum << std::endl;
    count[nxt] += count[cur];
    count[cur] = 0;
  }
  return 0;
}


Measured memory_bytes: 3924
from collections import defaultdict, Counter, namedtuple, deque
from bisect import bisect_left
from functools import reduce
import math

NN = 2020202
MOD = 10**9+7
INF = float("inf")


S = list(input().split())
Q = int(input())
query = [list(input().split()) for i in range(Q)]
que = deque(S)
rev = 0

for q in query:
    if len(q) == 1:
        rev ^= 1
    else:
        if q[1] == "1":
            if rev:
                que.append(q[2])
            else:
                que.appendleft(q[2])
        else:
            if rev:
                que.appendleft(q[2])
            else:
                que.append(q[2])
    # print(que)

if rev:
    print("".join(que)[::-1])
else:
    print("".join(que))




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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  
}



Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<string> M;
ll h,w;
vector<vector<ll>> dp;
vector<ll> dx={1,0,-1,0};
vector<ll> dy={0,1,0,-1};
pll cnt;

void dfs(ll x,ll y,ll num){
    dp[x][y]=num;
    if(M[x][y]=='#'){cnt.F++;}
    else{cnt.S++;}
    for(int i=0;i<4;i++){
        ll X=x+dx[i];
        ll Y=y+dy[i];
        if(X<0 || Y<0 || X>=h || Y>=w || M[X][Y]==M[x][y] || dp[X][Y]!=-1){continue;}
        dfs(X,Y,num);
    }
}



int main(){
    cin>>h>>w;
    M.resize(h);
    dp.resize(h,vector<ll>(w,-1));
    for(auto &i:M){cin>>i;}
    ll ans=0;
    ll num=0;
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            if(dp[i][t]==-1 && M[i][t]=='#'){
                cnt={0,0};
                dfs(i,t,num);
                ans+=cnt.F*cnt.S;
                num++;
            }
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 16768
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;
int main (){
	int a, b;
	cin >> a >> b;
	if (b*2>=a){
		cout << "0";
	}
	else {
		cout << (a-b*2);
	}
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()

    print(N*(N-1)//2)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    ll n;
    cin >> n;
    ll ans = 1e18;
    for(ll i = 1; i<=pow(n,0.5);++i){
        ll j = n/i;
        if(n%i!=0)continue;
        ans = min(ans, i+j-2);
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
	int res = 1;

	while (b)
	{
		if (b & 1) res = (res * a);

		a = (a * a); 
		b >>= 1;
	}
	return res;
}

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

#define N 100010
#define MOD 1000000007

int visited[N];

vector<int> g1[N], g2[N];
vector<int> component;

void dfs(int v)
{
	visited[v] = 1;
	component.pb(v);

	for (auto e : g1[v])
	{
		if (!visited[e])
			dfs(e);
	}
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	int n, m, k;
	cin >> n >> m >> k;
	int a, b;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		g1[a].pb(b);
		g1[b].pb(a);
	}

	for (int i = 0; i < k; ++i)
	{
		cin >> a >> b;
		g2[a].pb(b);
		g2[b].pb(a);
	}

	int ans[n + 1] = {};
	for (int i = 0; i < n; ++i)
	{
		if (!visited[i + 1])
			dfs(i + 1);
		else
			continue;
		int no = component.size();
		for (auto e : component)
		{
			int k1 = 0, k2 = 0;
			k1 = g1[e].size();

			for (auto e1 : g2[e])
			{
				// cout << e1 << ' ';
				if (visited[e1] == 1)
					k2++;
			}

			// cout << e << " " << k1 << " " << k2 << "\n";
			ans[e] = no - 1 - k1 - k2;
			
		}

		for (auto e : component)
			visited[e] = 2;
		component.clear();
	}

	for (int i = 1; i <= n; ++i)
		cout << ans[i] << " ";
	return 0;
}

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

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

    int K, N; cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int res = 0;
    for (int i = 0; i < N-1; i++) {
        res = max(res, A[i+1] - A[i]);
    }
    res = max(res, K - A[N-1] + A[0]);
    cout << K - res << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int a[n+10],b[n+10],ans=0,x;
    for(int i=0;i<n+1;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];

    for(int i=0;i<n;i++){
        if(b[i]<=a[i])
            ans+=b[i];
        else{
            ans+=a[i];
            x = min(b[i]-a[i],a[i+1]);
            ans+=x;
            a[i+1]-=x;

        }
    }
    return cout<<ans<<endl,0;

}





Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n;cin>>n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	
	vector<ll> a_sum(n + 1,0);
	for(int i = 1; i <= n; i++) {
		a_sum[i] = a[n - i] + a_sum[i - 1];
		a_sum[i] %= mod;
	}
	ll ans = 0;
	for(int i = 0; i < n - 1; i++) {
		ans += a[i] * (a_sum[n - i - 1]) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6380
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : September 10, 2020 4:57 PM
 *    Problem Name  : C - Distinct or Not
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc154/tasks/abc154_c
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int 
#define sz 1000000000
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n;

    vector<ll>v(n);
    for(ll i=0; i<n; i++){
        cin >> v[i];   
    }
    sort(v.begin(),v.end());
    for(ll i=0; i<n; i++) {
        if(v[i] != v[i+1]){
            continue;
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0 ;
}


Measured memory_bytes: 4732
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int n, m;
	while (cin >> n ) {
		bool f = false;
		for (int i = 1; i < 1024; i <<= 1) {
			if (i&n) {
				if (f)cout << " ";
				cout << i;
				f = true;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
    int N, K; cin >> N >> K;
    double res = 0.0L;

    for (int i = 1; i <= N; ++i) {
        if (K <= i) {
            res += (1.0L / (double)N);
            continue;
        }
        int cnt = 1;
        for (int tmp = 2; tmp * i < K; ++cnt, tmp *= 2);
        res += (1.0L / (double)N / (double)(1 << cnt));
    }

    printf("%.15f\n",res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N;
void input(){
    fast_io();
    cin >> N;
}

int solve(){
    ll K = 0;
    bool chk = false;
    if(N==1){
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << 1 << " " << 1 << endl;
        cout << 1 << " " << 1 << endl;
        return 0;
    }
    for (ll k = 2; k <= N; k++)
    {
        if(2*N==k*(k-1)){
            K = k;
            chk = true;
            break;
        }
    }
    if(!chk) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << K << endl;
    vector<vector<int>> S(K);
    for (int i = 0; i < N; i++)
    {
        S[i%K].push_back(i+1);
        int d = (i+1+K-1)/K;
        S[(i+d)%K].push_back(i+1);
    }
    for (int i = 0; i < K; i++)
    {
        cout << S[i].size() << " ";
        cout << S[i] << endl;
    }
    
    

    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 4240
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i, n) { cin >> d[i]; }
  ll sum = 0;
  REP(i, n - 1) {
    FOR(j, i + 1, n) { sum += d[i] * d[j]; }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import permutations as per
n = int(input())
pe = [i for i in range(1, n+1)]
P, Q = tuple(map(int, input().split())), tuple(map(int, input().split()))
p, q = 0, 0
for i, j in enumerate(per(pe)):
    if j==P: p = i + 1
    if j==Q: q = i + 1
print(abs(p-q))

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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C;
  cin >> K;
  for(int i = 0; i < K;i++){
    if(B<=A){
      B *= 2;
    }else{
      C *= 2;
    }
  }
  if(A<B&&B<C){
    cout << "Yes"<< endl;
  }else{
    cout << "No"<< endl;
  }

  return 0;
}

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

int main() {
	// your code goes here
	int n,i,k,j;
	cin>>n>>k;
	int A[n];
	for(i=0;i<n;i++)
		cin>>A[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(A[0]-A[1]);
	for(i=2;i<n;i++)
	{
		dp[i]=INT_MAX;
		for(j=1;i-j>=0 && j<=k;j++)
			dp[i]=min(dp[i],dp[i-j]+abs(A[i]-A[i-j]));
		
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024