akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long int
#define mod 1000000007
#define adjSize 100000
#define MAX 1000000000
#ifdef FASTIO
#endif
/*
	Coded by Archit Shinde
*/
bool prime[(ll)1e7+1]; 
 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
 
unordered_set<ll> primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    unordered_set<ll> result;
    if(n%2==0){
    	result.insert(2);
    	while(n%2==0){
    		n=n/2;
    	} 
    }
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        if(n%i==0){
        	result.insert(i);
        	while(n%i==0){
        		n=n/i;
        	}
        }
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
    	result.insert(n);
    return result;
}  

vector<ll> printDivisors(int n) 
{ 
    // Note that this loop runs till square root 
    vector<ll> div;
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i && i%2 != 0 && i != 1){
                div.push_back(i);
            }
  
            else // Otherwise print both 
            {
            	if(i%2!=0)
                	div.push_back(i);
                if((n/i) %2!=0)	
                	div.push_back(n/i);

            }
        } 
    }
    //sort(div.begin(), div.end());
    return div;
} 

unordered_set<ll> SieveOfEratosthenes(ll n) 
{ 
	unordered_set<ll> u;
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    for (ll p=2; p<=n; p++) 
       if (prime[p]) 
          u.insert(p);
    return u;
}

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

ll product(ll num, ll result[], ll size){
	ll m = 0;
	ll i = 0;
	ll ans;
	for(i = 0; i<size; i++){
		ans = num*result[i]+m;
		m = ans/10;
		result[i] = ans%10;
	}
	while(m!=0){
		result[size] = m%10;
		m /= 10;
		size++;
	}
	return size;
}
void factorial(ll n){
	ll result[159];
	result[0] = 1;
	ll i, size = 1;
	for(i = 2; i<=n; i++){
		size = product(i, result, size);
	}
	for(i = size-1; i>=0; i--){
		cout<<result[i];
	}
}


int main()
{
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	ll n;
	cin>>n;
	ll ans = 1000 - (n%1000);
	if(ans == 1000){
		cout<<0<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3564
import itertools
n,c=map(int,input().split())
ld=[list(map(int,input().split())) for i in range(c)]
lc=[list(map(int,input().split())) for i in range(n)]
ct=[[0 for i in range(c)] for i in range(3)]
for i in range(n):
  for j in range(n):
    ct[(i+j+2)%3][lc[i][j]-1]+=1
L=list(itertools.permutations([i for i in range(c)],3))
ans=[]
for i in range(len(L)):
  ct2=0
  for j in range(3):
    for k in range(c):
      ct2+=ld[k][L[i][j]]*ct[j][k]
  ans.append(ct2)
print(min(ans))

Measured memory_bytes: 46428
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n;

int main() {
    scanf("%d",&n);
    if (n==(n&-n)) {
        puts("No");
        return 0;
    }
    puts("Yes");
    for (int i=2;i<n;i+=2) {
        printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,1,i+1,1,i+n+1,i,i+1,i+n);
    }
    printf("%d %d\n",1+n,3+n);
    if (n%2==0) {
        int cnt = 1;
        while (cnt<n) cnt*=2;
        cnt/=2;
        printf("%d %d\n%d %d\n",n,cnt,n+n,(n^cnt^1));
    }

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////


ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}

#define N 400005
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}

ll n;
vector<ll>v[N];
ll kaz[N];
//ll par[N];
ll dp[N];

ll dfs1(ll id,ll par){
    dp[id]=1;kaz[id]=1;
    for(auto x:v[id]){
        if(x==par)continue;
        dp[id]=mod(dp[id]*dfs1(x,id));
        dp[id]=mod(dp[id]*kai2[kaz[x]]);
        kaz[id]+=kaz[x];
    }
    dp[id]=mod(dp[id]*kai[kaz[id]-1]);
    return dp[id];
}
void dfs2(ll id,ll par,ll dppar){
    ll kazpar=n-kaz[id];
    dp[id]=mod(dp[id]*kai[n-1]);
    dp[id]=mod(dp[id]*kai2[kaz[id]-1]);
    dp[id]=mod(dp[id]*kai2[kazpar]);
    dp[id]=mod(dp[id]*dppar);
    for(auto x:v[id]){
        if(x==par)continue;
        ll res=dp[id];
        res=mod(res*kai[kaz[x]]);
        res=mod(res*kai[n-1-kaz[x]]);
        res=mod(res*kai2[n-1]);
        res=mod(res*bunbo(dp[x]));
        dfs2(x,id,res);
    }
}

int main(){fastio
    calc();
    cin>>n;
    rep(i,1,n-1){
        ll a,b;cin>>a>>b;
        v[a].pb(b);v[b].pb(a);
    }
    dfs1(1,-1);
    //rep(i,1,n)cout<<dp[i]<<" ";cout<<endl;
    //rep(i,1,n)cout<<kaz[i]<<" ";cout<<endl;
    dfs2(1,-1,1);
    rep(i,1,n)cout<<dp[i]<<endl;
    return 0;
}


Measured memory_bytes: 31472
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		int count = 0;


		string s1 = Console.ReadLine();
		string s2 = Console.ReadLine();

		for(int i = 0;i < s1.Length; i++)
        {
            if (s1[i] != s2[i])
            {
                count++;
            }
        }

        Console.WriteLine(count);

	}

}

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

int main(){
  int H,N;
  cin>>H>>N;
  vector<int> vec(N);
  int sum=0;
  for(int i=0;i<N;i++){
  	cin>>vec.at(i);
    sum+=vec.at(i);
  }
  if(sum<H)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1LL<<60;
const int MOD = 1e9+7;

signed main()
{
   string s; cin >> s;

   string t;
   for (int i = 0; i < s.size(); ++i) {
      if (s[i] != 'x') t += s[i];
   }

   for (int i = 0; i <= t.size()/2; ++i) {
      if (t[i] != t[t.size() + ~i]) {
         cout << -1 << endl;
         return 0;
      }
   }

   int idx = 0;
   map<int,int> cnt;
   for (int i = 0; i < s.size(); ++i) {
      if (s[i] == 'x') {
         ++cnt[idx];
      } else {
         ++idx;
      }
   }

   int ans = 0;
   for (int i = 0; i <= t.size()/2; ++i) {
      ans += abs(cnt[i] - cnt[t.size() - i]);
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, u, v, M;
vector<vector<int>> G;

vector<int> bfs(int u) {
  vector<int> d(N, -1);
  queue<int> q;
  q.push(u);
  d[u] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int w : G[v]) {
      if (d[w] != -1) continue;
      d[w] = d[v] + 1;
      q.push(w);
    }
  }
  return d;
}

int main() {
  cin >> N >> u >> v;
  --u, --v;
  G.resize(N);

  rep(i, N - 1) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  vector<int> dT = bfs(u), dA = bfs(v);

  if (G[u].size() == 1 && G[u][0] == v) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;

  rep(i, N) {
    if (dT[i] < dA[i]) ans = max(ans, dA[i] - 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6784
k,n=map(int,input().split())
a=[0]*n
a=list(map(int,input().split()))

ans=0
for i in range(n-1):
    num=a[i+1]-a[i]
    ans=max(ans,num)
num=k-(a[n-1]-a[0])
ans=max(ans,num)
print(k-ans)

Measured memory_bytes: 27980
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// AGC024 B - Backfront

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> P(N);
  REP(i, N){
    cin >> P[i];
  }
  vector<int> PP(N+1, 0);
  REP(i, N){
    PP[P[i]] = PP[P[i]-1] + 1;
  }
  int res = 0;
  REP(i, N+1){
    res = max(res, PP[i]);
  }
  int ans = N - res;
  cout << ans << endl;
}

Measured memory_bytes: 4756
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    int a[200005], r[200005], b[200005];
    for(int i = 0; i < n; i++) r[i] = -1;
    for(int i = 0; i <= 200000; i++) b[i] = -1;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(b[a[i]] != -1){
            r[b[a[i]]] = i;
        }
        b[a[i]] = i;
    }
    for(int i = 0; i < n; i++){
        if(r[b[a[i]]] == -1) r[b[a[i]]] = i;
        b[a[i]] = i;
    }
    int u = 0;
    ll s = 0;
    for(int i = 0; i < n; i++){
        if(r[u] == u) s += n + 1;
        else s += (r[u] + n - u) % n + 1;
        u = (r[u] + 1) % n;
        if(u == 0) break;
    }
    k = k * n % s;
    for(int i = 0; i < n; i++){
        ll c;
        if(r[u] == u) c = n + 1;
        else c = (r[u] + n - u) % n + 1;
        if(k >= c){
            k -= c;
            u = (r[u] + 1) % n;
        }
        else{
            int ans[200005];
            int l = 0;
            while(k){
                ll c;
                if(r[u] == u) c = n + 1;
                else c = (r[u] + n - u) % n + 1;
                if(k >= c){
                    k -= c;
                    u = (r[u] + 1) % n;
                }
                else{
                    k--;
                    ans[l] = a[u];
                    u = (u + 1) % n;
                    l++;
                }
            }
            for(int j = 0; j < l; j++) cout << ans[j] << " ";
            cout << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n,m,a[N],f[N],p[N];
int sf(int x){
	return x==f[x]?f[x]:f[x]=sf(f[x]);
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
		f[i]=i;
	}
	for(int i=0,x,y; i<m; i++) {
		scanf("%d%d",&x,&y);
		f[sf(x)]=sf(y);
	} 
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(sf(i)==sf(a[i])) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int a,r,x[4],y[4],i,j,c,d;
	while(scanf("%d%d",&a,&r),a)
	{
		for(i=0;i<4;++i)x[i]=a%10,y[i]=r%10,a/=10,r/=10;
		for(c=d=i=0;i<4;++i)
		{
			if(x[i]==y[i])++c;
			else for(j=1;j<4;++j)if(x[i]==y[(i+j)%4])++d;
		}
		printf("%d %d\n",c,d);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf =0x3f3f3f3f;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define maxn 1000010
const int S=20;
ll gcd(ll a,ll b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}

int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
    string a="ARC",b="ABC";
    string temp;
    cin>>temp;
    if(temp==a) cout<<b<<endl;
    else cout<<a<<endl;

    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n;
  map<string, int> score;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    score[s]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    score[s]--;
  }
  int ans = -100000000;
  for (auto e : score) {
    ans = max(e.second, ans);
  }

  if (ans < 0) {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))
m=1000
r=0
for i in range(len(H)):
    s=abs(t-0.006*H[i]-a)
    if s<m:
        r=i+1
        m=s
print(r)

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

class MainClass
{
    static void Main()
    {
        var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = NM[0], M = NM[1];
        string S = Console.ReadLine();

        int now = N;
        var ans = new List<int>();
        while (true)
        {
            bool frag = false;
            for (int i = M; i >= 1; i--)
            {
                int next = now - i;
                if (next < 0) continue;
                if (S[next] == '0')
                {
                    frag = true;
                    now = next;
                    ans.Add(i);
                    break;
                }
            }
            if (!frag)
            {
                Console.WriteLine(-1);
                return;
            }
            else if (now == 0)
                break;
        }
        ans.Reverse();
        Console.WriteLine(string.Join(" ",ans));
    }
}

Measured memory_bytes: 30316
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))

here = 1
log = [1]
loop = []
num_log = [0] * (n + 1)
num_log[1] = 1
for i in range(k):
    here = A[here]
    if num_log[here] == 1:
        pre_loop = log.index(here)
        k = k - pre_loop
        loop = log[pre_loop:]
        here = loop[k % len(loop)]
        break
    else:
        num_log[here] = 1
    log += [here]
print(here)


Measured memory_bytes: 95276
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        sc.nextInt();
        String tmp;
        for(int i=0;i<h;i++){
            tmp=sc.next();
            for(int j=0;j<2;j++)System.out.println(tmp);
        }
    }
    
 
}

Measured memory_bytes: 24276
#include <iostream>
#include <vector>
#define NIL -1
#define rep(i,a) for(i=0;i<a;i++)
using namespace std;

typedef struct{
    int parent;
    int left;
    int right;
    int depth;
}tree;

void rec(vector<tree> &T, int p, int q){
    T[p].depth = q;
    if(T[p].right != NIL) rec(T,T[p].right,q);
    if(T[p].left != NIL) rec(T,T[p].left,q+1);

}

void print(vector<tree> &T, int p){
    int i=0,c;

    cout << "node " << p << ": ";
    cout << "parent = " << T[p].parent << ", ";
    cout << "depth = " << T[p].depth << ", ";
    if(T[p].parent == NIL) cout << "root, ";
    else if(T[p].left == NIL) cout << "leaf, ";
    else cout << "internal node, ";
    cout << "[";
    for(c = T[p].left; c != NIL; c = T[c].right,i++){
        if(i) cout << ", ";
        cout <<  c;
    }
    cout << "]" << endl;
}

int main(void){
    int i,j,v,d,c,l,r,n;

    cin >> n;
    vector<tree> T(n);
    rep(i,n){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
    rep(i,n){
        cin >> v >> d;
        rep(j,d){
            cin >> c;
            if(j==0) T[v].left = c;
            else T[l].right = c;
            l = c;
            T[c].parent = v;
        }
    }
    rep(i,n){
        if(T[i].parent == NIL) r = i;
    }

    rec(T,r,0);

    rep(i,n){
        print(T,i);
    }
    return 0;
}

Measured memory_bytes: 5756
n=int(input())
import numpy as np
l=np.zeros(81).reshape(9,9)
for i in range(1,1+n):
    first=int(str(i)[0])-1
    last=int(str(i)[-1])-1
    if last>=0:
        l[first][last]+=1
ans=0
for i in range(9):
    for j in range(i,9):
        ans+=l[i][j]*l[j][i]
        if i!=j:
            ans+=l[i][j]*l[j][i]
print(int(ans))


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 55, M = 3e3, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    ll a, b, x; cin >> a >> b >> x;

    cout << (b / x) - (max(0ll, (a-1)) / x) + (a == 0);
}

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

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

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  uint64_t a, b, x;
  cin >> a >> b >> x;

  uint64_t res = (a > 0) ? b / x - (a - 1) / x : b / x + 1;

  cout << res << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> vab(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
      swap(a, b);
    }

    vab[i].first = a;
    vab[i].second = b;
  }

  sort(vab.begin(), vab.end());
  int l = vab[0].first, r = vab[0].second;

  int ans = 0;
  for (int i = 1; i < m; ++i) {
    int tmp_l = l, tmp_r = r;
    l = max(l, vab[i].first);
    r = min(r, vab[i].second);
    // cout << r - l << '\n';
    if (r - l < 1) {
      ans++;
      l = vab[i].first;
      r = vab[i].second;
    }

    if (i == m - 1) {
      ans++;
    }
  }

  // cout << l << ' ' << r << '\n';
  cout << max(1, ans) << '\n';
  return 0;
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    P = [0] + list(map(int, input().split()))
    C = [0] + list(map(int, input().split()))
    circle_scores = [0] * (N + 1)
    circle_times = [0] * (N + 1)

    checked = set()  # これがないと最悪O(N^2)になる。。。
    all_negative = True
    for i in range(1, N + 1):
        if i in checked: continue
        visited = set()
        now = i
        while now not in visited:
            visited.add(now)
            now = P[now]
            circle_scores[i] += C[now]
            circle_times[i] += 1
        for j in visited:
            circle_scores[j] = circle_scores[i]
            circle_times[j] = circle_times[i]
            checked.add(j)

    ans = max(C[1:])
    for i in range(1, N + 1):
        q, r = K // circle_times[i], K % circle_times[i]
        if q > 0: q, r = q - 1, r + circle_times[i]
        val = circle_scores[i] * q
        if circle_scores[i] <= 0:
            val = 0
            r = min(circle_times[i] - 1, K)
        now = P[i]
        add_val = C[now]
        add_max_val = C[now]
        for _ in range(r - 1):
            now = P[now]
            add_val += C[now]
            add_max_val = max(add_max_val, add_val)
        ans = max(ans, val + add_max_val)
    print(ans)



if __name__ == "__main__":
    main()


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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
    int N;
    cin >> N;
    int ans =0;
    for(int i=1;i<N+1;i++){
      int num = 0;
      if(i%2==0){
        continue;
      }
      for(int h=1;h<i+1;h++){
        if(i%h==0){
          num++;
        }
      }
      if(num==8){
        ans++;
      }
    }
    
    printl(ans);
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
typedef long long ll;

ll calc_gcd(ll x, ll y) {
    if (y == 0) return x;
    return calc_gcd(y, x % y);
}

int main() {
    ll N, K, a, all_gcd, max_a = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (i == 0) all_gcd = a;
        else {
            all_gcd = calc_gcd(max(all_gcd, a), min(all_gcd, a));
        }
        max_a = max(max_a, a);
    }
    if (K <= max_a && K % all_gcd == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
    int H,N,i;
	int A[1000001];
	int s=0;
	scanf("%d %d",&H,&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<N;i++){
		s=s+A[i];
	}
	if(s>=H){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
    }

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

int main()
{
  int m, f, mu, t;

  string grade;

  while( true ) {
    cin >> m >> f >> mu;
    if( m == -1 and f == -1 and mu == -1 ) {
      break;
    }

    t = m + f;
    grade = "";
    if( 80 <= t ) {
      grade = "A";
    }
    if( 65 <= t and t < 80 ) {
      grade = "B";
    }
    if( 50 <= t and t < 65 ) {
      grade = "C";
    }
    if( 30 <= t and t < 50 ) {
      if( 50 <= mu ) {
        grade = "C";
      }
      else {
        grade = "D";
      }
    }
    if( t < 30 ) {
      grade = "F";
    }
    if( m == -1 or f == -1 ) {
      grade = "F";
    }

    cout << grade << endl;
  }

  return 0;
}

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

int main(){
    int x, y;
    cin >> x >> y;
    bool ans = false;
    for(int i = 0; i <= x; i++){
        int leg = i * 2 + ((x-i)*4);
        if (leg == y){
            ans = true;
            break;
        }
    }

    if (ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
// inputに入力データ全体が入る
function Main(input) {


  var inp = input.split('\n');

  var buf = inp[0].split(' ');

  var N = parseInt(buf[0]);
  var x = parseInt(buf[1]);

  var an = inp[1].split(' ');

  // ソート
  an.sort(function (a, b) {
    return a - b;
  })

  var ans = 0;
  for (var i = 0; i < N; i++) {
    if(parseInt(an[i]) <= x){
      x -= parseInt(an[i]);
      ans++;
    }else{
      break;
    }
    if(i === N - 1){
      if(x !== 0) ans--;
    }
  }

  console.log('%d', ans);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7500
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.141592653589793238

int main() {
	vector<vector<int>> c(3, vector<int>(3));
	rep(i, 3) {
		rep(j, 3) {
			cin >> c[i][j];
		}
	}
	int a1 = c[0][0], a2 = c[0][1], a3 = c[0][2], b1 = 0, b2 = c[1][0] - a1, b3 = c[2][0] - a1;
	if (a2 + b2 == c[1][1] && a2 + b3 == c[2][1] && a3 + b2 == c[1][2] && a3 + b3 == c[2][2]) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   string str;
   while(cin>>str)
   {
     if(str=="-") break;
     else
     {
       int count;
       cin>>count;
       while(count--)
       {
         int inter;
         cin>>inter;
         string a=str.substr(0,inter);
         string b=str.substr(inter);
         str=(b+a);              
       }    
     }      
     cout<<str<<endl;         
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll   = long long;
using ull  = unsigned long long;
using vi   = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

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

    cout << n / 3 << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    int d;
    cin >> d;
    string ans = d == 25 ? "Christmas" : d == 24 ? "Christmas Eve" : d == 23 ? "Christmas Eve Eve" : "Christmas Eve Eve Eve";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

s = input() + "T"
x, y = map(int, input().split())
A = []
B = []
now = 0
di = 1
for i in s:
  if i=="T":
    if di:
      A.append(now)
    else:
      B.append(now)
    now = 0
    di ^= 1
  else:
    now += 1

def test(L, dist):
  dist = abs(dist)
  su = sum(L)
  l = len(L)
  if su < dist or (su-dist)%2:
    return False
  can = (su-dist)//2
  dp = np.zeros(can+1, dtype=bool)
  dp[0] = True
  for i in L:
    if i <= can:
      dp[i:] |= dp[:can+1-i]
  return dp[-1]

if s[0] == "F":
  a = test(A[1:], x-A[0])
else:
  a = test(A, x)
b = test(B, y)
if a and b:
  print("Yes")
else:
  print("No")

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

using P = Point<long long>;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	P p0, p1;
	cin >> p0.x >> p0.y >> p1.x >> p1.y;
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		P p2;
		cin >> p2.x >> p2.y;
		long long x = (p1 - p0).cross(p2 - p0);
		if(x > 0){
			cout << "COUNTER_CLOCKWISE" << '\n';
		} else if(x < 0){
			cout << "CLOCKWISE" << '\n';
		} else {
			long long v1 = (p1 - p0).dot(p1 - p0);
			long long v2 = (p2 - p0).dot(p1 - p0);
			if(v1 < 0){
				v1 = -v1; v2 = -v2;
			}
			if(v2 < 0){
				cout << "ONLINE_BACK" << '\n';
			} else if(v2 > v1){
				cout << "ONLINE_FRONT" << '\n';
			} else {
				cout << "ON_SEGMENT" << '\n';
			}
		}
	}
}


Measured memory_bytes: 3180
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

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

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    int64_t A, B;
    cin >> n >> A >> B;
    vector<int64_t> x(n);
    cin >> x;
    int64_t ans = 0;
    for (int i = 1; i < n; ++i) {
        ans += min(B, A * (x[i] - x[i - 1]));
    }
    cout << ans;
}


Measured memory_bytes: 3936
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
//#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;

ll d;

pl ff(vvl s,vl c,vl last,ll depth,ll hukasa){
    if(hukasa >= 1 || depth >= d) return {0,0};
    ll ret = -inf;
    ll retind = 0;
    rep(i,26){
        ll minus = 0;
        rep(j,26){
            if(j != i) minus += c[j]*(depth-last[j]);
        }
        if(ret < s[depth][i]-minus){
            ret = s[depth][i]-minus;
            retind = i;
        }
    }
    return {retind,ret};
}

pl f(vvl s,vl c,vl last,ll depth,ll hukasa){
    if(hukasa >= 1 || depth >= d) return {0,0};
    ll ret = -inf;
    ll retind = 0;
    rep(i,26){
        ll minus = 0;
        rep(j,26){
            if(j != i) minus += c[j]*(depth-last[j]);
        }
        ll moto = last[i];
        last[i] = depth;
        pl saki = ff(s,c,last,depth+1,hukasa+1);
        last[i] = moto;
        if(ret < s[depth][i]-minus+saki.second){
            ret = s[depth][i]-minus;
            retind = i;
        }
    }
    return {retind,ret};
}

void score(vvl s,vl c,vl t){
    vl last(26);
    ll ans = 0;
    rep(i,d){
        ans += s[i][t[i]];
        ll minus = 0;
        last[t[i]] = i;
        rep(j,26) minus += c[j]*(i-last[j]);
        ans -= minus;
    }
    cout<<ans<<endl;
}

int main(){
    cin>>d;
    vl c(26);
    rep(i,26) cin>>c[i];
    vvl s(d,vl(26));
    rep(i,d) rep(j,26) cin>>s[i][j];
    vl last(26,0);
    vl t(d);
    rep(i,d){
        ll tmp = f(s,c,last,i,0).first;
        last[tmp] = i;
        cout<<tmp+1<<endl;
        t[i] = tmp;
    }
    //score(s,c,t);
    return 0;
}

Measured memory_bytes: 3936
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b, c;

	cin>>a>>b>>c;

	bool flag=false;

	repr(i, 1, b+1){
		if(a*i%b==c) flag=true;
	}
	cout<<YN(flag)<<endl;
}

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

int n;
int a[50];

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++){
  
    cin>>a[i];
    
  }
  
  sort( a, a + n );
  
  double ans = 0;
  
  for(int i=0;i<n;i++){
    if( i ) ans = ( ans + a[i] ) / 2;
    else ans += a[i];
  }
  
  cout<<ans<<endl;
  
  return 0;
}


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

int main(){
    vector<int> dish(5);
    rep(i, 0, 5){
        cin >> dish.at(i);
    }
    vector<int> v(5);
    iota(v.begin(), v.end(), 0);
    int cost = 1000 * 5;
    do {
        vector<int> comb;
        for(auto x: v){
            comb.push_back(x);
        }
        int time = 0;
        for (int i = 0; i < 4; i++){
            time += (dish[comb[i]] + 9) / 10 * 10;
        }
        time += dish[comb[4]];
        cost = min(cost, time);
    } while( next_permutation(v.begin(), v.end()));  
    cout << cost << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.regex;
import std.typecons;


int[] 素数の集合()
{
	const nの最大値 = 1000000;
	auto 表 = new bool[nの最大値];
	表[] = true;
	表[0] = 表[1] = false;
	int[] 素数;
	foreach(int i; 0 .. nの最大値)
	{
		if(表[i])
		{
			素数 ~= i;
			for(int j = 2 * i; j < nの最大値; j += i)
				表[j] = false;
		}
	}
	return 素数;
}

void main()
{
    auto 集合 = 素数の集合();
    int m = cast(int)集合.length;
	string l;
    while(l = readln(), l.length)
    {
		int n = l.chomp.to!int;
		if(n < 2)
			writeln(0);
		else if(集合[m - 1] <= n)
			writeln(m);
		else
		{
			for(int i; i <= m; ++i)
			{
				if(集合[i] > n)
				{
					writeln(i);
					break;
				}
			}
		}
	}
}

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

int main() {
	ll n,m,ans=0,sum,a[100010];
	char s;
	cin>>s;
	bool w=1;
	if(s=='W'){
		w=1;
	}
	else{
		w=0;
	}
	while(cin>>s){
		bool sw=( s=='W'? 1:0);
		if(sw!=w){
			ans++;
			w=sw;
		}
	}
	cout <<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<"square1001"<<endl;
}



Measured memory_bytes: 3084
import Control.Monad
import Control.Applicative

main = do
	[n, m] <- (map read . words) <$> getLine
	a <- replicateM n $ (map read . words) <$> getLine
	b <- replicateM m $ read <$> getLine
	mapM_ print $ map sum $ map (zipWith (*) b) a 

Measured memory_bytes: 7548
//
// Created by yamunaku on 2019/11/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    cout << (n-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()
prefix=[0]*(n+1)
for i in range(1,n):
	if s[i]=="C" and s[i-1]=="A":
		prefix[i+1]=1+prefix[i]
	else:
		prefix[i+1]=prefix[i]
# print(prefix)
for i in range(q):
	l,r=map(int,input().split())
	if prefix[r]==prefix[l]:
		print(0)
	else:
		print(prefix[r]-max(prefix[l-1],prefix[l]))

Measured memory_bytes: 53712
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    long N,K;
    cin >> N >> K;
    vector<long> enemy(N);
    repi(i,N){
        cin >> enemy[i];
    }
    sort(all(enemy));
    reverse(all(enemy));
    long Ans = 0;
    repi(i,N){
        if(i<K){
            continue;
        }else{
            Ans += enemy.at(i);
        }
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 1792
fn main() {
    proconio::input! {
        n: usize,
        a: [usize; n]
    }

    let maxn: usize = 1000000;
    let mut dp: Vec<usize> = vec![0; maxn + 1];

    for i in (2..).take_while(|&x| x * x <= maxn) {
        if dp[i] != 0 { continue; }
        for j in (i..maxn).step_by(i) {
            if dp[j] == 0 { dp[j] = i; }
        }
    }
 
    let mut used: Vec<bool>  = vec![false; maxn + 1];

    let mut is_paircoprime = true;

    for i in 0..n {
        let mut x = a[i];
        while x != 1 {
            let y = if dp[x] != 0 { dp[x] } else { x };
            if x != 1 && used[x] { is_paircoprime = false; }
            if y != 1 && used[y] { is_paircoprime = false; }
            used[x] = true;
            used[y] = true;
            while x % y == 0 { x /= y; }
        }

        if !is_paircoprime { break; }
    }

    if is_paircoprime {
        println!("pairwise coprime");
        return;
    }

    let setwise = &a.iter()
        .fold(a[0], |x: usize, &y: &usize| num::integer::gcd(x, y) as usize);

    if *setwise == 1 {
        println!("setwise coprime");
        return;
    }

    println!("not coprime");
    return;
}


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

int    n, m, ans;
int    a[60], b[60];
string color[10];

vector<int> adj[10];

bool ch()
{
    bool flag = true;
    for (int i = 0; i < n; i++) {
        if (color[i] == "White") {
            flag = false;
        }
    }
    if (flag) {
        return true;
    } else {
        return false;
    }
}

void ini()
{
    rep(i, n) color[i] = "White";
}

void dfs(int now)
{
    if (ch()) {
        ans++;

        return;
    }
    for (int i : adj[now]) {
        if (color[i] == "White") {
            color[i] = "Black";
            dfs(i);
            color[i] = "White";
        }
    }
}

int main()
{
    cin >> n >> m;
    rep(i, n) color[i] = "White";

    int x, y;
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
    int now = 0;
    color[now] = "Black";
    dfs(now);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e18;
using Graph = vector<vector<int>>;

signed main()
{
  int N, M;
  cin >> N >> M;

  if (M % 2 == 1){
    int sa = M - 1;
    for (int i = 1; sa > 1; i++){
      cout << i << " " << i + sa << endl;
      sa -= 2;
    }
    sa = M;
    for (int i = M + 1; sa > 0; i++){
      cout << i << " " << i + sa << endl;
      sa -= 2;
    }
  }else{
    int sa = M;
    for (int i = 1; sa > 1; i++){
      cout << i << " " << i + sa << endl;
      sa -= 2;
    }
    sa = M-1;
    for( int i = M+2; sa > 0; i++ ){
      cout << i << " " << i+sa << endl;
      sa -= 2;
    }
  }
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  int keta = 0;

  int test = n;
  while(test>0){
    test /= 10;
    keta++;
  }
  
  int ans = 0;
  switch(keta){
  case 1:
    for(int i = 1;i<=n;i++) ans++;
    break;
  case 2:
    ans = 9;
    break;
  case 3:
    ans = 9;
    for(int i = 100;i<=n;i++) ans++;
    break;
  case 4:
    ans = 9+900;
    break;
  case 5:
    ans = 9+900;
    for(int i = 10000;i<=n;i++) ans++;
    break;
  case 6:
    ans = 9+900+90000;
  }

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


Measured memory_bytes: 3636
import sys

input = sys.stdin.readline

n = int(input())
num_edge = 0
num_vertex = 0
for i in range(1, n): 
    u_v = list(map(int, input().split()))
    u = u_v[0]
    v = u_v[1]
    if v < u:
        tmp = v
        v = u
        u = tmp
    num_edge += u * (n - v + 1)
    num_vertex += i * (n - i + 1)
num_vertex += n

print(num_vertex - num_edge)



Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main (){
  ll k,a,b;
  int N = 50;
  cin >> k;
  a=k/N;
  b=k%N;
  ll ans[50];
  cout<<"50"<<endl;
  for(int i=0;i<50;i++)
    ans[i]=i+a;
  for(int i=0;i<b;i++){
    for(int j=0;j<N;j++){
      if(i==j)
        ans[j]+=50;
      else
        ans[j]--;
    }
  }
  for(int i=0;i<N;i++){
    if(i==0)
      cout<<ans[i];
    else
      cout<<" "<<ans[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
// C - Otoshidama
// O(1) snuke氏 より
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,Y; cin>>N>>Y;
	Y /= 1000;
	int a = 0, b = 0, c = Y;

	int x, z;
	x = min(c/5, (Y-N)/4); x = max(0, x);
	Y -= x*4;
	b += x;
	c -= x*5;

	x = min(b/2, Y-N); x = max(0, x);
	Y -= x;
	a += x;
	b -= x*2;

	if(Y == N) printf("%d %d %d\n", a, b, c);
	else puts("-1 -1 -1");
}

Measured memory_bytes: 256
n=int(input())
d={2:0}
while n%2<1:  n//=2;  d[2]+=1
for i in range(3,int(n**0.5)+1,2):
  while n%i<1:  n//=i;  d[i]=d.get(i,0)+1
  if n<2: break
if n>1: d[n]=1
a=0
for i in d.values():
  t=c=0
  while t+c<i: c+=1; t+=c
  a+=c
print(a)

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

int main() {
    //入力
    int c500, c100, c50, target;
    cin >> c500 >> c100 >> c50 >> target;

    //処理
    int result = 0;
    for(int i = 0; i < (c500 + 1); i++) {
        for(int j = 0; j < (c100 + 1); j++) {
            for(int k = 0; k < (c50 + 1); k++) {
                if((i * 500 + j * 100 + k * 50) == target) {
                    result++;
                }
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3532
def examC():
    H, W = LI()
    S = [SI() for _ in range(H)]
    ans = "Yes"
    for i in range(H):
        for j in range(W):
            if S[i][j]=="#":
                if (i>0 and S[i-1][j]==".") or i==0:
                    if (H-1>i and S[i+1][j]==".") or i==H-1:
                        if (j>0 and S[i][j-1]==".") or j==0:
                            if (W-1>j and S[i][j+1]==".") or j==H-1:
                                ans = "No"
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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

int main() {

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

    for(int i=1; i<=n; i++){
        cout << "node " << i << ": ";
        cout << "key = " << a[i] << ", ";
        if(i > 1)
            cout << "parent key = " << a[i/2] << ", ";
        if(i*2 <= n)
            cout << "left key = " << a[i*2] << ", ";
        if(i*2 + 1 <= n)
            cout << "right key = " << a[i*2+1] << ", ";
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3060
n, m = gets.split.map(&:to_i)
students = []
n.times do
  students << gets.split.map(&:to_i)
end
checkpoints = []
m.times do
  checkpoints << gets.split.map(&:to_i)
end

students.each do |x, y|
  puts checkpoints.index(checkpoints.min_by {|item| (item[0] - x).abs + (item[1] - y).abs}) + 1
end


Measured memory_bytes: 1788