akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pii pair<ll,ll>
#define mp make_pair
#define fr first
#define sd second
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const ll mod = 1e9+7;

int n,cnt[N],head[N],d[N],p[N],b[N],son[N],_f[N][21],dfn[N],cnte,st[N];
ll f[N][2];
vector<int>g[N];
struct nd{
	int ne,to;
}e[N*2];
void in(int x,int y){
	if(x==y||!x||!y)return;
	e[++cnte].to=y;e[cnte].ne=head[x];head[x]=cnte;
}

void dfs(int x){
	static int totw=0;
	cnt[d[x]]++;
	dfn[x]=++totw;
	g[d[x]].push_back(x);
	for(int i=head[x];i;i=e[i].ne){
		int y=e[i].to;
		d[y]=d[x]+1;
		_f[y][0]=x;
		dfs(y);
	}
}

ll qpow(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ret;
}

//ll C(int n,int m){
//	return n<m?0:fac[n]*rev[n-m]%mod*rev[m]%mod;
//}

void dfs1(int x,int lim){
	if(d[x]==lim){
		f[x][0]=f[x][1]=1;
		return;
	}
	for(int i=head[x];i;i=e[i].ne)dfs1(e[i].to,lim);
	ll totf=1,tot0=1;
	for(int i=head[x];i;i=e[i].ne){
		int y=e[i].to;
		totf=totf*(f[y][0]+f[y][1])%mod;
		tot0=(tot0*f[y][0])%mod;
	}
	for(int i=head[x];i;i=e[i].ne){
		int y=e[i].to;
		f[x][1]+=(f[y][1]*(tot0*qpow(f[y][0],mod-2)%mod))%mod;
		f[x][1]%=mod;
	}
	for(int i=head[x];i;i=e[i].ne)f[e[i].to][0]=f[e[i].to][1]=0;
	f[x][0]=(totf-f[x][1]+2*mod)%mod;
	head[x]=0;
}

int lca(int x,int y){
	if(d[x]<d[y])swap(x,y);
	for(int i=20;i>=0;--i)
	if(d[_f[x][i]]>=d[y])x=_f[x][i];
	if(x==y)return x;
	for(int i=20;i>=0;--i)
	if(_f[x][i]!=_f[y][i])
	x=_f[x][i],y=_f[y][i];
	return _f[x][0];
}

bool cmp(int a,int b){
	return dfn[a]<dfn[b];
}

ll solve(int d){
	int k=0,L=0;cnte=0;
 	for(int i=0;i<g[d].size();++i)p[++k]=g[d][i];
 	sort(p+1,p+k+1,cmp);
	st[++L]=1;
	for(int i=1;i<=k;++i){
		int x=p[i],l=lca(x,st[L]);
		while(1){
			if(dfn[st[L-1]]<=dfn[l]){
				in(l,st[L--]);
				if(st[L]!=l)st[++L]=l;
				break;
			}
			in(st[L-1],st[L]);L--;
		}
		if(st[L]!=x)st[++L]=x;
	}
	while(--L)in(st[L],st[L+1]);
	dfs1(1,d);
	ll res=f[1][1];
	f[1][1]=f[1][0]=0;
	return res*b[n-g[d].size()]%mod;
}

int main(){
	b[0]=1;
	for(int i=1;i<N;++i)b[i]=b[i-1]*2%mod;
	scanf("%d",&n);n++;
	for(int i=2;i<=n;++i)scanf("%d",&p[i]),p[i]++,son[p[i]]++;
	for(int i=2;i<=n;++i)in(p[i],i);
	d[0]=-1e7;dfs(1);
	for(int j=1;j<=20;++j)
	for(int i=1;i<=n;++i)
	_f[i][j]=_f[_f[i][j-1]][j-1];
	ll ans=0;
	memset(head,0,sizeof(head));
	for(int i=1;cnt[i];++i)(ans+=solve(i))%=mod;
	ans+=b[n-1];
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 45824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        long ans = 0;
        ans = Math.min(a, k);
        k = k - a;
        if(k <= 0) {
            System.out.println(ans);
            return;
        }
        k = k - b;
        if(k <= 0) {
            System.out.println(ans);
            return;
        }
        k = Math.min(c, k);
        System.out.println(ans - k);
    }
}

Measured memory_bytes: 35856
a, b = map(int, input().split())

import math
mina = math.ceil(a*12.5) #自身も含まれる
minb = b*10 #自身も含まれる
maxa = math.ceil((a+1)*12.5) #自身は含まれない
maxb = (b+1)*10 #自身は含まれない
minab = max([mina, minb])
maxab = min([maxa, maxb])

if minab >= maxab:
    ans = -1
else:
    ans = minab

print(ans)

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

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    for (unsigned int i = 0; i < S.size() / 2; i++)
    {
        if (S[i] != S[S.size() - (i + 1)])
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
	string s, p;
	getline(cin, s);
	getline(cin, p);
	
	s += s;
	
	int a = s.find(p);
	
	if(a == -1) cout<<"No"<<endl;
	else        cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#define MAX 10001
using namespace std;
int main(void) {
    int n, a[MAX], cnt=0;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i];
    
    for(int i=0; i<n; i++) {
        while(a[i]%2==0) {
            cnt++;
            a[i] /= 2;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> vec;
  while(n--) {
    int a; cin >> a;
    if (vec.size() > 0 && vec[vec.size()-1] == a) continue;
    vec.push_back(a);
  }

  unordered_map<int, int> mp;
  vector<ll> ans(vec.size()+1);
  ans[0] = 1;
  for(int i=0; i<vec.size(); i++) {
    ans[i+1] = ans[i];
    if (mp.find(vec[i]) == mp.end()) {
      mp[vec[i]] = i;
    } else {
      int p = mp[vec[i]];
      //debug(i); debugln(p);
      ans[i+1] += ans[p+1];
      mp[vec[i]] = i;
    }
    ans[i+1] %= mod;
    //debug(i); debugln(ans[i]);
  }
  cout << (ans[vec.size()])%mod << endl;
}


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

using namespace std;

#define ll long long

const int mod = 1e9+7;
ll quickpow(ll a, ll b) {  //璐归┈灏忓畾鐞嗘眰閫嗗厓
    if (b < 0) return 0;
    ll ret = 1;
    a %= mod;
    while(b) {
        if (b & 1) ret = (ret * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ret;
}
ll inv(ll a) {
    return quickpow(a, mod - 2);
}

//璁＄畻缁勫悎鏁板彇妯?
ll comp(ll a, ll b, int p) {
    if(a < b)   return 0;
    if(a == b)  return 1;
    if(b > a - b)   b = a - b;

    int ans = 1, ca = 1, cb = 1;
    for(ll i = 0; i < b; ++i) {
        ca = (ca * (a - i))%p;
        cb = (cb * (b - i))%p;
    }
    ans = (ca*inv(cb)) % p;
    return ans;
}
ll lucas(ll n, ll m, ll p) {
     ll ans = 1;

     while(n&&m&&ans) {
        ans = (ans*comp(n%p, m%p, p)) % p;
        n /= p;
        m /= p;
     }
     return ans;
}
int main(){
	int  x,y;
	cin >> x >> y;
	if(x>y)	swap(x,y);
	int level = (x+y)/3;
	if(level > min(x,y) || (x+y)%3!=0){
		cout << "0\n";
		return 0;
	}
	int  cnt = x - level;
	cout << lucas(level,cnt,mod)<<'\n';
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};

// [NOTE] つかうときには trim() 入れないと RE になるので注意
// abcde
fn read_as_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}

// -3.2
fn read_as_primitive<T: FromStr>() -> T {
    let s = read_as_line();
    s.trim().parse().ok().expect("failed to parse input")
}

// 1 -3 0 999
fn read_as_collection<U: FromStr, T: FromIterator<U>>() -> T {
    let s = read_as_line();
    s.trim().split_whitespace().map(|s| s.parse().ok().expect("failed to parse")).collect()
}

// #.#.###..
fn read_as_chars<T: FromIterator<char>>() -> T {
    let s = read_as_line();
    s.trim().chars().collect()
}

// 1 abc
fn read_as_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let s = read_as_line();
    let mut it = s.trim().split_whitespace();
    (
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
    )
}

// 1.5 -2 abc
fn read_as_triple<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let s = read_as_line();
    let mut it = s.trim().split_whitespace();
    (
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
    )
}


fn main() {
    let r: i64 = read_as_primitive();
    let mut ans = 3 * r * r;
    println!("{}", ans);

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    int S;
    S = (a - 1) * (b - 1);
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    simplify

    int n;
    cin>>n;
    //n--;
    string s;
    while(n>0){
        n--;
        int add=(n+1)%26;
        //cout<<add<<endl;
        char c;
        if(add==0)c='z';
        else c='a'+(add-1);
        s.push_back(c);
        n/=26;
        
    }
    //cout<<s;
    reverse(s.begin(),s.end());
    cout<<s;



    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main()
{
	int n,a,b,ans=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		int p=i,sum=0;
		while(p>0)
		{
			sum+=p%10;
			p=p/10;
		}
		if(sum>=a&&sum<=b) ans+=i;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		

		if(a>=1200)
			System.out.println("ARC");
		else
			System.out.println("ABC");
	}
}

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

int main(void){
  int n, flag, *a, j, t, i, counter=0;

  scanf("%d",&n);
  a = malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  flag = 1;
  while(flag){
    flag = 0;
    for(j=n-1;j>0;j--){
      if(a[j] < a[j-1]) {
	t = a[j]; a[j] = a[j-1]; a[j-1] = t;
	flag = 1;
	counter++;
      }      
    }
  }

  for(j=0;j<n;j++){
    printf("%d",a[j]);
    if(j==n-1) printf("\n");
    else printf(" ");
  }
  printf("%d\n",counter);
  return 0;
}


Measured memory_bytes: 1992
#include<iostream>

using namespace std;

int main() {
    int a, b, k, i;
    cin >> a >> b >> k;
    for(i = 100; i >= 1; i--) {
        if(a % i == 0 && b % i == 0) k--;
        if(k == 0) break;
    }
    cout << i << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
typedef unsigned long long UInt64;
typedef long long Int64;
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
using namespace std;

typedef pair<int,int> P;

//一段したは+4

int main()
{
	map<string,int> dist;

	int DX[]={1,-1,4,-4};
	//状態と0の位置
	queue<pair<string,int> > que;
	que.push(mp("01234567",0));
	dist["01234567"]=0;

	while(que.size())
	{
		pair<string,int> p=que.front();
		que.pop();

		rep(i,4)
		{
			int nx=p.sc+DX[i];
			string nextstr=p.fr;
			if(p.sc%4==0&&i==1) continue;
			if(p.sc%4==3&&i==0) continue;
			if(0<=nx&&nx<8)
			{
				swap(nextstr[nx],nextstr[p.sc]);
				if(dist.find(nextstr)==dist.end())
				{
					que.push(mp(nextstr,nx));
					dist[nextstr]=dist[p.fr]+1;
				}
			}
		}
	}

	string str;
	while(getline(cin,str))
	{
		stringstream ss(str);

		string str2,str3;

		while(ss>>str2)
			str3+=str2;
		cout<<dist[str3]<<endl;

	}

		return 0;
}

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

typedef long long ll;

int main() {
  ll Q,H,S,D;
  cin >> Q >> H >> S >> D;
  ll N;
  cin >> N;

  vector<pair<long double,char> > L(5);
  L[0].first = 4*Q;   L[0].second = 'A';
  L[1].first = 2*Q+H; L[1].second = 'B';
  L[2].first = 2*H;   L[2].second = 'C';
  L[3].first = S;     L[3].second = 'D';
  L[4].first = D/2.0; L[4].second = 'E';

  sort(L.begin(),L.end());

  ll ans=0;
  if(N%2==1){
    if(L[0].second == 'E'){
      ans += N/2*D;
      ans += L[1].first;
    }
    else {
      ans += N*L[0].first;
    }
  }
  else {
    ans += N*L[0].first;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
    "math"
    "bufio"
    "os"
)

func min(nums ...int) int {
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Min(float64(res), float64(nums[i])))
    }
    return res
}

func cnt(field [][]byte, ans [][]int) {

    var H = len(field)
    var W = len(field[0])
    for i := 0; i < H; i++ {
        var l = 0
        for j :=0; j < W; j++ {
            if field[i][j] != '#' {
                ans[i][j] += l
            }
            if field[i][j] == '#' {
                l = 0
            } else {
                l += 1
            }
        }
    }
}

func rot(field [][]byte) [][]byte {
    var H = len(field)
    var W = len(field[0])
    var res = make([][]byte, W)
    for i:= 0; i < W; i++ {
        res[i] = make([]byte, H)
    }
    for i := 0; i < H; i++ {
        for j := 0; j < W; j++ {
            res[j][H-i-1] = field[i][j]
        }
    }
    return res
}

func rot2(field [][]int) [][]int {
    var H = len(field)
    var W = len(field[0])
    var res = make([][]int, W)
    for i:= 0; i < W; i++ {
        res[i] = make([]int, H)
    }
    for i := 0; i < H; i++ {
        for j := 0; j < W; j++ {
            res[j][H-i-1] = field[i][j]
        }
    }
    return res
}

func main() {
    //cpuprofile := "mycpu.prof"
    //f, err := os.Create(cpuprofile)
    //if err != nil {
    //    log.Fatal(err)
    //}
    //pprof.StartCPUProfile(f)
    //defer pprof.StopCPUProfile()
    //

    var H, W int
    fmt.Scan(&H, &W)
    var ss[]string
    var reader = bufio.NewReader(os.Stdin)
    for i := 0; i < H; i++ {
        //fmt.Scan(&s)
        var s, _, _ = reader.ReadLine()
        ss = append(ss, string(s))
    }

    var field [][]byte
    for i := 0; i < H; i++ {
        var s []byte
        for j := 0; j < W; j++ {
            var c = ss[i][j]
            s = append(s, c)
        }
        field = append(field, s)
    }
    var ans = make([][]int, H)
    for i:= 0; i < H; i++ {
        ans[i] = make([]int, W)
    }

    for i := 0; i < 4; i++ {
        //fmt.Println("field")
        //
        //for t := 0; t < len(field); t++ {
        //    fmt.Println(field[t])
        //}
        //fmt.Println("ans")
        //for t := 0; t < len(ans); t++ {
        //    fmt.Println(ans[t])
        //}


        cnt(field, ans)
        field = rot(field)
        ans = rot2(ans)
    }

    //fmt.Println(ans)

    var t = 0
    for i := 0; i < H; i++ {
        for j := 0; j < W; j++ {
            if field[i][j] != '#' {
                t = int(math.Max(float64(t), float64(ans[i][j])))
            }
        }
    }
    fmt.Println(t + 1)

}

Measured memory_bytes: 103040
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = float('Inf')
for i in range(2 ** n):
    sum_ = [0] * m
    cost = 0
    for j in range(n):
        #sum_ = [0] * m
        if ((i >> j) & 1):
            cost += a[j][0]
            for k in range(m):
                sum_[k] += a[j][k + 1]
                
    flag = True
    for j in range(m):
        if sum_[j] < x:
            flag = False
    if flag:
        ans = min(ans, cost)
if ans == float('Inf'):
    print(-1)
else:
    print(ans)
        

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

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

	if (a <= 5)
	{
		cout << 0 << endl;
	}
	else if (6 <= a && a <= 12)
	{
		cout << b / 2 << endl;
	}
	else
	{
		cout << b << endl;
	}
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int a=0,b=0,c=0,n=0,i=0;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);

		if(a>=b&&a>=c){
			if(b*b+c*c==a*a){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}else if(b>=a&&b>=c){
			if(a*a+c*c==b*b){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}else if(c>=a&&c>=b){
			if(b*b+a*a==c*c){
				printf("YES\n");
			}else{
				printf("NO\n");
			}



		}
	}
}



Measured memory_bytes: 2060
#!/usr/bin/env python3
import sys


def solve(K: int, X: int):
    print(' '.join([str(i) for i in range(X-K+1, X+K)]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(K, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  map<ll, vector<ll> > memo;
  rep(i,N){
    ll a;
    cin >> a;
    memo[a%M].push_back(a);
  }


  ll ret = 0;
  rep(i,M){
    if(i > M-i) break;
    if(i==0 || (M%2==0 && i==M/2)){
      vector<ll> a = memo[i];
      ret += a.size()/2;
    }else{
      vector<ll> a = memo[i];
      vector<ll> b = memo[M-i];
      if(a.size() > b.size()) swap(a,b);
      map<ll,ll> cnt;
      rep(j,b.size()){
        cnt[b[j]]++;
      }
      vector<ll> tmp;
      FOR(it,cnt){
        tmp.push_back(it->second);
      }

      ll m = b.size();
      rep(j,tmp.size()){
        while(tmp[j] >= 2 && m-2 >= a.size()){
          m -= 2;
          tmp[j] -= 2;
          ret++;
        }
      }
      ret += a.size();
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vstr=vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vin p(n),q(n);
    rep(i,n)cin>>p[i];
    rep(i,n)q[i]=i+1-p[i];
    int sum=0;
    rep(i,n){
        if(q[i])sum++;
    }
    if(sum<=2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

using namespace std;

int make_before_tax(int price, int rate) {
    int before = (price * 100 + 99 + rate) / (100 + rate);
    if (before * (100 + rate) / 100 != price) {
        throw "tsurai";
    }
    return before;
}

int solve(int x, int y, int s) {
    int max_total = 0;
    for (int a = 1; a < s; ++a) {
        try {
            int changed_a = make_before_tax(a, x) * (100 + y) / 100;
            int changed_b = make_before_tax(s - a, x) * (100 + y) / 100;
            max_total = max(max_total, changed_a + changed_b);
        } catch (const char *) {
            continue;
        }
    }
    return max_total;
}

int main() {
    int x, y, s;
    while (true) {
        cin >> x >> y >> s;
        if (x == 0) {
            return 0;
        }
        cout << solve(x, y, s) << endl;
    }
}

Measured memory_bytes: 1256
N = int(input())
A = [0] + [int(input()) for _ in range(N)]

ans = 0
for i in range(1,N+1):
    if A[i] != 0:
        ans += A[i-1]
        A[i] -= A[i-1]
    ans += A[i]//2
    A[i] = A[i]%2

print(ans)


Measured memory_bytes: 7840
x,y = map(int,input().split())
if((x+y)%3 != 0):
    print(0)
    exit()

if(abs(y-x) > min(x,y)):
    print(0)
    exit()

sum_ = (x+y)//3
right = y - sum_
up = x - sum_

mod = 10**9 + 7

## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 10**6 + 10
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ans = com((right+up), right)
print(ans)

Measured memory_bytes: 62192
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=2e5+7;
const int mod=10007;
double isp=1e-6;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
int a[MX],b[MX];
int main()
{
 ios::sync_with_stdio(0),cin.tie(0);
 int A,B,M;
 cin>>A>>B>>M;
 int mi=1e9;
 rep(i,1,A)
 {
     cin>>a[i];
 }
 rep(i,1,B)
 {
     cin>>b[i];
 }
 rep(i,1,M)
 {
     int x,y,z;
     cin>>x>>y>>z;
     mi=min(a[x]+b[y]-z,mi);
//     cout<<a[x]<<" "<<b[y]<<" "<<z<<endl;
  //   cout<<mi<<endl;
 }
 sort(a+1,a+A+1);
 sort(b+1,b+B+1);
 mi=min(a[1]+b[1],mi);
 cout<<mi<<endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        StringBuilder left = new StringBuilder();
        StringBuilder right = new StringBuilder();
        int reverse = 0;
        int q = Integer.parseInt(br.readLine());
        for(int i = 0; i < q; i++){
            String[] query = br.readLine().split(" ");
            if("1".equals(query[0])){
                reverse = (reverse + 1) % 2;
            } else {
                int command = Integer.parseInt(query[1]);
                if((reverse == 0 && command == 2) || (reverse == 1 && command == 1)){
                    right.append(query[2]);
                } else {
                    left.insert(0, query[2]);
                }
            }
        }
        br.close();
        String result = left.toString() + s + right.toString();
        if(reverse == 1){
            result = new StringBuilder(result).reverse().toString();
        }
        System.out.println(result);
    }
}

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

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

  int N;
  cin >> N;
  int64_t A[N];
  int64_t B[N+1] = {};
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  if(A[0] != 0){
    cout << 0 << endl;
    return 0;
  }

  for(int i=0;i<N;i++){
    B[A[i]]++;
  }

  if(B[0] != 1){
    cout << 0 << endl;
    return 0;
  }

  int64_t ans = 1;
  for(int i=1;i<N;i++){
    for(int j=0;j<B[i+1];j++){
      ans = ans * B[i] % 998244353;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import math

A, B, H, M = map(int, input().split())
hour = (H+M/60) / 12 * 360
minute = M / 60 * 360
deg=(max(hour, minute) - min(hour, minute)) % 360
if deg <= 180:
    pass
else:
    deg = 360 - deg

ans = math.sqrt(A**2 + B**2 -2*A*B*math.cos(deg * math.pi / 180))
print(ans)


Measured memory_bytes: 9452
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,k,cnt=0,ans=0,viz[25][25];
char a[15][15];
map<vector<ll>, ll>mpp;
vector<ll>v;
void sol(ll x){
v.pb(x);
ll s1=0;
for(ll i=0;i<=20;i++)
{
    for(ll j=0;j<=20;j++)
    {
        viz[i][j]=0;
    }
}
for(ll i=0;i<v.size();i++)
{
    if(v[i]<=n){
        for(ll j=1;j<=m;j++)
        {
            if(a[v[i]][j]=='#'&&viz[v[i]][j]==0){
                s1++;
                 viz[v[i]][j]=1;
            }
        }
    }else {
    for(ll j=1;j<=n;j++)
    {
        if(a[j][v[i]-n]=='#'&&viz[j][v[i]-n]==0){
            s1++;
            viz[j][v[i]-n]=1;
        }
    }
    }
}
if(cnt-s1==k){
    ans++;
}
for(ll i=x+1;i<=n+m;i++)
{
    sol(i);
}
v.pop_back();
}
int32_t main(){
CODE_START;
cin>>n>>m>>k;
for(ll i=1;i<=n;i++)
{
    for(ll j=1;j<=m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='#'){
            cnt++;
        }
    }
}
for(ll i=1;i<=n+m;i++)
{
    sol(i);
}
if(cnt==k){
    ans++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 3620
def main():
    N = int(input())
    A = list(map(int, input().split()))

    solve(N,A)

def solve(N,A):
    ans = float("inf")

    # ans = TLE(N,A,ans)
    ans = AC(N,A,ans)

    print(ans)

def TLE(N,A, ans):
    for i in range(1, N):
        snk = sum(A[:i])
        ari = sum(A[i:])

        ans = min(ans, abs(snk - ari))

    return ans

def AC(N,A,ans):
    cum_A = [None] * N
    cum_A[0] = A[0]
    for i in range(1, N):
        cum_A[i] = cum_A[i-1] + A[i]

    for i in range(N-1):
        snk = cum_A[i]
        ari = cum_A[-1] - snk

        ans = min(ans, abs(snk - ari))

    return ans

if __name__ == "__main__":
    main()


Measured memory_bytes: 24492
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            for (int i = 1; ; i++) {
                String line = reader.readLine();
                int n = Integer.parseInt(line);
                if (n == 0) {
                    break;
                } else {
                    System.out.println("Case " + i + ": " + n);
                }
            }
        } catch (IOException e) {
            System.out.println(e);
        } catch (NumberFormatException e) {
            System.out.println("??°????????¢????????£????????????????????????");
        }
    }
}

Measured memory_bytes: 31940
#include<stdio.h>

int main()
{

    int j,i,n,k,m;
    scanf("%d",&n);
    if(n>=1 && n<=100)
    {
        for(i=1;i<=9;i++)
        {
            for(j=1;j<=9;j++)
            {
            if(n==i*j)
            {
               m=i*j;
            }

            }

        }
if(n==m)
{printf("Yes");}
else{printf("No");}



    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector< vector<int> > schedule(n, vector<int>(31));
		for(int i = 0; i < n; ++i){
			int fi;
			cin >> fi;
			for(int j = 0; j < fi; ++j){
				int d;
				cin >> d;
				schedule[i][d] = 1;
			}
		}
		vector<ll> share(n);
		for(int i = 0; i < n; ++i){ share[i] = 1ll << i; }
		const ll finish = (1ll << n) - 1;
		int answer = -1;
		for(int i = 1; i <= 30; ++i){
			ll sum = 0;
			for(int j = 0; j < n; ++j){
				if(schedule[j][i]){ sum |= share[j]; }
			}
			if(sum == finish){
				answer = i;
				break;
			}
			for(int j = 0; j < n; ++j){
				if(schedule[j][i]){ share[j] = sum; }
			}
		}
		cout << answer << endl;
	}
	return 0;
}

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

vector<int> BIT; //1-indexed

void bitadd(int faddend, int findex){
    for(int i=findex+1; i<BIT.size(); i += (i & -i))BIT[i] += faddend;
    return;
}

int bitsum(int fright){
    int res = 0;
    for(int i=fright+1; i>0; i -= (i & -i))res += BIT[i];
    return res;
}

int main(void){
    int N, Q, cbuf, lbuf, rbuf;
    vector<int> c;
    cin >> N >> Q;
    BIT.assign(N+1, 0);
    vector<int> Colors(N, -1);
    vector<int> colFormer(N, -1);
    vector<int> res(Q);
    vector<vector<pair<int, int>>> query(N);
    for(int i=0; i<N; i++){
        cin >> cbuf;
        cbuf--;
        c.push_back(cbuf);
        colFormer[i]=Colors[cbuf];
        Colors[cbuf]=i;
    }
    for(int iquery=0; iquery<Q; iquery++){
        cin >> lbuf >> rbuf;
        lbuf--;
        rbuf--;
        query[rbuf].push_back(pair<int, int>(iquery, lbuf));
    }
    int iquery_sorted=0;
    for(int curR=0; curR<N; curR++){
        if(colFormer[curR]>=0)bitadd(-1, colFormer[curR]);
        bitadd(1, curR);
        int rightsum = 0;
        int querysize = query[curR].size();
        if(querysize > 0)rightsum = bitsum(curR);
        for(int i=0; i<querysize; i++){
            res[query[curR][i].first] = rightsum - bitsum(query[curR][i].second-1);
        }
    }
    for(int iquery=0; iquery<Q; iquery++)cout << res[iquery] << endl;
    return 0;
}

Measured memory_bytes: 35168
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;

vector<int> A;
int n;


int binarysearch(int t){
	int left = 0;
	int right = n;
	int mid;

	while (left < right) {
		mid = (left + right) / 2;

		if (t == A[mid]) return 1;
		if (t < A[mid]) right = mid;
		else left = mid + 1;
	}

	return 0;


}


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

	int x;

	for (int i = 0; i < n; i++) {
		cin >> x;
		A.push_back(x);
	}

	cin >> q;

	int sum = 0;
	for (int i = 0; i < q; i++) {
		cin >> t;

		if (binarysearch(t)) sum++;
	}
	cout << sum << endl;



	return 0;
}


Measured memory_bytes: 3436
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define MAX(a, b) a > b ? a : b
#define MIN(a, b) a < b ? a : b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 100000000

using namespace std;
typedef pair<int, int> P;
int DX[4] = {1, 0, -1, 0};
int DY[4] = {0, 1, 0, -1};



int main() {
	int N;
	long long p = 1;
	CIN(N);
	for(int i = 1; i <= N; ++i) {
		p = p * i % 1000000007;

	}
	COUT(p);
}



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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
	    ll s,w;
	     cin>>s>>w;

	     if(s>w)
            cout<<"safe\n";
         else
            cout<<"unsafe\n";



	}
	return 0;
}













Measured memory_bytes: 3620
abcde = [int(input()) for _ in range(5)]
mn = 124
id = 0
for i in range(5):
    if abcde[i] % 10 != 0 and abcde[i] % 10 <= mn:
        mn = abcde[i] % 10
        id = i
ans = 0
for i in range(5):
    if i == id:
        ans += abcde[i]
    elif abcde[i] % 10 == 0:
        ans += abcde[i]
    else:
        ans += (abcde[i]//10+1)*10
print(ans)


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

//ifstream fin("date.in");
//ofstream gout("date.out");

const int NMax = 1e6 + 5;
const int mod = 1e9 + 7;



int main()
{
	//freopen("date.in", "r", stdin);
	//freopen("date.out", "w", stdout);

	
	int N;
	cin >> N;
	int x = int(sqrt(N));
	cout << x * x;
	return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input_text = scanner.nextLine();
        input_text = scanner.nextLine();
        String[] data = input_text.split(" ");
        scanner.close();
        for(int i = 0; i < data.length; i++) {
            int n = Integer.parseInt(data[i]);
            if(n % 2 == 0) {
                if(n % 3 != 0 && n % 5 != 0) {
                    System.out.println("DENIED");
                    return;
                }
            }
        }
        System.out.println("APPROVED");
    }

}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  if(n%2==1){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<(n/2);i++){
    if(s.at(i)!=s.at(i+n/2)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
h,w = map(int, input().split( ))
s = []

for i in range(h):
    s.append(input())
#幅優先探索
#経路不要
#最短経路長だけ白
from collections import deque

Q = deque()

Q.append((0,0))
N = [(1,0),(-1,0),(0,1),(0,-1)]
D = [[-1]*w for _ in range(h)]
D[0][0]=1
cnt = 0

for u in range(h):
    for v in range(w):
        if s[u][v]=="#":
            cnt +=1

while Q:
    a,b = Q.popleft()
    for i,j in N:
        if 0<=a+i<h and 0<=b+j<w:
            if D[a+i][b+j]<0 and s[a+i][b+j]==".":
                    D[a+i][b+j] = D[a][b]+1
                    Q.append((a+i,b+j))
           

if D[h-1][w-1]>0:
    print(h*w-cnt-D[h-1][w-1])
else:
    print(-1)
    


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

int main(){
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  vector<long long> F(N);
  for (int i=0; i<N; i++) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<long long>());
  long long Mx = 1e12, Mn = 0;
  while(Mn<Mx){
    long long md = (Mx + Mn)/2;
    long long tr = 0;
    for (int i=0; i<N; i++){
      if(A[i]*F[i] > md){
        tr += A[i] - (md / F[i]);
      }
    }
    if(tr>K){
      if (Mn == md){
        cout << Mx << endl;
        return 0;
      }
      Mn = md;
    } else {
      Mx = md;
    }
  }
  cout << Mx << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int get(int n) {
    if (n == 2) {
        return 0;
    } else if (n == 4 || n == 6 || n == 9 || n == 11) {
        return 1;
    } else {
        return 2;
    }
}

int main() {
    int x, y;
    cin >> x >> y;
    if (get(x) == get(y)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;




int main() {
	string s;
	cin >> s;
	string ans;
	if (s.length() % 2 == 0 ^ s[0] == s[s.length() - 1]) {
		ans = "Second";
	}
	else {
		ans = "First";
	}

	cout << ans << endl;
}


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

int main(void){
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    int a[n][m];
    rep(i,m){
        int x;
        cin >> x;
        b[i] = x;
    }
    rep(i,n){
        rep(j,m){
            int x;
            cin >> x;
            a[i][j] = x;
        }
    }
    int ans = 0;
    rep(i,n){
        int sum = 0;
        rep(j,m){
            sum += b[j]* a[i][j];
        }
        sum += c;
        if(sum > 0){
            ans++;
        }
    }
    
    cout << ans <<endl;
    
    
    return 0;
}




































Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

ll lcm(ll a, ll b) {
    return a / __gcd(a, b) * b;
}
ll f(ll x) {
    ll res = 0;
    while (x % 2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}
int main() {
    SS(ll,N,M)
    vl a(N);
    rep(i,N){
        cin>>a[i];
        a[i]/=2;
    }
    debug(0)
    ll deal=f(a[0]);
    rep(i,N){
        if(f(a[i])!=deal){
            p(0);
            return 0;
        }
    }
    ll res=1;
    rep(i,N)res=lcm(res,a[i]);
    if(res>M){
        p(0);
        return 0;
    }
    M/=res;
    ll ans=(M+1)/2;
    p(ans);
}

Measured memory_bytes: 1024
l, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]

ll, rr = 1, l
for l, r in lr:
    if ll <= l <= rr or l <= ll <= r:
        ll, rr = max(ll, l), min(rr, r)
    else:
        print(0)
        exit()
print(rr-ll+1)

Measured memory_bytes: 27272
#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[i];
	
	int mn=a[0],mx=a[0];
	for(int i=1;i<n;i++){
		if(mn>a[i])
			mn=a[i];
		if(mx<a[i])
			mx=a[i];
	}
	
	cout<<mx-mn<<endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 210
#define INF 10000005

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

int n;
int X,Y,E;
ll K;

struct edge{int to,cap,rev;};

vector<edge> G[SIZE];
bool used[SIZE];

//グラフ追加: from -> to (cap)
void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

//パスを一本見つける
int dfs(int v, int t, int f){
	if(v==t)return f;
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap>0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d>0){ //v -> G[v][i].toにd流す
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow = 0;
	for(;;){
		memset(used,0,sizeof(used));
		int f = dfs(s,t,INF);
		if(f==0)return flow;
		flow += f;
	}
}


int main()
{
	scanf("%d %d %d",&X,&Y,&E);
	int x,y;
	for(int i=0;i<X;i++)add_edge(200,i,1);
	for(int i=0;i<Y;i++)add_edge(100+i,201,1);
	for(int i=0;i<E;i++){
		scanf("%d %d",&x,&y);
		add_edge(x,100+y,1);
	}
	int ans = max_flow(200,201);
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 2876
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    if (a.at(a.size() - 1) == b.at(0))
    {
        if (b.at(b.size() - 1) == c.at(0))
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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

class union_find
{
public:
	int *par;
	int *rank;

	union_find(int n) {
		par = new int[n];
		rank = new int[n];
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int root(int a) {
		if (par[a] == a) {
			return a;
		}
		else {
			return root(par[a]);
		}
	}

	bool same(int a, int b) {
		return root(a) == root(b);
	}

	void uni(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return;
		}
		if (rank[a] < rank[b]) {
			par[a] = b;
		}
		else {
			par[b] = a;
			if (rank[a] == rank[b]) {
				rank[a]++;
			}
		}
	}
};

int n, k, l;
union_find *c, *t;

int main() {
	cin >> n >> k >> l;
	c = new union_find(n);
	for (int i = 0; i < k; i++) {
		int p, q;
		cin >> p >> q;
		p--;
		q--;
		c->uni(p, q);
	}

	t = new union_find(n);
	for (int i = 0; i < l; i++) {
		int s, r;
		cin >> s >> r;
		s--;
		r--;
		t->uni(s, r);
	}

	map<pair<int, int>, int>mp;
	pair<int, int>*pairs = new pair<int, int>[n];
	for (int i = 0; i < n; i++) {
		pair<int, int>p = make_pair(c->root(i), t->root(i));
		pairs[i] = p;
		mp[p]++;
	}
	for (int i = 0; i < n-1; i++) {
		cout << mp[pairs[i]]<<" ";
	}
	cout <<mp[pairs[n-1]]<< endl;
	return 0;
}



Measured memory_bytes: 16640
import sys
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
t=[[(0 if i == 0 or j == 0 or i == (h+1) or j == (w+1) or s[i-1][j-1]=='.' else 1) for j in range(w+2)] for i in range(h+2)]
for i in range(1,h+1):
	for j in range(1,w+1):
		if t[i][j] == 0:
			continue
		if t[i-1][j] == 0 and t[i][j-1] == 0 and t[i][j+1] == 0 and t[i+1][j] == 0:
			print("No")
			sys.exit()
print("Yes")

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

int main() {
  int X,Y;
  cin>>X>>Y;
  string board[X];
  for(int i=0;i<X;i++) cin>>board[i];
  int dx[]={1,1,1,0,0,-1,-1,-1};
  int dy[]={1,0,-1,1,-1,1,0,-1};
  for(int i=0;i<X;i++){
    for(int j=0;j<Y;j++){
      if(board[i][j]=='.'){
      int cnt=0;
      for(int k=0;k<8;k++){
        int x=i+dx[k];
        int y=j+dy[k];
      if(board[x][y]=='#'&&x>=0&&x<=X&&y>=0&&y<=Y) cnt++;
    }
      board[i][j]='0'+cnt;
      }
    }
  }
  for(int i=0;i<X;i++)
  cout<<board[i]<<endl;
}
      
      

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n, max = 0;
  int cnt[100] = {0};

  while(cin >> n) cnt[n-1]++;
  for(int i = 0; i < 100; i++) {
    if(cnt[i] > max) max = cnt[i];
  }

  for(int i = 0; i < 100; i++) {
    if(cnt[i] == max) cout << i+1 << endl;
  }
}

Measured memory_bytes: 1160