akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint n, k;
lint mod = 1e+9 + 7;

// a^n mod pを計算　O(log n)
long long pow_mod(long long a, long long n, long long p) {
    if (n == 0) return 1;
    if (n & 1) return pow_mod(a, n - 1, p) * a % p;
    long long temp = pow_mod(a, n / 2, p);
    return temp * temp % p;
}

vector<int64_t> divisor(int64_t n) {
    vector<int64_t> ret;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

// 素因数分解unordered_map版　O(√n)
template <typename T>
unordered_map<T, T> pf_um(T n) {
    unordered_map<T, T> res;
    for (long long i = 2; i * i <= n; i++)
        while (n % i == 0) res[i]++, n /= i;
    if (n != 1) res[n]++;
    return res;
}

int main() {
    cin >> n >> k;
    // count[i]:gcdがiの倍数なるやつの個数
    vector<lint> count(k + 1);
    for (lint i = 1; i <= k; i++) {
        lint num = k / i;
        count[i] = pow_mod(num, n, mod);
    }
    for (lint i = k; i >= 1; i--) {
        auto div = divisor(i);
        for (auto e : div) {
            if (e == i) {
                continue;
            }
            count[e] = (count[e] - count[i]) % mod;
        }
    }
    lint ans = 0;
    for (lint i = 1; i <= k; i++) {
        ans = (ans + i * count[i]) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		input := make([][]int, n+1, n+1)
		totalRow := make([]int, n+1, n+1)

		for i := 0; i < n; i++ {
			row := make([]int, n+1, n+1)
			scanner.Scan()

			row = numbers(scanner.Text())

			input[i] = row
			total(totalRow, row)
		}

		input[n] = totalRow

		for xk := range input {
			for yk, yv := range input[xk] {
				if yk == n {
					fmt.Printf("%5d\n", yv)
				} else {
					fmt.Printf("%5d", yv)
				}
			}
		}
	}
}

func total(sum, row []int) {
	for i := 0; i < len(row); i++ {
		sum[i] += row[i]
	}
}

func numbers(s string) []int {
	var n []int
	var sum int
	for _, f := range strings.Fields(s) {
		i, err := strconv.Atoi(f)
		if err == nil {
			n = append(n, i)
			sum += i
		}
	}
	n = append(n, sum)
	return n
}



Measured memory_bytes: 1144
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

class UnionFind{
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    //作る時はParentの値を全て-1にする
    //こうするとずべてバラバラになる
    UnionFind(int N){
      Parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているのか調べる
    int root(int A){
      if(Parent[A]<0) return A;
      return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
      return -Parent[root(A)];//親を取ってきたい
    }

    //AとBをくっつける
    bool connect(int A,int B){
      //AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける)
      A = root(A);
      B = root(B);
      if(A==B){
        //すでにくっついているからくっつけない
        return false;
      }
      //大きい方(A)に小さい方(B)をくっつけたい
      //大小が逆だったらひっくり返しちゃう
      if(size(A)<size(B)) swap(A,B);

      //Aのサイズを更新する
      Parent[A] += Parent[B];
      //Bの親をAに変更する
      Parent[B] = A;

      return true;
    }
  };


int main(){
  ll N , M; cin >> N >> M;
  vector<ll> a(M); vector<ll> b(M); rep(i,M) cin >> a[i] >> b[i];
  rep(i,M) {a[i]--; b[i]--;}
  ll ans = 0;
  rep(i,M){
    bool check = false;
    // i wo through
    UnionFind Uni(N);
    rep(j,M){
      if(j == i) continue;
      Uni.connect(a[j] , b[j]);
    }
    rep(j,N - 1){
      if(Uni.root(j) != Uni.root(j + 1)) check = true;
    }
    if(check) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
	long n, a, b, s;
 	cin >> n >> a >> b;
    s = n % (a + b);
    if (s >= a){
        s = a;
    }
    cout << long((n / (a + b) * a + s)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

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

    

    return 0;
}

Measured memory_bytes: 1732
n, k = map(int, input().split())

mod = 10**9 + 7
n_list = [0]*(n+1)
for i in range(n+1):
    n_list[i] = (10**100 + i) % mod

s = [0]*(n+1)
s[0] = n_list[0]

for i in range(1, n+1):
    s[i] = (s[i-1] + n_list[i]) % mod
#print(s)

count = 0
for i in range(k, n+1):
    min_sum = s[i-1] % mod
    max_sum = (s[n] - s[n-i]) % mod
    m = (max_sum - min_sum) + 1 % mod
    count += m
count += 1  # k=n+1の分
print(count % mod)

Measured memory_bytes: 109768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
int n,a[1000000],i,g;
int gcd(int x,int y)
{
	return y==0?x:gcd(y,x%y);
}
bool solve()
{
	int ji=0,ou=0,last;
	for (int i=1;i<=n;i++) if (a[i]&1)ji++,last=i;else ou++;
	if (ou&1) return true;
	if (ji>=2) return false;
	if (a[last]==1) return false;
	a[last]--;
	g=a[1];
	for (int i=2;i<=n;i++) 
	g=gcd(g,a[i]);
	for (int i=1;i<=n;i++) a[i]/=g;
	return !solve();
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	if (solve()) printf("First\n");
	else printf("Second\n");
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];

    vector<ll> SA(N+1, 0), SB(M+1, 0);
    REP(i, N) SA[i+1] = SA[i] + A[i];
    REP(i, M) SB[i+1] = SB[i] + B[i];

    ll res = 0;
    REP(i, N+1){
        if(SA[i]>K) continue;
        ll pos = upper_bound(SB.begin(), SB.end(), K-SA[i]) - SB.begin();
        pos--;
        chmax(res, i+pos);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 9532
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let x: i32 = read();
    println!("{}", match x {
        400 ..= 599 => 8,
        600 ..= 799 => 7,
        800 ..= 999 => 6,
        1000 ..= 1199 => 5,
        1200 ..= 1399 => 4,
        1400 ..= 1599 => 3,
        1600 ..= 1799 => 2,
        _ => 1
    });
}

Measured memory_bytes: 2088
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
    char s[131072]={};
    scanf("%s", s);
    size_t ub=strlen(s);
    s[ub] = '$';

    for (size_t i=0; i<ub; ++i)
        for (size_t j=1; j<=2; ++j)
            if (s[i] == s[i+j]) {
                printf("%llu %llu\n", i+1, i+j+1);
                return 0;
            }

    printf("-1 -1\n");
    return 0;
}


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

int main(){
    
    int n;
    int lmax = 0;
    int lsum = 0;
    int ltemp;
    cin >> n;

    for (int i = 0; i < n; ++i){
        cin >> ltemp;
        if(ltemp > lmax){
            lsum += lmax;
            lmax = ltemp;
        }else{
            lsum += ltemp;
        }
    }
    if(lsum > lmax){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10000000];
int bin(int x,int left,int right){
	while(left<=right){
		int mid=(left+right)/2;
		if(a[mid]==x){
			return mid;
		}
		else if(x<a[mid]){
			right=mid-1;
			continue;
		}
		else{
			left=mid+1;
		}
	}
	return -1;
}
int main(void){
	int x,q;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	cin>>q;
	int countt=0;
	for(int i=0;i<q;i++){
		scanf("%d",&x);
		if(bin(x,0,n-1)!=-1)
			countt++;
	}
	cout<<countt<<endl;
	return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n;
  cin>>n;
  vector<int> a(n-1),b(n);
  rep(i,n-1) cin>>a[i];
  rep(i,n-2){
    b.push_back(min(a[i],a[i+1]));
  }
  cout<<vec_sum(b)+a[n-2]+a[0]<<endl;
}
///////////////////////////

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

max = (10 ** 9) + 7

#一列の総和
wa = 0
for i in range (n):
    wa += a[i]

#a11, a22, ...の総和
rem = 0
for i in range(n):
    rem += a[i]*a[i]

sum = ((wa*wa) - rem) // 2

ans = sum % max

print(ans)

Measured memory_bytes: 94272
n = int(input())
arr = list(map(int,input().split()))
ans = []
#二次元リストを作る→ソート
for i in range(1,n+1):
    ans.append([arr[i-1],i])
ans.sort()
ans = [i[1] for i in ans]


print(' '.join(map(str,ans)))

Measured memory_bytes: 74924
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int digit(ll n) {
	int ans = 1;
	while (n / 10 > 0) {
		n /= 10;
		ans++;
	}
	return ans;
}

int main() {
	ll N; cin >> N;
	int ans = INF;

	for (ll i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			ans = min(ans, digit(max(i, N / i)));
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a, b, c, Max, flag = 0, ans = 0, A, B, C, X, Y;

int main()
{
	scanf("%d%d%d", &a, &b, &c);
	int Max = max(max(a, b), c);
	int A = Max - a;
	int B = Max - b;
	int C = Max - c;
	if((A + B + C) % 2 != 0)
	{
		A++;
		B++;
		C++;
		flag = 1;
	}
	if(flag == 0)
	{
		if(A == 0 && B != 0 && C != 0)
		{
			ans = min(B, C);
			if(B <= C) ans += (C - B)/2;
			else ans += (B - C) / 2;
		}
		if(B == 0 && A != 0 && C != 0)
		{
			ans = min(A, C);
			if(A >= C) ans += (A - C)/2;
			else ans += (C - A) / 2;
		}
		if(C == 0 && A != 0 && B != 0)
		{
			ans = min(A, B);
			if(A >= B) ans += (A - B) / 2;
			else ans += (B - A) / 2;
		}
		if(B == 0 && A == 0 && C != 0) ans = C / 2;
		if(B == 0 && C == 0 && A != 0) ans = A / 2;
		if(C == 0 && A == 0 && B != 0) ans = B / 2;
		if(A == 0 && B == 0 && C == 0) ans = 0;
	}
	if(flag == 1)
	{
		if(A == 1 && B >= 1 && C >= 1)
		{
			ans++;
			X = max(B, C);
			Y = min(B, C);
			Y--;
			ans += (X - Y) / 2 + Y;
		}
		else if(B == 1 && A >= 1 && C >= 1)
		{
			ans++;
			X = max(A, C);
			Y = min(A, C);
			Y--;
			ans += (X - Y) / 2 + Y;
		}
		else if(C == 1 && B >= 1 && A >= 1)
		{
			ans++;
			X = max(B, A);
			Y = min(B, A);
			Y--;
			ans += (X - Y) / 2 + Y;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.14159
#include <map>
#include <iterator>
using namespace std;
int main()
 {
 	long long int n,k,i,j,f=0;
 	cin>>n>>k;
 	int a[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 		sort(a,a+n);
 	if(k>=n)
 		f==0;
 	else
 		{
 			for(i=0;i<n-k;i++)
 				f+=a[i];
		 }
		cout<<f<<endl;
 	}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, m;
	cin >> n >> m;
	int l, r;
	int ruiseki[110000] = {};
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r;
		++ruiseki[l];
		--ruiseki[r + 1];
	}
	int ans = 0;
	for (int i = 1; i < n + 1; ++i)
	{
		ruiseki[i] += ruiseki[i - 1];
		ans += (ruiseki[i] == m);
	}
	cout << ans << endl;
	return 0;
}

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

int n,ans;
ll a[N];
map <ll,ll> M,M1,M2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i&1) M1[a[i]]++;
		else M2[a[i]]++; 
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		if(i&1)
		{
			if(!M1[a[i]])
				ans++;
			else M1[a[i]]--;
		}
		else
		{
			if(!M2[a[i]])
				ans++;
			else M2[a[i]]--;
		}
	}
	printf("%d\n",ans/2);
	return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n,k; cin >> n >>k;
  map<ll,ll> m;
  rep(i,k){
    ll d; cin >> d;
    rep(j,d){
      ll a; cin >> a;
      m[a]++;
    }
  }
  ll ans=0;
  rep(i,n){
    if(m.count(i+1)==0){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 3596
from collections import defaultdict


N, *UVW = map(int, open(0).read().split())
g = defaultdict(set)

ans = [0] * N
for u, v, w in zip(*[iter(UVW)] * 3):
    u -= 1
    v -= 1
    g[u].add((v, w))
    g[v].add((u, w))
visited = {0}
stack = [0]
while stack:
    v = stack.pop()
    for nv, nw in g[v]:
        if nv in visited:
            continue
        if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
        stack.append(nv)
        visited.add(v)
print("\n".join(map(str, ans)))


Measured memory_bytes: 79324
import math

a, b, x = map(int, input().split())

if a ** 2 * b < x * 2:
	theta_rad = math.atan(2 * (a ** 2 * b - x) / (a ** 3))
else:
	theta_rad = math.atan((a * b ** 2) / (2 * x))

theta = math.degrees(theta_rad)
print(theta)


Measured memory_bytes: 2940
N = int(input())

array = list(map(int, input().split()))

#print(N, array)

ans_array = [array[0]]
for i in range(N - 1):
    #print("i: ", i)
    #print(ans_array)
    if i == N - 2:
        ans_array.append(array[-1])
    else:
        ans_array.append(min([array[i], array[i + 1]]))
print(sum(ans_array))


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
 
int n;
vector<pair<int, int> > adj[MAX];
 
void dijkstra() {
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
 
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;
 
    while (!PQ.empty()) {
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
 
        if (d[u] < f.first*(-1)) continue;
 
        for (unsigned int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
 
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}
 
int main() {
    int k, u, v, c;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
 
    dijkstra();
 
    return 0;
}


Measured memory_bytes: 8072
s = gets.to_i

MOD = 10 ** 9 + 7
x = Array.new(s + 1, 0)

if s < 3 then
	puts 0
	exit
else
	sum = 0
	(3..s).each{ |i|
		sum += x[i - 3] % MOD
		x[i] = (sum + 1) % MOD
	}
end

print x[s]


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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef double db;
typedef long long LL;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2005;

int n,m;
struct edge{
	int x,nxt;
}e[N*2];
int h[N],tot;

void inse(int x,int y){e[++tot].x=y;e[tot].nxt=h[x];h[x]=tot;}

int vis[N],tim;
pair<int,int>que[N*N];
int he,ta;

struct Tree{
	int tp[N],fa[N];
	int rt;
	
	void dfs(int x){
		vis[x]=tim;
		for(int p=h[x];p;p=e[p].nxt)
		if (vis[e[p].x]<tim){
			int y=e[p].x;
			dfs(y);
			fa[y]=x;
		}
	}
	
	void init(int st){
		rt=st;
		tim++;
		dfs(rt);
		fo(i,1,n)tp[i]=0;
	}
	
	int gettp(int x){return !tp[x]||tp[x]==x?x:tp[x]=gettp(tp[x]);}
	
	void fill(int x,int t){
		tp[x]=t;
		for(int p=h[x];p;p=e[p].nxt)
		if (fa[e[p].x]==x){
			int y=e[p].x;
			if (tp[y]){
				tp[y]=t;
				que[++ta]=make_pair(t,y);
			}
			else{
				tp[y]=t;
				fill(y,t);
			}
		}
	}
	
	int insert(int x){
		if (x==rt)return 0;
		if (tp[x])return gettp(x);
		return 0;
	}
}t[N];
vector<int>neigh[N];

int sta[N],top;
bool pd[N];
int ans;
bool to[N];

void getans(int x){
	pd[sta[++top]=x]=1;
	to[x]=(top==1);
	for(auto y:neigh[x])
		if (pd[y])to[x]|=to[y];
	if (to[x]&&top>1)ans++;
	for(int p=h[x];p;p=e[p].nxt)
	if (!pd[e[p].x])getans(e[p].x);
	pd[x]=sta[top--]=0;
}

int main(){
	n=get();m=get();
	fo(i,1,n-1){
		int x=get(),y=get();
		inse(x,y),inse(y,x);
	}
	fo(i,1,n)t[i].init(i);
	fo(i,1,m){
		int x=get(),y=get();
		he=0,ta=1;
		que[1]=make_pair(x,y);
		for(;he<ta;){
			pair<int,int> u=que[++he];
			x=u.first,y=u.second;
			int z=t[x].insert(y);
			if (z){
				if (y!=z)que[++ta]=make_pair(z,y);
			}
			else{
				z=t[y].insert(x);
				if (z){if (x!=z)que[++ta]=make_pair(x,z);}
				else{
					t[x].fill(y,y);
					t[y].fill(x,x);
				}
			}
		}
	}
	fo(i,1,n)fo(j,1,n)if (t[i].tp[j]==j)neigh[i].push_back(j);
	ans=0;
	fo(i,1,n)
	getans(i);
	ans/=2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 33152
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Wed Aug 26 18:57:13 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

template <char margin = 'A', int char_size = 26> struct Trie {
    struct TrieNode {
        std::array<int, char_size> node;
        TrieNode() { node.fill(-1); };
        typename std::array<int, char_size>::iterator begin() { return node.begin(); }
        typename std::array<int, char_size>::iterator end() { return node.end(); }
        int& operator[](int i) { return node[i]; }
    };
    std::vector<TrieNode> tree;
    std::vector<int> num;  // 部分木内の個数
    Trie() : tree(1), num(1) {}
    void insert(const std::string& s) {
        num[0]++;
        int t = 0;
        for (char c : s) {
            int d = c - margin;
            if (tree[t][d] == -1) {
                tree[t][d] = tree.size();
                tree.emplace_back();
                num.push_back(0);
            }
            t = tree[t][d];
            num[t]++;
        }
    }
    void erase(const std::string& s) {
        int par = 0;
        num[par]--;
        for (char c : s) {
            int d = c - margin;
            int nxt = tree[par][d];
            assert(nxt != -1 && "s does not exist");
            if (--num[nxt] == 0) tree[par][d] = -1;
            par = nxt;
        }
    }
};

signed main() {
    Int n;
    std::cin >> n;
    std::vector<std::string> ss(n);
    REP(i, n) std::cin >> ss[i], std::reverse(ALL(ss[i]));
    std::sort(ALL(ss), [&](std::string a, std::string b) { return a.size() < b.size(); });

    Int ans = 0;
    Trie<> t;
    auto num = make_vec<Int>(1, 26, 0);
    for (const std::string& s : ss) {
        Int idx = 0;
        REP(i, s.size() - 1) {
            REP(c, 26) {
                if (num[idx][c] && std::find(s.begin() + i, s.end(), 'a' + c) != s.end()) ans += num[idx][c];
            }
            Int c = s[i] - 'a';
            if (t.tree[idx][c] == -1) {
                t.tree[idx][c] = t.tree.size();
                t.tree.emplace_back();
                num.emplace_back(26);
            }
            idx = t.tree[idx][c];
        }
        num[idx][s.back() - 'a']++;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 347324
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい


ll x;

int main(){
	cin>>x;
	ll cnt=(x/11)*2;
	ll y=x-(x/11)*11;
	if(y==0) cout<<cnt<<endl;
	else if(y<=6) cout<<cnt+1<<endl;
	else cout<<cnt+2<<endl;
	
	  return 0;
  }


Measured memory_bytes: 256
l = "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"
s = list(map(int, l.split(", ")))
k = int(input())
print(s[k-1])

Measured memory_bytes: 2940
#include<cstdio>

int main(){
    char ch;
    int counter[26] = {0};

    while(scanf("%c", &ch) != EOF){
        if('A' <= ch && ch <= 'Z'){
            int num = ch + 32 - 'a';
            counter[num] += 1;
        } else if('a' <= ch && ch <= 'z'){
            int num = ch - 'a';
            counter[num] += 1;
        }
    }

    for (int i = 0; i < 26; i++){
        printf("%c : %d\n", i + 'a', counter[i]);
    }

    return 0;
    
}


Measured memory_bytes: 2732
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define si short int
using namespace std;
const int N=101;
si n,m,x,y,ans,dp[N][N][N][N],sum[N][N];
char g[N][N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
inline void cmx(si &a,si b){if(b>a) a=b;}
template<typename I>inline void swp(I&a,I&b){I t=a; a=b; b=t;}
inline si s(int a,int b,int c,int d){
	if(a>c) swp(a,c); if(b>d) swp(b,d);
	return sum[c][d]-sum[c][b-1]-sum[a-1][d]+sum[a-1][b-1];
}
int main()
{
//	freopen("Salvage Robots.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,m);
	for(int i=1;i<=n;i++) 
	{
		scanf("%s",g[i]+1);
		for(int j=1;j<=m;j++)
		{
			if(g[i][j]=='o') sum[i][j]=1;
			else if(g[i][j]=='E') x=i, y=j;
			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
		}
	}
	for(int i=x;i;i--)
	 for(int j=y;j;j--)
	  for(int k=x;k<=n;k++)
	   for(int l=y;l<=m;l++)
	   {
			ans=mx(ans,dp[i][j][k][l]);
//			int ri=m-l+y, li=y-j+1, us=x-i+1, ds=n-k+x;
			int li=l-y+1, ri=m-y+j, us=k-x+1, ds=n-x+i;
			if(i-1>=us) cmx(dp[i-1][j][k][l],dp[i][j][k][l]+s(i-1,mx(li,j),i-1,mi(ri,l)));
			if(j-1>=li) cmx(dp[i][j-1][k][l],dp[i][j][k][l]+s(mx(i,us),j-1,mi(k,ds),j-1));
			if(k+1<=ds) cmx(dp[i][j][k+1][l],dp[i][j][k][l]+s(k+1,mx(li,j),k+1,mi(ri,l)));
			if(l+1<=ri) cmx(dp[i][j][k][l+1],dp[i][j][k][l]+s(mx(i,us),l+1,mi(k,ds),l+1));
	   }
//	printf("%d\n",ans);
	cout<<ans<<endl;
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 201088
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def ope(self, x, y):
        return x + y

    def update(self, i, v):
        while i <= self.n:
            self.data[i] = self.ope(self.data[i], v)
            i += i & -i

    def query(self, i):
        ret = 0
        while 0 < i:
            ret = self.ope(self.data[i], ret)
            i &= i - 1
        return ret

    def lowerBound(self, w):
        if w <= 0: return 0
        x, k = 0, 2**self.n.bit_length()
        while k:
            if x+k <= self.n and self.data[x+k] < w:
                w -= self.data[x+k]
                x += k
            k >>= 1
        return x + 1

n = int(input())
p = list(map(int, input().split()))
pos = [0]*n
for i, pi in enumerate(p):
    pos[pi-1] = i

bit1 = BIT(n)
bit2 = BIT(n)
ans = 0
for pi in range(n, 0, -1):
    i = pos[pi-1]
    cur = bit1.query(i+1)
    if cur == 0:
        left_0 = i+1
        left_1 = 0
    else:
        tmp = bit1.lowerBound(cur)
        tmp2 = bit1.lowerBound(cur-1)
        left_0 = i+1-tmp
        left_1 = tmp-tmp2
    # 更新
    bit1.update(i+1, 1)
    j = n-i-1
    cur = bit2.query(j+1)
    if cur == 0:
        right_0 = j+1
        right_1 = 0
    else:
        tmp = bit2.lowerBound(cur)
        tmp2 = bit2.lowerBound(cur-1)
        right_0 = j+1-tmp
        right_1 = tmp-tmp2
    # 更新
    bit2.update(j+1, 1)
    ans += pi*(left_0*right_1 + left_1*right_0)

print(ans)

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

// MY TOOLS
#define let long long int
#define async ios_base::sync_with_stdio(false);cin.tie(NULL);
#define i_upto( n ) for( int i = 0 ; i < n ; i++ )
#define ij_upto( n, m ) for( int i = 0 ; i < n ; i++ ) for( int j = 0 ; j < m ; j++ )
template<class T>
T ** array2D( let R , let C ){
	T ** t = new T * [R] ;
	for( int i = 0 ; i < R ; i++ ){
		t[i] = new T[C] ;
	}
	return t ;
}
template<class T>
T ** array2D( let R , let C, T value ){
	T ** t = new T * [R] ;
	for( int i = 0 ; i < R ; i++ ){
		t[i] = new T[C] ;
	}
    ij_upto( R, C ) t[i][j] = value ;
	return t ;
}
template<class T>
T * array1D( let N, T value ){
    T * t = new T[N] ;
    i_upto(N) t[i] = value ;
    return t ;
}
template<class T>
T * array1D( let N ){
    T * t = new T[N] ;
    return t ;
}
template<class T>
vector<vector<T>> vector2D( let N, let M ){
	return vector<vector<T>>(N,vector<T>(M)) ;
}
template<class T>
vector<vector<T>> vector2D( let N, let M, T Value ){
	return vector<vector<T>>(N,vector<T>(M,Value)) ;
}
#define then ;
#define vector2D( t ) vector<vector<t>>
template<class T>
class matrix{
	public :
    T ** v ;
	let rows, cols ;
		matrix( let n, let m ){
			v = array2D<T>( n, m ) ;
			rows = n ;
			cols = m ;
		}
		void input(){
			ij_upto( rows, cols ) cin >> v[i][j] ;
		}
		T& at( let i, let j ){
			return v[i][j] ;
		}
		void set( let i, let j, T value ){
			v[i][j] = value ;
		}
		void output(){
			for( let i = 0 ; i < rows ; i++ ){
				for( let j = 0 ; j < cols ; j++ ){
					cout << v[i][j] << " " ;
				}
				cout << endl ;
			}
		}
		void fill( T value ){
			ij_upto( rows, cols ) v[i][j] = value ;
		}
		T ** begin(){
			return v ;
		}
		T ** end(){
			return v + rows ;
		}
};
//

bool compare( let * a, let *b ){
	return a[0] + a[1] < b[0] + b[1] ;   // w should be in increasing order and s should also in increasing order
}
let Min( let a, let b ){
	return a < b ? a : b ;
}
let Max( let a, let b ){
	return a > b ? a : b ;
}

// 0 -> w, 1 -> s, 2 -> v 
// main
// write your code here
int main(){
	async ;
    let N then cin >> N ;
    matrix<let> arr( N, 3 ) then arr.input() ;
	sort( arr.begin() , arr.end() , compare ) ;
	let dp[20001] = {0} ;
	for( let part = 0 ; part < N ; part++ ){
		for( let j = Min( 20001 - arr.at(part,0), arr.at(part,1) ) ; j >= 0 ; j-- ){
			dp[j+arr.at(part,0)] = Max(dp[j+arr.at(part,0)], dp[j]+arr.at(part,2) ) ;
		}
	}
	let ans = 0 ;
	i_upto( 20001 ) ans = Max( ans, dp[i] ) ;
	cout << ans then return 0 ;
}

Measured memory_bytes: 3864
#include <stdio.h>

const int MAX_V = 10000;

int main() {
	int i, k, n, p1, q1;
	int a[MAX_V + 1];
	for(i = 2; i <= MAX_V; i++) {
		a[i] = 1;
	}
	for(i = 2; i * i <= MAX_V; i++) {
		if(a[i]) {
			for( k = 2 * i; k <= MAX_V; k += i) {
				a[k] = 0;
			}
		}
	}
	while(1) {
		scanf("%d", &n);
		if(n == 0) break;
		for( i = n; i > 1; i--) {
			if(a[i] == 1 && a[i - 2] == 1) break;
		}
		p1 = i - 2;
		q1 = i;
		printf("%d %d\n", p1, q1);
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 using namespace std;
int main(){
  long n,m,i,j,ans,c;
  long long k,s;
  cin >> n >> m >> k;
  long* a;
  long* b;
  a = new long[n+1];
  b = new long[m+1];
  s = 0;
  a[0] = 0;
  for(i=1;i<n+1;i++){
    cin >> c;
  	s += c;
    a[i] = s;
  }
  s = 0;
  b[0] = 0;
  for(i=1;i<m+1;i++){
    cin >> c;
  	s += c;
    b[i] = s;
  }
  s = 0;
  ans = 0;
  j = m;
  for(i=0;i<=n;i++){
    if (a[i] > k)
      break;
    while (a[i]+b[j] > k)
      j--;
    ans = max(ans,i+j);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6680
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String dance = sc.next();
    boolean flg = true;
    
	for(int i = 0; i < dance.length(); i++){
      char c = dance.charAt(i);
      if((i + 1) % 2 == 0){
        if(c != 'L' && c != 'U' && c != 'D'){
         flg = false;
         break;
        }
      }else{
        if(c != 'R' && c != 'U' && c != 'D'){
         flg = false;
         break;
        }
      }
    }
    if(flg){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main(void)
{
  char n[8];
  int number, t, a;
  int h;
  int x;
  int min = INT_MAX;
  int ans=0;

  fgets(n, sizeof(n), stdin);
  sscanf(n, "%d", &number);

  scanf("%d %d", &t, &a);

  for (int i=0; i < number; i++) {

    scanf("%d", &h);
    x = (t*1000 - h*6) - a*1000;
    if (x < 0) { x = -x; }
    if (x < min) {
      min = x;
      ans = i+1;
      }
  }

  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
int main() {

ll h,n;
cin>>h>>n;
vector<ll>A(n);
ll ans=0;
REP(i,0,n)
{
    cin>>A[i];
    ans+=A[i];
}
 
 if(ans>=h)
 {
     cout<<"Yes";
 }
 else
 {
     cout<<"No";
 }
	return 0;
}

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

int main() {
  int n;cin>>n;
  vector<int> p(n),q(n);
  rep(i,n)cin>>p[i];
  rep(i,n)cin>>q[i];
  vector<int>a(n);
  rep(i,n)a[i]=i+1;
  map<vector<int>,int> mp;
  do{
    mp[a]=mp.size();
  }while(next_permutation(all(a)));
  int ans=abs(mp[p]-mp[q]);
  cout<<ans<<endl;
}

Measured memory_bytes: 8644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
const int maxn = 100;
int main(){
    int n,x;
    cin >> n >> x;
    
    int l[maxn];
    int counter = 0;
    rep(i,n) {
        cin >> l[i];
    }
    int num = 1;
    for(int i=1;i<=n;i++) {
        counter = counter + l[i-1];
        if(counter > x)break;
        num++;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>n;
 for(int i=n; i>0; i/=10)
 if(i%10==9)
 {
 	cout<<"Yes"<<endl;
 	return 0;
 }
 cout<<"No"<<endl;
 return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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





int main(){
    long long A, B, C;
    scanf("%lld %lld.%lld", &A, &B, &C);
    std::cout << (A * (100*B + C)) / 100 << std::endl;
    return 0;
}


Measured memory_bytes: 3688
import sys

n = int(input())
a = [int(x) for x in input().split()]
am = max(a)
mod = 10**9+7
if n==1:
    print(1)
    sys.exit()
li = [0]*(am+1)
lcm = 1
for k in range(n):
    z = a[k]
    for i in range(2,int(z**0.5)+1):
        x = 0
        while z%i==0:
            x += 1
            z//=i
        li[i] = max(li[i],x)
    if z!=1 and li[z]==0:
        li[z] = 1

for i in range(2,am+1):
    if li[i]>0:
        lcm = lcm * i**li[i] % mod

ans = 0
for i in range(n):
    m = pow(a[i],mod-2,mod)
    ans = (ans+(lcm*m)%mod)%mod
print(ans%mod)

Measured memory_bytes: 52444
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;
ll a[MAX];

int main() {
   

    ll n;
    cin >> n;
    for (ll i=1;i<=n;i++){
        cin >> a[i];
    }
    ll ans = 0;
    for (ll i=1;i<=n;i++){
        if(a[i]%2 == 0 and a[i] > 0) {
            ans += a[i] / 2 - 1;
            a[i] = 2;
        }else if(a[i] != 0){
            ans += a[i]/2;
            a[i] = 1;
        }
    }

    for (ll i=1;i<=n;i++){
        if(a[i] == 2){
            ans += 1;
            a[i] = 0;
        }else if (a[i] == 1){
            if(i < n){
                if(a[i+1] >= 1) {
                    ans += 1;
                    a[i] -= 1;
                    a[i + 1] -= 1;
                }
            }
        }
    }
    cout << ans << endl;
}



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

using namespace std;
using i64 = int64_t;

int main(){
   int n;
  cin >> n;
  vector<i64> a, b;
  for(int i=0;i<n;i++){
   	i64 x, y;
    cin >> x >> y;
    a.emplace_back(x+y);
    b.emplace_back(x-y);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  cout << max(abs(a[0]-a[n-1]), abs(b[0]-b[n-1])) << endl;
}


Measured memory_bytes: 6576
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>

using namespace std;

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

int main(){
    int N;
    cin >> N;
    vector<int> h(N, 0);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    vector<int> dp(N, INT32_MAX);

    dp[0] = 0;

    for(int i=1; i<N; i++){
        /* +1ステップ */
        int a = dp[i-1] + abs(h[i]-h[i-1]);
        chmin(dp[i], a);
        /* +2ステップ */
        if(i>1){
            a = dp[i-2] + abs(h[i] - h[i-2]);
            chmin(dp[i], a);
        }
    }

    cout << dp[N-1] << endl;

    return 0;

}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    char c[6];
    for (int i = 0; i < 6; i++)
    {
        cin>>c[i];
    }
    if(c[2]==c[3] && c[4]==c[5])
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
     return 0;
}

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

int main(){
  int n,k,x,y,total;
  cin >> n >> k >> x >> y;
  
  if(n>k){
  	total = k*x + (n-k)*y;
  }else{
    total = x*n;
  }
 
  cout << total << endl;
}

Measured memory_bytes: 256
fn main() {
    let (x1, x2, x3, x4, x5) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut iter = s.split_whitespace().map(|i| i.parse::<i32>().unwrap());
        (
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
        )
    };
    if x1==0{
        println!("1");
    }
    if x2==0{
        println!("2");
    }
    if x3==0{
        println!("3");
    }
    if x4==0{
        println!("4");
    }
    if x5==0{
        println!("5");
    }
}

Measured memory_bytes: 2104
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //問題数
		int [] t = new int[n]; //それぞれの問題にかかる時間
		for(int i = 0; i < n; i++) {
			t[i] = stdIn.nextInt();
		}
		int m = stdIn.nextInt(); //ドリンクの数
		int[] p = new int[m]; //どの問題のドリンクか
		int[] x = new int[m]; //ドリンクを飲んだ時に短縮できる時間
		
		for(int i = 0; i < m; i++) {
			p[i] = stdIn.nextInt();
			x[i] = stdIn.nextInt();
		}
		
		for(int i = 0; i < m; i++) {
			int[] b = t.clone();
			int ans = 0;
			
			b[p[i]-1] = x[i];
					
			for(int j = 0; j < n; j++) {
				ans += b[j];
			
			}
			
			System.out.println(ans);
		}
		
		
		
	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll l, r;
    cin >> l >> r;
    int ans = 2019;
    r=min(r, 2019*2+l);
    
    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<=r;j++){
            int mod = i * j % 2019;
            if(ans>mod) ans=mod;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

if (b - a) % 2 == 0:
  print((b - a)//2)
  
elif a - 1 < n - b:
  newB = b - a
  print(a + (newB-1)//2)

else:
  newA = (a + (n - b + 1))
  print((n - b + 1) + (n - newA)//2)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){

	while(1){
		ll n,m;
		cin >> n >> m;
		if( n == 0 ) break;
		vector<ll> a(n);
		rep(i,0,n) cin >> a[i];

		ll ans = -1;

		rep(i,0,n){
			rep(j,0,n){
				if( i == j ) continue;
				ll sum = a[i] + a[j];
				if( sum <= m && ans < sum ) ans = sum;
			}
		} 

		if( ans > 0 ) cout << ans << endl;
		else cout << "NONE" << endl;
	}
	ret 0;
}


Measured memory_bytes: 3080
#include <stdio.h>

int a[105];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	int ma=-1;
	int mi=1005;

	for(i=0;i<N;i++){
	scanf(" %d",&a[i]);
	if(ma<a[i]){ma=a[i];}
	if(mi>a[i]){mi=a[i];}
	}

	printf("%d\n",ma-mi);

return 0;
}

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

using namespace std;

long long gcd(long long x, long long y) {
    long long a = min(x, y), b = max(x, y);
    if (b%a == 0)
        return a;
    else 
        return gcd(a, b%a);
}

int main() {
    int n;  cin >> n;
    long long *a = new long long[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    long long ans = a[0];
    for (int i = 1; i < n; i++)
        ans = gcd(a[i], ans);
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

ll h,w;
bool uni[444][444];
ll ans = 0;
string s[444];
ll kuro = 0,siro = 0;
void check(int x,int y) {
	// bool a[444][444];
	uni[x][y] = true;
	if (s[x][y] == '.') {
		siro++;
	} else {
		kuro++;
	}
	for (int i = 0;i < 4;i++) {
		
		if (0 <= x + dx[i]&&x + dx[i] < h&&0 <= y + dy[i]&&y + dy[i] < w) {
			if (!uni[x+dx[i]][y+dy[i]]&&s[x][y] != s[x+dx[i]][y+dy[i]]) {
				// end = false;
				// cout << x << y << x+dx[i] << y+dy[i] << endl;

			check(x+dx[i],y+dy[i]);
				
			}
		}
		
	}
	
}

int main() {
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		cin >> s[i];
	}
	for (int i = 0;i < 444;i++) {
		for (int j = 0;j < 444;j++) {
			uni[i][j] = false;
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (!uni[i][j]) {check(i,j);ans+=kuro*siro;kuro = 0;siro = 0;}
		}
	}
	// for (int i = 0;i < 444;i++) {
	// 	for (int j = 0;j < 444;j++) {
	// 		if (uni[i][j]) cout << "1" << " ";
	// 		else cout << "2" << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << ans;
}

Measured memory_bytes: 15616
D=int(input())                                          #コンテの日数
c=list(map(int,input().split()))                        #26タイプ(AAC~AZC)のコンテストの満足度低下度
s=[list(map(int,input().split())) for _ in range(D)]    #s[d][i]...d(1<=d<=D)日目にi(1<=i<=26)番目のコンテストを行った時の満足度上昇
types=[int(input()) for _ in range(D)]                  #コンテタイプ(1~26)
#満足度低下はΣ(1<=i<=26)ci*(d-last(d,i))                  #なおlast(d,i)=d日目以前に最後にタイプiのコンテストをやった日にち(ない場合0)
#よって満足度はs[d][i]-Σ(1<=i<=26)ci*(d-last(d,i))
#i日目のスコアはmax(10^6+s[d][i]-Σ(1<=i<=26)ci*(d-last(d,i)),0)
last=[0]*26                                             #typeごとに、最後に使われた日にちを記録するよ
typ=0
ans=0
for i in range(D):
    typ=types[i]-1
    score=s[i][typ]
    dwn=0
    last[typ]=(i+1)
    for j in range(26):
        dwn=dwn+c[j]*((i+1)-last[j])
    ans=ans+(score-dwn)
    #print(score,last)
    print(ans)
    #input()


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

int main( void )
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ( ( a * b ) >= ( c * d ) )
    {
        cout << a * b << endl;
    }
    else
    {
        cout << c * d << endl;
    }

    return 0;
}


Measured memory_bytes: 256
a, b, c, d, e, f = list(map(int, input().split()))
water = []
suger = []
ans = [0, 0]
ans_max = 0
for i in range(f//100+1):
  for j in range(f//100+1):
    x = 100*(i*a+j*b)
    if x <= f and x > 0 and x not in water:
      water.append(x)
for i in range(f):
  for j in range(f):
    y = c*i + d*j
    if y <= f and y not in suger:
      suger.append(y)
ans[0] = water[0]
for i in water:
  if i == 0:
      continue
  for j in suger:
    if (i+j <= f) and (i*e >= 100*j):
      percent = (100*j)/(i+j)
      if ans_max < percent:
        ans_max = percent
        ans = [i, j]
print(sum(ans), ans[1])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  rep(i,H) cin>>S[i];
  VI X(26);
  rep(i,H) rep(j,W) X[S[i][j]-'a']++;
  sort(all(X));
  int ans=1;
  int tmp;
  rep(i,(H/2)*(W/2)){
    if(X[25]<4) ans=0;
    else X[25]-=4;
    sort(all(X));
  }
  rep(i,(H/2)*(W%2)+(H%2)*(W/2)){
    if(X[25]<2) ans=0;
    else X[25]-=2;
    sort(all(X));
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;


int main() {
  int n, a;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  v.insert(v.begin(), 0);
  v.push_back(0);
  
  int s = 0;
  for (int i = 1; i < v.size(); i++) {
    s += abs(v[i-1]-v[i]);
  }
  for (int i = 1; i < v.size()-1; i++) {
    cout << s + abs(v[i-1] - v[i+1]) - (abs(v[i-1]-v[i]) + abs(v[i]-v[i+1])) << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 1784
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int k = sc.nextInt();
        String s = sc.next();

        System.out.println(s.length() <= k ? s : s.substring(0, k) + "...");

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 38616