akhauriyash/Code-Regression huggingface dataset:
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-20 14:14:53
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n; int64 k; cin >> n >> k;
  vector<int64> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  vector<int> dp(60, 0);
  // dp[i] : i 桁目の bit が立っている a_i がいくつあるか

  for (int i = 0; i < n; ++i) {
    bitset<50> bit(a[i]);
    for (int j = 0; j < 50; ++j) {
      if (bit.test(j)) {
        ++dp[j];
      }
    }
  }

  int64 ans = 0;
  int64 tmp = 0;
  for (int i = 0; i < n; ++i) {
    tmp += (a[i] ^ k);
  }

  ans = tmp;

  for (int i = 49; i >= 0; --i) {
    bitset<50> kbit(k);
    if (kbit.test(i)) {
      kbit.reset(i);
      for (int j = i - 1; j >= 0; --j) {
        if (dp[j] > n - dp[j]) {
          kbit[j] = 0;
        } else {
          kbit[j] = 1;
        }
      }
      int64 best = kbit.to_ullong();
      debug(best);
      int64 t = 0;
      for (int j = 0; j < n; ++j) {
        t += (best ^ a[j]);
      }
      ans = max(ans, t);
    }
  }
  cout << ans << endl;

  return 0;
}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque…双方向リスト
//stack…FILO, 深さ優先探索
//queue…FIFO, 幅優先探索
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}
template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}
template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}

using Graph = vector<vector<int>>;

template <class T, class S>
class Edge {
  T to;  //辺の行き先
  S weight;  //辺の重み

public:
  Edge(T t, S w) : to(t), weight(w) {}
};

int ansi = 0;
ll ansl = 0;
double ansd = 0.0;

int main() {
  string s;
  cin >> s;
  rep(i, 0, s.size()-2) {
    if (s[i] == s[i+1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 384
h, w = map(int, input().split())
img = [list(input()) for i in range(h)]
out = [[0 for j in range(w)] for i in range(2*h)]
for i in range(2*h) :
    for j in range(w) :
        out[i][j] = img[int(i/2)][j]
for i in range(2*h) :
    for j in range(w) :
        print(out[i][j],sep="",end="")
    print("")


Measured memory_bytes: 9352
#include <bits/stdc++.h>
using namespace std;
//解説AC　難しい
int main(){
  int n;
  cin>>n;
  long long sum=0;
  long long sum2=0;
  vector<int>a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
    if(i%2==1)sum2+=a[i];
  }
  b[0]=sum-2*sum2;
  for(int i=1;i<n;i++){
    b[i]=2*a[i-1]-b[i-1];
  }
  for(int i=0;i<n;i++){
    cout<<b[i]<<" ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3976
def add(x, y, op):
    if op == '+':
        return x + y
    else:
        return x - y



def main():
    ops = ('+', '-')
    A, B, C, D = [int(i) for i in input()]

    for i in ops:
        for j in ops:
            for k in ops:
                s = 0
                s = add(A, B, i)
                s = add(s, C, j)
                s = add(s, D, k)
                if s == 7:
                    print('{}{}{}{}{}{}{}=7'.format(A, i, B, j, C, k, D))
                    return 0

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define VALS(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pf push_front
#define LLINF ((long long)1e18)
#define INF 1234567890ll
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define ll long long int 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define f first
#define s second
typedef pair <int, int> pi;
typedef pair <ll, ll> pl;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
const int MOD = 1e9 + 7;

ll ans;
int main()
{
	IAMSPEED
	ll n, m; cin >> n >> m;
	priority_queue<ll> pq;
	FOR(i, 0, n-1) {
		ll x; cin >> x;
		pq.push(x);
	}
	while(m--) {
		ll x = pq.top(); pq.pop();
		x /= 2;
		pq.push(x);
	}
	while (!pq.empty())
	{
		ans += pq.top(); pq.pop();
	}
	cout << ans;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long x = Math.abs(scanner.nextLong()), k = scanner.nextLong(), d = scanner.nextLong();
			if (k < (x / d)) {
				System.out.println(x - k * d);
			} else {
				k -= x / d;
				if (0 == (k & 1)) {
					System.out.println(x - (x / d) * d);
				} else {
					System.out.println(Math.abs(x - (x / d) * d - d));
				}
			}
		}
	}
}


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

int main() {
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    for (int i = 0; i < tx-sx; ++i){
        cout << 'R';
    }
    for (int i = 0; i < ty-sy; ++i){
        cout << 'U';
    }
    for (int i = 0; i < tx-sx; ++i){
        cout << 'L';
    }
    for (int i = 0; i < ty-sy+1; ++i){
        cout << 'D';
    }
    for (int i = 0; i < tx-sx+1; ++i){
        cout << 'R';
    }
    for (int i = 0; i < ty-sy+1; ++i){
        cout << 'U';
    }
    cout << 'L' << 'U';
    for (int i = 0; i < tx-sx+1; ++i){
        cout << 'L';
    }
    for (int i = 0; i < ty-sy+1; ++i){
        cout << 'D';
    }
    cout << 'R' << endl;

}


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
double distance(int a,int b,int c,int d){ return sqrt((a-c)*(a-c)+(b-d)*(b-d)); }
int main() {
  int N;
  cin >> N;
  rep(i, 50000) {
    if (floor(i * 1.08) == N) {
      cout << i;
      return 0;
    }
  }
  cout << ":(";
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

*/


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

const int Mod = 1e9 + 7;
int N, K;
int f[100003], psum[100003];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a;
	cin >> N >> K;
	psum[0] = 1;
	reg int lim;
	for(reg int i = 1; i <= N; ++i) {
		cin >> a;
		for(reg int j = 1; j <= K; ++j)
			(psum[j] += psum[j - 1]) %= Mod;
		lim = - (a + 1);
		for(reg int j = 0; j <= K; ++j) {
			++lim;
			if(lim <= 0) {
				f[j] = psum[j];
			} else {
				f[j] = (psum[j] - psum[lim - 1] + Mod) % Mod;
			}
		}
		memcpy(psum, f, sizeof psum);
	}
	cout << f[K] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 1002
//#define mp make_pair
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int b[MAX][MAX][6];
char a[MAX][MAX];
string str[MAX];
char c[3] = {'J', 'O', 'I'};
stack<int> st;
int main(){
	int h, w, k;
	scanf("%d%d%d", &h, &w, &k);
	rep(i,h)cin >> str[i];
	rep(i,h)rep(j,w)a[i+1][j+1] = str[i][j];
	rep(i,h)rep(j,w)rep(u,3){
		if(a[i+1][j+1] == c[u])b[i+1][j+1][u]++;
		b[i+1][j+1][u] += b[i+1][j][u];
	}
	rep(i,h)rep(j,w)rep(u,3){
		b[i+1][j+1][u+3] = b[i][j+1][u+3] + b[i+1][j+1][u];
	}
	
	int x[4], y[3];
	for(int i = 0;i < k;i++){
		rep(j,4)scanf("%d", &x[j]);
		x[0]--;x[1]--;
		rep(u,3)
		y[u] = b[x[2]][x[3]][u+3]+b[x[0]][x[1]][u+3]-b[x[2]][x[1]][u+3]-b[x[0]][x[3]][u+3];
		printf("%d %d %d\n", y[0], y[1], y[2]);
		//printf("%d %d %d\n",x[3], x[2], b[x[2]][x[3]][3]);
	}
	
	/*rep(i,h){
		rep(j,w)printf("%d ", b[i+1][j+1][3]);
		printf("\n");
	}*/
	return 0;
}

Measured memory_bytes: 28396
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    cout << ((s.size()%2==0)^(s[0]==s[n-1]) ? "Second" : "First") << '\n';
}



Measured memory_bytes: 512
r,c = map(int,input().split())
num=[]
r_sum =[]
for i in range(r):
    num.append([int(i) for i in input().split()])
for i in range(r):
    line_sum = 0
    for j in range(c):
        line_sum += num[i][j]
    num[i].append(line_sum)
for i in range(c+1):
    row_sum = 0
    for j in range(r):
        row_sum += num[j][i]
    r_sum.append(row_sum)
num.append(r_sum)
for i in range(len(num)):
    print(' '.join(str(i) for i in num[i]))


Measured memory_bytes: 5680
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N; string S;
    cin>>N>>S;
    ll r=0, g=0, b=0;
    rep(i, N){
        if(S[i]=='R') r++;
        if(S[i]=='G') g++;
        if(S[i]=='B') b++;
    }
    ll count=r*g*b;
    ll cou=0;
    rep1(d, (N-1)/2){
        rep(i, N-d*2){
            if(S[i]!=S[i+d] && S[i+2*d]!=S[i+d] && S[i+2*d]!= S[i]) cou++;
        }
    }
    cout<<count-cou<<endl;
    return 0;
}


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

//47
typedef long long ll;

int main() {
	int n;
	cin >> n;
	//vector<string> v(n);
	map<string,ll> m;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		sort(s.begin(),s.end());
		m[s]++;
	}
	//sort(v.begin(),v.end());
	//int ans = 0;
	//map<string,int> m;
	//for (int i = 0; i < n; ++i) {
		//m[v[i]]++;
	//}
	ll ans = 0;
	for (auto it = m.begin(); it != m.end(); ++it) {
		if (it->second > 1) {
			ans += 1LL * ((it->second *(it->second - 1)) / 2);
		}
	}
	cout << ans;
}


Measured memory_bytes: 11444
if __name__ == '__main__':
    a, b = tuple([int(s) for s in input().split()])
    tr, cr = 0.08, 0.1

    tr_a = int(a / tr)
    tr_b = int(b / cr)

    i = min([tr_a, tr_b])
    while i <= max([tr_a, tr_b]):
        if int(i * tr) == a and int(i * cr) == b:
            break
        else:
            i += 1

    if int(i * tr) == a and int(i * cr) == b:
        print(i)
    else:
        print(-1)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)
s = input()

a = s.count("a")
b = s.count("b")
c = s.count("c")

max_ = max(a, b, c)
min_ = min(a, b, c)

if max_ - min_ >= 2:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define count(v, t) count(v.begin(), v.end(), t)
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

int main() {
  cin.tie(0);ios_base::sync_with_stdio(false);
  ll n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,1000) {
    string p = "00" + to_string(i);
    p = p.substr(p.size()-3);
    bool found = true;
    rep(j,3) {
      int pos;
      if (j == 0) {
        pos = s.find(p[j]);
      } else {
        pos = s.find(p[j], pos+1);
      }
      if (pos == string::npos) {
        found = false;
        continue;
      }
    }
    if (found) {
      ans++;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
//~ #define MOD 1000000007
#define MOD 1000003
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<int>E[20000];
int c[20000];
int in[20000];
int d[20000];

int main(){
	int n;cin>>n;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
		in[a]++;
		in[b]++;
	}
	rep(i,n){
		scanf("%d",&c[i]);
	}
	sort(c,c+n);
	int c1=0;
	set<P>se;
	rep(i,n){
		se.insert(P(in[i],i));
	}
	ll ans=0;
	while(!se.empty()){
		P p=*se.begin();se.erase(se.begin());
		d[p.second]=c[c1++];
		ans+=d[p.second]*p.first;
		for(int u:E[p.second]){
			if(!se.count(P(in[u],u)))continue;
			se.erase(P(in[u],u));
			in[u]--;
			se.insert(P(in[u],u));
		}
	}
	cout<<ans<<endl;
	rep(i,n){
		cout<<d[i]<<' ';
	}
	cout<<endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}




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

    ll n;
    cin>>n;

    ll all = pw(10, n);
    ll no0 = pw(9, n);
    ll no9 = pw(9, n);

    ll no09 = pw(8, n);


    ll res = all - no0 - no9 + no09;
    res %= mod;
    res += mod;
    res %= mod;

    out(res);
    
    return 0;
}


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

int main(){
    //input
    long long n;
    cin >> n;
    long long A[n];
    long long i;
    for(i = 0; i < n; i++){
        cin >> A[i];
    }
    long long q;
    cin >> q;
    long long m[q];
    long long j;
    for(j = 0; j < q; j++){
        cin >> m[j];
    }

    //calc&answer
    long long bit, sum;
    for(j = 0; j < q; j++){
        for(bit = 0; bit < (1<<20); bit++){
            sum = 0;
            for(i = 0; i < n; i++){
                sum += A[i]*((bit>>i) & 1);
            }
            if(sum == m[j]){
                break;
            }
        }
        if(bit < (1<<20)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
  int n,l;
  int x = 1000,y,sum = 0;
  cin >> n >> l;
  for(int i = 1;i <= n;i++){
    if(abs(l+i-1) < abs(l+x-1)){
      x = i;
    }
    sum += l+i-1;
  }
  cout << sum-(l+x-1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2 && d2 == 1) {
		cout << 1;
		return 0;
	}
	cout << 0;*/
	

	/*double n;
	cin >> n;
	int ans, i;
	for (i = 0; i <= n; i++) {
		if (int(i * 1.08) == n) {
			ans = i;
			cout << ans;
			return 0;
		}
	}
	cout << ":(";*/
	
	
	int x;
	cin >> x;
	int buy = x / 100;
	if (x - buy * 100 > 5 * buy) {
		cout << 0;
		return 0;
	}
	cout << 1;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

  int a=1,b=1;

  while(1){

   for(b=1;b<10;b++){
     printf("%dx%d=%d\n",a,b, a*b);
    }

   a=a+1;
   if(a==10)break;
  }





  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
const int M=1e5+5;
int mark[M],par[M];
vi adj[M];
void dfs(int v){
	mark[v]=1;
	for(int u:adj[v]) if(!mark[u]) par[u]=v,dfs(u);
}
int cnt=0;
void pfs(int v){
	cnt++;
	for(int u:adj[v]) if(u!=par[v]) pfs(u);
}
int32_t main()
{
	int n; cin>>n;
	for(int i=1;i<n;i++){
		int u,v; cin>>u>>v;
		adj[u].pb(v),adj[v].pb(u);
	}
	dfs(1);
	vi vec; int now=n;
	while(now!=1) vec.pb(now),now=par[now];
	pfs(vec[(vec.sz-1)/2]);
	if(cnt>=(n+1)/2) cout << "Snuke" ;
	else cout << "Fennec" ;
	return cout << endl,0;
}


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

int main() {
  
  int n, l, r;

  scanf("%d", &n);

  int sum = 0;
  for(int i = 0; i < n; i++){
    scanf("%d %d", &l, &r);
    sum += r - l + 1; 
  }

  cout << sum <<endl;
}



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

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)

using namespace std;

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

int Pow(int x, int e) {
	int ret = 1;
	while (e) {
		if (e & 1) ret = 1ll * ret * x % Mod;
		x = 1ll * x * x % Mod;
		e >>= 1;
	}
	return ret;
}

int n;

struct Binary_Indexed_Tree {

	int c[N], st[N * 20], k;

	void init() {
		while (k) c[st[k--]] = 0;
	}

	int lowbit(int x) {
		return x & (-x);
	}

	void add(int x, int w) {
		while (x <= n) {
			st[++k] = x;
			c[x] = (c[x] + w) % Mod;
			x += lowbit(x);
		}
	}

	int query(int x) {
		int ans = 0;
		while (x) {
			ans = (ans + c[x]) % Mod;
			x -= lowbit(x);
		}
		return ans;
	}

}T;

int A[N], rk[N], cnt[N], d[N];
int pos[N], c;

bool cmp(int x, int y) {
	return A[x] < A[y];
}

int main() {

	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &A[i]), rk[i] = i, ++cnt[A[i]];
	sort(rk + 1, rk + n + 1, cmp);
	Forr(i, n, 1) cnt[i] += cnt[i + 1];
	
	int S = 1;
	For(i, 1, n) {
		cnt[i] -= n - i;
		S = 1ll * S * cnt[i] % Mod;
		if (cnt[i] <= 0) { puts("0"); return 0; }
	}

	int ans = 0;
	Forr(i, n, 1) ans = (ans + T.query(A[i] - 1)) % Mod, T.add(A[i], 1);

	int p = 1;
	For(i, 1, n) {
		int r = i;
		while (r < n && cnt[r + 1] > 1) ++r;
		c = 0;
		while (p <= n && A[rk[p]] <= r) pos[++c] = rk[p], ++p;
		sort(pos + 1, pos + c + 1);

		d[i] = 1;
		For(j, i + 1, r) d[j] = 1ll * d[j - 1] * (cnt[j] - 1) % Mod * Pow(cnt[j], Mod - 2) % Mod;

		T.init();
		For(j, 1, c) {
			int x = A[pos[j]];
			ans = (ans + 1ll * T.query(x) * d[x] % Mod * (Mod + 1) / 2) % Mod;
			T.add(x, Pow(d[x], Mod - 2));
		}
		T.init();
		Forr(j, c, 1) {
			int x = A[pos[j]];
			ans = (ans - 1ll * T.query(x - 1) * d[x] % Mod * (Mod + 1) / 2) % Mod;
			T.add(x, Pow(d[x], Mod - 2));
		}

		i = r;
	}
	ans = 1ll * (ans + Mod) * S % Mod;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 12544
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <iostream>
#include <map>

using namespace std;

const int CMax = 100005;

int main()
{
    long long h, daug = 1, sum = 0;
    scanf("%lld", &h);

    while (h > 0) {
        sum += daug;
        daug *= 2;
        h /= 2;
    }

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


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve()
{
  int n, x;
  cin >> n >> x;
  vector<int> pos(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> pos[i];
  }

  int min_pos = *min_element(pos.begin(), pos.end());
  x -= min_pos;

  int ans = abs(x);
  for(int i = 0; i < n; ++i)
  {
    ans = gcd(ans, pos[i] - min_pos);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3616
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define kloop(n) for(ll k=0; k<(n); k++)
#define gloop(n) for(ll g=0; g<(n); g++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll LINF = 2e17+423;
const int INF = 2e9 + 69;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);



































int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = len(s);
    loop(n) cout << 'x';
    R 0;
}
/*

*/



























































ll po(ll x, ll n){
  if(n==0) R 1%mod;
  ll y = po(x, n/2)%mod;
  y = ((y%mod)*(y%mod));
  if(n%2) y = (y*(x%mod))%mod;
  R y%mod;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
	int N;
	int ans=0;

	cin >> N;
	
	vector<int> V(N),C(N);

	for (int i = 0; i < N; i++) {
		cin >> V.at(i);
	}
	for (int i = 0; i < N; i++) {
		cin >> C.at(i);
	}

	for (int i = 0; i < N; i++) {
		if (V.at(i) > C.at(i)) {
			ans += V.at(i) - C.at(i);
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import copy
def partition(A, p, r):
    x = A[r][0]
    i = p - 1
    for j in range(p, r):
        if A[j][0] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
        
    A[i+1], A[r] = A[r], A[i+1]
    
    return i+1

def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


def merge(A, left, mid, right):
    L = A[left:mid] + [[10000000000, 'S']]
    R = A[mid:right] + [[10000000000, 'S']]

    i = j = 0

    for k in range(left, right):
        if L[i][0] <= R[j][0]:
            A[k] = L[i]
            i += 1

        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
lstA = []
for i in range(n):
    C, N = input().split()
    k = [int(N), C]
    lstA.append(k)

lstB = copy.copy(lstA)
mergeSort(lstA, 0, n)
quicksort(lstB, 0, n-1)

if lstA == lstB:
    print('Stable')

else:
    print('Not stable')

for i in lstB:
    print(i[1], i[0])


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int a,b,c;

int main(){
	cin.sync_with_stdio(false);
  cin>>a>>b>>c;
  rep(i,61){
    int start=(a+b)*i,end=(a+b)*i+a;
    int l,u;
    if(end-c<0)continue;
    if(start-c<0)l=0;
    else l=(start-c+59)/60;
    u=(end-c)/60;
    if(l<=u){
      cout<<c+60*l<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3160
k=input()
a=int(k[0])
b=int(k[1])
c=int(k[2])
d=int(k[3])
if (a+b+c+d)==7:print(k[0]+'+'+k[1]+'+'+k[2]+'+'+k[3]+'='+'7')
elif (a-b+c+d)==7:print(k[0]+'-'+k[1]+'+'+k[2]+'+'+k[3]+'='+'7')
elif (a+b-c+d)==7:print(k[0]+'+'+k[1]+'-'+k[2]+'+'+k[3]+'='+'7')
elif (a+b+c-d)==7:print(k[0]+'+'+k[1]+'+'+k[2]+'-'+k[3]+'='+'7')
elif (a-b-c+d)==7:print(k[0]+'-'+k[1]+'-'+k[2]+'+'+k[3]+'='+'7')
elif (a+b-c-d)==7:print(k[0]+'+'+k[1]+'-'+k[2]+'-'+k[3]+'='+'7')
elif (a-b+c-d)==7:print(k[0]+'-'+k[1]+'+'+k[2]+'-'+k[3]+'='+'7')
elif (a-b-c-d)==7:print(k[0]+'-'+k[1]+'-'+k[2]+'-'+k[3]+'='+'7')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b;
  cin >> a >> b;
  if(a<=b)cout << a << endl;
  else cout << a-1 << endl;
  return 0;
}

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

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

    rep(i,8){
        if(200*(i+2)<=X && X<200*(i+3))
        cout << 8-i <<endl;
    }
}

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

int main(){
  int N, K; cin >> N >> K;
  vector<int> x(N), vec(K);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  int ans = 1e9;
  for(int i = 0; i <= N - K; i++){
    int min1, max_K, min_K;
    max_K = x[i + K - 1];
    min_K = x[i];
    if(min_K >= 0) min1 = max_K;
    else if(max_K <= 0) min1 = -min_K;
    else min1 = min(abs(min_K), max_K)*2 + max(abs(min_K), max_K);
    ans = min(ans, min1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int mod = 1e9+7;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/*---------------------------------------------------------------------------------------------------------------------*/

const int M = 200001;

int arr[M] , brr[M];

int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);


    int n;
    si(n);

    for(int i = 1 ; i <= n ; i++){
        si(arr[i]);
        brr[i] = arr[i];
    }

    int res = 0 , ans = 0;

    for(int i = 1 ; i - 1 <= n ; i++){
        if(arr[i] == i && arr[i + 1] == i + 1){
            ans++;
            swap(arr[i] , arr[i + 1]);
            i++;
        }
        else if(arr[i] == i && arr[i + 1] != i + 1){
            ans++;
            swap(arr[i] , arr[i + 1]);
        }
        else if(arr[i] != i && arr[i + 1] == i + 1){
            //ans++;
            //swap(arr[i] , arr[i + 1]);
        }
    }

    if(arr[n] == n){
        ans++;
        swap(arr[n] , arr[n - 1]);
    }
    for(int i = 1 ; i <= n ; i++){
        assert(arr[i] != i);
    }
    cout<<ans;






}














Measured memory_bytes: 1024
package main

import "fmt"

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

	al := make([]int, n)

	over := false
	for i := 0; i < n; i++ {
		var num int
		fmt.Scan(&num)
		if num > 1e18 {
			over = true
		}
		if num == 0 {
			fmt.Println(0)
			return
		}
		al[i] = num
	}

	if over {
		fmt.Println(-1)
		return
	}

	ans := 1
	for i := 0; i < n; i++ {
		if ans > 1e18/al[i] {
			over = true
			break
		}
		ans = ans * al[i]
	}

	if over {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

Measured memory_bytes: 6340
from operator import itemgetter

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
#print(ab)
i = 0
ans = 0
while m >0:
  if ab[i][1]<=m:
    m -= ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    ans += ab[i][0]*m
    m = 0
  i+=1
print(ans)

Measured memory_bytes: 27360
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N;cin>>N;int n=N;
  std::vector<int> ans,awa;
  for(int i=1;i<=60;i++)if(i%2==0||i%3==0||i%5==0)awa.push_back(i);
  int k;
  int S=awa.size();
  if(N>=S){
    for(k=0;N>=S;k++){
      N-=S;
      for(int p:awa)ans.push_back(p+60*k);
    }
    while(N--)ans.push_back(60*++k);
    for(int p:ans)cout<<p<<" ";cout<<endl;
  }
  else{
    if(N==3){cout<<"2 5 63"<<endl;return 0;}
    if(N==4){cout<<"2 5 20 63"<<endl;return 0;}
    if(N==5){cout<<"2 3 8 9 14"<<endl;return 0;}
    for(int k=0;6*k+10<=30000&&N>=6;k+=2){
      ans.push_back(6*k+2);
      ans.push_back(6*k+3);
      ans.push_back(6*k+4);
      ans.push_back(6*k+8);
      ans.push_back(6*k+9);
      ans.push_back(6*k+10);
      N-=6;
    }
    for(int k=1;6*k<=30000&&N>0;k++){
      ans.push_back(6*k);
      N--;
    }
    for(int p:ans)cout<<p<<" ";cout<<endl;
  }
}


Measured memory_bytes: 640
from sys import stdin
input = stdin.readline

S = input().rstrip()

c = S.count("R")

if c == 0:
    print(0)
elif c == 1:
    print(1)
elif c == 2:
    if S[1] == "R":
        print(2)
    else:
        print(1)
else:
    print(3)


Measured memory_bytes: 9096
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
//segment-tree
int n;//nは2のべき乗
pii dat[1000000*2-1];
//i番目の値(0-indexed)をxに変更
void update(int i,int x){
	//葉のノード番号
	int team =i;
	i +=n-1;
	dat[i].first +=x;
	dat[i].second = -team;
	while(i >0){
		i =(i-1)/2;
		dat[i] =max(dat[i*2+1],dat[i*2+2]);
	}
}

//初期化
void init(int _n){
	n = 1;
	while(n<_n)
		n *=2;
	for(int i = 0;i <_n;i++){
		update(i,0);
	}
}

/*
//[a,b)の最小値,l,rにはノードkに対応づく区画を与える
//外からはquery(a,b,0,0,n)のように呼ぶ
int query(int a,int b,int k,int l,int r){
	if(r <=a||b <=l)//交差しない
		return INT_MAX;
	if(a <=l&&r<=b)//完全に含む
		return dat[k];
	else{
		int vl =query(a, b, k*2+1, l, (l+r)/2);
		int vr =query(a, b, k*2+2, (l+r)/2, r);
		return max(vl,vr);
	}
}
*/
int main(){
	int N,R,L;
	cin>>N>>R>>L;
	init(N);
	int team = 0;
	int pret  =0;
	int sum[110000];
	for(int i = 0;i < R;i++){
		int d,t,x;
		cin>>d>>t>>x;
		d--;
		update(d,x);
		sum[team]+=t-pret;
		pret =t;
		team =-dat[0].second;
	}
	sum[team] +=L-pret;
	int ans = 0;
	for(int i = 0;i < N;i++){
		if(sum[ans]<sum[i]){
			ans = i;
		}
	}
	cout <<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 17180
import sys
 
 
def main():
    orders = sys.stdin.readlines()[1:]
    dna_set = set()
    for order in orders:
        command, dna = order.split(" ")
        if command == "insert":
            dna_set.add(dna)
        elif command == "find":
            if dna in dna_set:
                print("yes")
            else:
                print("no")
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 114700
#include<bits/stdc++.h>
//"谷は0にすることが可能"
int main()
{
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for(int i = 0; i < n; i++)std::cin >> h[i];
    int res = 0;

    for(int t = 1; t <= *std::max_element(h.begin(),h.end()); t++){
        int last = -10;
        for(int i = 0; i < n; i++){
            if(t <= h[i]){
                if(last + 1 != i)res++;
                last = i;
                //std::cout << t <<" :" <<i << std::endl;
            }
        }
    }
    std::cout << res << std::endl;
}
// 0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<

Measured memory_bytes: 256
H,W=map(int,input().split())
S=[[1 if c=='#' else 0 for c in input()] for i in range(H)]
from collections import deque
r=0
for i in range(H):
    for j in range(W):
        if S[i][j]==1:
            continue
        d=[[-1]*W for x in range(H)]
        q=deque([(i,j,0)])
        d[i][j]=0
        while q:
            x,y,d0=q.popleft()
            if x>0 and S[x-1][y]==0 and d[x-1][y]==-1:
                q.append((x-1,y,d0+1))
                d[x-1][y]=d0+1
            if y>0 and S[x][y-1]==0 and d[x][y-1]==-1:
                q.append((x,y-1,d0+1))
                d[x][y-1]=d0+1
            if x<H-1 and S[x+1][y]==0 and d[x+1][y]==-1:
                q.append((x+1,y,d0+1))
                d[x+1][y]=d0+1
            if y<W-1 and S[x][y+1]==0 and d[x][y+1]==-1:
                q.append((x,y+1,d0+1))
                d[x][y+1]=d0+1
        r=max(r,d0)
print(r)

Measured memory_bytes: 3316
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o C.exe C.cpp 
Execute: ./C
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int n, a, a_max; 
	unsigned long long result = 0ULL; 
	
	cin >> n; 
	cin >> a; 
	a_max = a; 
	for(int i = 1; i < n; i++) {
		cin >> a;
		if(a_max > a) {
			result += (unsigned long long) (a_max - a); 
		} else {
			a_max = a; 
		}
	}
	
	cout << result << endl; 
	
	return 0; 
} 


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

int main() {
    int W, H, N; cin >> W >> H >> N;
    pair<int, int> lp, rp;
    lp = pair<int, int>(0, 0);
    rp = pair<int, int>(W, H);
    rep(i, N) {
        int x, y, a; cin >> x >> y >> a;
        if (a == 1) { if (x > lp.first) lp.first = x; }
        else if (a == 2) { if (x < rp.first) rp.first = x; }
        else if (a == 3) { if (y > lp.second) lp.second = y; }
        else if (a == 4) { if (y < rp.second) rp.second = y; }
    }
    int w = (rp.first - lp.first);
    int h = (rp.second - lp.second);
    if (h < 0 or w < 0) cout << 0 << endl;
    else cout << h * w << endl;
    return 0;
}


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

int main(void)
{
    int n;
    cin >> n;
    int w;
    vector<int> s(n+1);
    s[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> w;
        s[i+1] = s[i] + w;
    }

    int mins = 10000;
    for (int i = 0; i < n; i++) {
        mins = min(mins, abs(s[i] - (s[n] - s[i])));
    }
    cout << mins << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    int l, r;
    REP(i,s.length()){
        if (s[i] == 'A'){
            l = i; break;
        }
    }
    REP(i,s.length()) if (s[i] == 'Z') r = i;
    cout << r-l+1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
	int a[200],n;
	cin >> n;
	for(int i=0; i<n; i++)
		cin >> a[i];
	int res = 0;
	while(1){
		bool existOdd = false;
	    for(int i=0; i<n; i++){
		    if(a[i]%2==1)
				existOdd = true;
		}
		if(existOdd)
			break;
		for(int i=0; i<n; i++){
		    a[i] /= 2;
		}
		res++;
	}
	cout << res << endl;
	return 0;
}


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int mm[201][201];

int gcd(int a, int b){
   if(a<b){int tmp=a; a=b; b=tmp;}
   if(mm[a][b] != -1) return mm[a][b];
   int ret;
   if(a%b==0) ret=b;
   else ret=gcd(a%b, b);
   mm[a][b]=ret;
   return ret;
}

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

   rep(i, 201) rep(j, 201) mm[i][j]=-1;

   ll sum=0;
   for(int i=1; i<=k; i++) for(int j=1; j<=k; j++) for(int l=1; l<=k; l++){
      sum+=gcd(gcd(i, j), l);
   }

   cout << sum << endl;
   return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const ll INF = 1LL << 56;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll left=0,right=INF;
    while(right>left+1){
        ll x=(left+right)/2;
        ll con=0;
        for (ll i=0;i<n;i++){
            con+=(a[i]+x-1)/x-1;
        }
        if (con<=k)right=x;
        else left=x;
    }
    cout << right << endl;
    return 0;
}


Measured memory_bytes: 5124
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include <numeric>
using namespace std;
int main(){
long long int N,A,B;
cin>>N>>A>>B;
if(A>B)
cout<<0<<endl;
if(N==1&&A==B)
cout<<1<<endl;
else if(N==1&&A!=B)
cout<<0<<endl;
if(N>=2&&A<=B)
cout<<(B-A)*(N-2)+1<<endl;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 05/31/20 18:19:58
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T, T MOD>
class modint {
 private:
  T val_;

 public:
  constexpr modint() : val_(0) {}
  constexpr modint(T v) : val_(v%MOD) {}
  constexpr modint& operator=(T v) { val_ = v%MOD; return *this; }

  constexpr T val() const { return val_; }
  constexpr modint operator+(modint x) const { return (val() + x.val())%MOD; }
  constexpr modint operator+=(modint x) { return *this = *this + x; }
  constexpr modint operator++() { return *this += 1; }
  constexpr modint operator++(int) { modint c = *this; ++(*this); return c; }
  constexpr modint operator-(modint x) const { return (val() + MOD - x.val())%MOD; }
  constexpr modint operator-=(modint x) { return *this = *this - x; }
  constexpr modint operator--() { return *this -= 1; }
  constexpr modint operator--(int) { modint c = *this; --(*this); return c; }
  constexpr modint operator*(modint x) const { return (val() * x.val())%MOD; }
  constexpr modint operator*=(modint x) { return *this = *this * x; }
  friend constexpr modint pow(modint x, T p) {
    modint t = 1;
    modint u = x;
    while (p) {
      if (p & 1)
        t *= u;
      u *= u;
      p >>= 1;
    }
    return t;
  }
  constexpr modint operator/(modint x) const { return *this * pow(modint{x}, MOD-2); }
  constexpr modint operator/=(modint x) { return *this = *this / x; }

  constexpr bool operator==(modint x) const { return val() == x.val(); }
  constexpr bool operator!=(modint x) const { return val() != x.val(); }
  constexpr bool operator<(modint x) const { return val() < x.val(); };
  constexpr bool operator<=(modint x) const { return val() <= x.val(); };
  constexpr bool operator>(modint x) const { return val() > x.val(); };
  constexpr bool operator>=(modint x) const { return val() >= x.val(); };

  friend std::ostream& operator<<(std::ostream& os, const modint& x) {
    return os << x.val();
  }
  friend std::istream& operator>>(std::istream& is, modint& x) {
    return is >> x.val_;
  }

};

using mint = modint<ll, 998244353>;

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

  int n,s; cin>>n>>s;
  vector<int> A(n); for (auto& a:A) cin>>a;
  vector<mint> dp(s+1);
  dp[0] = pow(mint(2), n);
  for (int i = 0; i < n; i++) {
    for (int t = s-A[i]; t >= 0; t--) {
      dp[t+A[i]] += dp[t]/2;
    }
  }
  cout << dp[s] << endl;

  return 0;
}


Measured memory_bytes: 3596