akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef vector<vector<ll> > Graph;
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 = 1e18;

ll n,m,k;
vector<ll>a;
vector<ll>b;
vector<ll>sa;
vector<ll>sb;
//vector<ll>a;
// index が条件を満たすかどうか
bool isOK(ll ida,ll idb) {
    if (sa[ida]+sb[idb] <= k) return true;
    else return false;
}
// 汎用的な二分探索のテンプレ
ll binary_search(ll ida) {
    ll ok = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ng = (ll)sb.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(ida,mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> n >> m >> k;
    a.resize(n);
    b.resize(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    sa.resize(n+1,0);
    sb.resize(m+1,0);
    rep(i,n){
        sa[i+1]=sa[i]+a[i];
    }
    rep(i,m){
        sb[i+1]=sb[i]+b[i];
    }
    ll ans = 0;
    rep(i,n+1){
        ll now = binary_search(i);
        if(now==-1)continue;
        chmax(ans,i+now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9588
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int b[30];
int main(){
string s;
 cin>>s;
 int d;
 d=s.size();
 int a,b,c;a=b=c=0;
 for(int i=0;i<d;i++)
 {
     if(s[i]=='a')a++;
     if(s[i]=='b')b++;
     if(s[i]=='c')c++;
 }
 int z;z=0;
 while(a||b||c)
 { if(a&&b&&c){a--;b--;c--;}
   else if(a&&b&&!c){
    if(a!=b||(a==b&&a!=1))z=1;break;
   }
     else if(!a&&b&&c){
if(c!=b||(c==b&&c!=1))z=1;break;

     }
     else if(!b&&a&&c){
        if(a!=c||(a==c&&a!=1))z=1;break;
     }
     else{ if(a>1||b>1||c>1)
        z=1;break;}

 }
 if(z)cout<<"NO";
 else cout<<"YES";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

int n,a[N];
//a[j] - a[i] >= 2 i < j

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	for (int i = 1; i <= n; i++)
	{
		if (a[i] != 1 && a[i] != a[i-1])
			a[i]--;
	}

	for (int i = 2; i <= n; i++)
	{
		if (a[i] < a[i-1])
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 640
import heapq

n = int(input())
num = [ int(v) for v in input().split() ]

left_list = num[:n]
right_list = [ -i for i in num[2*n:] ]
left_list.sort()
right_list.sort()
sl, sr = sum(left_list), sum(right_list)
sum_left_list = [sl]
sum_right_list = [sr]

for p in num[n:2*n]:
    q = heapq.heappop(left_list)
    if p > q:
        sl += (p-q)
        heapq.heappush(left_list, p)
    else:
        heapq.heappush(left_list, q)
    sum_left_list.append(sl)

for p in num[2*n-1:n-1:-1]:
    p *= -1
    q = heapq.heappop(right_list)
    if p > q:
        sr += (p-q)
        heapq.heappush(right_list, p)
    else:
        heapq.heappush(right_list, q)
    sum_right_list.append(sr)

sum_right_list.reverse()
ans_list = [ sum_left_list[i] + sum_right_list[i] for i in range(n+1) ]
print(max(ans_list))

Measured memory_bytes: 119188
use std::io::stdin;
use std::time::SystemTime;
use std::collections::HashMap;

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

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

#[allow(dead_code)]
fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr
{
    read_line().split(" ").map(|n| n.parse::<T>().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn read_chars() -> Vec<char>
{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn print_time() -> () {
    println!("{:?}", SystemTime::now());
}

#[allow(unused_variables)]
fn main() {
    read::<u64>();
    let mut v: Vec<u64> = read_vec();
    let mut group = vec![v];
    
    let mut count = 0;
    loop {
        for i in 0..group.len() {
            let g = group[i].clone();
            if g.contains(&0) {
                if g.len() == 1 {
                    continue;
                }
                let mut t = vec![];
                for n in g {
                    if n == 0 {
                        if t.len() > 0 {
                            group.push(t);
                            t = vec![];
                        }
                    } else {
                        t.push(n);
                    }
                }
                if t.len() > 0 {
                    group.push(t);
                }
                group[i] = vec![0];
            }
        }
        
        for mut g in &mut group {
            let mut min = g[0];
            for i in 0..g.len() {
                let v = g[i];
                if min > v {
                    min = v;
                }
            }
            for i in 0..g.len() {
                g[i] = g[i] - min;
            }
            count = count + min;
        }
        if group.iter().all(|v| v == &[0]) {
            break;
        }
    }
    println!("{}", count);
}

Measured memory_bytes: 4352
#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;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

bool DEBUG = 0;
const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	map<string,int> cnt;
	forn(i,0,n){
		string s; cin>>s;
		cnt[s]++;
	}
	
	cout<<"AC x "<<cnt["AC"]<<'\n';
	cout<<"WA x "<<cnt["WA"]<<'\n';
	cout<<"TLE x "<<cnt["TLE"]<<'\n';
	cout<<"RE x "<<cnt["RE"]<<'\n';
	
	return 0;
}


Measured memory_bytes: 3664
#include<iostream>
using namespace std;
 
int main()
{
    int a, b;
    cin >> a >> b;
    if(a<b)
    {
        cout << "a < b"<< endl;
    }
    else if (a>b)
    {
        cout << "a > b" << endl;
    }
    else if (a == b)
    {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    if(b>c){
        temp=b;
        b=c;
        c=temp;
    }
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    printf("%d\n",a+b);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//C - Coloring Colorfully
int main(void){
    // Your code here!
    string s;
    std::cin >> s;
    string x="01";
    string y="10";
    int a=0,b=0;
    //01の順序
    for (int i = 0; i < s.length(); i++) {
        if(s[i]!=x[i%2]){
            a++;
        }
    }
    //10の順序
    for (int i = 0; i < s.length(); i++) {
        if(s[i]!=y[i%2]){
            b++;
        }
    }
    std::cout << min(a,b) << std::endl;
    
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll hoge(ll n, V &v){
    rep(i, v.size()){
        n = (n / v[i]) * v[i];
    }
    return n;
}

int main(){

    ll N;
    cin >> N;
    V v(N);
    rep(i, N)cin >> v[i];
    ll l = 2, h = 2;
    rrep(i, N){
        ll l2 = (l / v[i] + (l % v[i] > 0)) * v[i];
        ll h2 = (h / v[i]) * v[i] + (v[i] - 1);
        if(l2 > h2){
            cout << -1 << endl;
            return 0;
        }
        l = l2;
        h = h2;
    }
    if(hoge(l, v) == 2 && hoge(h, v) == 2)cout << l << " " << h << endl;
    else cout << -1 << endl;
    return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K; 
  
  if(A <= B){
    vector<int> c(A);
    for(int i = 1; i <= A; i++){
      if(A % i == 0 && B % i == 0){
        c.at(i - 1) = i;
      }
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    int d = c.at(K - 1);
    cout << d << endl;
  }
  else{
    vector<int> c(B);
    for(int i = 1; i <= B; i++){
      if(A % i == 0 && B % i == 0){
        c.at(i - 1) = i;
      }
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    int d = c.at(K - 1);
    cout << d << endl;
  }
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,0);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = max(node[2*i+1],node[2*i+2]);
    }
    void update(int x,int val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = max(node[2*x+1],node[2*x+2]);
        }
    }

    int getmax(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        int vl = getmax(a,b,2*k+1,l,(l+r)/2);
        int vr = getmax(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }

    int find(int a,int b,int x,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l || node[k] <= x) return b;
        if (k >= n-1) return k-n+1;
        int vl = find(a,b,x,2*k+1,l,(l+r)/2);
        if (vl != b) return vl;
        return find(a,b,x,2*k+2,(l+r)/2,r);
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    SegmentTree seg(a);
    for (int i = 0;i < q;++i) {
        int t,x,v;
        cin >> t >> x >> v;
        if (t == 1) seg.update(x-1,v);
        else if (t == 2) cout << seg.getmax(x-1,v) << newl;
        else cout << seg.find(x-1,n,v-1)+1 << newl;
    }
}

Measured memory_bytes: 6984
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる
  ll cost; // e.costでその辺の重みにアクセスできる
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  long long ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  string S;
  cin >> S;
  S.at(3) = '8';
  cout << S << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	string S;
	cin >> S;

	int result = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i + 0] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
		{
			result++;
		}
	}

	cout << result;

	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 drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int N, X[1 << 18], Y[1 << 18];
char D[1 << 18];

void Rotate() {
    // 時計回りに90度回転
	for (int i = 1; i <= N; i++) {
		int cx = Y[i], cy = 200000 - X[i];
        char cz;
		if (D[i] == 'U') cz = 'R';
		if (D[i] == 'R') cz = 'D';
		if (D[i] == 'D') cz = 'L';
		if (D[i] == 'L') cz = 'U';
		X[i] = cx; Y[i] = cy; D[i] = cz;
	}
}

vector<pair<int, char>> V1[1 << 19];
vector<pair<int, char>> V2[1 << 19];

int solve_01() {
    // 右向きと上向きが衝突する最短時間
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V1[i].clear();
	for (int i = 1; i <= N; i++) {
		if (!(D[i] == 'R' || D[i] == 'U')) continue;
		V1[X[i] + Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V1[i].begin(), V1[i].end());
		for (int j = 0; j < (int)V1[i].size() - 1; j++) {
			if (!(V1[i][j].second == 'R' && V1[i][j + 1].second == 'U')) continue;
			Answer = min(Answer, V1[i][j + 1].first - V1[i][j].first);
		}
	}
	return Answer * 10;
}

int solve_02() {
    // 右向きと左向きが衝突する最短時間
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V2[i].clear();
	for (int i = 1; i <= N; i++) {
		if (!(D[i] == 'L' || D[i] == 'R')) continue;
		V2[Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V2[i].begin(), V2[i].end());
		for (int j = 0; j < (int)V2[i].size() - 1; j++) {
			if (!(V2[i][j].second == 'R' && V2[i][j + 1].second == 'L')) continue;
			Answer = min(Answer, V2[i][j + 1].first - V2[i][j].first);
		}
	}
	return Answer * 5;
}

int main() {
    // 入力
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i] >> D[i];

	int FinalAns = (1 << 24);
	for (int t = 1; t <= 4; t++) {
		int val1 = solve_01(); FinalAns = min(FinalAns, val1);
		int val2 = solve_02(); FinalAns = min(FinalAns, val2);
		Rotate();   // 時計回りに90度回転
	}
	if (FinalAns == (1 << 24)) cout << "SAFE" << endl;
	else cout << FinalAns << endl;
	return 0;
}


Measured memory_bytes: 42520
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;
typedef pair<int,int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

// graph //
struct Edge {
    int from,to,cost;
    Edge(int f,int t, int c) : from(f), to(t), cost(c) {}
    bool operator<(const Edge &e){return cost < e.cost;}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

template<class T>
class ShortestPath {
    public:
        ShortestPath(int size){
            mDst.assign(size,INF);
        }

        // bellman_ford : 負の閉路があったらtrue
        bool bellman_ford(int s, int V, Edges &es){
            mDst[s] = 0;
            for(int i = 0; i < V;++i){
                for(auto e : es){
                    if(mDst[e.from]!=INF && mDst[e.to] > mDst[e.from] + e.cost){
                        mDst[e.to] = mDst[e.from] + e.cost;
                        if(i == V-1) return true;
                    }
                }
            }
            return false;
        }
        //
        
        // dijkstra
        void dijkstra(int s, Graph &g){
            mDst[s] = 0;
            priority_queue<pair<T,T>,vector<pair<T,T> >,greater<pair<T,T> > > pq;
            pq.push(make_pair(0,s));
            while(!pq.empty()){
                auto v = pq.top(); pq.pop();
                if(mDst[v.second] < v.first) continue;
                for(auto e : g[v.second]){
                    if(mDst[e.from] != INF && mDst[e.to] > mDst[e.from] + e.cost){
                        mDst[e.to] = mDst[e.from] + e.cost;
                        pq.push(make_pair(mDst[e.to],e.to));
                    }
                }
            }
        }
        //
        
                

        vector<T> getDst(){return mDst;}
    private:
        vector<T> mDst;
};


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int V,E,r,s,t,d;
    cin >> V >> E >> r;

    Graph g(V);
    ShortestPath<int> sp(V);
    REP(i,E){
        cin >> s >> t >> d;
        g[s].emplace_back(s,t,d);
    }
    sp.dijkstra(r,g);
    auto dst = sp.getDst();
    REP(i,V){
        if(dst[i]==INF) cout << "INF" << '\n';
        else cout << dst[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 15420
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+7;
const int mod=1e9+7;
const double pi=acos(-1);
int a[15][15];
int main(){
    int n,d;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>a[i][j];
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            int dis=0;
            for(int k=0;k<d;k++){
                dis+=(a[i][k] - a[j][k])* (a[i][k] - a[j][k]);
            }
            int sum=sqrt(dis);
            if(sum*sum==dis) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

const int INF = 100 * 100 * 100;

int main(){
    int n; cin >> n;
    int x[n], minv = INF, cost;
    rep(i, n) cin >> x[i];
    for(int p = 1; p <= 100; p++){
        cost = 0;
        rep(i, n){
            cost += (x[i] - p) * (x[i] - p);
        }
        minv = min(minv, cost);
    }
    cout << minv << endl;
    return 0;
}

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

char mcxi[] = {'i', 'x', 'c', 'm' };

int calc(string s){
	int res = 0;
	for(int i = 0; i < s.size(); ++i){
		int t = 1;
		if('2' <= s[i] && s[i] <= '9'){
			t = s[i] - '0';
			++i;
		}
		if(s[i] == 'm'){
			res += t * 1000;
		}
		else if(s[i] == 'c'){
			res += t * 100;
		}
		else if(s[i] == 'x'){	
			res += t * 10;
		}
		else if(s[i] == 'i'){
			res += t;
		}
	}
	return res;	
}

int main() {
	int n;
	cin >> n;
	for(int q = 0; q < n; ++q){
		string s1, s2, ans("");
		cin >> s1 >> s2;
		int l = calc(s1);
		int r = calc(s2);
		int w = l + r;
		int t = 3;
		while(pow(10, t) > w)
			t--;
		for(int i = 0; i  <= t; ++i){
			int a = w % 10;
			w /= 10;
			if(a == 0){
				continue;
			}
			else if(a == 1){
				ans += mcxi[i];
			}
			else{
				ans += mcxi[i] + to_string(a);
			}
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define endl '\n'
#define PI 3.14159265358979323844
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define mp make_pair
#define pb push_back
#define int long long int 
#define forr(i,a,b) for (int i= a; i <b; ++i)
    using namespace std; 
    signed main(){
        int n;
        cin>>n;
        int k;cin>>k;
        int arr[n];forr(i,0,n)cin>>arr[i];
        int dp[k+2]{0};
        forr(i,1,k+1){
         forr(k,0,n){
             if(i>=arr[k] &&dp[i-arr[k]]==0){dp[i]=1;}
                 }} 
  if(dp[k]==1)cout<<"First";
  else cout<<"Second";
         }
    

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

def recursion(y, x, island, dp):
    if island[y][x].isdigit() and int(island[y][x]) in range(10):        
        if y == 0 and x == 0:
            dp[y][x] = int(island[y][x])
        elif y == 0:
            if dp[y][x-1] != -1:
                dp[y][x] = dp[y][x-1] * 10 + int(island[y][x])
            else:
                dp[y][x] = int(island[y][x])
        elif x == 0:
            if dp[y-1][x] != -1:
                dp[y][x] = dp[y-1][x] * 10 + int(island[y][x])
            else:
                dp[y][x] = int(island[y][x])
        else:
            if dp[y-1][x] == -1 and dp[y][x-1] == -1:
                dp[y][x] = int(island[y][x])
            elif dp[y-1][x] == -1:
                dp[y][x] = dp[y][x-1] * 10 + int(island[y][x])
            elif dp[y][x-1] == -1:
                dp[y][x] = dp[y-1][x] * 10 + int(island[y][x])
            else:
                dp[y][x] = max(dp[y][x-1] * 10 + int(island[y][x]), dp[y-1][x] * 10 + int(island[y][x]))
    else:
        dp[y][x] = -1
        
def solve(w, h, island, dp):
    for i in range(h):
        for j in range(w):
            recursion(i, j, island, dp)
    #print dp
    print max(map(max, dp))

def func():
    '''

    '''
    while True:
        global count
        w, h = map(int, raw_input().split())

        if w == 0 and h == 0:
            break

        island = []
        count = 0
        for i in range(h):
            row = []
            line = raw_input()
            for j in line:
                row.append(j)
            island.append(row)
        
        dp = []
        for i in range(h):
            dp_row = []
            for j in range(w):
                dp_row.append(0)
            dp.append(dp_row)
        solve(w, h, island, dp)

if __name__ == '__main__':
    func()
    

Measured memory_bytes: 4400
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

N = int(input())
A = [None] + list(map(int, input().split()))
answer = []
B = [0] * (N + 1)

for n in range(1, N + 1)[::-1]:
    x = sum(B[2*n::n])
    if x % 2 == A[n]:
        continue
    else:
        B[n] += 1
        answer.append(str(n))

print(len(answer))
print(' '.join(answer))





Measured memory_bytes: 17800
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) {
    val list = readLine.split(" ").map(_.toInt)
    val s = list(0) * list (1)
    val l = 2*list(0)+2*list(1)
    println(s"$s $l")
  }
}

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

using namespace std;

#define long long long
#define INF (long) 1e18
#define MOD 1'000'000'007
#define mll map<long, long>
#define pll pair<long, long>
#define umap unordered_map
#define umll umap<long, long>
#define uset unordered_set
#define pb push_back
#define FOR(i, a, b) \
  for (long i = (a); i < (long) (b); i++)

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

  long n;
  cin >> n;

  set<string> s;
  while (n--) {
    string x;
    cin >> x;
    s.insert(x);
  }
  if ((long) s.size() == 3) puts("Three");
  else puts("Four");
}


Measured memory_bytes: 256
h={12=>6,13=>10,14=>12,15=>14,16=>27,17=>33,23=>7,24=>9,25=>12,26=>23,27=>30,34=>5,35=>8,36=>20,37=>27,45=>5,46=>17,47=>26,56=>12,57=>23,67=>10}
while(a=gets.to_i)>0
	x,y=gets.split.map(&:to_i)
	y+=x*60
	b=gets.to_i
	x,z=gets.split.map(&:to_i)
	z+=x*60
	c=h[a*10+b]
	c/=2.0 if c<27&&((1050<=y&&y<=1170)||(1050<=z&&z<=1170))
	p c.ceil*50
end

Measured memory_bytes: 2400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // long startTime = System.currentTimeMillis();

        Scanner scanner = new Scanner(System.in);

        long[] n = new long[3];
        n[0] = scanner.nextInt();
        n[1] = scanner.nextInt();
        n[2] = scanner.nextInt();
        int k = scanner.nextInt();
        scanner.close();

        int maxIdx = 0;
        if (n[maxIdx] < n[1]) {
            maxIdx = 1;
        }
        if (n[maxIdx] < n[2]) {
            maxIdx = 2;
        }

        // System.out.println(maxIdx);

        long d = (long) Math.pow(2, k);

        long result = 0;

        for (int i = 0; i < 3; i++) {
            result += (i == maxIdx) ? (n[i] * d) : n[i];
        }

        System.out.println(result);

        // System.out.println(System.currentTimeMillis() - startTime);
    }
}

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

using namespace std;
using ll = long long;

const ll MOD = 998244353;
ll x[301];
int N;

ll dp1[301][100001]; // 3-color
ll dp2[301][100001]; // 2-color


int main() {
    cin >> N;
    ll S = 0;
    ll ans = 1;
    for(int i = 0; i < N; i++) {
        cin >> x[i];
        S += x[i];
        ans *= 3;
        ans %= MOD;
    }

    dp1[0][0] = dp2[0][0] = 1;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 100001; j++) {
            dp1[i+1][j+x[i]] += (dp1[i][j] * 2) % MOD; // 色を塗り替えても同じ．
            dp1[i+1][j+x[i]] %= MOD;
            dp1[i+1][j] += dp1[i][j];
            dp1[i+1][j] %= MOD;

            dp2[i+1][j+x[i]] += dp2[i][j];
            dp2[i+1][j+x[i]] %= MOD;

            dp2[i+1][j] += dp2[i][j];
            dp2[i+1][j] %= MOD;
        }
    }

    for(int i = 0; i <= S/2; i++) {
        ans -= (dp1[N][i] * 3) % MOD; // 条件(S/2 > i)を満たさない数を引く
        ans %= MOD;
    }

    if(S%2 == 0) {
        ans += (dp2[N][S/2]*3 % MOD);
    }

    ans += MOD;
    ans %= MOD;
    cout << ans << endl;

}

Measured memory_bytes: 469760
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double num = 0;
        double jpy = 0;
        double btc = 0;
        String kind = "";
        List<Double> number = new ArrayList<>();
        for(int i = 0;i < N;i++) {
        	num = sc.nextDouble();
        	if("JPY".equals(sc.next())) {
        		jpy += num;
        	}
        	else {
        		btc += num;
        	}
        }
        btc *= 380000;
        jpy += btc;
        System.out.println(jpy);
	}

}

Measured memory_bytes: 23124
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, Q = map(int, input().split())
    uf = UnionFind(N)

    for _ in range(Q):
        query, x, y = map(int, input().split())
        if query == 0:
            uf.union(x, y)
        else:
            if uf.same(x, y):
                print('1')
            else:
                print('0')


if __name__ == '__main__':
    main()



Measured memory_bytes: 5808
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextInt();
        long m = scan.nextInt();
        if( n == 1&& m == 1) {
            System.out.println(1);
            return;
        }
        if(n == 1) {
            System.out.println(m - 2);
            return;
        }
        if(m == 1) {
            System.out.println(n -2);
            return;
        }
        System.out.println((n -2) * (m-2));
    }

}


Measured memory_bytes: 21844
def f(N):
    if N==0:
        return 0
    if N==1:
        return 1
    if N==2:
        return 1^2
    if N==3:
        return 0
    k = 2
    while 2**k<=N:
        k += 1
    k -= 1
    if 2**k==N:
        return N
    n = (N-2**k)//4
    cnt = 0
    i = 2**k+4*n
    while i<=N:
        cnt = cnt^i
        i += 1
    return cnt
A,B = map(int,input().split())
if A==0 and B==0:
    print(0)
elif A==0 and B>0:
    print(f(B))
else:
    print(f(B)^f(A-1))

Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define mod 1000000007
#define G() Cr=getchar()
int Xr;char Cr;
inline int rd(){   //读入优化
    Xr=0,G();
    while(Cr<'0'||Cr>'9')G();
    while(Cr>='0'&&Cr<='9')Xr=(Xr<<3)+(Xr<<1)+Cr-'0',G();
    return Xr;
}
string s;
int main(){
    cin>>s;
    if(s.size()!=6){
    	puts("No");
    	return 0;
	} 
    for(int i=0;i<5;i++){
    	if(s[i]<'a'||s[i]>'z'){
    		puts("No");
    		return 0;
		} 
	}
	if(s[2]!=s[3]||s[4]!=s[5]){
		puts("No");
    	return 0;
	}
	puts("Yes");
}


Measured memory_bytes: 256
#![allow(dead_code)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    bytes: Vec<u8>,
    begin: usize,
    end: usize,
}

impl Scanner {
    pub fn new() -> Self {
        let mut buffer: Vec<u8> = Vec::new();
        std::io::Read::read_to_end(&mut std::io::stdin(), &mut buffer).unwrap();
        let mut end = 0;
        while end < buffer.len() && !buffer[end].is_ascii_whitespace() {
            end += 1;
        }
        Scanner {
            bytes: buffer,
            begin: 0,
            end: end,
        }
    }
    pub fn next<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let s: &str = unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
        let ret: T = s.parse::<T>().unwrap();
        self.skip();
        ret
    }
    pub fn next_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
    pub fn next_word(&mut self) -> Vec<u8> {
        let r = Vec::from(&self.bytes[self.begin..self.end]);
        self.skip();
        r
    }
    fn skip(&mut self) {
        let mut begin = self.end;
        while begin < self.bytes.len() && self.bytes[begin].is_ascii_whitespace() {
            begin += 1;
        }
        let mut end = begin;
        while end < self.bytes.len() && !self.bytes[end].is_ascii_whitespace() {
            end += 1;
        }
        self.begin = begin;
        self.end = end;
    }
}

fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(
    u: usize,
    p: usize,
    dp: &mut Vec<i32>,
    ans: &mut Vec<usize>,
    a: &Vec<i32>,
    edge: &Vec<Vec<usize>>,
    pans: usize,
) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    ans[u] = if dp[idx] == i32::max_value() { pans + 1} else {pans};
    dp[idx] = a[u];

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge, ans[u]);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge, 0);
    for x in ans {
        println!("{}", x);
    }
}


Measured memory_bytes: 39224
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    
    string s;
    cin >> s;
    if((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ||
        (s[0] == s[2] && s[1] == s[3]&& s[0] != s[1]) ||
        (s[0] == s[3] && s[1] == s[2]&& s[0] != s[1]) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc132.contest.atcoder.jp/tasks/abc132_b

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MOD 1000000007
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int i;
    long long int stair[100001];
    for(i=0;i<=n;i++){
        stair[i] = -1;
    }

    int a[100000];
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
    }
    stair[0] = 1;
    if(a[0]==1){
        stair[1] = 0;
    }
    else{
    stair[1] = 1;
    }
    for(i=0;i<m;i++){
        stair[a[i]]=0;
    }
    for(i=2;i<=n;i++){
        if(stair[i]==0){
        }
        else{
        stair[i] = (stair[i-2]+stair[i-1])%MOD;
        //printf("stair[%d] = %lld\n",i,stair[i]);
        }
    }
    printf("%lld\n",stair[n]);
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll goukei=0;
    for(ll i=0; i<n; i++){
         cin >> a[i];
         goukei += a[i];
}
    ll zettaiti = goukei;
    ll totyu=0;
    for(ll i=0; i<n; i++){
        totyu += a[i];
    zettaiti = min(zettaiti,abs(totyu-(goukei - totyu)));
    }
    cout << zettaiti << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<string> s(N);

    for(int i = 0; i < N; i++){
        cin >> s.at(i);
    }
    int count=0;
    for(int i=0; i <N;i++){
        for(int j =0; j < s.at(i).size()-1; j++){
            if(s.at(i).at(j)=='A'&& s.at(i).at(j+1)=='B'){
                count ++;
            }
        }
    }

    //cout << count << endl;
    int acount=0,bcount=0,abcount=0;

    for(int i=0; i < N; i++){
        if(s.at(i).at(0)=='B')
            acount++;
        if(s.at(i).at(s.at(i).size()-1)=='A')
            bcount++;
        if(s.at(i).at(0)=='B'&&s.at(i).at(s.at(i).size()-1)=='A')
            abcount++;
    }
    acount -= abcount;
    bcount -= abcount;

   if(abcount==0){
       count +=min(acount,bcount);
   }else{
       if(acount==0&&bcount==0){
           count +=abcount -1;
       }else if(acount ==0 || bcount ==0){
           count +=abcount;
       }else{
           count += abcount + min(acount,bcount);
       }
   }
    //cout << "A" << acount << "B" << bcount << "C" <<abcount;
    cout << count <<endl;


}

Measured memory_bytes: 768
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String word = br.readLine();
		for(int i=0;i<word.length();i++){
			if(Character.isUpperCase(word.charAt(i))){
				System.out.print(Character.toLowerCase(word.charAt(i)));
			}else
				System.out.print(Character.toUpperCase(word.charAt(i)));
		}
		System.out.println("");
	}
}

Measured memory_bytes: 16968
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
3 2
4 1 5
'''

test_data2 = '''\
13 17
29 7 5 7 9 51 7 13 8 55 42 9 81
'''

test_data3 = '''\
10 400000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
'''
td_num=3

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3
    
if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        n,m=map(int,f.readline().split())
        a=list(map(int,f.readline().split()))
        # End Input code ---------------------------------------
else:
    # Start Input code ---------------------------------------
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    # End Input code ---------------------------------------

pre=0
acc=[0]*n
cnt=dict()
for i in range(n):
    pre+=a[i]
    pre=pre%m
    acc[i]=pre
    if pre in cnt:
        cnt[pre]+=1
    else:
        cnt[pre]=1
for i in range(n):
    acc
def comb(nn,rr):
    rr=min(rr,nn-rr)
    rt=1
    for i in range(rr):
        #rt=rt*(nn-i)/(rr-i)
        rt*=(nn-i)
    for i in range(rr):
        rt//=(rr-i)
    return int(rt)
ans=0
for i in cnt:
    cc=cnt[i]
    if cc>1: ans+=comb(cc,2)
if 0 in cnt: ans+=cnt[0]
#print(ans,'n,m=',n,m,' a=',a,'acc=',acc,'cnt=',cnt)
print(ans)
#ans=count(0)+2^(count(n)-1)

Measured memory_bytes: 14748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d[100005],mod=1e9+7;
int main(){
	ll n,k,ans=1,num=2;
	cin>>n>>k;
	for(ll i=1;i<n;i++){
		ll u,v;cin>>u>>v;
		d[u]++;d[v]++;
	}
	if(n<=3){
		for(ll i=0;i<n;i++){
			ans=(ans%mod*(k-i)%mod)%mod;
		}
		cout<<ans%mod<<endl;
		return 0;
	}
	for(ll i=1;i<=n;i++){
		if(d[i]>=3){
			for(ll j=3;j<=d[i];j++){
				ans=(ans%mod*(k-j)%mod)%mod;num++;
			}
		}
	}
	ans=(ans%mod*k%mod*(k-(ll)1)%mod)%mod;
	//cout<<ans<<" "<<num<<endl;
	for(int i=num+1;i<=n;i++){
		ans=(ans%mod*(k-2)%mod)%mod;
	}
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 1152
use std::io;
use std::cmp;


fn main() {
    let (l, r) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut ans: usize = std::usize::MAX;
    'outer: for i in l..r + 1 { for j in (i + 1)..r + 1 {
        ans = cmp::min(ans, (i * j) % 2019);
        if ans == 0 { break 'outer; }
    }}

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


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int n=0; n<N; n++) {
        cin >> a[n];
    }
    
    int b=0;
    vector<int> ans(N);
    for(int n=N-1; n>=0; n--) {
        int curn=n+1;
        int tmp=0;
        int cnt=2;
        // cout << curn << " :";
        while(curn*cnt<=N) {
            tmp += ans[curn*cnt-1];
            tmp %= 2;
            // cout << curn*cnt << " ";
            // cout << ans[curn*cnt-1] << ", ";
            cnt++;
        }
        // cout << endl;
        if(tmp) {
            ans[n] = a[n] ? 0 : 1;
        } else {
            ans[n] = a[n];
        }
        if(ans[n]) b++;
    }
    cout << b << endl;
    for(int n=0; n<N; n++) {
        if(ans[n]) {
            cout << n+1 << " ";
        }
    }
    if(b) cout << endl;


    return 0;
    
}

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

using namespace std;

int main(){
	deque<int> hoge;
	int n;
	cin>>n;
	bool now=true;

	for(int i=0;i<n;i++){
		int fuga;
		cin>>fuga;

		if(now) hoge.push_back(fuga);
		else hoge.push_front(fuga);

		now=!now;
	}

	while(!hoge.empty()){
		if(now){
			cout<<hoge.front();
			hoge.pop_front();
		}else{
			cout<<hoge.back();
			hoge.pop_back();
		}

		if(!hoge.empty()) cout<<" ";
	}

	cout<<endl;

	return 0;
}


Measured memory_bytes: 2944
//https://atcoder.jp/contests/dp/tasks/dp_b
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    int n,k; cin>>n>>k;
    vector<int> a(n);
    for(int i =0; i<n; i++){
        cin>>a[i];
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i =0; i<n; i++){
        for(int j = i + 1; j<=i + k; j++){
            if(j < n){
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
            }
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
A, B = map(int, input().split())

def gcd(x, y):
    return gcd(y, x%y) if y else x

def factorize(n):
    res = []
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
            continue
        res.append([i, n])
        while n % i == 0:
            n //= i
            res[-1][1] += 1
        i += 1
    if n != 1:
        res.append([n,1])
    return res

g = gcd(A, B)
f = factorize(g)
ans = len(f) + 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <cstring>

using namespace std;
#define int long long

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

Measured memory_bytes: 764
object Main extends App {

  def read() = {
    val n = scala.io.StdIn.readInt()
    val monstersArr = scala.io.StdIn.readLine().split(" ").map(_.toLong)
    val heroesArr = scala.io.StdIn.readLine().split(" ").map(_.toLong)
    (n, monstersArr, heroesArr)
  }


  def solve() = {
    val (n, monstersArr, heroesArr) = read()
    var defeatCount = 0L
    for(i <- 0 until heroesArr.length) {
      // City 1
      val tmpDefeat = Math.min(monstersArr(i), heroesArr(i))
      defeatCount += tmpDefeat
      // City 2
      val tmpDefeat2 = Math.min(monstersArr(i+1), heroesArr(i) - tmpDefeat)
      defeatCount += tmpDefeat2
      monstersArr(i+1) -= tmpDefeat2
    }
    defeatCount
  }

  println(solve)

}

Measured memory_bytes: 58696
#include <bits/stdc++.h>
#define MAX (ll)(1e6 + 7)
#define INF (ll)(1e17 + 7)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 22

using namespace std;
using ll = long long;

vector<int> gr[MAX];

int main () {
	int n, x, y;
	cin >> n >> x >> y;
	for (int i = 1; i < n; i++) {
		gr[i].push_back (i + 1);
		gr[i + 1].push_back (i);
	}
	gr[x].push_back (y);
	gr[y].push_back (x);
	int ans[n + 1] = {};
	for (int i = 1; i <= n; i++) {
		bool co[n + 1] = {};
		queue<pair<int, int>> q;
		q.push (make_pair (i, 0));
		co[i] = 1;
		while (q.size ()) {
			int no = q.front ().first, d = q.front ().second;
			q.pop ();
			for (int x : gr[no]) {
				if (!co[x]) {
					ans[d + 1]++;
					q.push (make_pair (x, d + 1));
					co[x] = 1;
				}
			}
		}
	}
	for (int i = 1; i < n; i++) {
		cout << ans[i] / 2 << "\n";
	}
}


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

int main() {
	int a, b;
	cin >> a >> b;

	int ans = 0;
	for (int i = 0; i < 2; i++) {
		if (a > b) {
			ans += a--;
		}
		else {
			ans += b--;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256