akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

double distance(double a1, double a2, double b1, double b2) {
	return sqrt((a1 - b1) * (a1 - b1) + (a2 - b2) * (a2 - b2));
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int h, w;
	cin >> h >> w;

	vector<vector<int>> a(h, vector<int>(w));
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	vector<pair<P, P>> ans;
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] % 2 == 1) {
					a[i][j]--;
					if (j == w - 1) {
						if (i + 1 < h) {
							a[i + 1][j]++;
							ans.push_back(make_pair(P(i, j), P(i + 1, j)));
						}
					}
					else {
						a[i][j + 1]++;
						ans.push_back(make_pair(P(i, j), P(i, j + 1)));
					}
				}
			}
		}
		else {
			for (int j = w - 1; j >= 0; j--) {
				if (a[i][j] % 2 == 1) {
					a[i][j]--;
					if (j == 0) {
						if (i + 1 < h) {
							a[i + 1][j]++;
							ans.push_back(make_pair(P(i, j), P(i + 1, j)));
						}
					}
					else {
						a[i][j - 1]++;
						ans.push_back(make_pair(P(i, j), P(i, j - 1)));
					}
				}
			}
		}
	}

	cout << sz(ans) << endl;
	for (auto p : ans) {
		cout << p.first.first + 1 << " " << p.first.second + 1 << " "
			<< p.second.first + 1 << " " << p.second.second + 1 << endl;
	}

	return 0;
}

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

int main()
{
  string S;

  cin >> S;

  string ans = "Good";

  for (int i = 0; i < 3; i++)
  {
    if (S.at(i) == S.at(i + 1))
    {
      ans = "Bad";
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
num = int(input()) #標準入力
for _ in range(num): #num回繰り返す
    a,b = map(int,input().split()) #標準入力
    if a % b == 0:print(b) #aをbで割った余りがないなら最後の人がとったことになるから最後の人の番号を出力する
    else:print(a % b) #上記でなければaをbで割った余りを出力する


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    ll ans = 0;
    if(N%2==0){
        for (ll i = 10; i <= N; i*=5){
            ans+=(N/i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>

using namespace std;

#define REP(i,a,b) for(int i=(a); i<(b); ++(i))
#define rep(i,n) REP(i,0,n)

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

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

  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);

  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];

  ll cnt = 0ll;
  rep(i, N) {
    if (A[i] < B[i]) cnt += (B[i] - A[i]) / 2ll;
    else cnt -= (A[i] - B[i]);
  }

  cout << (0 <= cnt ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int step[200001];
    int h[200001];
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> h[i+1];
        step[i]=0;
    }
    step[1]=0;
    step[2]=abs(h[1]-h[2]);
    for(int i=3;i<n+1;i++){
        step[i]=min(step[i-1]+abs(h[i-1]-h[i]),step[i-2]+abs(h[i-2]-h[i]));
    }
    //for(int i=1;i<n+1;i++){
    //    cout << step[i] << " ";
    //}
    //cout << endl;
    cout << step[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll d=in();
    vector<ll>c(26);
    for(ll i=0;i<26;++i)c[i]=in();
    auto s=vec2<ll>(d,26);
    for(ll i=0;i<d;++i)for(ll j=0;j<26;++j)s[i][j]=in();
    vector<ll>last(26,-1);
    ll v=0;
    for(ll i=0;i<d;++i){
        ll t=in()-1;
        v+=s[i][t];
        last[t]=i;
        for(ll j=0;j<26;++j)v-=c[j]*(i-last[j]);
        cout<<v<<endl;
    }
}


Measured memory_bytes: 3708
int main(void) {

	int n, k, l[55], i, j, tmp, sum=0;

	scanf("%d%d", &n, &k);

	for (i = 0; i < n; i++) {
		scanf("%d", l + i);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n - i - 1; j++) {
			if (l[j] < l[j + 1]) {
				tmp = l[j];
				l[j] = l[j + 1];
				l[j + 1] = tmp;
			}
		}
	}

	for (i = 0; i < k; i++) {
		sum += l[i];
	}

	printf("%d", sum);

	return 0;
}

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


int main(){
    int N;
    cin >> N;
    int a[N+1] = {0};
    for(int i=2; i<=N; i++){
        int Ai;
        cin >> Ai;
        a[Ai]++;
    }
    for(int i=1; i<=N; i++){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4436
# 入力
n = int(input())

# 処理
sum = 0

for i in range(1, n + 1):
    if i % 15 == 0:
        i = 'FizzBuzz'
    elif i % 3 == 0:
        i = 'Fizz'
    elif i % 5 == 0:
        i = 'Buzz'
    else:
        sum += i

print(sum)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n;
	cin >> n;
	int h[n];
	for(int i = 0; i < n; i++)
	cin >> h[i];
	ll ans = 0;
	int dp[n]; // cost
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i = 2; i < n; i++)
	{
		ll x = abs(h[i]-h[i-1])+dp[i-1];
		ll y = abs(h[i]-h[i-2])+dp[i-2];
		if(x <= y)
		dp[i] = x;
		else
		dp[i] = y;
	}
	cout << dp[n-1] << '\n';
	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(int, N);

  i64 sum = 0;
  vector<int> s(N);
  rep(i, N) {
    IN(s[i]);
    sum += s[i];
  }

  if (sum % 10) {
    OUTL(sum); return 0;
  }

  i64 maxv = 0;
  rep(i, N) {
    if ((sum - s[i]) % 10) chmax(maxv, sum - s[i]);
  }

  OUTL(maxv);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int mod = 1e9+7;
int Pow(int x, int n){	//x^n
  int ans = 1;
  while(n > 0){
    if(n & 1)ans = (ans*x)%mod;
    x = (x*x)%mod;
    n >>= 1;
  }
  return ans;
}

int A[200000], C[200000], B[2][200000];
signed main(){
	string str;
	cin >> str;
	int n = str.size();
	str = " "+str;
	rrep(i,n){
		if(str[i] == 'A')A[i]++;
		if(str[i] == '?')B[0][i]++;
		A[i] += A[i-1];
		B[0][i] += B[0][i-1];
	}
	drep(i,n,1){
		if(str[i] == 'C')C[i]++;
		if(str[i] == '?')B[1][i]++;
		C[i] += C[i+1];
		B[1][i] += B[1][i+1];
	}
	
	int ans = 0;
	rrep(i,n){
		if(str[i] == '?' or str[i] == 'B'){
			int tmp1 = A[i-1]*Pow(3, B[0][i-1]);tmp1 %= mod;
			if(B[0][i-1] > 0)tmp1 += (B[0][i-1]*Pow(3, B[0][i-1]-1))%mod;
			int tmp2 = C[i+1]*Pow(3, B[1][i+1]);tmp2 %= mod;
			if(B[1][i+1] > 0)tmp2 += (B[1][i+1]*Pow(3, B[1][i+1]-1))%mod;
			//printf("%lld %lld\n", tmp1, tmp2);
			ans += tmp1*tmp2;
			ans %= mod;
		}
	}
	
	//rrep(i,n)printf("%lld ", B[1][i]);
	printf("%lld\n", ans);
	return 0;
}







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

#define ll long long int
#define li long int
#define ld long double
#define W while
#define endl "\n"
#define For(i,s,x) for(i=s;i<x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define FoR(i,x) for(i=1;i<=x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

#define IO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()
 
typedef unsigned long long ull;
typedef pair <int, int> pii;
 
const int N = 1e5+5;
const int M = 1e5+5;
const int inf = INT_MAX;
const int MOD = 1e7+9;

int main() {
	IO;
	int temp;
	cin>>temp;
	if(temp>=30){
	    cout<<"Yes"<<endl;
	}
	else{
	    cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int cnt =0;
	while(a >= b){
		b *= 2;
		++cnt;
	}
	while(b >= c){
		c*= 2;
		++cnt;
	}
	cout << ((cnt <= k)?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 3640
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n = get();
    let a: Vec<i64> = (0 .. n).map(|_| get()).collect();
    let mut hash = HashMap::new();
    for v in a {
        *hash.entry(v).or_insert(0) += 1;
    }
    println!("{}", hash.values().filter(|&f| f % 2 == 1).count());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 16636
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, k := scanInt(), scanInt()
	p := scanInts(n)
	c := scanInts(n)

	ans := -1 << 60

	for i := 0; i < n; i++ {
		ss := make([]int, n)
		tt := make([]int, n)

		s := 0
		t := 0
		u := i

		for tt[p[u]-1] == 0 && p[u]-1 != i && t < k {
			u = p[u] - 1
			t++
			tt[u] = t
			s += c[u]
			ss[u] = s
			ans = max(ans, ss[u])
		}

		if t == k {
			continue
		}

		u = p[u] - 1
		cyc := t - tt[u] + 1
		tot := s - ss[u] + c[u]
		if tot > 0 {
			b := u
			ans = max(ans, ss[u]+tot*((k-tt[u])/cyc))

			for p[u]-1 != b {
				u = p[u] - 1
				ans = max(ans, ss[u]+tot*((k-tt[u])/cyc))
			}
		}
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 6360
N, M, Q = map(int, input().split())

x = [[0 for i in range(N + 1)] for j in range(N + 1)]

for i in range(M):
    l, r = map(int, input().split())
    x[l][r] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1]

for i in range(Q):
    p, q = map(int, input().split())

    ans = x[N][q] - x[p - 1][q]
    print(ans)


Measured memory_bytes: 13424
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

const ll MOD=(ll)1e9+7;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n;cin>>n;
    string s;cin>>s;
    ll cnt=0;
    for(int i=0;i<n;i++){
        while(s[i+1]==s[i]&&i<n-1)i++;
        cnt++;
    }
    cout<<cnt<<"\n";

}


Measured memory_bytes: 3752
X, K, D = map(int, input().split())

if K * D < abs(X):
    print(abs(X)-K*D)
    exit(0)

new_X = abs(X) % D
new_K = K - abs(X) // D

if new_K % 2 == 0:
    print(new_X)
else:
    print(abs(new_X-D))


Measured memory_bytes: 9168
# max(1*(a+n-1), 2*(a+n-2), ..., n*a)
def f(a, n):
  x = min((a+n)/2, n)
  y = a+n-x
  return x*y

Q = input()
for _ in range(Q):
  A, B = map(int, raw_input().split())
  if A>B:
    A,B = B,A
  n = 0
  b = 2**32
  while b>0:
    if f(A+1, n+b)<A*B:
      n += b
    b /= 2
  print A-1+n


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define All(a) a.begin(), a.end()
int main(){
    string S, T, U;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    cin >> U;
    if(S == U){
        cout << A - 1 << ' ' << B << endl;
    }
    else cout << A << ' ' << B - 1 << endl;
}

Measured memory_bytes: 256
#n = int(input())
a, b = [int(x) for x in input().split()]
#n, m = [int(x) for x in input().split()]

for i in range(int(101/0.08)+1):
  i+=1
  if int(i*(0.08)) == a and int(i*(0.10)) == b:
    print(i)
    quit()

print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    mat G(N, vec(0));
    ll res = N * (N + 1) * (N + 2) / 6;
    rep(i, N - 1){
        ll a, b;
        cin>>a>>b;
        if(a < b) swap(a, b);
        res -= b * (N + 1 - a);
    }
    cout<<res<<endl;

}


Measured memory_bytes: 8016
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    string a, b, c;
    cin >> a >> b >> c;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());
    char s = a.back();
    a.pop_back();
    while (true) {
        if (s == 'a') {
            if (a.empty()) {
                cout << "A" << endl;
                return 0;
            }
            else {
                s = a.back();
                a.pop_back();
            }
        }
        else if (s == 'b') {
            if (b.empty()) {
                cout << "B" << endl;
                return 0;
            }
            else {
                s = b.back();
                b.pop_back();
            }
        }
        else if (s == 'c') {
            if (c.empty()) {
                cout << "C" << endl;
                return 0;
            }
            else {
                s = c.back();
                c.pop_back();
            }
        }
    }
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int x;
	cin >> x;
	
	if(x < 1200) cout << "ABC" << endl;
	else cout << "ARC" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(){
	int cnt=0;
	char c;
	string p,s,sum;
	cin>>s>>p;
	sum=s+s;
	for(int i=0;i<s.size();i++){
		string ans;
		for(int j=0;j<p.size();j++){
			c=sum[i+j];
			ans+=c;
		}
		if(ans==p){
			cnt++;
			break;
		}
	}
	if(cnt>0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x; cin >> x;
    long long m;
    if(x%11 == 0) m = x/11;
    else  m = x/11+1;
    if(m*11-x <= 4) cout << m*2 << endl;
    else cout << m*2-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;

#define ll long long
//#define int long long
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

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


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

signed main(){

	int N, L;
	string S[101];

	cin >> N >> L;
	for (int i = 0; i < N; i++) cin >> S[i];

	sort(S, S + N);

	string result ="";

	for (int i = 0; i < N; i++)
		result = result + S[i];

	cout << result << endl;


	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N, K = list(map(int, input().split()))

min_val = N
memory = [N]
n = N
while True:
    if n > K*2:
        n = n % K
        memory.append(n)
        if min_val > n:
            min_val = n
        continue
    n = abs(K-n)
    if n in memory:
        break
    memory.append(n)
    if min_val > n:
        min_val = n
    if min_val == 0:
        break
print(min_val)

Measured memory_bytes: 3060
from collections import Counter
import sys
sys.setrecursionlimit(200000)


def read():
    N, M, Q = map(int, input().split())
    ABCD = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        ABCD.append((a, b, c, d))
    return N, M, Q, ABCD


def iter_combinations(a, r):

    q = []

    def _dfs(a, r, m=[]):
        if r == 0:
            q.append(m)
        else:
            for i in range(len(a)):
                _dfs(a[i:], r-1, m + [a[i]])
    
    _dfs(list(a), r)
    return q
        

def solve(N, M, Q, ABCD):
    smax = 0
    for x in iter_combinations(range(1, M+1), N):
        sd = 0
        for a, b, c, d in ABCD:
            if x[b-1] - x[a-1] == c:
                sd += d
        smax = max(smax, sd)
    return smax


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("{}".format(outputs))


Measured memory_bytes: 23240
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if (a==b && b==c && c ==a)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 20820
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    string op;
    for(int i=0; i<9999999; i++){
        cin >> a >> op >>b;
        
        if(op=="?"){
            break;
        }
        if(op=="+"){
            cout << a+b << endl;
        }
        else if(op=="-"){
            cout << a-b << endl;
        }
        else if(op=="*"){
            cout << a*b << endl;
        }
        else if(op=="/"){
            cout << a/b << endl;
        }
    }
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
	#define fast ios::sync_with_stdio(false);cin.tie(NULL)

	using namespace std;
	typedef long long ll;

	int main() {
        fast;
    	ll n;
    	string ans;
    	cin >> n;
    	while(n > 0) {
            n -= 1;
        	ans += ('a' + n % 26);
        	n /= 26;
    	}
    	reverse(ans.begin(), ans.end());
    	cout << ans; 
    	
        return 0;
	}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>

int main(){

  char moji[11],ans[11]="\0";
  int j=0;

  scanf("%s",moji);
  int len = strlen(moji);
  
  for(int i=0; i<len ; i++){
    if( moji[i] != 'B'){
      ans[j] = moji[i];
      j++;
    }else{
      if( j==0 ){
        /*何もしない*/
      }else{
        ans[j-1] = '\0';
        j--;
      }
    }
  }

  printf("%s",ans);
  

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define M 100000

int parti(int *A,int p,int r){
  int x,i,j,a;

  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      a = A[i];
      A[i] = A[j];
      A[j] = a;
    }
  }
  a = A[i+1];
  A[i+1] = A[r];
  A[r] = a;
  return i+1;
}
  
int main(){
  int A[M],i,n,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  q = parti(A,0,n-1);

  for(i=0;i<n-1;i++){
    if(i == q){
        printf("[");
    }
    printf("%d",A[i]);
    if(i == q){
        printf("]");
    }
    printf(" ");
  }
  printf("%d\n",A[i]);

  return 0;
}


Measured memory_bytes: 2136
def calc(N, A):
    B = [(i + 1, A[i]) for i in range(N)]
    B.sort(key=lambda p: p[1])
    return ' '.join([str(b[0]) for b in B])


N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))

Measured memory_bytes: 24932
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


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

    ll d_sum = 0;
    ll d_cou = 0;

    rep(_, n) {
        ll d;
        ll c;
        cin >> d >> c;

        d_cou += c;

        d_sum += (d * c);

    }

    cout << (d_cou - 1) + ((d_sum - 1) / 9) << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int x,y;
	cin >> x >> y;
	
	int a[] = {1,3,5,7,8,10,12};
	int b[] = {4,6,9,11};
	
	int a_sum = 0;
	int b_sum = 0;
	
	for (int i = 0; i<7; i++){
		if (a[i] == x) a_sum++;
		if (a[i] == y) a_sum++;
	}
	for (int j = 0; j<4; j++){
		if (b[j] == x) b_sum++;
		if (b[j] == y) b_sum++;
	}
	
	if (a_sum == 2 || b_sum == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int A, B, M;
    cin >> A >> B >> M;
    vector<int>a(A),b(B);
    rep(i,A)cin >> a[i];
    rep(i,B)cin >> b[i];
    int ans = *min_element(a.begin(),a.end()) + *min_element(a.begin(), a.end());
    while(M--){
        int c,d,e;
        cin >> c >> d >> e;
        ans = min(ans, a[c-1]+b[d-1]-e);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.io.*;

class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		}
	}
}

Measured memory_bytes: 20692
#include<stdio.h>
int main(){
	int a,b;
	char op;
	scanf("%d %c %d",&a,&op,&b);
	if(op == '+'){
		printf("%d\n",a+b);
	}
	else if(op == '-'){
		printf("%d\n",a-b);
	}

	return (0);
}


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

int main(){
	int n,m,xx;
	cin>>n>>m>>xx;
	int c[n+1],a[n+1][m+1],x[n+1];
	memset(x,0,sizeof(x));
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}	
	int mi=100000000;
	while(x[0]==0){
		for(int i=n;i>=0;i--){
			if(x[i]==1){
				x[i]=0;
			}else{
				x[i]=1;
				break;
			}
		}
		int k[m+1],s=0;
		memset(k,0,sizeof(k));
		for(int i=1;i<=n;i++){
			if(x[i]==1){
				for(int j=1;j<=m;j++){
					k[j]+=a[i][j];
				}
				s+=c[i];
			}
		}
		int f=1;
		for(int i=1;i<=m;i++){
			if(k[i]<xx){
				f=0;
			}
		}
		if(f){
			mi=min(mi,s);
		}
	}
	cout<<(mi>10000000?-1:mi)<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include<math.h>
#include<iomanip>
 int main()
{
    double A,B,H,M;
    double r;
    std::cin>>A>>B>>H>>M;
    H=(H*60+M)*.5;
    H > M*6 ? r = H - M*6 : r = M*6 - H;
    if(r>180)
    {
        r=360-r;
    }
    r = r  * M_PI / 180.0;
    std::cout  <<std:: fixed<<std::setprecision(10)<< sqrt((double)(A*A+B*B)-(double)(2*A*B*cos(r))) << std::endl;
    return 0;
}


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

int main(){
int n,l;
  cin >> n >> l;
  string str[n+5];
  for(int i=0;i<n;i++){
   cin >> str[i]; 
  }
	sort(str,str + n);
  for(int i=0;i<n;i++){
  cout<<str[i];
  }
  return 0;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,ans=0;
  cin >> n >> k;
  if(k==0) {
    cout << n*n << endl;
    return 0;
  }
  /*k=2,b=3のとき
  a=1,2,3|4,5,6|7,8...
    1,2,0|1,2,0|1,2,0...*/
  for(int i=k+1; i<=n; i++) {
    ans+=n/i*(i-k)+max(0LL,n%i-k+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
function main()
  V=zeros(Int,3010,3010)
  dp=zeros(Int,3010,3010,4)
  R,C,K=parse.(Int,split(readline()))
  for i=1:K
    r,c,v=parse.(Int,split(readline()))
    V[r,c]=v
  end
  for i=1:R
    for j=1:C
        for k=1:4
        #sita
        dp[i+1,j+1,1]=max(dp[i+1,j+1,1],dp[i,j+1,k])
        dp[i+1,j+1,2]=max(dp[i+1,j+1,2],dp[i,j+1,k]+V[i,j])
        #migi
        dp[i+1,j+1,k]=max(dp[i+1,j+1,k],dp[i+1,j,k],k>1 ? dp[i+1,j,k-1]+V[i,j] : 0)
      end
    end
  end
  println(maximum(dp[R+1,C+1,:]))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 577424
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  long long int ans;
  string s1, s2;
  vector<char> dir;
  cin >> n;
  cin >> s1;
  cin >> s2;
  for (int i = 0; i < n; i++) {
    if (s1[i] == s2[i]) dir.push_back('v');
    else {
      dir.push_back('h');
      i++;
    }
  }
  if (dir[0] == 'v') ans = 3;
  else ans = 6;
  for (int i = 1; i < dir.size(); i++) {
    if (dir[i - 1] == 'h' && dir[i] == 'h') {
      ans *= 3;
    } else if (dir[i - 1] == 'v') {
      ans *= 2;
    }
    ans = ans % 1000000007;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int check1(int x){
	int res=x*0.08;
	return res;
}

int check2(int x){
	int res=x*0.10;
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int A,B;
	cin>>A>>B;
	int ok=-1;
	for(int i=1;i<=2000;i++){
		if(check1(i)==A && check2(i)==B){
			ok=i;
			break;
		}
	}
	cout<<ok;
	return 0;
}

Measured memory_bytes: 256
<?php
list($a, $b, $c) = ints();
for ($i = $a; $i <= $a * $b; $i += $a)
    if ($i % $b === $c) exit('YES');
echo 'NO';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

int main(){
  int n, x;
  cin >> n >> x;
  int m = 1e9;
  for (int i = 0; i < n; i++) {
    int k; cin >> k;
    x -= k;
    m = min(m, k);
  }
  cout << n + x / m << endl;
  return 0;
}

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

namespace AOJ.Volume0
{
    class Program0022
    {
        static void Main(string[] args)
        {
            int dataNum;
            var dataSet = new Queue<int[]>();

            while ((dataNum = int.Parse(Console.ReadLine())) != 0)
            {
                dataSet.Enqueue(Enumerable.Range(0, dataNum).Select(x => Console.ReadLine()).Select(int.Parse).ToArray());
            }

            foreach (var datas in dataSet)
            {
                int max = datas[0];

                for (int i = 0; i < datas.Length; i++)
                {
                    int sum = 0;

                    for (int j = 0; j < datas.Length - i; j++)
                    {
                        sum += datas[i + j];
                        if (sum > max)
                        {
                            max = sum;
                        }
                        else if(sum < 0)
                        {
                            break;
                        }
                    }
                }

                Console.WriteLine(max);
            }
        }
    }
}

Measured memory_bytes: 6380
program gluttony
    implicit none
    integer(8):: n,i
    integer(8), allocatable:: a(:), f(:)
    integer(8):: k, ans

    read*, n, k
    allocate(a(n), f(n))
    read*, a(:)
    read*, f(:)
    call merge_sort(a(:), 1_8, n)
    call merge_sort(f(:), 1_8, n)
    f(:) = [(f(i), i=n,1_8,-1_8)]

    if (sum(a(:)) <= k)then
        print*, 0
        stop
    end if
    ! print*, a(:)
    ! print*, f(:)
    block
        integer(8):: l=-1, r=1000000000000_8, c
        do while(l+1_8 < r)
            ans = 0_8
            c = (l+r)/2_8
            do i=1_8, n
                ans = ans + max(0_8, a(i) - c/f(i))
            end do
            if (ans <= k) then
                r = c
            else
                l = c
            end if
        end do
        print*, r
    end block

    contains
    recursive subroutine merge_sort(ar,start,end)
        integer(8):: ar(:), start, end

        if (end-start < 2_8) then
            if (ar(start) > ar(end)) then
            block; integer(8):: tmp
                tmp = ar(start)
                ar(start) = ar(end)
                ar(end) = tmp
            end block; end if
            return
        end if

        block
            integer(8):: c
            c = (start+end)/2_8
            call merge_sort(ar(:), start, c)
            call merge_sort(ar(:), c+1_8, end)
            call merge(ar(:), start, c, end)
        end block
    end subroutine

    subroutine merge(ar, start, c, end)
        integer(8):: ar(:), start, c, end
        integer(8),pointer:: tmp(:)
        allocate(tmp(end-start+1))

        block
            integer(8):: l,r,ti
            l=start
            r=c+1_8
            ti=1_8
            do while(l <= c .and. r <= end)
                if (ar(l) <= ar(r)) then
                    tmp(ti) = ar(l)
                    l=l+1_8
                else
                    tmp(ti) = ar(r)
                    r=r+1_8
                end if
                ti=ti+1_8
            end do

            if (r > end) then
                tmp(ti:) = ar(l:c)
            else
                tmp(ti:) = ar(r:end)
            end if
        end block

        ar(start:end) = tmp(:)
        deallocate(tmp)
    end subroutine
end program gluttony

Measured memory_bytes: 6180
/*
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;
 
int main()
{
    li n,a[2]={0},x;
    cin>>n;
    rep(i,n) cin>>x, a[x%2]++;
    if( a[1]%2==0 ) cout<<"YES\n";
    else cout<<"NO\n";
    
    return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int key[102];
		for (int i = 0;i < n;i++) {
			cin >> key[i];
		}
		string h = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		string s;
		cin >> s;

		for (int i = 0;i < s.size();i++) {
			if (s[i] >= 'a'&&s[i] <= 'z') {
				int a = s[i]-'a';
				a -= key[i%n];
				a %= 52;
				if (a < 0)a += 52;
				s[i] = h[a];
			}
			else {
				int a = s[i] - 'A' + 26;
				a -= key[i%n];
				a %= 52;
				if (a < 0)a += 52;
				s[i] = h[a];
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>

int main(){
    int N=0;
    scanf("%d",&N);
    int w[N];
    for(int i=0;i<N;i++){
        scanf("%d",&w[i]);
    }
    int SR=0,SL=0,ans[N];
    for(int t=1;t<=N-1;t++){
        for(int i=0;i<t;i++){
            SL+=w[i];
        }
        for(int i=0;N-1-i>t-1;i++){
            SR+=w[N-1 -i];
        }
        ans[t]=abs(SL-SR);
        SL=0,SR=0;
    }
    if(N==2){
        printf("%d",ans[1]);
        return 0;
    }
    for(;;){
        int count=0;
        for(int i=1;i<=N-2;i++){
            if(ans[i]>ans[i+1]){
                int t=ans[i]+ans[i+1];
                ans[i]=t-ans[i];
                ans[i+1]=t-ans[i+1];
            }else{
                count++;
            }
        }
        if(count==N-2){
            break;
        }
    }
    printf("%d",ans[1]);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

int main(){
	int a[1000]={},ans=0;
	string s;
	cin>>s;
	rep(i,0,4)a[s[i]]++;
	rep(i,0,1000){
		if(a[i]==2)ans+=2;
	}
	if(ans==4?print("Yes"):print("No"));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  vii v(m);
  fi(0, m) {
    cin >> v[i].second;
  }
  v[0].first = n - v[m - 1].second + v[0].second;
  fi(1, m) {
    v[i].first = v[i].second - v[i - 1].second;
  }
  sort(all(v));
  fi(0, m - 1)
    ans += v[i].first;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1792
from collections import defaultdict
n, m = map(int, input().split())
a = defaultdict(list)
for _ in range(m):
    p, s = input().split()
    a[p].append(1 if s == "AC" else 0)

ac, wa = 0, 0
for l in a.values():
    pcnt = 0
    for is_ac in l:
        if is_ac:
            ac += 1
            wa += pcnt
            break
        else: pcnt += 1

print(ac, wa)


Measured memory_bytes: 27016
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::vector<std::string> v { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    std::string s;
    std::cin >> s;
    std::cout << v.end() - std::find(v.begin(), v.end(), s) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n,i=0,out=0,score=0;
	bool fir=0,sec=0,thi=0;
	cin>>n;
	while(1){
		string s;
		cin>>s;
		if(s=="HIT"){
			if(thi) score++;
			thi=sec; sec=fir; fir=1;
		}if(s=="OUT"){
			out++;
			if(out==3){
				i++; o(score);
				if(i==n) break;
				fir=sec=thi=0;
				out=0; score=0;
				continue;
			}
		}if(s=="HOMERUN"){
			score++;
			if(fir) score++;
			if(sec) score++;
			if(thi) score++;
			fir=sec=thi=0;
		}
	}
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {

			double a = scanner.nextDouble();
			double b = scanner.nextDouble();
			double c = scanner.nextDouble();
			double d = scanner.nextDouble();
			double e = scanner.nextDouble();
			double f = scanner.nextDouble();

			double x = (c*e - f*b)/ (a*e - b*d);
	        double y = (c - a*x)/b;

			if (x == -0) {
				x = 0;
			}
			if (y == -0) {
				y = 0;
			}
			//System.out.println(list);
			System.out.println(String.format("%.3f", x) + " " + String.format("%.3f", y) );
		}
		scanner.close();

	}
}



Measured memory_bytes: 28444
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] chars = new int[256];
		for (int i = 0; i < 256; i ++) chars[i] = 0;
		while (scan.hasNextLine()) {
			String line = scan.nextLine();
			for (int i = 0; i < line.length(); i ++) {
				char ch = Character.toLowerCase(line.charAt(i));
				if (ch >= 'a' && ch <= 'z') chars[ch] ++;
			}
		}
		for (char ch = 'a'; ch <= 'z'; ch ++) System.out.println(ch + " : " + chars[ch]);	
	}
}

Measured memory_bytes: 26044