akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll mod = 998244353;
long long ruijo(long long  k,ll m){
	if(m==0)return 1;
	if(m==1)return k%mod;
	long long s = ruijo(k,m/2);
	if(m%2==0){
		return (s*s)%mod;
	}else{
		long long ans;
		ans = (s*s)%mod;
		return (k*ans)%mod;
	}
}
int main(){
    ll n,a,b,k;
    cin >> n >> a >> b >> k;
    vector<long long> p(n+2);
    p[0]=1,p[1]=1;
    vector<long long> inv(n+2);
    for(long long i=2;i<n+2;i++){
        p[i] = (p[i-1]*i)%mod;
    }
    inv[n+1] = ruijo(p[n+1],mod-2);
    for(long long i=n;i>=0;i--){
        inv[i] = ((i+1)*inv[i+1])%mod;
    }
    ll ans = 0;
    for(ll i=0;i<=n;i++){
        if(k-a*i<0)continue;
        if((k-a*i)%b==0){
            ll s = (k-a*i)/b;
            if(s<=n){
                ll tmp = p[n]*inv[i]%mod;
                tmp = tmp*inv[n-i]%mod;
                tmp = tmp*p[n]%mod;
                tmp = tmp*inv[s]%mod;
                tmp = tmp*inv[n-s]%mod;
                //cout << i << " " << s << " "<< tmp << endl;
                ans = (ans +tmp)%mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    long long power = 1;
    int b = 1000000007;
    for(int i = 0;i<N;i++){
        power = power * (i+1);
        power = power % b;
    }
    cout << power << endl;
}

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

using namespace std;

#define MAX_N 100
#define MAX_M 100

int main(){
  int N,M,A[MAX_M],B;
  cin >> N >> M;
  for(int i = 0 ; i < M ; i++){
    cin >> A[i]; A[i]--;
  }
  int point[MAX_N] = {0};
  for(int i = 0 ; i < M ; i++){
    int X = 0;
    for(int j = 0 ; j < N ; j++){
      cin >> B; B--;
      if(A[i] != B){ X++; }
      else{ point[j]++; }
    }
    point[A[i]] += X;
  }
  for(int i = 0 ; i < N ; i++){
    cout << point[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
using namespace std;
int insertionSort(int a[],int n,int g){
    int temp;
    int pre=g;
    int i=0;
    int cnt=0;
    while(pre<n){
        temp=a[pre];
        for(i=pre-g;i>=0;i-=g){
            if(a[i]>temp){
                a[i+g]=a[i];
                cnt++;
            }
            else{break;}
        }
        if(temp!=a[pre])
            a[i+g]=temp;
        pre+=1;
    }
    return cnt;
}
int shellSort(int a[],int n){
    vector <int> G;
    G.push_back(1);
    while(G.at(G.size()-1)<n){
        G.push_back(G.at(G.size()-1)*3+1);
    }
    if(G.size()!=1)
        G.pop_back();
    int cnt=0;
    cout<<G.size()<<endl;
    for(int i=G.size()-1;i>=0;i--){
        cnt+=insertionSort(a,n,G[i]);
        if(G[i]!=1)cout<<G[i]<<" ";
        else cout<<1<<endl;
    }
    return cnt;
}
int main()
{
    int n;
    cin>>n;
    int *a=new int [n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int cnt=shellSort(a,n);
    cout<<cnt<<endl;
    for(int i=0;i<n-1;i++){
        cout<<a[i]<<endl;
    }
    cout<<a[n-1];
    return 0;
}



Measured memory_bytes: 6920
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
#define pi 3;
int  main()
{
	int r;
	cin >> r;
	int x = 1;
	int area = r*r*pi;
	int xarea = x*x*pi;
	cout << area / xarea << endl;
	// cout << area;
	return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

vector<int> v;

int main() {
    int n;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        int c;
        cin >> c;
        v.push_back(c);
    }
    
    int mini = 0;
    sort(v.begin(), v.end());
    for ( int i = 0; i < n - 1; i++ ) {
        mini += v[i + 1] - v[i];
    }
    
    cout << mini << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a[5];
  for(int i = 0; i < 5; i++) {
    cin >> a[i];
    if(a[i] == 0) {
      cout << i + 1 << endl;
    }
  }
}
  

Measured memory_bytes: 3584
import sys
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n = int(input())
if n == 1:
    print(0)
    sys.exit()
res = factorization(n)
d = dict()
for i,j in res:
    d[i] = j
ans = 0
for n in d.keys():
    for i in range(100):
        #print(d[n],i*(i+1)//2)
        if d[n] < i*(i+1)//2:
            ans += i-1
            break
        else:
            pass
print(ans)

Measured memory_bytes: 63384
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long

int N,T;
int dp[3005][3005];
//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> T;

  vector<pair<int,int>> p(N);
  REP(i,N){
  	cin >> p[i].first >> p[i].second;
  }
  int ans = 0;
  sort(all(p));
  REP(i,N){
  	REP(j,T){
  		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
  		int nj = j + p[i].first;
  		if(nj < T){
  			dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + p[i].second);
  		}
  	}
  	int now = dp[i][T-1] + p[i].second;
  	ans = max(ans,now);
  }
  cout << ans << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 70784
object Main {

    def main(args: Array[String]): Unit = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val a = Array.fill(n)( (sc.next, sc.nextInt) )
        val found = a.map{
            case (suit, num) => cards_toIndex(suit, num)
        }.toSet

        ((0 to 51).toSet &~ found).toSeq.sorted.foreach{
            i => {
                i/13 match {
                    case 0 => println("S " + (i%13+1))
                    case 1 => println("H " + (i%13+1))
                    case 2 => println("C " + (i%13+1))
                    case 3 => println("D " + (i%13+1))
                }
            }
        }
    }

    // 0 to 51
    def cards_toIndex(suit: String, num: Int): Int = {
        suit match {
            case "S" => num-1
            case "H" => 13+num-1
            case "C" => 26+num-1
            case "D" => 39+num-1
            case _ => -1
        }
    }

}



Measured memory_bytes: 45108
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    cout<<N*N*N<<endl;
}


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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, l, r, ans = 0;
	cin >> n;
	while (n--) {
		cin >> l >> r;
		ans += r - l + 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7, INF = 1e9 * 1e7 * 100;

vector<bool> graph[2];
set<ll> st;
vector<pair<ll, ll>> vec;

ll dp[500][500];

int main() {
    fastInp;

    ll n, c, s = 1, sm = 0;
    cin >> n >> c;

    vec.resize(n);
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a;
        vec[i].first = a;
    }

    for (int i = 0; i < n; i++) {
        ll b;
        cin >> b;
        vec[i].second = b;
    }

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        ll curS = 0;
        for (int curA = vec[i - 1].first; curA <= vec[i - 1].second; curA++) {
            curS = 0;
            for (int j = 0; j <= c; j++) {
                dp[i][j] += dp[i - 1][j];
                if (j > 0) dp[i][j] += curS;
                curS *= curA;
                curS += dp[i - 1][j] * curA;
                curS %= MOD;
                dp[i][j] %= MOD;
            }
        }
    }

    cout << dp[n][c];
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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(){
    cout << fixed << setprecision(10);
    int n,m,t;
    cin >> n  >> m >> t;
    vector<int> v(n,0);
    rep(i,n) cin >> v[i];
    ll ans = 0;
    int now = 0;
    ans += v[0] - now - m;
    now = v[0];
    bool ie = 0;
    rep(i,n){
        if(i == 0) continue;
        if(v[i] - now > 2*m){
            // cout << "Yes" << endl;
            ans += v[i] - now - 2*m;
            //家に戻る
            now = v[i];
        }else{
            now = v[i];
        }
    }
    // cout << ans << endl;
    ans += max(0,t -  v[n-1] - m);
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n,d; cin>>n>>d; 
  vector<vector<int>> X(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>X[i][j];
    }
  }
  int sum=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      int dis=0;
      for(int k=0;k<d;k++){
        dis+=pow(X[i][k]-X[j][k],2);
      }
      bool flag=false;
      for(int k=1;k*k<=dis;k++){
        if(dis==k*k){
          flag=true;
          break;
        }
      }
      if(flag) sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        scan.nextLine();

        int[] x = new int[n];
        for(int i = 0; i < n; i++) {
            x[i] = scan.nextInt();
        }
        scan.nextLine();

        int m = scan.nextInt();
        scan.nextLine();

        // int[] a = new int[m];
        int a;
        for(int j = 0; j < m; j++) {
            // a[j] = scan.nextInt();
            a = scan.nextInt();

            if (a == n) {
                if (x[a - 1] < 2019) {
                    x[a - 1]++;
                }
            } else {
                if (x[a - 1] + 1 < x[a]) {
                    x[a - 1]++;
                }
            }
        }
        scan.nextLine();

        scan.close();

        for (int i = 0; i < n; i++) {
            System.out.println(x[i]);
        }
    }
}


Measured memory_bytes: 26400
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

int a[arr];
int b[arr];

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+n+1);
    int ans=0;
    for (int i=1;i<=n;i+=2){
        int pos_in_b=lower_bound(b+1,b+n+1,a[i])-b;
        if (pos_in_b%2==0){
            ans++;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 1792
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#define ll long long
using namespace std;

int main(){
    int N;
    string S;
    cin>>N>>S;
    ll Rn=0,Gn=0,Bn=0;


    for(int i=0;i<N;i++){
        if(S[i]=='R'){
            Rn++;
        } 
        else if(S[i]=='G'){
            Gn++;
        }
        else if(S[i]=='B'){
            Bn++;
        }
    }
    ll comn=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(2*j-i<N){
                if(S[i]!=S[j]&&S[i]!=S[2*j-i]&&S[j]!=S[2*j-i]){
                    comn++;
                }
            }
            
        }    
    }
    
    cout<<Rn*Bn*Gn-comn<<endl;
    return 0;
}

Measured memory_bytes: 3604
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,tk,ao = MI()
    tk-=1
    ao-=1

    AB=LLIN_(N-1)
    edge = [[]for _ in range(N)]
    for a,b in AB:
        edge[a].append(b)
        edge[b].append(a)
    
    dist_from_tk = [-inf]*N
    dist_from_ao = [-inf]*N
    
    dist_from_ao[ao]=0
    q = deque([ao])
    while q:
        fr = q.popleft()
        for to in edge[fr]:
            if dist_from_ao[to]!=-inf:
                continue
            # print(fr,to,dist_from_ao)
            dist_from_ao[to]=dist_from_ao[fr]+1
            q.append(to)
    # print(dist_from_ao)

    dist_from_tk[tk]=0
    q = deque([tk])
    mid = -inf
    add_flag=0
    while q:
        fr = q.popleft()
        for to in edge[fr]:
            if dist_from_tk[to]!=-inf:
                continue
            if dist_from_ao[to]<=dist_from_tk[fr]+1:
                mid = fr
                if(dist_from_ao[to]==dist_from_tk[fr]+1):
                    add_flag=1
                continue
            # print(fr,to,dist_from_tk)
            dist_from_tk[to]=dist_from_tk[fr]+1
            q.append(to)
    # print("#########")
    # print(dist_from_ao)
    # print(dist_from_tk)
    # print(mid)


    dist_from_mid = [-inf]*N
    dist_from_mid[mid]=0
    q = deque([mid])
    while q:
        fr = q.popleft()
        for to in edge[fr]:
            if dist_from_mid[to]!=-inf:
                continue
            if dist_from_tk[to]==-inf:#到達不可
                continue
            # print(fr,to,dist_from_mid)
            dist_from_mid[to]=dist_from_mid[fr]+1
            q.append(to)
    # print(dist_from_mid)
    
    if dist_from_ao[tk]==1 and max(dist_from_tk)==0: ##自滅
        print(0)
    elif max(dist_from_tk)==0: ##動いたらすぐ死ぬ
        print(1)
    else:
        ans = dist_from_tk[mid]+max(dist_from_mid)
        print(ans+add_flag)
    # print(dist_from_tk[mid],max(dist_from_mid))

if __name__ == '__main__':
    main()

Measured memory_bytes: 87516
def pow(b, e):
    res = 1
    while e:
        if e & 1:
            res = (res * b) % MOD
        e >>= 1
        b = (b * b) % MOD
    return res


MOD = 10 ** 9 + 7
N, K = map(int, input().split())
counts = [0] * (K + 1)
ans = 0
for i in range(K, 0, -1):
    counts[i] = pow(K // i, N)
    for j in range(i + i, K + 1, i):
        counts[i] = (counts[i] + MOD - counts[j]) % MOD
    ans = (ans + i * counts[i]) % MOD
print(ans)


Measured memory_bytes: 69976
#include <stdio.h>
int main() {
	char s[3+1];
	scanf("%s",&s);
	
	if (s[1] == 'B')
	{
		printf("ARC\n");
	}
	else if (s[1] == 'R')
	{
		printf("ABC\n");
	}
	
	return 0;
}


Measured memory_bytes: 1584
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define INF 1e9+7
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

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

Measured memory_bytes: 1792
def minimum_cost(A, m, k):
    """整数列 A を最小コストソートでソートした場合の総コストを返す。

    A 内の整数は 0 <= <= k のすべて異なる整数であり、
    m がその中で最小の数。
    """
    # A 内の整数 i の出現数を C[i] に記録していく。
    C = [0 for _ in range(0, k + 1)]
    for x in A:
        C[x] += 1
    
    # A 内の i 番目の整数のソート後の位置（0 起点）を C[i] に記録する。
    C[0] -= 1
    for i in range(1, k + 1):
        C[i] += C[i - 1]

    total_cost = 0
    n = len(A)
    for i in range(n):
        j = i
        length = 0
        sum_weight = 0
        cur_min = k + 1
        while C[A[j]] >= 0:
            length += 1
            sum_weight += A[j]
            if A[j] < cur_min:
                cur_min = A[j]
            z = C[A[j]]
            C[A[j]] = -1
            j = z
        if length >= 3:
            if cur_min > m:
                total_cost += min(sum_weight + cur_min * (length - 2),
                                  (sum_weight - cur_min) + m * (length - 1) + 2 * (m + cur_min))
            else:
                total_cost += sum_weight + cur_min * (length - 2)
        elif length == 2:
            total_cost += sum_weight

    return total_cost

if __name__ == '__main__':
    import sys

    n = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    print(minimum_cost(A, min(A), max(A)))


Measured memory_bytes: 5792
#include <stdio.h>

int main()
{
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	
	int P1, P2;
	P1 = A * N;
	P2 = B;
	
	if ( P1 <= P2 ){
		printf("%d\n", P1);
	}
	
	else{
		printf("%d\n", P2);
	}
	
	return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  
  vector<int> s(n);
  rep(i,k){
    int m;
    cin >> m;
    
    rep(j,m){
      int a;
      cin >> a;
      s[a-1]=1;
    }
  }
  
  int ans=0;
  rep(i,n) if(s[i]==0) ans++;
  
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define rrep(i,a) for(int i=a; i>=0; --i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    vector<ll> t(N);
    rep(i,N){
        cin>>t[i];
    }
    ll ans=1;
    rep(i,N){
        ans = LCM(ans,t[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef map<string, int> M;

int main() {
  int n, t, f;
  string c, ans, first;
  vector<int> v;
  while(cin >> n, n){
    M m;
    t = 0;
    f = 1;
    for (int i = 0; i < n; ++i){
      cin >> c;
      m[c] += 1;
      v.erase(v.begin(), v.end());
      for (M::iterator itr = m.begin(); itr != m.end(); ++itr) {
	v.push_back(-itr->second);
	if (itr->second > t) {
	  first = itr->first;
	  t = itr->second;
	}
      }
      sort(v.begin(), v.end());
      if (f && ((v.size() > 1 && -v[1]+n-1-i < t) || -v[0] > n/2)) {
	cout << first << " " << i+1 << endl;
	f = 0;
      }
    }
    if (f) cout << "TIE" << endl;
    m.erase(m.begin(), m.end());
  }
  return 0;
}

Measured memory_bytes: 3192
U = 10**5
is_prime = [1]*(U+1)
is_prime[0] = 0
is_prime[1] = 0
for p in range(2, int(U**.5)+1):
    if is_prime[p]:
        for q in range(2*p, U+1, p):
            is_prime[q] = 0

A = [0]*(10**5+1)
for i in range(1, U+1, 2):
    if is_prime[i] and is_prime[(i+1)//2]:
        A[i] = 1


S = [0]*(10**5+1)
for i in range(1, 10**5+1):
    S[i] = S[i-1]+A[i]


q = int(input())
for _ in range(q):
    L, R = map(int, input().split())
    ans = S[R]-S[L-1]
    print(ans)

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

int main(){
  string s;
  while(1){
    getline(cin,s);
    if(cin.eof()) break;
    for(int i=0;i<25;i++){
      if((s.find("this")!=string::npos) || (s.find("that")!=string::npos) || (s.find("the")!=string::npos)) break;
      for(int j=0;j<=s.size();j++){
	if(s[j] >= 'a' && s[j] <= 'y') s[j]++;
	else if(s[j] == 'z') s[j]='a';
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef bitset<35> sta;

int n;

int main(){
	cin>>n;
	if (n==(n&-n)){
		cout<<"No"<<endl;
		return 0;
	}
	printf("Yes\n%d %d\n%d %d\n%d %d\n%d %d\n%d %d\n",1,2,2,3,3,n+1,n+1,n+2,n+2,n+3);
	int x,y;
	for (int i=5;i<=n;i+=2){
		if ((n^1^(i-1))>=2) x=i-1,y=n^1^(i-1);
		if ((n^1^i)>=2) x=i,y=n^i^1;
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",i-1,i,i+n,i-1+n,i-1,n+1,i+n,n+1);
	}
	if (n%2==0){
		if ((x==2 || x%2==1)&&x!=3) x+=n;
		if ((y==2 || y%2==1)&&y!=3) y+=n;
		printf("%d %d\n%d %d\n",n,x,2*n,y);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>


int main(void){
  int n;
  int a,v;
  int retNum=100;
  int retFish=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&a,&v);
    if(v>retFish){
      retFish=v;
      retNum=a;
    }
    else if(v==retFish){
      if(retNum>a){
        retNum=a;
      }
    }
  }
  printf("%d %d\n",retNum,retFish);
  return 0;
}



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

int main(){
    string s;
    cin >> s;
    int ans = 1000;
    rep(i, 26){
        int res = 0;
        int t = 0;
        rep(j, s.size()){
            if (s[j] == 'a' + i){
                res = max(res, t);
                t = 0;
            }else t++;
        }
        res = max(res, t);
        ans = min(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

ll ans = 0;
int N;
vector<int> B;
vector<ll> masks;
vector<vector<int>> G;

void rec(int n,ll mask,ll cost,vector<ll>& sum){
    if(n == N){
        ans = max(ans,cost);
        return;
    }
    for(int i = n; i < N;i++){
        if(cost+sum[i] <= ans) break;
        if((mask>>i)&1) continue;
        rec(i+1,mask | masks[i],cost+B[i],sum);
    }
    rec(N,mask,cost,sum);
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N,N){
        ans = 0;
        map<string,int> A2idx;
        vector<string> A(N);
        B = vector<int>(N);
        vector<vector<string>> D(N);
        for(int i = 0; i < N;i++){
            cin >> A[i] >> B[i];
            A2idx[A[i]] = i;
            int C; cin >> C;
            for(int j = 0; j < C;j++){
                string S; cin >> S;
                D[i].push_back(S);
            }
        }
        
        G =  vector<vector<int>>(N);
        for(int i = 0; i < N;i++){
            for(auto S:D[i]){
                G[i].push_back(A2idx[S]);
            }
        }
        
//        for(int i = 0; i < N;i++){
//            cout << i << " : "; for(auto v:G[i]) cout << v << " "; cout << endl;
//        }
        
        
        masks = vector<ll>(N);
        for(int i = 0; i < N;i++){
            masks[i] |= (1LL<<i);
            for(auto v:G[i]){
                masks[i] |= (1LL<<v);
            }
        }
        
        
        vector<ll> sum(N);
        for(int i = 0; i < N;i++){
            for(int j = i; j < N;j++){
                sum[i] += B[j];
            }
        }
        
        rec(1,masks[0],B[0],sum);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3360
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s.back()=='s')
            cout<<s<<"es"<<endl;
        else
            cout<<s<<"s"<<endl;
    }
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main(){
  int m1, d1;
  int m2, d2;
  cin >> m1 >> d1;
  cin >> m2 >> d2;

  if( d2 == 1 ){
    cout << 1 << endl;
  }else{
    std::cout << 0 << '\n';
  }

  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<llint> vllint;
typedef vector<vllint> vvllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define coutans rep(i, ans.size())cout << ans[i] << endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int n, m;
	cin >> n >> m;
	vvint a(n + 1, vint(m + 1, 0));
	rep(i, n) {
		rep(j, m)cin >> a[i][j];
	}
	rep(i, n) {
		rep(j, m)a[i][m] += a[i][j];
	}
	rep(j, m) {
		rep(i, n)a[n][j] += a[i][j];
	}
	rep(i, n) {
		a[n][m] += a[i][m];
	}
	rep(i, n + 1) {
		rep(j, m + 1) {
			cout << a[i][j];
			if (j == m)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a,b,ms,ns;
		a = sc.nextInt();
		b = sc.nextInt();
		ms = a*b;
		ns = 2*(a+b);
		System.out.println(ms+" "+ns);
	}
}

Measured memory_bytes: 17160
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

struct Rect{long long h; int w_pos;};

int main(){
	int N;
	long long c[100001]={};
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lld",&c[i]);
	}
	
	long long ans=0;
	stack<Rect> s;
	for(int j=0;j<=N+1;j++){
		Rect rect;
		rect.h = c[j];	
		rect.w_pos = j;
		if(s.empty()) s.push(rect);
		else{
			if(s.top().h < rect.h) s.push(rect);
			else if(s.top().h > rect.h){
				int t=j;
				while(!s.empty() && s.top().h >= rect.h){
					Rect pre=s.top();
					s.pop();
					long long area=pre.h * (j-pre.w_pos);
					ans = max(ans,area);
					t=pre.w_pos;
				}
				rect.w_pos=t;
				s.push(rect);
			}
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 5360
#include <iostream>

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


Measured memory_bytes: 3084
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

#define N 20010
#define M 1005
#define LLINF 2000000000000000000LL
ll dp[N];

int main(){
  int n,m,k;
  ll a[N];

  scanf("%d%d%d",&n,&m,&k);

  for(int i=0;i<=n;i++){
    dp[i] = LLINF;
  }

  for(int i=0;i<n;i++){
    scanf("%lld",a+i);
  }
  
  dp[0] = 0;

  for(int i=0;i<n;i++){
    ll min_a = LLINF;
    ll max_a = 0;

    for(int j=0;j<m;j++){
      if(i+j >= n) break;
      
      min_a = min(min_a,a[i+j]);
      max_a = max(max_a,a[i+j]);

      dp[i+j+1] = min(dp[i+j+1],dp[i]+(k+(j+1)*(max_a-min_a)));
    }
  }
      
  printf("%lld\n",dp[n]);

  return 0;
}

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

using namespace std;

int a, b, c, x, y; 

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> a >> b >> c >> x >> y;
	if (a + b <= 2 * c)
		cout << a * x + b * y << endl;
	else
	{
		int z = min(x, y);
		int res = z * 2 * c;
		x -= z, y -= z;
		res += min(2 * c, a) * x;
		res += min(2 * c, b) * y;
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
print(ceil(N/2))


Measured memory_bytes: 5780
#include <iostream>
#include<math.h>

using namespace std;


int main() {

    int D, N;

    cin >> D >> N;

    //
    if( N != 100 )
    {
        cout << ((int)pow(100,D)) * N << endl;
    }
    else
    {
        cout << ((int)pow(100,D))*101 << endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
   int v,h,t,s;
   scanf("%d",&v);
   h = v / 3600;
   t = v / 60-h*60;
   s = v -t*60 -h*3600;
   printf("%d:%d:%d\n", h, t, s);
   return 0;
}

Measured memory_bytes: 1808
# editorial

def main():
    from operator import itemgetter

    N = int(input())
    reds = [tuple(map(int, input().split())) for _ in range(N)]
    blues = [tuple(map(int, input().split())) for _ in range(N)]

    reds.sort(key=itemgetter(0))
    blues.sort(key=itemgetter(0))

    used = [0] * N
    for bx, by in blues:
        mai = -1
        may = -1
        for i, (is_used, (rx, ry)) in enumerate(zip(used, reds)):
            if is_used: continue
            if rx >= bx: break
            if (ry >= by) or (~mai and may >= ry): continue
            mai = i
            may = ry
        if ~mai:
            used[mai] = 1

    print(sum(used))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<cmath>

using namespace std;

#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b

int main()
{
	int n;
	cin>>n;
	int maxdel = -1010101010;
	int minval = 0x7FFFFFFF;
	int num;
	for(int i=0;i<n;i++){
		cin>>num;
		maxdel = max(maxdel,(num-minval));
		minval = min(minval,num);
	}
	cout<<maxdel<<endl;
	return 0;
}


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

using namespace std;

int ct;

int GCD(int m, int n);

int main()
{
	int m, n;
	
	while (cin >> m >> n, m, n){
		ct = 1;
		if (m < n){
			swap(m, n);
		}
		int gcd = GCD(m, n);
		cout << gcd << ' ' << ct << endl;
	}
	
	return (0);
}

int GCD(int m, int n)
{
	int r;
	
	while (m % n != 0){
		r = n;
		n = m % n;
		m = r;
		ct++;
    }
	
	return (n); 
}

Measured memory_bytes: 1160
program main
    implicit none
    integer(8) n,m,k
    integer(8), allocatable, dimension(:) :: a, b
    integer(8) i, j, time, na, nb, c, cmax

    read(*,*) n,m,k
    allocate(a(n))
    read(*,*) a
    allocate(b(m))
    read(*,*) b

    time = 0
    do i = 1, n
        time = time + a(i)
        if(time > k) then
            time = time - a(i)
            na = i-1
            c = i-1
            exit
        end if
        if(i == n) then
            na = n
            c = n
        end if
    end do


    do i = 1, m
        time = time + b(i)
        if(time > k) then
            time = time - b(i)
            nb = i-1
            exit
        end if
        c = c + 1
    end do


    cmax = c

    if (c == (n+m)) then
        write(*,*) c
    else
        do i = 0, na-1
            time = time - a(na-i)
            c = c - 1
            do j = nb+1, m
                time = time + b(j)
                if(time > k) then
                    time = time - b(j)
                    nb = j-1
                    exit
                end if
                c = c + 1
            end do
            if(c > cmax) then
                cmax = c
            end if
        end do

        write(*,*) cmax
    end if


end program


Measured memory_bytes: 6080
"use strict";
function Main(input) {
    let at = input.split("\n").map((v) => v - 0);
    let k = at[5];
    let d = at[4] - at[0];
    console.log((d > k) ? ':(' : 'Yay!');
}
if (typeof window === 'undefined') Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <stdio.h>
#include <string.h>

int main(void) {
    int n, i;
    scanf("%d", &n);
    int a[n + 1];
    int ball[n + 1];  /* i 番目に ball を入れたら ball[i] = 1 */
    for ( i = 1; i <= n ; i++ ) {
        scanf("%d", &a[i]);
        ball[i] = 0;
    }
    int ball_sum = 0, temp_sum, x;
    for ( i = n; i > 1; i-- ) {
        temp_sum = 0;
        x = 2;
        while ( (i * x) <= n ) {
            if ( ball[i * x] == 1 ) {
                temp_sum++;
            }
            x++;
        }
        if ( a[i] != temp_sum % 2 ) {
            ball[i] = 1;
            ball_sum++;
        }
    }
    /* 一番目の箱に入れるかどうか */
    if ( a[1] != ball_sum % 2 ) {
        ball[1] = 1;
        ball_sum++;
    }
    printf("%d\n", ball_sum);
    if ( ball_sum != 0 ) {
        for ( i = 1; i <= n; i++ ) {
            if ( ball[i] == 1 ) {
                printf("%d ", i);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2432
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then Enum.empty ()
  else
    List.map (fun _ -> scan fmt f) (List.range 1 `To n)
    |> List.enum

let scan_list cnv =
  String.split_on_char ' ' @@ read_line ()
  |> List.map cnv

let scan_array cnv = Array.of_list @@ scan_list cnv

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (List.range 0 `To (pred n))
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let (n, q) = scan "%d %d" Tuple.Tuple2.make
let ab = List.of_enum @@ scan_lines (n-1) "%d %d" Tuple.Tuple2.make
let px = List.of_enum @@ scan_lines q "%d %d" Tuple.Tuple2.make

let () =
  let tree = Array.init n (fun _ -> []) in
  let ntree = Array.make n 0 in
  ListL.iter ab ~f:(fun (a, b) ->
      tree.(pred a) <- (pred b)::tree.(pred a);
      tree.(pred b) <- (pred a)::tree.(pred b));
  ListL.iter px ~f:(fun (p,x) ->
      ntree.(pred p) <- ntree.(pred p) + x);
  let rec update n v visited =
    if not visited.(n) then
      let w = v + ntree.(n) in
      visited.(n) <- true;
      ntree.(n) <- w;
      ListL.iter tree.(n) ~f:(fun p -> update p w visited)
  in
  update 0 0 (Array.make n false);
  IO.to_string (Array.print ~first:"" ~last:"\n" ~sep:" " Int.print) ntree
  |> Printf.printf "%s"


Measured memory_bytes: 66556
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
    int n;
    cin>>n;
    vector<int>dp(n+1,0);
    dp[0]=1;
    ll x=0;
    for(int i=1;i<n+1;i++){
      if(i-3>=0){
          x+=dp[i-3];
          x%=MOD;
      }
      dp[i]=x;
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

using namespace std;

string s[55];
char b[55][55];
const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() { 
    int h, w;
    cin >> h >> w;
    int x, y;
    for (int i = 0; i < h; ++i) cin >> s[i];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') b[i][j] = '#';
            else {
                int cnt = 0;
                for (int k = 0; k < 8; ++k) {
                    x = i+dx[k], y = j+dy[k];
                    if (x >= 0 && x < h && y >= 0 && y < w) {
                        if (s[x][y] == '#') ++cnt;
                    }
                }
                b[i][j] = '0' + cnt;
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) cout << b[i][j];
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    string ans;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            ans.push_back(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
  unsigned long long a, b, k;
	cin >> a >> b >> k;
	if (a <= k) {
		k -= a;
		a = 0;
		if (b <= k) {
			b = 0;
		}
		else {
			b -= k;
		}
	}
	else {
		a -= k;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
a = list(map(int, input().split()))

G = {}
for i in range(1, n + 1):
    G.update({i: a[i - 1]})

seen = [False] * (n + 1)
path = [1]

i = 1
while True:
    seen[i] = True
    i = G[i]
    
    if seen[i]:
        break
    else:
        path.append(i)

m = path.index(i)

if m > k:
    print(path[k])
else:
    k -= m
    path = path[m:]
    k %= len(path)
    print(path[k])


Measured memory_bytes: 40556
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

int main(){
    int a[3],b[3];
    for(int i=0;i<3;i++){
        cin>>a[i]>>b[i];
    }
    int p[4]={1,2,3,4};
    do{
        bool flag=true;
        for(int i=0;i<3;i++){
            bool can=false;
            for(int j=0;j<3;j++){
                if(p[i]==a[j]&&p[i+1]==b[j])can=true;
                else if(p[i]==b[j]&&p[i+1]==a[j])can=true;
            }
            if(!can)flag=false;
        }
        if(flag){
            cout<<"YES"<<endl;
            return 0;
        }
    }while(next_permutation(p,p+4));
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int h,w,i;
	scanf("%d%d",&h,&w);
	char a[h][w+1];
	
	for(i=0;i<h;i++){
		scanf("%s",&a[i]);
	}
	for(i=0;i<w+2;i++)printf("#");
	printf("\n");
	for(i=0;i<h;i++){
		printf("#%s#\n",a[i]);
	}
	for(i=0;i<w+2;i++)printf("#");
	return 0;
}

Measured memory_bytes: 128