akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <std::uint_fast64_t Modulus>
class modint {
  using u64 = std::uint_fast64_t;

 public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept
      : a(x % Modulus) {
  }
  constexpr u64 &value() noexcept {
    return a;
  }
  constexpr const u64 &value() const noexcept {
    return a;
  }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(const modint rhs) noexcept {
    return *this *= ~rhs;
  }
  constexpr modint operator^(u64 exp) const noexcept {
    modint v = 1, x = *this;
    while (exp) {
      if (exp & 1) {
        v *= x;
      }
      x *= x;
      exp >>= 1;
    }
    return v;
  }
  constexpr modint operator~() const noexcept {
    return *this ^ (Modulus - 2);
  }
};

using mint = modint<1000000007>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> C(N);
    for (ll &x : C) cin >> x;
    sort(C.begin(), C.end());
    mint res = 0;
    for (int i = 0; i < N; i++) {
      mint e = mint(1) + mint(1) / 2 * max(0, N - i - 1);
      e /= 2;
      res += e * C[i];
    }
    mint p = 1;
    for (int i = 0; i < N; i++) p *= 2;
    res *= p;
    res *= p;
    cout << res.value() << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, i321) => {
        read_value!($next, i32) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input! { n: chars }
    if n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3] {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
N = int(input())
S = list(input())
L = 0
out = []
out2 = []
for i in range(N):
    X = S[i]
    if X=="(":
        L += 1
        out.append("(")
    elif X==")":
        if L>0:
            L += -1
            out.append(")")
        else:
            out2.append("(")
            out.append(")")
for i in range(L):
    out.append(")")
print("".join(out2)+"".join(out))

Measured memory_bytes: 61848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,i,b,a[1000]={0};
    cin>>x;
    a[1]=1;
    for(i=2;i<=x;i++)
    {
        b=i*i;
        while(b<=x)
        {
            a[b]=1;
            b*=i;
        }
    }
    for(i=x;i>=0;i--)
    {
        if(a[i]==1)
        {
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X;
  cin >> X;
  long long dep = 100;
  int ans = 0;
  while(true){
    ans++;
    dep += dep/100;
    if(dep >= X) break;
  }
  cout << ans << endl;
}

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

// #LIB#

using namespace std;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll a, p;
  cin >> a >> p;
  cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

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

	for (int i = 0; i < 3; i++) {
		if (n[i] == '1') {
			cout << 9;
		}
		else if(n[i]=='9'){
			cout << 1;
		}
	}
	cout <<  endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void Verify(bool eq, string val){
	if(!eq) {
		cout << "![" << val << "]" << endl;
		exit(0);
	}
}
int main(){
	const int magic = 38;
	vector<vector<int> > tables, res;
	for(int i = 1; i <= magic - 1; i++){
		vector<int> here;
		for(int j = 1; j <= magic; j++){
			here.push_back((i - 1) * magic + j);
		}
		tables.push_back(here);
	}
	for(int i = 0; i < magic - 1; i++){
		for(int j = 0; j < magic - 1; j++){
			vector<int> now;
			now.push_back(tables[i].back());
			for(int k = 0; k < magic - 1; k++){
				int ind = j + k * i;
				ind %= (magic - 1);
				now.push_back(tables[ind][k]);
			}
			res.push_back(now);
		}
	}
	const int gg = magic * (magic - 1) + 1;
	for(int i = 0; i < magic; i++){
		vector<int> now;
		for(int j = 0; j < magic - 1; j++) now.push_back(tables[j][i]);
		now.push_back(gg);
		res.push_back(now);
	}
	const int n = gg, k = magic;
	cout << n << " " << k << endl;
	for(int i = 0; i < n; i++, cout << endl) for(int j = 0; j < k; j++) cout << res[i][j] << " ";
	return 0;
}


Measured memory_bytes: 768
/**
 *   created: 03 June 2019  00:25:23
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int num;
		cin>>num;
		vl n,p;
		ll sum=0;
		ll mini = INFLL;
		rep(i,0,num){
			ll x;

			cin>>x;
			if(x<=0)
				n.push_back(x);
			else
				p.push_back(x);
			sum += abs(x);
			mini = min(mini, abs(x));
		}
		if(n.size()%2!=0){
			sum -= 2*mini;
		}
		cout<<sum;
	}
	return 0;
}


Measured memory_bytes: 1656
#include <stdio.h>
#include <ctype.h>

int main() {

  char ch[1200];
  int i,n;
  n=0;
  char a[1200];

  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;

    }
    
    
    n = n +1;
    
  }
  
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
  
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define ll long long
#define str string
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	ll n,m;
	cin>>n>>m;
	ll a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	ll cnt=0;
	if(m>=n){
		cout<<0;
		return 0;
	}
	sort(a,a+n);
	ll s=m;
	while(m--){
			a[n-1]=0;
			n--;
	}
	for(int i=0; i<n; i++){
		cnt+=a[i];
	}
	cout<<cnt;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;

int main(){
  int k,s,ans = 0;
  scanf("%d%d",&k,&s);

  if(s % k == 0 && s / k == 3){
    printf("1");
    return 0;
  }else if(k * 3 < s){
    printf("0");
    return 0;
  }

  rep(i,k + 1){
    rep(j,k + 1){
      int z = s - i - j;
      if(z < 0 || z > k) continue;
      ans++;
    }
  }

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

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
using Graph = vector<vector<ll>>;
#define all(x) (x).begin(), (x).end() //string の sort とかはこれ
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll A, B, M, x, y, c;

  cin >> A >> B >> M;
  vector<ll> a(A), b(B);
  for (i = 0; i < A; i++)
  {
    cin >> a[i];
  }
  for (i = 0; i < B; i++)
  {
    cin >> b[i];
  }
  ans = *min_element(all(a)) + *min_element(all(b));
  for (i = 0; i < M; i++)
  {
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(a[x] + b[y] - c, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func isSquare(n int) bool {
	if x := n % 10; x == 2 || x == 3 || x == 7 || x == 8 {
		return false
	}
	y := math.Sqrt(float64(n))
	return y == math.Trunc(y)
}

func main() {
	var n int
	fmt.Scan(&n)

	for i := n; i > 0; i-- {
		if isSquare(i) {
			fmt.Println(i)
			return
		}
	}
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define ff first
#define ss second

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=2e5+5;

int n, k;
int a[N], f[N];
map<int, int> m;
multiset<pair<int, int> > s;

int32_t main()
{
	IOS;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	int distinct=m.size();
	if(distinct<=k)
	{
		cout<<0;
		return 0;
	}
	for(auto it:m)
	{
		pair<int, int> p={it.ss, it.ff};
		s.insert(p);
	}
	int to_remove=distinct-k;
	int ans=0;
	for(auto it:s)
	{
		if(to_remove==0)
			break;
		ans+=it.ff;
		to_remove--;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 26880
#include<iostream>
#include<string>
using namespace std;
int main() {
	char a, b, c;
	string str;
	int JOI, IOI;
	while (cin >> str){
		JOI = 0;
		IOI = 0;
		a = str[0];
		b = str[1];
		c = str[2];
		for (int i = 0; i != str.size() - 2; i++) {
			if (b == 'O'&&c == 'I'){
				if (a == 'J'){
					JOI += 1;
				}
				if (a=='I'){
					IOI += 1;
				}
			}
			a = b;
			b = c;
			c = str[i + 3];
		}
		cout << JOI << endl << IOI << endl;
	}
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-6; 
const double pi = 3.1415926;
const int INF = 0x3f3f3f3f;
const int N = 20 + 5;
 
int main()
{
	int r;
	cin >> r;
	cout << 2 * pi * r << endl; 
    return 0;
}

Measured memory_bytes: 3788
def count_bigger(a, b):
    i = j = 0
    c = []
    while i < len(a) and j < len(b):
        if a[i] >= b[j]:
            j += 1
            continue
        c.append(len(b) - j)
        i += 1
    if len(c) < len(a):
        c += [0] * (len(a) - len(c))
    return c


def f(a, b, c):
    bc = count_bigger(b, c)
    for i in range(len(bc) - 1, 0, -1):
        bc[i - 1] += bc[i]
    i = j = ans = 0
    while i < len(a) and j < len(b):
        if a[i] >= b[j]:
            j += 1
            continue
        ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:]))
        i += 1
    return ans


def solve(string):
    n, s = string.split()
    r, g, b = [], [], []
    for i, _s in enumerate(s):
        if _s == "R":
            r.append(i)
        if _s == "G":
            g.append(i)
        if _s == "B":
            b.append(i)
    return str(f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9260
#include<stdio.h>
int main()
{
  int a,b,c,d,e,k,f,j,h,t,i,x,z,m,n,p;
  scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
  f=b-a;
  i=c-a;
  j=d-a;
  z=e-a;
  x=c-b;
  m=d-b;
  n=e-b;
  h=d-c;
  p=e-c;
  t=e-d;
  if(f<=k && i<=k && j<=k && z<=k && x<=k && m<=k && n<=k && h<=k && p<=k && t<=k){
    printf("Yay!");}
	
  else if(f>k || i>k || j>k || z>k || x>k || m>k || n>k || h>k || p>k || t>k){
    printf(":(");}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n, a, ans;
	cin >> n >> a;
	ans = n;
	for(int i = 2; i <= 50; i++){
		for(int root = 2; ; root++){
			long long p = 1;
			for(int j = 0; j < i; j++) p *= root;
			if(p >= n){
				long long sum = (root - 1) * i;
				p = 1;
				for(int j = 0; j < i; j++) p *= root - 1;
				while(p < n){
					p /= root - 1;
					p *= root;
					sum += 1;
				}
				ans = min(ans, sum + a * (i - 1));
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  ll now = 1;
  for (ll i = 0; i < N; ++i) {
    cin >> a.at(i);
    if (a.at(i) == now) {
      now += 1;
    }
  }
  now -= 1;
  if (now == 0) {
    cout << -1 << "\n";
  }
  else {
    cout << N - now << "\n";
  }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=55,INF=1<<30;
ll dp[MAX][2];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        string A,B,C;cin>>A>>B>>C;
        if(A=="0") break;
        int N=A.size();
        memset(dp,0,sizeof(dp));
        dp[N][0]=1;
        
        for(int i=N-1;i>=0;i--){
            for(int k=0;k<2;k++){
                for(int a=0;a<10;a++){
                    for(int b=0;b<10;b++){
                        for(int c=0;c<10;c++){
                            if(A[i]!='?'&&int(A[i]-'0')!=a) continue;
                            if(B[i]!='?'&&int(B[i]-'0')!=b) continue;
                            if(C[i]!='?'&&int(C[i]-'0')!=c) continue;
                            
                            if(i==0){
                                if(a==0||b==0||c==0) continue;
                            }
                            
                            if((a+b+k)%10==c){
                                dp[i][(a+b+k-c)/10]+=dp[i+1][k];
                                dp[i][(a+b+k-c)/10]%=mod;
                            }
                        }
                    }
                }
            }
        }
        
        cout<<dp[0][0]<<endl;
    }
}




Measured memory_bytes: 3228
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

constexpr int M = 33;
constexpr ll D = (1ll << M) - 1;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<PL> ps(n);
  FOR(p,ps) {
    cin >> p.first >> p.second;
  }
  ll parity = abs(ps[0].first + ps[0].second) % 2;
  FOR(p,ps) {
    if(abs(p.first + p.second) % 2 != parity) {
      cout << -1 << endl;
      return 0;
    }
  }
  if(parity) {
    cout << M << endl;
  } else {
    cout << M + 1 << endl;
    cout << 1 << " ";
  }
  REP(i,0,M) {
    cout << (1ll << i) << " ";
  }
  cout << endl;
  FOR(p,ps) {
    PL delta;
    if(parity) {
      delta = {p.first - D, p.second};
    } else {
      delta = {p.first - D - 1, p.second};
      cout << 'R';
    }
    ll du = (-delta.first + delta.second) / 2;
    ll dv = (-delta.first - delta.second) / 2;
    REP(i,0,M) {
      if((du & 1) == 0) {
        if((dv & 1) == 0) {
          cout << 'R';
        } else {
          cout << 'D';
        }
      } else {
        if((dv & 1) == 0) {
          cout << 'U';
        } else {
          cout << 'L';
        }
      }
      du >>= 1;
      dv >>= 1;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   998244353

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};

 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                    > pq;*/


int main()
{
   ll n;cin>>n;
    ll ans=0;
    for(ll a=1;a<n;a++)
    {
        ans+=(n-1)/a;
    }
    cout<<ans<<endl;

    return 0;
}



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

string seven(vector<int> A){
  string s="";
  for(int bit=0;bit<(1<<3);++bit){
    bitset<3> tmp(bit);
    int sum=A.at(0);
    s=to_string(A.at(0));
    for(int i=0;i<3;++i){
      if(tmp.test(i)){
        sum+=A.at(i+1);
        s+="+";
      }
      else{
        sum-=A.at(i+1);
        s+="-";
      }
      s+=to_string(A.at(i+1));
    }

    if(sum==7){
      s+="=7";
      break;
    }
  }
  return s;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(4);
  for(int i=3;i>=0;i--){
    A.at(i)=N%10;
    N/=10;
  }

  cout << seven(A) << endl;
  
}


Measured memory_bytes: 3672
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3104
#include <iostream>
#include <map>

using namespace std;

int A = 0, B = 0, C = 0;

map<int,int> mp;

int main(void){

    mp[5] = 0;
    mp[7] = 0;

    cin >> A >> B >> C;
    mp[A]++;
    mp[B]++;
    mp[C]++;

    if(mp[5] == 2 && mp[7] == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

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

    int n;
    std::cin >> n;
    std::vector<int> v( n );

    int sum = 0;
    for( auto& elem : v ){
        std::cin >> elem;
        sum += elem;
    }

    int maxNum = *std::max_element( v.begin(), v.end() );
    sum -= maxNum;

    if( maxNum < sum ){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    rep(i, n-m+1) rep(j, n-m+1) {
        bool f = true;
        rep(y, m) rep(x, m) f&=(s[i+y][j+x] == t[y][x]);
        if(f) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def solve(S):
    index = 1
    for word in S:
        if index % 2 != 0 and word == 'L':
            return 'No'
        elif index % 2 == 0 and word == 'R':
            return 'No'
        index += 1

    return 'Yes'


S = input()
print(solve(S))


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

int main(){
  int X, Y;
  cin >> X >> Y;
  
  for (int i = 0; i < X + 1; i++){
    if (2 * i + 4 * (X - i) == Y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}


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

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

gtyo = [0] *n
gtyo[0] = 1

gone = 0
t = 1

while t < n:
    gone = lis[gone] -1
    t += 1
    if gtyo[gone]:
        loop = t -gtyo[gone]
        t = n
    else:
        gtyo[gone] = t
        
if k -(gtyo[gone]-1)>= 0:
    res = (k- (gtyo[gone]-1)) % loop
else:
    res = k- (gtyo[gone]-1)
    
tmp = [i - gtyo[gone] for i in gtyo]

print(tmp.index(res)+1)

Measured memory_bytes: 32336
#前後の桁数
front,back = map(int,input().split())
#テスト対象
test_code = list(input())
#数列
seikai = ["0","1","2","3","4","5","6","7","8","9"]
flag = True

if test_code[front] == "-":
    for x in range(front + back + 1):
        if x != front:
            if (test_code[x] in seikai) is False:
                flag = False
                break
else:
    flag = False

if flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int INF = 1<<30;

int main(){
    int n;
    cin >> n;
    vector<int> m;
    m.push_back(1);
    int x = 6;
    while(x <= n){
        m.push_back(x);
        x *= 6;
    }
    x = 9;
    while(x <= n){
        m.push_back(x);
        x *= 9;
    }
    sort(all(m));

    vector<int> dp(n+1, INF);
    dp[0] = 0;
    for(int i = 0; i < m.size(); i++){
        int x = m[i];
        for(int j = 0; j <= n; j++){
            if (j+x > n) break;
            dp[j+x] = min(dp[j+x], dp[j]+1);
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 3692
import scala.io.StdIn

object Main extends App {

  val Array(w, a, b) = StdIn.readLine().split(" ").map(_.toInt)
  // a1
  // a2 = w + a
  // b1
  // b2 = w + b
  val (a1, a2, b1, b2) = (a, a + w, b, b + w)
  // a1 <= b1 <= a2 || 
  // a1 <= b2 <= a2    => 0

  // a2 < b1 => b1 - a2
  // b2 < a1 => b2 - a1
  val r = if ((a1 <= b1 && b1 <= a2) || (a1 <= b2 && b2 <= a2)) 0
  else if (a2 < b1) b1 - a2
  else a1 - b2
  println(r)
}


Measured memory_bytes: 27316
N = int(input())
A = list(map(int, input().split()))

flag = 1
cnt = 0
while flag:
    flag = 0
    # ????????????????????????
    for j in reversed(range(1, N)):
        # 1?????????????´???¨??????
        if A[j] < A[j-1]:
            # 1???????????????????°????????????°??????
            A[j], A[j-1] = A[j-1], A[j]
            flag = 1
            cnt += 1

print(' '.join(map(str, A)))
print(cnt)

Measured memory_bytes: 7664
#include <iostream>
std::string m[12];
void d(int x,int y){
	if(x>0&&m[y][x-1]-'0')m[y][x-1]='0',d(x-1,y);
	if(x<11&&m[y][x+1]-'0')m[y][x+1]='0',d(x+1,y);
	if(y>0&&m[y-1][x]-'0')m[y-1][x]='0',d(x,y-1);
	if(y<11&&m[y+1][x]-'0')m[y+1][x]='0',d(x,y+1);
	return ;
}
main(){
	while(1){
		int y=12;
		for(;y;y--)std::cin>>m[y-1];
		if(std::cin.eof())return 0;
		int r = 0;
		for(y=0;y<12;y++)for(int x=0;x<12;x++)if(m[y][x]-'0')r++,m[y][x]='0',d(x,y);
		std::cout<<r<<'\n';
	}
}

Measured memory_bytes: 0
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

from itertools import accumulate, repeat, chain

MOD = 10**9+7


N,A,B,C = map(int,input().split())

r = 100*modinv(100-C, MOD) % MOD
a = A*modinv(100, MOD)*r % MOD
b = B*modinv(100, MOD)*r % MOD

ap = tuple(chain((1,),accumulate(repeat(a,N),lambda x,y: x*y % MOD)))
bp = tuple(chain((1,),accumulate(repeat(b,N),lambda x,y: x*y % MOD)))

# print(a,b,ap,bp)

def it():
    numer = N
    denom = 1
    for m in range(N):
        yield numer*denom*(ap[N]*bp[m]+ap[m]*bp[N]) % MOD
        numer *= N+m+1
        numer %= MOD
        denom *= modinv(m+1, MOD)
        denom %= MOD


print(sum(it())*r % MOD)





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

int main(){
    int N; cin >> N;
    int H; cin >> H;
    vector<pair<int,int> > p(2 * N);
    rep(i, 0, N){
        p[i].second = 0;
        p[i + N].second = 1;
        cin >> p[i].first >> p[i+N].first;
    }
    sort(p.begin(), p.end(), greater<pair<int,int>>());
    int cnt = 0, sum = 0, i = 0;
    while(sum < H){
        if(p[i].second == 1){
            sum += p[i].first;
            i++;
            cnt++;
        }else{
            cnt += ((H - sum)-1) / p[i].first + 1;
            break;
        }
    }
    cout << cnt << endl;

}

Measured memory_bytes: 1792
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
s=[None]*N
for i in range(N):
    A,B=map(int,input().split())
    s[i]=(A+B,A,B)
s.sort(reverse=1)
i=0
t=0
a=0
while i<N:
    if t:
        a-=s[i][2]
    else:
        a+=s[i][1]
    t=not t
    i+=1
print(a)

Measured memory_bytes: 20944
#include<stdio.h>
int main(void){
    int n,i,a,data[100];
    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d",&data[i]);
    }

    for(i=n-1;i>=0;i--){

        printf("%d",data[i]);

        if(i!=0){
            printf(" ");
        }

    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  char s[N];
  scanf("%s",&s);
  int r,b;
  r=0;
  b=0;
  for(int i = 0;i < N;i++){
    if(s[i] == 'R'){
      r++;   
    }else if(s[i]=='B'){
      b++;
    }
  }
  if( r > b){
    printf("Yes");
  }else{
    printf("No");
  }
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,a[100010];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    int all=0;
    rep(i,n){
        cin>>a[i];
        all^=a[i];
    }
    rep(i,n)a[i]&=~all;
    vector<int>base;
    rep(i,n){
        int x=a[i];
        for(int y:base)chmin(x,x^y);
        if(x){
            for(int &y:base)chmin(y,y^x);
            base.pb(x);
            sort(all(base),greater<int>());
        }
    }
    int ans=0;
    for(int x:base)ans^=x;
    cout<<ans*2+all<<endl;
    return 0;
}

Measured memory_bytes: 4404
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  char s[30];
  int a[200]={};
  
  cin>>s;
  bool flg=false;
  for(int i=0;i<strlen(s);i++){
    if(a[s[i]]==1){
      flg=true;
    }
    a[s[i]]=1;
  }
  if(flg){
    cout<<"no\n";
  }else{
    cout<<"yes\n";
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();

        System.out.println( solve() );
    }

    private static String solve() {
        if( N >= 1000 ) return "ABD";
        else return "ABC";
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



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

int main() {
	int a, b; cin >> a >> b;
	int ans = max(a+b, a-b);
	ans = max(ans, a*b);
	cout << ans << endl;
}

Measured memory_bytes: 256
import math
import fractions
import collections
import itertools
from collections import deque
d=collections.deque()
S=list(input())
N=len(S)
cnt=0

amari=[0]*(N+1)
num=0
for i in range(N):
    d.append(int(S[i]))
#print(d)
for i in range(N):
    n=d.pop()
    num=(num+pow(10,i,2019)*n)%2019
    amari[i+1]=num
#print(amari)
#c=collections.Counter(amari)
#values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
amari.sort()
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
buf=0
#print(amari)
c=collections.Counter(amari)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
    cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt)



Measured memory_bytes: 95384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}

ll const mod =1e9+7;
int main() {
  int N,T; cin >> N >> T;
  vector<int> t(N);
  rep(i,N) cin >> t[i];
  int now=0,X=0,x;
  rep(i,N) {
    x = t[i];
    X+=min(x+T-now,T);
    now = x+T;
  }
  cout << X << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
#define fir first
#define sec second
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> Q;

const int inf1=1e9+9;
const ll inf2=1e16+9;
const ll mol=1e9+7;
const int maxn=1e5+9;
const ll maxx=1e12+9;

char s[200009];

int main()
{
    cin>>s;
    int ans=0;
    for(int i=0;s[i];i++) ans+=s[i]-'0';
    printf("%s\n",ans%9==0?"Yes":"No");
}


Measured memory_bytes: 3256
object Main extends App {
  val src: List[(String, Array[Int])] = io.Source.stdin.getLines.toList.map(_.split(" ")).map { case Array(a, b) => (a, Array(b)) }.sortWith(_._1 < _._1).map( tup => (tup._1, tup._2.map(_.toInt)))

  def step(li: List[(String, Array[Int])], tup: (String, Array[Int])): List[(String, Array[Int])] = li match {
    case Nil => List(tup)
    case h :: tail if h._1 == tup._1 => (h._1, h._2 :+ tup._2(0)) :: tail
    case h :: tail => h :: step(tail, tup)
  }

  val mergeNum: List[(String, Array[Int])] = (Nil /:[List[(String, Array[Int])]] src)(step)

  mergeNum.map { case (str, arr) => println(s"${str}\n${arr.sorted.mkString(" ")}")}
}



Measured memory_bytes: 44416
#include <iostream>
#include <algorithm>
using namespace std;
main () {
	string w, t;
	int a = 0;
	cin >> w;
	transform(w.begin(), w.end(), w.begin(), ::tolower);
	while (cin >> t, t != "END_OF_TEXT") {
		transform(t.begin(), t.end(), t.begin(), ::tolower);
		if (w == t) a++;
	}
	cout << a << endl;
}

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

int main(){
  ll n;
  scanf("%lld",&n);
  vector<ll> a(n*2),sum(n*2+1,0);
  for(int i=0;i<n;i++)scanf("%lld",&a[i]), a[n+i] = a[i];
  for(int i=0;i<2*n;i++)sum[i+1] = sum[i] + a[i];

  ll ans=0, l=0, r=0;
  while(l<n){
    while(r<l+n-1 && 3*(sum[r]-sum[l])<=sum[n])r++; r--;
    if(r-l>1){
      ll cur = sum[r]-sum[l], rem = sum[n]-cur, L=r, R=l+n;
      while(R-L>1){
	ll M = (L+R)/2;
	if(2*(sum[M]-sum[r])<rem)L = M;
	else R = M;
      }
	
      ll minv = 0;
      for(int i=0;i<2;i++){
	if(R-i<l+n && r<R-i)minv = max(minv, min(sum[R-i]-sum[r], sum[l+n]-sum[R-i]));
      }
      minv = min(minv, cur);
      ans = max(ans, minv);
    }
    l++; if(r<l)r++;
  }

  printf("%lld\n",ans);
}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int n;
int dns(vector<int> v, vector<int> c, int cost, int i) {
    if(i == n) {
        return cost;
    } else {
        int selected_cost = dns(v, c, cost + v[i] - c[i], i+1);
        int nonselected_cost = dns(v, c, cost, i+1);
        if(selected_cost > nonselected_cost) {
            return selected_cost;
        } else {
            return nonselected_cost;
        }
    }
    
}

int main() {
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for(int i=0; i<n; i++) {
        cin >> v[i];
    }
    for(int i=0; i<n; i++) {
        cin >> c[i];
    }
    cout << dns(v, c, 0, 0);

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
            int m;
            cin>>m;
            long long sum=0,ans=0;
            long long a[m+1],b[m+1];
            memset(b,0,sizeof(b));
            for(int j=1;j<=m;j++)
            {
                cin>>b[j];
                sum+=b[j];

            }
         //   cout<<sum<<endl;

               printf("%lld\n",sum-m);

}


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

using namespace std;

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    for(int i = 0; i < N; i++){
        cin >> x[i];
    }
    for(int i = 0; i < M; i++){
        cin >> y[i];
    }
    
    int x_max = *max_element(x.begin(), x.end());
    int y_min = *min_element(y.begin(), y.end());
    
    bool judge = false;
    for(int z = X + 1; z <= Y; z++){
        if(z <= x_max || z > y_min)     continue;
        
        cout << "No War\n";
        return 0;
    }

    cout << "War\n";
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $n);

for($i = 1; $i <= $n; $i++) {
  if($i % 3 === 0) {
    printf(' %d', $i);
    continue;
  }

  $m = $i;
  while($m) {
    if($m % 10 === 3) {
      printf(' %d', $i);
      break;
    }
    $m= (int)$m / 10;
  }
}
echo PHP_EOL;



Measured memory_bytes: 9228
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector <ll> sumaList(n + 1), sumbList(m + 1);
	ll sum = 0;
	for (ll i = 1; i <= n; i++) {
		ll tmp;
		cin >> tmp;
		sum += tmp;
		sumaList[i] = sum;
	}
	sum = 0;
	for (ll i = 1; i <= m; i++) {
		ll tmp;
		cin >> tmp;
		sum += tmp;
		sumbList[i] = sum;
	}
	ll ans = 0;
	for (ll i = n; i >= 0; i--) {
		ll tmp = k;
		tmp -= sumaList[i];
		if (tmp < 0) {
			continue;
		}
		auto itr = upper_bound(sumbList.begin(), sumbList.end(), tmp);
		ll tmpAns = i + (itr - sumbList.begin() - 1);
		if (tmpAns > ans) {
			ans = tmpAns;

		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 6424
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		if(0>=B-A) {
			System.out.println("delicious");
		}

		else if(X>=B-A) {
			System.out.println("safe");
		}

		else if(X<B-A) {
			System.out.println("dangerous");
		}
	}
}

Measured memory_bytes: 21844