akhauriyash/Code-Regression huggingface dataset:
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    string s;
    int n;
    cin >> n>> s;
    for (int i = 0; i <s.size(); i++)
    {
        int x = s[i]-'A';
        x = (x+n)%26;
        cout<<(char) ('A'+x); 
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int n;

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







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

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());   
    s.erase(unique(s.begin(), s.end()), s.end());
    if (s == "abc"){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;

int main() {
  long long a, b ,k;
  cin >> a >> b >> k;
  if (a>=k) {
    cout << a-k << " " << b << endl;
  }
  else {
    if ( a+b <= k) {
      cout << 0 << " " << 0 << endl;
    }
    else {
      cout << 0 << " " << a+b - k << endl;
    }
  }
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n, m; cin >> n >> m;
    if(n == 0 && m == 0) {
      break;
    }
    vector<int> a(n), b(m);
    int sua = 0, sub = 0;
    for(int i=0;i<n;++i) {
      cin >> a[i];
      sua += a[i];
    }
    for(int i=0;i<m;++i) {
      cin >> b[i];
      sub += b[i];
    }

    int tmp = sub - sua;
    vector<pair<int, int>> p;
    for(int i=0;i<n;++i) {
      for(int j=0;j<m;++j) {
        if(2 * (b[j] - a[i]) == tmp) {
          p.push_back({i, j});
        }
      }
    }

    if((int)(p.size()) == 0) {
      cout << -1 << endl;
    } else {
      int mi = INF;
      pair<int, int> ans;
      for(int i=0;i<(int)(p.size());++i) {
        int s = a[p[i].first], t = b[p[i].second];
        if(s + t < mi) {
          mi = s + t;
          ans = {s, t};
        }
      }
      cout << ans.first << " " << ans.second << endl;
    }
  }
}



Measured memory_bytes: 3216
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x, y;
	scanf("%2d%2d", &x, &y);
	bool vx = false, vy = false;
	if (1 <= x && x <= 12) vx = true;
	if (1 <= y && y <= 12) vy = true;
	if (!vx && !vy) printf("NA\n");
	else if (!vx && vy) printf("YYMM\n");
	else if (vx && !vy) printf("MMYY\n");
	else printf("AMBIGUOUS\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int a; CI a;

	if (a % 100 == 0&&a/100>12) { CO "NA" EN; return 0; }
	if (a % 100 == 0 && a / 100 <= 12&&a/100>0) { CO "MMYY" EN; return 0; }
	if(a%100>12&&a/100>12){ CO "NA" EN; return 0; }
	if (a / 100 == 0 && a % 100 <= 12&&a%100>0) { CO "YYMM" EN; return 0; }
	if (a / 100 == 0 && a % 100 > 12) { CO "NA"  EN; return 0; }
	if (a / 100 == 0 && a % 100 == 0) { CO "NA" EN; return 0; }

	if (a / 100 <= 12) {
		if (a % 100 != 0) {
			if (a % 100 > 12) { CO "MMYY" EN; }
			else CO "AMBIGUOUS" EN;
		}
	}
	else {
		CO "YYMM" EN;
		return 0;
	}

	return 0;
}

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

using namespace std;

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

typedef long long i64;
typedef pair<i64, i64> pii;

const int INF = 0x3f3f3f3f;
const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  int x, y, b, p;
  int ans;
  rep(i, n) {
    cin >> x >> y >> b >> p;
    ans = x * b + y * p;
    if (b >= 5 && p < 2) {
      if (ans > (x * 0.8) * b + (y * 0.8) * 2) ans = (x * 0.8) * b + (y * 0.8) * 2;
    }
    else if (b < 5 && p >= 2) {
      if (ans > (x * 0.8) * 5 + (y * 0.8) * p) ans = (x * 0.8) * 5 + (y * 0.8) * p;
    }
    else if (b >= 5 && p >= 2) {
      ans = (x * 0.8) * b + (y * 0.8) * p;
    }
    cout << ans << "\n";
  }
  return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <sstream>
using namespace std;
 
void solve() {
	int n;
	cin >> n;
	long long mx = 0L;
	long long ans = 0L;
	for(int i = 0; i < n; i++) {
		long long cur;
		cin >> cur;
		if(cur >= mx) {
			mx = cur;
		}else {
			ans += abs(mx - cur);
		}
	}
	cout << ans << endl;
}
 
int main () {
	int t = 1;
	for(int tt = 0; tt < t; tt++) solve();
	return 0;
}

Measured memory_bytes: 3628
#!/bin/env python
#長さが4の文字列で、２種の文字が２回ずつ現れる文字列かどうか判定

def main():
  s = input() # len(s) == 4
  if s[0] != s[1]:
    if s.count(s[0]) == 2 and s.count(s[1]) == 2:
      print("Yes")
    else:
      print("No")
  elif s.count(s[0]) == 2 and s.count(s[3]) == 2:
    print("Yes")
  else:
    print("No")

main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define LETSGO     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;



void solve(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    sort(all(a) , greater<int>());
    ll ans=0;
    vector<int>res;
    res.push_back(a[0]);
    for(int i=1;i<n;++i)res.push_back(a[i]) , res.push_back(a[i]);
    for(int i=0;i<n-1;++i)ans+=res[i];
    cout << ans;
}





int main(){
    LETSGO
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000500

string s, t;
int dp[3005][3005];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> s >> t;
    s = " " + s, t = " " + t;
    int n = s.size(), m = t.size();
    for (int i = 1; i < n; i++){
        for (int j = 1; j < m; j++){
            if (s[i] == t[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else{
                if (dp[i - 1][j] > dp[i][j - 1])
                    dp[i][j] = dp[i - 1][j];
                else dp[i][j] = dp[i][j - 1];
            }
        }
    }
    string ans = "";
    int i = n - 1, j = m - 1;
    while (i > 0 && j > 0){
        if (s[i] == t[j]){
            ans += s[i];
            i--;
            j--;
        }
        else{
            if (dp[i][j] == dp[i - 1][j]) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
inline LL solve(LL a,LL b){
	if(a<b)swap(a,b);
	if(a%b==0)return (a/b)*2*b-b;
	return (a/b)*2*b+solve(a%b,b);
}
int main() {
	LL n,X;
	scanf("%lld%lld",&n,&X);
	printf("%lld\n",solve(n-X,X)+n);
}

Measured memory_bytes: 256
mod = 10**9 + 7

n, k = map(int,input().split())
A = list(map(int,input().split()))

C = [0] * (max(A)+1)
a1 = 0
a2 = 0

for i in range(n):
    C[A[i]] += 1
    a2 += sum(C[A[i]+1:])
for i in range(n):
    a1 += sum(C[A[i]+1:])

a1 %= mod
a2 %= mod
#print(a1*0.5*n*(n-1))
k %= mod

if k % 2 == 0:
    kk = [k//2, k-1]
else:
    kk = [k, (k-1)//2]

ans = 0
ans += a2*k % mod
ans2 = a1*kk[0] % mod
ans2 *= kk[1] % mod
ans += ans2 % mod

print(int(ans % mod))

Measured memory_bytes: 40560
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    ll n,x,q,b,c;
    cin>>n;

    map<ll,ll> m;

    ll s=0;

    for(int i=0; i<n; i++)
    {
        cin>>x;
        m[x]++;
        s=s+x;
    }

    cin>>q;

    while(q--)
    {
        cin>>b>>c;

        s=s-(b*m[b]);

        s=s+(c*m[b]);

        m[c]=m[c]+m[b];
        m[b]=0;

        cout<<s<<endl;


    }




    return 0;
}



Measured memory_bytes: 9568
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
l = LI()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                L = max(l[i], l[j], l[k])
                s = l[i] + l[j] + l[k]
                if s - L > L:
                    ans += 1
print(ans)


Measured memory_bytes: 69156
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    vvll ans(h, vll(w));
    for(ll i = 0; i < h; i++) {
        for(ll j = 0; j < w; j++) {
            if((i < b) ^ (j < a)) ans[i][j] = 1;
        }
    }
    for(ll i = 0; i < h; i++) {
        for(ll j = 0; j < w; j++) cout << ans[i][j];
        cout << endl;
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

int main() {
	int n;
	cin >> n;
	for(int i = 111;i < 1000;i += 111)
	{
		if(n <= i)
		{
			cout << i << endl;
          break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

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>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
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> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

double solve()
{
    int n, k;
    std::cin >> n >> k;

    double res = 0;
    const double prob = 1.0 / static_cast<double>(n);

    for (int i = 1; i <= n; ++i)
    {
        if (i >= k)
        {
            res += prob;
        }
        else
        {
            int tmp = ceil(log2(static_cast<double>(k) / static_cast<double>(i)));
            res = res + prob * (std::pow(0.5, tmp));
        }
    }

    return res;
}

int main()
{
    cout << std::setprecision(10) << solve() << endl;

    return 0;
}

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

cnt = 0
r_num = s.count('R')
w_num = n - r_num

# 要はRRRRWWWWWの形にする
# r_num以内にあるRは動かさなくて良い
# r_numより外にあるRを動かす必要がある

for i in range(n):
    if i > r_num - 1 and s[i] == 'R':
        cnt += 1
print(cnt)

Measured memory_bytes: 9488
#include<iostream>
#include<cmath>
using namespace std;
int check(int a){
    bool f=0;
    for(int i=1;i*i<=a;i++){
        if(i*i==a){f=1;break;}
    }
    return f;
}
int n,d,cnt,x[10][10];
int main(){
    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int sum=0;
            for(int k=0;k<d;k++){
                int p=abs(x[i][k]-x[j][k]);
                sum+=p*p;
            }
            if(check(sum))cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, t, i, sum = 0;
    scanf("%d %d %d", &a, &b, &t);

    for (i = a; i <= t; i += a)
    {
        sum += b;
    }
    
    printf("%d", sum);

    return 0;
}

Measured memory_bytes: 1724
// EducationalDPContest.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
int main()
{
	// A - Frog 1
	int n;
	cin >> n;
	vector<long long> dp(n, INF);
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1)	chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0, a + b - n) << endl;
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 144
typedef long long ll;

int main(){

    int N;
    cin >> N;
    rep(i, 1, 9)rep(j, 1, 9){
        if(i * j == N){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#define EPS (1e-7)
using namespace std;






int main() {


	long long X, Y, ans=1;
	cin >> X >> Y;
	
	while (true) {
		X = X * 2;
		if (X <= Y) {
			ans += 1;
		}
		else {
			break;
		}
	}



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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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;
}

int main() {
  int k, n;
  cin >> k >> n;
  int a[n];
  rep(i, n) cin >> a[i];

  int ans = 1 << 30;
  rep(i, n) {
    int start = i;
    int v1 = a[start];

    int end = i - 1;
    int v2;
    if (end < 0) {
      end += n;
      v2 = a[end];
    } else {
      v2 = k + a[end];
    }

    ans = min(ans, v2 - v1);
  }

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

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    long long mn=min(x,y);
    long long ans1=0;
    long long ans2=0;
    if(x*a+y*b>=mn*2*c){
        ans1+=mn*c*2;
        if(x>y){
            long long sn=x-y;
            ans1+=min(sn*a,sn*2*c);
        }
        else{
            long long sn=y-x;
            ans1+=min(sn*b,sn*2*c);
        }
    }
    ans2+=x*a+y*b;
    if(ans1!=0)
    cout << min(ans1,ans2) << endl;
    else
    cout << ans2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#define ALL(a) (a).begin(),(a).end()

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

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

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
  ll N;
  cin>>N;
  vector <ll> A;
  vector <ll> B;
  vector <ll> C;

  FOR(i,0,N-1){
    ll tmp;
    cin>>tmp;
    A.push_back(tmp);
  }

  FOR(i,0,N-1){
    ll tmp;
    cin>>tmp;
    B.push_back(tmp);
  }
  FOR(i,0,N-1){
    ll tmp;
    cin>>tmp;
    C.push_back(tmp);
  }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  
  ll ans=0;

  FOR(i,0,N-1){
    ll tmp=B[i];
    auto ite1 = lower_bound(ALL(A), B[i]);
    auto ite2 = upper_bound(ALL(C), B[i]);
    ans+=(ite1-A.begin())*(C.end()-ite2);

    //cout<<ite1[0]<<endl;

  }

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


Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli f(lli a, lli b)
{
    return a % b ? b - a % b : 0;
}
int main()
{
    lli n;
    cin >> n;
    lli a[114514], b[114514];
    rep(i, n) cin >> a[i] >> b[i];
    lli cnt = 0;
    rrep(i, n)
    {
        lli target = f(a[i] + cnt, b[i]);
        cnt += target;
    }
    cout << cnt << endl;
};


Measured memory_bytes: 1792
#include <cstdio>
//按顺序输出数组元素
void trace(int a[], int n) {
	for (int i = 0; i < n; i++) {
		if (i > 0) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}
void insertionSort(int a[], int n) {
	int temp, j;
	for (int i = 1; i < n; i++) {
		temp = a[i]; 
		j = i - 1;
		while (j >= 0 && a[j] > temp) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = temp;
		trace(a, n);
	}
}

int main() {
    int N;
    scanf("%d", &N);
    int a[N];
    for (int i = 0; i < N; i++) {
    	scanf("%d", &a[i]);
	}
	trace(a, N);
    insertionSort(a, N);
    return 0;
}


Measured memory_bytes: 2760
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  if (s == "RRR") {
    ans = 3;
  } else if (s == "RRS" || s == "SRR") {
    ans = 2;
  } else if (s == "RSS" || s == "RSR" || s == "SRS" || s == "SSR") {
    ans = 1;
  } else {
    ans = 0;
  } 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        mll v;
        rep(i, n){
            cin >> a;
            v[a]++;
        }
        ans = 0;
        each(p, v){
            if(p.second % 2){
                ans++;
            }
        }
        print(ans);
    }
}



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

int main(){
  while(1){
    int n, x;
    cin>>n>>x;
    if(n == 0 && x == 0) break;

    int i, j, k, sum=0;
    for(i=0;i<n;i++){
      for(j=0;j<i;j++){
	for(k=0;k<j;k++){
	  if((i+1)+(j+1)+(k+1) == x) sum++;
	}
      }
    }

    cout<<sum<<endl;	 		     
		  
  }

  return 0;
}



Measured memory_bytes: 3096
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<queue>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;


void solve(long long N, long long M, std::vector<long long> A){
    priority_queue<double> pq;
    for (int ai : A) pq.push(ai);
    REP(i, M) {
        double t = pq.top();
        pq.pop();
        pq.push(t / 2);
    }
    long long ans = 0;
    while(!pq.empty()) {
        ans += (int)floor(pq.top());
        pq.pop();
    }
    cout << ans << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 2168
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int r = count(s.begin(), s.end(), 'R');
    int b = n - r;
    if(r > b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>

using namespace std;

int main()
{
    while (true) {
        int d, e;
        cin >> d >> e;
        if (d == 0 && e == 0) {
            return 0;
        }

        double min_ = numeric_limits<double>::max();
        for (int i = 1; i <= d; ++i) {
            int x = i;
            int y = (d - x);
            min_ = min(min_, abs(sqrt(x * x + y * y) - e));
        }
        cout << setprecision(12) << min_ << endl;
    }
}

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

class M{static void Main(string[] _) {
  var I0 = Console.ReadLine().Split(' ');
  var N = int.Parse(I0[0]);
  var M = int.Parse(I0[1]);
  var C = int.Parse(I0[2]);
  
  var I1 = Console.ReadLine().Split(' ');
  var B  = I1.Select(a=>int.Parse(a)).ToList();
  
  int result = 0;
  for(int I=0;I<N;++I) {
    var I2 = Console.ReadLine().Split(' ');
    var A = I2.Select(a=>int.Parse(a)).ToList();    
    int val = C;
    for( int J=0;J<A.Count();++J) {
      int a = A[J];
      int b = B[J];
      val += a * b;
    }
    if ( val > 0 ) {
      result ++;
    }
  }
  
  Console.Write(result);  
}}
        

Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v, int num=0){
  if(num == 0) num = (int)v.size();
	for(int i=0; i<num; i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

template<typename T>
struct BIT{
  int n;
  vector<T> d;
  BIT(int n=0): n(n), d(n+1){}

  void add(int i, T x=1){
    for(i++; i<=n; i+=i&(-i)){
      d[i] += x;
    }
  }
  
  T sum(int i){
    T x = 0;
    for(i++; i; i-=i&(-i)){
      x += d[i];
    } 
    return x;
  }
};

int main(){

  int INF = 100000;
  vector<int> num_divisor(INF+1, 0);
  for(int i=2; i<=INF; i++){
    for(int j=i; j<=INF; j+=i){
      num_divisor[j]++;
    }
  }

  //BITでも累積和でも解ける てか累積和のほうが知識レベル的に簡単だね
  //BIT<int> bi(INF+1);
  vector<int> wa(INF+1, 0);//累積和
  for(int i=2; i<=INF; i++){
    // if(num_divisor[i] == 1){
    //   if(num_divisor[(i+1)/2] == 1) bi.add(i);
    // }
    bool like_2017 = false;
    if(num_divisor[i] == 1){
      if(num_divisor[(i+1)/2] == 1) like_2017 = true;
    }
    wa[i] = wa[i-1] + like_2017;
  }
  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    int l, r;
    cin >> l >> r;
    //cout << bi.sum(r) - bi.sum(l-1) << endl;
    cout << wa[r] - wa[l-1] << endl;
  }

	return 0;
}



Measured memory_bytes: 3848
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  int a,b,c[3]={0,0,0};
  int flag = 0,i;
  
  for(i=0;i<3;i++){
    cin>>a>>b;
    c[a]+=1;
    c[b]+=1;
  }

  for(i=1;i<=4;i++){
//    cout<<c[i]<<endl;
    if(c[i]==0 || c[i] == 3){
      flag = 1;
    }
  }

  if(flag == 1) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int X,N;
    cin>>X>>N;
    int p[N];
    rep(i,N){
        cin>>p[i];
    }
    sort(p,p+N);
    int ans=0;
    int sum=INF;
    for(int i=-1;i<=101;i++){
        bool z=true;
        rep(j,N){
            if(i==p[j]){
                z=false;
                break;
            }
        }
        if(z){
            int w=abs(X-i);
            if(sum>w){
                sum=w;
                ans=i;
            }
        }
    }
    cout << ans << endl;

    



}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    string ans = "APPROVED";
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    for (int i=0; i<N; i++){
        if (A[i] % 2 == 0){
            if ((A[i] % 3 == 0) || (A[i] % 5 == 0)){
                continue;
            } else{
                ans = "DENIED";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    float max_val, kekka, sum=0;
    cin >> n;
    vector<float> a(n);
    
    for(int i=0; i<n; i++) cin >> a[i];
    
    max_val = *max_element(a.begin(), a.end());
    
     for(int i=0; i<n; i++) {
         sum += (max_val/a[i]);
     }
     
     kekka = max_val / sum;
    
    cout << kekka << endl;
}

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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c) cout << 1 << "\n";
  else if ((a == b && b != c) || (b == c && c != a) || (a == c && c != b)) cout << 2 << "\n";
  else cout << 3 << "\n";

  return 0;
}

Measured memory_bytes: 256
import Control.Applicative

main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ a `compare'` b

compare' :: Int -> Int -> String
compare' a b
    | ordering == LT = "a < b"
    | ordering == EQ = "a == b"
    | ordering == GT = "a > b"
    where ordering = a `compare` b

Measured memory_bytes: 3564
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n;
	cin >> n;
	int lm = 0;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int l;
		cin >> l;
		sum += l;
		lm = max(lm, l);
	}

	if (lm * 2 < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3604
import itertools

if __name__ == "__main__":
    ns = []
    xs = []

    while True:
        n, x = list(map(int, input().split()))

        if n == 0 and x == 0:
            break

        ns.append(n)
        xs.append(x)

    for n, x in zip(ns, xs):
        all_combinations = itertools.combinations(range(1, n + 1), 3)

        combinations_satisfied_sum_x = list(
            filter(lambda combination: sum(combination) == x, all_combinations)
        )

        print(len(combinations_satisfied_sum_x))


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


using namespace std;
int main()
{
	int n;
	cin >> n;
	int l[100000], k[10000];
	int sum = 0;

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

	for (int i = 0; i < n; i++) {
		sum += k[i] - l[i] + 1;
	}

	cout << sum << endl;


	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

const MOD: u64 = 1_000_000_000 + 7;

fn main() {
	let param = read_vector::<usize>();
    let (n, k) = (param[0], param[1] as u64);
    let mut adj = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let line = read_vector::<usize>();
        let (a, b) = (line[0] - 1, line[1] - 1);
        adj[a].push(b);
        adj[b].push(a);
    }
    println!("{}", paint(&adj, k));
}

fn paint(adj: &[Vec<usize>], k: u64) -> u64 {
    let mut stack = vec![(0, 0)];
    let mut ans = k;
    let mut used = vec![false; adj.len()];
    let mut valid_children = vec![0; adj.len()];
    while stack.len() > 0 {
        let (p, index) = stack.pop().unwrap();
        used[p] = true;
        if index >= adj[p].len() {
            continue;
        }
        stack.push((p, index + 1));
        if used[adj[p][index]] {
            continue;
        }
        if stack.len() > 1 {
            ans = (ans * (k - 2 - valid_children[p])) % MOD;
        } else {
            ans = (ans * (k - 1 - valid_children[p])) % MOD;
        }
        valid_children[p] += 1;
        stack.push((adj[p][index], 0));
    }
    ans
}

#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .trim()
        .parse()
        .unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    use std::io::prelude::*;
    let stdin = stdin();
    return stdin
        .lock()
        .lines()
        .map(|line| line
            .unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect())
        .collect();
}

Measured memory_bytes: 16636
#include <bits/stdc++.h>
using namespace std;
int n,k,a[200005],sum,ans;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i]; 
	for(int i=0;i<k;i++)
		sum+=a[i];
	ans=sum;
	for(int i=0;i+k<n;i++)
	{
		int l=i,r=i+k;
		sum=sum-a[l]+a[r];
		ans=max(ans,sum);
	}
	double anss=ans+k;
	anss/=2;
	printf("%.12f\n",anss);
	return 0;
}

Measured memory_bytes: 1024
A,B,K = map(int,input().split())
L = 0
ans = 0
for i in reversed(range(1,2000)):
  if A%i == 0:
    if B%i == 0:
      L += 1
    else:
      L += 0
  else:
    L += 0
  if L == K:
    ans = i
    break
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

int main(){
  int n,k;
  int i,j;
  int count;
  double sum=0;
  scanf("%d%d",&n,&k);
  int h[n];
  for(i=1;i<=n;i++){
    j=i;
    count=0;
    while(j<k){
      j=j*2;
      count++;
    }
    h[i-1]=count;
  }
  double s[n];
  double tmp;
  double tmpp;
  for(i=1;i<=n;i++){
    tmp=1.0/(double)n;
    tmpp=(pow(0.5,(double)h[i-1]));
    s[i-1]=(tmp*tmpp);
  }
  for(i=0;i<n;i++){
    sum+=s[i];
  }


    printf("%.12lf",sum);
    return 0;
}


Measured memory_bytes: 1280
program prob2
    implicit none
    integer::i, l, cnt, k, j
    character(len=200005)::S
    character(len=2)::a
    read(*,*) S
    l = len_trim(S)

    a = S(1:1)
    cnt = 1
    i = 2
    do while(i <= l)
        k = len_trim(a)
        if(k > 1) then
            a = S(i:i)
            i = i+1
            cnt = cnt + 1
        else
            if(S(i:i) .ne. a(1:1)) then
                a = S(i:i)
                i = i+1
            else if(i /= l) then
                a = S(i:i+1)
                i = i+2
            else
                exit
            end if
            cnt = cnt + 1
        end if
    end do

    write(*,*) cnt
    stop
end program prob2

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

using namespace std;

bool used[5010];
vector<int> lose[5010], ans;

void func(int s) {
  used[s] = true;
  for (int i = 0; i < lose[s].size(); i++) {
    int v = lose[s][i];
    if (used[v]) continue;
    func(v);
  }
  ans.push_back(s);
}

int main(void) {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int w, l;
    cin >> w >> l;
    w--, l--;
    lose[l].push_back(w);
  }

  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    func(i);
  }

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

    bool link = false;
    for (int j = 0; j < lose[a].size(); j++) {
      link |= lose[a][j] == b;
    }
    for (int j = 0; j < lose[b].size(); j++) {
      link |= lose[b][j] == a;
    }
    if (!link) flag = 1;
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] + 1 << endl;
  }
  cout << flag << endl;

  return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <complex>
#include <iomanip>
#include <assert.h>
using namespace std;
typedef complex<double> P;
const double EPS = 1e-10;
int n;
double l[10];

struct C {
	P p;
	double r;

	C() {
		p = P(0, 0);
		r = 0;
	}

	C(const P& p, double r) : p(p), r(r) {
	}

	bool in(P t) {
		return norm(p - t) < r * r + EPS;
	}

	bool in(C t) {
		return abs(p - t.p) + t.r < r + EPS;
	}
} c[10];

bool check(double h) {
	for (int i = 0; i < n; i++) {
		if (l[i] * l[i] - h * h < EPS) return false;
		c[i].r = sqrt(l[i] * l[i] - h * h);
	}

	vector<P> cs;
	for (int i = 0; i < n; i++) {
		cs.push_back(c[i].p);
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			C c1 = c[i], c2 = c[j];
			if (abs(c1.p - c2.p) > c1.r + c2.r) return false; // ????????????
			if (c1.in(c2) || c2.in(c1)) continue;

			P v = c2.p - c1.p;
			double t = (c1.r * c1.r + norm(v) - c2.r * c2.r) / (2 * abs(v));
			double theta = acos(t / c1.r);
			//assert(-1.0 <= t / c1.r && t / c1.r <= 1.0);
			P b[2];
			b[0] = c1.p + v / abs(v) * c1.r * polar(1.0, theta);
			b[1] = c1.p + v / abs(v) * c1.r * polar(1.0, -theta);
			cs.push_back(b[0]);
			cs.push_back(b[1]);
		}
	}

	for (int i = 0; i < cs.size(); i++) {
		bool flag = true;
		for (int m = 0; m < n; m++) {
			if (!c[m].in(cs[i])) {
				flag = false;
				break;
			}
		}
		if (flag) return true;
	}
	return false;
}

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

	while (cin >> n , n) {
		for (int i = 0; i < n; i++) {
			double x, y;
			cin >> x >> y >> l[i];
			c[i].p = P(x, y);
		}
		check(0);
		double ok = 0, ng = 100000;
		for (int loop = 0; loop < 1000; loop++) {
			double h = (ok + ng) / 2;
			if (check(h)) ok = h;
			else ng = h;
		}
		cout << setprecision(15) << ok << endl;
	}
}

Measured memory_bytes: 1400
//0006 Reverse Sequence
//^¦çê½¶ñð½]µ½àÌðoÍµÈ³¢
//È¨AüÍ³êé¶ñÍ20¶ÈºÆ·é

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(void)
{
	string str;
	while( cin >> str)
	{
		reverse(str.begin(), str.end());
		cout << str << endl;
	}
}

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

const int MAX = 10005;

bool linearSearch(int A[], int n, int key) {
  A[n] = key;
  int i {0};
  while (A[i] != key) i++;
  return i != n;
}

int main() {
  int S[MAX];
  int T[MAX];
  int n {0}, q {0};
  int cnt {0};

  // input
  cin >> n;
  for (int i = 0; i < n; i++) cin >> S[i];

  cin >> q;
  for (int i = 0; i < q; i++) cin >> T[i];

  // main part
  for (int i = 0; i < q; i++) {
    if (linearSearch(S, n, T[i])) cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3116
H, W = gets.split.map(&:to_i)

G = []

H.times do
  a = Array.new(W)
  line = gets.chomp + '#'
  i, j = 0, 0
  while i <= W
    if line[i] == '#'
      if j < i
        c = i - j
        k = j
        while k < i
          a[k] = c
          k += 1
        end
      end 
      i += 1
      j = i
    else
      i += 1
    end
  end
  G << a
end 
G << Array.new(W)

ans = 0
for x in (0...W)
  i, j = 0, 0
  local_max = 0
  while i <= H
    v = G[i][x]
    if v.nil?
      if j < i
        local_max += (i - j)
        ans = local_max if ans < local_max
        local_max = 0
      end 
      i += 1
      j = i
    else
      local_max = v if local_max < v  
      i += 1
    end 
  end 
end
puts ans - 1

Measured memory_bytes: 34452
amax = int(input())
bmax = int(input())
cmax = int(input())
x = int(input())
q = 0
for a in range(amax+1):
    for b in range(bmax+1):
        for c in range(cmax+1):
            if 500*a+100*b+50*c == x:
                q += 1
print(q)

Measured memory_bytes: 3060
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
lst=[a,b,c,d,e,f,g,h,i]
for i in range(int(input())):
  x=int(input())
  for j in range(9):
    if x==lst[j]:
      lst[j]=0
a,b,c,d,e,f,g,h,i=lst
tf=0
for k in [a+b+c,d+e+f,g+h+i,a+d+g,b+e+h,c+f+i,a+e+i,c+e+g]:
  if not k:
    tf=1
    break
if tf:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Vacation
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int K = 3;

/* typedef */

/* global variables */

int dp[MAX_N + 1][K];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    for (int j = 0; j < K; j++) {
      int aij;
      scanf("%d", &aij);
      setmax(dp[i + 1][j], aij + max(dp[i][(j + 1) % K], dp[i][(j + 2) % K]));
    }

  printf("%d\n", max(max(dp[n][0], dp[n][1]), dp[n][2]));
  return 0;
}


Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {

        int[] AB = new int[2];
        AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int concent_count=1;
        int i =0;

        while (AB[1] > concent_count)
        {
            i++;
            concent_count = i*AB[0] - 1 * i+1;            
        }
        Console.WriteLine(i);
    }

}


Measured memory_bytes: 13396