akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int c[26],s[365][26]={{0}},type[365];
void solve(int d)
{
  int since[26]={0};
  for(int i=0;i<d;i++)
  {
    int max=0,now=0;
    for(int j=0;j<26;j++){if(max<s[i][j]){max=s[i][j];now=j;}}
    type[i]=now;since[now]=i;
  }
}
int main()
{
  int D=IN(),i=0,j=0;
  while(i<26){c[i++]=IN();}i=0;
  while(i<D){while(j<26){s[i][j++]=IN();}i++,j=0;}i=0;
  solve(D);
  while(i<D){printf("%d\n",type[i++]+1);}
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
int h,w,n,c,sum,x[9999],y[9999];
main(){cin>>h>>w>>n;x[0]=1;y[0]=1;for(int i=1;i<=n;i++){cin>>x[i]>>y[i];}for(int i=1;i<n;i++){if((x[i+1]>=x[i]&&y[i+1]>=y[i])||(x[i+1]<=x[i]&&y[i+1]<=y[i])){c=max(abs(x[i+1]-x[i]),abs(y[i+1]-y[i]));}else{c=abs(x[i]-x[i+1])+abs(y[i]-y[i+1]);}sum+=c;}cout<<sum<<endl;}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

using P = pair<i64, i64>;

i64 n, m;
vector<i64> a;
vector<P> ps;
int main() {
  cin >> n >> m;
  read_n(a, n);
  init_n(ps, m);
  for (i64 i = 0; i < m; ++i) {
    cin >> ps[i].second >> ps[i].first;
  }
  for (i64 x : a) {
    ps.emplace_back(x, 1);
  }
  sort(begin(ps), end(ps));

  i64 i = 0, ans = 0;
  while (!ps.empty()) {
    auto p = ps.back(); ps.pop_back();
    for (i64 j = p.second; j > 0 && i < n; --j, ++i) {
      ans += p.first;
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7556
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  int a,b,c; cin>>a>>b>>c; Cout(a+b+c-max({a,b,c}));
}












Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

int main() {
    string a;
    cin >> a;
    
    vector<ll> csum(0x100, 0);
    for (auto s : a)
        csum[s]++;
    
    ll count = 0;
    for (auto c : csum) {
        if (c > 0)
            count += c * (c - 1) / 2;
    }
    
    ll size = a.size();
    ll pat = size * (size - 1) / 2 + 1;
    cout << pat - count << endl;
    
}



Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Scanner;
public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int n,tmp,sum;
        sum=0;
        tmp=0;
        n=nextInt();
        String[] st = new String[n];
        int[] time = new int[n];
        for(int i=0;i<n;i++){
            st[i]=next();
            time[i]=nextInt();
        }
        String x;
        x=next();
        for(int i=0;i<n;i++){
            if(st[i].equals(x)){
                tmp=i+1;
                break;
            }
        }
        for(int i=tmp;i<n;i++){
            sum+=time[i];
        }
        print(sum);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[2000005];
int main()
{
    /*string s;
    int cnt=0;
    cin >> s;
    int mx=0;;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='R')
            cnt++;
        else
        {
            mx = max(cnt,mx);
            cnt=0;
        }
    }
    mx = max(cnt,mx);
    cout << mx << endl;*//*
    int ans=0;
    int  n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n-2;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            for(int k=j+1;k<=n;k++)
            {
                if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
                    ans++;
            }
        }
    }
    cout << ans << endl;*/
    ll x,k,d;
    cin >> x>> k >>d;
    x = abs(x);
    ll p = x/d;
    if(k<=p)  {
        cout << x-k*d << endl;
        return 0;
    }
    else
    {
        x = x-p*d;
        k-=p;
        ll  y = d-x;
        if(k%2)cout << y << endl;
        else cout << x << endl;
    }
}


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

int main() {
    int x, i = 0;
    while(true) {
        cin >> x;
        if (x != 0) {
            cout << "Case" << " " << i + 1 <<  ":" << " " << x << endl;
        }
        if (x == 0) {
            break;
        }
        i++;
    }

    return 0;
}


Measured memory_bytes: 3008
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

string s;

ll solve(){
    cin >> s;
    ll sum = 0;
    for(int j = 0; j < (1 << (s.size() - 1)); ++j){
        // cout << "\n" << j << " ";
        ll cur = 0;
        ll x = s[0] - '0';
        // for(int i = 0; i < s.size() - 1; ++i) cout << ((j >> i) & 1);
        // cout << "\n";
        for(int i = 1; i < s.size(); ++i){
            if((j >> (i - 1)) & 1){
                // cout << x << " ";
                cur += x;
                x = s[i] - '0';
            }else{
                x *= 10;
                x += s[i] - '0';
            }
        }
        // cout << x << "\n";
        cur += x;
        // cout << cur << "\n";
        sum += cur;
    }
    return sum;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N, M, R = map(int, input().split())
r = tuple(map(int, input().split()))

inf = 10**9
graph = np.ones((N, N), dtype=int)*inf
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c
fy = floyd_warshall(graph)

ans = 10 ** 9
for p in permutations(r):
    tmp = 0
    for x, y in zip(p[:-1], p[1:]):
        x -= 1
        y -= 1
        tmp += int(fy[x][y])
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 19072
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL n, sum = 0;
	cin >> n;
	vector<LL> a(n);
	for (LL i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(a.begin(), a.end());
	LL ans = 1LL << 60;
	for (LL i = max(0LL, n / 2 - 1); i <= n / 2; ++i) {
		LL t = 0;
		for (LL j = 0; j < n; ++j) {
			t += abs(a[j] - a[i]);
		}
		ans = min(ans, t);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1920
import bisect
prime = [2,3,5,7,11,13]

shieve1 = [1]*257
for i in prime:
    itr = i-1
    while(itr<256):
        shieve1[itr] = 0
        itr += i

for i in range(16,256):
    if shieve1[i]:
        prime.append(i+1)

shieve2 = [1]*(50101)

for i in prime:
    itr = i-1
    while(itr<50100):
        shieve2[itr] = 0
        itr += i

for i in range(257,50101):
    if shieve2[i]:
        prime.append(i+1)

while True:
    try:
        n = int(input())
        m = bisect.bisect(prime,n)
        if n==prime[m-1]:
            print(prime[m-2],prime[m])
        else:
            print(prime[m-1],prime[m])
    except EOFError:
        break

Measured memory_bytes: 7852
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
     ll a,b,k;
     cin>>a>>b>>k;
     if(k>=a)
     {
      k-=a;
      a=0;
      b-=k;
      b=max(b,0LL);
     }
     else
     {
      a-=k;
     }
     cout<<a<<" "<<b;

    }
    return 0;
   }

Measured memory_bytes: 14124
import java.util.Scanner;
public class Main{

     public static void main(String[] args){
         
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                String s = sc.next();
                if (n >= 3200) {
                    System.out.println(s);
                } else {
                    System.out.printf("red");
                }

     }

}

Measured memory_bytes: 21972
N,M,X = map(int,input().split())
li = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for i in range(X,N):
  for j in range(M):
    if li[j] == i:
      ans1 += 1
for i in range(X):
  for j in range(M):
    if li[j] == i:
      ans2 += 1
print(min(ans1,ans2))

Measured memory_bytes: 38896
//#include <iostream>
//#include <vector>
//#include <set>
//#include <map>
//#include <algorithm>

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll len = 2 * (int) 1e5 + 1;

ll n, m, l;
ll from, to, cost;

int main() {
//    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> m >> l;
    vector<vector<ll>> g(n, vector<ll>(n, (ll) 1e15 + 1));
    for (int i = 0; i < m; i++) {
        cin >> from >> to >> cost;
        from--;
        to--;
        g[from][to] = g[to][from] = cost;
    }
    for (int i = 0; i < n; i++) {
        g[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
            }
        }
    }


    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (g[i][j] <= l) {
                g[i][j] = 1;
            } else {
                g[i][j] = (int) 1e6 + 1;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
            }
        }
    }

    int q;
    cin >> q;
    while (q--) {
        cin >> from >> to;
        from--;
        to--;
        cout << (g[from][to] == (int)1e6 + 1 ? -1 : g[from][to] - 1) << endl;
    }

}

Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

int f[24],c[13];

int dfs(int x){
    int ans=24;
    if(x==12){
        for(int i=0;i<24;i++){
            for(int j=i+1;j<24;j++){
                if(f[i]&&f[j]){
                    ans=min(ans,min(j-i,24-j+i));
                }
            }
        }
        return ans;
    }
    if(c[x]!=1){
        return dfs(x+1);
    }
    f[x]=1;
    ans=dfs(x+1);
    f[x]=0;
    f[24-x]=1;
    ans=max(ans,dfs(x+1));
    f[24-x]=0;
    return ans;
}

int main(){
    int n,d;
    f[0]=1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&d);
        c[d]++;
    }
    if(c[0]){
        printf("0\n");
        return 0;
    }
    for(int i=1;i<13;i++){
        if(c[i]==2){
            if(i==12){
                printf("0\n");
                return 0;
            }
            f[i]=1;
            f[24-i]=1;
        }
        if(c[i]>2){
            printf("0\n");
            return 0;
        }
    }
    f[12]=c[12];
    printf("%d\n",dfs(1));
}

Measured memory_bytes: 128
N=int(input())
C=[list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    c,s,f=C[i]
    ans=s+c
    for j in range(i+1,N-1):
        nc,ns,nf=C[j]
        # print('D',ans,nc,ns,nf,(ans-ns)%nf)
        ans=max(ans,ns)
        m=(ans-ns)%nf
        if m!=0:ans+=nf-m
        # print('D',ans,nc,ns,nf,(ans-ns)%nf)
        ans+=nc
    print(ans)
print(0)

Measured memory_bytes: 9212
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
map<char,int> 
count_same_elements(const vector<char>& v){map<char,int>cmap; for_each(v.begin(),v.end(),[&cmap](int x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T,class U>
void msg_with_compare(T A,T B,U A_greater_B,U A_eq_B,U A_less_B){
    if(A==B){cout<<A_eq_B<<"\n";}else if(A>B){cout<<A_greater_B<<"\n";}else{cout<<A_less_B<<"\n";}}
template<class B,class T>
void msg_with_boolean(B A,T true_msg,T false_msg){cout<< ( A? true_msg:false_msg);}
template<class B,class T>
void msg_with_boolean(B A1,B A2,T both_true_msg,T true_false_msg,T false_true_msg,T both_false_msg){
    if(A1){if(A2){cout<<both_true_msg;}else{cout<<true_false_msg;}
    }else{if(A2){cout<<false_true_msg;}else{cout<<both_false_msg;}}
}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}
bool operator<(pair<const string,int> lhs,pair<const string,int> rhs){
    return lhs.second < rhs.second;
}

ll n,d,x;
vector<ll>v;
void input(){
    cin>>n>>d>>x;
    scan_vector(n,v);
}
void src(){
    rep(i,n){
        x += ((d-1)/v[i]+1);
    }
    cout<<x;
}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

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

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

int rand16() {
    return rand() & (TWO(16) - 1);
}
int my_rand() {
    return rand16() << 15 | rand16();
}

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int NBIT = 60;
int a[66], b[66];

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9) << boolalpha;
    int la, lb;
    while (cin >> la >> lb) {
        if (la == lb) {
            cout << 1 << endl;
            continue;
        }
        FORD(i,NBIT,1) {
            a[i] = la % 2; la /= 2;
            b[i] = lb % 2; lb /= 2;
        }

        FOR(diff,1,NBIT) if (a[diff] != b[diff]) {
            int start = 0;
            int last = 0;
            FOR(i,diff+1,NBIT) {
                start = start * 2 + a[i];
                last = last * 2 + 1;
            }

            int res = last - start + 1;

            int l = 0, r = 0;
            bool good = false;
            FOR(i,diff+1,NBIT) {
                if (b[i]) good = true;
                r = r * 2 + good;
            }

            int u = start;
            int v = last;

            if (r < u) res += (r - l + 1) + (v - u + 1);
            else res += v - l + 1;

            cout << res << endl;
            break;
        }
    }
    return 0;
}


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

region = []
mod = 998244353

for i in range(k):
    l, r = map(int, input().split())
    region.append((l, r))

cnt = [0] * (n + 1)
cnt[0] = 0
imos = [0] * (n + 1)
imos[0] = 1

for i in range(n):

    if i - 1 >= 0:
        cnt[i] = cnt[i - 1] + imos[i]
        cnt[i] %= mod
    for l, r in region:
        if i + l < n:
            imos[i + l] += cnt[i] if i != 0 else 1
            imos[i + l] %= mod

        if i + r + 1 < n:
            imos[i + r + 1] -= cnt[i] if i != 0 else 1
            imos[i + l + 1] %= mod

print(cnt[n - 1] % mod)


Measured memory_bytes: 71404
def main():

    N = int(input())
    ans = 0

    for A in range(1, 1000000):
        for B in range(1, 1000000):
            if A * B < N:
                #print(A, B, A*B)
                ans = ans + 1
            else:
                break
        if A >= N:
            break

    print(ans)

    return

main()

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

int main()
{

#ifdef _d
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif

    int k;
    cin >> k;
    if (k%7 == 0) {
        k /= 7;
    }
    set<int> s;
    if (k == 1) {
        cout << "1\n";
    } else {
        vector<int> a(2, 1);
        int p = 2;
        while (true) {
            a.push_back(((10*a[p-1])+1)%k);
            if (a[p] == 0) {
                cout << p << "\n";
                break;
            } else {
                if (s.count(a[p]) == 1) {
                    cout << "-1\n";
                    break;
                } else {
                    s.insert(a[p]);
                    ++p;
                }
            }
        }
    }

#ifdef _d
    cerr << "Time: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
#endif

    return 0;
}


Measured memory_bytes: 53888
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

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

int main(){
    int n, ans = 1;
    string s;
    cin >> n >> s;

    for(int i = 1; i < n; i++){
       if(s[i] != s[i-1]) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define bug(x) cerr << #x << " = " << x << '\n'
#define ll     long long
#define maxn   200005

int n, k;
int a[maxn];

bool f (int x) {
        ll cnt = 0;
        for(int i = 1; i <= n; ++ i) {
            cnt += (ll) (a[i] - 1LL) / x;
            if(cnt > k) return false;
        }
        return cnt <= k;
}

int main() {
        //freopen(".inp","r",stdin);

        cin >> n >> k;

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

        int lo = 0, hi = (int) 1e9 + 7;

        while(hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if(f(mid)) hi = mid;
            else lo = mid;
        }
        cout << hi;
}



Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)
#define REPRE(i,n) for (lint i = N-1; i < 0; i--)
#define REP1RE(i,n) for (lint i = N-1; i < 1; i--)

lint N;
lint a, ans;
vector<lint> A;
// list<lint> A;

int main(void){
    cin >> N;
    for (lint i = 0; i < N; ++i) {
        cin >> a;
        if (((a % 2) == 0)) A.push_back(a);
        // A.push_back(a);
    }

    sort(A.begin(), A.end(), greater<lint>());
    // A.sort(greater<lint>());

    for (auto it = A.begin(); it != A.end(); ++it) {
        while (((*it) % 2) == 0) {
            (*it) /= 2;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  int count = 0, res = 0;

  cin >> N;
  for (int i = 1; i <= N; i = i + 2) {
    for (int j = 1; j <= i; j++) {
      if (i%j == 0)
        count++;
    }
    if (count == 8)
      res ++;
    count = 0;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    map<int, int> mp;

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

    int sub = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        sub += itr->second-1;
    }

    cout << N - (sub+1)/2*2 << endl;
}

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

int main() {
  int a,b,c,x;
  cin >> a >> b >> c;
  x = 0;
  
  if(a >= b){
    a = a%b;
  }
  
  for(int i=1;i<b;i++){
    if((a*i)%b == c){
      x++;
      break;
    }
  }
  
  if(x>0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N, M;
int D[1100];
int C[1100];
int dp[1100][1100];

int main() {
  cin >> N >> M;
  for (int i=0; i<N; i++) cin >> D[i];
  for (int i=0; i<M; i++) cin >> C[i];

  for (int i=0; i<N+1; i++) {
    for (int j=0; j<M+1; j++) {
        dp[i][j] = 1145141919;
    }
  }
  dp[0][0] = 0;
  for (int i=0; i<N+1; i++) {
    for (int j=0; j<M+1; j++) {
      dp[i][j+1]   = min(dp[i][j+1], dp[i][j]);
      dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + D[i]*C[j]);
    }
  }
  int ans = 1145141919;
  for (int i=0; i<M+1; i++) {
    ans = min(ans, dp[N][i]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 6536
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[1000000];
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1000){
		for(int j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}
	int n;
	while(cin>>n){
		int cnt=0;
		rep(i,n+1){
			if(prime[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	deque<char> ans(s.size());
	rep(i, s.size()) ans[i] = s[i];
	int q; cin >> q;
	bool elf = true;//true -> sonomama
	rep(i, q) {
		int t; cin >> t;
		if (t == 1) {
			elf = elf ? false : true;
		}
		else {
			int g; char k;
			cin >> g >> k;
			if (g == 1) {
				if (elf) ans.emplace_front(k);
				else ans.emplace_back(k);
			}
			else {
				if (!elf) ans.emplace_front(k);
				else ans.emplace_back(k);
			}
		}
	}
	if (!elf) reverse(all(ans));
	for (auto& c : ans) cout << c;
	cout << endl;
	return 0;
}


Measured memory_bytes: 976
import java.util.Scanner;

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

        while (true) {
	    String line = sc.nextLine();
	    if (line.equals(".")) break;
	    char[] stack = new char[line.length()];
	    int index = 0;
	    boolean flag = true;
	    for (int i = 0; i < line.length(); i++) {
		if (line.charAt(i) == '(') {
		    stack[index++] = '(';
		} else if (line.charAt(i) == '[') {
		    stack[index++] = '[';
		}
		if (line.charAt(i) == ')') {
		    if (index == 0) {
			flag = false;
			break;
		    }
		    if (stack[index-1] == '(') {
			index--;
		    } else {
			flag = false;
			break;
		    }
		} else if (line.charAt(i) == ']') {
		    if (index == 0) {
			flag = false;
			break;
		    }
		    if (stack[index-1] == '[') {
			index--;
		    } else {
			flag = false;
			break;
		    }
		}
	    }
	    if (index != 0) flag = false;
	    if (flag) {
		System.out.println("yes");
	    } else {
		System.out.println("no");
	    }
	}
		    
	sc.close();
    }
}


Measured memory_bytes: 45452
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int b,c,a;
  cin>>a>>b>>c;
  if(a!=b && a!=c) cout<<a<<'\n';
  else if(a!=b && b!=c) cout<<b<<'\n';
  else cout<<c<<'\n';
  return 0;
}


Measured memory_bytes: 256
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
xflg = True
yflg = True
for z in range(100):
  if X < z <= Y:
    for xn in x:
      if z <= xn:
        xflg = False  
    if xflg:
      for yn in y:
        if yn < z:
          yflg = False 
      if yflg:
        print('No War')
        exit()
      else:
        yflg = True
    else:
      xflg = True
print('War')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAXN 200007
#define MO (int(1e9)+7)
int a[MAXN];
inline int qpow(int a, int b) {
	int ans=1;
	for(;b;b>>=1) {
		if(b&1) ans=1ll*ans*a%MO;
		a=1ll*a*a%MO;
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for(int i=0; i<n; i++) cin>>a[i];
	int s=0;
	for(int i=0; i<n; i++) {
		s=(s+a[i])%MO;
	}
	s=(long long)s*s%MO;
	for(int i=0; i<n; i++) {
		s=(s-1ll*a[i]*a[i]%MO)%MO;
	}
	s=1ll*s*qpow(2,MO-2)%MO;
	if(s<0) s+=MO;
	cout << s << '\n';
}


Measured memory_bytes: 4384
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;



int main(){

	char n1,n2;


	cin>>n1>>n2;

	if(n1=='9'){
		cout<<"Yes"<<endl;
	}else if(n2=='9'){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[200005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        a[i]=a[i]-i-1;
    }
    sort(a,a+n);
    long long ans=0;
    for(int i=0;i<n/2;i++) ans+=(long long)abs(a[i]-a[n-1-i]);
    printf("%lld\n",ans);
}


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

int main() {
	
	int A,B,total,count;
	cin >>A >>B;
	
	total=1;
	count=0;
	
	while(total<B){
		
		total=total-1+A;
		
		count++;
		
	}
	
	cout <<count <<endl;
	
	
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

void dfs(const int start, vector<int> &dist, vector<vector<int>> &tree) {
    deque<pair<int, int>> s;
    s.push_back({start, 0});
    bool visited[tree.size()] = {};
    while (!s.empty()) {
        pair<int, int> p = s.back();
        s.pop_back();
        visited[p.first] = true;
        dist[p.first] = p.second;
        for (auto &node : tree[p.first]) {
            if (!visited[node]) {
                s.push_back({node, p.second + 1});
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> dist_f(N, 0), dist_s(N, 0);
    vector<vector<int>> tree(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(0, dist_f, tree);
    dfs(N - 1, dist_s, tree);
    int cnt = 0;
    rep(i, N) {
        if (dist_f[i] > dist_s[i]) cnt++;
    }
    if (cnt >= N - cnt)
        cout << "Snuke" << endl;
    else
        cout << "Fennec" << endl;

    return 0;
}


Measured memory_bytes: 6656
#include<stdio.h>
#define N 100

int main(){
  int G[N][N];
  int a,b,v,k;
  int i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      G[i][j]=0;
      
    }
  }
  for(i=0;i<a;i++){
    scanf("%d%d",&b,&k);
    b--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      G[b][v] = 1;
    }
  }
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      if(j>0){
	printf(" ");
      }
      printf("%d",G[i][j]);
    }
      printf("\n");
    
  }
  return 0;
}



Measured memory_bytes: 2132
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
res = "NO"
dist = abs(B-A)
diff = V-W
if diff >0:
  chall = diff * T
  if chall < dist:
    pass
  else:
    res = "YES"
else:
  pass
print(res)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
const int N = 3050;
int mod = 1000000007;
 int rec[N];
int main()
{
//	freopen("in.txt", "r", stdin);
	int n, y;
	while (~scanf("%d%d", &n, &y))
	{
		if (y % 1000 == 0)
		{
			int ans = -1;
			int a, b, c;
			y /= 1000;
			for (int i = 0; i <= n; i++)
				for (int j = 0; j <= n-i; j++)
				{
					int l = y - (i*10 + j*5);
					if (l + i + j == n)
					{
						ans = 0;
						a = i;b = j; c = l;
						goto here;
					}
				}
here:		
			if (ans == -1)
				puts("-1 -1 -1");
			else
				printf("%d %d %d\n", a, b, c);
		}else
		{
			puts("-1 -1 -1");
		}
	}
   	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
using namespace std;
set<int>s;
int p[123456], n, m, a[123456], ans;
signed main() {
	cin >> n >> m;
	while (n--) {
		int x; cin >> x;
		if (s.find(x) != s.end()) {
			s.erase(x);
			p[x % m] += 2;
		}
		else s.insert(x);
	}
	for (int i : s)a[i % m]++;
	for1(i, (m + 1) / 2 - 1) {
		while (p[i] && a[i] + 2 <= a[m - i]) { p[i] -= 2; a[i] += 2; }
		while (p[m - i] && a[m - i] + 2 <= a[i]) { p[m - i] -= 2; a[m - i] += 2; }
		ans += p[i] / 2 + p[m - i] / 2 + min(a[i], a[m - i]);
	}
	ans += p[0] / 2 + a[0] / 2;
	if (m % 2 == 0)ans += p[m / 2] / 2 +a[m / 2] / 2;
	puts(ans);
}

Measured memory_bytes: 5760
<?php

while (true) {
	$stdin = preg_split('/ /', trim(fgets(STDIN)));
	$a = intval($stdin[0]);
	$b = intval($stdin[1]);
	
	if ($a == 0 && $b == 0) break;
	
	if ($a > $b) {
		$temp = $a;
		$a = $b;
		$b = $temp;
	}
	
	print("{$a} {$b}\n");
}

Measured memory_bytes: 6656
from math import *
import itertools

S = int(input())
T = 10**9

M = S % T

a = 1
b = (T - M) % T
x = 10**9
y = (S + a*b)/x

X3 = x
Y2 = y
X2 = a
Y3 = b

print('0 0 ' + str(int(X2)) + ' ' + str(int(Y2)) + ' ' + str(int(X3)) + ' ' + str(int(Y3)))



Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int read()
{
	int x = 0, f = 1; char c = getchar(); 
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

typedef long long LL;
const int maxn = 3010, mod = 1e9 + 7;
int a[maxn], f[maxn][maxn];

int Pow(int x, int p)
{
	int r = 1;
	while(p)
	{
		if(p & 1) r = (LL)x * r % mod;
		x = (LL)x * x % mod; p >>= 1;
	}
	return r;
}

int main()
{

	int n = read(), Q = read();
	for(int i = 1; i <= n; ++i) a[i] = read();
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(a[i] < a[j]) f[i][j] = 1;

	int inv2 = 500000004, tmp = Pow(2, Q);
	while(Q--)
	{
		int x = read(), y = read();
		f[x][y] = f[y][x] = (LL)(f[x][y] + f[y][x]) * inv2 % mod;
		for(int i = 1; i <= n; ++i)
			if(i != x && i != y)
				f[i][x] = f[i][y] = (LL)inv2 * (f[i][x] + f[i][y]) % mod,
				f[x][i] = f[y][i] = (LL)inv2 * (f[x][i] + f[y][i]) % mod;
	}

	int ans = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j < i; ++j)
			(ans += f[i][j]) %= mod;

	cout << (LL)ans * tmp % mod << endl;

	return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    int count = 0;
    for(int i = 0; i < 3; ++i){
        if (s[i] == t[i])
            ++count;
    }
    cout << count << endl;
}


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

using i64 = int64_t;

int main(){
    i64 n, k;
    cin >> n >> k;
    vector<i64> v, nxt(n, -1), num2idx(200001, -1);
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
        if(num2idx[a] != -1)nxt[num2idx[a]] = i;
        num2idx[a] = i;
    }
    for(int i=0;i<n;++i){
        if(nxt[num2idx[v[i]]] != -1)continue;
        nxt[num2idx[v[i]]] = i;
    }

    i64 a = 0, period = 0;
    do{
        i64 b = nxt[a];
        if(b <= a)period++;
        b = (b+1) % n;
        if(b == 0)period++;
        a = b;
    }while(a != 0);

    i64 m = k % period - 1;
    if(m < 0)m += period;
    //cerr << period << " " << m << endl;
    a = 0;
    while(m > 0){
        i64 b = nxt[a];
        if(b <= a)m--;
        b = (b+1) % n;
        if(b == 0)m--;
        a = b;
        //cerr << a << " " << m << endl;
    }

    vector<i64> ans;
    for(;a<n;++a){
        if(nxt[a] > a){
            a = nxt[a];
            continue;
        }
        ans.push_back(v[a]);
    }
    for(int i=0;i<(int)ans.size();++i){
        if(i)cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 9072
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long M) {
  ll ret = min(N, M / 2);
  M -= ret * 2;
  ret += M / 4;

  cout << ret << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  long long M;
  cin >> N;
  cin >> M;
  solve(N, M);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,i,t,ans=0;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t;
		while (t%2==0){
			t/=2;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
    int a;
    int f;
    long long int t;
}node;

int compare_ascending(const void* a, const void* b){
    if(*(long long int*)a > *(long long int*)b){
        return 1;
    }
    if(*(long long int*)a < *(long long int*)b){
        return -1;
    }
    return 0;
}
int compare_descending(const void* a, const void* b){
    if(*(long long int*)a > *(long long int*)b){
        return -1;
    }
    if(*(long long int*)a < *(long long int*)b){
        return 1;
    }
    return 0;
}

int main(){
    int n;
    long long int k;
    scanf("%d %lld", &n, &k);
    long long int a[n], f[n];
    for(int i=0; i<n; i++){
        scanf("%lld", &a[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%lld", &f[i]);
    }
    qsort(a, n, sizeof(long long int), compare_ascending);
    qsort(f, n, sizeof(long long int), compare_descending);
    long long int l = 0, r = a[n-1]*f[0] + 1;
    long long int m = (l+r)/2;
    while(l < r){
        long long int cnt = 0;
        for(int i=0; i<n; i++){
            if(a[i]*f[i] > m){
                cnt += a[i] - m/f[i];
            }
        }
        if(cnt <= k){
            r = m;
        }else{
            l = m+1;
        }
        m = (l+r)/2;
    }
    printf("%lld", m);

    return 0;
}

Measured memory_bytes: 4860
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int room[][][] = new int [4][3][10];
        Arrays.fill(room, 0, 0, 0);
        
        for(int i = 0; i < n; i++){
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            room[b - 1][f - 1][r - 1] += v;
        }
        
        StringBuilder sb = new StringBuilder();
        
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    sb.append(" ").append(room[i][j][k]);
                }
                sb.append("\n");
            }
            if(i != 3){
                sb.append("####################").append("\n");
            }
        }
        System.out.print(new String (sb));
    }
}


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

int main(void) {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  cout << min({abs(A1 - A2) + abs(A2 - A3), abs(A1 - A3) + abs(A3 - A2),
               abs(A2 - A1) + abs(A1 - A3)})
       << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())

ans = [0, 0, 0, 0]
for i in range(n):
    inp = input()
    if inp == "AC":
        ans[0] += 1
    elif inp == "WA":
        ans[1] += 1
    elif inp == "TLE":
        ans[2] += 1
    else:
        ans[3] += 1

code = ["AC", "WA", "TLE", "RE"]
for a, c in zip(ans, code):
    print(c, "x", a)

Measured memory_bytes: 9188
import java.io.*;
import java.util.*;
class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        while(true){
            try{
                System.out.println(prime_number(Integer.parseInt(br.readLine())));
            }catch(Exception e){
                System.exit(0);
            }
        }
    }
    
    static int prime_number(int n){
        boolean[] array=new boolean[n+1];
        Arrays.fill(array, true);
        int i=2;
        array[0]=false;
        array[1]=false;
        while(Math.pow(i, 2)<=n){
            int j=i+i;
            while(j<=n){
                array[j]=false;
                j+=i;
            }
            i++;
        }
        
        int count=0;
        for(i=0;i<array.length;i++){
            if(array[i]) count++;
        }
        
        return count;
    }
}

Measured memory_bytes: 39532
import java.util.*;
 
 
 
public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int max = 1;
		 Map<String, Integer> map = new HashMap<String, Integer>();
		 while(N > 0) {
			 String str = sc.next();
			if(map.containsKey(str)) {
				map.put(str,(map.get(str)+1));
			}
			else {
                map.put(str,1);
            }
			 if (map.get(str) > max) {
	                max = map.get(str);
	            }
			N--;
		 }
	        List<String> result = new ArrayList<>();
	        for (String str: map.keySet()){
	            if(map.get(str) == max){
	                result.add(str);
	            }
	        }
	        Collections.sort(result);
	        for(String s : result) {
	        	System.out.println(s);
	        }
	}
}

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

const int MaxN = 10 + 2;

int N;
int A[MaxN];

int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  sort(A + 1, A + 1 + N);
  int sum = 0;
  for (int i = 1; i < N; ++i) sum += A[i];
  if (sum > A[N]) puts("Yes");
  else puts("No");
  return 0;
}

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

int main(){
	ll N,K;
	cin >> N >> K;
	vector<ll> A(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
		A[i]--;
	}

	ll ans=0,sum=0;
	map<ll,ll> ma;
	ma[0]++;
	vector<ll> clear;
	for(int i=0;i<N;i++){
		if(i==K-1)ma[0]--;
		if(i-K>=0)ma[clear[i-K]]--;
		(sum += A[i] ) %= K;
		ans += ma[sum];
		ma[sum]++;
		clear.push_back(sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 15856
#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define f first
#define s second
#define LL long long
using namespace std;

LL n,tar,ans;
int main(){
	cin>>n>>tar;
	for (int i=0;i<=n;i++){
		for (int j=0;j<=n;j++){
			if (tar-(i+j)<=n && tar-(i+j)>=0) ans++;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3612