akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 10;
ll ans;
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		ll N = n / i;
		ans += i * N * (N + 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3756
#include <cstdio>

int main(){
    int n, x, t, ans = 0;
    while(true){
        ans = 0;
        scanf("%d %d", &n, &x);
        if(n == 0 && x == 0){
            break;
        }
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j<=n; j++){
                t = x - i - j;
                if (j < t && t <= n){
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2692
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print $ succ n `div` 2

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include<iostream>//97 122
#include<algorithm>
using namespace std;
int a[1005];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++)
        ans+=a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3552
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var s = input[0].replace(/^2017/g, '2018');
    console.log(s);

    return 0;
}


Measured memory_bytes: 9804
n=int(input())
h=[int(i) for i in input().split()]
pre=[0]
for i in range(len(h)):
    pre.append(max(pre[-1],h[i]))
ans=0
for i in range(1,n+1):
    if(h[i-1]>=pre[i]):
        ans+=1
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int n, i, k2, k4;

	scanf("%d", &n);
	k2 = k4 = 0;
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d", &a);
		if (a % 4 == 0)
			k4++;
		else if (a % 2 == 0)
			k2++;
	}
	printf(k4 + k2 / 2 >= n / 2 ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	set<int>s;
	int a,b,c;
	cin>>a>>b>>c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define REP(i,a,e) for(int i=(a);i<(e);++i)
using namespace std;
int main(){
	while(true){
		int n;
		int r;
		vector<int> v1,v2;
		cin>>n>>r;
		if(n==0&&r==0)break;
		v1.resize(n);
		REP(i,0,n){
			v1[n-1-i]=i+1;
		}
		REP(i,0,r){
			int p,c;
			cin>>p>>c;
			v2=v1;
			--p;
			v1.insert(v1.begin(),v2.begin()+p,v2.begin()+p+c);
			v1.erase(v1.begin()+c+p,v1.begin()+c+p+c);
		}
		cout << v1[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(long i=0;i<(long)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline long IN(void)
{
  long x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main()
{
  long N=IN(),calc=0;int X=IN(),MOD=IN(),vis[100001],val[100001];
  if(N<=MOD){rep(i,N){calc+=X;X=1l*X*X%MOD;}return OUT(calc),0;}
  else
  {
    rep(i,MOD+1)
    {
      val[i+1]=X;
      if(vis[X])
      {
        rep(j,vis[X]){calc+=val[j+1];}
        int k=vis[X]+1;while(k<=i+1){calc+=1l*(N-vis[X]+i+1-k)/(i+1-vis[X])*val[k];k++;}
        return OUT(calc),0;
      }
      vis[X]=i+1;X=1l*X*X%MOD;
    }	
  }
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> ans(n);

  ll two = 1;
  ll t = 0;
  while(two < (ll)(1e9)){
    ll s = 0;
    rep(i,n){
      if(a[i]>>t&1){
        s++;
      }
    }
    if(s%2==0){
      rep(i,n){
        if(a[i]>>t&1){
          ans[i] += two;
        }
      }
    }else{
      rep(i,n){
        if(((
          a[i]>>t)&1)==0){
          ans[i] += two;
        }
      }
    }
    two *= 2;
    t++;
  }

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

  return 0;
} 



Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long X){
  int N = 100010;
  int limitN = floor(sqrt(N-1));
  vector<bool> isPrimes(N, true);
  isPrimes.at(0) = false; isPrimes.at(1) = false;
  for(int x = 2; x < limitN; ++x) {
    for(int y = x+x; y < N; y += x) {
      isPrimes.at(y) = false;
    }
  }

  int minPrime = 0;
  FOR(x, X, N-1) {
    if (isPrimes.at(x)) {
      minPrime = x;
      break;
    } 
  }

  cout << minPrime << endl;
}

signed main(){
  long long X;
  scanf("%lld",&X);
  solve(X);
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	res := 0
	for i := 1; i <= n; i++ {
		if len(strconv.Itoa(i))%2 == 1 {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9

using namespace std;
using P = pair<int, int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

vector<P> g[1100][1100];
int d[1100][1100];

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

  rep(i, N) {
    int px = 0;
    int py = 0;
    rep(j, N-1) {

      int x = i;
      int y; cin >> y;

      if (x > y) swap(x, y);
      if (j > 1) {
        g[px][py].emplace_back(x, y);
        // 終点になっている個数
        d[x][y]++;
      }

      px = x; py = y;
    }
  }

  vector<P> curr;

  rep(i, N) {
    for(int j=i+1;j<=N;++j) {
      if (d[i][j] == 0) curr.emplace_back(i, j);
    }
  }

  int ans = 0;
  int ct = 0;

  while (!curr.empty()) {
    ans++;
    vector<P> tmp;

    for (auto &p : curr) {
      ct++;

      int x = p.first;
      int y = p.second;

      // cout << x << y << "\n";

      for (auto &pp : g[x][y]) {
        int xx = pp.first;
        int yy = pp.second;

        if (d[xx][yy] == 1) tmp.emplace_back(xx, yy);
        d[xx][yy]--;
      }
    }

    curr = tmp;
  }

  if (ct != N * (N-1) / 2) {
    cout << "-1\n"; 
  } else {
    cout << ans << "\n";
  }

}

Measured memory_bytes: 48896
n = int(input())
a = list(map(int, input().split()))
for i in range(len(a) - 1, -1, -1):
    if a[i] == 1:
        cntnum = 2
        num = 1
        for j in range(i + 1, len(a)):
            if a[j] == cntnum:
                num += 1
                cntnum += 1
        print(n - num)
        exit()

print(-1)


Measured memory_bytes: 26012
/*
02:08 - 04:05
 */

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<queue>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 2000
#define pow2(a) ((a)*(a))
#define EPS 1e-7
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

struct Point{
  double x,y;
  Point(double x=IINF,double y=IINF):x(x),y(y){}
  Point operator - (const Point& a)const { return {x-a.x,y-a.y}; }
};

struct Edge{
  int from,to;
  double dist;
  Edge(int from=IINF,int to=IINF,double dist=IINF):from(from),to(to),dist(dist){}
};

struct Data{
  int pre,cur,cost;
  double dist;
  Data(int pre=IINF,int cur=IINF,int cost=IINF,double dist=IINF):pre(pre),cur(cur),cost(cost),dist(dist){}
  bool operator < (const Data& a) const {
    if(equals(dist,a.dist))return cost > a.cost;
    return dist > a.dist;
  }
};

inline double getDist(Point a,Point b){ return sqrt(pow2(a.x-b.x)+pow2(a.y-b.y)); }
inline double cross(Point a,Point b){ return a.x*b.y-a.y*b.x; }

vector<Edge> G[MAX];
vector<Point> ps;
double mindist[MAX][MAX];//mindist[pre_node][cur_node] 
int    mincost[MAX][MAX];
int E,V,sp,gp;

void compute(){

  rep(i,V)rep(j,V){
    mindist[i][j] = IINF;
    mincost[i][j] = IINF;
  }
  priority_queue<Data> Q;
  rep(i,G[sp].size()){
    mindist[sp][G[sp][i].to] = G[sp][i].dist;
    mincost[sp][G[sp][i].to] = 2;
    Q.push(Data(sp,G[sp][i].to,2,G[sp][i].dist));
  }

  while(!Q.empty()){
    Data data = Q.top(); Q.pop();
    Point cp = ps[data.cur];
    Point pp = ps[data.pre];

    if(data.cur == gp){ cout << data.cost << endl; return; }

    rep(i,G[data.cur].size()){
      Point np = ps[G[data.cur][i].to];
      if(G[data.cur][i].to == data.pre)continue;
      if(cross(cp-pp,np-pp) < -EPS)continue;
      double dist = G[data.cur][i].dist;
      if(equals(mindist[data.cur][i],data.dist+dist)){
	if(mincost[data.cur][G[data.cur][i].to] > data.cost+1){
	  mincost[data.cur][G[data.cur][i].to] = data.cost+1;
	  Q.push(Data(data.cur,G[data.cur][i].to,data.cost+1,data.dist+dist));
	}
      } else if(mindist[data.cur][G[data.cur][i].to] > data.dist+dist){
	mindist[data.cur][G[data.cur][i].to] = data.dist + dist;
	mincost[data.cur][G[data.cur][i].to] = data.cost + 1;
	Q.push(Data(data.cur,G[data.cur][i].to,data.cost+1,data.dist+dist));
      }
    }
  }
  cout << "impossible" << endl;
}

int main(){
  while(cin >> V >> E,V|E){
    unordered_map<string,int> getIndex;
    int x,y;
    string name,p,q;
    ps.clear();
    rep(i,V)G[i].clear();

    rep(i,V){
      cin >> name >> x >> y;
      getIndex[name] = (int)ps.size();
      ps.push_back(Point(x,y));
    }

    rep(i,E){
      cin >> p >> q;
      int node1 = getIndex[p], node2 = getIndex[q];
      G[node1].push_back(Edge(node1,node2,getDist(ps[node1],ps[node2])));
      G[node2].push_back(Edge(node2,node1,getDist(ps[node1],ps[node2])));
    }

    cin >> p >> q;
    sp = getIndex[p], gp = getIndex[q];
    compute();
  }
  return 0;
}

Measured memory_bytes: 28124
#include<iostream>
using namespace std;
int main(){
    cout <<"1x1=1" << endl;
    cout <<"1x2=2"<<endl;
    cout <<"1x3=3"<<endl;
    cout <<"1x4=4"<<endl;
    cout <<"1x5=5"<<endl;
    cout <<"1x6=6"<<endl;
    cout <<"1x7=7"<<endl;
    cout <<"1x8=8"<<endl;
    cout <<"1x9=9"<<endl;
    cout <<"2x1=2"<<endl;
    cout <<"2x2=4"<<endl;
    cout <<"2x3=6"<<endl;
    cout <<"2x4=8"<<endl;
    cout <<"2x5=10"<<endl;
    cout <<"2x6=12"<<endl;
    cout <<"2x7=14"<<endl;
    cout <<"2x8=16"<<endl;
    cout <<"2x9=18"<<endl;
    cout <<"3x1=3"<<endl;
    cout <<"3x2=6"<<endl;
    cout <<"3x3=9"<<endl;
    cout <<"3x4=12"<<endl;
    cout <<"3x5=15"<<endl;
    cout <<"3x6=18"<<endl;
    cout <<"3x7=21"<<endl;
    cout <<"3x8=24"<<endl;
    cout <<"3x9=27"<<endl;
    cout <<"4x1=4"<<endl;
    cout <<"4x2=8"<<endl;
    cout <<"4x3=12"<<endl;
    cout <<"4x4=16"<<endl;
    cout <<"4x5=20"<<endl;
    cout <<"4x6=24"<<endl;
    cout <<"4x7=28"<<endl;
    cout <<"4x8=32"<<endl;
    cout <<"4x9=36"<<endl;
    cout <<"5x1=5"<<endl;
    cout <<"5x2=10"<<endl;
    cout <<"5x3=15"<<endl;
    cout <<"5x4=20"<<endl;
    cout <<"5x5=25"<<endl;
    cout <<"5x6=30"<<endl;
    cout <<"5x7=35"<<endl;
    cout <<"5x8=40"<<endl;
    cout <<"5x9=45"<<endl;
    cout <<"6x1=6"<<endl;
    cout <<"6x2=12"<<endl;
    cout <<"6x3=18"<<endl;
    cout <<"6x4=24"<<endl;
    cout <<"6x5=30"<<endl;
    cout <<"6x6=36"<<endl;
    cout <<"6x7=42"<<endl;
    cout <<"6x8=48"<<endl;
    cout <<"6x9=54"<<endl;
    cout <<"7x1=7"<<endl;
    cout <<"7x2=14"<<endl;
    cout <<"7x3=21"<<endl;
    cout <<"7x4=28"<<endl;
    cout <<"7x5=35"<<endl;
    cout <<"7x6=42"<<endl;
    cout <<"7x7=49"<<endl;
    cout <<"7x8=56"<<endl;
    cout <<"7x9=63"<<endl;
    cout <<"8x1=8"<<endl;
    cout <<"8x2=16"<<endl;
    cout <<"8x3=24"<<endl;
    cout <<"8x4=32"<<endl;
    cout <<"8x5=40"<<endl;
    cout <<"8x6=48"<<endl;
    cout <<"8x7=56"<<endl;
    cout <<"8x8=64"<<endl;
    cout <<"8x9=72"<<endl;
    cout <<"9x1=9"<<endl;
    cout <<"9x2=18"<<endl;
    cout <<"9x3=27"<<endl;
    cout <<"9x4=36"<<endl;
    cout <<"9x5=45"<<endl;
    cout <<"9x6=54"<<endl;
    cout <<"9x7=63"<<endl;
    cout <<"9x8=72"<<endl;
    cout <<"9x9=81"<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<string.h>
#include<algorithm>
#define ll long long 
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define ret return 
#define elif else if
using namespace std;
int main(){
	while(1){
	ll n;cin>>n;
	ll a[n][3];
	memset(a,0,sizeof(a));
	rp(i,1,n){cin>>a[i][0]>>a[i][1]>>a[i][2];}
		ll time=0;
	rp(i,1,n){
		rp(j,i,n){
		if(time<a[j][1]){time=a[j][1];}
		elif(time%a[j][2]==0){}
		else{time+=a[j][2]-(time%a[j][2]);}
		time+=a[j][0];
		}cout<<time<<endl;time=0;
	}cout<<0<<endl;
	
		
		
		
		ret 0;
	}	
}

Measured memory_bytes: 256
S = gets
t = 0
renzoku = 0
renzokuMax = 0
for i in 0..S.size - 1
  if S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'
    renzoku += 1
  elsif S[i] != 'A' || S[i] != 'C' || S[i] != 'G' || S[i] != 'T'
    if renzokuMax < renzoku
      renzokuMax = renzoku
    end
    renzoku = 0
  end
end
puts renzokuMax


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    LL n, t;
    cin >> n >> t;
    vector<LL> T(n);
    rep(i, n) cin >> T[i];
    LL ans = 0;
    rep1(i, n) ans += min(t, T[i]-T[i-1]);
    ans += t;
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    bool flag=false;
    for(int i=1;i<=3;i++){
        if((a*b*i)%2!=0)flag=true;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

using i64 = int64_t;

int cumsum[502][502]={0};

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i=0;i<m;++i){
        int l, r;
        cin >> l >> r;
        cumsum[r][l]++;
    }

    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cumsum[i][j] += cumsum[i][j-1];
        }
    }

    for(int i=0;i<q;++i){
        int l, r;
        cin >> l >> r;
        int ans = 0;
        for(int j=l;j<=r;++j){
            ans += cumsum[j][j] - cumsum[j][l-1];
        }
        cout << ans << endl;
    }

    return 0;
}


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

#define MAXN 1000005


int spf[MAXN];

// Hash to store prime factors count
map<int,int> hash1;

// Function to calculate SPF (Smallest Prime Factor)
// for every number till MAXN
void sieve()
{
	spf[1] = 1;
	for (int i = 2; i < MAXN; i++)

		// Marking smallest prime factor for every
		// number to be itself
		spf[i] = i;

	// Separately marking spf for every even
	// number as 2
	for (int i = 4; i < MAXN; i += 2)
		spf[i] = 2;

	// Checking if i is prime
	for (int i = 3; i * i < MAXN; i++) {

		// Marking SPF for all numbers divisible by i
		if (spf[i] == i) {
			for (int j = i * i; j < MAXN; j += i)

				// Marking spf[j] if it is not
				// previously marked
				if (spf[j] == j)
					spf[j] = i;
		}
	}
}

// Function to store the prime factors after dividing
// by the smallest prime factor at every step
bool getFactorization(int x,int i)
{
	int num=i;
	int temp;
	while (x != 1) {
		temp = spf[x];
		if (x % temp == 0) {

			if(hash1.find(spf[x])!=hash1.end()&&hash1[spf[x]]!=num){
                return true;
			}
			hash1[spf[x]]=num;
			x = x / spf[x];
		}
		while (x % temp == 0)
			x = x / temp;
	}
	return false;
}



// Function that returns true if there is
// an element in the array which is coprime
// with all the other elements of the array
bool hasValidNum(int arr[], int n)
{

	// Using sieve for generating prime factors
	sieve();

	for (int i = 0; i < n; i++){
        if(getFactorization(arr[i],i))
            return false;
	}
	return true;


}

// Driver code
int main()
{
	hash1.clear();
	ios_base::sync_with_stdio (false) ;cin.tie(NULL);
	int n;cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
        cin>>arr[i];
	}
	bool ans=hasValidNum(arr,n);
	if(ans){
        cout<<"pairwise coprime";
	}else{
	  int s=arr[0];
	  for(int i=1;i<n;i++){
        s=__gcd(arr[i],s);
	  }
	  if(s==1){
        cout<<"setwise coprime";
	  }else{
	   cout<<"not coprime";
	  }
	}


}


Measured memory_bytes: 11536
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
    struct node *cur = nil->next;
    while ( cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
    if (t == nil ) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  deleteNode(nil->prev);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* your code */

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32968
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, a, n) for (int i = (n); i >= (a); i--)

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n,k;
  cin>>n>>k;
  int l[n];
  rep(i,0,n){cin>>l[i];}
  sort(l,l+n,greater<int>());
  int ans=0;
  rep(i,0,k){ans+=l[i];}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int rem = n%1000;
      if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem);
    
    }
}

Measured memory_bytes: 35700
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int i, j,k;
	int N;
	cin >> N;
	if (N==1) {
		cout << 1 << endl;
	}
	else if (N >= 2 && N < 4) {
		cout << 2 << endl;
	}
	else if (N >= 4 && N < 8) {
		cout << 4 << endl;
	}
	else if (N >= 8 && N < 16) {
		cout << 8 << endl;
	}
	else if (N >= 16 && N < 32) {
		cout << 16 << endl;
	}
	else if (N >= 32 && N < 64) {
		cout << 32 << endl;
	}
	else if (N >=64 && N <= 100) {
		cout << 64 << endl;
	}


}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int a = tmp[0], b = tmp[1];
        int ans = (int) Math.Ceiling((a+b)/2.0);
        WriteLine(ans);
    }
}


Measured memory_bytes: 13268
def ans (num, total, amax)
  if(total<=0)
    0
  elsif(num==1)
    if(total<=amax)
      1
    else
      0
    end
  else
    sum=0
    for i in 1..amax do
      sum+=ans(num-1,total-i,i-1)
    end
    sum
  end
end
      
  

while(true)
  a,b=gets.split(" ").map(&:to_i)
  if(a==0&&b==0) then
    break
  end
  d=ans(3,b,a)
  puts(d)
end

  

Measured memory_bytes: 8660
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll N;
  cin >> N;

  unordered_map<ll, int> um;

  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    um[tmp]++;
  }

  vector<ll> cand;
  for (auto& kv : um) {
    if (kv.second >= 4) {
      cand.emplace_back(kv.first);
      cand.emplace_back(kv.first);
    } else if (kv.second >= 2)
      cand.emplace_back(kv.first);
  }

  ll ans = 0;
  if (cand.size() >= 2) {
    sort(cand.begin(), cand.end());
    reverse(cand.begin(), cand.end());
    ans = cand[0] * cand[1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4388
#include <assert.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define F first
#define S second
#define qq queue
#define dq deque
#define vc vector
#define INF ((int)(2e9))
#define LINF ((int)(1e18))
#define out cout <<
#define ln  << endl
#define pb push_back
#define mp make_pair
#define _tp template
#define _tyn typename
#define pf push_front
#define itor iterator
#define mp make_pair
#define sint short int
#define ull unsigned long long
#define pq priority_queue
#define pii pair<int,int>
#define uint unsigned int
#define ll long long
#define B out "BreakPoint\n";
#define read(_nowans) scanf("%d",&_nowans)
#define ms(_data) memset(_data,0,sizeof(_data))
#define fin(_filename) freopen(_filename,"r",stdin)
#define fout(_filename) freopen(_filename,"w",stdout)
#define read2(_nowans1,_nowans2) scanf("%d %d",&_nowans1,&_nowans2)
#define msn(_data,_nowans) memset(_data,_nowans,sizeof(_data))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define read3(_nowans1,_nowans2,_nowans3) scanf("%d %d %d",&_nowans1,&_nowans2,&_nowans3)
#define lb( _x , _y ) ( lower_bound( _x.begin() , _x.end() , _y ) - _x.begin() + 1 )
using namespace std;
_tp<_tyn T>void mymax( T &_a , T _b ){ if( _a < _b ) _a = _b; }
_tp<_tyn T>void mymin( T &_a , T _b ){ if( _a > _b ) _a = _b; }
void print( int _x ){ printf("%d\n",_x); }
_tp<_tyn T>void print( T _data[] , int _size ){
	for( int i = 1 ; i <= _size ; i++ )
		cout << _data[i] << " ";
	cout << endl;
}

ll s1 , s2 , s3 , s4;
ll n;
vc< pair< ll , int > > mon;

// a b   x y
// a/x - b/y
// ay - bx
bool cmp( pair<ll,int> p1 , pair<ll,int> p2 ){
	return ( p1.F*p2.S - p2.F*p1.S ) < 0;
}

int main(){
	//fin( "A.txt" );

	while( cin >> s1 >> s2 >> s3 >> s4 >> n ){
		mon.clear();
		n *= 4;
		mon.pb( mp( s1 , 1 ) );
		mon.pb( mp( s2 , 2 ) );
		mon.pb( mp( s3 , 4 ) );
		mon.pb( mp( s4 , 8 ) );

		sort( mon.begin() , mon.end() , cmp );

		//for( uint i = 0 ; i < mon.size() ; i++ ){
	//		cout << i << "  |  " << mon[i].F << " " << mon[i].S << endl;
		//}
		int i = 0LL;
		ll ans = 0LL;
		while( n ){
			ll buy = n / mon[i].S;
			n -= buy * mon[i].S;
			ans += buy * mon[i].F;
			i++;
		}

		cout << ans << endl;
		}

	return 0;
}

// 80 60 70 45


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


int main(){
    int W, H, N;
    cin >> W >> H >> N;
    vector<int> x(N), y(N), a(N);
    rep(i, N) cin >> x[i] >> y[i] >> a[i];

    vector<vector<int>> grid(H, vector<int>(W, 0));

    for(int i = 0; i < N; i++){
        if(a[i] == 1){
            for(int m = 0; m < x[i]; m++){
                for(int n = 0; n < H; n++){
                    grid[n][m] = 1;
                }
            }
        }else if(a[i] == 2){
            for(int m = x[i]; m < W; m++){
                for(int n = 0; n < H; n++){
                    grid[n][m] = 1;
                }
            }

        }else if(a[i] == 3){
            for(int m = 0; m < y[i]; m++){
                for(int n = 0; n < W; n++){
                    grid[m][n] = 1;
                }
            }
        }else if(a[i] == 4){
            for(int m = y[i]; m < H; m++){
                for(int n = 0; n < W; n++){
                    grid[m][n] = 1;
                }
            }
        }
    }
    int cnt = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(grid[i][j] == 0) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

vector<ll> fact, invfact;
ll modpower(ll x, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n&1)res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n){
    return modpower(n,MOD-2,MOD);
}
void COMinit(ll k){ //空っぽの配列を二つ
   k++;
   fact.resize(k, 0);
   invfact.resize(k, 0);
   fact[0] = 1;
   repi(i, k, 1)
   {
       fact[i] = fact[i - 1] * i % MOD;
   }
   invfact[k - 1] = inv(fact[k - 1]);
   repd(i, k - 2, 0)
   {
       invfact[i] = invfact[i + 1] * (i + 1) % MOD;
   }
   return;
}
ll nCk(vector<ll> &fact,vector<ll> &invfact,ll n, ll k){ //この関数を使う前にCOMinit
   if (k < 0 || n < k)
       return 0LL;
   return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
ll com(ll n, ll k)
{
    ll iv = 1;
    ll fa = 1;
    repi(i, k, 0)
    {
        fa *= (n - i);
        fa %= MOD;
    }
    repi(i, k + 1, 1)
    {
        iv *= inv(i);
        iv %= MOD;
    }
    return fa * iv % MOD;
}

//---------main function----------

int main()
{
    int n = 5;
    repi(i,n,0){
        int x;
        cin >> x;
        if(x == 0){
            cout << i  + 1<< endl;
        }
    }
   return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL
	int a, b, c, x, y;
	scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

	int ans1 = a * x + b * y;
	int ans2 = max(x, y) * c * 2;

	int ans3;
	if (x > y) {
		ans3 = c * y * 2 + (x - y) * a;
	}else {
		ans3 = c * x * 2 + (y - x) * b;
	}

	cout << min(min(ans1, ans2), ans3) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf             LLONG_MAX
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
bool sortbysec(const pair<pair<string,int>,int> &a, 
              const pair<pair<string,int>,int> &b) 
{ 
	if(a.first.first==b.first.first)
		return a.first.second > b.first.second;
    return (a.first.first < b.first.first); 
} 
bool checkValidity(ll a, ll b, ll c) 
{ 
    // check condition 
    if (a + b > c && a + c > b && b + c > a) 
        return false; 
    else
        return true; 
} 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,ans=0;
        cin>>n;
        vector<ll>A(n);
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
        }
        for(ll i=0;i<n-1;i++)
        {
            if(A[i]>A[i+1])
            {
                ans=ans+(A[i]-A[i+1]);
                A[i+1]=A[i];
            }
        }
        cout<<ans;
    } 
    return 0;
}


Measured memory_bytes: 4776
#include <stdio.h>

int main(void) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if(a+b>c+d) printf("Left");
    else if(a+b<c+d) printf("Right");
    else printf("Balanced");
    return 0;
}

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

int main(void)
{
	int a, b;
	cin >> a >> b;
	if(!((a + b) % 3))
		cout << "Possible" << endl;
	else if(!(a % 3))
		cout << "Possible" << endl;
	else if(!(b % 3))
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	return 0;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
//inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int const mod = 1e9+7;

inline void safe_add(int& x, const int y) {
    x += y;
    if (x >= mod)
        x -= mod;
}

inline int safe_mul(const int x, const int y) {
    return x * 1LL * y % mod;
}


inline int safe_inv(int x) {
    int res = 1;
    for (int y = mod - 2; y > 0; y >>= 1) {
        if (y&1)
            res = safe_mul(res, x);
        x = safe_mul(x, x);
    }
    return res;
}

int const maxn = 5005;
int fact[maxn];
int invfact[maxn];


inline int C(const int n, const int k) {
    if (n < 0 || n < k || k < 0)
        return 0;
    return safe_mul(fact[n], safe_mul(invfact[k], invfact[n - k]));
}

int main()
//    freopen("in.txt","r", stdin);
{
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    fact[0] = invfact[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        fact[i] = safe_mul(fact[i - 1], i);
        invfact[i] = safe_inv(fact[i]);
    }

    int n,k;
    cin >> n >> k;

    for (int i = 1; i <= k; ++i) {
        int res = C(n - k + 1, i);
        int rest = k - i;
        res = safe_mul(res, C(i+ rest - 1, rest));
        cout << res << '\n';
    }
}


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

int main(){
    int N;
    cin >> N;
    vector<int> B(N);
    for(int i=0;i<N-1;i++) cin >> B.at(i);
    int sum = B.at(0);
    for(int i=1;i<N;i++){
        sum += min(B.at(i - 1), B.at(i));
    }
    sum = sum + B.at(N - 2);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int n,m,q,x,y;
vector <int> g[100005];
int a[100005],b[100005],c[100005],res[100005];
int misd[100005];
void dfs(int node,int Cin,int Din)
{
	if(Din<=misd[node])
	    return;
	misd[node]=Din;
	if(res[node]==0)
	    res[node]=Cin;
	if(Din==0)
	    return;
	for(int i=0;i<g[node].size();i++)
	    dfs(g[node][i],Cin,Din-1);
}
int main() 
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		x--,y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=0;i<n;i++)
	    misd[i]=-1;
	scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
    	scanf("%d%d%d",&a[i],&b[i],&c[i]);
    	a[i]--;
	}
	for(int i=q-1;i>=0;i--)
	    dfs(a[i],c[i],b[i]);
	for(int i=0;i<n;i++)
	    printf("%d\n",res[i]);
	return 0;
}

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

int main()
{
    char ref[2] = {'0', '1'};
    string S;
    cin >> S;
    ll ans = 0;

    bool zero = S[0] == '0';
    for (int i = 0; i < S.size(); ++i)
    {
        bool even = i % 2;
        if (zero)
        {
            if (S[i] != ref[even])
            {
                ++ans;
            }
        }
        else
        {
            if (S[i] != ref[!even])
            {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  long ans = 0, mx = 0;
  auto cmax = [&](auto& a, auto b) { if (a < b) a = b; };
  for (auto a : A) {
    if (a < mx) ans += mx - a;
    cmax(mx, a); 
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  if(N == M){
    for(int i=0; i<N; i++){
      cout << M;
    }
  }
  else{
    for(int i=0; i<max(N,M); i++){
      cout << min(N,M);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define Add_Speed ios_base::sync_with_stdio(0);cin.tie(0);
#define ins insert
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define sz size()
#define s second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define inf (int)1e9
#define gcd(a, b) __gcd(a, b)
#define int ll
#define pii pair<int, int>
#define pll pair<ll, ll>
 
using namespace std;
 
const int maxn = (int)1e2 + 17;
const int maxm = (int)1e5 + 7;
const int minn = (int)1e3 + 7;
const int mod = (int)1e9 + 7;
const long double PI = acos(-1);
const int P = (int)1e5 + 7;

int n, S, w[maxn], v[maxn], dp[maxn][maxm];

main () {
 
    Add_Speed;
 
    cin >> n >> S;
    for(int i = 1; i <= n; i++){
        cin >> w[i] >> v[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= S; j++){
            if(w[i] <= j){
                dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
            }
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[n][S];
}

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

int main() {
    int k, x;
    cin >> k >> x;
    if((500 * k) >= x) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    string ret = "AC";
    
    if(s[0]!='A') ret = "WA";
    ll count = 0;
    for (auto it = s.begin()+1; s.end() - it > 1; ++it  ){
        if (*it == 'C') ++count;
        else if ( *it - 'a' < 0 or *it - 'a' > 26){
            ret = "WA";
            break;
        }
    }
    if (count != 1) ret = "WA";
    auto it =s.begin()+1;
    if ( (*it - 'a' < 0) or (*it - 'a') > 26)ret = "WA";
    it =s.end()-1;
    if ( *it - 'a' < 0 or *it - 'a' > 26)ret = "WA";
    
    cout << ret << endl;
    return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {


    int N, M;
    cin >> N >> M;

    vector<int> l(M);
    vector<int> r(M);
    for (int i = 0; i < M; ++i) {
        cin >> l[i];
        cin >> r[i];
    }

    vector<int> s(N);

    int maxLeft = 0;
    int maxRight = N - 1;
    for (int i = 0; i < M; ++i) {
        int left = l[i] - 1;
        int right = r[i] - 1;
        if (left >= maxLeft) {
            maxLeft = left;
        }
        if(right <= maxRight){
            maxRight = right;
        }
        // cout << left << ":" << right << endl;
//        for (int j = left; j < right + 1; ++j) {
//            s[j]++;
//        }
    }

    int ans = 0;
//    for (int i = 0; i < N; ++i) {
//        int temp = s[i];
//
//        // cout << i << ":" << temp << endl;
//        if (temp == M) {
//            ans++;
//        }
//
//
//    }
    if (maxRight< maxLeft){ans = 0;}
    else{
    ans = maxRight - maxLeft + 1;}
    cout << ans << endl;

}

Measured memory_bytes: 1408
s = list(input())
ans = [-1, -1]
if len(s) == 2:
    if s[0] == s[1]:
        ans = [1, 2]
else:
    for i in range(len(s) - 2):
        if s[i] == s[i + 1] or s[i + 1] == s[i + 2] or s[i + 2] == s[i]:
            ans = [i + 1, i + 3]
            break
print(ans[0], ans[1])

Measured memory_bytes: 4084
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]

ndict = {i:0 for i in range(10)}
for i in range(H):
  for j in map(int, input().split()):
    if j == -1:
      continue
    ndict[j] += 1

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][j], c[i][k]+c[k][j])

ans = 0
for i in range(10):
  ans += ndict[i] * c[i][1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ll N,ans=1e9,d;
  cin>>N;
  ll X[N];
  for(ll i=0;i<N;i++) cin>>X[i];
  sort(X,X+N);
  for(int i=X[0];i<=X[N-1];i++){
    d=0;
    for(int j=0;j<N;j++){
      ll a=(X[j]-i)*(X[j]-i);
      d+=a;
    }
    ans=min(d,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;

	if (s.length() + 1 != t.length()) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<double,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int m;cin >> m;
    vector<LL> d(m),c(m);
    LL ans = 0;
    vector<LL> k(10,0);
    for (int i = 0; i < m; i++) {
        cin >> d[i] >> c[i];
        k[d[i]] += c[i];
    }
    while(true){
        bool f = false;
        for (int i = 0; i < 10; i++) {
            if(k[i]>1) f = true;
        }
        if(!f){
            int p = 0;
            for (int i = 0; i < 10; i++) {
                if(k[i]){
                    p += i;
                    ans++;
                }
            }
            ans--;
            ans += (p - 1) / 9;
            cout << ans << endl;
            return 0;
        }
        for (int i = 0; i < 10; i++) {
            LL t = k[i] / 2;
            if(i >= 5) ans += 2 * t;
            else ans += t;
            k[(i + i) / 10 + (i + i)%10] += t;
            k[i] -= 2 * t;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(){
  int a,c[10],i,b=0;
  cin>>a;
  for(i=0;i<6;i++){
    c[i]=a%10;
    a=a/10;
    bool r=c[i]==1;
    if(r)
      b++;
  }
  cout<<b;
  return 0;
}
           


Measured memory_bytes: 3188
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans;

    for(int i=0;i<19;i++){
        char a=0;
        cin >>a;
        if(a==',')cout <<' ';
        else cout << a;
    }
    cout <<endl;

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    dbg cout <<ans<<endl;

    return 0;

}

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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int n;
VI ss, gs;

const int INF = INT_MAX / 2;

bool check(int s) {
	rep (i, gs.size()) {
		if (s >= gs[i]) {
			gs[i] = INF;
			return true;
		}
	}
	return false;
}

int main(void) {
	while (1) {
		ss.clear();
		gs.clear();
		cin >> n;
		if (n == 0) break;
		VI gts;
		rep (i, n) {
			int h, m, s;
			scanf("%d:%d:%d", &h, &m, &s);
			int stime = h * 60 * 60;
			stime += m * 60;
			stime += s;
			scanf("%d:%d:%d", &h, &m, &s);
			int gtime = h * 60 * 60;
			gtime += m * 60;
			gtime += s;
			ss.PB(stime);
			gs.PB(gtime);
		}
		sort(ALL(gs));
		reverse(ALL(gs));
		int ans = 0;
		rep (i, n) {
			if (!check(ss[i])) {
				ans++;
			}
		}
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 3352
#include<cstdio>
#include<queue>
#include<algorithm>
const int N = (1<<19)+5;
int a[N];
int cnt[N];
std::priority_queue<int>Q;

int main(){
	int n;
	scanf("%d",&n);
	int m = 1<<n;
	for(int i = 1; i <= m; i++) scanf("%d",&a[i]);
	std::sort(a+1,a+1+m);
	int p = m; Q.push(n);
	int ok = 1;
	while(p>=1){
		int next = p;
		while(next>=1 && a[next]==a[p]) next--;
		if(p-next>Q.size()){
			ok = 0;
			break;
		}
		else{
			for(int i = p; i > next; i--){
				cnt[i] = Q.top();
				Q.pop();
			}
			for(int i = p; i > next; i--){
				for(int j = cnt[i]-1; j >= 0; j--) Q.push(j);
			}
			p = next;
		}
	}
	//printf("%d\n",Q.size());
	if(ok) printf("Yes\n");
	else printf("No\n"); 
	return 0;
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

template <class Monoid, class OperatorMonoid = Monoid> class LazySegmentTree {
  using F = std::function<Monoid(Monoid, Monoid)>;
  using G = std::function<Monoid(Monoid, OperatorMonoid, int)>;
  using H = std::function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;

  private:
    int n;
    std::vector<Monoid> seg;
    std::vector<OperatorMonoid> lazy;

    const F f;
    const G g;
    const H h;
    const Monoid M1;
    const OperatorMonoid OM1;

    void lazyUpdate(int k, int l, int r) {
      if(lazy[k] == OM1) return;

      if(2 * k + 1 < 2 * n - 1) {
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
        lazy[2 * k + 2] = h(lazy[2 * k + 2], lazy[k]);
      }
      seg[k] = g(seg[k], lazy[k], r - l);
      lazy[k] = OM1;
    }

  public:
    LazySegmentTree(int sz, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid &OM1) : f(f), g(g), h(h), M1(M1), OM1(OM1) {
      n = 1;
      while(n < sz) n *= 2;
      seg.resize(2 * n - 1, M1);
      lazy.resize(2 * n - 1, OM1);
    }

    void update(int a, int b, Monoid x, int k = 0, int l = 0, int r = -1) {
      if(r < 0) r = n;

      lazyUpdate(k, l, r);

      if(b <= l || r <= a) return;

      if(a <= l && r <= b) {
        lazy[k] = h(lazy[k], x);
        lazyUpdate(k, l, r);
      }
      else {
        update(a, b, x, 2 * k + 1, l, (l + r) / 2);
        update(a, b, x, 2 * k + 2, (l + r) / 2, r);
        seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
      }
    }

    Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) {
      if(r < 0) r = n;

      lazyUpdate(k, l, r);

      if(b <= l || r <= a) return M1;
      if(a <= l && r <= b) return seg[k];
      Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
};

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

  int n, q;
  cin >> n >> q;
  LazySegmentTree<int> seg(n, [](int a, int b){ return min(a, b); },
                              [](int a, int b, int len){ return b; },
                              [](int a, int b){ return b; }, INT_MAX, INT_MAX);
  rep(i, 0, q) {
    int c;
    cin >> c;
    if(c == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    }
    else {
      int x;
      cin >> x;
      cout << seg.query(x, x + 1) << endl;
    }
  }
}


Measured memory_bytes: 4972