akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, 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;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int e = a + b;
	int f = c + d;
	if (e == f)cout << "Balanced" << endl;
	else if (e < f)cout << "Right" << endl;
	else cout << "Left" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n,nowt=0,nowx=0,nowy=0;cin>>n;
    REP(i,n)
    {
        int x,y,t;cin>>t>>x>>y;
        int tt=abs(x+y-nowx-nowy);
        if((t-nowt)<tt){cout<<"No"<<endl;return 0;}
        if((t-nowt)%2!=tt%2){cout<<"No"<<endl;return 0;}
        nowt+=tt;nowx=x;nowy=y;
    }
    cout<<"Yes"<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,c; cin>>n>>k>>c;
    string s; cin>>s;
    vi dp(n+1), dp2(n+1);
    int now=0;
    rep(i,n){
        dp[i+1]=dp[i];
        if (s[i]=='o' && i>=now){
            dp[i+1]++;
            now=i+c+1;
        }
    }
    now=0;
    rep(i,n){
        dp2[n-1-i]=dp2[n-i];
        if (s[n-1-i]=='o' && i>=now){
            dp2[n-1-i]++;
            now=i+c+1;
        }
    }
    rep(i,n)if(s[i]=='o'){
        if (dp[i]+dp2[i+1]<k){
            cout<<i+1<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3348
while true
    a, l = gets.chomp.split.map(&:to_i)
    break if [a, l] == [0, 0]

    arr = [a]
    i = 1
    while true
        temp = sprintf("%0#{l}d", a)
        temp_min = temp.to_s.split("").sort
        temp_max = temp_min.reverse
        a = temp_max.join.to_i - temp_min.join.to_i
        j = arr.index(a)
        if j
            puts "#{j} #{a} #{i - j}"
            break
        end
        arr << a
        i += 1
    end
end


Measured memory_bytes: 7320
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int a, b, c, numOfDiv = 0;
    cin >> a >> b >> c;

    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            numOfDiv++;
        }
    }
    cout << numOfDiv << endl;

    return 0;
}


Measured memory_bytes: 3116
a, b = map(int, input().split())
c = list(map(int, input().split()))
c = sorted(c)
count = 0
for i in range(a):
    b = b - c[i]
    if i == a - 1:
        if (b == 0):
            count += 1
    else:
        if (b >= 0):
            count += 1
        else:
            break
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define DICE 6
int dice[DICE];

void N_move(){
    int temp;
    temp = dice[0]; dice[0] = dice[1]; dice[1] = dice[5]; dice[5] = dice[4]; dice[4] = temp;
}
void E_move(){
    int temp;
    temp = dice[0]; dice[0] = dice[3]; dice[3] = dice[5]; dice[5] = dice[2]; dice[2] = temp;
}
void S_move(){
    int temp;
    temp = dice[0]; dice[0] = dice[4]; dice[4] = dice[5]; dice[5] = dice[1]; dice[1] = temp;
}
void W_move(){
    int temp;
    temp = dice[0]; dice[0] = dice[2]; dice[2] = dice[5]; dice[5] = dice[3]; dice[3] = temp;
}
int main(void){
    for(int i=0; i<6; i++){
        cin >> dice[i];
    }
    string S; cin >> S;
    for(int i=0; i<S.size(); i++){
        if(S[i] == 'N') N_move();
        if(S[i] == 'E') E_move();
        if(S[i] == 'S') S_move();
        if(S[i] == 'W') W_move();
    }
    cout << dice[0] << endl;
            
    return 0;
}
    

Measured memory_bytes: 3200
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def rotate_right(self):
        tmp = self.ns
        tmp.reverse()
        self.ns = self.we
        self.we = tmp

    def fit_top_s(self, top, s):
        while self.get_top() != top:
            if top in self.ns:
                self.n()
            elif top in self.we:
                self.w()
            else:
                self.n()
                self.n()
        while self.get_s() != s:
            self.rotate_right()

    def get_top(self):
        return self.ns[1]

    def get_s(self):
        return self.ns[2]

    def get_e(self):
        return self.we[2]


def resolve():
    nums = [int(i) for i in input().split()]
    dc1 = Dice(nums)
    nums = [int(i) for i in input().split()]
    dc2 = Dice(nums)
    dc2.fit_top_s(dc1.get_top(), dc1.get_s())
    if dc1.get_e() == dc2.get_e():
        print("Yes")
    else:
        print("No")


resolve()



Measured memory_bytes: 6028
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;


int main(){
  int h,w; cin>>h>>w;
 // Matrix bo(h,vector<int>(w,0));
  queue<pair<int,int>> que;
  Matrix dist(h,vector<int>(w));

  REP(i,h)REP(j,w){
    char a; cin>>a;
    if(a=='#'){
      que.push({i,j});
      dist[i][j]=0;
    }else dist[i][j]=-1;
  } 
 

  while(!que.empty()){
    pair<int,int> v=que.front();
    que.pop();

    int y=v.first,x=v.second;

     if(y>0&&dist[y-1][x]==-1){
     dist[y-1][x]=dist[y][x]+1;
     que.push({y-1,x});
   }
   if(y<h-1&&dist[y+1][x]==-1){
     dist[y+1][x]=dist[y][x]+1;
     que.push({y+1,x});
   }
   if(x>0&&dist[y][x-1]==-1){
     dist[y][x-1]=dist[y][x]+1;
     que.push({y,x-1});
   }
   if(x<w-1&&dist[y][x+1]==-1){
     dist[y][x+1]=dist[y][x]+1;
     que.push({y,x+1});
   }
  }
  
  int max_dist=0;
  REP(i,h)REP(j,w)if(max_dist<dist[i][j])max_dist=dist[i][j];
  cout<<max_dist<<endl;

}

Measured memory_bytes: 12432
def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a % b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m + x % m) % m


def mod_comb(n, k, mod):
    mul, div = 1, 1
    for i in range(k):
        mul *= (n-i)
        div *= (i+1)
        mul %= mod
        div %= mod
    return mul * mod_inverse(div, mod) % mod


X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print(0)
    exit(0)

al = (X + Y) // 3
ch = (2 * Y - X) // 3
if ch < 0 or al - ch < 0:
    print(0)
    exit(0)
print(mod_comb(al, ch, int(1e9+7)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    map<int, int> mp;
    REP(i, n)
    {
        cin >> d[i];
        mp[d[i]]++;
    }
    if( mp[0] >=1){
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        if(mp[d[i]] >=3 ){
            cout << 0 << endl;
            return 0;
        }
    }
    if(mp[12]>=2){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << 11); bit++)
    {
        vector<int> v;
        v.push_back(0);
        if(mp[12] >0){
            v.push_back(12);
        }
        for (int i = 0; i < 11; i++)
        {
            if(mp[i+1] == 2){
                v.push_back(i + 1);
                v.push_back(-(i + 1));
                continue;
            }
            if(1<<i & bit){
                   if(mp[i+1] >0) v.push_back(i+1);
            }
            else{
                    if(mp[i+1]>0)v.push_back(-(i + 1));    
            }
        }
      //  show(v);
        int tmp = 12;
        for (int i = 0; i < v.size(); i++)
        {
            for (int j = i+1; j < v.size(); j++)
            {
                chmin(tmp, min(24 - abs(v[i] - v[j]),abs(v[i] - v[j])));
            }
        }
        //cerr << tmp << endl;
        chmax(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef unsigned long long parallel_type;
const int bit_width=8*sizeof(parallel_type);

int main(){
	int H,W;
	for(;~scanf("%d%d",&H,&W)&&H&&W;){
		vector<string>m(H);
		for(int h=0;h<H;h++)cin>>m[h];
		if(H<=21){
			vector<vector<parallel_type> >l(H);
			int parallel_width=(W+bit_width-1)/bit_width;
			for(int h=0;h<H;h++){
				l[h].resize(parallel_width);
				for(int w=0;w<W;w++)l[h][w/bit_width]|=parallel_type(m[h][w]=='1')<<(w%bit_width);
			}
			int R=0;
			for(int i=0;i<1<<H;i++){
				vector<parallel_type> v(parallel_width);
				int r=0;
				for(int j=0;j<H;j++)if(i>>j&1){
					r++;
					for(int k=0;k<parallel_width;k++)v[k]^=l[j][k];
				}
				if(none_of(v.begin(),v.end(),[](parallel_type e){return e;}))R=max(R,r);
			}
			cout<<R<<endl;
		}else{
			vector<int>b(H);
			for(int h=0;h<H;h++){
				for(int w=0;w<W;w++)b[h]=(b[h]<<1)|(m[h][w]=='1');
			}
			vector<short>s(1<<W),t(1<<W);
			for(int w=1;w<1<<W;w++)s[w]=-1;
			for(int h=0;h<H;h++){
				for(int w=0;w<1<<W;w++){
					t[w]=max(s[w],short(s[w^b[h]]>=0 ? 1+s[w^b[h]] : -1));
				}
				swap(s,t);
			}
			cout<<s[0]<<endl;
		}
	}
}

Measured memory_bytes: 19464
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, m;
            {
                var i = (from s in Console.ReadLine().Split(' ')
                               select int.Parse(s)).ToList();
                n = i[0];
                m = i[1];
            }
            List<Tuple<long, long>> ab = new List<Tuple<long, long>>();
            for (int i = 0; i < n; i++)
            {
                long a, b;
                var k = (from s in Console.ReadLine().Split(' ')
                         select int.Parse(s)).ToList();
                a = k[0];
                b = k[1];
                ab.Add(new Tuple<long, long>(a, b));
            }
            ab = ab.OrderBy(t => t.Item1).ToList();
            long res = 0;
            long cur = 0;
            for (int i = 0; i < n; i++)
            {
                long w = Math.Min(m - cur, ab[i].Item2);
                cur += w;
                res += w * ab[i].Item1;
                if (cur == m)
                {
                    break;
                }
            }
            Console.WriteLine("{0}", res);
        }
    }
}


Measured memory_bytes: 28340
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
#define ll long long

int main(){
    std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
    int n;
    double ans;
    cin>>n;
    ans=n*2*3.14159265359;
    cout<<ans<<endl;
}

Measured memory_bytes: 3792
//noob
#include<bits/stdc++.h>
using namespace std;
#define fori(x) for(int i=0;i<x;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
#define all(x) (x).begin(),(x).end()
typedef vector<int> vi;
typedef pair<int,int> PI;
const int MOD = (int)1e9 + 7;

void solve()
{	
   int n;cin>>n;
   ll a[200000];
   fori(n) cin>>a[i];
   vector<ll>sum;
   ll temp=0;
   for(int i=0;i<n;i++){
   	temp+=a[i];
   	sum.pb(temp%MOD);
   }
   ll ans=0;
   for(int i=1;i<n;i++){
   	int x=i-1;
   	ans+=(a[i]*sum[x])%MOD;
   }
   cout<<ans%MOD<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	
solve();
	return 0;
}

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

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

ans = 0
new_a = A.copy()
while 1:
    new_a = [a // 2 if a % 2 == 0 else -1 for a in new_a]
    if -1 in new_a:
        print(ans)
        exit()
    ans += 1

print(ans)


Measured memory_bytes: 2940
using System;

namespace ConsoleApp7
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Console.ReadLine().Split(' ');
            int a = int.Parse(A[0]);
            int b = int.Parse(A[1]);
            double c = a;
            double d = b;
            Console.Write("{0} {1} ",a/b,a%b);
            Console.WriteLine((c/d).ToString("0.00000000"));
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 9336
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_1.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    # tokens = iterate_tokens()
    # N = int(next(tokens))  # type: int
    # K = int(next(tokens))  # type: int
    # S = list(next(tokens))  # type: str
    A, B = mi()

    # write code
    if A >= 13:
        print(B)
    elif 6 <= A <= 12:
        print(B // 2)
    else:
        print(0)


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

int main() {
  int N;
  string S;
  cin >> N >> S;

  vector<int> cnt_B(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cnt_B[i + 1] = cnt_B[i];
    if (S[i] == '#') cnt_B[i + 1]++;
  }

  int ans = N, cnt = 0;
  for (int i = 0; i < N + 1; i++) {
    int left_B = cnt_B[i];
    int right_W = (N - i) - (cnt_B[N] - cnt_B[i]);
    ans = min(ans, left_B + right_W);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include <string>

using namespace std;

int
main()
{
  long int a;
  string b;
  cin >> a >> b;
  
  int pos = b.find('.');
  if ( pos == -1 ) pos = b.size();
  long int b_upper = 0, b_lower = 0;
  for ( int i = 0 ; i < pos ; ++i ) {
    b_upper *= 10;
    b_upper += b[i] - '0';
  }
  for ( int i = pos + 1 ; i < b.size() ; ++i ) {
    b_lower *= 10;
    b_lower += b[i] - '0';
  }
  
  long int ans = a * b_upper + a * b_lower / 100;
  cout << ans << endl;
}

Measured memory_bytes: 3616
//Twitter@KonoLv1 2020年春卒で現在就職活動中！
 
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
 
int main(void){
    int i,j;            //  ループ文に使用
    int x,y,z;
    int count1,count2,count;   //  カウント用に使用
    int box[256] = {};
    int box2[256] = {};
    int box3[256] = {};
    char s[200001] = {};        //  文字列
    char s2[200001] = {};        //  文字列
    int a,b,c,n,save;
    a = b = c = i = 0;
    save = -999;
    int mode = 0;
    count = count1 = count2 = 0;
 
    //  入力処理
    
    scanf("%d",&n);
    for (i = 0; i < n; i++){
        scanf("%d",&box[i]);
    }
    for (i = 0; i < n; i++){
        scanf("%d",&box2[i]);
    }
    for (i = 0; i < n - 1; i++){
        scanf("%d",&box3[i]);
    }
 
    //  計算処理
    
    for (i = 0; i < n; i++){
        j = box[i];
        count = count + box2[j - 1];
        if (save + 1 == j){
            count = count + box3[save - 1];
        }
        save = j;
    }
  
    //  出力処理
 
 
    printf("%d",count);

 
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

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

  cout << N*(N-1)/2 + M*(M-1)/2 << endl;  

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>

using namespace std;

int main(void)
{
	int n, k;
	cin >> n >> k;
	int d[k];
	for (int i = 0; i < k; i++) {
		cin >> d[i];
	}
	int i;
	for (i = n; ; i++) {
		string s = to_string(i);

		bool found = false;
		for (int j = 0; j < k; j++) {
			if (s.find(to_string(d[j])) != string::npos)
				found = true;
		}
		if (!found)
			break;

	}
	cout << i << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rint register int
using namespace std;
inline int read(){
	int s=0,f=1; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=0;c=getchar();}
	while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return f?s:-s;
}
const int Mod=1e9+7;
char s[300010];
int n,f[300010][3][3],ans;
int main(){
	scanf("%s",s+1); n=strlen(s+1);
	f[0][0][0]=1;
	for(rint i=0;i<n;++i)
		for(rint j=0;j<=2;++j)
			for(rint k=0;k<=2;++k){
				if(s[i+1]!='0'){
					if(k) f[i+1][j][k-1]=1ll*(f[i+1][j][k-1]+f[i][j][k])%Mod;
					else f[i+1][min(j+1,2)][k]=1ll*(f[i+1][min(j+1,2)][k]+f[i][j][k])%Mod;
				}
				if(s[i+1]!='1'){
					if(k==2) f[i+1][j][1]=1ll*(f[i+1][j][1]+f[i][j][k])%Mod;
					else f[i+1][j][k+1]=1ll*(f[i+1][j][k+1]+f[i][j][k])%Mod;
				}
			}
	for(rint i=0;i<=2;++i)
		for(rint j=0;j<=i;++j) ans=1ll*(ans+f[n][i][j])%Mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 14668
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	long A,B,C,K;cin>>A>>B>>C>>K;
	if(K <= A){
		cout<<K<<endl;
	}else if(K <= A + B){
		cout<<A<<endl;
	}else{
		cout<<A - (K - A - B)<<endl;
	}
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
# abc142/abc142_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = [None] * N
    for i, v in enumerate(i2nn()):
        A[i] = (i, v)
    A2 = sorted(A, key= lambda x:x[1])
    print(*[a[0]+1 for a in A2])
    return

main()


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)

const string YES = "Yes";
const string NO = "No";

int main(){
    ll n;
    cin >> n;
    while(n > 0){
        if(n % 10 == 7){
            cout << YES << endl;
            return 0;
        }
        n /= 10;
    }
    cout << NO << endl;
    return 0;
}


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


int main()
{
  
  int n;
  
  cin >> n;
  
  
  for(int i=1; i<=9; i++)
  {
    for(int j=1; j<=9; j++)
    {
      if((i*j)==n)
      {
        cout << "Yes" << endl;
     
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 1e5 + 123;
const int PLS = 3e5 + 123;
const int mod = 1e9 + 7;
const ll inf = 1e16;


ll n, a[N], b[N], w, dp[110][N];


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i];
    dp[0][0] = 0;
    for (int i = 1; i <= 100000; i++)
        dp[0][i] = inf;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= 100000; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= b[i])
                dp[i][j] = min(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
        }
    for (int i = 100000; i >= 0; i--)
        if (dp[n][i] <= w)
            return cout << i, 0;
}

Measured memory_bytes: 80256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
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; }
static const lint MOD = (lint)1e9+7;

lint Sum(lint n)
{
    return (n*(n-1)) / 2;
}

int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    rep (i, N)
    {
        cin >> s[i]; 
        sort(ALL(s[i]));
    }

    map<string, lint> cnt;
    rep (i, N)
    {
        cnt[s[i]] = 0;
    }
    rep (i, N)
    {
        cnt.at(s[i])++;
    }

    lint ans = 0;
    for (auto it = cnt.begin(); it != cnt.end(); ++it)
    {
        ans += Sum(it->second);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18176
const Main = (input) => {
	var xs = input.trim().split(' ').map(v=>parseInt(v,10));
    var piece = xs[0] * 3;
    var pie = Math.floor((piece + xs[1]) / 2);
    console.log(pie);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21956
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

template <typename T>
inline auto enumerate_divisors (T n)
{
  set <T> res;
  for (T i = 1; i * i <= n; ++ i)
  {
    if (n % i == 0)
    {
      res.insert (i);
      res.insert (n / i);
    }
  }
  return res;
}

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

  ll n;
  cin >> n;
  auto divisors = enumerate_divisors (n);
  auto ans = inf;
  for (auto && elem : divisors)
  {
    auto a = elem;
    auto b = n / elem;
    auto t = a - 1 + b - 1;
    ans = min (ans, t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    ll n,maxv=0;
    ll MOD2=998244353;
    in(n);
    vector<ll> vec(n),tree(n,0);
    ll ans=0;
    rep(i,n){
        in(vec[i]);
        if(i==0&&vec[i]!=0){
            goto skip;
        }else if(i!=0&&vec[i]==0){
            goto skip;
        }
        maxv=max(maxv,vec[i]);
        tree[vec[i]]++;
    }
    ans=1;
    //debug(tree);
    for(int i=1;i<=maxv;i++){
        //debug(ans);
        ans*=modpow(tree[i-1],tree[i],MOD2);
        ans%=MOD2;
    }
    skip:
    out(ans);
}



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

int main(){
    int n, t;
    pair<int, int> menu[3000];
    cin >> n >> t;
    for(int i=0;i<n;++i){
        int a, b;
        cin >> a >> b;
        menu[i] = {a, b};
    }
    sort(menu, menu+n);

    static int64_t dp[3001][3001];
    for(int i=1;i<t;++i){
        for(int j=1;j<=n;++j){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(i >= menu[j-1].first) dp[i][j] = max(dp[i][j], dp[i-menu[j-1].first][j-1] + menu[j-1].second);
        }
    }

    for(int j=1;j<=n;++j){
        dp[t][j] = max(dp[t-1][j], dp[t][j-1]);
        dp[t][j] = max(dp[t][j], dp[t-1][j-1] + menu[j-1].second);
    }
    cout << dp[t][n] << endl;

    return 0;
}

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

int main() {
  int n;cin>>n;
  set<int> st;
  rep(i,n){
    int a;cin>>a;
    st.insert(a);
  }
  if(st.size()==n)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    ll n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];
    ll min_abs = INF;
    ll cnt_minus = 0;
    rep(i, n) {
        if (abs(a[i]) < min_abs) min_abs = abs(a[i]);
        if (a[i] < 0) cnt_minus++;
    }
    ll ans = 0;
    rep(i, n) {
        ans += abs(a[i]);
    }
    if (cnt_minus % 2 == 1) {
        ans -= min_abs * 2;
    }

    out(ans);
    return 0;
}


Measured memory_bytes: 1024
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val (d, x) = intList()
    val f = 0.until(n).sumBy {
        val a = readLine()?.toInt() ?: return
        d / a + if (d % a == 0) {
            0
        } else {
            1
        }
    } + x
    println(f.toString())
}

Measured memory_bytes: 36008
# -*- coding: utf-8 -*-
coin_day, coin_week, goal = map(int, input().split())
total_coin_per_week = coin_week + (7 * coin_day)
res_week, rest_coin = divmod(goal, total_coin_per_week)

res_day, residual = divmod(rest_coin, coin_day)
if residual >= 1:
    res_day += 1
if res_day >= 7:
    res_day = 7

print(res_week * 7 + res_day)



Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
string str[1009];
int dp[1009][1009];
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
		int n,m,i,j,k,l;
		cin>>n>>m;
		memset(dp,0,sizeof(dp));
		rep(i,0,n)
		cin>>str[i];
		if(str[0][0]=='#'||str[n-1][m-1]=='#')
			cout<<"0";
		else{
			dp[0][0]=1;
			int f=0;
			for(i=1;i<m;i++){
				if(str[0][i]!='#'&&f==0)
					dp[0][i]=dp[0][i-1];
				else if(str[0][i]=='#')
					f=1;
			}
			f=0;
			for(i=1;i<n;i++){
				if(str[i][0]!='#'&&f==0)
					dp[i][0]=dp[i-1][0];
				else if(str[0][i]=='#')
					f=1;
			}
			for(i=1;i<n;i++){
				for(j=1;j<m;j++)
					if(str[i][j]!='#')
						dp[i][j]=(dp[i][j]%mod+dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
			}
			cout<<dp[n-1][m-1];
		}


}

Measured memory_bytes: 9216
#include<iostream>  
#include<vector>
using namespace std; 
int main() {
	int a,b,c;  
	cin >> a >> b >> c;
	int ans = 0; 
	if (a==c&&c==b)
	{
		ans = 1;
	} 
	else if (a==b&&b!=c)
	{
		ans =2;
	} 
	else if(a!=b&&b==c)
	{
		ans = 2; 
	} 
	else if (a==c&&c!=b)
	{
		ans = 2;
	}
	else 
	{
		ans = 3;
	} 
	cout << ans << "\n";
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (n < 26) {
        set<char> ss;
        rep(i, 26) ss.insert('a' + i);
        for (char c : s) ss.erase(c);

        string t = s + char(*ss.begin());
        cout << t << endl;
        ret();
    }

    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        ret();
    }

    vector<int> v(26);
    rep(i, n) v[i] = s[i] - 'a';

    next_permutation(v.begin(), v.end());

    int q = [&] {
        rep(i, n) if (s[i] - 'a' != v[i]) return i;
        __throw_runtime_error("konaide");
    }();

//    cout << char(v[q] + 'a') << endl;

    rep(i, q + 1) cout << char(v[i] + 'a');


    cout << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int n, m;
vector<short> point[3];
ld p[2222], win[2222][2222];
ld dp[2222][2222][4], exper[3][2222];
ld score[] = { 5,3,2 };

ld calc(int m, int i)
{
	ld res = 1.0;
	int a = m - i;
	REP(j, i)
	{
		res *= ld(m - j);
		res /= ld(j + 1);
		res /= 3.0;
		if (a > 0)
		{
			res *= 2.0 / 3.0;
			a--;
		}
	}
	while (a > 0)
	{
		res *= 2.0 / 3.0;
		a--;
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> n >> m;
	REP(i, 3) point[i].resize(n);
	REP(i, m + 1)
	{
		p[i] = calc(m, i);
	}
	for (int i = m - 1; i >= 0; i--) p[i] += p[i + 1];
	REP(i, n)REP(j, 3) cin >> point[j][i];
	REP(i, 3)
	{
		REP(j, m + 1)FOR(k, 1, n)
		{
			int need;
			int my = j * point[i][0];
			if (my % point[i][k] == 0) need = my / point[i][k];
			else need = my / point[i][k] + 1;
			win[j][k] = 1 - p[min(need, m + 1)];
		}
		REP(j, 2222)REP(k, 2222)REP(l, 4) dp[j][k][l] = 0.0;
		REP(j, 2222) dp[j][0][0] = dp[j][0][3] = 1.0;
		REP(j, m + 1)
		{
			FOR(k, 1, n)
			{
				REP(l, 3)
				{
					dp[j][k][l] += dp[j][k - 1][l] * win[j][k];
					if (l != 2) dp[j][k][l + 1] += dp[j][k - 1][l] * (1 - win[j][k]);
					if (dp[j][k][l] < EPS) dp[j][k][l] = 0;
				}
				dp[j][k][3] = dp[j][k - 1][3] * (1 - win[j][k]);
				if (dp[j][k][3] < EPS) dp[j][k][3] = 0;
			}
		}
		REP(j, m + 1) exper[i][j] = (dp[j][n - 1][0] + dp[j][n - 1][1] + dp[j][n - 1][2])*score[i] - dp[j][n - 1][3];
	}
	ld ans = -INF;
	REP(i, m + 1)REP(j, m + 1)
	{
		int k = m - i - j;
		if (k < 0) continue;
		ld tmp = exper[0][i] + exper[1][j] + exper[2][k];
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 192372
#include <stdio.h>


int main(void) {
  int a,b;
  scanf("%d %d",&a,&b);
  if (a > b) {
    printf("a > b\n");
  } else if (a < b) {
    printf("a < b\n");
  } else {
    printf("a == b\n");
  }
  return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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;}

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    ll sum = 0;
    map<ll, ll> mp;
    vector<ll> lis(n), blis(n),  clis(n);
    REP(i, 0, n){cin >> lis[i]; mp[lis[i]]++; sum += lis[i];}
    int q; cin >> q;
    REP(i, 0, q){
        ll b, c; cin >> b >> c;
        ll k = mp[b];
        mp[b] = 0;
        sum -= k * b;
        sum += k * c;
        mp[c] += k;
        cout << sum << endl;
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    vector<ll> p(N);
    rep (i, N-1) {
        if (i%2) {
            p[i]--;
            p[i+1]++;
        } else {
            p[i]++;
            p[i+1]--;
        }
    }

    sort(p.begin(), p.end());

    ll sum1 = 0;
    ll sum2 = 0;

    rep (i, N) {
        sum1 += p[i]*A[i];
        sum2 -= p[i]*A[N-(i+1)];
    }

    cout << max(sum1, sum2) << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

string S;
size_t cur;
int parse();

int digit(){
    assert(isdigit(S[cur]));
    int n=S[cur]-'0';
    cur++;
    return n;
}

int number(){
    int n=digit();
    while(cur<S.size()&&isdigit(S[cur]))
	n=n*10+digit();
    return n;
}

int expression();
int factor(){
	if(S[cur]!='(')return number();
	cur++;
	int n=expression();
	assert(S[cur]==')');
	cur++;
	return n;
} 

int term1(){
    int a=factor();
    while(cur<S.size()&&S[cur]=='^'){
	cur++;
	int b=factor();
	a=pow(a,b);
    }
    return a;
}

int term2(){
    int a=term1();
    while(cur<S.size()&&(S[cur]=='*'||S[cur]=='/')){
		char op=S[cur++];
		int b=term1();
		if(op=='*')a*=b; else a/=b;
    }
    return a;
}

int expression(){
    int a=term2();
    while(cur<S.size()&&(S[cur]=='+'||S[cur]=='-')){
	char op=S[cur++];
	int b=term2();
	if(op=='+')a+=b; else a-=b;
    }
    return a;
}

int main() {
    int n;
    cin>>n;
    while(cin>>S){
	cur=0;
	cout<<expression()<<endl;
    }
} 

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

 
#include <vector>
#include <utility>


#include <algorithm>


char s[110000];

void solve() {
	scanf("%s", s);
	int n = strlen(s);

	int ct = 0;
	for (int i = 0; i < n; i++) {
		if (s[i]=='g') ct++;
		else ct--;
	}

	printf("%d\n", ct/2);
}


int main() {
    solve();
}




Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 1000000000;
const double EPS = 1e-10;

int main(){
//	freopen("test.txt", "r", stdin);
	int casenum = 0;
	while(1){
		int W, n;
		cin >> W >> n;
		if(!W) break;

		vector<int> w(n+1);
		vector<int> v(n+1);
		FOR(i, 1, n+1){
			scanf("%d,%d", &v[i], &w[i]);
		}

		vector<vector<int> > table(n+1, vector<int>(W+1));

		FOR(i, 1, n+1){
			for(int j = 0; j <= W; j++){
				if(j >= w[i]){
					table[i][j] = max(table[i-1][j], table[i-1][j-w[i]]+v[i]);
				}else{
					table[i][j] = table[i-1][j];
				}
			}
		}


		int idx = 0;
		rep(i, W+1){
			if(table[n][idx] < table[n][i]){
				idx = i;
			}
		}

		cout << "Case " << ++casenum << ':' << endl;
		cout << table[n][idx] << endl;
		cout << idx << endl;
	}

	return 0;
}

Measured memory_bytes: 5072
#include <stdio.h>

int main(){

  int a,b;
  scanf("%d%d",&a,&b);
  if(a < b){
    printf("a < b\n");
  }else if(a==b){
    printf("a == b\n");
  }else{
    printf("a > b\n");
  }
  return 0;
}

Measured memory_bytes: 1008
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int X, Y;
  ci(X, Y);
  co(X + Y / 2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=2e5+2;
const int inf=(int)(1e19+10LL);
void solve()
{
 int s,w;
 sl(s);sl(w);
 if(s<=w){
 	cout<<"unsafe"<<endl;
 	return;
 }
 cout<<"safe"<<endl;
  
}

signed main(){
  int test=1;
// sl(test);
 while(test--){
 	solve();
 }
 
}

Measured memory_bytes: 3596
//
//  main.cpp
//  L
//
//  Created by LucienShui on 2017/4/20.
//  Copyright ? 2017年 LucienShui. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>

#define mfor(i,n) for(int i=0 ; i<n ; ++i)

using namespace std;

long long a[1005];

bool cmp(long long a, long long b) {
    return a>b;
}
bool panduan(long long a) {
    while(a/10) {
        long long t = a%10;
        a /= 10;
        if(a%10!=t-1) return false;
    }
    return true;
}
int main() {
    int n;
    while(~scanf("%d",&n)) {
        int cnt=0;
        long long result=-1,t;
        for(int i=0 ; i<n ; i++) {
            scanf("%lld",a+i);
            for(int j=0 ; j<i ; j++) {
                t=a[i]*a[j];
                if(panduan(t)) result = max(t,result);
            }
        }
        printf("%lld\n",result);
    }
    return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}




int main()
{
	IOS;
	int n;
	cin>>n;
  ll a[n+1];
  for(int i=1;i<=n;i++)
	a[i]=2;
	a[1]=a[0]=1;
	for(int i=2;i*i<=n;i++)
	{
			for(int j=i*i;j<=n;j+=i)
			{
				if(j==i*i)
				a[j]++;
				else
				a[j]+=2;
			}
	}
	for(int i=2;i<=n;i++)
	{
		a[i]=a[i]*i;
		a[i]+=a[i-1];
	}
	cout<<a[n]<<endl;
	
}



Measured memory_bytes: 81764