akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> h(N);
    REP(i, 0, N) cin >> h[i];

    int dp[N] = {};
    REP(i, 1, N) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        if (i > 1) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int par[MAX];
int depth[MAX];
int siz[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        siz[i]=1;
    }
}

int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

void unit(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(depth[x]>depth[y])swap(x,y);
    par[x]=y;
    siz[y]+=siz[x];
    if(depth[x]==depth[y])depth[x]++;
}

bool issame(int x,int y){
    return find(x)==find(y);
}

int size(int x){
    return siz[find(x)];
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<P>a(m);
    REP(i,m){
        int x,y;
        cin>>x>>y;
        a[i]={x,y};
    }
    init(n);
    vector<ll>ans(m+1);
    ans[m]=(ll)n*(n-1)/2;
    for(int i=m-1;i>=0;i--){
        int x=a[i].first;
        int y=a[i].second;
        if(issame(x,y)){
            ans[i]=ans[i+1];
        }else{
            ans[i]=ans[i+1]-(ll)size(x)*size(y);
        }
        unit(x,y);
    }
    REP(i,m)OUT(ans[i+1]);
    return 0;
}

Measured memory_bytes: 4096
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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; }

class Modulo{
public:
    ll val;
    static const ll mod = 1e9+7;
    vector<ll> factable = {1};
    vector<ll> invtable = {1};
    ll pro(ll x,ll y){return ((x%mod)*(y%mod))%mod;}
    ll sum(ll x,ll y){return ((x%mod)+(y%mod))%mod;}
    ll dif(ll x,ll y){ll d =((x%mod)-(y%mod))%mod;if(d>=0){return d;}else{return d+mod;}}
    ll quo(ll x, ll y){return pro(x,pow(y,mod-2));}
    ll pow(ll x,ll y){
        if(y<=0){return 1;}
        if(y%2==0){ll d = pow(x,y/2);return ((d%mod)*(d%mod))%mod;}
        else{return (x*pow(x,y-1))%mod;}
    }
    void operator=(ll n){this->val = n%mod;}
    ll operator+(ll n){return sum(this->val,n);}
    ll operator-(ll n){return dif(this->val,n);}
    ll operator*(ll n){return pro(this->val,n);}
    ll operator/(ll n){return quo(this->val,n);}
    void operator+=(ll n){this->val = sum(this->val,n);}
    void operator-=(ll n){this->val = dif(this->val,n);}
    void operator*=(ll n){this->val = pro(this->val,n);}
    void operator/=(ll n){this->val = quo(this->val,n);}
    ll fac(ll x){
        //x! mod mod
        if(factable.size()<=x){
            ll s = factable.size();
            FOR(i,s,x+1){
                factable.push_back(pro(i,factable.back()));
                invtable.push_back(quo(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return factable[x];
    }
    ll facinv(ll x){
        if(invtable.size()<=x){
            ll s = invtable.size();
            FOR(i,s,x+1){
                factable.push_back(pro(i,factable.back()));
                invtable.push_back(quo(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return invtable[x];
    }
    ll com(ll x,ll y){
        //xCy mod mod = x!/((x-y)!*y!) mod mod
        if(x-y<y)return com(x,x-y);
        return pro(fac(x),pro(facinv(x-y),facinv(y)));
    }
};


ll n;

int main() {
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    Modulo res;
    res = 0;
    vector<Modulo> p(n+1);
    p[0] = 0;
    REP(i,n){
        p[i+1] += p[i]+p[i].quo(1,(i+1));
    }
    Modulo b;
    REP(i,n){
        b = 0;
        b += p[i+1].val+p[n-i].val-1;
        b *= b.fac(n);
        res += b.val*a[i];
    }
    put(res.val);
    return 0;
}




Measured memory_bytes: 14572
def main():
    N, A, B = map(int, input().split())
    X = list(map(int, input().split()))
    walk = []
    for i in range(N-1):
        diff = X[i+1] - X[i]
        if diff*A < B:
            walk.append(diff)
    print(A*sum(walk) + B*(N-1 - len(walk)))


if __name__ == "__main__":
    main()

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

typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)
#define print(v) cout << v << endl

int main()
{
    int n;
    cin >> n;
    int h[100];
    REP(i,n){
        cin >> h[i];
    }
    int tmp = -1;
    int ans = 0;
    REP(i,n){
        if(h[i]>=tmp){
            ans+=1;
            tmp = h[i];
        }
    }
    print(ans);
}

Measured memory_bytes: 256
import heapq
n,m=map(int,input().split())
l=[[] for _ in range(m)]
for _ in range(n):
  a,b=map(int,input().split())
  if a<=m:
    l[a-1].append(b)
ans=0
w=[]
for i in range(m):
  for j in l[i]:
    heapq.heappush(w,-j)
  if w!=[]:
    ans-=heapq.heappop(w)
print(ans)

Measured memory_bytes: 18416
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn gcd(a: u64, b: u64) -> u64 {
    let mut c = cmp::max(a, b);
    let mut d = cmp::min(a, b);

    while c%d > 0 {
        let tmp = d;
        d = c%d;
        c = tmp;
    }

    d
}

fn div2_count(a: u64) -> u64 {
    let mut tmp = 0;
    let mut b = a;
    while b % 2 == 0 {
        b /= 2;
        tmp += 1;
    }
    tmp
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let m = line[1] as u64;
    let a: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut tmp = 1;

    for i in 0..n {
        tmp = tmp * (a[i]/2) / gcd(tmp, a[i]/2);
    }
    
    let tar = div2_count(a[0]);
    let flag = a.iter().find(|x| tar != div2_count(**x)).is_none();

    let ans = if tmp <= m && flag {
        1 + (m - tmp) / (tmp*2)
    } else {
        0
    };
    

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define fr(i,n) for(int i=0;i<(n);++i)
#define foor(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,n) for(int i=(n);i--;)
#define roof(i,b,a) for(int i=(b);i>=(a);--i)
#define all(x) x.begin(),x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define print(x) cout<<(x)<<endl
using namespace std;            typedef vector<int>  vi;
typedef long long ll;           typedef vector< ll>  vl;
typedef unsigned long long ull; typedef vector<ull>  vu;
typedef double dbl;             typedef vector<dbl>  vd;
typedef pair<int,int>pii;       typedef vector<pii>vpii; typedef map<int,int>mii;
typedef pair< ll, ll>pll;       typedef vector<pll>vpll; typedef map< ll, ll>mll;
typedef pair<dbl,dbl>pdd;       typedef vector<pdd>vpdd; typedef map<dbl,dbl>mdd;
typedef pair< ll,int>pli;       typedef vector<pli>vpli; typedef map< ll,int>mli;
typedef pair<dbl,int>pdi;       typedef vector<pdi>vpdi; typedef map<dbl,int>mdi;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T>multiset<T>&operator<<(multiset<T>&m,const T t){m.insert(t);return m;}
template<typename T>set<T>&operator<<(set<T>&s,const T t){s.insert(t);return s;}
template<typename T,typename U>PQ<T,vector<T>,U>&operator<<(PQ<T,vector<T>,U>&q,const T t){q.push(t);return q;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T>istream&operator>>(istream&s,vector<T>&v){fr(i,v.size()){s>>v[i];}return s;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto a:v){s<<a<<endl;}return s;}
const int MD=1e9+7;
vpli dijkstra(const int N,const vpli E[],const int s,const ll inf){vpli d;fr(i,N)d<<pli{inf,i};d[s].first=0;PQ<pli,vpli,greater<pli>>pq;pq<<(d[s]=pli{0,s});while(pq.size()){pli a=pq.top();pq.pop();int v=a.second;if(d[v].first>=a.first){for(pli e:E[v]){if(d[v].first+e.first<d[e.second].first){d[e.second]=pli{d[v].first+e.first,v};pq<<pli{d[v].first+e.first,e.second};}}}}return d;}
ll gcd(const ll a,const ll b){return a?gcd(b%a,a):b;}
ll pow(const ll a,const ll n,const int m){ll t;return n?(n&1?a>=0?a%m:~-m+~a%m:1)*(t=pow(a,n>>1,m),t*t%m)%m:1;}
ll C2(const int n){return(ll)n*~-n/2;}

main(){cin.tie(0);ios::sync_with_stdio(false);
	int N,K;
	cin>>N>>K;
	print((N-2)/~-K+1);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	if(n>m)swap(n,m);
	if(n==1&&m==1){
		cout << 1 << endl;
		return 0;
	}
	if(n==1){
		cout << m-2 << endl;
		return 0;
	}
	cout << (m-2)*(n-2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


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

    ll h; cin >> h;

    int depth = 0;

    ll ans = 0;

    while(h!=0){
        ans += pow(2,depth);
        h/=2; depth++;
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<long,long>
using namespace std;
ifstream fin("f.in");
ofstream fout("f.out");
int i;
string s;
int main()
{
    cin>>s;
    int n=s.length();
    vector<char> a,b;
    //a.pb(s[0]);
    a.pb(' ');
    int ans=0;
    for(i=0;i<n;i++)
    {
        b.pb(s[i]);
        if(b!=a)
        {
            ans++;
            a=b;
            b.clear();
        }

    }
    cout<<ans;
    fin.close();
    fout.close();
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;

const long MOD = 1000000007;

ll N,K;
vector<ll> seen;
map<ll,ll> mp;
ll aaa;
ll aa;
ll res;
void dfs(ll prev = -1, ll start=0,ll count=0){
    if(seen[start]!=-100){
        aaa = seen[prev] - seen[start] + 1;    
        aa = seen[start];
        return;
    }
    seen[start] = count;
    dfs(start, mp[start],count+1);
}
 
void dfs2(ll start,ll count){
    if(count==0){
        res = start;
        return;
    }
    // cout<<(start+1)<<endl;
    dfs2(mp[start],count-1);
}
 
int main(){
    cin>>N>>K;
    
	seen.resize(N);
    for(ll i=0;i<N;i++){
        seen[i] = -100;
    }
    
    for(ll i=0;i<N;i++){
        ll a;cin>>a;a--;
        mp[i] = a;
    }
    dfs();
    if(K<=aa){
        dfs2(0,K);
        cout<<(res+1)<<endl;
        return 0;
    }
    ll tmp = (K-aa)%aaa+aa;
    // cout<<tmp<<":"<<aaa<<":"<<aa<<endl;
    dfs2(0,tmp);
    cout<<(res+1)<<endl;
}
 

Measured memory_bytes: 29548
n = int(input())
al = list(map(int, input().split())) 

res = bin(0)
for i in range(n):
    res = bin(int(res,2)^al[i])

resu=[]
for j in range(n):
    ress = bin(int(res,2)^al[j])
    resu.append(int(ress,2))

print(' '.join(map(str,resu)))

Measured memory_bytes: 41860
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,c[3][3],f=0,m,m1;
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    cin>>c[i][j];
    m=c[1][0]-c[0][0];
    m1=c[1][0]-c[2][0];
    for(i=1;i<3;i++)
    {
        if((c[1][i]-c[0][i]!=m)or(c[1][i]-c[2][i]!=m1))f=1;
    }
    if(f)cout<<"No\n";
    else cout<<"Yes\n";

}


Measured memory_bytes: 256
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(a,b);
    int ansChar = min(a,b);
    int iter = max(a,b);
    rep(i,iter)cout<<ansChar;
    cout << nn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a,b,c;

    rep(i,n){
        cin >> a >> b >> c;
        if(a*a == b * b + c*c || b*b == a*a+c*c || c*c == a*a + b*b)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<cstring>
using namespace std;
int a[5000],c;
int main()
{int n;
 cin>>n;
 for(int i=0;i<n;i++)
 cin>>a[i];
 int x=123456789;
 for(int i=0;i<n;i++){
 if(a[i]%10!=0)
 x=min(x,a[i]);
 c+=a[i];
 }
 if(c%10!=0)
 cout<<c<<endl;
 else if(c%10==0 && x!=123456789)
 cout<<c-x<<endl;
 else
 cout<<0<<endl;
 system("pause");
 return 0;
}

Measured memory_bytes: 504
/**
 *    author:  Mohamad Milhem
 *    created: 2020-03-23-17.40.52
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(9)

bool pal(string s){
    string v = s;
    reverse(s.begin(),s.end());

    return (s == v ? true : false);



}



int main(){

    FAST;


    int n;
    cin >> n;
    vector<int> v(n);
    set<int> s;
    for (int i = 0 ; i < n ; i++)cin >> v[i];

    map<int,int> acc;
    for (int i = 0 ; i < n ; i++){
        acc[v[i]]++;
        s.insert(v[i]);
    }


    long long sum = 0;

    for(auto i = s.begin() ; i != s.end() ; i++){
        long long now = acc[*i];
        sum+= now*(now-1)/2.0;
    }

    for (int i = 0 ; i < n ; i++){
        cout << sum - acc[v[i]] + 1 << "\n";
    }




    return 0;
}


Measured memory_bytes: 14208
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main() {
	int n, m = 0, i, j;
	long long int ans;
	scanf("%d", &n);
	char s[n + 100];
	for (i = 0; i < n; i++) {
		scanf("%s", &s[i]);
	}
	long long int a[5]; // MARCHの数
	for (i = 0; i < 5; i++) {
		a[i] = 0;
	}
	for (i = 0; i < n; i++) {
		if (s[i] == 'M') a[0]++;
		else if (s[i] == 'A') a[1]++;
		else if (s[i] == 'R') a[2]++;
		else if (s[i] == 'C') a[3]++;
		else if (s[i] == 'H') a[4]++;
	}
	ans = a[0]*a[1]*a[2] + a[0]*a[1]*a[3] + a[0]*a[1]*a[4] + a[0]*a[2]*a[3] + a[0]*a[2]*a[4] + a[0]*a[3]*a[4] + a[1]*a[2]*a[3] + a[1]*a[2]*a[4] + a[1]*a[3]*a[4] + a[2]*a[3]*a[4];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
            int i,kai;
            int[] a = new int[2000];
            string[] siki = new string[2000];
            int[] b = new int[2000];
            for(i=0;i<2000;i++)
            {
                string inp = Console.ReadLine();
                string[] data = inp.Split();
                a[i] = int.Parse(data[0]);
                siki[i] = data[1];
                b[i] = int.Parse(data[2]);
                if (siki[i] == "?")
                {
                    break;
                }
            }
            for (i = 0; i < 2000; i++)
            {
                switch (siki[i])
                {
                    case "+":
                        kai = a[i] + b[i];
                        Console.WriteLine("{0}", kai);
                        break;
                    case "-":
                        kai = a[i] - b[i];
                        Console.WriteLine("{0}", kai);
                        break;
                    case "*":
                        kai = a[i] * b[i];
                        Console.WriteLine("{0}", kai);
                        break;
                    case "/":
                        kai = a[i] / b[i];
                        Console.WriteLine("{0}", kai);
                        break;
                    case "?":
                        break;
                }
            }
    }
}


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

int main() {
    int n;
    int s, t;
    int a, b;
    int f = 0;

    cin >> a >> b;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s >> t;

        if (!(t <= a || b <= s)) {
            f = 1;
        }
    }

    cout << f << endl;
    
    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll h, w;
  cin >> h >> w;

  ll dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
  ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

  string s[h];
  for(ll i = 0; i < h; i++){
    cin >> s[i];
  }

  for(ll i = 0; i < h; i++){
    for(ll j = 0; j < w; j++){
      ll cnt = 0;
      if(s[i][j] == '#'){
        cout << '#';
        continue;
      }
      for(ll k = 0; k < 8; k++){
        //cout << s[i+dx[k]][j+dy[k]] << endl;
        cnt += (s[i+dx[k]][j+dy[k]] == '#');
      }
      cout << cnt;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  int	a;
  int	b;
  int	c;
  int	k;
  int	i;
  
  scanf("%d %d %d", &a, &b, &c);
  scanf("%d", &k);
  i = 0;
  while (a >= b)
  {
  	b *= 2;
    i++;
  }
  while (b >= c)
  {
    c *= 2;
    i++;
  }
  if (i <= k)
    printf("Yes");
  else
    printf("No");
  return (0);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,k,c;
	string s;
	cin >> n >> k >> c >> s;

	vector<int> left(k, -1), right(k, -1);
	int cur = 0;
	REP(i,k){
		while(cur<n && s[cur]=='x') cur++;
		if(cur==n) break;
		left[i] = cur;
		cur += c+1;
	}

	reverse(ALL(s));
	cur = 0;
	REP(i,k){
		while(cur<n && s[cur]=='x') cur++;
		if(cur==n) break;
		right[k-i-1] = n-cur-1;
		cur += c+1;
	}

	REP(i,k){
		if(left[i]==-1 || right[i]==-1) continue;
		if(left[i]==right[i]) cout << left[i]+1 << '\n';
	}

	return 0;
}



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

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

    rep(i, h) {
        if (i == 0) rep(k, w + 2) cout << '#';
        cout << endl;
        rep(j, w) {
            if (j == 0) cout << '#';
            char a;
            cin >> a;
            cout << a;
            if (j == w - 1) cout << '#';
        }
    }

    cout << endl;
    rep(k, w + 2) cout << '#';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int main(){
  int n = in();
  int m = in();
  vector<pii> keys(m);
  foreach(key,keys){
    key.first = in();
    int b = in();
    rep(i,b){
      key.second |= bit(in()-1);
    }
  }
  vector<int> dp(bit(n),INF);
  dp[0] = 0;
  rep(i,bit(n)){
    foreach(key,keys){
      chmin(dp[i|key.second],dp[i]+key.first);
    }
  }
  int ans = dp[bit(n)-1];
  cout << (ans==INF?-1:ans) << endl;
  return 0;
}


Measured memory_bytes: 256
# https://abc084.contest.atcoder.jp/tasks/abc084_d


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime


def main():
    p_l = primes(10**5)
    total = [0 for _ in range(10 ** 5 + 1)]
    for i in range(3, 10 ** 5 + 1):
        if p_l[i] and p_l[(i + 1) // 2]:
            total[i] = 1 + total[i - 1]
        else:
            total[i] = total[i - 1]

    # print(total[:10])
    Q = int(input())
    lrs = [list(map(int, input().split())) for _ in range(Q)]
    for lr in lrs:
        print(total[lr[1]] - total[lr[0]-1])


main()






Measured memory_bytes: 29828
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  using Pair = pair<ll, ll>;
  ll N, M; cin >> N >> M;
  vector<vector<ll>> nbr(N);
  vector<ll> A(M), B(M);
  for (ll i = 0; i < M; i++) {
    ll a, b; cin >> a >> b; a--; b--;
    nbr.at(a).push_back(b);
    nbr.at(b).push_back(a);
    A.at(i) = a;
    B.at(i) = b;
  }
  vector<ll> dist0(N, -1);
  queue<Pair> que;
  que.emplace(0, 0);
  while (!que.empty()) {
    ll n, d; tie(n, d) = que.front(); que.pop();
    if (dist0.at(n) >= 0) continue;
    dist0.at(n) = d;
    for (ll m : nbr.at(n)) {
      if (dist0.at(m) >= 0) continue;
      que.emplace(m, d+1);
    }
  }
  ll even = 0; ll odd = 0;
  for (ll i = 0; i < N; i++) {
    if (dist0.at(i) % 2 == 0) even++;
    else                      odd++;
  }
  for (ll i = 0; i < M; i++) {
    if (dist0.at(A.at(i)) % 2 != dist0.at(B.at(i)) % 2) continue;
    cout << N * (N-1) / 2 - M << endl;
    return 0;
  }
  cout << even * odd - M << endl;
  return 0;
}



Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;
 
struct edge{
    int to, cost;
    edge(int to, int cost):to(to), cost(cost){}
};
 
const int INF = 1e12;
int d[100010];
int n, m, s;
vector<edge> G[100010];
 
 
void dijkstra(int s){
    typedef pair<int, int> pii;
    //greater<pii>????????????????????¨??§first????°???????????????????????????????????????????
    priority_queue<pii, vector<pii>, greater<pii> > que;
    fill(d, d + n, INF);
    d[s] = 0;
    que.push(pii(0, s));
 
    while(!que.empty()){
        pii p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}

 
signed main(){
    cin >> n >> m >> s;
    rep(i, 0, m){
        int a, b, c;
        cin >> a >> b >> c;
        G[a]. push_back(edge(b, c));
    }
    dijkstra(s);
    rep(i, 0, n){
        if(d[i] >= INF) cout << "INF" << endl;
        else cout << d[i] << endl;
    }
}

Measured memory_bytes: 19452
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//library end
int a[5][5];
bool bo[5][5];
bool x[5]={true},y[5]={true},l=true,r=true;
int n;
int b[15];
signed main(){
    
    cin>>n;
    cout<<(n+1)/2<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int res;
  
  for(int i = 0; i < N; i++) {
    int A;
    int B;
    cin >> A >> B;
    
    res += B - A + 1;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,m,a,b,c,t;
    cin>>n>>t;
    long long arr[n+100];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];

    }
    c=0;
    for(i=0;i<n-1;i++)
    {
        if(abs(arr[i+1]-arr[i])>=t)
        {
            c+=t;
        }
        else
        {
            k=abs(arr[i+1]-arr[i]);
            {
                c+=k;
            }
        }

    }
    c+=t;
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc084/tasks/abc084_d

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
ll lcm(long a, long b) { return a * b / gcd(a, b); }

int dp[100001];
bool isPrime(int num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> l(n), r(n);
    REP(i, n) cin >> l[i] >> r[i];
    for (int i = 1; i <= 100000; i++) {
        dp[i] = dp[i - 1] + (isPrime(i) & isPrime((i + 1) / 2));
    }

    for (int i = 0; i < n; i++) {
        cout << dp[r[i]] - dp[l[i] - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 4520
import java.util.*;

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

    int max = 1;
    for (int b = 2; b * b <= X; b++) {
      for (int p = 2; beki(b, p) <= X; p++) {
        int n = beki(b, p);
        if (max < n) {
          max = n;
        }
      }
    }
    System.out.println(max);
  }
  
  private static int beki(int b, int p) {
    if (p == 0) {
      return 1;
    }
    
    return b * beki(b, p-1);
  }
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int n, a, b;
int x, y, z;

int main() {
	scanf("%d %d %d", &n, &a, &b);
	for (int i = 0; i < n; i++) {
		int num;
		scanf("%d", &num);
		if (num <= a) x++;
		else if (num <= b) y++;
		else z++;
	}
	printf("%d\n", min(x, min(y, z)));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    int c=0;
    for(int i=n;i>0;i/=10)c+=i%10;
    if(n%c==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

Measured memory_bytes: 1024
#include <cstdio>

int n,m;
int a[100][100];

bool in(int x,int y)
{
	return x>=1 && x<=n && y<=m && y>=1;
}

int main()
{
	scanf("%d%d",&n,&m);
	getchar();
	for (int i = 1; i<=n; i++)
	{	
		for (int j = 1; j<=m; j++)
			a[i][j] = getchar();
		getchar();
	}

	const int xp[] = {-1,1,0,0,1,-1,1,-1};
	const int yp[] = {0,0,-1,1,1,-1,-1,1};

	for (int i = 1; i<=n; i++)
		for (int j = 1; j<=m; j++)
			if (a[i][j] == '.')
			{
				a[i][j] = '0';
				for (int k = 0; k<8; k++)
					if (in(i+xp[k],j+yp[k]))
						if (a[i+xp[k]][j+yp[k]] == '#')
							a[i][j]++;
			}

	for (int i = 1; i<=n; i++)
	{
		for (int j = 1; j<=m; j++)
			printf("%c",a[i][j]);
		printf("\n");
	}
}

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

int main() {
  stack<int> s1;
  stack<pair<int, int>> s2;
  char ch;
  int sum = 0;

  for (int i = 0; cin >> ch; i++) {
    if (ch == '\\') {
      s1.push(i);
    } else if (ch == '/' && !s1.empty()) {
      int j = s1.top();
      s1.pop();
      sum += i - j;
      int a = i -j;
      while (!s2.empty() && s2.top().first > j) {
        a += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j, a));
    }
  }

  vector<int> ans;

  while(!s2.empty()) {
    ans.push_back(s2.top().second);
    s2.pop();
  }
  reverse(ans.begin(), ans.end());

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



Measured memory_bytes: 3192
l, r = map(int, input().split())

ans = 2019
for i in range(l, r):
    for j in range(l+1, r+1):
        tmp = i*j % 2019
        if ans > tmp:
            ans = tmp
        if ans == 0:
            print(ans)
            exit(0)
print(ans)

Measured memory_bytes: 3060
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,c = iim()

if a == b:
    print(c)
else:
    if a == c:
        print(b)
    else:
        print(a)

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


int main() {
	
	string s;
	cin >> s;
	bool flag = 1;
	multiset<char> t;
	
	if(s.at(0)!='A') flag = 0;
	for(int i=2; i<s.size()-1; i++){
		t.insert(s.at(i));
		if( s.at(i)!='C' && ('a'>s.at(i) || 'z'<s.at(i)) ) flag = 0;
	}
	if(t.count('C')!=1) flag = 0;
	if('a'>s.at(1) || 'z'<s.at(1)) flag = 0;
	if('a'>s.at(s.size()-1) || 'z'<s.at(s.size()-1)) flag = 0;
	if(flag) cout << "AC" << endl;
	else cout << "WA" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    auto A = new int[](N+1);
    foreach (i; 0..N) A[i+1] = A[i] + (S[i] == '#');
    int ans = 1 << 29;

    foreach (i; 0..N+1) {
        int left_black = A[i];
        int right_white = N - i - (A[N] - A[i]);
        ans = min(ans, left_black + right_white);
    }

    ans.writeln;
}

Measured memory_bytes: 3452
#include"bits/stdc++.h"
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 double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (size_t i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	bool debug = false;
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

inline void Main(){
	int r;
	cin >> r;
	cout << r * r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <vector>;
#include <numeric>
using namespace std;

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

	long long ans = 0, a, c = 0;;
	for (int i = 0;i < n;i++) {
		cin >> a;
		if (a < c) {
			ans += c - a;
		}
		if (a > c) c = a;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
	int ALL=0;
	for (int i=0;i<6;++i){
		int c;
		int okane[6]={1,5,10,50,100,500};
		cin>>c;
		ALL+=okane[i]*c;
	}
	if(ALL>=1000){
		cout<<"1"<<endl;
	}
	else{
		cout<<"0"<<endl;
	}
	return 0;
}

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

const ll INF = 1e18;

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

    ll N, W;
    cin >> N >> W;
    vector<ll> v(N), w(N);
    for (int i = 0; i < N; ++i) {
        cin >> v.at(i) >> w.at(i);
    }

    vector<pair<ll, ll> > P1;
    ll N2 = N / 2;
    for (ll tmp = 0; tmp < (1 << N2); ++tmp) {
        bitset<21> b(tmp);
        ll sv = 0;
        ll sw = 0;
        for (int i = 0; i < N2; ++i) {
            if (b.test(i)) {
                sv += v.at(i);
                sw += w.at(i);
            }
        }
        if (sw > W) continue;
        P1.push_back(make_pair(sw, sv));
    }
    sort(P1.begin(), P1.end());
    ll m = 1;
    for (int i = 1; i < P1.size(); ++i) {
        if (P1.at(m - 1).second < P1.at(i).second) {
            P1.at(m++) = P1.at(i);
        }
    }
    ll ans = 0;
    for (int tmp = 0; tmp < (1 << (N - N2)); ++tmp) {
        bitset<21> b(tmp);
        ll sv = 0;
        ll sw = 0;
        for (int i = 0; i < (N - N2); ++i) {
            if (b.test(i)) {
                sv += v.at(N2 + i);
                sw += w.at(N2 + i);
            }
        }
        if (sw > W) continue;
        pair<ll, ll> p = make_pair(W - sw, INF);
        ll tv = (lower_bound(P1.begin(), P1.begin() + m, p) - 1)->second;
        ans = max(ans, sv + tv);
    }
    cout << ans << endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
//ll MLG(ll n,ll b){ll a=0;while(n)a++,n/=b;return a-1;}

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;//cin>>tt;
    while(tt--){
        int k,n;
        cin>>k>>n;
        vector<int> a(n);
        rep(i,0,n)cin>>a[i];
        vector<int> as;
        rep(i,1,n){
            as.pb(a[i]-a[i-1]);
        }
        as.pb(k-a[n-1]+a[0]);
        sort(all(as));
        ll s=0;
        rep(i,0,_sz(as)-1){
            s+=as[i];
        }
        cout<<s<<nl;
    }

    return 0;
}


Measured memory_bytes: 2168
/**************erik****************/
#include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  int ll;
typedef unsigned long long int ull;
//map<ll,ll> mp1;
//set<int> s1;
//set<int>::iterator it;
#define maxm(a,b,c)  max(a,max(c,b))
#define minm(a,b,c)  min(a,min(c,b))
#define f(i,n)  for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;i--)
const int MXM = 100005;
int dp[MXM];
int solve(int a[],int x,int n,int k){
    if(x>=n){
        return INT_MAX;
    }
  	if(x== n-1){
    	return 0;
    }
  	if(dp[x]!=-1){
      return dp[x];
    }
  int p = INT_MAX;
  for(int i=1;i<=k;i++){
  	int z;
    if(x+i >= n){
    	z = INT_MAX;
    }
    else {
      	z = solve(a,x+i,n,k) + abs(a[x]-a[x+i]);
    }
    p = min(p,z);
  }
  return dp[x] = p;
   
}
int main()
{
  int n,k;
 cin>>n>>k;
  int a[n+1];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }
 memset(dp, -1, sizeof(dp));
 int v = solve(a,0,n,k);
 cout<<dp[0]<<endl;
 return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define int long long
#define f(i,l,n) for(int i=l;i<n;i++) 
#define E "\n"

int solve()
{
    int n;
    cin >> n;
    string s="ACL";

    while(n--) cout<<s;
    cout<<E;
    return 0;    
}


int32_t main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
     int t = 1;
     //cin >> t;
     while(t--)
     {
          solve();
     }
     return 0;
}

Measured memory_bytes: 3592
N,M = map(int,input().split())
SC = [tuple(map(int,input().split())) for i in range(M)]

if N==1:
    r = range(0,10)
elif N==2:
    r = range(10,100)
else:
    r = range(100,1000)

for n in r:
    n = str(n)
    for s,c in SC:
        s -= 1
        if n[s] != str(c):
            break
    else:
        print(n)
        exit()
print(-1)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        int dayRcoin = scan.nextInt();
        int weekRcoin = scan.nextInt();
        int aimRcoin = scan.nextInt();
        int nowRcoin = 0;
        int logindays;

        for(logindays=0; nowRcoin<aimRcoin; logindays++)
            nowRcoin+=logindays%7==6 ? dayRcoin+weekRcoin : dayRcoin;
        
        System.out.println(logindays);
    }
}


Measured memory_bytes: 26488
#include <stdio.h>
int main(void)
{
    int h, n, i, a[10000000];

    scanf("%d %d", &h, &n);
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);

    for (i = 0; i < n; i++)
        h = h - a[i];

    if (h <= 0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 2304
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for j in range(W+1):
        # i番目のitemを使わない場合
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        # i番目のitemを使う場合
        if j + items[i][0] > W:
            continue
        dp[i+1][j+items[i][0]] = max(dp[i][j] + items[i][1], dp[i+1][j+items[i][0]])
print(dp[N][W])


Measured memory_bytes: 121436
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t A, B, C;

    std::cin >> A >> B >> C;

    std::cout << C << " " << A << " " << B << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;

vector<int> v[100001];
vector<int> memo(100001);

int dfs(int x){
    if(memo[x]!=0) return memo[x];
    int ret=0;
    for (int i = 0; i < v[x].size(); i++) {
        ret=max(ret,dfs(v[x][i])+1);
    }
    return memo[x]=ret;
}


int main(){
    int N,M;cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        v[x].pb(y);
    }
    int ans=0;
    for (int i = 0; i < N; i++) {
        ans=max(ans,dfs(i));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 8192
#include<iostream>
#include<cstdio>
#include<cstring>

int main() {
	char a[1000];
	while (1) {
		int sum = 0;
		scanf("%s", a);
		if (a[0] == '0')break;
		for (int i = 0;i < strlen(a);i++) {
			sum += (a[i] - '0');
		}
		printf("%d\n", sum);
	}
	return 0;
}


Measured memory_bytes: 3192