akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::min;
using std::max;
using std::vector;
using std::string;

using llint = long long int;

int main()
{

	
	int H,W;
	
	cin >> H >> W;

	
	vector<int> S(H * W);
	vector<int> E(H * W * H * W);

	auto over = [&](int i,int j)->bool{
		return i < 0 || H <= i || j < 0 || W <= j;
	};

	auto gs = [&](int i,int j)->auto&{
		return S[i*W + j];
	};
	auto ge = [&](int i,int j, int m,int n)->auto&{
		return E[i* W * W * H + j * W * H + m * W + n];
	};
	for (auto& a:E)a = 1000;

	for (size_t i =0 ; i < H;i++){
		for (size_t j =0 ; j < W;j++){
			char c;
			cin >> c;
			if(c == '.')gs(i,j) = 1;
			else gs(i,j) = 0;
		}
	}

	for (size_t i =0 ; i < H;i++){
		for (size_t j =0 ; j < W;j++){
			if(gs(i,j)){
				ge(i,j,i,j) = 0;
				if(!over(i+1,j))if(gs(i+1,j)){
					ge(i,j,i+1,j) = 1;
					ge(i+1,j,i,j) = 1;
				}
				if(!over(i,j+1))if(gs(i,j+1)){
					ge(i,j,i,j + 1) = 1;
					ge(i,j + 1,i,j) = 1;
				}
			}
		}
	}

	bool changed = true;

	while (changed){
	changed = false;

		for (size_t i =0 ; i < H;i++){
			for (size_t j = 0 ; j < W;j++){
				for (size_t n = 0; n < H;n++){
					for (size_t m = 0; m < W;m++){
						for (size_t o = 0; o < H;o++){
							for (size_t p = 0; p < W;p++){
									if(ge(i,j,n,m) > ge(i,j,o,p) + ge(o,p,n,m)){
									ge(i,j,n,m) = ge(i,j,o,p) + ge(o,p,n,m);
									changed = true;
								}
							}
						}
					}
				}
			}
		}
	}

	int a = 0;
	for (auto d : E){
		if(d < 1000){
			a = max(a,d);
		}
	}

	cout << a << endl;


	return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = 0, cnt = 0;
	rep(i,s.size()){
		if(s[i] == 'T'){
			if(cnt > 0) --cnt;
			else ++ans;
		}
		else{
			++cnt;
		}
	}
	ans += cnt;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3692
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

k=II()
x,y=MI()

# Kが偶数で、ゴールまでのマンハッタン距離が奇数だと不可能
if k%2==0 and (x+y)%2:
    print(-1)
    exit()

# x>=0,y>=0,x<=yに修正して解き、最後に復元
cx=-1 if x<0 else 1
cy=-1 if y<0 else 1
x,y=abs(x),abs(y)
swap=False
if x>y:
    swap=True
    x,y=y,x

ans=[]
if (x+y)%2 and x+y<k:
    ans.append((x,y))
    y+=k
l=(x+y+k-1)//k*k
if (l-x-y)%2:l+=k
d=(l-x-y)//2
if d>0 and d+y<k:d+=k//2

if d:
    ans.append((x,y))
    x+=d
    y-=k-d

while y-k>=0:
    ans.append((x, y))
    y-=k

if y:
    ans.append((x,y))
    x-=k-y
    y=0

while x>0:
    ans.append((x, y))
    x-=k

print(len(ans))
for x,y in ans[::-1]:
    if swap:x,y=y,x
    print(cx*x,cy*y)


Measured memory_bytes: 31320
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)

x_arr = []

x_arr << a_arr.map.with_index do |a, i|
  if i % 2 == 0 then
    a
  else
    a * (-1)
  end
end.inject(:+) / 2

a_arr.each_with_index do |a, i|
  x_arr << a - x_arr[i]
end

puts x_arr[0..-2].map{|x| (x * 2).to_s }.join(" ")


Measured memory_bytes: 18564
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        s: chars
    }
    println!("{}", s.iter().fold(0, |acc, &c| acc + if c == '+' { 1 } else { -1 }));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5+5, M=1e5+5, oo=0x3f3f3f3f, mod = 1e9+7;

int n, m, u, v, in[N], mxpath[N], mx;
vector<int>g[N];
int solve(){
    queue<int>q;
    for(int i=1; i<=n; i++){
        if(in[i] == 0){
            q.push(i);
        }
    }
    while(q.size()){
        int node = q.front();
        int y = mxpath[node];
        q.pop();
        for(auto i: g[node]){
            mxpath[i] = max(mxpath[i], y + 1);
            mx = max(mx, mxpath[i]);
            in[i]--;
            if(!in[i])
                q.push(i);
        }
    }

    return mx;
}

int main()
{
    _69e27
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> u >> v;
        g[u].push_back(v);
        in[v]++;
    }
    cout << solve();
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;


     signed main(){
          cout << std::fixed << std::setprecision(15);
int n,m;
cin>>n>>m;
cout<<n*m<<endl;









 }

 


 






    





      

        


Measured memory_bytes: 3608
#include<stdio.h>
#include<math.h>
#include<string>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<fstream>  // 文件读取  ifstream ofstream
#include<algorithm>  
#include<vector>
using namespace std;


int n;

struct List{
	int node;
	List *next;
};

int main()  
{  


	cin>>n;
	List *L;
	L = new List;
	List *end = new List;
	end = L;
	for(int i =0;i<n;i++){
		int temp;
		cin>>temp;
		List *t = new List;
		t->node = temp;
		if(i%2==0){
			end->next = t;
			end = end->next;
		}else{
			t->next = L->next;
			L->next  = t;
		}
	}

	vector<int>sq;

	L=L->next;
	int index = 0;
	while(index<n){
		sq.push_back(L->node);
		L=L->next;
		index++;
	}

	if(n%2==0){
		for(int i = 0;i<sq.size();i++)
			cout<<sq[i]<<" ";
	}else{
		for(int i = sq.size()-1;i>=0;i--)
			cout<<sq[i]<<" ";
	}


	return 0;


} 




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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll L, R;
    cin >> L >> R;

    ll ans = inf;
    FOR(i, L, R){
        if(i%2019==0){
            p(0);
            return 0;
        }
        FOR(j, L+1, R+1){
            if(j%2019==0){
                p(0);
                return 0;
            }
            ll a = (i*j)%2019;
            chmin(ans, a);
        }
    }    
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]

nm=N-M+1
for i in range(nm):
    for j in range(nm):
        flag=[0]*M
        for k in range(M):
            a=A[i+k][j:j+M]
            b=B[k]
            if a==b: flag[k]=1
            else: flag[k]=0
        if sum(flag)==M:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
t = list(input())
t.append("null")

if t[0] == "?":
    if t[1] == "D":
        t[0] = "P"
    elif t[1] == "P":
        t[0] = "D"
    else:
        t[0] = "D"

for i in range(1, len(t)-1):
    if t[i] == "?":
        if t[i-1] == "P":
            t[i] = "D"
        elif t[i+1] == "D":
            t[i] = "P"
        else:
            t[i] = "D"

t.remove("null")
print("".join(t))

Measured memory_bytes: 10920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin>>S;
  if(S=="abc"||S=="acb"||S=="bac"||S=="bca"||S=="cab"||S=="cba"){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	
	string S, T;
	cin >> S >> T;

	int s[100], t[100];
	rep(i, S.size()) {
		s[i] = S[i];
	}
	rep(i, T.size()) {
		t[i] = T[i];
	}
	sort(s, s + S.size());
	sort(t, t + T.size(), std::greater<int>());
	rep(i, S.size()) {
		S[i] = s[i];
	}
	rep(i, T.size()) {
		T[i] = t[i];
	}
	if (S < T) co("Yes");
	else co("No");

	Would you please return 0;
}

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

#define NMAX 100005
using namespace std;

long long dp[105][NMAX], val[NMAX], w[NMAX];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, g;
    cin >> n >> g;

    for(int i = 1; i <= n; ++i)
        cin >> w[i] >> val[i];

    for(int i = 1; i <= n; ++i)
        for(int j = 0; j <= g; ++j)
            if(w[i] <= j)
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + val[i]);
            else dp[i][j] = dp[i - 1][j];

    long long maxx = 0;
    for(int j = 0; j <= g; ++j)
        maxx = max(maxx, dp[n][j]);
    cout << maxx << '\n';
    return 0;
}


Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n!=0){
    int a,b,c;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      if(a==100||b==100||c==100||(a+b)/2>=90||(a+b+c)/3>=80){
	cout<<'A'<<endl;
      }else if((a+b+c)/3>=70||((a+b+c)/3>=50&&(a>=80||b>=80))){
	cout<<'B'<<endl;
      }else{
	cout<<'C'<<endl;
      }	
    }
    cin>>n;
  }
  return 0;
}



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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

i64 sum_a[100005]={0}, sum_c[100005]={0};
i64 sum_qf[100005]={0}, sum_qb[100005]={0};

i64 repeated_squaring(i64 x, i64 n) {
    i64 res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    string s;
    cin >> s;
    for(int i=1;i<=(int)s.size();++i){
        sum_a[i] = sum_a[i-1];
        if(s[i-1] == 'A')sum_a[i]++;
        sum_qf[i] = sum_qf[i-1];
        if(s[i-1] == '?')sum_qf[i]++;
    }
    for(int i=(int)s.size();i>0;--i){
        sum_c[i] = sum_c[i+1];
        if(s[i-1] == 'C')sum_c[i]++;
        sum_qb[i] = sum_qb[i+1];
        if(s[i-1] == '?')sum_qb[i]++;
    }

    i64 ans = 0;
    for(int i=1;i<=(int)s.size();++i){
        if(s[i-1] != 'B' && s[i-1] != '?')continue;
        i64 ca = sum_a[i-1] * repeated_squaring(3, sum_qf[i-1]) % MOD;
        ca += sum_qf[i-1] * repeated_squaring(3, sum_qf[i-1]-1) % MOD;
        ca %= MOD;

        i64 cc = sum_c[i+1] * repeated_squaring(3, sum_qb[i+1]) % MOD;
        cc += sum_qb[i+1] * repeated_squaring(3, sum_qb[i+1]-1) % MOD;
        cc %= MOD;
        i64 tmp = ca * cc % MOD;
        ans = (ans + tmp) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring> 
using namespace std;
int main()
{
	int n,k,a[100];
	while(cin>>n)
	{
		int i,s=1,sum=0;
		cin>>k;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		    if(a[i]<k-a[i])s=2*a[i];
		    else s=2*(k-a[i]);
		    sum+=s;
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[list(input()) for _ in range(2)]
    ans=1
    i=0
    while(i<n):
        # 縦に置かれているとき
        if(A[0][i]==A[1][i]):
            if(i==0): ans*=3
            elif(A[0][i-1]==A[1][i-1]): ans*=2
            else: pass
            i+=1
        # 横に置かれているとき
        else:
            if(i==0): ans*=6
            elif(A[0][i-1]==A[1][i-1]): ans*=2
            else: ans*=3
            i+=2

    print(ans%MOD)
resolve()

Measured memory_bytes: 38256
#include "bits/stdc++.h"

using namespace std;

int main(){
	int c[3][3], a[3], b[3];

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}

	a[0] = 0;
	for (int i = 0; i < 3; i++){
		b[i] = c[0][i] - a[0];
		a[i] = c[i][0] - b[0];
	}

	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			if (a[i] + b[j] != c[i][j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif 

using namespace std;

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

	vector<int> a(10);
	for(int i = 0; i < 10; i++){
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.rbegin(), a.rend());
	for(int i = 0; i < 3; i++)cout << a[i] << '\n';
	return 0;
}
// Write Here



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

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


Measured memory_bytes: 256
R,C,K = map(int,input().split())
mat = {}
for _ in range(K):
  r,c,v = map(int,input().split())
  mat[(r,c)] = v

# dp[i][j][k] = i,jまでで、i列のものをk個取ったときのスコア
dp0 = [[0] * (C+1) for _ in range(R+1) ]
dp1 = [[0] * (C+1) for _ in range(R+1) ]
dp2 = [[0] * (C+1) for _ in range(R+1) ]
dp3 = [[0] * (C+1) for _ in range(R+1) ]

for i in range(1,R+1):
  for j in range(1,C+1):
    if (i,j) in mat:
      m = mat[(i,j)]
      # 左からの遷移
      dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
      dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
      dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
    else:
      dp1[i][j] = dp1[i][j-1]
      dp2[i][j] = dp2[i][j-1]
      dp3[i][j] = dp3[i][j-1]

    # 上からの遷移
    x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
    dp0[i][j] = max(dp0[i][j-1], x)
    if (i,j) in mat:
      m = mat[(i,j)]
      dp1[i][j] = max(dp1[i][j], x+m)
    else:
      dp1[i][j] = max(dp1[i][j], x)

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))

Measured memory_bytes: 379176
H,W=map(int, input().split())
a=10**10
S=H*W
s=[None]*3
for i in range(W):
    s[0]=H*i
    s[1]=(W-i)//2*H
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
    s[1]=H//2*(W-i)
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
for i in range(H):
    s[0]=W*i
    s[1]=(H-i)//2*W
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
    s[1]=W//2*(H-i)
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FASTIO \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr);



ll get_max_happy_bu(ll n) {
    ll a, b, c;

    ll dp[n][3];

    for (int i = 0; i < n; i++) {
        cin>>a>>b>>c;
        if(i == 0) {
            dp[i][0] = a;
            dp[i][1] = b;
            dp[i][2] = c;
        }
        else {
            dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
            dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
            dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
        }
    }

     
    return max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]);
    
}

void solve() {
    ll n;
    cin>>n;

    cout<<get_max_happy_bu(n)<<"\n";
}

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

Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int red = 0;
    int blue = 0;
    rep(i,n) {
        if (s[i] == 'R') red++;
        else blue++;
    }
    string ans = "No";
    if (red > blue) ans = "Yes";
    cout << ans << endl;
}

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

using namespace std;


int main()
{   
    long long A, B, C, K;
   
    cin >> A >> B >> C >> K;
    
    if(A>=K){
        cout << K << endl;
    }else if(B>=(K-A)){
        cout << A << endl;
    }else{
        cout << A - (K-A-B) << endl;
    }
        
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll inf = 100000000;
typedef pair<ll, ll> P;
int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (a == b) {
		cout << "1" << endl;
		return 0;
	}
	ll sum = (n - 2) * b - (n - 2) * a;
	if (sum < 0) {
		cout << "0" << endl;
		return 0;
	}
	cout << sum+1 << endl;
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

for i in range(m):
    r,l = map(int,input().split())
    if i==0:
        x = r
        y = l
    else:
        if r>x:
            x = r
        if l<y:
            y = l

if y>=x:
    print(y-x+1)
else:
    print(0)

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
long long a, b, c, d;
int main() {
	while (cin >> a >> b >> c >> d, a) {
		long long r = 119 * a - 1;
		for (int i = 0; ; i++) {
			long long cp = (d * r + i) * 60 * a, cq = 3600 * a * r;
			long long bp = (c * 60 * r + cp / (60 * a)) * a, bq = 3600 * a * r;
			long long ap = b * 3600 * r + bp / a, aq = 3600 * a * r;
			ap %= aq; bp %= bq; cp %= cq;
			while (cp < ap) cp += cq;
			while (bp < cp) bp += bq;
			if (ap == bp) continue;
			if (cp - ap == bp - cp) {
				long long cr = d * r + i, br = c, ar = b;
				br += cr / (60 * r); cr %= 60 * r;
				ar += br / 60; br %= 60;
				ar %= a;
				long long f = gcd(cr, r);
				cr /= f; r /= f;
				cout << ar << ' ' << br << ' ' << cr << ' ' << r << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;

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

    for (int i = 0; i < n; ++i) {
        char s;
        cin >> s;
        if (s == 'Y') {
            cout << "Four" << endl;
            exit(EXIT_SUCCESS);
        }
    }

    cout << "Three" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  string s;
  cin >> s;

  if (s == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << '\n';
    return 0;
  }
  if (s.length() != 26) {
    vector<bool> used(26, false);
    rep(i, s.length()) used[s[i] - 'a'] = true;
    rep(i, 26) {
      if (!used[i]) {
        char c = 'a' + i;
        cout << s << c << '\n';
        return 0;
      }
    }
  }
  vector<bool> used(26, false);
  char res = 'a';
  repr(i, 25) {
    if (s[i] < res) {
      FOR(j, s[i] - 'a', 26) {
        if (used[j]) {
          char c = 'a' + j;
          cout << s.substr(0, i) << c << '\n';
          return 0;
        }
      }
    }
    res = s[i];
    used[s[i] - 'a'] = true;
  }





  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    vector<vector<int>> a(h, vector<int>(w));
    vector<vector<int>> b(h, vector<int>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            scanf("%d", &b[i][j]);
        }
    }
    
    using boolean = int;
    vector<vector<vector<boolean>>> dp(h, vector<vector<boolean>>(w, vector<boolean>(80 * (h + w) + 1)));
    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < 80 * (h + w - 1) + 1; k++){
                if(!dp[i][j][k]) continue;
                if(i < h - 1){
                    ll d = abs(a[i + 1][j] - b[i + 1][j]);
                    dp[i + 1][j][abs(k + d)] = dp[i + 1][j][abs(k - d)] = true;
                }
                if(j < w - 1){
                    ll d = abs(a[i][j + 1] - b[i][j + 1]);
                    dp[i][j + 1][abs(k + d)] = dp[i][j + 1][abs(k - d)] = true;
                }
            }
        }
    }
    
    for(int k = 0; k < 80 * (h + w); k++){
        if(dp[h - 1][w - 1][k]){
            printf("%d\n", k);
            return 0;
        }
    }
}

Measured memory_bytes: 324608
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i64 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = n - 1;
    for a in 2..n {
        if a * a > n {
            break;
        }
        if n % a == 0 {
            ans = min(ans, (n / a - 1) + (a - 1));
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		double b = scan.nextDouble();
		long ib = (long)(b*100+0.5);
		System.out.print((a*ib)/100);
	}
}


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

vector<vector<pair<int,int>>> G;
vector<int> ans;
int mx = -1;

void dfs(int t,int c, int prv){
    int color_now = 1;
    for(int i = 0; i<G[t].size();++i){
        if(color_now == c) ++color_now;
        int e = G[t][i].first;
        if(e == prv) continue;
        ans[G[t][i].second] = color_now;
        mx = max(mx,color_now);
        dfs(e,color_now,t);
        ++color_now;
    }
}

int main() {
    int N;
    cin >> N;
    G.resize(N);
    ans.resize(N-1,-1);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        G[a].push_back({b,i});
        G[b].push_back({a,i});
    }
    dfs(0,0,-1);
    cout << mx << endl;
    for(auto e:ans) cout << e << endl;
}

Measured memory_bytes: 8320
import sys
input = sys.stdin.readline
n=int(input())

a=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==a[i]:
            cnt[i]+=1
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)


Measured memory_bytes: 3064
//https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_a
//A - CF
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    string s; cin>>s;
    bool cf=false,ff=false;
    bool ans=false;
    REP(i,s.size()){
        if(cf){
            if(s.at(i)=='F'){
                ans=true;
            }
        }else{
            if(s.at(i)=='C') cf=true;
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main(){
    int h,w;
    string oneline;
    cin >> h >> w;
    int map[50][50];
    int a=0;
    while(cin >> oneline ){
        for(int i=0;i<w;i++){
            if(oneline[i]=='#'){
                map[i][a]=1;
            }else{
                map[i][a]=0;
            }
        }
        a++;
    }
    bool flag=true;
    for(int i=0;i<w && flag;i++){
        for(int j=0;j<h && flag;j++){
//            cout << map[i][j] << " ";
            int isok=0;
            flag=false;
            if (j<h-1){
                isok+=map[i][j+1];
            }
            if (i<w-1){
                isok+=map[i+1][j];
            }
            if (j>0){
                isok+=map[i][j-1];
            }
            if (i>0){
                isok+=map[i-1][j];
            }
            isok=min(2,isok*map[i][j]+map[i][j]);
            if (isok!=1){
                flag=true;
            }
        }
//        cout <<endl;
    }
    if (flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

long long n,k,ans,ans1;

int main()
{
	cin>>n>>k;
	if(k&1)
	{
		ans=n/k;
		printf("%lld\n",ans*ans*ans);
	}
	else
	{
		ans1=(n+k/2)/k;
		ans=n/k;
		printf("%lld\n",ans*ans*ans+ans1*ans1*ans1);
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
    int x,y,a,b,c;

    vector<ll> apple;
    vector<ll> r_app;
    vector<ll> g_app;
    vector<ll> app;

    cin >> x >> y >> a >> b >> c;
    for(int i=0;i<a;i++){
        ll p;
        cin >> p;
        r_app.push_back(p);
    }
    for(int i=0;i<b;i++){
        ll p;
        cin >> p;
        g_app.push_back(p);
    }
    for(int i=0;i<c;i++){
        ll p;
        cin >> p;
        app.push_back(p);
    }
    sort(r_app.begin(),r_app.end());
    sort(g_app.begin(),g_app.end());
    
    for(int i=0;i<x;i++){
        app.push_back(r_app[a-i-1]);
    }
    for(int i=0;i<y;i++){
        app.push_back(g_app[b-i-1]);
    }

    sort(app.begin(),app.end());
    ll ans=0;
    for(int i=0;i<x+y;i++){
        ans += app[x+y+c-i-1];
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 7792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,s=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x==y)
		{
			s++;
			if(s==3)
			{
				puts("Yes");
				return 0;
			}
		}
		else
			s=0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=5e5+5;
ll inf=1e15;

ll ar[sz],vis[sz],nxt[sz];
vector<int> tree[4*sz];

void build(int st,int en,int no)
{
    if(st==en)
    {
        tree[no].push_back(nxt[st]);
        return;
    }
    int mid=(st+en)/2;
    build(st,mid,2*no+1);
    build(mid+1,en,2*no+2);
    merge(tree[2*no+1].begin(),tree[2*no+1].end(),tree[2*no+2].begin(),tree[2*no+2].end(),back_inserter(tree[no]));
}

int query(int st,int en,int no,int l,int r,int k)
{
    if(l>r or st>en or en<l or st>r)
        return 0;
    if(l<=st and r>=en)
    {
        return tree[no].size()-(upper_bound(tree[no].begin(),tree[no].end(),k)-tree[no].begin());
    }
    int mid=(st+en)/2;
    return query(st,mid,2*no+1,l,r,k)+query(mid+1,en,2*no+2,l,r,k);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n,q;
        cin>>n>>q;
        for(int i=1;i<=n;i++)
        {
            cin>>ar[i];
            nxt[i]=n+1;
        }
        for(int i=n;i>=1;i--)
        {
            if(vis[ar[i]]!=0)
            {
                nxt[i]=vis[ar[i]];
            }
            vis[ar[i]]=i;

            // cout<<nxt[i]<<" ";

        }

        build(1,n,0);

        while(q--)
        {
            int l,r;
            cin>>l>>r;
            cout<<query(1,n,0,l,r,r)<<endl;
        }

    }

    return 0;
}

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

using namespace std;

const int maxn = 105;

int c[maxn][maxn];
int n, m;

void add(int &x, int &y) {

    if (m == 1) {x ++; return;}

    if (y == 0) {
        if (c[x][y + 1]) x ++;
        else y ++;
    }
    else if (y == m - 1) {
        if (c[x][y - 1]) x ++;
        else y --;
    }
    else {
        if (c[x][y + 1]) y --;
        else y ++;
    }
}

int main(int argc, char const *argv[]) {

    cin >> n >> m;
    int k; cin >> k;
    
    memset(c, 0, sizeof(c));
    int tx = 0, ty = 0;
    for (int cc = 1; cc <= k; cc ++) {
        int x; scanf("%d", &x);
        while (x --) {
            c[tx][ty] = cc;
            add(tx, ty);
        }
    }

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

Measured memory_bytes: 384
from functools import reduce

s = list(map(int, list(input())))
max_len = len(s) - 1
li = []
for bit in range(1 << max_len):
    tmp = s[0]
    for n in range(max_len):
        if (bit & 1 << n) != 0:
            li.append(tmp)
            tmp = 0
        else:
            tmp *= 10
        tmp += s[n + 1]
    li.append(tmp)
print(reduce(lambda x, y: x + y, li))

Measured memory_bytes: 39536
/* 
 * Project: AtCoder Beginners Contest 166 A - A?C
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/05/03∫
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;

string s;
int a, b;

void solve() {

    if (s == "ABC")
        printf("ARC\n");
    else
        printf("ABC\n");
}

int main() {

    cin >> s;

    solve();

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
const int MAX = 710000;
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool is_integer( double x ){
  return floor(x)==x;
}

int main(){
    double x, y, i, j, mi=0;
    ll ans=1;
    cin >> x >> y;
    i = (-1*x+2*y)/3;
    j = (x-i)/2;
    if(is_integer(i) && is_integer(j)){
        mi = min(i, j);
        COMinit();
        cout << COM(i+j, i) << endl; 
    }
    else {
        cout << 0;
    }
}  


Measured memory_bytes: 16896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        int answer = 0;

        for (int i = 0; i < n; i++)
        {
            int num = sc.NextInt();
            while (num % 2 == 0)
            {
                answer++;
                num = num / 2;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int main() {
  string s;
  long unsigned int k;
  cin >> k >> s;
  if(s.length() > k) {
    cout << s.substr(0, k) << "..." << endl;
  } else {
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_by_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	string s;
	cin>>s;
	int ac = 0, bc = 0;
	for(auto u : s)
	{
		if(u == 'A')
		ac++;
		else bc++;	
	}
	if((ac == 3) || (bc == 3))
	cout<<"No\n";
	else cout<<"Yes\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	char n[201],N[201],copy[201];
	int i,k,j,h,m,len;
	while(1){
		scanf("%s",n);
		if(strcmp(n,"-")==0)break;
		scanf("%d",&m);
		len=strlen(n);
		for(i=0;i<m;i++){
			strcpy(N,n);
			scanf("%d",&h);
			(int)N>>len-h;
			strcpy(copy,N);
			for(k=0;k<len-h;k++){
				n[k]=n[k+h];
			}
			j=0;
			for(k=len-h;k<len;k++){
				n[k]=copy[j];
				j++;
			}
		}
		printf("%s\n",n);
	}
	return 0;
}


Measured memory_bytes: 1816
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

double dist(int x[],int y[],int n,int p){
  long long sum = 0;
  for(int i=0;i<n;i++){
    sum += pow(abs(x[i] - y[i]),p);
  }
  return pow(sum,1.0/(double)p);
}

int main(){
  int n;
  cin>>n;
  int x[n],y[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin>>y[i];
  }

  printf("%.10lf\n",dist(x,y,n,1));
  printf("%.10lf\n",dist(x,y,n,2));
  printf("%.10lf\n",dist(x,y,n,3));
  double max = -1.0;
  for(int i=0;i<n;i++){
    int tmp = abs(x[i] - y[i]);
    if(max<tmp) max=tmp;
  }
  printf("%.10lf\n",max);

  return 0;
}

Measured memory_bytes: 3336
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[int(input())-1])

Measured memory_bytes: 3060
//============================================================================
// Name        : aoj0047.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdio>

using namespace std;

int main(void){
	int a[3] = {1,0,0};
	char str[4];
	while(scanf("%s",str) != EOF){
		int tmp = a[str[0] - 'A'];
		a[str[0] - 'A'] = a[str[2] - 'A'];
		a[str[2] - 'A'] = tmp;
	}
	for(int i = 0;i < 3;i++){
		if(a[i] == 1){
			printf("%c\n",'A' + i);
		}
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  sort(S.begin(), S.end());

  for(int i = 0; i < S.size()-1; i++){
    if (S.at(i) == S.at(i+1)){
      cout << "no" << endl;
      return 0;
    }
  }
    
  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

typedef unsigned long long ull;

int N, K;
int P[101];
int dp[101][4][4];

int solve(int i, int j, int k);

int main(void){
	scanf("%d %d", &N, &K);
	memset(dp, -1, sizeof(dp));

	for(int i = 0;i < K;++i){
		int t, u;
		scanf("%d %d", &t, &u);
		P[t-1] = u;
	}

	printf("%d\n", solve(0, 0, 0));
}
int solve(int i, int j, int k){ //前日にパスタjを食べ，前々日にパスタkを食べた場合の，i日目以降の組合せ
	if(i == N) return 1;

	if(dp[i][j][k] != -1) return dp[i][j][k];

	if(P[i] != 0){
		if(P[i] == j && j == k) return 0;
		dp[i][j][k] = solve(i+1, P[i], j) % 10000;
		return solve(i+1, P[i], j) % 10000;
	}

	int t = 0;

	for(int u = 1;u <= 3;++u){
		if(!(u == j && j == k)){
			t += solve(i+1, u, j) % 10000;
		}
	}

	dp[i][j][k] = t % 10000;
	return t % 10000;
}


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

int main() {
  vector<int> a(3),b(3),c(3);
  for(int i=0; i<3; i++){
    cin >> a.at(i);
    cin >> b.at(i);
    cin >> c.at(i);
  }
  
  bool k=1;
  for(int i=0; i<2; i++){
    if(a.at(i)-b.at(i)!=a.at(i+1)-b.at(i+1)){
      k=0;
    }
    if(b.at(i)-c.at(i)!=b.at(i+1)-c.at(i+1)){
      k=0;
    }
    if(a.at(i)-a.at(i+1)!=b.at(i)-b.at(i+1)){
      k=0;
    }
    if(a.at(i)-a.at(i+1)!=c.at(i)-c.at(i+1)){
      k=0;
    }
  }
  
  if(k){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i;
    int a,b,c,cnt;
    scanf("%d" , &cnt );
    for( i = 0 ; i < cnt ; i++ ){
        scanf( "%d %d %d " , &a , &b , &c );
        if( a * a + b * b == c * c || c * c + b * b == a * a || a * a + c * c == b * b ){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
}


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

int guess_number(int N, int M){
   int s[3], c[9];
  for(int i = 0; i < M; i++){
    cin >> s[i] >> c[i];
  }
  for(int i = 0; i <= 999; i++){
    stringstream iss; iss << i;
    string str = iss.str();
    if(str.size() != N) continue;
    bool is_valid_num = true;
    for(int j = 0 ; j < M; j++){
      if(str[s[j] - 1] != (c[j] + '0')){
        is_valid_num = false; break;
      }
    }
    if(is_valid_num) return i;
  }
  return -1;
}

int main(){
  int N, M;
  cin >> N >> M;
  cout << guess_number(N, M) << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
q=deque()

n=int(input())
a=input().split()
for i in range(n):
    if i%2==0:
        q.append(a[i])
    else:
        q.appendleft(a[i])

if n%2==0:
    print(' '.join(q))
else:
    print(' '.join(list(q)[::-1]))

Measured memory_bytes: 106940
#include <bits/stdc++.h>
#define maxn 200001
#define maxa 1000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}


    ll fre[maxa];

void solve(){
    ll n;
    cin >> n;
    ll a[n];

    for(ll i = 0; i < n; i++){
        cin >> a[i];
        ll x = a[i];
        for(ll j = 2; j <= sqrt(x); j++){
            if(x%j == 0){
                ll c = 0;
                while(x%j == 0){
                    x /= j;
                    c++;
                }
                fre[j] = max(fre[j], c);
            }
        }
        if(x > 1) fre[x] = max(fre[x], (ll)1);
    }
    ll sum = 0, lcf = 1;
    for(ll i = 1; i < maxa; i++){
        if(fre[i]) lcf = (lcf*power(i, fre[i]))%MOD;
    } //cout << lcf << endl;
    for(ll i = 0; i < n; i++){
        sum = (sum +((lcf*power(a[i]))%MOD))%MOD;
    }cout << sum;
}

int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6656
import heapq
N, M, S = map(int, input().split())
edges = [[]for _ in range(N)]
inf = 10**18
for _ in range(M):
    u, v, d = map(int, input().split())
    edges[u].append((v, d))


def dijkstra(s):

    dist = [inf]*N
    dist[s] = 0
    vs = []
    heapq.heappush(vs, (0, s))
    while len(vs):
        res, v = heapq.heappop(vs)
        if res > dist[v]:
            continue
        for nxt, cost in edges[v]:
            if res+cost < dist[nxt]:
                dist[nxt] = res+cost
                heapq.heappush(vs, (dist[nxt], nxt))
    return dist


dist = dijkstra(S)
for i in range(N):
    if dist[i] == inf:
        print("INF")
    else:
        print(dist[i])



Measured memory_bytes: 89284
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <vector>
#include <array>
#include <set>
#include <climits>
#include <sstream>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <numeric>
using namespace std;
using namespace __gnu_pbds;
typedef tree< // find_by_order & order_of_key
        int ,
        null_type ,
        less<int> ,
        rb_tree_tag ,
        tree_order_statistics_node_update 
> new_set;
#define MOD 1000000007
#define MAXN (int)1e5+10
array<int,MAXN>arr;
array<int64_t,MAXN>dp;
int main(void){
#ifdef HELL_JUDGE
    freopen("input","r",stdin);
    freopen("output","w",stdout);
    freopen("error","w",stderr);
#endif 
    int n; scanf("%d",&n);
    for(int i=0;i<n;++i){
        cin>>arr[i];
    }
    fill(dp.begin() , dp.begin()+n , INT_MAX);
    dp[0] = 0;
    for(int i=0;i<n;++i){
        for(int j:{i+1,i+2}){
            if(j>n){
                continue;
            }
            dp[j] = min(dp[j] , dp[i]+(int64_t)abs(arr[i]-arr[j]));
        }
    }
    cout<<dp[n-1]<<'\n';
    return 0;
}


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

int main(){
	int K, S, x, y, tmp=0;
	cin >> K >> S;
	for(x=0;x<=K;x++){
		for(y=0;y<=K;y++){
			if(S-x-y<=K&&S-x-y>=0){
				tmp++;
			}
		}
	}
	cout << tmp << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
         int N = tmp[0], D = tmp[1];
         int cnt = 0;
         for(int i = 0; i < N; i++){
             tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
             if(Math.Sqrt(Math.Pow(tmp[0],2) + Math.Pow(tmp[1],2)) <= D) cnt++;
         }
         WriteLine(cnt);
      }
   }
}

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

int main() {
  int N, M, j = 0, f = 0, g = 0;
  string w;
  cin >> N;
  vector<string> B(N);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  cin >> M;
  vector<string> R(M);
  for (int i = 0; i < M; i++) cin >> R.at(i);
  
  while (j < N){
    w = B.at(j);
    for (int i = j; i < N; i++) if (w == B.at(i)) f++;
    for (int i = 0; i < M; i++) if (w == R.at(i)) f--;
    if (f > g) g = f;
    f = 0;
    j++;
  }
  
  cout << g << endl;
}

Measured memory_bytes: 3608