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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	ll k; cin>>k;
	map<int,ll> ct;
	for (int i=0; i<n; i++) {
		int a,b; cin>>a>>b; ct[a]+=b;
	}
	ll cur=0;
	for (const auto &it : ct) {
		if(cur+it.second>=k) {
			cout<<it.first<<"\n";
			return 0;
		}
		cur+=it.second;
	}
	return 0;
}

Measured memory_bytes: 4224
from math import gcd
k=int(input())
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      
      cnt+=gcd(gcd1,q)
 
      
print(cnt)

Measured memory_bytes: 68392
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;
int n;

const int INF = 1 << 29;
typedef long long LL;
typedef pair<int, LL> P;
map<P, LL> dp;
vector<int> nums;
int ans = 0;

LL dfs(int m, LL v)
{
	if(v < 0LL || v > 20LL) return 0LL;
	if(dp[P(m, v)] > 0LL)
		return dp[P(m, v)];

	LL res = 0LL;
	if((n - 1) == m)
		res = v == nums[n - 1] ? 1LL : 0LL;
	else
		res = dfs(m + 1, v - (LL)nums[m]) + dfs(m + 1, v + (LL)nums[m]);

	return dp[P(m, v)] = res;
}

int main(void)
{
	while(cin >> n && n)
	{
		nums.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> nums[i];
		}
		dp = map<P, LL>();
		cout << dfs(1, nums[0]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI   3.14159265358979323846264338327950

#define PB push_back 
#define F first
#define S second
 
#define ll 	 long long int

#define mod  1000000007





int main()
{
	FAST;
	string s;
	cin >> s;
	if(s[2] == s[3]  &&  s[4] == s[5]){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3624
using System;

namespace ABC113_A
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] inStr = Console.ReadLine().Split(' ');
			int x = int.Parse(inStr[0]);
			int y = int.Parse(inStr[1]);
			
			Console.WriteLine(x + y / 2);
		}
	}
}

Measured memory_bytes: 13140
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::collections::HashMap;

fn main() {
    let N = get!(usize);
    let s = get!(String; N);

    // ソート後の各文字列について、各度数をもとに数え上げればよい
    let mut c = HashMap::new();
    for t in s {
        let mut x = t.chars().collect::<Vec<_>>();
        x.sort();
        let y = c.entry(x).or_insert(0_i64);
        *y += 1;
    }
    let ans = c.values().map(|y| y * (y - 1) / 2).sum::<i64>();

    println!("{}", ans);
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int a, b;
  cin >> a >> b;
  if (a > 9 || b > 9) cout << -1 << endl;
  else cout << a * b << endl;
  return 0;
}


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

int main(){
    string str[4] = {"dream", "dreamer", "erase", "eraser"};
    string s;
    bool flg;
    cin >> s;
    reverse(s.begin(), s.end());
    for(int i=0; i<4; i++){
        reverse(str[i].begin(), str[i].end());
    }
    
    for(int i=0; i<s.size();){
        flg = false;
        for(int j=0; j< 4;j++){
            string c = str[j];
            if(s.substr(i,c.size())==c){
                flg = true;
                i += c.size();
            }
            
        }
        if(flg==false){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES"<< endl;
    
    
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int n,m,a[1000];

map<int,int> c;

int main() {
    while(true) {
        cin >> n >> m;
        if(n == 0)break;
        rep(i,n){
            cin >> a[i];
            c[a[i]] = 0;
        }
        rep(i,n) {
            c[a[i]]++;
        }
        sort(a,a+n);//aをソート

        int ans = -1;
        rep(i,n) {
            int* itr = upper_bound(a,a+n,m - a[i]);//m-a[i]<a[j] となる最小のjのa[j]へのポインタを取得
            if(itr - a == 0) {//m - a[i]>=a[j]を満たすjが存在しない時
                continue;
            }
            itr--;//ポインタを一つ減算してm-a[i]>=a[j]となる最大のjのa[j]へのポインタを取得
            if(*itr == a[i] && c[a[i]] < 2) {//境界のものがa[i]だった時
                if(itr - a == 0) {//a[i]未満のものがない時
                    continue;
                }
                itr--;//さらに一つ前に
            }
            ans = max(ans,*itr + a[i]);
        }
        if(ans == -1)cout << "NONE" << endl;
        else cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3620
import numpy as np

# 終点でソート
N, M = map(int, input().split())
AB = np.array([input().split() for _ in range(M)], np.int32)
AB = sorted(AB, key=lambda x: x[1])
ans, end = 0, 0
for a, b in AB:
    # print(end, a, b)
    if end <= a:
        ans += 1
        end = b
print(ans)


Measured memory_bytes: 46900
a = [str(i) for i in input()]

b = 0
c = 0

for i in range(len(a)):
    if a[i] == 'A' or a[i] == 'C' or a[i] == 'G' or a[i] == 'T':
        b += 1
        if b > c:
            c = b
    else:
        b = 0

print(c)

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

ll N,M;
ll dp[1010][1010];

int main(){
    cin >> N >> M;
    vector<ll> x(N+1),y(N+1),z(N+1);
    
    for(int i=0;i<N;++i){
        cin >> x[i] >> y[i] >> z[i];
    }

    ll res = -INF;
    for(int a=-1;a<=1;++a)for(int b=-1;b<=1;++b)for(int c=-1;c<=1;++c){
        if(a)if(b)if(c){
            for(int i=0;i<=N;++i)for(int j=0;j<=M;++j) dp[i][j] = -INF;
            dp[0][0] = 0;
            for(int i=0;i<N;++i){
                for(int j=0;j<=M;++j){
                    ll d = a * x[i] + b * y[i] + c * z[i];
                    dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
                    dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + d);
                }
            }
        }
        res = max(res, dp[N][M]);
    }
    cout << res << endl;
}

Measured memory_bytes: 8192
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


vector<int> primes;
vector<bool> mark(1000002);
void sieve(int n)
{
    int i, j, limit = sqrt(n*1.) + 2;

    mark[1] = 1;

    for(i = 4; i<=n; i+=2) mark[i] = 1;

    primes.push_back(2);

    for(i = 3; i <= n; i += 2)
    {
        if(!mark[i])
        {
            primes.push_back(i);

            if(i<=limit)
            {
                for(j = i*i; j <= n; j += i*2)
                {
                    mark[j] = 1;
                }
            }
        }
    }
}
void task()
{
    //code here...
    ll n;
    
    cin >> n;
    sieve(sqrt(n+1));
    
    int p = 1, cnt = 0, i = 0, ans = 0, len = (int)primes.size();
    while(i<len && primes[i] <= n){
		if(n%primes[i]==0){
			cnt++;
			//cout << "cnt = " << cnt << ' ' << p << "\n";
			if(cnt==p){
				ans++;
				cnt = 0;
				p++;
			}
			n /= primes[i];
		}
		else{
			i++;
			cnt = 0;
			p = 1;
		}
		//cout << primes[i] << ' ' << n << ' ' << ans << "\n";
	}
	
	if(n>1) ans++;
	
	cout << ans << "\n";
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}



Measured memory_bytes: 3988
// Problem : B - Golden Coins
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int main(){
	int x;
	cin >> x;
	
	int ans = 0;


    ans += (x / 500) * 1000;
	
	x = x % 500;
	
	ans += (x / 5) *  5;
	
	
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll unsigned long long

const ll MOD = 1000000000000000000;

int main() {
	//入力
	ll n,a,b;
	cin >> n >> a >> b;

	//処理
	ll x = 0;
	ll ans = 0;
	x = floor(n / (a + b));
	if (n - (a + b) * x <= a)
		ans = x * a + n - (a + b) * x;
	else
		ans = x * a + a;

	//出力
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair<int,int>
#define fi first
#define se second
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,b,a) for (int i=(b);i>=(a);--i)
typedef long long LL;
inline int read(){
    int x=0,f=1; char ch=getchar();
    while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    return x*f;
}

const int MAXN=300005;
int n,m,a[MAXN];
LL gcd(LL i,LL j){ return j==0?i:gcd(j,i%j); }
int main(){
	n=read(); m=read();
	FOR(i,1,n) a[i]=read();
	sort(a+1,a+1+n);
	LL tmp=a[1];
	FOR(i,1,n) tmp=gcd(tmp,a[i]);
	FOR(i,1,n)
	if (a[i]>=m) {
		LL x=(a[i]-m)/tmp;
		if (x*tmp+m==a[i]) { printf("POSSIBLE\n"); return 0;} 
	}
	printf("IMPOSSIBLE\n");
    return 0;
}

/*
*/


Measured memory_bytes: 640
N,K = (int(x) for x in input().split())

V_arr = [int(x) for x in input().split()]

ans = 0
for l in range(K+1):
    if l > N:
        continue
    l_arr = V_arr[:l]
    for r in range(K+1-l):
        if l == 0 and r == 0:
            continue
        if l+r > N:
            continue
        r_arr = V_arr[N-r:]
        have_arr = sorted(l_arr+r_arr)
        delete_top = 0
        for d in range(K-l-r):
            if d >= l+r:
                break
            if have_arr[d] > 0:
                break
            delete_top = d+1
        ans = max(ans, sum(have_arr[delete_top:]))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='h'){
            i++;
            if(s[i]!='i'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int LOG = 20;
const int maxN = 2e5 + 10;
int lg[maxN];
pair < int, int > mn[2][LOG][maxN];
int fenw[2][maxN];
void upd(int v, int by, int c) {
    while (v <= n) {
        fenw[c][v] += by;
        v = (v | (v - 1)) + 1;
    }
}
int get(int c, int r) {
    int ans = 0;
    while (r > 0) {
        ans += fenw[c][r];
        r &= (r - 1);
    }
    return ans;
}
int get(int c, int l, int r) {
    return get(c, r) - get(c, l - 1);
}
int p[maxN];
const int INF = (int)1e9;
bool used[maxN];
int fri[maxN];

int after[maxN];
int nxt[maxN];
pair < int, int > get_mn(int l, int r, int c) {
    int k = lg[r - l + 1];
    return min(mn[c][k][l], mn[c][k][r - (1 << k) + 1]);
}
int pp[maxN];
vector < int > g[maxN];
int deg[maxN];
bool ff[maxN];
int bck[maxN];
int solve(int l, int r, int need) {
    if (l > r) return -1;
    auto it = get_mn(l, r, need);
    auto pit = get_mn(it.second + 1, r, need ^ 1);
    pp[it.second] = pit.first;
    ff[it.second] = true;
    int c1 = solve(l, it.second - 1, need);
    int c2 = solve(it.second + 1, pit.second - 1, need ^ 1);
    int c3 = solve(pit.second + 1, r, need);
    g[it.second].emplace_back(c1);
    g[it.second].emplace_back(c2);
    g[it.second].emplace_back(c3);
    return it.second;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    vector < pair < int, int > > gg;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        bck[p[i]] = i;
        gg.emplace_back(p[i], i);
        mn[(i % 2) ^ 1][0][i] = make_pair(INF, i);
        mn[(i % 2)][0][i] = make_pair(p[i], i);
    }
    lg[1] = 0;
    for (int i = 2; i <= n; i++) {
        lg[i] = lg[i - 1];
        if (!(i & (i - 1))) lg[i]++;
    }
    for (int step = 0; step < 2; step++) {
        for (int j = 0; j + 1 < LOG; j++) {
            for (int i = 1; i + (1 << (j + 1)) -  1 <= n; i++) {
                mn[step][j + 1][i] = min(mn[step][j][i], mn[step][j][i + (1 << j)]);
            }
        }
    }


    int r = solve(1, n, 1);
    set < int > t;
    t.insert(p[r]);
    while (!t.empty()) {
        auto v = *t.begin();
        t.erase(v);
        v = bck[v];
        cout << p[v] << " " << pp[v] << " ";
        for (int c : g[v]) {
            if (c == -1) continue;
            t.insert(p[c]);
        }
    }
    return 0;
}


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

int main(){

    int i,j=0,num,shuf;
    char moji[400],mojix[400],mojiy[400],mojiz[400][400],*p;
    
        
  while(1){
	  
    scanf("%s",moji);
     
    if (strcmp(moji,"-")==0) break;   
    
    scanf("%d",&num);

    p=moji;

    //printf("%s\n",moji);
    
    for(i=1;i<=num;++i){
      scanf("%d",&shuf);
      
      strcpy(mojix,p+shuf);
      strncat(mojix,p,shuf);
      
      //printf("%d %s\n",shuf,mojix);
      
      strcpy(mojiy,mojix);   
      
      p=mojiy;
         
     }
     strcpy(mojiz[j],mojix);   
     //printf("%s\n",mojix);      
     ++j;
  }
  
     for(i=0;i<j;++i) printf("%s\n",mojiz[i]);    
 
     return 0;
}

Measured memory_bytes: 608
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/math/common_factor.hpp> 
#include<bits/stdc++.h>
using namespace std;
template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
	out<<p.first<<' '<<p.second;
	return out;
}
 
template<class T1,class T2>
istream& operator >> (istream& in,pair<T1,T2> &p)
{
	in>>p.first>>p.second;
	return in;
}
 
template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
	for(auto &x:v)
		in>>x;
	return in;
}
 
template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
	for(auto &x:v)
		out<<x<<'\n';
	return out;
}
 
template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
	for(auto x:v)
		out<<x<<' ';
	return out;
}
 
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pii pair<int,int>
#define F first
#define S second
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;
#define maxn 200005
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// int pow(int a, int b, int m)
// {
// 	int ans=1;
// 	while(b)
// 	{
// 		if(b&1)
// 			ans=(ans*a)%m;
// 		b/=2;
// 		a=(a*a)%m;
// 	}
// 	return ans;
// }
 
// int fact[N], invfact[N];
 
// int modinv(int k)
// {
// 	return pow(k, MOD-2, MOD);
// }
 
// void precompute()
// {
// 	fact[0]=fact[1]=1;
// 	for(int i=2;i<N;i++)
// 	{
// 		fact[i]=fact[i-1]*i;
// 		fact[i]%=MOD;
// 	}
// 	invfact[N-1]=modinv(fact[N-1]);
// 	for(int i=N-2;i>=0;i--)
// 	{
// 		invfact[i]=invfact[i+1]*(i+1);
// 		invfact[i]%=MOD;
// 	}
// }
 
// int nCr(int x, int y)
// {
// 	if(y>x)
// 		return 0;
// 	int num=fact[x];
// 	num*=invfact[y];
// 	num%=MOD;
// 	num*=invfact[x-y];
// 	num%=MOD;
// 	return num;
// }
bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
long long power(long long x, long long int y, long long mod) { 
    long long res = 1; 
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y >> 1; 
        x =(x*x)%mod; 
    } 
    return res; 
}
int main()
{
    ios;
    int n,c=0;
  cin >> n;
  rep(i,1,n+1)
  {
      int x;
      cin >>x;
    //cin >>a[i];
    if (x%2==1 && i%2==1)
      c++;
  } 
  cout <<c<<endl;
    return 0;
}

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

#define x first
#define y second
#define pb push_back
#define Set(i, v) memset(i, v, sizeof i)
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

typedef long long LL;

using namespace std;

const int Mod = 1e9 + 7;
const int N = 1e5 + 10, M = N << 2;

int Begin[N], Next[M], to[M], len[M], e = 1;

void add(int u, int v, int w){
	len[++e] = w, Next[e] = Begin[u], Begin[u] = e, to[e] = v;
}

struct Node{
	int o;
	LL d;

	Node(int _o = 0, LL _d = 0): o(_o), d(_d) {}

	bool operator < (const Node& B) const{
		return d > B.d;
	}
};

int n, m, S, T;
bool vis[N];
LL dis[N];
vector<int> G[N];

void Dijkstra(){
	priority_queue<Node> q;
	memset(dis, 0x3f, sizeof dis);
	dis[S] = 0;
	q.emplace(S, 0);
	while(!q.empty()){
		Node s = q.top(); q.pop();
		if(vis[s.o]) continue;
		vis[s.o] = true;

		for(int i = Begin[s.o]; i; i = Next[i]){
			int u = to[i];
			if(dis[u] > s.d + len[i]){
				G[u].clear();
				G[u].pb(s.o);
				dis[u] = s.d + len[i];
				q.emplace(u, dis[u]);
			}
			else if(dis[u] == s.d + len[i]) G[u].pb(s.o);
		}
	}
}

int f[N], g[N];
bool imp[N];

void DFS_init(int o){
	imp[o] = true;
	for(int v : G[o]){
		if(dis[v] > dis[o]) continue;
		if(!imp[v]) DFS_init(v);
		G[v].pb(o);
	}
}

void add(int &x, int y){
	x += y;
	if(x >= Mod) x -= Mod;
}

int DFS_workpre(int o){
	if(vis[o]) return f[o];
	vis[o] = true;
	f[o] = 0;
	for(int v : G[o]){
		if(!imp[v] || dis[v] < dis[o]) continue;
		add(f[o], DFS_workpre(v));
	}
	return f[o];
}

int DFS_worksuf(int o){
	if(vis[o]) return g[o];
	vis[o] = true;
	g[o] = 0;
	for(int v : G[o]){
		if(!imp[v] || dis[v] > dis[o]) continue;
		add(g[o], DFS_worksuf(v));
	}
	return g[o];
}

int main(){

	scanf("%d%d%d%d", &n, &m, &S, &T);
	For(i, 1, m){
		int u, v, d;
		scanf("%d%d%d", &u, &v, &d);
		d *= 2;
		add(u, v, d), add(v, u, d);
	}
	Dijkstra();
	DFS_init(T);

	LL D = dis[T] / 2;
	
	Set(vis, false);
	vis[T] = true, f[T] = 1;
	DFS_workpre(S);

	Set(vis, false);
	vis[S] = true, g[S] = 1;
	DFS_worksuf(T);

	LL ans = 1ll * f[S] * g[T] % Mod;
	For(i, 1, n) if(imp[i] && dis[i] == D) ans = (ans + Mod - 1ll * f[i] * g[i] % Mod * f[i] % Mod * g[i] % Mod) % Mod;
	For(i, 1, n) if(imp[i] && dis[i] < D)
		for(int j : G[i]) if(imp[j] && dis[j] > D){
			ans = (ans + Mod - 1ll * g[i] * f[j] % Mod * g[i] % Mod * f[j] % Mod) % Mod;
		}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 17232
#include<stdio.h>
int main(){
  int N,K;
  scanf("%d%d",&N,&K);
  int i;
  int X=1;
  for(i=0;i<N;i++){
    if(X<=K){
    X=2*X;
    }else{
    X=X+K;
    }  
  }
  printf("\n%d",X);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for ( int i=0;  i<n; i++)
#define REP(i, n) for ( int i=1; i<=n; i++)
#define fi first
#define sc second 
#define pb push_back
#define pf push_front 
#define mod 1000000007
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double const pi = 3.141592653589793238462643383279502;

    ld r; cin >> r;
//    cout << M_PI << setprecision(20) << endl;
    cout << setprecision(23) << pi * 2.0 * r<< endl;
    return 0;
} 


Measured memory_bytes: 3804
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int ct = 0;
			for (int i = 1; i <= n - 2; i++) {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							ct++;
						}
					}
				}
			}
			System.out.println(ct);
		}
	}
}



Measured memory_bytes: 26572
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int maxi = 0;
    vector<pair<int, int>> areas;
    areas.emplace_back(0, 1); // b, e
    vector<int> as(n);
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    for(int i = 0; i < n; i++){
        int a = as[i];
        int cnt = 1;
        // while(i < n && a == as[i]){ i++; cnt++; }
        // i--;
        maxi += a * cnt;
        vector<pair<int, int>> a2, a3;
        for(auto& area : areas){
            for(int i = 1; i <= cnt; i++){
                a2.emplace_back(area.first + a * i, area.second + a * i);
            }
        }
        size_t i1 = 0, i2 = 0;
        a3.push_back(areas[i1]);
        i1++;
        auto push = [&](vector<pair<int, int>> &v, size_t& idx){
            if(a3.back().second < v[idx].first){
                a3.push_back(v[idx]);
            }else{
                a3.back().second = max(a3.back().second, v[idx].second);
            }
            idx++;
        };
        while(i1 < areas.size() || i2 < a2.size()){
            if(i2 == a2.size() || (i1 < areas.size() && areas[i1] < a2[i2])){
                push(areas, i1);
            }else{
                push(a2, i2);
            }
        }
        areas.swap(a3);
    }
    // printd(areas);
    printd(areas.size());
    int ans = M, targ = (maxi + 1) / 2;
    for(auto& area : areas){
        if(area.second - 1 >= targ){
            // printd(ans, area);
            ans = min(ans, max(targ, area.first));
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 7068
# abc118_b.py
N, M = map(int,input().split())
A = []
ans_list = [0]*(M+1)
ans = 0
for i in range(N):
    _,*a = list(map(int,input().split()))
    A.append(a)
for i in A:
    for j in i:
        ans_list[j] += 1
for i in ans_list[1:]:
    if i == N:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    s64 m = MIN(a, MIN(b, MIN(c, MIN(d, e))));


    cout << (s64)4 + CEIL(n, m) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=998244353;
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  ll dp1[3020][3020];
  ll dp2[3020][3020];
  ll dp3[3020][3020];
  for(ll i=A;i<=C;i++){
    for(ll j=B;j<=D;j++){
      if(i==A && j==B){
        dp2[i][j]=1;
      }
      else if(i==A){
        dp1[i][j]=1;
        dp2[i][j]=j-B;
        dp3[i][j]=pow(A,j-B)-j+B-1;
      }
      else if(j==B){
        dp1[i][j]=0;
        dp2[i][j]=pow(B,i-A);
        dp3[i][j]=0;
      }
      else{
        dp1[i][j]=0;
        dp2[i][j]=(dp1[i-1][j]+dp2[i-1][j]+dp3[i-1][j])*j;
        dp3[i][j]=dp3[i][j-1]*i+dp2[i][j-1];
      }
      dp3[i][j]+=MOD;
      dp1[i][j]%=MOD;
      dp2[i][j]%=MOD;
      dp3[i][j]%=MOD;
    }
  }
  cout<<(dp1[C][D]+dp2[C][D]+dp3[C][D])%MOD<<endl;
}

Measured memory_bytes: 215928
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;


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

  int X, Y, na, nb, nc;
  cin >> X >> Y >> na >> nb >> nc;
  multiset<int> A, B, C;
  for (int i = 0; i < na;i++){
    int x;
    cin >> x;
    A.insert(x);
  }
  for (int i = 0; i < nb;i++){
    int x;
    cin >> x;
    B.insert(x);
  }
  for (int i = 0; i < nc;i++){
    int x;
    cin >> x;
    C.insert(x);
  }

  while(sz(A) > X){
    A.erase(A.find(*A.begin()));
  }
  while(sz(B) > Y){
    B.erase(B.find(*B.begin()));
  }
  while(!C.empty()){
    int fa = *A.begin();
    int fb = *B.begin();
    int fc = *C.rbegin();

    if (fa < fb){
      if(fc > fa){
        A.erase(A.find(fa));
        A.insert(fc);
        C.erase(C.find(fc));
      }
      else break;
    }
    else{
      if(fc > fb){
        B.erase(B.find(fb));
        B.insert(fc);
        C.erase(C.find(fc));
      }
      else break;
    }
  }
  int ans = 0;
  for(auto i : A){
    ans += i;
  }
  for(auto i : B){
    ans += i;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 17248
/*zhen hao*/
#include <bits/stdc++.h>
using namespace std;

#define lson l, m, rt*2
#define rson m + 1, r, rt*2+1
#define xx first
#define yy second

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;

int result[110][110];

bool dfs(int a, int b) {
    if (a > b) swap(a, b);
    if (result[a][b] != -1) return result[a][b];
    bool ok = 0;
    for (int i = 1; i <= b / 2; i++) {
        if (2 * i <= a) {
            if (!dfs(a - 2 * i, b + i)) ok = 1;
        }
        if (!dfs(a + i, b - 2 * i)) ok = 1;
        if (ok) break;
    }
    return result[a][b] = ok;
}

int main() {
#ifdef JUDGE
    freopen("case.in", "r", stdin);
#endif
//    LL a, b;
//    cin >> a >> b;
    memset(result, -1, sizeof result);
////    int a, b;
////    cin >> a >> b;
////    cout << dfs(a, b) << endl;
//    for (int i = 0; i <= 20; i++) {
//        for (int j = i; j <= 20; j++) {
//            if (!dfs(i,j))
//            printf("%d %d %s\n", i, j, dfs(i, j) ? "Alice" : "Brown");
//        }
//    }
    LL a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    if (a < 10 && b < 10) {
        printf("%s\n", dfs(a, b) ? "Alice" : "Brown");
    }
    else {
        if (a == b || a + 1 == b) puts("Brown"); else puts("Alice");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))


Int pos[216000];
set<Int> nums;
Int res, n, a;

int main(){
  cin >> n;
  for(Int i = 0;i < n;i++){
    cin >> a;
    pos[a-1] = i;
  }
  nums.insert(-1);
  nums.insert(n);
  for(Int i = 0;i < n;i++){
    nums.insert(pos[i]);
    auto l = nums.find(pos[i]);l--;
    auto r = nums.find(pos[i]);r++;
    res += (pos[i] - *r) * (*l - pos[i]) * (i+1);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> graph(n);

    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--;v--;
        graph[u].push_back(make_pair(v, w));
        graph[v].push_back(make_pair(u, w));
    }
    
    queue<int> idx;
    idx.push(0);
    vi ans(n, -1);
    ans[0] = 0;
    
    while (!idx.empty()){
        int x = idx.front(); idx.pop();
        rep(i, graph[x].size()){
            int j =graph[x][i].first;
            int w = graph[x][i].second;
            if (ans[j] == -1){
                idx.push(j);
            }else{
                continue;
            }
            if (w%2 == 0){
                ans[j] = ans[x];
            }else{
                ans[j] = (ans[x] + 1) % 2;
            }
        }
    }
    rep(i, n){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long
#define MAXN 100000
using namespace std;

int A[MAXN+2];
int B[MAXN+2];

int Bit(ll x, ll K) {
    return ((x>>K)&1);
}


int main() {
    int N,K;
    cin>>N>>K;
    for(int i=1;i<=N;i++) {
        cin>>A[i]>>B[i];
    }
    
    ll ans = 0;
    for(int b=31;b>=0;b--) {
        
        ll currsum = 0;
        for(int i=1;i<=N;i++) {
            // 31 to b
            
            if (b>0 && Bit(A[i],b-1) >= Bit(K,b-1))
                continue;
            bool ok=true;
            for(int j=31;j>=b;j--) {
                if (Bit(A[i],j) > Bit(K,j)) {
                    ok=false;
                }
            }
            if (ok) {
                currsum+=B[i];
            }
        }
        ans = max(ans, currsum);
        
    }
    
    
    cout << ans << endl;
    
    
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

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

int dp[100001];

signed main(){
    int N; cin >> N;
    vector<int> h( N );
    REP( i, N ) cin >> h[i];

    int t = 0, ans = 0;
    REP( i, N - 1 ){
        if( h[i] >= h[i + 1] ){
            t++;
        }else{
            chmax( ans, t );
            t = 0;
        }
    }
    chmax( ans, t );
    t = 0;

    cout << ans << endl;

}



Measured memory_bytes: 1024
n, l = list(map(int, input().split(' ')))
n_cake = n * l + n * (n + 1) // 2 - n
now_min = 10**10
ans = n_cake - l

for i in range(1, n + 1):
    minus_cake = n_cake - (l + i - 1)
    if abs(n_cake - minus_cake) < now_min:
        ans = minus_cake
        now_min = abs(n_cake - minus_cake)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  ll n; cin >> n;
  vector<int> ans;
  if (n==0){
    cout << 0 << endl;
  }
  else{
  while(abs(n) >= 1){
    if (n%2 == 0){
      ans.push_back(0);
      n = n/(-2);
    }
    else {
      ans.push_back(1);
      n = (n-1)/(-2);
    }
  }  
  
    reverse(ans.begin(), ans.end());
    
    for (int i=0; i<ans.size(); i++){
      cout << ans[i];
    }  
    cout << endl;
  }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	int cur=1;
	FOR(i,N) cur=min(cur+K,cur*2);
	cout<<cur<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 100000

using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

int main () {
    int N, K;
	string T;
	vector<ll> score(3);
	cin >> N >> K >> score[0] >> score[1] >> score[2] >> T;
	map<char, int> mp;
	mp['r'] = 0, mp['s'] = 1, mp['p'] = 2;
	vector<int> t(N);
	rep(i,N) t[i] = mp[T[i]];
	ll ans = 0;
	rep(i,K) {
		int m = N/K + ( (i < N%K) ? 1 : 0);
		vector< vector<ll> > dp(m, vector<ll>(3, 0));
		rep(q,m) {
			int cur = q*K + i;
			int win_hand = (t[cur] + 2)%3;
			dp[q][win_hand] += score[win_hand];
		}
		for (int q = 1; q < m; ++q) {
			rep(j,3) {
				dp[q][j] += max( dp[q-1][(j+2)%3], dp[q-1][(j+1)%3] );
			}
		}
		ans += max(dp[m-1][0], max(dp[m-1][1], dp[m-1][2])); 
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define scs(ch) scanf("%s", ch)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
int main()
{
	string s;
	cin>>s;
	if(s=="ABC")
	printf("ARC\n");
	else
	printf("ABC\n");
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main(void){
    char S[6];
    cin >> S;

    bool islike = true;

    if(S[2] != S[3]){
        islike = false;
    }

    if(S[4] != S[5]){
        islike = false;
    }

    if(islike){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
    
    size_t l, r;
    std::cin >> l >> r;

    if(r - l >= 2018){
        std::cout << 0 << std::endl;
        return 0;
    }

    size_t min = 2019;

    for(size_t i = l; i <= r; i++){
        for(size_t j = i + 1; j <= r; j++){
            min = std::min(min, i * j % 2019);
        }
    }

    std::cout << min << std::endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;

int DiditSums(int N) {
    int temp = 0;
    while (N > 0) {
        temp += N % 10;
        N /= 10;
    }

    return temp;
}
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    if (N % DiditSums(N) == 0) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No"  << std::endl;
    }
    return 0;
}

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

bool check(vector<pair<long long, long long> > P) {
	if (P.empty()) return true;
	sort(P.begin(), P.end());
	queue<long long> Q;
	if (P[0].first > 0) return false;
	Q.push(P[0].second);
	long long NOW = 1, COUNT = 0;
	while (!Q.empty()) {
		COUNT += Q.front();
		Q.pop();
		while (NOW < (int)P.size()) {
			if (P[NOW].first <= COUNT) {
				Q.push(P[NOW].second);
				NOW++;
			}
			else break;
		}
	}
	return NOW == (int)P.size();
}

int main() {
	int N;
	cin >> N;
	vector<pair<long long, long long> > P(N);
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		long long MIN = 0, NOW = 0;
		for (int j = 0; j < (int)S.size(); j++) {
			if (S[j] == '(') NOW++;
			else NOW--;
			MIN = min(MIN, NOW);
		}
		P[i].first = -MIN, P[i].second = NOW;
	}
	long long COUNT = 0;
	for (int i = 0; i < N; i++) COUNT += P[i].second;
	if (COUNT != 0) {
		cout << "No" << endl;
		return 0;
	}
	vector<pair<long long, long long> > X, Y;
	for (int i = 0; i < N; i++) {
		if (P[i].second >= 0) X.push_back(P[i]);
		else Y.push_back({ P[i].second + P[i].first, -P[i].second });
	}
	if (!check(X)) {
		cout << "No" << endl;
		return 0;
	}
	if (!check(Y)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

double dp1[150010];
vector<vll> G;
void dfs1(ll v,ll p){
  ll cnt=0;
  for(ll u:G[v])if(u!=p){
    dfs1(u,v);
    dp1[v] += dp1[u];
    cnt++;
  }
  if(cnt>0){
    dp1[v] /= cnt;
    dp1[v] += 1;
  }
}
double dp2[150010];
void dfs2(ll v,ll p,double pval){
  double tmp=0;
  for(ll u:G[v]){
    if(u==p)tmp += pval;
    else tmp += dp1[u];
  }
  ll size=G[v].size();
  dp2[v] = tmp/size+1;
  for(ll u:G[v])if(u!=p){
    dfs2(u,v,size<=1?0:(tmp-dp1[u])/(size-1)+1);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  G.resize(N);
  for(ll i=0;i<N-1;i++){
    ll u,v;cin>>u>>v;u--;v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs1(0,-1);
  //debug(dp1[0]);
  dfs2(0,-1,0);
  for(ll i=0;i<N;i++){
    printf("%.7lf\n",dp2[i]);
  }
  return 0;
}


Measured memory_bytes: 19328
N = int(input())
P = list(map(int,input().split()))
cnt = 0
is_continue = False
for i in range(N):
    if (i + 1) == P[i]:
        cnt += 1
        if is_continue:
            cnt -= 1
            is_continue = False
        else:
            is_continue = True
    else:
        is_continue = False
print(cnt)

Measured memory_bytes: 13880
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var A, B, X int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &A, &B, &X)

	if A <= X && X <= A+B {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int n, rta = 0;
    cin >> n;
    int v[n], c[n];
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n; i++){
        if(v[i]-c[i] > 0) rta += v[i]-c[i];
    }

    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3616
def solve(num, id, ar)
  ar[id] = num
  if id == @n-1
    sum = 0
    for i in 0..(@q-1)
      sum += @d[i] if ar[@b[i]-1]-ar[@a[i]-1] == @c[i]
    end
    @ans = [@ans, sum].max
    return
  else
    for i in num..@m
      solve(i, id+1, ar)
    end
  end
end

@n, @m, @q = gets.split.map(&:to_i)
@a, @b, @c, @d = @q.times.map{gets.split.map(&:to_i)}.transpose

@ans = 0
ar = Array.new(@n)
for i in 1..@m
  solve(i, 0, ar)
end
puts @ans

Measured memory_bytes: 14380
#include <bits/stdc++.h>
using namespace std;
long long i,j,k,n,t,as[5],arr[16],a[10];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(i=0;i<3;i++){
    cin>>arr[j++]>>a[k];
    arr[j++]=a[k++];}
 //   for(i=0;i<6;i++)cout<<arr[i]<<" ";
    for(i=0;i<6;i++)
    {
        as[arr[i]]++;
    }
    for(i=0;i<5;i++)
    {
        if(as[i]>=3){cout<<"NO\n";
        return 0;}
    }
    cout<<"YES\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//vector
template <class T>
using vec = std::vector<T>;

void solve()
{
    using namespace std;
    
    int A, B, C;
    cin >> A >> B >> C;

    bool can = false;
    for (int i = 1; i <= B; ++i)
        if ((i * A) % B == C)
            can = true;
    
    if (can)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=200010;
int i,j,k,n,m,x,y,t,b[20];
int fi[N*2],ne[N*2],la[N*2],a[N*2],w[N];
int f[N][20],g[N][20];
void add(int x,int y){
	k++;a[k]=y;
	if (fi[x]==0)fi[x]=k;else ne[la[x]]=k;
	la[x]=k;
}
void dfs(int x,int fa){
	for (j=0;j<20;j++)f[x][j]=1;
	for (int i=fi[x];i;i=ne[i])if (a[i]!=fa){
		dfs(a[i],x);
		for (j=0;j<20;j++)f[x][j]&=f[a[i]][j],g[x][j]+=g[a[i]][j];
	}
	memset(b,0,sizeof b);
	for (int i=fi[x];i;i=ne[i])if (a[i]!=fa)
		for (int j=0;j<20;j++)
			if (g[a[i]][j]&&!f[a[i]][j])
				b[j]++;
	for (j=19;j>=0;j--)if (b[j]>1){
		for (k=j;k<20;k++)if (f[x][k]){w[x]=k;break;}
		break;
	}
	if (!w[x]){for (j=0;j<20;j++)if (f[x][j]){w[x]=max(w[x],j);break;}}
	f[x][w[x]]=0;g[x][w[x]]++;
	for (j=0;j<w[x];j++)f[x][j]=1;
}
int main(){
	scanf("%d",&n);
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,-1);
	int ans=0;
	for (i=1;i<=n;i++)ans=max(ans,w[i]);
//	for (i=1;i<=n;i++)printf("%d ",w[i]);printf("\n");
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 31872
import java.io.IOException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author wijebandara
 */
public class Main {
     public static void main(String[] args) throws IOException {
        java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        {
            int data[] =new int [4];
            for (int i = 0; i < 10; i++) {
                int p =Integer.parseInt(in.readLine());
                int k=2;
                while(k>=0 && data[k]<p)
                {
                    data[k+1]=data[k];
                    k--;
                }
                data[k+1]=p;
                
            }
            for (int i = 0; i < 3; i++) {
                System.out.println(data[i]);
            }
            
            
        }
     }   
        
        
    
}

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

int main() {
    int n, m, sum = 0;
    cin >> n;
    int T[n];
    for (int i = 0; i < n; i++) {
        cin >> T[i];
        sum += T[i];
    }
    cin >> m;
    int p[m], x[m];
    int ans[m];
    for (int i = 0; i < m; i++) {
        cin >> p[i] >> x[i];
        ans[i] = sum - T[p[i] - 1] + x[i];
    }
    for (auto it : ans) cout << it << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

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


#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main() {
	int a;
	string s;
	cin >> a;
	cin >> s;
	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

}

Measured memory_bytes: 256