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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while(1){
    string s;
    cin >> s;
    if(s=="0") break;
    int n = SZ(s);
    int sum =0;
    REP(i,n) sum += s[i] - '0';
    cout << sum <<endl;
  }



  return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n;cin>>n;
	vector<int> A;
	vector<pair<int,int>> B;
	rep(i,n){
		int a;cin>>a;
		A.push_back(a);
		B.push_back({a,i});
	}
	sort(all(A));
	sort(all(B));
	int max = A.back();
	int max_i = B.back().second;
	int ans_i = 0;
	int ans_r = 0;
	rep(i,n){
		if(min(max-A[i], A[i]) > ans_r){
			ans_r = min(max-A[i], A[i]);
			ans_i = i;
		}
	}
	cout<<max<<" "<<A[ans_i]<<endl;
	return 0;
}


Measured memory_bytes: 1780
#include <vector>
#include <iostream>
#include <complex>
using namespace std;

typedef complex<long long> P;

string s;
int p;

P A();
P B();
P C();

P A(){
	P l = B();
	while( s[p] == '+' || s[p] == '-' ){
		char c = s[p++];
		P r = B();
		if( c == '+' ) l += r;
		else l -= r;
		if( abs(l.real()) > 10000 || abs(l.imag()) > 10000 ) throw -1; 
	}
	if( abs(l.real()) > 10000 || abs(l.imag()) > 10000 ) throw -1; 
	return l;
}
P B(){
	P l = C();
	while( s[p] == '*' ){
		char c = s[p++];
		P r = C();
		l *= r;
		if( abs(l.real()) > 10000 || abs(l.imag()) > 10000 ) throw -1; 
	}
	if( abs(l.real()) > 10000 || abs(l.imag()) > 10000 ) throw -1; 
	return l;
}
P C(){
	if( s[p] == '(' ){
		p++;
		P r = A();
		p++;
		return r;
	}
	if( s[p] == '-' ){
		p++;
		return -C();
	}
	if( s[p] == '+' ){
		p++;
		return C();
	}
	long long a = 0;
	int fst = 0;
	while( s[p] >= '0' && s[p] <= '9' || s[p] == 'i'){
		if( s[p] == 'i' ){
			p++;
			if( !fst ) a = 1;
			return P(0,a);
		}else{
			a = a * 10 + s[p] - '0';
			p++;
			fst = true;
		}
		if( abs(a) > 10000 ) throw -1; 
	}
	return P(a,0);
}

int main(){
	while(getline(cin,s)){
		p = 0;
		try{
			P r = A();
			if( r.real() ){
				if( r.imag() ){
					if( r.imag() == -1 ){
						cout << r.real() << "-1i" << endl;
					}else if( r.imag() == 1 ){
						cout << r.real() << "+1i" << endl;
					}else if( r.imag() < 0 ){
						cout << r.real() << r.imag() << "i" << endl;
					}else if( r.imag() > 0 ){
						cout << r.real() << "+" << r.imag() << "i" << endl;
					}
				}else{
					cout << r.real() << endl;
				}
			}else{
				if( r.imag() ){
					if( r.imag() == -1 ){
						cout << "-1i" << endl;
					}else if( r.imag() == 1 ){
						cout << "1i" << endl;
					}else{
						cout << r.imag() << "i" << endl;
					}
				}else{
					cout << 0 << endl;
				}
			}
		}catch(int x){
			cout << "overflow" << endl;
		}
	}
}

Measured memory_bytes: 1256
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        string s;
        int H;
        int W;
        string[] str;
        string outputRow = string.Empty;

        while((s = Console.ReadLine() ) != null)
        {
            str = s.Split(' ');
            H = int.Parse(str[0]);
            W = int.Parse(str[1]);

            if (H == 0 || W == 0) break;

            for(int i = 0; i < W; i++)
            {
                outputRow += "#";
            }
            for(int i = 0; i < H; i++)
            {
                Console.WriteLine(outputRow);
            }
            Console.WriteLine();
            outputRow = string.Empty;
        }
    }
}

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

N = int(input())
vN = list(map(int, input().split()))

even = {}
odd = {}
# 奇数番目と偶数番目に分けて集計
for i in range(N):
    if i % 2 == 0:
        even[vN[i]] = even.get(vN[i], 0) + 1
    else:
        odd[vN[i]] = odd.get(vN[i], 0) + 1

# 集計数の多い順ソート
even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

# 1番多い数字が同じだった場合の別処理
if even_sorted[0][0] == odd_sorted[0][0]:
    # 偶奇それぞれ数字が1種類しかない場合は、この後の比較処理のためにダミーの0を入れておく
    if len(even_sorted) == 1:
        even_sorted.append((0, 0))
    if len(odd_sorted) == 1:
        odd_sorted.append((0, 0))
    # 偶奇それぞれを2番目にしてみて、数の大きい方
    print(N - max(even_sorted[1][1] + odd_sorted[0][1], even_sorted[0][1] + odd_sorted[1][1]))
else:
    print(N - even_sorted[0][1] - odd_sorted[0][1])

Measured memory_bytes: 20764
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
    long long int n, ans = 0;
    string s;
    cin >> s;
    n = s.size();
    if(n == 2) {
        ans = 9;
    } else if(n == 3) {
        ans = 9 + atoi(s.c_str()) - 99;
    } else if(n == 4) {
        ans = 909;
    } else if(n == 5) {
        ans = 909 + atoi(s.c_str()) - 9999;
    } else if(n == 6) {
        ans = 90909;
    } else {
        ans = atoi(s.c_str());
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const long double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

void solve(){     
    int n;
    cin >> n;
    
    set <int> st;
    vector <int> a;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a.pb(x);
    }
    int ans = 0;
    for (int i = 0; i < a.size(); i++){
        for (int j = i + 1; j < a.size(); j++){
            for (int  k = j + 1; k < a.size(); k++){
                if (a[i] == a[j] || a[j] == a[k] || a[i] == a[k]) continue;
                vector <int> v = {a[i], a[j], a[k]};
                sort(v.begin(), v.end());
                if (v[0] + v[1] > v[2]) ans++;
            }
        }
    }
    cout << ans << endl;
    
    
    

}
int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(6);
    //freopen("input.txt", "r", stdin);   
    //freopen("sausage.in","r",stdin); freopen("sausage.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		sc.close();

		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += l + i;
		}

		int ans = Integer.MAX_VALUE;
		int idx = -1;
		for (int i = 0; i < n; i++) {
			int val = sum - (l + i);
			val = Math.abs(sum - val);
			if (val < ans) {
				ans = val;
				idx = i;
			}
		}
		System.out.println(sum - (l + idx));
	}
}


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

struct StTrain
{
  StTrain() :
    m_nNext(0), m_nDone(false)
  { }

  int  m_nNext;
  bool m_nDone;
};

void fnInput(vector<StTrain>& rvoTrain)
{
  int nSize;
  cin >> nSize;

  StTrain oTrain;
  rvoTrain.resize(nSize, oTrain);
  
  for (int n = 0; n < nSize; n++)
    cin >> rvoTrain[n].m_nNext;
}

int fnTrain(vector<StTrain>& rvoTrain)
{
  int nCnt = 0;
  int n = 0;
  while (true)
  {
    nCnt++;
    if (rvoTrain[n].m_nDone)       return -1;

    rvoTrain[n].m_nDone = true;
    if (rvoTrain[n].m_nNext == 2)  return nCnt;
 
    n = rvoTrain[n].m_nNext - 1;
  }
}
    
int main()
{
  vector<StTrain> voTrain;
  
  fnInput(voTrain);
  int nReslt = fnTrain(voTrain);
  cout << nReslt << endl;

  return 0;
}

Measured memory_bytes: 1024
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int A, B;

    cin >> A >> B;

    cout << max(A+B, max(A-B, A*B)) << endl;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
     cin>>a[i];
  sort(a.rbegin(),a.rend());
  if(n<=k)
     cout<<0;
  else{
    long long s=0;
    for(int i=k;i<n;i++)
      s=s+a[i];
    cout<<s;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int suml[maxn], sumr[maxn];

int gcd(int x, int y) {
    return y==0?x:gcd(y, x%y);
}

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

    if (n==1) {
        cout << a[1] << endl;
        return 0;
    }

    suml[0] = 0;
    for (int i=1; i<=n; i++) {
        suml[i] = gcd(a[i], suml[i-1]);
    }

    sumr[n] = a[n];
    sumr[0] = 0;
    for (int i=n-1; i>=1; i--) {
        sumr[i] = gcd(a[i], sumr[i+1]);
    }

    int ans = max(suml[n-1], sumr[2]);
    for (int i=2; i<n; i++) {
        ans = max(ans, gcd(suml[i-1], sumr[i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;

ll m_pow(int p, int n){
    if(n==0) return 1;
    else if(n%2){
        ll now = m_pow(p,(n-1)/2);
        return (now*now%MOD)*p%MOD;
    }
    else{
        ll now = m_pow(p,n/2);
        return now*now%MOD;
    }
}

int main(){
    int n;
    cin >> n;
    ll ans;
    ans = m_pow(10,n) - 2*m_pow(9,n) + m_pow(8,n) + 2*MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> vec(H);
   for (int i = 0; i < H; i++) {
    cin >> vec.at(i);
   }
  
  for (int i = 0; i < H; i++) {
  
    for (int j = 0; j < W; j++) {
      if (vec.at(i).at(j) == '#') {
        continue;
      }
      else if (vec.at(i).at(j) == '.') {
       int count = 0;
        if (i != 0 && j != 0 && vec.at(i-1).at(j-1) == '#') {
          count++;
        }
        if (i != 0 && vec.at(i-1).at(j) == '#') {
          count++;
        }
        if (i != 0 && j != W-1 && vec.at(i-1).at(j+1) == '#') {
          count++;
        }
        if (j != 0 && vec.at(i).at(j-1) == '#') {
          count++;
        }
        if (j != W-1 && vec.at(i).at(j+1) == '#') {
          count++;
        }
        if (i != H-1 && j != 0 && vec.at(i+1).at(j-1) == '#') {
          count++;
        }
        if (i != H-1 && vec.at(i+1).at(j) == '#') {
          count++;
        }
        if (i != H-1 && j != W-1 && vec.at(i+1).at(j+1) == '#') {
          count++;
        }
        
       if (count == 0) {
       vec.at(i).at(j) = '0';
       }
       else if (count == 1) {
       vec.at(i).at(j) = '1';
       }
       else if (count == 2) {
       vec.at(i).at(j) = '2';
       }
       else if (count == 3) {
       vec.at(i).at(j) = '3';
       }
       else if (count == 4) {
       vec.at(i).at(j) = '4';
       }
       else if (count == 5) {
       vec.at(i).at(j) = '5';
       }
       else if (count == 6) {
       vec.at(i).at(j) = '6';
       }
       else if (count == 7) {
       vec.at(i).at(j) = '7';
       }
       else if (count == 8) {
       vec.at(i).at(j) = '8';
       }
      } 
    }
    
    cout << vec.at(i) << endl;
    
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace  std;
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rep(n) for (int i = 0; i < n; ++i)

const int md = 1e9 + 7; //998244353 ;
void addto(int &x, int y) { x = x + y; if (x >= md) x -= md; }
int add(int x, int y) { int z = x + y; return z >= md? z -= md : z;}
void updmin(auto&x, auto y ) { if (y < x) x = y;}
void updmax(auto&x, auto y ) { if (y > x) x = y;}
long long pw(auto x, auto y) {	
	long long s = 1;
	while(y) {
		if (y & 1) s = s * x % md;
		x= 1LL * x * x % md; y /= 2;
	}
	return s;
}


const int maxn = 1e6 + 10;

int T, n, m;

void task() {
	int n, k;  cin >> n;
	vector<int> a(n + 1);
	debug(n);
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		debug(a[i]);
	}
  vector<long long> f(n + 1);
  f[1] = 1000;
  long long ans = 1000;
  for (int i = 2; i <= n; ++i) {
		f[i] = f[i - 1];
		for (int j = 1; j < i; ++j) if (a[i] > a[j]) {
			f[i] = max(f[i], f[j] / a[j] * a[i] + f[j] - f[j] / a[j] * a[j]);
		}
		
		ans = max(ans, f[i]);
		debug(ans);
	}
	cout << ans << endl;
	// you should actually read the stuff at the bottom
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout<<fixed<<setprecision(20);
  T = 1;
  for (int ti = 1; ti <= T; ++ti) {
    task();
  }
  return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* write down
*/


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

int main() {
    int R, G, B, n;
    cin >>R >>G >>B >>n;
    int ret = 0;
    for (int r = 0; r <= 3000; r++) {
        for (int g = 0; g <= 3000; g++) {
            if (r*R + g*G <= n && (n - r*R - g*G)%B==0) {
                ret++;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(std::string s, long long K)
{

    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i] == 'a')
            continue;
        if ('z' - s[i] + 1 <= K)
        {
            K -= (ll)('z' - s[i] + 1);
            s[i] = 'a';
        }
    }

    K %= 26;
    s[s.size() - 1] += K;
    cout << s << endl;
}

int main()
{
    std::string s;
    std::cin >> s;
    long long K;
    scanf("%lld", &K);
    solve(s, K);
    return 0;
}


Measured memory_bytes: 512
import java.io.PrintWriter

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    //    val sc = new Scanner(System.in)
    val n, q = Scanner.nextInt()

    val tree = new Array[mutable.Set[Int]](n)

    for (i <- tree.indices) {
      tree(i) = mutable.Set.empty
    }

    val vertex = new Array[Int](n)
    for (_ <- 0 until n - 1) {
      val a, b = Scanner.nextInt()
      tree(a - 1) += b - 1
      tree(b - 1) += a - 1
    }

    for (_ <- 0 until q) {
      val p, x = Scanner.nextInt()
      vertex(p - 1) += x
    }

    val queue = mutable.Queue(0)
    val s = mutable.Set(0)  
    while (queue.nonEmpty) {
      val i = queue.dequeue()
      tree(i).foreach(j => {
        if (!s.contains(j)) {
          vertex(j) += vertex(i)
          queue.enqueue(j)
          s += j
        }
      })
    }

    printArray(vertex)
  }

  def printArray[T](arr: Array[T]): Unit = {
    val pw = new PrintWriter(System.out)

    for (i <- arr.indices) {
      if (i != arr.length - 1) {
        pw.print(s"${arr(i)} ")
      }
    }
    pw.println(arr(arr.length - 1))
    pw.flush()
  }
}


object Scanner {
  private val buf = new Array[Byte](1024);
  private var ptr = 0;
  private var len = 0

  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }

  def nextLong(): Long = {
    if (!hasNext()) ???
    var minus = false;
    var b = readByte()
    if (b == '-') {
      minus = true;
      b = readByte()
    }

    def go(b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') {
        go(readByte(), n * 10 + b - '0')
      }
      else if (minus) {
        -n
      } else {
        n
      }

    go(b)
  }

  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }

  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126

  @inline private def readByte(): Byte =
    if (hasNextByte()) {
      val res = buf(ptr);
      ptr += 1;
      res
    } else {
      -1
    }

  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) {
      ptr = 0;
      len = System.in.read(buf);
      len > 0
    } else {
      true
    }

  def nextDouble(): Double = next.toDouble

  def next(): String = {
    if (!hasNext()) ???
    val sb = new StringBuilder;
    var b = readByte()
    while (isPrintableChar(b)) {
      sb.append(b.toChar);
      b = readByte()
    }
    sb.toString
  }
}

Measured memory_bytes: 131360
sc = iter(open(0).read().split())
ni = lambda: int(next(sc))
ns = lambda: next(sc)

N, K = ni(), ni()

K2 = K * 2
A = [[0] * K2 for _ in range(K2)]
for _ in range(N):
    x, y, c = ni(), ni(), ns()
    if c == "W":
        y += K
    A[y % K2][x % K2] += 1

S = [[0] * (K2 + 1) for _ in range(K2 + 1)]
for i in range(K2):
    for j in range(K2):
        S[i + 1][j + 1] = (
            A[i][j]
            + S[i + 1][j]
            + S[i][j + 1]
            - S[i][j]
        )

ans = 0
for i in range(K, K2 + 1):
    for j in range(K, K2 + 1):
        res = (
            S[i][j] + S[i - K][j - K] - S[i - K][j] - S[i][j - K]
            + S[i - K][j - K]
            + S[K2][j - K] - S[i][j - K]
            + S[i - K][K2] - S[i - K][j]
            + S[K2][K2] + S[i][j] - S[i][K2] - S[K2][j]
        )
        ans = max(ans, res, N - res)

print(ans)

Measured memory_bytes: 147588
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define Toktama ""

using namespace std;

#ifdef superset
  #include <ext/pb_ds/assoc_container.hpp>
  #include <ext/pb_ds/tree_policy.hpp>
  #include <ext/pb_ds/detail/standard_policies.hpp>

  using namespace __gnu_pbds;
  typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 300 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int get_int() {
  char x = getchar();
  bool mns = 0;
  while (!isdigit(x)) mns |= x == '-', x = getchar();
  int res = 0;
  while (isdigit(x)) res = res * 10 + x - '0', x = getchar();
  if (mns) res = -res;
  return res;
}
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
int mult(int x, int y) {
  return x * 1ll * y % mod;
}
int sum(int x, int y) {
  add(x, y);
  return x;
}

int n, m;
int ptr[N], bad[N], cnt[N];
int a[N][N];

bool check(int mid) {
  memset(bad, 0, sizeof(bad));
  memset(cnt, 0, sizeof(cnt));
  rep(i, 1, n) {
    ptr[i] = 1;
    cnt[a[i][1]]++;
  }
  set < pair <int, int> > st;
  rep(i, 1, m)
    st.insert({cnt[i], i});
  while (sz(st)) {
    pair <int, int> v = *st.rbegin();
    if (v.f <= mid) break;
    st.erase(--st.end());
    if (bad[v.s]) continue;
    bad[v.s] = 1;
    memset(cnt, 0, sizeof(cnt));
    rep(i, 1, n) {
      while (bad[a[i][ptr[i]]]) ptr[i]++;
      if (ptr[i] > m) return 0;
      cnt[a[i][ptr[i]]]++;
    }
    st.clear();
    rep(i, 1, m)
      if (!bad[i]) st.insert({cnt[i], i});
  }
  return 1;
}
void solve() {
  n = get_int(), m = get_int();
  rep(i, 1, n) {
    rep(j, 1, m) {
      a[i][j] = get_int();
    }
  }
  int l = 1, r = n, res = n;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid)) res = mid, r = mid - 1;
    else l = mid + 1;
  }
  cout << res;
}
int main() {
  #ifndef Toktama
    freopen (Toktama".in", "r", stdin);
    freopen (Toktama".out", "w", stdout);
  #endif
  int t = 1;
  while (t--)
    solve();
  ioi
}


Measured memory_bytes: 640
N, P = map(int, input().split())
A = map(int, input().split())
n = 0

for a in A:
    if a % 2 == 0:
        n += 1

if n == N:
    if P == 0:
        print(2**N)
    else:
        print(0)
else:
    print(2**(N-1))

Measured memory_bytes: 3060
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);
int a, b;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> a >> b;
    if (a > b) swap(a, b);
    for (int i = 0; i < b; i++) cout << a;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); 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; }

long long calc(long long A) {
  if (A <= 0) return 0;

  long long ans = 0;
  rep(i, 50) {
    // 0桁目: 2
    // 1桁目: 4
    // 2桁目: 8
    long long loop = 1LL << i+1;
    long long cnt = (A+1)/loop * loop/2;
    // 0000....0001111...111
    cnt += max(0LL, (A+1)%loop - loop/2);
    // cout << cnt << endl;

    if (cnt%2 == 1) {
      ans += 1LL << i;
    }
  }

  return ans;
}

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

  long long A; cin >> A;
  long long B; cin >> B;

  cout << (calc(B)^calc(A-1)) << endl;
}

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

int n;
ll dp[100000][4],a[100000];

ll solve(){
    dp[0][0] = -a[0];
    dp[0][1] = -1e15;
    dp[0][2] = -1e15;
    dp[0][3] = a[0];

    for(int i = 0;i < n-1;i ++){
        dp[i+1][0] = max(dp[i][2],dp[i][3])-a[i+1];
        dp[i+1][1] = max(dp[i][0],dp[i][1])+a[i+1];
        dp[i+1][2] = max(dp[i][0],dp[i][1])-a[i+1];
        dp[i+1][3] = max(dp[i][2],dp[i][3])+a[i+1];
    }
    return max(dp[n-1][2],dp[n-1][3]);
}

int main(){
    cin >> n;
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 4096
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
typedef vector<ii> vii;
typedef vector<lii> lvii;

#define min_prq(t) priority_queue<t,vector<t>,greater<t>>
#define max_prq(t) priority_queue<t>
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n;
	cin>>n;
	lvi a(n+1);
	bool flag=true;
	lvii nodes(n+2,{1,1});
	for (int i = 0; i < n+1; ++i)
	{
		cin>>a[i];

		if(a[i]>nodes[i].ss) flag=false;

		if(a[i]>=nodes[i].ff) nodes[i+1].ff=0;
		else nodes[i+1].ff=(nodes[i].ff-a[i]);

		nodes[i+1].ss=(nodes[i].ss-a[i])*2;
		nodes[i+1].ss=min((ll)1e18,nodes[i+1].ss);
	}
	if(a[n]<nodes[n].ff) flag=false;
	if(!flag)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	ll ans=a[n];
	ll ct=a[n];
	for(int i=n-1;i>=0;i--)
	{
		ct+=a[i];
		if(ct>nodes[i].ss) ct=nodes[i].ss;
		if(ct<nodes[i].ff || ct>nodes[i].ss) flag=false;
		ans+=ct;
	}
	if(!flag)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 5576
#include<bits/stdc++.h>
 using namespace std;
 #define rep(i, c) for(int i = 0; i < (int)c; i++)
 const int inf = 1000000000; // 10^9

 int main() {
 int n;
 cin >> n;
 int mas[n];
 for (int i = 0; i < n; i++)
 {
     cin >> mas[i];
 }
 sort(mas, mas+n);
 bool flag = true;
 for (int i = 0; i < n-1; i++)
 {
     if(mas[i]==mas[i+1]) flag = false;
 }
 if(flag) cout << "YES";
 if(!flag)cout << "NO";
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;cin >> a >> b;
    cout << a*b << endl;
}


Measured memory_bytes: 3652
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

# --------------------------------------------

dp = None

def main():
    n_case, n_tle = list(map(int, input().split()))

    t_each_submit = 1900 * n_tle + 100 * (n_case - n_tle)

    mean_submit_times = (2 ** n_tle)

    print(t_each_submit * mean_submit_times)

main()


Measured memory_bytes: 5120
n = int(input())
if n % 4 ==0 or n % 7 ==0:
    print('Yes')
    exit()
for i in range(n // 4 + 1):
    for j in range (n // + 1):
        if 4 * i + 7 * j == n:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m=inf;
    sf(n);
    for(i=1;i<=sqrt(n+1);i++)
    {
        if(n%i==0)
        {
            m = min(m,(i-1)+(n/i-1));
        }
    }
    pf(m);
    return 0;
}



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

using namespace std;

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

    string s;
    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        cout << "Bad\n";
    else
        cout << "Good\n";

    return 0;
}

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

class Node{
public:
	Node* prev;
	Node* next;
	int data;
	Node(){
		prev=0;
		next=0;
		data=0;
	}
};
	
class List{
private:
	Node head;
public:
	List(){
		head.prev=&head;
		head.next=&head;
	}
	int insert(int x);
	int del(int x);
	int deleteFirst();
	int deleteLast();
	void print();
};

int List::insert(int x){
	Node*p=new Node();

	if(p==0)
		return -1;

	Node* q=&head;
	Node* r=head.next;
	
	p->prev=q;
	p->next=r;
	p->data=x;

	q->next=p;
	r->prev=p;
	
	return 0;
}

int List::del(int x){
	Node* p;

	for(p=head.next;p!=&head;p=p->next){
		if(p->data==x)
			break;
	}

	if(p==&head)
		return -2;

	Node* q=p->prev;
	Node* r=p->next;

	q->next=r;	
	r->prev=q;

	delete p;
	
	return 0;
}

int List::deleteFirst(){
	Node* p=head.next;
	
	if(p==&head)
		return -2;
	
	Node* q=p->prev;
	Node* r=p->next;

	q->next=r;	
	r->prev=q;		

	delete p;
	
	return 0;
}

int List::deleteLast(){
	Node* p=head.prev;
	
	if(p==&head)
		return -2;
	
	Node* q=p->prev;
	Node* r=p->next;

	q->next=r;	
	r->prev=q;		

	delete p;
	
	return 0;	
}

void List::print(){
	for(Node* p=head.next;p!=&head;p=p->next){
		cout<<p->data;

		if(p->next!=&head){
			cout<<' ';
		}
		else{
			cout<<endl;
		}
	}
}

int main(){
	List L;

	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		char com[20];
		cin>>com;
	
		if(com[0]=='i'){
			int x;
			cin>>x;
		
			L.insert(x);
		}
		else if(com[6]=='F'){
			L.deleteFirst();
		}
		else if(com[6]=='L'){
			L.deleteLast();
		}
		else{
			int x;
			cin>>x;
	
			L.del(x);
		}
	}

	L.print();

	return 0;
}

Measured memory_bytes: 34236
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:57:32 2019

@author: Yamazaki Kenichi
"""
import sys

N = int(input())
A = list(map(int,input().split()))

def eg(x,y):
    if y == 0:
        return x
    x, y = y, x%y
    return eg(x,y)

if N == 2:
    print(max(A[0],A[1]))
    sys.exit()

tmp1 = eg(A[0],eg(A[1],A[2]))
tmp2 = max(eg(A[0],A[1]),eg(A[1],A[2]),eg(A[0],A[2]))

T = [[1,1,1] for i in range(N)]
T[1][0],T[1][1],T[1][2] = tmp1, tmp2, tmp2
for i in range(2,N):
    T[i][0] = eg(T[i-1][0],A[i])
    T[i][1] = T[i-1][0]
    T[i][2] = max(eg(T[i-1][2],A[i]),eg(T[i-1][1],A[i]))
print(max(T[N-1]))



Measured memory_bytes: 17260
h, w, k=map(int, input().split())
table=list(input() for i in range(h))

ans=0
cnt=0

for i in range(2**h):
    for j in range(2**w):
        for s in range(h):
            for t in range(w):
                if table[s][t]=="#" and (i>>s)&1 and (j>>t)&1:
                    cnt+=1
        
        if cnt==k:
            ans+=1

        cnt=0
print(ans)

Measured memory_bytes: 73692
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll m; cin >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}

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

#define ORZ_lqs2015
#define ORZ_EVERYBODY

#define fi first
#define se second
typedef long long ll;
const size_t MAX_N = (size_t)1e5 + 5;

vector<pair<int, ll> > g[MAX_N];
ll dis[MAX_N];
int lca[20][MAX_N], n, k, dep[MAX_N];

void dfs(int v, int p, int depth, ll d) {
    dep[v] = depth;
    lca[0][v] = p;
    dis[v] = d;
    for (auto x: g[v])
        if (x.fi != p) dfs(x.fi, v, depth + 1, d + x.se);
}

int up(int x, int height) {
    for (int i = 20; i >= 0; i--)
        if (height >> i & 1) x = lca[i][x];
    return x;
}

int getLca(int x, int y) {
    if (dep[x] < dep[y]) swap(x, y);
    x = up(x, dep[x] - dep[y]);
    if (x == y) return x;
    int l = 1, r = n, mid, res = -1;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (up(x, mid) == up(y, mid)) {
            r = mid - 1;
            res = mid;
        } else {
            l = mid + 1;
        }
    }
    return up(x, res);
}

ll getDis(int x, int y) {
    assert(dep[x] >= dep[y]);
    return dis[x] - dis[y];
}

int main() {
    scanf("%d", &n);
    for (int i = 1, a, b, c; i < n; i++) {
        scanf("%d%d%d", &a, &b, &c);
        g[a].emplace_back(b, (ll)c);
        g[b].emplace_back(a, (ll)c);
    }
    dfs(1, 0, 0, 0LL);
    for (int i = 1; i < 20; i++)
        for (int j = 1; j <= n; j++)
            lca[i][j] = lca[i - 1][lca[i - 1][j]];
    int q;
    scanf("%d%d", &q, &k);
    unordered_map<int, int> l;
    l.reserve(512);
    l.max_load_factor(0.25f);
    ios::sync_with_stdio(false);
    for (int i = 0, x, y; i < q; i++) {
        scanf("%d%d", &x, &y);
        if (!l.count(x)) l[x] = getLca(x, k);
        if (!l.count(y)) l[y] = getLca(y, k);
        cout << getDis(x, l[x]) + getDis(k, l[x]) + getDis(k, l[y]) + getDis(y, l[y]) << '\n';
    }
}

Measured memory_bytes: 29228
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
C = Counter(a)
k = sorted(list(C.keys()))[::-1]
ans = []
for c in k:
    if C[c]>3:
        ans.append(c)
        ans.append(c)
    elif C[c]>1:
        ans.append(c)
if len(ans)<2:
    print(0)
else:
    print(ans[0]*ans[1])


Measured memory_bytes: 18316
n=int(input())
a=list(map(int,input().split()))
am=max(a)
num=[0]*(am+1)
for i in a:
  num[i]+=1
#print(num)
mx=0
for i in range(1,am):
  #print(num[i-1:i+2])
  m=sum(num[i-1:i+2])
  if m>mx:
    mx=m
if len(num)<=3:
  mx=sum(num)
print(mx)

Measured memory_bytes: 84292
from itertools import accumulate


def LI():
    return list(map(int, input().split()))


Q = int(input())
n = 10**5
sosu = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    sosu.difference_update(range(i*2, n+1, i))
xlist = [0]*(10**5+1)
for i in range(1, 10**5+1, 2):
    if i in sosu:
        if (i+1)//2 in sosu:
            xlist[i] = 1
Xsum = list(accumulate(xlist))
for _ in range(Q):
    L, R = LI()
    ans = Xsum[R]-Xsum[L-1]
    print(ans)

Measured memory_bytes: 20640
N, M = map(int, input().split())
S = []
C = 0
cost = 0
for i in range(N):
  a, b = map(int, input().split()) 
  S.append((a, b))
S.sort()
for i in range(N):
  if S[i][1] + C < M:
    C += S[i][1]
    cost += S[i][0] * S[i][1]
  else:
    cost += (M-C) * S[i][0]
    break
print(cost)

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

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

    long long int ans = 0;
    for(int i=1; i<=n; i++){
        ans += i * (n-i+1);
    }
    for(int i=0; i<n-1; i++){
        int u, v;
        cin >> u >> v;

        if(u > v) swap(u,v);
        ans -= u * (n-v+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i,n-1){
    ans += p[i];
  }
  ans += p[n-1] / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[105][100005],n,m,val[105];
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&val[i]);
	for(int j=m;j>-1;j--)
	{
		if(j>=m-val[1])dp[1][j]=1;
		else dp[1][j]=0;
	}
	for(int i=2;i<=n;i++)
	{
		long long k=0;
		for(int j=m;j>-1;j--)
		{
			if(j<m-val[i])k-=dp[i-1][j+val[i]+1];
			k+=dp[i-1][j];
			k+=1000000007;
			k%=1000000007;
			dp[i][j]=k;
		}
	}
	printf("%d",dp[n][0]);
}

Measured memory_bytes: 40832
import java.util.*;

class Main{
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
int a,b;
for(;;){
a =sc.nextInt();
String op =sc.next();
b =sc.nextInt();
if("+".equals(op)) System.out.println(a+b);
else if("-".equals(op)) System.out.println(a-b);
else if("*".equals(op)) System.out.println(a*b);
else if("/".equals(op)) System.out.println(a/b);
else break;
}
}
}

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

#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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

    return ans;
}


void bruce()
{
    cout << "\nExpected answer:\n";
    cout << "\nAnswer recieved:\n";
}


void task()
{
    //code here...
    
    int n;
    
    cin >> n;
    
    int ans = (int)1000-(n%1000);
    if(ans==1000) cout << '0' << "\n";
    else cout << ans << "\n";
}


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

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

    task();

    return 0;
}




Measured memory_bytes: 3648
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]

data.append(0)
tmp=0
ans=0
for i in data:
    if i < tmp:
        ans+=(tmp-i)
        tmp=i
    else:
        tmp=i
print(ans)

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

int main()
{
	int N, M, L, R;

	cin >> N >> M;

	cin >> L >> R;
	int min, max;

	min = L;
	max = R;

	for (int i = 1; i < M; i++) {
		cin >> L >> R;



		if (min < L) {
			min = L;
		}
		if (max > R) {
			max = R;
		}
	}

	if (max < min) {
		cout << 0 << endl;
		return 0;
	}

	cout << max - min + 1 << endl;

	return 0;
}

Measured memory_bytes: 384