akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define maxn 3000
struct Node{
	int w,v;
	bool operator < (const Node &b)const{
		return w<b.w;
	}
}a[maxn+5];
int n,f[maxn*2+5];
int main(){
	int n,m;scanf("%d%d",&n,&m);
	memset(f,0,sizeof(f));
	for(int i=0;i<n;i++)scanf("%d%d",&a[i].w,&a[i].v);sort(a,a+n);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=m-1;j>=0;j--){
			f[j+a[i].w]=max(f[j+a[i].w],f[j]+a[i].v);
			ans=max(ans,f[j+a[i].w]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
  int a[3][3];
  for(int j=0;j<3;j++){
    for(int i=0;i<3;i++){
      cin>>a[j][i];}}
int N;
  cin>>N;
  int b[N];
      for(int i=0;i<N;i++){
      cin>>b[i];}

  int c[3][3]={0};
  for(int k=0;k<N;k++){ 
  for(int j=0;j<3;j++){
    for(int i=0;i<3;i++){
      if(a[j][i]==b[k])c[j][i]=1;
    }}  
  }
  
  int ans=0;
  int flag=0;
      for(int i=0;i<3;i++){
        flag=1;
	      for(int j=0;j<3;j++){
            if(flag==1){
            if(c[i][j]==0)flag=0;}
    	  }
        if(flag==1)ans=1;
      }
      for(int i=0;i<3;i++){
        flag=1;
	      for(int j=0;j<3;j++){
            if(flag==1){
            if(c[j][i]==0)flag=0;}
    	  }
        if(flag==1)ans=1;
      }  

     flag=1;
	      for(int j=0;j<3;j++){
            if(flag==1){
            if(c[j][j]==0)flag=0;}
    	  }
          if(flag==1)ans=1;
      
     flag=1;
	      for(int j=0;j<3;j++){
            if(flag==1){
            if(c[2-j][j]==0)flag=0;}
    	  }
          if(flag==1)ans=1;
      
  

if(ans==1)cout<<"Yes"<<endl;
if(ans==0)cout<<"No"<<endl;
  
  
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  int a[200010];
  int flag[200010];
  for(int i = 1; i <= 200005; i++) flag[i] = 0;
  for(int i = 1; i <= n; i++) cin >> a[i];
  
  int pos = 1, cnt = 0;
  while(k) {
    pos = a[pos];
    k--;
    cnt++;
    if(flag[pos]) k %= (cnt-flag[pos]);
    else flag[pos] = cnt;
  }
  cout << pos << "\n";
}


Measured memory_bytes: 5200
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower, islower
#include <math.h> //pow

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
//using ll = long long; using ld = long double;
//using P = pair<int, int>;

int N = 55555;

void Eratosthenes2(int* arr) {
    for (int i = 0; i < N; i++) {
        arr[i] = 1;
    }
    arr[0] = 0; arr[1] = 0;
    for (int i = 2; i * i <= N; i++) {
        if (!arr[i]) continue; 
        for (int j = i * i; j <= N; j += i) {
            arr[j] = 0;
        }
    }
    for (int i = 2; i < N; i++) {
        if (arr[i]) {
            //std::cout << i << std::endl;
        }
    }
}

int main() {
  int arr[N];
  Eratosthenes2(arr);
  int n;
  cin >> n;
  int ans[n];
  int j = 0;
  int sum = 0;
  rep(i,N) {
    if (arr[i] && i % 5 == 1) {
        ans[j] = i;
        j++;
        if (j > n-1) break;
    }
  }


  rep(i,n) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin >> n;
    
    cout << 111+999 - n << endl;
    
    return 0;
}



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

#define i64 long long int
#define ran 202202

int n, k;
int a[ran];

int main() {
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	sort(a, a+n);
	
	i64 ans = 0;
	for(int i=0;i<n-k;i++)
		ans += a[i];
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	int a[3] ,i,j,tmp;
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	for (i = 0;i < 3;i++) {
		for (j = i + 1;j < 3;j++) {
			if (a[j] < a[i]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);
}


Measured memory_bytes: 2140
import java.util.Scanner;

//how many islands
public class Main {
	
//	public static int[][] land;
	public static boolean[][] land;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w,h,count;
//		int[][] land;
		while(true) {
			w = sc.nextInt();
			if(w == 0) {break;}
			h = sc.nextInt();
			count =0;
			
			land = new boolean[h+2][w+2];
			
			for(int i=0;i<h+2;i++) {
				for(int j=0;j<w+2;j++) {
					if(i == 0 || j == 0 || i==h+1 || j==w+1) {				//端っこを0埋め
						land[i][j] = false;
						continue;
					}									//端っこを0埋め
					land[i][j] = (sc.nextInt()==1);
				}
			}
			//end of input data
			
			for(int i=1;i<h+1;i++) {
				for(int j=1;j<w+1;j++) {
					if(land[i][j]) {
						count++;
						sink(i,j);
					}
				}
			}
			
			
			System.out.println(count);
		}
		sc.close();
	}
	
	public static void sink(int i,int j) {
		if(land[i][j]) {
			land[i][j] = false;
			sink(i-1,j-1);
			sink(i-1,j);
			sink(i-1,j+1);
			sink(i,j-1);
			sink(i,j+1);
			sink(i+1,j-1);
			sink(i+1,j);
			sink(i+1,j+1);
		}
	}

}


Measured memory_bytes: 45420
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String taro;
		String hanako;
		int point_taro = 0;
		int point_hanako = 0;
		for (int i = 0; i < n; i++) {
			taro = scan.next();
			hanako = scan.next();
			if (taro.compareTo(hanako) < 0) {
				point_hanako += 3;
			} else if (taro.compareTo(hanako) > 0) {
				point_taro += 3;
			} else {
				point_taro += 1;
				point_hanako += 1;
			}
		}
		System.out.println(point_taro + " " + point_hanako);
	}
}

Measured memory_bytes: 29784
n, m, x, y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

for i in range(x+1, y+1):
    if all([j < i for j in xlist]) and all([k >= i for k in ylist]):
        print("No War")
        break
else:
    print("War")

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll y[101010];
ll a[101010];
ll b[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
string s[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

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

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

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
ll sr,sc;
int main() {
    cin>>N>>P;
    P+=N*3;
    cout<<P/2<<endl;
	return 0;
}


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

int main(){
  while (true){
    int x, y;
    cin >> x >> y;
    if (x==0 && y==0){
      break;
    }
    else if (x>y){
      cout << y << " " << x << endl;
    }
    else {
      cout << x << " " << y << endl;
    }
  }
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MAX = 200005;
vector<int> to[MAX];
bool ok = false;
int n;
void rec(int num, int cur) {
    if(num==0) {
        for(int v : to[cur]) {
            rec(num+1, v);
        }
    } else {
        for(int v : to[cur]) {
            if(v == n) ok = true;
        }
    }
}
int main() {
    int m; cin >> n >> m;
    rep(i, m) {
        int a, b; cin >> a >> b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rec(0,1);
    if(ok) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 12016
#include<stdio.h>
#include<string.h>
#define ll long long
#define MOD 1000000007

//next_permutation
void nexp(ll*a,int cnt){
	int l=cnt-1,r=cnt-1;
	ll t;
	while(--l>=0&&a[l]>a[l+1]);
	if(l>=0){
		while(a[l]>a[r])r--;
		t=a[l];a[l]=a[r];a[r]=t;
	}
	for(l++,r=cnt-1;l<r;l++,r--)t=a[l],a[l]=a[r],a[r]=t;
}

ll a[10]={0,1,2,3,4,5,6,7,8,9};
char s[100010];
ll sum[10];
int main(){
	int r;
	scanf("%d%s",&r,s);
	int n=strlen(s);
	if(n==1&&r==0){
		puts("0");
		return 0;
	}

	ll p10=1;
	for(int i=n-1;i>=0;i--){
		int c=s[i]-'0';
		sum[c]=(sum[c]+p10)%MOD;
		p10=p10*10%MOD;
	}
	
	for(int i=0;i<3628800;nexp(a,10),i++)if(a[s[0]-'0']){
		ll ans=0;
		for(int k=0;k<10;k++)ans=(ans+sum[k]*a[k])%MOD;
		if(ans==r){
			for(int i=0;i<n;i++)printf("%d",a[s[i]-'0']);
			puts("");
			return 0;
		}
	}
	puts("-1");
}


Measured memory_bytes: 2092
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 100000001;

//int d[202][8];
int n, k;
int x[51], y[51];
const ll ma = 1000000000;
ll xcheck(ll x1, ll x2,int i,int j) {
	int count = 0;
	vector<int> pv;
	for (size_t k = 0; k < n; k++)
	{
		if (x1 <= x[k] && x[k] <= x2) {
			pv.push_back(y[k]);
			count++;
		}
	}

	if (count < k) return (ma * 2)  * (ll)(ma * 2);

	sort(pv.begin(), pv.end());
	ll yr = ma * 2;
	for (size_t i = 0; i < pv.size() - k + 1; i++)
	{
		ll mi = pv[i];
		ll hi = pv[i + k - 1];
		yr = min(hi - mi,yr);
	}
	return (x2 - x1) * (ll)(yr);
}
bool ycheck(ll y1, ll y2) {
	int count = 0;
	for (size_t k = 0; k < n; k++)
	{
		if (y1 <= y[k] && y[k] <= y2) count++;
	}
	return count >= k;
}
void AxisParallelRectangle() {
	cin >> n >> k;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
	}
	
	ll res = ma * 2;
	res *= res;
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = i + 1; j < n; j++)
		{
			for (size_t b1 = 0; b1 < 2; b1++)
			{
				for (size_t b2 = 0; b2 < 2; b2++)
				{
					ll x1 = x[i] * pow(-1, b1);
					ll x2 = x[j] * pow(-1, b2);
					ll mi = min(x1, x2);
					ll hi = max(x1, x2);
					res = min(res, xcheck(mi, hi, i, j));
				}
			}
		}
	}

	cout << res  << endl;
}

int main() {
	AxisParallelRectangle();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 2005;

int main() {
  int L,n;
  scanf("%d%d",&L,&n);
  vl a(n), b;
  cin>>a;
  a.pb(0);
  a.pb(L);
  sort(rng(a));
  b = a;
  rep(i,n+1) a[i+1] += a[i];
  reverse(rng(b));
  rep(i,n) b[i] = L-b[i];
  rep(i,n+1) b[i+1] += b[i];
  ll ans = 0;
  rep(ti,2) {
    rep(i,n) {
      int j = n-i;
      int s = min(i,j-1);
      ll now = (a[i]-a[i-s])*2;
      now += (b[j]-b[j-1-s])*2;
      now -= b[j]-b[j-1];
      maxs(ans,now);
    }
    rep(i,n) {
      int j = n-i;
      int s = min(i,j);
      ll now = (a[i]-a[i-s])*2;
      now += (b[j]-b[j-s])*2;
      now -= b[j]-b[j-1];
      maxs(ans,now);
    }
    swap(a,b);
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 4736
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from math import sqrt, ceil

s = ni()

m = ceil(sqrt(s))
if m * m < s:
    m = m+1

if m*(m-1) >= s:
    x1, y1 = 0, 0
    x2, y2 = m, 1
    x3, y3 = m*(m-1) - s, m-1

else:
    x1, y1 = 0, 0
    x2, y2 = m, 1
    x3, y3 = m*m - s , m

print(x1, y1, x2, y2, x3, y3)

Measured memory_bytes: 3064
n, m = map(int, input().split())
to_c = []
fm_c = []

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        to_c.append(b)
    if b == n:
        fm_c.append(a)

if len(set(to_c) & set(fm_c)) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

int main(){
    int m,f,r,sum;


    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1){
            break;
        }

        sum = m+f;
        if(m==-1 || f==-1){
            cout << "F" << endl;
        } else if(sum>=80){
            cout << "A" << endl;
        } else if(sum>=65){
            cout << "B" << endl;
        } else if(sum>=50){
            cout << "C" << endl;
        } else if(sum>=30){
            if(r>=50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            }
        } else if(sum<30){
            cout << "F" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  
  int maxl=0;
  int minr=10e5;
  for(int i=0; i<m; i++){
    int l,r;
    cin >> l >> r;
    maxl=max(maxl,l);
    minr=min(minr,r);
  }
  
  int ans = minr-maxl+1;
  if(ans<0) cout << 0 << endl;
  else cout << ans << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B;
  cin >> A >> B;
  if(A==B)
  {
    cout << "Draw" << endl;
    return 0;
  }
  else if(A==1)
  {
    cout << "Alice" << endl;
    return 0;
  }
  else if(A>B&&B!=1)
  {
    cout << "Alice" << endl;
    return 0;
  }
  else
  {
    cout << "Bob" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
dls = list(map(int,input().split()))
while 1:
    s = list(map(int,list(str(n))))
    # print(s)
    for i in dls:
        # print(i)
        if i in s:
            # print(n)
            break
    else:
        print(n)
        exit()
    n += 1

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

int main(){
    int N,X,m[110];
    cin >>N>>X;
    for(int i=0;i<N;i++){
        cin >>m[i];
    }

    int sum=0,min=1001;
    for(int i=0;i<N;i++){
        sum +=m[i];
        if(min>m[i]){
            min=m[i];
        }
    }

    int k=0,nokori;
    nokori=X-sum;
    while(true){
        if(nokori-min>=0){
            nokori -=min;
            k++;
        }else{
            break;
        }
    }
    
    cout <<N+k<<endl;
}

Measured memory_bytes: 256
#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;
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;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll k,q;cin>>k>>q;
    ll d[k];rep(i,0,k-1)cin>>d[i];
    ll n[q],x[q],m[q];rep(i,0,q-1)cin>>n[i]>>x[i]>>m[i];
    ll amari[k];
    ll sum[5010];
    ll c[5010];
    ll l,r;
    rep(i,0,q-1){
        sum[0]=x[i];
        l=x[i];
        c[0]=0;
        rep(j,0,k-1){
            amari[j]=d[j]%m[i];
            sum[j+1]=sum[j]+amari[j];
            if(amari[j]==0){
                c[j+1]=c[j]+1;
            }else{
                c[j+1]=c[j];
            }
        }
        r=x[i]+(sum[k]-sum[0])*((n[i]-1)/k)+(sum[(n[i]-1)%k]-sum[0]);
        cout<<(n[i]-1)-((r/m[i])-(l/m[i]))-(c[k]*((n[i]-1)/k)+c[(n[i]-1)%k])<<endl;
        
        
    }
    
    
    return 0;
}



Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var ab = Input.ar;
        var gred = Enumerable.Repeat(0, 100).Select(_ => new char[100]).ToArray();
        for (var i = 0; i < 100; i++)
            for (var j = 0; j < 100; j++)
                gred[i][j] = i < 50 ? '#' : '.';
        for(var i=0;i<50;i+=2)
            for(var j = 0; j < 100; j += 2)
            {
                if (ab[0] == 1) goto THERE;
                gred[i][j] = '.';
                ab[0]--;
            }
        THERE:;
        for(var i=51;i<100;i+=2)
            for(var j = 0; j < 100; j += 2)
            {
                if (ab[1] == 1) goto FIN;
                gred[i][j] = '#';
                ab[1]--;
            }
        FIN:;
        WriteLine("100 100\n"+string.Join("\n", gred.Select(v=>new string(v))));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13440
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n;
int a[100005];

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a+n);
	
	if(n % 3){
		if(a[0] == a[n-1] && a[0] == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}
	
	
	if(a[0] == a[n/3-1] && a[n/3] == a[n/3*2-1] && a[n/3*2] == a[n-1] && (a[0] ^ a[n/3] ^ a[n/3*2]) == 0){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	
	return 0;
}

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

using ll = long long;
const int maxn = 2e6 + 3;
const int dr[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int h, w, k, xt, yt, x2, y2;
std::vector<std::vector<char>> mp;
std::vector<std::vector<bool>> vis;
std::vector<std::vector<int>> d;
static char buf[maxn];
std::queue<std::pair<int, int>> q;

struct node {
    int f, l, r;
};
std::vector<std::vector<node>> rf, cf;

int getF(auto &f, int u) {
    if(f[f[u].f].f == f[u].f)
        return f[u].f;
    return f[u].f = getF(f, f[u].f);
}

void uniF(auto &f, int u, int v) {
    u = getF(f, u);
    v = getF(f, v);
    if(u == v)
        return;
    f[u].f = f[v].f;
    f[v].l = std::min(f[u].l, f[v].l);
    f[v].r = std::max(f[u].r, f[v].r);
}

void update(int x, int y) {
    for(int i = 0; i < 4; ++i) {
        int nx = x + dr[i][0];
        int ny = y + dr[i][1];
        if(nx < 0 || nx >= h || ny < 0 || ny >= w || mp[nx][ny] != '.' || !vis[nx][ny])
            continue;
        if(dr[i][0] == 0)
            uniF(rf[x], y, ny);
        if(dr[i][1] == 0)
            uniF(cf[y], x, nx);
    }
}

void nxtTo(int i, int &x, int &y) {
    if(i == 0) {
        y = rf[x][getF(rf[x], y)].r + 1;
    } else if(i == 1) {
        y = rf[x][getF(rf[x], y)].l - 1;
    } else if(i == 2) {
        x = cf[y][getF(cf[y], x)].r + 1;
    } else if(i == 3) {
        x = cf[y][getF(cf[y], x)].l - 1;
    }
}

int main() {
    scanf("%d%d%d", &h, &w, &k);
    scanf("%d%d%d%d", &xt, &yt, &x2, &y2);
    xt -= 1; yt -= 1;
    x2 -= 1; y2 -= 1;
    for(int i = 0; i < h; ++i) {
        scanf("%s", buf);
        mp.emplace_back(buf, buf + w);
        vis.emplace_back(w, false);
        d.emplace_back(w, 0xf7f7f7f);
    }
    for(int i = 0; i < h; ++i) {
        rf.emplace_back(w);
        for(int j = 0; j < w; ++j)
            rf[i][j] = {j, j, j};
    }
    for(int i = 0; i < w; ++i) {
        cf.emplace_back(h);
        for(int j = 0; j < h; ++j)
            cf[i][j] = {j, j, j};
    }
    q.emplace(xt, yt);
    d[xt][yt] = 0;
    vis[xt][yt] = true;
    update(xt, yt);
    while(!q.empty()) {
        int x, y;
        std::tie(x, y) = q.front();
        // fprintf(stderr, "%d %d\n", x, y);
        q.pop();
        for(int i = 0; i < 4; ++i) {
            int nx = x, ny = y;
            nxtTo(i, nx, ny);
            while(std::abs(nx - x) + std::abs(ny - y) <= k) {
                if(nx < 0 || nx >= h || ny < 0 || ny >= w || mp[nx][ny] != '.')
                    break;
                if(!vis[nx][ny]) {
                    q.emplace(nx, ny);
                    d[nx][ny] = d[x][y] + 1;
                }
                vis[nx][ny] = true;
                update(nx, ny);
                nxtTo(i, nx, ny);
            }
        }
    }
    printf("%d\n", vis[x2][y2] ? d[x2][y2] : -1);
    return 0;
}

Measured memory_bytes: 75604
s0=input()
s1="maerd"
s2="remaerd"
s3="esare"
s4="resare"
s=""
for i in range(len(s0)):
    s+=s0[-1-i]
num=0
num2=len(s)
ans=0
for i in range(num2):
    if num==num2:
        ans=1
        break
    if num2-num<=4:
        break
    if num2-num<=7:
        s13=s[num:]
        if s13==s1 or s13==s2 or s13==s3 or s13==s4:
            ans=1
        break
    if s[num:num+5]==s1 or s[num:num+5]==s3:
        num+=5
    elif s[num:num+6]==s4:
        num+=6
    elif s[num:num+7]==s2:
        num+=7
    else:
        break
if ans==0:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 9268
#include<stdio.h>

int main(){
  int i,sx,sy,tx,ty;
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
  for(i=sy;i<ty;i++){
    printf("U");
  }
  for(i=sx;i<tx;i++){
    printf("R");
  }
  for(i=ty;i>sy;i--){
    printf("D");
  }
  for(i=tx;i>=sx;i--){
    printf("L");
  }
  for(i=sy;i<=ty;i++){
    printf("U");
  }
  for(i=sx;i<=tx;i++){
    printf("R");
  }
  printf("DR");
  for(i=ty;i>=sy;i--){
    printf("D");
  }
  for(i=tx;i>=sx;i--){
    printf("L");
  }
  printf("U");
  return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n = int(input())
s = [int(i) for i in readline().split()]

n -= 1
ans = 0

for d in range(1,n+1):
    a = n-d
    res = 0
    p,q = n,0
    while a >= d:
        if a <= n-a and n%d == 0: break
        p -= d
        q += d
        res += s[p] + s[q]
#        print(d,a,res)
        if res > ans: ans = res
        a -= d
    
print(ans)    
    
    
    
    
    
    
    
    
    
    

Measured memory_bytes: 14860
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll a,b;
    cin>>a>>b;
    ll ans=(a+b)*(a+b-1);
    ans/=2;
    ans-=(a*b);
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
	ll n;
	cin >> n;
	ll length = 0;
	ll bits = 1;
	ll start = 0;
	ll buf = n;
	while (buf > 0) {
		start += bits;
		bits *= 26;
		buf -= bits;
		length++;
	}
	ll a = n - start;
	vector<char> cs;
	rep(i, length) {
		cs.push_back('a' + (a % 26));
		a /= 26;
	}
	reverse(cs.begin(), cs.end());
	for (auto c : cs) {
		cout << c;
	}
	cout << endl;
	return 0;
}
	

Measured memory_bytes: 3632
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		long k = sc.nextLong();
		long cur = 7 % k;
		for(int i = 1; i < 1e7; i++) {
			if(cur == 0) {
				System.out.println(i);
				return;
			}
			cur = (cur*10+7)%k;
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 35764
S = input()

bucket = [0] * 26


def c_to_num(c):
    return ord(c) - 97


def num_to_c(num):
    return chr(num+97)


for c in S:
    bucket[c_to_num(c)] += 1

ret = 'None'
for i, n in enumerate(bucket):
    if not n:
        ret = num_to_c(i)
        break

print(ret)


Measured memory_bytes: 3188
#include<iostream>
//#include<algorithm>
using namespace std;
#define max 100010
#define INT32_MAX 2147483647
int n, k;
int mark[max];
int mid;

bool find()
{
	int i;
	int f = 0;
	int tmp;
	for (i = 0; i < k; ++i)
	{
		tmp = 0;
		while (tmp + mark[f] <= mid)
		{
			tmp += mark[f];
			++f;
			if (f == n)return true;
		}

	}
	return false;
}
int main()
{
	//cout << INT32_MAX;
	cin >> n >> k;
	int right = INT32_MAX;
	int left = 0;
	//int mid;
	for (int i = 0; i < n; ++i)
	{
		cin >> mark[i];
	}
	//sort(mark, mark + k);
	while (right != left+1 )
	{
		mid = (right + left) / 2;
		if (find())
		{
			right = mid;
		}
		else
		{
			left = mid;
		}
	}
	cout << right << endl;
	return 0;
}




Measured memory_bytes: 3488
#include <iostream>
#include <algorithm>
#include <cstdio>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
using namespace std;
typedef long long ll;
const int N=1e5+5;

    int n,m,t;
    int fa[N];
    int i,j,k;
struct point
{
    int x,y,id;
}p[N];
struct Edge
{
    int u,v,valu;
    bool const operator<(const Edge &b)
    const{
        return valu<b.valu;
    }
}edge[N];
int Find(int son)
{
    return son==fa[son] ? son : fa[son]=Find(fa[son]);
}
bool Union(int x,int y)
{
    x=Find(x),y=Find(y);
    if(x==y) return 1;
    else{
        fa[y]=x;
        return 0;
    }
}
bool cmpx(point &a,point &b){
    return a.x<b.x;
}
bool cmpy(point &a,point &b){
    return a.y<b.y;
}
int main()
{
    cin.tie(0);istream::sync_with_stdio(false);
    while(cin>>n){
        for(i=1;i<=n;i++) fa[i]=i;

        for(i=1;i<=n;i++){
            cin>>p[i].x>>p[i].y;
            p[i].id=i;
        }

        int num=0;
        sort(p+1,p+1+n,cmpx);//尽量以x之间的距离为经费建路
        for(i=1;i<n;i++){
            edge[++num].u=p[i].id;
            edge[num].v=p[i+1].id;
            edge[num].valu=min(abs(p[i].x-p[i+1].x),abs(p[i].y-p[i+1].y));
        }
        sort(p+1,p+1+n,cmpy);//尽量以y之间的距离为经费建路
        for(i=1;i<n;i++){
            edge[++num].u=p[i].id;
            edge[num].v=p[i+1].id;
            edge[num].valu=min(abs(p[i].x-p[i+1].x),abs(p[i].y-p[i+1].y));
        }

        stable_sort(edge+1,edge+1+num);
        int ans=0,cnt=0;
        for(i=1;i<=num;i++){
            if(0==Union(edge[i].u,edge[i].v)){//若u，v两点还未连接
                ans+=edge[i].valu;
                cnt++;
            }
            if(cnt==n-1) break;//建路数达到联通所有城市
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5248
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod        1000000007 
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod;}
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2);}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
map<ll,vector<ll> >m1;
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    if(a.first==b.first)
    return (a.second < b.second);
    return (a.first < b.first); 
} 
ll ans=0;
vector<ll>root;
void calldfs(ll v,int visit[])
{
 visit[v]=1;
 for(int i=0;i<m1[v].size();i++)
 {
  if(visit[m1[v][i]]==0)
  {
   calldfs(m1[v][i],visit);
  }
 }
}
void dfs(ll n)
{
 ll i;
 int visit[1000000]={0};
 fli(i,1,n+1)
 {
  visit[i]=0;
 }
 fli(i,1,n+1)
 {
  if(visit[i]==0)
  {
   calldfs(i,visit);
   ans++;
  } 
 }
}
void comp()
{
 ll n,i,k,temp;
 string s;
 cin>>s;
 string p="",q="";
 n=10*(s[0]-'0')+s[1]-'0';
 k=10*(s[2]-'0')+s[3]-'0';
 if(n>=1 && n<=12)
 {
  if(k>=1 && k<=12)
  {
   cout<<"AMBIGUOUS\n";
  }
  else
  {
   cout<<"MMYY\n";
  }
 }
 else
 {
  if(k>=1 && k<=12)
  {
   cout<<"YYMM\n";
  }
  else
  {
   cout<<"NA\n";
  }
 }
} 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!ulong;
	auto K = RD!ulong;
	auto A = RDR.split.to!(ulong[]);

	ulong[64] bitCnt;
	foreach (e; A)
	{
		foreach (i; 0..64)
		{
			if (e & (cast(ulong)1 << i)) ++bitCnt[i];
		}
	}
	auto bitQ = new ulong[](64);
	fill(bitQ, ulong.max);
	foreach (ulong i; 0..64)
	{
		if (bitCnt[i] > N / 2) continue;
		bitQ[i] = ((N - bitCnt[i]) - bitCnt[i]) * (cast(ulong)1 << i);
	}

	//stderr.writeln(bitQ);
	ulong x;
	ulong ans;
	foreach_reverse (ulong i, e; bitQ)
	{
		if (bitCnt[i] > N / 2) continue;

		
		ulong bit = cast(ulong)1 << i;
		//stderr.writeln(x, " a ", i , " ", bit);
		x += bit;
		if (x > K)
		{
			ulong best = ulong.max, bestPos;
			/*foreach (j, ee; bitQ[i..$])
			{
				if (ee < best)
				{
					best = ee;
					bestPos = i + j;
				}
			}*/
			foreach_reverse (ulong j; i..64)
			{
				if (x & (cast(ulong)1 << j))
				{
					if (bitQ[j] < best)
					{
						best = bitQ[j];
						bestPos = j;
					}
				}
			}
			x -= cast(ulong)1 << bestPos;
			//stderr.writeln(x, " ", i, " ", bestPos);
		}
		else
		{
			//stderr.writeln("else");
		}
	}

	foreach (e; A)
	{
		ans += e ^ x;
	}

	writeln(ans);
	stdout.flush();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    ll M = 1;
    ll ans = 0;
    REP(i,N){
        ll a = A[i];
        if(i == 0){
            ans += a - 1;
            a = 1;
            M = 2;
        }
        else{
            if(a <= M) {
                chmax(M, a+1);
                continue;
            }

            ll k = 0;
            if(a % M != 0){
                k = a/M;
                a -= M*k;
            }
            else{
                while(a % M == 0){
                    k++;
                    a -= (M+1);
                }
                k += a/M;
                a -= M*a/M;
            }
            chmax(M, a+1);
            ans += k;
        }
    }

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


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
// numeric_limits<int>::max()
// cout << setprecision(20) << double << endl;

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    int maxN = 0, minN = numeric_limits<int>::max();
    for (int i = 0; (i < M); ++i) {
        cin >> L[i] >> R[i];
        minN = min(minN, R[i]);
        maxN = max(maxN, L[i]);
    }
    int res = (minN+1-maxN);
    res = max(0, res);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_6_A
    {
        static void Main(string[] args)
        {
            int n;
            List<int> dataSet;

            n = int.Parse(Console.ReadLine());
            dataSet = Console.ReadLine().Split().Select(int.Parse).ToList();

            dataSet.Reverse();

            StringBuilder outputLine = new StringBuilder();
            foreach (int number in dataSet)
            {
                outputLine.Append(number + " ");
            }
            Console.WriteLine(outputLine.ToString().Trim());
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 18352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
#ifndef ONLINE_JUDGE
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n;
    	cin>>n;
    	ll arr[n+1];
    	ll ans=0;

    	for(ll i=1;i<=n;i++)
    	{
    		cin>>arr[i];
    	}
    	ll mx=arr[1];
    	for(ll i=2;i<=n;i++)
    	{
    		mx=max(mx,arr[i]);
    		ans+=mx-arr[i];
    	}
    	cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 5212
main(){
    int w,h,n,i;
    scanf("%d %d %d",&w,&h,&n);
    int x,y;
    scanf("%d %d",&x,&y);
    int tempx,tempy,xx,yy,cnt=0;
    for(i=1;i<n;i++){
        scanf("%d %d",&tempx,&tempy);
        xx=tempx-x;
        yy=tempy-y;
        while(xx>0&&yy>0){
            xx--;
            yy--;
            cnt++;
        }
        while(xx<0&&yy<0){
            xx++;
            yy++;
            cnt++;
        }
        while(xx>0){
            xx--;
            cnt++;
        }
        while(xx<0){
            xx++;
            cnt++;
        }
        while(yy>0){
            yy--;
            cnt++;
        }
        while(yy<0){
            yy++;
            cnt++;
        }
        x=tempx;
        y=tempy;
       
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int N;
int Q;
int K;
ll d[112345];
cp2 P[112345];
int a, b, c;
vector< cp2 >G[112345];

void mkd( ll root, ll v ){
	
	REP( i, G[v].size() ){
		if( G[v][i].fi == root )continue;
		d[G[v][i].fi] = d[v] + G[v][i].se;
		mkd( v, G[v][i].fi );
	}
}

int main(){
	
	cin>>N;
	
	fill( d, d+N+1, 0 );
	
	REP( i, N-1 ){
		scanf("%d %d %d", &a, &b, &c );
		G[a].push_back( cp2( b, c ) );
		G[b].push_back( cp2( a, c ) );
	}
	
	cin>>Q>>K;
	
	d[0] = 0;
	d[K] = 0;
	
	mkd( 0, K );
	
	REP( i, Q ){
		scanf("%d %d", &a, &b );
		P[i].fi = a;
		P[i].se = b;
	}
	
	REP( i, Q ){
		printf("%lld\n", d[P[i].fi]+d[P[i].se]);
	}
	
	return 0;
	
}

Measured memory_bytes: 16128
#include <stdio.h>

int
main(int argc, char *argv[])
{
        int a, b;
        char op;
        int ans;

        while(scanf("%d %c %d", &a, &op, &b), op != '?') {
                switch(op) {
                case '+':
                        ans = a + b;
                        break;
                case '-':
                        ans = a - b;
                        break;
                case '*':
                        ans = a * b;
                        break;
                case '/':
                        ans = a / b;
                        break;
                } 
                printf("%d\n", ans);
        }


        return 0;
}

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int X, Y;
  cin >> X >> Y;
  cout << X + Y / 2 << endl;
}


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

int main(void){
    ll x;
    cin >> x;

    ll sum = 0, count = 0;
    while(sum < x){
        count++;
        sum += count;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


A,B = map(int, input().split())

da = defaultdict(int)
db = defaultdict(int)



p = 2
while p * p <= A:
    while A % p == 0:
        da[p] += 1
        A //= p
    p += 1

if A != 1:
    da[A] += 1

p = 2
while p * p <= B:
    while B % p == 0:
        db[p] += 1
        B //= p
    p += 1

if B != 1:
    db[B] += 1



ans = len(set(da.keys()) & set(db.keys())) + 1
print(ans)



Measured memory_bytes: 3316
# include <cstdio>
# include <iostream>
# include <vector>
# include <map>
# include <set> 
# include <algorithm> 
# include <string>
# include <cstring>
# include <queue> 
# include <stack> 
# include <cstdlib> 
# include <cassert> 

using namespace std ;

int N ; 
//int K ; 
long long int INF = 1000000000LL + 10LL ; 
long long int dp[100009][4] ; 
long long int a[100009]  ; 
long long int b[100009]  ; 
long long int c[100009]  ; 

long long int iabs(long long int a){
	if(a<0LL)return (a*-1LL) ; 
	return a ;  
}
long long maxVal(long long a, long long b){
	if(a>b) return a ; 
	return b ; 
}

long long go(int cur, int lastActivity)
{
	//if(cur < 0 ) return INF ; 
	long long int& ret = dp[cur][lastActivity]; 
	if(ret != -1LL) return ret ;
	 
	ret = -INF ; 
	
	//task 1 
	if(lastActivity != 1)
		ret = maxVal(ret , go(cur-1, 1) + a[cur ] );

	//task 2 
	if(lastActivity != 2)
		ret = maxVal(ret, go(cur-1, 2) + b[cur]);

	//task 3 
	if(lastActivity != 3)
		ret = maxVal(ret, go(cur-1, 3)+c[cur]);


	return ret ;
}

int main()
{
	scanf("%d",&N);
	//vector< int > H(N) ; 
	for(int i = 1 ; i <= N ; ++i){
		scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
		dp[i][3]=dp[i][2]=dp[i][1]=dp[i][0]=-1LL; 
	}
	dp[0][3]=dp[0][2]=dp[0][1]=dp[0][0]=0LL;
	
	
	//vector< int > dp(N+3, -1); 

	long long tmp = go(N, 0) ; 

	assert(tmp != -INF) ; 

	cout << tmp << "\n" ; 
	

	//cout << "Hello World\n" ; 
	return 0 ; 
}

Measured memory_bytes: 12032
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
//　90min
int main(void)
{
    int n;
    int h[101] = {0};
    int ans = 0;

    scanf("%d", &n);

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

    ans = h[0];
    for (int i = 1; i < n; i++) {
        if (h[i-1] < h[i]) {
            ans += h[i] - h[i-1];
        }
    }
  
    printf("%d\n", ans);
    return 0;
}


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

namespace ConsoleApplication1
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var s = Console.ReadLine().Split('/').Select(int.Parse).ToArray();
			Console.WriteLine(s[1] <= 4 ? "Heisei" : "TBD");
		}
	}
}

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

class DisjoinSet{
	public:
		vector<int> rank,p;
		
		DisjoinSet(){ }
		DisjoinSet(int size){
			rank.resize(size,0);
			p.resize(size,0);
			for(int i=0;i<size;i++) makeSet(i);
		}
		
		void makeSet(int x){
			p[x]=x;
			rank[x]=0;
		}
		
		bool same(int x,int y){
			return findSet(x)==findSet(y);
		}
		
		void unite(int x,int y){
			link(findSet(x),findSet(y));
		}
		
		void link(int x,int y){
			if(rank[x]>rank[y]){
				p[y]=x;
			}else{
				p[x]=y;
				if(rank[x]==rank[y]){
					rank[y]++;
				}
			}
		}
		
		int findSet(int x){
			if(x!=p[x]){
				p[x]=findSet(p[x]);
			}
			return p[x];
		}
};

int main() {

	int n,a,b,q;
	int t;
	
	cin>>n>>q;
	
	DisjoinSet ds = DisjoinSet(n);
	
	for(int i=0;i<q;i++){
		cin>>t>>a>>b;
		if(t==0) ds.unite(a,b);
		else if(t==1){
			if(ds.same(a,b)) cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	
	return 0;
}

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

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}


int main()
{
  ll n,a,b;
  ll ans=0;
  cin>>n>>a>>b;
  reps(i,n+1){
    if(digit_sum(i)>=a&&digit_sum(i)<=b)ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>
int main(){
    int L, R, d;
    scanf("%d %d %d", &L, &R, &d);
    int cnt, i;
    cnt=0;
    for(i=L; i<=R;i++){
        if(i%d==0){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 1728