akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>

int main()
{
    int n;
    double m, sum, sum_a;

    while (1) {
        sum = 0;
        sum_a = 0;
        scanf("%d", &n);
        if(n == 0) break;

        else {
            double score[n];
            for(int i = 0; i < n; i++){
                scanf("%lf", &score[i]);
                sum += score[i];
            }
            m = sum/n;
            for(int i = 0; i < n; i++){
                sum_a += (score[i] - m) * (score[i] - m);
            }
            printf("%lf\n", sqrt(sum_a/n));
        }
    }
    return 0;
}

Measured memory_bytes: 1092
#include<iostream>
#include<string>
#include<iostream>
#include<string>
using namespace std;
 
int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    string t1 = S.substr(0, N / 2);
    string t2 = S.substr(N / 2, N / 2);
    string res = (t1 == t2 && N > 1 && N % 2 ==0 )? "Yes":"No";
    cout << res << endl;
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main(void){
  int n=0;
  cin>>n;
  long long int ans=1;
  for(int i=1;i<=n;i++){
    ans*=i;
    ans%=mod;
  }
  cout<<ans<<endl;
  return 0;
}

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

int sumDigits(int n) {
    int sum = 0;
    for (int i = n; i > 0; i /= 10) {
        sum += i % 10;
    }
    return sum;
}

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

    int counter = 0;
    int ans = 9999999;

    for (int a = 1; a < n; a++) {
        int b = n - a;
        int x = sumDigits(a) + sumDigits(b);
        if (x < ans) ans = x;
    }

    cout << ans << endl;
}


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

dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)]
# 1-index

for i in range(n+1):
    for j in range(n-i+1):
        for k in range(n-i-j+1):
            ext = i + j + k
            if ext == 0:continue
            dp[i][j][k] = n/ext
            if i > 0:
                dp[i][j][k] += i/ext*dp[i-1][j+1][k]
            if j > 0:
                dp[i][j][k] += j/ext*dp[i][j-1][k+1]
            if k > 0:
                dp[i][j][k] += k/ext*dp[i][j][k-1]

a = list(map(int,input().split()))
q = [0,0,0,0]
for i in a:
    q[i] += 1

print(dp[q[3]][q[2]][q[1]])


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

public class Main {
	static class PriorityQueue {
		long[] heap = new long[2000000];
		int size = 0;
	}
	public static void main(String[]  args) {
		PriorityQueue s = new PriorityQueue();
		
		out:while (true) {
			next();
			switch (nextbuf[0]) {
				case 'i':
					insert(s, nextLong());
					break;
				case 'e':
					switch (nextbuf[1]) {
						case 'x':
							System.out.println(extractMax(s));
							break;
						case 'n':
							break out;
					}
					break;
			}
		}
	}

	static int parent(int i) {
		return (i  - 1) / 2;
	}

	static int left(int i) {
		return i * 2 + 1;
	}

	static int right(int i) {
		return left(i) + 1;
	}
	
	static void maxheapify(PriorityQueue s, int i) {
		int l = left(i);
		int r = right(i);
		int max = i;
		
		if (l < s.size && s.heap[l] > s.heap[max]) {
			max = l;
		}
		if (r < s.size && s.heap[r] > s.heap[max]) {
			max = r;
		}
		
		if (max != i) {
			long temp = s.heap[i];
			s.heap[i] = s.heap[max];
			s.heap[max] = temp;
			
			maxheapify(s, max);
		}
	}
	
	static void insert(PriorityQueue s, long k) {
		s.heap[s.size] = k;
		int i = s.size ++;
		
		while(i > 0 && s.heap[parent(i)] < s.heap[i]) {
			long tmp = s.heap[parent(i)];
			s.heap[parent(i)] = s.heap[i];
			s.heap[i] = tmp;
			
			i = parent(i);
		}
	}
	
	static long extractMax(PriorityQueue s) {
		long max = s.heap[0];
		
		s.heap[0] = s.heap[-- s.size];
		maxheapify(s, 0);
		
		return max;
	}
	
	private static byte[] buf = new byte[1 << 20];
	private static int len = 0;
	private static int ptr = 0;

	private static byte read() {
		if (ptr >= len) {
			try {
				len = System.in.read(buf);
			} catch (Exception e) {
			}
			ptr = 0;
		}

		return buf[ptr++];
	}

	private static long nextLong() {
		long num = 0;

		byte b = read();
		while(!Character.isDigit(b) && b != '-') b = read();
		int sign;
		if (b == '-') {
			sign = -1;
			b = read();
			if (!Character.isDigit(b)) return 0;
		} else {
			sign = 1;
		}

		while(Character.isDigit(b)) {
			num *= 10;
			num += sign * (b - '0');
			b = read();
		}

		return num;
	}

	private static byte[] nextbuf = new byte[11];
	private static int nextlen;

	private static void next() {
		nextlen = 0;

		byte b = read();
		while(!Character.isAlphabetic(b) && !Character.isDigit(b)) b = read();
		while(Character.isAlphabetic(b) || Character.isDigit(b)) {
			nextbuf[nextlen++] = b;
			b = read();
		}
	}
} 



Measured memory_bytes: 78836
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 26

int hight[MAX];
int depth[MAX];

struct Node {
	int parent;
	int lchild;
	int rchild;
};

Node tree[MAX];


void getDepth(int node, int dep)
{
	depth[node] = dep;

	if (tree[node].lchild != -1)
		getDepth(tree[node].lchild, dep + 1);

	if (tree[node].rchild != -1)
		getDepth(tree[node].rchild, dep+1);

}
int getHight(int node)
{
	int height_l=-1, height_r=-1;

	if (tree[node].lchild != -1)
		height_l = getHight(tree[node].lchild);

	if (tree[node].rchild != -1)
		height_r = getHight(tree[node].rchild);

	return hight[node] = max(height_l+1,height_r+1);
}
int getSibling(int node)
{
	if (tree[node].parent == -1)
		return -1;
	if (tree[tree[node].parent].lchild == node)
		return tree[tree[node].parent].rchild;
	else
		return tree[tree[node].parent].lchild;
}

void print(int node)
{
	cout << "node " << node << ": parent = " << tree[node].parent << ", sibling = ";

	cout << getSibling(node) << ", degree = ";
	if (tree[node].lchild != -1 && tree[node].rchild != -1)
		cout << 2 << ", ";
	else if (tree[node].lchild != -1 || tree[node].rchild != -1)
		cout << 1 << ", ";
	else
		cout << 0 << ", ";

	cout << "depth = " << depth[node] << ", ";
	cout << "height = " << hight[node] << ", ";
	if (tree[node].parent == -1)
		cout << "root" << endl;
	else if (tree[node].rchild == -1&&tree[node].lchild == -1)
		cout << "leaf" << endl;
	else
		cout << "internal node" << endl;

}
void preOrder(int nod)
{
	cout << ' ' << nod;
	if (tree[nod].lchild != -1)
		preOrder(tree[nod].lchild);
	if (tree[nod].rchild != -1)
		preOrder(tree[nod].rchild);
}
void inOrder(int nod)
{
	if (tree[nod].lchild != -1)
		inOrder(tree[nod].lchild);

	cout << ' ' << nod;

	if (tree[nod].rchild != -1)
		inOrder(tree[nod].rchild);
}
void postOrder(int nod)
{
	if (tree[nod].lchild != -1)
		postOrder(tree[nod].lchild);

	if (tree[nod].rchild != -1)
		postOrder(tree[nod].rchild);

	    cout << ' ' << nod;
}
int main()
{
	int n, root;
	int rchild, lchild;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		tree[i].lchild = -1;
		tree[i].parent = -1;
		tree[i].rchild = -1;
	}
	for (int i = 0; i < n; i++)
	{
		int node;
		cin >> node >>lchild >> rchild;

		tree[node].lchild = lchild;
		tree[node].rchild = rchild;

		if (lchild != -1)
			tree[lchild].parent = node;
		if (rchild != -1)
			tree[rchild].parent = node;
	}
	for (int i = 0; i < n; i++)                 //确定根节点
	{
		if (tree[i].parent == -1)
		{
			root = i;
			break;
		}
	}
	cout << "Preorder" << endl;
	preOrder(root);
	cout << endl;

	cout << "Inorder" << endl;
	inOrder(root);
	cout << endl;

	cout << "Postorder" << endl;
	postOrder(root);
	cout << endl;

	return 0;
}


Measured memory_bytes: 3088
import sys
# A,B,C = [int(n) for n in input().split()]
N = int(input())
# S = str(input())
# T = str(input())
# a,b,c = [int(n) for n in input().split()]
S = [0]*N
s = set()
for i in range(N):
    S[i] = str(input())
for i in range(N):
    if(S[i][0] == "i"):
        s.add(S[i][7:])
    elif(S[i][0] == "f"):
        if(S[i][5:] in s):
            print("yes")
        else:
            print("no")



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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if( (H == 0) && (W == 0))break;
        
        for (int i = 0; i < H; i++){
            for ( int j = 0; j < W; j++){
                cout << "#";
            }
            cout << "\n";
            
        }
        cout << endl;
        
    }
    return 0;
}


Measured memory_bytes: 3084
main :: IO ()
main = readLn >>= putStrLn . (lunlun !!) . subtract 1

lunlun :: [String]
lunlun = prettify . concat . iterate (concatMap next) $ map pure [1 .. 9]
  where
    prettify = map (concatMap show . reverse)
    next xs@(x : _) = (:) <$> filter (\ x -> 0 <= x && x <= 9) [x - 1 .. x + 1] <*> [xs]


Measured memory_bytes: 11772
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int n, k;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    int ans = 0;
    while (n) {
        ans++;
        n /= k;
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

struct Node{int parent,left,right;};
Node T[100001];
int D[100001];
void setDepth(int u,int p)
{
	D[u] = p;
	if(T[u].right != -1)
	{
		setDepth(T[u].right,p);
	}
	if(T[u].left != -1)
	{
		setDepth(T[u].left,p+1);
	}
}





int main()
{
	int n;
	cin >> n;
	for(int i = 0;i<n;i++)
	{
		T[i].left=T[i].right=T[i].parent = -1;
	}
	for(int i = 0;i<n;i++)
	{
		int now,roop;
		cin >> now >> roop;
		vector<int> next;
		for(int j = 0;j<roop;j++){int x;cin >> x;next.push_back(x);T[x].parent=now;}
		if(next.size())T[now].left = next[0];
		for(int i = 1;i<roop;i++)T[next[i-1]].right = next[i];
	}
	for(int i = 0;i<n;++i)
	{
		if(T[i].parent==-1)
		{
			setDepth(i,0);
			break;
		}
	}
	for(int i = 0;i<n;i++)
	{
		printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,D[i]);
		if(T[i].parent==-1)
		{
			cout<<"root, [";
			int c = T[i].left;
			while(c!=-1)
			{
				if(c!=T[i].left)cout<<", ";
				cout<<c;
				c = T[c].right;
			}
			cout<<"]\n";
		}
		else if(T[i].left==-1)
		{
			cout<<"leaf, []\n";
		}
		else
		{
			cout<<"internal node, [";
			int c = T[i].left;
			while(c!=-1)
			{
				if(c!=T[i].left)cout<<", ";
				cout<<c;
				c = T[c].right;
			}
			cout<<"]\n";
		}
	}

	return 0;
}


Measured memory_bytes: 8008
#include<stdio.h>
const int INF = 1001001001;
int dp[1010][1010];
int main(void){
    int n,m,C[1010],D[1010];
    int i,j,k;
    int ans;

    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
	scanf("%d",&D[i+1]);
    }
    for(j=0;j<m;j++){
	scanf("%d",&C[j+1]);
    }

/*
    for(i=1;i<=n;i++) printf("%d,%d\n",i,D[i]);
    for(j=1;j<=m;j++) printf("%d,%d\n",j,C[j]);
*/

    dp[0][0]=0;
    for(i=1;i<=n;i++){
	dp[i][0]=INF;
    }


    for(i=1;i<=n;i++){
	for(j=1;j<=m;j++){
	    if(dp[i-1][j-1]+D[i]*C[j] < dp[i][j-1]){
		dp[i][j]=dp[i-1][j-1]+D[i]*C[j];
	    }else{
		dp[i][j]=dp[i][j-1];
	    }

	    if(i>j||i-j>m-n) dp[i][j]=INF;

/*
	    printf("i=%d,j=%d\n",i,j);
	    printf("    %d\n",dp[i][j]);
*/

	}
    }

    ans=INF;
    for(j=1;j<=m;j++){
	if(dp[n][j]<ans) ans=dp[n][j];
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 3812
#include<stdio.h>
char show_sign(int m)
{
    if (m==0) return '+';
    else return '-';
}

int main()
{
    int a[8]={0},sign[8],i,j,result=0;
    int temp;
    scanf("%d",&temp);
    for (i=0;i<4;i++)
    {
        a[3-i]=temp%10;
        temp/=10;
    }
    for (i=0;i<8;i++)
    {
        sign[0]=i%2;
        sign[1]=(i/2)%2;
        sign[2]=(i/4)%2;
        result=a[0];
        for (j=0;j<3;j++)
        {
            if (sign[j]==0) result+=a[j+1];
            if (sign[j]==1) result-=a[j+1];
        }
        if (result==7){
            printf("%d%c%d%c%d%c%d=7\n",a[0],show_sign(sign[0]),a[1],show_sign(sign[1]),a[2],show_sign(sign[2]),a[3]);
            break;
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

vector<int> g[100005];
int q0[100005],q1[100005],q2[100005];
int c[100005];
bool v[100005][16];
int n,m,q;
queue<pair<int,int> > qq;

void bfs(int x, int d, int t){
	if(v[x][d])return;
	v[x][d]=true;
	qq.push(mp(x,d));
	while(!qq.empty()){
		x=qq.front().fst;d=qq.front().snd;qq.pop();
		if(!c[x])c[x]=t;
		if(!d)continue;
		for(int y:g[x])if(!v[y][d-1]){
			v[y][d-1]=true;qq.push(mp(y,d-1));
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	fore(i,0,m){
		int x,y;
		scanf("%d%d",&x,&y);x--;y--;
		g[x].pb(y);g[y].pb(x);
	}
	scanf("%d",&q);
	fore(i,0,q)scanf("%d%d%d",q0+i,q1+i,q2+i),q0[i]--;
	for(int i=q-1;i>=0;--i)bfs(q0[i],q1[i],q2[i]);
	fore(i,0,n)printf("%d\n",c[i]);
	return 0;
}

Measured memory_bytes: 10624
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d=0,e=0,f=0,nn=0;
	cin>>a>>b>>c;
	e=a+b+c;
	d=min(a,min(b,c));
	f=max(a,max(b,c));
	e-=d;
	e-=f;
	nn=e+d;
	cout<<nn<<endl;
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
l = list(set(S))
ans = 0
for i in range(len(l)):
    ans = max(S.count(l[i])-T.count(l[i]),ans)
print(ans)
    

Measured memory_bytes: 3060
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    x=  100;
    cin>>n;
    if(n<=100)
    {
        cout<<0<<endl;
        return 0;
    }
    for(i=1;;i++)
    {
        x = x+ (x*0.01);
        if(x>=n)
        {
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 3628
use std::cmp;
use std::io;


fn read_line() -> String {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line).unwrap();
    return String::from(line.trim());
}

fn main() {
    let n = read_line().parse::<i64>().unwrap();
    let values: Vec<i64> = read_line().split_whitespace().map(|v| v.parse::<i64>().unwrap()).collect();
    let min = values.iter().cloned().min().unwrap();
    let max = values.iter().cloned().max().unwrap();
    let min_index = values.iter().cloned().enumerate().filter(|&(_, v)| v == min).collect::<Vec<(usize, i64)>>()[0].0;
    let max_index = values.iter().cloned().enumerate().filter(|&(_, v)| v == max).collect::<Vec<(usize, i64)>>()[0].0;

    let p = |i0, i1| {println!("{} {}", i0 + 1, i1 + 1)};

    println!("{}", (values.len() - 1) * 2);
    if (0 < min) || (-min < max) {
        for i in (0..values.len()).filter(|i| *i != max_index) {
            p(max_index, i);
        }
        for i in 0..values.len() - 1 {
            p(i, i + 1);
        }
    } else {
        for i in (0..values.len()).filter(|i| *i != min_index) {
            p(min_index, i);
        }
        for i in (0..values.len() - 1).rev() {
            p(i + 1, i);
        }
    }
}

Measured memory_bytes: 4352
m=23,c=100,f[168],d[]={23,24,25,12,36,11,13,35,37,22,26,48},i,x,s;main(y){for(;s?++f[y*12+x+d[--s]]:~scanf("%d,%d,%d",&x,&y,&s)?s=s*4+1:++m<142?m%12<10?i=fmax(i,f[m]),f[m]?c--:1:1:!printf("%d\n%d\n",c,i););}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  if(A==B&&B!=C)
  {
    printf("Yes");
  }
  else if(B==C&&C!=A)
  {
    printf("Yes");
  }
  else if(C==A&&A!=B)
  {
    printf("Yes");
  }
  else 
  {
    printf("No");
  }
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

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


int main(void){
  vector<string > buf(8);
  rep(i,8){
    cin>>buf[i];
  }


  cout<<"90"<<endl;
  rep(i,8){
    rep(j,8){
      cout<<buf[7-j][i];
    }
    cout<<endl;
  }

  cout<<"180"<<endl;
  rep(i,8){
    rep(j,8){
      cout<<buf[7-i][7-j];
    }
    cout<<endl;
  }

  cout<<"270"<<endl;
  rep(i,8){
    rep(j,8){
      cout<<buf[j][7-i];
    }
    cout<<endl;
  }  
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
int K,n,a[200010];
int main(){
    cin>>K>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans=max(ans,(K+a[i]-a[(i-1+n)%n])%K);
    }
    cout<<K-ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main(){

    int m ,n;

	cin >> m >> n;

    int mpat, npat;

    if(m<2)
        mpat = 0;
    else
        mpat = m * (m-1) / 2;

    if(n<2)
        npat = 0;
    else
        npat = n * (n-1) / 2;

    
    cout << mpat + npat << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

auto readNum(T)(){
  return readln.chomp.to!T;
}

auto readNums(T)(){
  return readln.chomp.split.to!(T[]);
}

void main(){
  auto nm = readNums!int;
  int maxGate = nm[0]+1, minGate = 0;

  foreach(i; 0 .. nm[1]){
    auto g = readNums!int;
    minGate = max(minGate, g[0]);
    maxGate = min(maxGate, g[1]);
  }

  int ret = maxGate - minGate + 1;
  writeln(ret >= 0 ? ret : 0);
}


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

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

  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());

  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> A(N+1);
    A[0] = 0;
    for(int i=1; i<=N; i++){
        cin >> A[i];
        A[i]+=A[i-1];
        A[i]=A[i]%M;
    }
    map<int, int> mp;
    for(int i=0; i<=N; i++){
        mp[A[i]]++;
    }

    ll ans = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        ll cnt = itr->second;
        ans += cnt*(cnt-1)/2;
    }

    cout << ans << endl;
}

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

const int H = 10, W = 10000;
int state[H][W];
int cstate[H][W];

int main(){
	int lim, r, c, p, max, tmp, count;
	while(cin >> r >> c, r != 0, c != 0){
		lim = 1;
		max = p = 0;
		for(int i = 0;i < r;++i){
			lim *= 2;
		}
		for(int i = 0;i < r;++i){
			for(int j = 0;j < c;++j){
				cin >> state[i][j];
			}
		}
		while(p < lim){
			tmp = p;
			count = 0;
			int a, b;
			for(int i = 0;i < r;++i){
				for(int j = 0;j < c;++j){
					if(tmp % 2)	cstate[i][j] = 1 - state[i][j];
					else cstate[i][j] = state[i][j];
				}
				tmp /= 2;
			}
			for(int j = 0;j < c;++j){
				a = b = 0;
				for(int i = 0;i < r;++i){
					if(cstate[i][j]) ++a;
					else ++b;
				}
				if(b - a > 0) count += b;
				else count += a;
			}
			max = count > max ? count : max;
			p += 1;
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1940
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int n;
  int ln,ct;
  string s;
  while(cin>>n&&n){
    cin>>ln>>s;
    ct=0;
    for(i=0;i<ln-2;i=j+1){
      for(;i<ln-2&&s[i]!='I';i++);
      for(j=i;j<ln-2&&s[j+1]=='O'&&s[j+2]=='I';j+=2);
      if(j-i+1>=n*2+1)
	ct+=(j-i)/2-n+1;
    }
    cout<<ct<<endl;
  }    
  return 0;
}

Measured memory_bytes: 1904
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=1005;
int p[N][N];
int tmp[N];
int n,m,a,b;
void init()
{
	read(n); read(m); read(a); read(b);
}

void solve()
{
	for (int i=1;i<=b;++i)
	{
		for (int j=1;j<=a;++j)
		{
			p[i][j]=1;
		}
	}
	for (int i=b+1;i<=n;++i)
	{
		for (int j=a+1;j<=m;++j)
		{
			p[i][j]=1;
		}
	}
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=m;++j)
		{
			printf("%d",p[i][j]);
		}printf("\n");
	}
}

int main()
{
	init();
	solve();
	return 0;
}


Measured memory_bytes: 7696
from collections import Counter
n = int(raw_input())
a = [raw_input() for _ in range(n)]
c = Counter(a)
m = int(raw_input())
b = [raw_input() for _ in range(m)]
d = Counter(b)
i = 0
for k,ct in c.items():
    j = ct - d[k]
    i = max(i,j)
print i


Measured memory_bytes: 2936
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	int n, m, t=0;
	cin >> n >> m;
	for(int i=1; i<=n; i++)
	{
		for(int j=i+1; j<=n; j++)
		{
			t ++;	
		}	
	}
	for(int i=1; i<=m; i++)
	{
		for(int j=i+1; j<=m; j++)
		{
			t ++;	
		}	
	}
	cout << t;
	
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
int n;

struct Tree{
	vector<int> g[N];
	int deg[N];
	queue<int> q;
	inline void init(){
		for(int i=1;i<=n;i++)g[i].clear(), deg[i]=0;
	}
	inline void adde(int u,int v){
		g[u].push_back(v),deg[v]++;
	}
	inline bool solve(){
		int cnt=0;
		for(int i=1;i<=n;i++)if(!deg[i])q.push(i);
		while(!q.empty()){
			++cnt;int u=q.front();q.pop();
			for(size_t i=0;i<g[u].size();i++){
				int v=g[u][i];
				--deg[v];if(!deg[v])q.push(v);
			}
		}
		return cnt==n;
	}
}dag;

vector<int> g[2][N];
int fa[2][N];
int mp[2][N][N];
int flg;

inline int dfs2(int u){
	int tot=1;for(int v=1;v<=n;v++)if(fa[0][v]==u&&fa[1][v]==u){
		tot+=dfs2(v);
	}
	return tot;
}

inline void dfs(int p,int u,int pre){
	fa[p][u]=pre;
	for(size_t i=0;i<g[p][u].size();i++){
		int v=g[p][u][i];if(v==pre)continue;
		dfs(p,v,u);
	}
}

int vis[N],tsiz;
inline void check(int u){
	if(vis[u])return; tsiz++, vis[u]=1;
	for(size_t i=0;i<g[0][u].size();i++)check(g[0][u][i]);
}

inline int solve(int rt){
	
	
	for(int d=0;d<2;++d){
		for(int u=1;u<=n;u++){
			g[d][u].clear();
			for(int v=1;v<=n;v++)if(mp[d][u][v])g[d][u].push_back(v);
		}
	}
		tsiz=0;
		for(int i=1;i<=n;i++)vis[i]=0;
		check(1);
		if(tsiz<n)return 0;
	dfs(0,rt,0);
	dfs(1,rt,0);
	dag.init();
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(fa[0][i]!=fa[1][i]){
			if(fa[1][fa[1][i]]!=fa[0][fa[1][i]]) dag.adde(fa[1][i],i);
			if(fa[1][fa[0][i]]!=fa[0][fa[0][i]]) dag.adde(i, fa[0][i]);
		}
		else cnt++;
	}
	if(dfs2(rt)!=cnt)return 0;
	if(dag.solve()){
		flg=1;int cnt=0;
		for(int i=1;i<=n;++i)cnt+=fa[1][i]==fa[0][i];
		return cnt;
	}
	return 0;
}

int main()
{
	int T;cin >> T;
	while(T--){
		flg=0;
		scanf("%d",&n);
		for(int i=1,x,y;i<n;i++){scanf("%d%d",&x,&y);mp[0][x][y]=mp[0][y][x]=1;}
		for(int i=1,x,y;i<n;i++){scanf("%d%d",&x,&y);mp[1][x][y]=mp[1][y][x]=1;}
		int ans = solve(1);
		for(int u=1;u<=n;u++){
			int t=0;for(int v=1;v<=n;v++)t+=mp[0][u][v];
			if(t>1)continue;
			for(int v=1;v<=n;v++)if(mp[0][u][v]){
				for(int w=1;w<=n;w++)if(!mp[0][u][w]){
					
					mp[0][u][v]=mp[0][v][u]=0;
					mp[0][u][w]=mp[0][w][u]=1;
					
					ans = max(ans, solve(u)-1);
					mp[0][u][v]=mp[0][v][u]=1;
					mp[0][u][w]=mp[0][w][u]=0;
				}
			}
		}
		if(!flg){
			puts("-1");
		}
		else {
			printf("%d\n",n-ans);
		}
		for(int d=0;d<2;d++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					mp[d][i][j]=0;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	string S, T;
	cin >> S >> T;
	rep(i, S.size()) {
		if (S[i] != T[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

using namespace std;

const int maxn=2e5+10;

int head[maxn],num;
struct Le
{
	int nt,to;
}edge[maxn];
int a[maxn],n,du[maxn],rt;
void add(int f,int t) {
	edge[++num].nt=head[f];
	edge[num].to=t;
	head[f]=num;
}
int dfs(int u,int fa) {
	if(du[u]==1) return a[u];
	int sy=a[u]<<1;
	for(int i=head[u];i;i=edge[i].nt) {
		int v=edge[i].to;
		if(v==fa) continue ;
		int x=dfs(v,u);
		if(x>a[u]) {
			puts("NO");exit(0);
		} 
		sy-=x;
	}
	if(sy<0||sy>a[u]) {
		puts("NO");exit(0);
	}
	return sy;
} 

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n;++i) {
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
		du[u]++;du[v]++;
		if(du[u]>1) rt=u;
		if(du[v]>1) rt=v;
	}
	if(n==2) {
		if(a[1]==a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	if(dfs(rt,0)) puts("NO");
	else puts("YES");
	return 0;
}



Measured memory_bytes: 7680
def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
  
N = int(input())
a = N / 1.08
if is_integer_num(a) == True:
  print(int(a))
else:
  a = int(a)
  b = a+1
  
  n = int(a * 1.08)
  m = int(b * 1.08)
  
  if n == N:
    print(a)
  elif m == N:
    print(b)
  else:
    print(":(")

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;
ll LARGE = 1000000;


int main() {
	ll h, a;
	cin >> h >> a;
	cout << ceil(double(h) / double(a)) << endl;
}


Measured memory_bytes: 256
/*
Till the roof comes off, till the lights go out
Till my legs give out, can’t shut my mouth.
Till the smoke clears out. Am I high? Perhaps
I'ma rip this shit till my bones collapse.
*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#include <stack>
#include <complex>


#define f first
#define s second
#define ll long long
#define sz(v)      ((int)((v).size()))
#define X real()
#define Y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define len(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)

using namespace std;

typedef pair<int,ll>ii;
typedef pair<ii,int>node;
typedef complex<double>point;


const int N=200005;
const int M=101;
const double EPS = 1e-9;
const int INF =1e9;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
double getDist(point a,point b){return sqrt((a.X-b.X)*(a.X-b.X)+(a.Y-b.Y)*(a.Y-b.Y));}
int dcmp(double x, double y) {return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;}

ll mod=1000000007;
ll power(ll base,int p){
  if(!p)return 1;
  ll ret=power(base,p/2);
  ret*=ret;
  ret%=mod;
  if(p&1)ret*=base,ret%=mod;
  return ret;
}
ll modInverse(int a){
  return power(a,mod-2);
}

int n,dp[N][28];
string s;
int solve(int idx,int last){
  if(idx==n)return 0;
  if(dp[idx][last]!=-1)return dp[idx][last];
  int ret=n;
  if(s[idx]-'a'==last){
    for(int j=0;j<26;j++)
        ret=min(ret,solve(idx+1,j)+1);
  }
  else
    ret=solve(idx+1,last);

 return dp[idx][last]=ret;
}
string z="abcdefghijklmnopqrstuvwxyz";
void printo(int idx,int last,int cur){
  if(cur==0)return;
  if(s[idx]-'a'==last){
    for(int j=0;j<26;j++){
          if(1+solve(idx+1,j)==cur){
            cout<<z[j];
            printo(idx+1,j,cur-1);
            break;
          }
    }
  }
  else
    printo(idx+1,last,cur);

}
int main()
{
    //freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    cin>>s;
    n=s.length();
    memset(dp,-1,sizeof(dp));
    int a=n;
    for(int i=0;i<26;i++){
        a=min(a,solve(0,i)+1);
    }
    for(int i=0;i<26;i++){
        if(solve(0,i)+1==a){
            cout<<z[i];
            printo(0,i,a-1);
            break;
        }
    }
  return 0;
}

/*
100% reason to Remember THE NAME
*/


Measured memory_bytes: 34948
n=Hash.new{|h,k|h[k]=0}
gets.to_i.times do
  c = gets[0]
  next unless c==?M || c==?A || c==?R || c==?C || c==?H
  n[c]+=1
end
s=[]
n.each do |k,v|
  s << v
end
res=0
(0...n.size).to_a.combination(3) do |(a,b,c)|
  res += s[a]*s[b]*s[c]
end
p res


Measured memory_bytes: 4092
//include
//------------------------------------------
#include <bits/stdc++.h>
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> P;
typedef long long ll;
//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);
const long long INF = 1000000007;
//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;
// chmax chmin
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; }

int main(void){
    int H=2, W=3;
    char c[H][W]; REP(i,H)REP(j,W) cin >> c[i][j];
    if(c[0][0]==c[1][2] && c[0][1]==c[1][1] && c[1][0]==c[0][2]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	l =[ int(io()) for _ in range(5)]
	k=int(io())
	return ret((l[-1] - l[0]) <= k)

def ret(isOk):
	return 'Yay!' if isOk else ':('

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 3060
//God's Grace
#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <list>
#include <string>
#include <cmath>
#include <stack>
#include <cstdio>
#include <fstream>
#include <climits>
#include <set>
#include <vector>
#include <tuple>
#include <cstring>
#include <functional>
#include <utility>
#include <iomanip>

using namespace std;

#define endl '\n'
#define f(k,a,b) for(int k=(a);k<(b);k++)
#define vi vector <int>
#define vvi vector <vector <int> >
#define vii vector <pair <int, int > >
#define int long long
#define lli long long
#define pii pair <int,int>
#define piii pair< pair<lli,lli>, lli >
#define fsd fflush(stdout);
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//#define tdef typedef
#define ret return
const int fix = (int)1e9 + 7;

int po2(lli a){double temp = a;if(log2(temp)==(int)log2(temp))return log2(temp);return -1;}
void tc(int i){cout<<"Case #"<<i+1<<": ";}
void yes(){cout<<"YES"<<endl;}
void no(){cout<<"NO"<<endl;}
void impb(){cout<<"IMPOSSIBLE"<<endl;}
int ct(){int t;scanf("%lld",&t);return t;}
int gcd(int a, int b) {if (b == 0)return a;return gcd(b, a % b);}
int pwr(int a, int b){ int x=1, y=a; while(b>0){if(b%2) x = (x*y)%fix; y=(y*y)%fix; b/=2;} return x;}
void error(){cerr<<"Here!"<<endl;}

/*
lli modinv(lli a, lli m){
	lli m0 = m;
	lli y = 0, x = 1;

	    if (m == 1)
	      return 0;

	    while (a > 1)
	    {
	        // q is quotient
	       lli q = a / m;
	       lli t = m;

	        // m is remainder now, process same as
	        // Euclid's algo
	        m = a % m, a = t;
	        t = y;

	        // Update y and x
	        y = x - q * y;
	        x = t;
	    }

	    // Make x positive
	    if (x < 0)
	       x += m0;

	    return x;

}

*/

int pmodinv(int a){
	return pwr(a,fix-2);
}

//int arr[(int)5e5+5];
const int N = 5e5+5;
list <int> adj[N];
queue <int> q;

int comanc(int u, int v,int parent[]){
	while(u^v){
		if(u==1||v==1)
			return 1;
		u = parent[u];
		v = parent[v];
	}

	return u;
}
int x;

int max(int a, int b){
	if (a>b)
		return a;
	return b;
}

vector <int> factorial((int)4002);

int nCr(int n, int k){
	return (factorial[n]*((pmodinv(factorial[k])*pmodinv(factorial[n-k]))%fix))%fix;
}





int32_t main() {




	int t=1;
	//t=ct();


	f(ii,0,t){
		int n=ct();
		int k = ct();
		vi dp(n+1,INT_MAX);
		vi h(n+1);
		f(j,1,n+1)cin>>h[j];
		dp[1]=0;

		f(j,2,n+1){
			f(i,1,k+1){
				if(j-i>=1)
			dp[j] = min(dp[j], dp[j-i] + abs(h[j]-h[j-i]));
			}

		}

		printf("%lld\n",dp[n]);
	}
	ret 0;
}


Measured memory_bytes: 16708
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d", &n);
    int arr[105];
    for(int i=0;i<n;i++){
        scanf("%d", &arr[i]);
    }
    sort(&arr[0], &arr[n]);
    printf("%d", arr[n-1]-arr[0]);
}

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 3010;

int R, C, K;
V< V<> > item;

int dp[MAX_N][MAX_N][4];

int dfs(int i, int j, int state) {
    if(i >= R && j >= C) { return 0; }

    int& ret = dp[i][j][state];
    if(~ret) { return ret; }
    ret = 0;

    // 右に移動
    if(j < C - 1) {
        if(item[i][j + 1] > 0) {
            if(state < 3) {
                // アイテムがまだ取れる
                chmax(ret, dfs(i, j + 1, state + 1) + item[i][j + 1]);
            }
        }
        // とらない場合
        chmax(ret, dfs(i, j + 1, state));
    }

    // 下に移動
    if(i < R - 1) {
        if(item[i + 1][j] > 0) {
            // 取る
            chmax(ret, dfs(i + 1, j, 1) + item[i + 1][j]);
        }
        // とらない場合
        chmax(ret, dfs(i + 1, j, state));
    }

    return ret;
}

signed main() {
    IOS;

    cin >> R >> C >> K;
    item.assign(R, V<>(C, 0));
    REP(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        --r; --c;
        item[r][c] = v;
    }

    MINUS(dp);
    int ans = max(dfs(0, 0, 0), dfs(0, 0, 1) + item[0][0]);
    print(ans);

    return 0;
}


Measured memory_bytes: 357144
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] cup = new boolean[3];
		cup[0] = true;
		cup[1] = false;
		cup[2] = false;
		
		while(sc.hasNext()){
			String s = sc.next();
			String t = s.substring(0,1);
			String u = s.substring(2,3);
			int x=0;
			int y=0;
			if(t.compareTo("B")==0)x=1;
			if(t.compareTo("C")==0)x=2;
			if(u.compareTo("B")==0)y=1;
			if(u.compareTo("C")==0)y=2;
			
			boolean z = cup[x];
			cup[x] = cup[y];
			cup[y] = z;
		}

		if(cup[0]==true)System.out.println("A");
		if(cup[1]==true)System.out.println("B");
		if(cup[2]==true)System.out.println("C");
	}
}

Measured memory_bytes: 17124
use v5.26; # strict say state biwise
use warnings;
use List::Util qw(reduce any all none notall first max maxstr min minstr product sum sum0 pairs unpairs pairkeys pairvalues pairfirst pairgrep pairmap shuffle uniq uniqnum uniqstr);

chomp (my ($a, $b, $c, $d) = split / /, <STDIN>);
my $t = 0;
while ($a > 0 && $c > 0) {
  if ($t % 2 == 0) {
    $c -= $b;
  } else {
    $a -= $d;
  }
  $t++;
}
my $ans = ($a <= 0) ? "No" : "Yes";
say $ans;

Measured memory_bytes: 5376
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())
    ans = (N // K) ** 3

    if K % 2 == 0:
        k2 = K // 2
        ans += (1 + (N - k2) // K) ** 3
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>

#define FOR(i,n)	for(int i = 0 ; i < n ; i++)
#define FORrev(i,n)	for(int i = n - 1 ; i >= 0 ; i--)
#define ALL(a)		a.begin(),a.end()
#define pii			pair<int , int>
#define mp(a , b)	make_pair(a , b)


typedef long long int ll; 

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<pair<int , int> > a;
	FOR(i , n) {
		int t;
		cin>>t;
		a.push_back(mp(t , i + 1));
	}
	sort(ALL(a));
	FOR(i , n) {
		cout<<a[i].second<<" ";
	}
}

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

int main(){
  string s, t;
  cin >> s >> t;
  
  int sl = s.size(), tl = t.size();
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  bool ans = false;
  for(int i = 0; i < sl; i++){
    if(i + tl > sl) continue;
    string now = s.substr(i, tl);
    bool ok = true;
    for(int j = 0; j < tl; j++){
      if(now.at(j) == '?' || now.at(j) == t.at(j)) continue;
      ok = false;
    }
    if(ok){
      for(int j = 0; j < tl; j++) s.at(i+j) = t.at(j);
      ans = true;
      break;
    }
  }
  for(int i = 0; i < sl; i++){
    if(s.at(i) == '?') s.at(i) = 'a';
  }
  
  reverse(s.begin(), s.end());
  if(ans) cout << s << endl;
  else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=1e9+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,d,ans=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        double x,y,s=0;
        cin>>x>>y;
        x*=x;
        y*=y;
        s=sqrt(x+y);
        if(s<=d)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3872
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define CLOSEALL() fclose(stdin), fclose(stdout)
using namespace std;
typedef long long i64;
const int MAXN = 1e5 + 10;
const int MAXQ = 1e5 + 10;

int N, Q;

int monoTop;
i64 monoStk[MAXN], tmp[MAXN], ans[MAXN];

void solve(i64 query, i64 delta)
{
	int index = lower_bound(monoStk + 1, monoStk + monoTop + 1, query) - monoStk - 1;
	if(index <= 0)
		ans[1] += delta, ans[query + 1] -= delta;
	else
		tmp[index] += delta * (query / monoStk[index]),
		solve(query % monoStk[index], delta);
}

int main()
{
	//REDIRECT("seq");

	scanf("%d%d", &N, &Q);
	monoStk[++monoTop] = N;
	for(int i = 1; i <= Q; i++)
	{
		i64 t;
		scanf("%lld", &t);

		while(monoTop && t < monoStk[monoTop])
			monoTop--;
		monoStk[++monoTop] = t;
	}

	tmp[monoTop] = 1;
	for(int i = monoTop; i > 0; i--)
		solve(monoStk[i], tmp[i]);
	for(int i = 1; i <= N; i++)
		ans[i] += ans[i-1], printf("%lld\n", ans[i]);

	CLOSEALL();
	return 0;
}


Measured memory_bytes: 4096
def rec_cost(x,acc,plist,clist):
  if x == 1:
    return acc
  else:
    minimum = -1
    for next in plist:
      nextplist = plist.copy()
      nextplist.remove(next)
      candidate = rec_cost(next,acc+clist[x][next],nextplist,clist)
      if minimum == -1:
        minimum = candidate
      elif candidate < minimum:
        minimum = candidate
    return minimum
      

def cost(n,clist):
  plist = [0,1,2,3,4,5,6,7,8,9]
  plist.remove(n)
  return rec_cost(n,0,plist,clist)

def joisino(a,clist):
  note = [-1,0,-1,-1,-1,-1,-1,-1,-1,-1]
  answer = 0
  for raw in a:
    for number in raw:
      if number != -1:
        if note[number] == -1:
          note[number] = cost(number,clist)
        answer += note[number]
      
  return answer

def i_o():
  h, w = map(int,input().split(" "))
  i = 0 
  clist = []
  while i < 10:
    raw = list(map(int,input().split(" ")))
    clist.append(raw)
    i += 1
  a = []
  i = 1
  while i <= h:
    raw = list(map(int,input().split(" ")))
    a.append(raw)
    i += 1
  return h,w,clist,a

def fact(n):
  if n == 1:
    return 1
  else:
    return n * fact(n-1)
  
  
 
if __name__ == '__main__':
  h,w,clist,a = i_o()
  ans =joisino(a,clist)
  
  print(ans, flush=True)

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b) cout<<c<<endl;
    else if(a==c) cout<<b<<endl;
    else if(b==c) cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        self.S_arr = [ord(x) for x in S]

        self.POWER = [1] * (N + 1)
        self.HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            self.POWER[i + 1] = p = (p * BASE) % MOD
            self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = self.HASH[r] - (self.HASH[l] * self.POWER[r - l] % self.MOD)
        if _hash < 0:
            _hash += self.MOD
        return _hash

# 汎用的な二分探索のテンプレ
# check_func(x) = true となるxの最小値を探索する
# left : check_func(x) = falseとなるx
# right: check_func(x) = true となるx
# search_max: check_func(x) = true となるxの"最大値"を探索する場合はTrue
# check_func: answer <= x であればcheck_func(x) = true となるような関数
def binary_search(left: int, right: int, check_func, search_max:bool=False):
    # ok と ng のどちらが大きいかわからないことを考慮
    while abs(right - left) > 1:
        mid = (left + right) // 2
    
        if check_func(mid) ^ search_max:
            right = mid
            # print(left, right, mid, 't')
        else:
            left = mid
            # print(left, right, mid, 'f')

    return left if search_max else right

def main():
    N = int(input())
    S = input()

    rs = RollingHash(S, MOD=998244353, BASE=37)

    # 長さLの部分文字列同士が、範囲を重ねず同じ文字列となる場合はTrue,
    # そうでない場合はFalseを返す関数
    def isOK(L):
        if L == 0:
            return True
        hash_to_left = defaultdict(list)
        for i in range(N - L + 1):
            _hash = rs.hash(i, i + L)
            # hashが衝突しても文字列が完全に一致するか分からないので、
            # 衝突した場合は文字列が完全に一致するか調べ、かつ
            # 文字列同士がSの中で重なるような範囲にない場合はOKとする
            for j in hash_to_left[_hash]:
                if j+L <= i and S[i:i+L] == S[j:j+L]:
                    return True
            hash_to_left[_hash].append(i)

        return False
    # 範囲が重ならないことが条件にあるので、答えは最大でもN // 2（文字列の長さの半分）となる。
    # ただし、二分探索する上で絶対に答えとならない範囲を含めたいので、
    # 探索範囲としてはN // 2 + 1 と、+1しておく。
    ans = binary_search(0, N // 2 + 1, isOK, search_max=True)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b; cin>>x>>a>>b;
  if(a>=b){
    cout<<"delicious"<<endl;
  }else if(b-a>x){
    cout<<"dangerous"<<endl;
  }else{
    cout<<"safe"<<endl;
  }
}


Measured memory_bytes: 384