akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	ll i,n,d,s=0,t;
	cin>>n;
	d = (ll)log10(n);
	t = n - (ll)pow(10,d);
	for(i=0 ; i<d ; i+=2){
		s += 9*pow(10,i);
		}
	if((d+1)%2) s += t+1;
	cout<<s<<nw;
	
	return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int dp[200005][2];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string t;
    cin >> t;
    for(int i=0; i<t.size(); i++)
    {
        if(t[i] == '?')
        {
            cout << 'D';
        }
        else
        {
            cout << t[i];
        }
    }
    return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N, T; cin >> N >> T;
  vector <int> A(N), deg(N);

  int m = 1e9;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    if (m > A[i]) m = A[i];
    deg[i] = A[i] - m;
  }
  sort(deg.begin(), deg.end(), greater<int>());

  int ans = 1;
  for (int i = 0; i < N - 1; i++){
    if (deg[i] == deg[i + 1]){
      ans++;
    }else{
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 998244353;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int n, m, k;
signed main() {
	COMinit();
	cin >> n >> m >> k;
	int ans = 0;
	for (int i = 0; i <= k; i++) {
			ans += ((COMB(n - 1, i) * m) % mod * mod_pow(m - 1, n - i - 1, mod)) % mod;
			ans %= mod;
	}
	cout << ans << endl;
	ggr
}


Measured memory_bytes: 11332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    vector<vector<int>> mi(N, vector<int>(N, INT_MAX));
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        mi[i][i] = a[i];
    }

    for (int i = 1; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            int l = j, r = j + i;
            if (r >= N)
                r -= N;

            if (r == 0)
                mi[l][r] = min(mi[l][N - 1], a[r]);
            else
                mi[l][r] = min(mi[l][r - 1], a[r]);
        }
    }

    ll ans = LLONG_MAX;
    for (int i = 0; i < N; ++i) {
        ll tmp = (ll)i * x;
        for (int j = 0; j < N; ++j) {
            int l = j - i, r = j;
            if (l < 0)
                l += N;
            tmp += mi[l][r];
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    std::string S;
    int w;

    std::cin >> S;
    std::cin >> w;

    for(int i=0;i<S.size();i+=w){
        std::cout << S[i];
    }

    std::cout << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[10];
	int i;
	for ( i = 0 ; i < 10 ; i ++){
		do{
			scanf("%d",&a[i]);
		} while (a[i] < 0 ||  a[i] > 10000);
	}
	
	int m, temp;
	for( m = 0 ; m < 3 ; m ++){
		for ( i = m ; i < 10 ; i ++){
			if ( a[m] < a[i]){
				temp = a[m];
				a[m] = a[i];
				a[i] = temp;
			}
		}
	}
	
	for(i = 0 ; i < 3; i ++){
		printf("%d\n",a[i]);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(void) {
	int ac = 0, bc = 0, cc = 0;
	char A[101], B[101], C[101], cache, player = 's';
	scanf("%s %s %s", A, B, C);
	cache = 's';
	while (1)
	{

		if (cache == 'a' || cache == 's') {
			player = 'A';
			if (A[ac + 1] == '\0')
			{
				break;
			}
			else
			{
				cache = A[ac];
				ac++;
			}
		}
		else {
			if (cache == 'b') {
				player = 'B';
				if (B[bc + 1] == '\0')
				{
					break;
				}
				else
				{
					cache = B[bc];
					bc++;
				}
			}
			else
			{
				if (cache == 'c') {
					player = 'C';
					if (C[cc + 1] == '\0')
					{
						break;
					}
					else
					{
						cache = C[cc];
						cc++;
					}
				}
			}
		}
	}
	printf("%c\n", player);
	return 0;
}

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

int main () {

    int D, G, p[11], c[11];
    cin >> D >> G;

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

    int ans = 1e9;

    for (int mask = 0; mask < (1 << D); mask++) {
        int s = 0, num = 0, rest_max = -1;
        for (int i = 0; i < D; i++) {
            if (mask >> i & 1) {
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }
            else {
                rest_max = i;
            }
        }

        if (s < G) {
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if (need >= p[rest_max]) {
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;

    return 0;
}

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

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

  // load
  vector <int> disk(n);
  for(int i = 0; i < n; i++)
    cin >> disk.at(i);

  // sort
  sort(disk.begin(), disk.end());

  // count up
  int count = 0;
  int prev  = 0;
  for(int i = 0; i < n; i++) {
    if (prev != disk.at(i))
      count++;
    prev = disk.at(i);
  }

  // output
  cout << count << endl;
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;
const LL LINF = 1e16;
const int MOD = 1e9 + 7;

LL func(int num) {
  LL result = 1;

  for (int i = 1; i <= num; i++) {
    result = (result * i) % MOD;
  }

  return result;
}

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

  LL ans;
  int N, M;
  cin >> N >> M;

  int sub = abs(N - M);

  if (sub >= 2) {
    cout << 0 << '\n';
    return 0;
  }

  if (sub) {
    // N と M が違う時
    ans = func(N) * func(M);
    ans = ans % MOD;
  } else {
    // N と M が同じ時
    ans = func(N) * func(M) * 2;
    ans = ans % MOD;
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#![allow(dead_code, unused_mut, unused_variables)]
use std::collections::VecDeque;
use std::io::*;
struct Io<'a> {
    r: BufReader<StdinLock<'a>>,
    w: BufWriter<StdoutLock<'a>>,
    buf: VecDeque<String>,
    buf_str: String,
}
impl<'a> Io<'a> {
    fn r<T: std::fmt::Debug, S: std::str::FromStr<Err = T>>(&mut self) -> S {
        if self.buf.len() == 0 {
            self.r.read_line(&mut self.buf_str).unwrap();
            for w in self.buf_str.split_whitespace() {
                self.buf.push_back(w.to_owned());
            }
            self.buf_str.clear();
        }
        self.buf.pop_front().unwrap().parse().unwrap()
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.w, "{}", v).unwrap();
    }
    fn iter<'b, T: std::fmt::Debug, S: std::str::FromStr<Err = T>>(
        &'b mut self,
    ) -> IoIter<'a, 'b, T, S> {
        IoIter {
            io: self,
            p: std::marker::PhantomData,
            q: std::marker::PhantomData,
        }
    }
}
struct IoIter<'a: 'b, 'b, T: std::fmt::Debug, S: std::str::FromStr<Err = T>> {
    io: &'b mut Io<'a>,
    p: std::marker::PhantomData<T>,
    q: std::marker::PhantomData<S>,
}
impl<'a, 'b, T: std::fmt::Debug, S: std::str::FromStr<Err = T>> Iterator for IoIter<'a, 'b, T, S> {
    type Item = S;
    fn next(&mut self) -> Option<S> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let r = BufReader::new(stdin.lock());
    let w = BufWriter::new(stdout.lock());
    let io = Io {
        r: r,
        w: w,
        buf: VecDeque::new(),
        buf_str: String::new(),
    };
    problem(io);
}

fn problem(mut io: Io) {
    let r: f64 = io.r();
    io.w(r * std::f64::consts::PI * 2.0);
}


Measured memory_bytes: 2208
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

char s[1000001];

int main(){

  fgets(s, sizeof(s), stdin);
  int res = 0, oc, ic, jc;
  int i, j, k, l;
  int slen = strlen(s);
  jc = oc = ic = 0;
  rep(i, slen){
    if(ic == 0 && oc == 0 && s[i] == 'J') jc++;
    else if(jc && ic == 0 && s[i] == 'O') oc++;
    else if(jc && oc && s[i] == 'I') ic++;
    else{
      if(jc >= oc && ic >= oc) res = max(res, oc);
      jc = oc = ic = 0;
      if(s[i] == 'J') jc++;
    }
  }

  if(jc >= oc && ic >= oc) res = max(res, oc);
  printf("%d\n", res);
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  
  int alp[26]={};
  rep(i,n){
    alp[s[i]-'a']++;
  }
  vector<char>word;
  rep(i,26){
    if(alp[i]) word.push_back((char)('a'+i));
  }
  int now=0;
  int ans=100;
  rep(i,word.size()){
    vector<int>num;
    rep(j,n){
      if(word[i]==s[j]){
        num.push_back(now);
        now=0;
      }
      else now++;    
    }
    sort(num.begin(),num.end(),greater<int>());
    int length = max(now,num[0]);
    now=0; 
    ans=min(ans,length);  
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

an.sort()
bn.sort()
cn.sort()

cnt = 0

for b in bn:
    a = bisect_left(an,b)
    c = bisect_right(cn,b)
    cnt += a * (n-c)
print(cnt)

Measured memory_bytes: 29484
#include <iostream>
#include <cstdio>
#include <cstring>
#include <deque>

using namespace std;

const int N = 100010;

int n;

int dist[N];
deque<int> dq;

inline void Update(int u, int v, int w) {
    if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        if (w) dq.push_back(v);
        else dq.push_front(v);
    }
    return;
}

void Dijkstra() {
    memset(dist, 0x3f, sizeof(dist));
    dist[1] = 1;
    dq.push_back(1);
    while (!dq.empty()) {
        int u = dq.front();
        dq.pop_front();
        Update(u, (u + 1) % n, 1);
        Update(u, u * 10 % n, 0);
    }
    return;
}

int main() {
    scanf("%d", &n);
    Dijkstra();
    printf("%d\n", dist[0]);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

ll gcd(ll a, ll b) {
    if(a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
   ll A, B, C, D;
   cin >> A >> B >> C >> D;

    //Cで割り切れる個数
    ll div_C = B / C - A / C + 1;
    //Dで割り切れる個数
    ll div_D = B / D - A / D + 1;
    //最小公倍数CDで割り切れる個数
    ll CD = lcm(C, D);
    ll div_CD = B / (CD) - A / (CD) + 1;
    if(A % C != 0) div_C--;
    if(A % D != 0) div_D--;
    if(A % (CD) != 0) div_CD--;
    cout << (B - A + 1) - (div_C + div_D - div_CD);
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  ll n,m;cin>>n>>m;
  if(n==1&&m==1)cout<<1<<endl;
  else if(n==1){
    cout<<m-2<<endl;
  }else if(m==1){
    cout<<n-2<<endl;
  }else{
    cout<<(ll)(n-2)*(m-2)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
	string d[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string in;
	cin >> in;
	LOOP(i,7){
		if(d[i]==in){
			cout << 7-i << endl;
		}
	}
}

// 2WPDX-JHP9X-JTM2T-3HWY4-RTMHZ


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg


int main()
{
	double a;
	cin >> a;

	cout << ll(a+pow(a,2)+pow(a,3))<<endl;


	return 0;
}



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

int main() {
  long long N1, N2;
  map<long long, long long> A;
  map<long long, long long> B;
  cin >> N1 >> N2;
  
  /* prior N1 */
  
  long long div = 2;
  long long N_tmp = N1;
    
  while(N1>=div*div) {
    if(N_tmp%div==0) {
      A[div]++;
      N_tmp /= div;
    } else {
      div++;
    }
  }
  
  if(N_tmp!=1) {
    A[N_tmp]++;
  }
  
  /* prior N2 */
  
  div = 2;
  N_tmp = N2;
    
  while(N2>=div*div) {
    if(N_tmp%div==0) {
      B[div]++;
      N_tmp /= div;
    } else {
      div++;
    }
  }
  
  if(N_tmp!=1) {
    B[N_tmp]++;
  }
  
  /* gcd */
  map<long long, long long> C;
  for(auto a:A) {
    long long tmp = a.first;
    if(B.find(tmp) != B.end()) {
      C[tmp] = min(a.second, B[tmp]);
    }
  }
  long long s = C.size();
  cout << s+1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;


int dp[20010];

int main() {
  int h, n;
  cin >> h >> n;
  rep(i,20011) dp[i] = INF;
  dp[0] = 0;
  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  for(int i = 1; i <= 20010; i++) {
    rep(j,n) {
      if(i>=a[j].first) dp[i] = min(dp[i],dp[i-a[j].first]+a[j].second);
    }
  }
  int ans = INF;
  for(int i = h; i<= 20010; i++) ans = min(ans,dp[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int mod(int a,int b)
{
if(a>b)
    return a-b;
return b-a;
}
int main()
{
    int n;
    cin>>n;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    vector<int> v1(n+1);
    v1[n]=0;
    v1[n-1]=mod(v[n-1],v[n]);
    for(int i=n-2;i>0;i--)
    {
        v1[i]=min(mod(v[i],v[i+1])+v1[i+1],mod(v[i],v[i+2])+v1[i+2]);
    }
    cout<<v1[1]<<endl;
    return 0;
}


Measured memory_bytes: 4036
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = a*2+b*2;
    System.out.println(area+" "+length);
  }
}


Measured memory_bytes: 26168
#include <iostream>

using namespace std;

int main(void){
  int n=3;
  int a[n];
  int tmp;

int i,j;
  for(i=0;i<n;i++){
    cin >> a[i];
  }


  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j-1]>a[j]){
        tmp=a[j];
        a[j]=a[j-1];
        a[j-1]=tmp;
      }
    }
  }
for(i=0;i<n;i++){
  if(i==2){
cout << a[i]<< endl;
  }else{
  cout << a[i] << ' ';
}
}
  //cout << a[] << endl;
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
/**/
int main()
{
	// freopen("test.in","r",stdin);
	// freopen("test.out","w",stdout);
	int a,b,c,d;
	read(a);read(b);read(c);read(d);
	cout<<a*b-b*c-a*d+c*d;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			map = new int[n][n];
			v = new boolean[n][n];
			m = 0;
			p = new int[2][n * n];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					map[i][j] = scanner.nextInt();
					if (map[i][j] < 0) {
						p[0][m] = i;
						p[1][m++] = j;
						v[i][j] = true;
					}

				}
			System.out
					.println(slove(p[0][0], p[1][0], 0, map[p[0][0]][p[1][0]]) ? "YES"
							: "NO");

		}
	}

	private boolean slove(int y, int x, int k, int sum) {
		if (m == k)
			return true;
		if (sum > 0)
			return false;
		if (sum == 0)
			return slove(p[0][k + 1], p[1][k + 1], k + 1,
					map[p[0][k + 1]][p[1][k + 1]]);
		for (int[] mo : move) {
			int ny = y + mo[0];
			int nx = x + mo[1];
			if (!isOK(ny, nx))
				continue;
			if (v[ny][nx])
				continue;
			v[ny][nx] = true;
			if (slove(ny, nx, k, sum + map[ny][nx]))
				return true;
			v[ny][nx] = false;
		}

		return false;
	}

	private boolean isOK(int ny, int nx) {
		return 0 <= ny && ny < n && 0 <= nx && nx < n;
	}

	int n, m;
	int[][] map;
	int[][] p;
	boolean[][] v;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
}

Measured memory_bytes: 27224
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

class combination
{
public:
  vector<int> fac, finv, inv;

  combination(int M)
  {
    fac = vector<int>(M, 1);
    finv = vector<int>(M, 1);
    inv = vector<int>(M, 1);

    for (int i = 2; i < M; i++)
    {
      fac.at(i) = fac.at(i - 1) * i % MOD;
      inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
      finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
    }
  }

  int P(int N, int K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * finv.at(N - K) % MOD;
  }

  int C(int N, int K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * (finv.at(K) * finv.at(N - K) % MOD) % MOD;
  }

  int H(int N, int K)
  {
    return C(N + K - 1, K);
  }
};

signed main()
{
  int N, M;
  cin >> N >> M;

  vector<int> Q;
  for (int p = 2; p * p <= M; p++)
  {
    int k = 0;
    while (M % p == 0)
    {
      M /= p;
      k++;
    }
    if (k != 0)
      Q.push_back(k);
  }
  if (M != 1)
    Q.push_back(1);

  combination com(111111);

  int ans = 1;
  for (int i = 0; i < Q.size(); i++)
  {
    ans *= com.H(N, Q.at(i));
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 2816
#include<stdio.h>

int main(){
  long long int N,a[5],min=1000000000000001L,num;
  int i;
  scanf("%lld",&N);
  for(i = 0;i < 5;i++){
    scanf("%lld",&a[i]);
    if(min > a[i]){min = a[i];}
  }
  num = N / min+4;
  if(N % min > 0){num++;}
  printf("%lld\n",num);
}

Measured memory_bytes: 128
package main

import (
  "fmt"
  "sort"
)

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

func main() {
  var n int
  fmt.Scan(&n)
  A := scanNums(n)
  sort.Ints(A)
  
  s := 0
  res := 0
  for i := 0; i < n; i++ {
    a := A[i]
    if s != 0 && s * 2 < a {
      res = 0
    }
  	s += a
    res++
  }
  
  fmt.Println(res)
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;

ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd( b, a%b);
}

int main(){
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)a[i] = abs(a[i]-x);
    ll res = a[0];
    for(int i=1;i<n;i++) res = gcd(res,a[i]);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A, B;
  cin >> A >> B;
  long long q = A * B;
  if(!(A == 1 || B == 1)) {
  if(q % 2 == 1) {
    cout << q / 2 + 1 << endl;
  }
  else {
    cout << q / 2 << endl;
  }
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using pll = pair<long long, long long>;
int N;
long long D, A;
vector<long long> X, H;

long long solve() {
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return X[i] < X[j];});

    long long res = 0;
    queue<pll> que;
    long long num = 0;
    for (auto i : ids) {
        while (!que.empty() && que.front().first < X[i]) {
            num -= que.front().second;
            que.pop();
        }
        H[i] -= num;
        if (H[i] <= 0) continue;
        res += H[i];
        que.push({X[i] + D*2, H[i]});
        num += H[i];
    }
    return res;
}

int main() {
    while (cin >> N >> D >> A) {
        X.resize(N); H.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> X[i] >> H[i];
            H[i] = (H[i] + A - 1) / A;
        }
        cout << solve() << endl;
    }
}

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

using namespace std;

const int N = 2*1e5+5;
const int MAX = 1e6+5;
int n;
bool danhDau[MAX];
int arr[N];

bool mark[MAX];

void Danhdau(bool danhDau[], int num){
    mark[num] = true;
    for(int i=num;i<MAX;i+=num){
        danhDau[i]=true;
    }
}

int main()
{
    int i, count=0;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>arr[i];
    sort(arr+1,arr+1+n);
    for(i=1;i<=n;i++){
        if(danhDau[arr[i]]==false){
             if(arr[i]==arr[i+1]){
                if (mark[arr[i]] == false) Danhdau(danhDau,arr[i]);
                continue;
             }
             count++;
        }
        if (mark[arr[i]] == false) Danhdau(danhDau,arr[i]);
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 6332
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

const int mod = 998244353;

li pw(li x, li y) {
    return y ? ((y & 1) ? pw(x, y - 1) * x % mod : pw(x * x % mod, y / 2)) : 1;
}

int gauss (vector < vector<int> > a) {
    int n = (int) a.size();
    int m = (int) a[0].size();
    int rank = 0;

    for (int col=0, row=0; col<m && row<n; ++col) {
        int sel = row;
        for (int i=row; i<n; ++i)
            if (a[i][col]) {
                sel = i;
                break;
            }
        if (!a[sel][col])
            continue;
        ++rank;
        for (int i=col; i < m; ++i)
            swap (a[sel][i], a[row][i]);
 
        for (int i=0; i<n; ++i)
            if (i != row && a[i][col]) {
                for (int j = col; j < m; ++j)
                    a[i][j] ^= a[row][j];
            }
        ++row;
    }
    return rank;
}

void solve(bool __attribute__((unused)) read) {
    int n, m;
	cin >> n >> m;
    vector <vector <int>> a(n);
    for (int i = 0; i < n; ++i) {
        a[i].resize(m);
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    int rank = gauss(a);
    // cout << rank << endl;
    // cout << pw(2, n) << endl;
    // cout << pw(2, n - rank) << endl;
    li ans = (pw(2, n) - pw(2, n - rank) + mod) % mod * pw(2, m - 1) % mod;
    ans = (ans % mod + mod) % mod;
    cout << ans << "\n";
}

// IDI OBRATNO KOD SMOTRET, RANO POKA SUBMITIT


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
lint mod = 1e9+7;

lint app() {
  int n;
  cin>>n;

  vector<lint> a(n);
  rep(i,n){
    cin>>a[i];
  }

  lint o=0;
  rep(j,60){
    lint t=0;
    rep(i,n){
      t+=(a[i]>>j&1);
    }
    lint add=t*(n-t);
    add%=mod;
    rep(k,j){
      add=add*2%mod;
    }
    o+=add;
    o%=mod;
  }

  return o;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<int> A,B;
vector<int> C;

ll dp[2][(1<<12)];
const ll INF=1e18;

void chmin(ll &a,ll b){
  if(a>b) a=b;
}

int main(){
  cin>>N>>M;
  A.resize(M);
  B.resize(M);
  C.resize(M,0);
  rep(i,M){
    cin>>A[i]>>B[i];
    int res=0;
    for(int j=0;j<B[i];j++){
      int c;
      cin>>c;
      c--;
      res|=(1<<c);
    }
    C[i]=res;
  }

  for(int i=0;i<2;i++) for(int j=0;j<(1<<N);j++) dp[i][j]=INF;
  int t=0;
  dp[0][0]=0;
  for(int i=0;i<M;i++){
    for(int j=0;j<(1<<N);j++){
      if(dp[t][j]==INF) continue;

      chmin(dp[1-t][j],dp[t][j]);
      chmin(dp[1-t][j|C[i]],dp[t][j]+A[i]);
    }
    for(int j=0;j<(1<<N);j++) dp[t][j]=INF;
    t=1-t;
  }

  if(dp[t][(1<<N)-1]==INF) cout<<-1<<endl;
  else cout<<dp[t][(1<<N)-1]<<endl;

  return 0;
}


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

int main(){
  	unsigned long long a[3];
  	unsigned long long ans = 0,memo1 = 0,memo2 = 0;
  	cin >> a[0] >> a[1] >> a[2];
  
  	if(a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0){
      cout << 0 << endl;
    }
  	else{
      sort(a,a+3);
      memo1 = a[0];
      memo2 = a[1];
      ans = memo1 * memo2;
      cout << ans << endl;
    }
	return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>
using namespace std;

int s[100][100];

int main() {
  int n, m, x, y, z, ans, mind, mini;
  int d[100], a[100];
  bool b[100];

  while (1) {
    scanf("%d", &n);
    if (!n) break;
    scanf("%d", &m);
    memset(s, 0, sizeof(int)*n*100);
    for (int i=0; i<m; i++) {
      scanf("%d,%d,%d", &x, &y, &z);
      s[x][y] = s[y][x] = z/100-1;
    }

    for (int i=0; i<n; i++) d[i] = INT_MAX;
    memset(b, 0, sizeof(bool)*n);
    d[0] = 0;
    a[0] = 0;
    ans = 0;
    while (1) {
      mind = INT_MAX;
      for (int i=0; i<n; i++) {
        if (!b[i] && d[i]<mind) {
          mind = d[i];
          mini = i;
        }
      }
      if (mind == INT_MAX) break;
      ans += s[a[mini]][mini];
      b[mini] = true;
      for (int i=0; i<n; i++) {
        if (!b[i] && s[mini][i]) {
          if (d[i] > s[mini][i]) {
            d[i] = s[mini][i];
            a[i] = mini;
          }
        }
      }
    }
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 1072
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#include <vector>
typedef long long ll;
typedef pair<ll, ll> PLL;
const int MAXN = 150005;
const ll INF = 1e12;
int n;
int son[MAXN][2], fa[MAXN], s[MAXN], val[MAXN];
int siz[MAXN]; ll dis[MAXN], mid;

vector<PLL> v[MAXN];
PLL ord[MAXN]; int tot;

void dfs_init(int o) {
    dis[o] = dis[fa[o]] + val[o], siz[o] = 1, s[o] = 0;
    if (!son[o][0]) {
        v[o].resize(1);
        return;
    }
    dfs_init(son[o][0]), dfs_init(son[o][1]);
    siz[o] += siz[son[o][0]] + siz[son[o][1]];
    v[o].resize(min(siz[son[o][0]], siz[son[o][1]]) << 1);
}

void insert(ll x, ll y) {
    ord[tot++] = make_pair(x, y);
}

bool dfs(int o) {
    if (!son[o][0]) {
        tot = 0, insert(dis[o], dis[o]), s[o] = tot;
        for (int i = 0; i < tot; i++)
            v[o][i] = ord[i];
        return 1;
    }
    int ls = son[o][0], rs = son[o][1];
    if (!dfs(ls) || !dfs(rs))
        return 0;
    if (s[ls] > s[rs])
        swap(ls, rs);
    for (int i = tot = 0, j = s[rs] - 1; i < s[ls] && ~j; i++) {
        while (~j && v[ls][i].first + v[rs][j].first - (dis[o] << 1) > mid)
            j--;
        if (j >= 0) {
            insert(v[ls][i].second, v[rs][j].second);
            insert(v[rs][j].second, v[ls][i].second);
        }
    }
    if (!tot)
        return 0;
    sort(ord, ord + tot);
    ll _min = INF; int cnt = 0;
    for (int i = 0; i < tot; i++)
        if (ord[i].second < _min)
            _min = ord[i].second, ord[cnt++] = ord[i];
    for (int i = 0; i < cnt; i++)
        v[o][i] = ord[i];
    return s[o] = cnt, 1;
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; i++) {
		scanf("%d %d", fa + i, val + i);
		son[fa[i]][s[fa[i]]++] = i;
	}
    dfs_init(1);
    ll l = 0, r = INF;
    while (l <= r)
        mid = (l + r) >> 1, dfs(1) ? r = mid - 1 : l = mid + 1;
    printf("%lld", l);
	return 0;
}


Measured memory_bytes: 43392
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int cardSet[4][13];
    int n;
    cin >> n;
    
    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            cardSet[i][j] = 0;
        }
    }
    
    for(int i=0; i<n; i++){
        char x; int y;
        cin >> x >> y;
        if(x == 'S'){
            cardSet[0][y-1] = 1;
        }else if(x == 'H'){
            cardSet[1][y-1] = 1;
        }else if(x == 'C'){
            cardSet[2][y-1] = 1;
        }else if(x == 'D'){
            cardSet[3][y-1] = 1;
        }
    }
    
    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            if(cardSet[i][j] != 1){
                if(i == 0){
                    cout << "S " << j + 1 << endl; 
                }else if(i == 1){
                    cout << "H " << j + 1 << endl;
                }else if(i == 2){
                    cout << "C " << j + 1 << endl;
                }else if(i == 3){
                    cout << "D " << j + 1 << endl;
                }
            }
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;
int r;
int yukuri(int a, int b){
  int r=1;
  while(r != 0){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main(int argc, char const *argv[]) {
  int N, X;
  std::cin >> N >> X;
  std::vector<int> x(N);
  int tmp;
  range(i, N){
    std::cin >> tmp;
    x[i] = abs(tmp - X);
  }
  tmp = x[0];
  ranges(i, 1, N){
    tmp = yukuri(max(tmp, x[i]), min(tmp, x[i]));
  }
  std::cout << tmp << '\n';
  return 0;
}


Measured memory_bytes: 640
s=input()
lst=[]
ans=0
for i in range(len(s)):
    if len(lst)==0:lst.append(s[i])
    elif lst[len(lst)-1]!=s[i]:
        lst.pop(len(lst)-1)
        ans+=1
        continue
    else:lst.append(s[i])
print(ans*2)

Measured memory_bytes: 3956
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())

# グラフを作成(隣接リスト表現)
graph = [[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, readline().split())
    graph[a].append(b)
    graph[b].append(a)

# distance
dist = [-1] * (n + 1)
point = [-1] * (n + 1)
dist[0] = 0
dist[1] = 0
point[0] = 0
point[1] = 0

q = deque([])
q.append(1)

while len(q) > 0:
    v = q.popleft()
    # キューから先頭頂点(調べる点）を取り出す

    # v から辿れる頂点をすべて調べる
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        point[i] = v
        q.append(i)

if - 1 not in set(point):
    print('Yes')
    for k in point[2::]:
        print(k)
else:
    print('No')


Measured memory_bytes: 39896
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

struct good{int weight,value;};
struct napsak{
    int N,W;
    vector<good> goods;
    VVi dp;
    napsak(int n,int w){
        init(n,w);
    }
    void init(int n,int w){
        N=n; W=w;
        dp.resize(N+1);
        REP(i,0,N+1) dp[i].resize(W+1);
        REP(i,0,N+1) REP(j,0,W+1) dp[i][j]=INF;
    }
    void add_goods(int w,int v){
        good g;
        g.weight=w,g.value=v;
        goods.pb(g);
    }
    int solve(){
        REP(i,0,N+1) REP(j,0,W+1) dp[i][j]=0;
        N=goods.size();
        REP(i,0,N){
            REP(j,0,W+1){
                chmax(dp[i+1][j],dp[i][j]);
                if(j+goods[i].weight<=W){
                    chmax(dp[i+1][j+goods[i].weight],dp[i][j]+goods[i].value);
                }
            }
        }
        return dp[N][W];
    }
};

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n,t;
    cin>>n>>t;
    Vi a(n),b(n);
    REP(i,0,n) cin>>a[i]>>b[i];

    napsak NS(n,t-1);
    REP(i,0,n){
        NS.add_goods(a[i],b[i]);
    }
    NS.solve();

    napsak NS2(n,t-1);
    REPR(i,n-1,-1){
        NS2.add_goods(a[i],b[i]);
    }
    NS2.solve();

    int ans=0;
    REP(i,0,n){
        int tmp=0;
        REP(j,0,t-1){
            chmax(tmp,NS.dp[i][j]+NS2.dp[n-i-1][t-1-j]);
        }
        chmax(ans,tmp+b[i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 141440
using System;

class Program {
    static void Main() {
        var n = int.Parse(Console.ReadLine());
        for (var i = 0; i < n; i++) {
            var l = Console.ReadLine().Split(' ');
            var k = int.Parse(l[0]);
            var p = int.Parse(l[1]);
            Console.WriteLine((k - 1) % p + 1);
        }
    }
}

Measured memory_bytes: 9188
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long int a;
    cin>>a;
    double b;
    cin>>b;
    int c=b*100+0.5;
    a=(a*c);
    a=a/100;
    cout<<a<<endl;
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

const ll MOD = 1e9+7;

ll solve_min(vector<ll>& plus, vector<ll>& minus, ll k)
{
    ll ans = 1;
    vector<ll> tmp;
    ll i;
    for(i = 0;i < plus.size();++i){
        tmp.push_back(plus.at(i));
    }
    for(i = 0;i < minus.size();++i){
        tmp.push_back(abs(minus.at(i)));
    }
    sort(all(tmp));
    for(i = 0;i < k;++i){
        ans *= tmp.at(i);
        ans %= MOD;
    }
    ans = MOD - ans;
    return ans;
}

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll zero = 0;
    vector<ll> plus;
    vector<ll> minus;
    for(i = 0;i < n;++i){
        cin >> a.at(i);
        if(a.at(i) == 0) ++zero;
        else if(a.at(i) > 0) plus.push_back(a.at(i));
        else if(a.at(i) < 0) minus.push_back(a.at(i));
    }
    if(plus.size() + minus.size() < k){
        cout << 0 << endl;
        return 0;
    }
    if(plus.size() + minus.size() == k){
        if(minus.size()%2 == 1){
            if(zero != 0){
                cout << 0 << endl;
                return 0;
            }
            ll ans = solve_min(plus, minus, k);
            cout << ans << endl;
            return 0;
        }
    }else{
        if(plus.size() == 0 && k%2 == 1){
            if(zero == 0){
                ll ans = solve_min(plus, minus, k);
                cout << ans << endl;
                return 0;
            }else{
                cout << 0 << endl;
                return 0;
            }
        }
    }
    ll ans = 1;
    sort(all(plus),greater<ll>());
    sort(all(minus));
    ll pi = 0;
    ll mi = 0;
    while(k){
        if(k == 1){
            ans *= plus.at(pi);
            ans %= MOD;
            break;
        }else{
            if(pi+1 >= plus.size()){
                ans *= abs(minus.at(mi));
                ans %= MOD;
                ++mi;
                ans *= abs(minus.at(mi));
                ans %= MOD;
                ++mi;
                k -= 2;
            }else if(mi+1 >= minus.size()){
                ans *= abs(plus.at(pi));
                ans %= MOD;
                ++pi;
                ans *= abs(plus.at(pi));
                ans %= MOD;
                ++pi;
                k -= 2;
            }else{
                ll tmp1 = plus.at(pi)*plus.at(pi+1);
                ll tmp2 = minus.at(mi)*minus.at(mi+1);
                if(tmp1 > tmp2){
                    tmp1 %= MOD;
                    ans *= tmp1;
                    ans %= MOD;
                    pi += 2;
                }else{
                    tmp2 %= MOD;
                    ans *= tmp2;
                    ans %= MOD;
                    mi += 2;
                }
                k -= 2;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8408
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ld r;cin>>r;
    ld cir=2*pi*r;
    cout<<setprecision(10)<<cir<<"\n";
}

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

int N, P;
string S;

int main() {
    cin >> S;
    int N = S.size();
    P = 2019;

    // 例外処理
    if (P == 2 or P == 5) {
        long long ans = 0;
        for (int r = 0; r < N; r++) {
            if ((S[r] - '0') % P == 0) {
                ans += r + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    // 各桁ごとにmodを求める
    vector<int> s(N+1);
    int ten = 1;
    for (int i = N-1; i >= 0; i--) {
        int num = (S[i] - '0') * ten;
        s[i] = num % P;
        ten *= 10;
        ten %= P;
    }

    // 累積和を求める
    for (int i = N-1; i >= 0; i--) {
        s[i] += s[i+1];
        s[i] %= P;
    }

    // 両端の数値を判定して答えを求めていく
    long long ans = 0;
    map<int, int> mp;
    mp[0] = 1;
    for (int i = N-1; i >= 0; i--) {
        ans += mp[s[i]];
        mp[s[i]]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,ans=0;
    cin >> n;
    for(int i=1;i<=n;i++){
    	int x=i,c=0;
    	while(x)x/=10,c++;
    	if(c&1)ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        while(in.hasNext()){
            int a = in.nextInt();
            int b = in.nextInt();
            int n = in.nextInt();
            int x = n / 2;
            int y = n % 2;
            for (int i = 0; i < x; i++) {
                if(a % 2 != 0){
                    a --;
                }
                a = a / 2;
                b += a;
                if(b % 2 !=0){
                    b --;
                }
                b = b / 2;
                a += b;
            }
            if(y != 0){
                if(a % 2 != 0){
                    a --;
                }
                a = a / 2;
                b += a;
            }
            System.out.println(a + " " + b);
        }
    }
}

Measured memory_bytes: 23124