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

using namespace std;

typedef long long ll;

const int N=1e6+5,M=1e3+7,mod=1e9+7;

int dx[]={0,1,-1,0},
    dy[]={1,0,0,-1};
              
char s[N];

int a[N],n,m,k,tc,ans,d;

int main() {
    
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;s[i];i++){
        char c=s[i]+n;
        if (c>'Z')
            c-=26;
        printf("%c",c);
    }

}

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

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

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	sort(A.begin(),A.end());
	int ans=0;
	rep(i,K) ans+=A[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>


using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const set<A>& s) {
    for(auto it = s.begin(); it != s.end(); ++it) {
        output << *it << endl;
    }
    return output;
}

template<class A, class B>
ostream& operator << (ostream& output, const map<A, B>& m) {
    for(auto it = m.begin(); it != m.end(); ++it) {
        output << "[" << it->first << ", " << it->second << "]" << endl;
    }
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
    	cin >> v[i];
    }
    vector<int> temp{v};
    sort(all(v));
    int count = 0;
    for(int i = 0; i < n; ++i) {
    	if(v[i] != temp[i]) {
    		count++;
    	}
    }
    if(count <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b));
  memi;
}

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

void print(vector<int> children) {
    for(int i = 0; i < children.size(); i++) {
        if(i != 0) {
            cout << " ";
        }
        cout << children.at(i);
    }
    cout << endl;
}

int main() {
    string s;
    cin >> s;

    vector<int> children(s.size(), 0);
    int even = 0;
    int odd = 0;
    int start = -1;
    char current = ' ';
    for(int i = 0; i < s.size(); i++) {
        // cout << s.at(i) << endl;
        if(current != s.at(i)) {
            if(current != ' ') {
                if(current == 'R') {
                    if(i % 2 == 0) {
                        children.at(i) += even;
                        children.at(i - 1) += odd;
                    } else {
                        children.at(i) += odd;
                        children.at(i - 1) += even;
                    }
                } else {
                    if(start % 2 == 0) {
                        children.at(start) += even;
                        children.at(start - 1) += odd;
                    } else {
                        children.at(start) += odd;
                        children.at(start - 1) += even;
                    }
                }
            }
            current = s.at(i);
            start = i;
            even = 0;
            odd = 0;
        }
        if(i % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }

    if(start % 2 == 0) {
        children.at(start) += even;
        children.at(start - 1) += odd;
    } else {
        children.at(start) += odd;
        children.at(start - 1) += even;
    }

    print(children);

    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<double> x(N);
    vector<string> u(N);
    rep(i, 0, N) cin >> x[i] >> u[i];
    double ans = 0;
    rep(i, 0, N) {
        if (u[i][0] == 'B') {
            ans += x[i] * 380000;
        } else {
            ans += x[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    r = (n - 1) * (n - 2) // 2 - k
    if r < 0:
        return [[-1]]

    edges = [(1, v) for v in range(2, n+1)]
    m = n - 1 + r

    u = 2; v = 3
    for _ in range(r):
        edges.append((u, v))
        v += 1
        if v == n + 1:
            u += 1
            v = u + 1

    res = [[m]] + edges 
    return res
    
if __name__ == '__main__':
    ans = main()
    for a in ans:
        print(*a, sep=' ')

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>

template<std::uint_fast64_t Mod>
class ModInt{
    using u64 = uint_fast64_t;
public:
    u64 num;
    constexpr ModInt(const u64 x = 0) noexcept : num(x % Mod) {}
    constexpr u64 &value() noexcept { return num; }
    constexpr const u64 &value() const noexcept { return num; }
    constexpr ModInt operator+(const ModInt rhs) const noexcept {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt rhs) const noexcept {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt rhs) const noexcept {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt rhs) const noexcept {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        num += rhs.num;
        if (num >= Mod) {
            num -= Mod;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (num < rhs.num) {
            num += Mod;
        }
        num -= rhs.num;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        num = num * rhs.num % Mod;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Mod - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    constexpr ModInt &operator=(const u64 num) noexcept {
        this->num = num % Mod;
        return *this;
    }

    constexpr ModInt pow(u64 k){
        return pow(num, k);
    }

    static constexpr ModInt pow(ModInt x, u64 k){
        if(k == 0) return 1;
        if(k % 2 == 0) return pow((x * x).num % Mod, k / 2);
        else return (x * pow(x, k - 1)).num % Mod;
    }
};

template<std::uint_fast64_t Mod>
std::ostream &operator<<(std::ostream &out, const ModInt<Mod> &m)
{
    out << m.num;
    return out;
}

using namespace std;

int main(){
    static const int INF = 1e9 + 7;
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for(auto&& i : a){
        cin >> i;
    }
    vector<vector<ModInt<INF>>> dp(h + 1, vector<ModInt<INF>>(w + 1));
    for(int i = 1; i < h; i++){
        dp[i][0] = 0;
    }
    for(int i = 0; i < w; i++){
        dp[0][i] = 0;
    }
    dp[0][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(a[i - 1][j - 1] == '#'){
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        }
    }
    cout << dp[h][w] << "\n";
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807

signed main()
{
  int x=0,y=1,z=0,w=0,n=0,m=0;
std::cin >> x;
while(1){
  if(y*2<=x){
    y*=2;
  }else{
    std::cout << y << '\n';
    return 0;
  }
}
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
#my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())


#your code here!
def resolve():
    S=input()
    ans=0
    
    hidari=0
    for i,c in enumerate(S):
        if c=="W":
            ans+=i-hidari
            hidari+=1
    print(ans)

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """BBW"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """BWBWBW"""
        output = """6"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()


    resolve()#and submit 2 atcoder!



Measured memory_bytes: 6208
#include <iostream>
int main(){
  char a;
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%c",&a);
    if(a=='Y'){
      printf("Four\n");
      return 0;
    }
  }
  printf("Three\n");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define int long long
#define mod 1000000007
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 200005 
int d[N];
int mul[N];
int c[N];
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=n;i++) c[i]=read();
	sort(c+1,c+n+1);
	d[1]=1;
	int ad=1;
	for(int i=2;i<=n+1;i++)
	{
		d[i]=(d[i-1]*2+ad)%mod;
		ad=ad*2%mod;
	}
	mul[0]=1;
	for(int i=1;i<=n;i++)
	{
		mul[i]=mul[i-1]*2%mod;
	}
//	for(int i=1;i<=n+1;i++) printf("%lld ",d[i]);
//	cout<<"\n";
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=(ans+mul[i-1]*d[n-i+1]%mod*c[i])%mod;
	}
	cout<<ans*mul[n]%mod<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 4992
#include <iostream>
using namespace std;
#define ll long long int
int main()
{
    char ch;
    cin>>ch;
    if(ch>='A'&&ch<='Z'){
        cout<<"A";
    }
    else if(ch>='a'&&ch<='z'){
        cout<<"a";
    }
    else{
        cout<<"A";
    }
}


Measured memory_bytes: 3632
from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw, gh, gw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1 if maze[sh][sw] == "#" else 0 # スタートの値
    while stack:
        h, w = stack.popleft()
#        # ゴールの条件
#        if h == gh and w == gw:
#            break
        for j, k in ([1, 0], [0, 1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
                new_w < 0 or new_w >= W:
                    continue
            else:
              cost = 1 if maze[new_h][new_w] == "#" and maze[h][w] == "." else 0
              # visited[new]が未踏(-1)、もしくはコストが下がる  
              if visited[new_h][new_w] == -1 or visited[new_h][new_w] > visited[h][w] + cost:
                visited[new_h][new_w] = visited[h][w] + cost
                stack.append([new_h, new_w])
    
    return visited[gh][gw]

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [list(input()) for _ in range(H)]

    visited = [[-1] * W for _ in range(H)]
    print(bfs(maze, visited, 0, 0, H-1, W-1))
    


Measured memory_bytes: 3572
N = int(input())
a = [0]
for i in range(N):
    a.append(int(input()))
key = 1
count = 0
while True:
    if count > N:
        print('-1')
        break
    count += 1
    key = a[key]
    if key == 2:
        print(count)
        break


Measured memory_bytes: 7080
def LI(): return list(map(int,input().split()))
A,B,C,X,Y = LI()
ans = float('INF')
for i in range(max(X,Y)+1):
    price = A*max(X-i,0)+B*max(Y-i,0)+C*2*i
    ans = min(price,ans)
print(ans)


Measured memory_bytes: 3060
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
 
int main() {
  int n,a;
  cin >> n >> a;
  if(n%500<=a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
    string s1;
    int sum=0;

    cin >> s1;
    for (char s : s1) {
        sum += s - '0';
    }
    printf("%s\n",sum%9?"No":"Yes");
    return 0;
}

Measured memory_bytes: 3752
n,m=map(int,input().split())
ans=[10**10]*n
edge=[[]for _ in range(n)]
for _ in range(m):
	l,r,d=map(int,input().split())
	l-=1
	r-=1
	edge[l].append([r,d])
	edge[r].append([l,-d])
for i in range(n):
	if ans[i]==10**10:
		ans[i]=0
		Q=[i]
		while Q:
			P=[]
			for i in Q:
				for j,d in edge[i]:
					if ans[j]==10**10:
						P+=[j]
						ans[j]=ans[i]+d
			Q=P
for i in range(n):
	for j,k in edge[i]:
		if ans[i]+k!=ans[j]:print("No");exit()
print("Yes")

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N; cin >> N;
  vector<pair<ll, ll>> ab(N);
  REP(i, N) {
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }

  sort(all(ab));

  ll cnt = 0;
  ll max_A = ab[N - 1].first;
  ll max_B = ab[N - 1].second;
  ll min_A = ab[0].first;
  ll min_B = ab[0].second;
  // cout << max_A << " " << min_A << " " << max_B << " " << min_B << endl;
  cnt = (max_A - min_A) + 1 + max_B + (min_A - 1);
  cout << cnt << endl;
}


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

using namespace std;

int N;
vector < int > v[100009];

bool dfs (int nod, int tata)
{
    int cnt = 0;
    for (auto it : v[nod])
        if (it != tata)
            cnt += dfs (it, nod);
    if (cnt == 1) return 0;
    if (cnt > 1)
    {
        printf ("First\n");
        exit (0);
    }
    return 1;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
}
bool ok = dfs (1, -1);
if (!ok) printf ("Second\n");
else printf ("First\n");
return 0;
}


Measured memory_bytes: 5888
from collections import deque

k = int(input())
limit = 10

start = [i for i in range(1, 10)]
q = deque(start)
ans = []

while q:
    cur = q.popleft()
    if len(str(cur)) > 11:
        continue
    ans.append(cur)
    r = str(cur)[-1]
    if r == '0':
        add = ['0', '1']
    elif r == '9':
        add = ['8', '9']
    else:
        add = [str(int(r) - 1), str(int(r)), str(int(r) + 1)]

    for i in add:
        q.append(int(str(cur) + i))

ans = sorted(ans)
print(ans[k - 1])


Measured memory_bytes: 119128
//Triangle
#include<stdio.h>

int main(void) {
    
    int i,a,b,c,n;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d%d%d",&a,&b,&c);
        
        if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
        
    }
       
    return 0;
}

Measured memory_bytes: 580
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		boolean[] primes = new boolean[10000];
		NavigableSet<Integer> navigableSet = new TreeSet<Integer>();
		for (int i = 2; i < 10000; i++) {
			if (!primes[i]) {
				for (int j = i * i; j < 10000; j += i) {
					primes[j] = true;
				}
				if (!primes[i - 2]) {
					navigableSet.add(i);
				}
			}

		}
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int num = scanner.nextInt();
			if (num == 0)
				break;
			int ans = navigableSet.floor(num);
			System.out.println(ans- 2 + " " + ans);
		}
	}
}

Measured memory_bytes: 33476
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e3 + 7;
const int M = 5e3 + 7;

int x[N];
vector<int> g[N];

int dp[N];
bitset<2 * M> c;

void dfs(int cur) {
	for (auto t : g[cur]) {
		dfs(t);
	}
	int s = 0;
	c.reset();
	c[0] = 1;
	for (auto t : g[cur]) {
		c = (c << x[t]) | (c << dp[t]);
		s += x[t];
		s += dp[t];
	}
	for (int i = x[cur]; i >= 0; i--) {
		if (c[i]) {
			dp[cur] = s - i;
			return;
		}
	}
	cout << "IMPOSSIBLE\n";
	exit(0);
}

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

	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int p;
		cin >> p;
		p--;
		g[p].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	dfs(0);
	cout << "POSSIBLE\n";
}


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

int main() {
  int A;
  int B;
  int C;
  int D;
  
  cin >> A >> B >> C >> D ;
  
  if ((A+B) == (C+D)){
    cout << "Balanced" << endl;
  }
  else if((A+B) > (C+D) ){
    cout << "Left" << endl;
  }
  else if ((A+B) < (C+D) ){
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	while(scanf("%d", &n) != EOF) {
		printf("3C%02d\n", n%39==0?39:n%39);
	}
	return 0;
}

Measured memory_bytes: 1036
N, K = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(N)]
l.sort(key=lambda x: x[0])
cnt = 0
for i in range(N):
    a = l[i][0]
    b = l[i][1]
    cnt += b
    if cnt >= K:
        print(a)
        break


Measured memory_bytes: 18180
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(61):
    count0=0
    count1=0
    for j in a:
        if not (j>>i & 1):
            count0+=1
        if j>>i & 1:
            count1+=1
    ans+=((count0*count1)*(2**i))%mod
    
print(ans%mod)

Measured memory_bytes: 124216
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long a[3];
    scanf("%ld%ld%ld", &a[0], &a[1], &a[2]);
    sort(a+0, a+3);
    if(a[0]+a[1]==a[2]) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }



    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI
#define ll long long

int main(){
    int n, k;
    cin >> n >> k;
    
    if(n%k != 0){
        cout << 1 << endl;
    }
    else if(n%k == 0){
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
A, B, H, M = map(int, input().split())

deg_H = (H * 60 + M) / 2
deg_M = (6 * M) % 360

theta = abs(deg_H - deg_M)

import math

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(theta))))

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

using namespace std;

typedef long long int ll;

const ll MAXN = 505;

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

  ll n, m, q;
  cin >> n >> m >> q;
  vector < vector < ll > > dp(MAXN, vector < ll > (MAXN, 0));
  for(int i = 0; i < m; i++){
    ll l, r;
    cin >> l >> r;
    dp[l][r]++;
  }
  
  for(int i = MAXN - 1; i >= 0; i--){
    for(int j = i + 1; j < MAXN; j++){
      dp[i][j] += dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1];
    }
  }

  while(q--){
    ll l, r;
    cin >> l >> r;
    cout << dp[l][r] << '\n';
  }
}


Measured memory_bytes: 2944
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
 
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int h, w, a, b; 
    cin >> h >> w >> a >> b;
    ll ans = 0;
    
    COMinit();
    for (int i = 0; i < w - b; i++) {
        ll x = COM(b + i + h - a - 1,min(b + i,h - a - 1)) % MOD;
        ll y = COM(a - 1 + w - b - i - 1,min(a - 1,w - b - i - 1)) % MOD;
        ans += (x * y) % MOD; //cout << ans << endl;
    }
    ans %= MOD;
    cout << ans << endl;
}


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

int main() {
    long long n;
    long long x;
    long long mn = 1000000000000001;

    cin >> n;
    for(int i = 0; i < 5; i++) {
        cin >> x;
        mn = min(mn, x);
    }

    if (n % mn == 0) {
        n = n / mn - 1;
    } else {
        n /= mn;
    }

    cout << (n + 5) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(auto& el: v) cin >> el;
    for(int i = k; i < n; ++i) {
    	if(v[i] > v[i - k]) {
    		cout << "Yes\n";
    	} else {
    		cout << "No\n";
    	}
    }
	return 0;
}


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

string A[MAX];
priority_queue<string> PQ;

int n;
string s;

int facctorialMethod(int k){
    int sm = 1;
    for (int i = 1; i <= k; ++i)
    {
        sm *= i;
    }
    return sm;
}

int main(){
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> s;
    sort(s.begin(), s.end());
    PQ.push(s);
    }
  string pr, p;
  pr=PQ.top();
  PQ.pop();
  ll ans=0;
  ll cnt=0;
  while(!PQ.empty()){
    p=PQ.top();
    PQ.pop();
    if(p==pr){
      pr=p;
      cnt++;
    } else {
      if(cnt!=0)ans+=cnt*(cnt+1)/2;
      cnt=0;
      pr=p;
    }
  }
  if(cnt!=0)ans+=cnt*(cnt+1)/2;
  cout << ans <<endl;
}


Measured memory_bytes: 5876
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

long long l = 2000001;
vector<long long> b(l, 0);

long long func(long long n)
{
	return n * (n - 1) / 2;
}

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

	vector<int> a(n);

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

	long long sum = 0;

	for (int i = 1; i < l; i++)
	{
		sum += b[i] * (b[i] - 1) / 2;
	}

	for (int i = 0; i < n; i++)
	{
		cout << sum - func(b[a[i]]) + func(b[a[i]] - 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 19612
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int maxn = 200005;
int n, m, p[maxn], add[maxn], a, b;
vector <int> v[maxn];

void dfs(int node, int pa){
    for (int i:v[node]){
        if (i != pa){
            add[i] += add[node];
            dfs(i, node);
        }
    }
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < n-1; i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        add[a] += b;
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++){
        if (i != 1) cout << " ";
        cout << add[i];
    }
    cout << "\n";
}

Measured memory_bytes: 24192
/**
* 氏名: 阿部寛之
* 学籍番号: 170441004
***/


#include<stdio.h>

int main(void)
{
	int time;
	int hour, minute, second;
	scanf("%d", &time);

	hour = time / 3600;
	minute = (time - hour * 3600) / 60;
	second = time - minute * 60 - hour * 3600;
	
	printf("%d:%d:%d\n", hour, minute, second);
	return 0;
}


Measured memory_bytes: 2080
import java.util.*;
public class Main {
	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();
		sc.close();

		int[] arr = new int[]{P + Q, Q + R, R + P};

		int min = arr[0];
		for (int i = 0; i < arr.length; i++) {
			int v = arr[i];
			if (v < min) {
				min = v;
			}
		}
		System.out.println(min);
	
	}
}

Measured memory_bytes: 22228
N = int(input())

d = {1:["a"], 2:["aa", "ab"]}
for i in range(3, N+1):
    d[i] = []
    for base in d[i-1]:
        max_c = ord(max(base)) + 1
        for j in range(ord("a"), max_c+1):
            cand = base
            cand += chr(j)
            d[i].append(cand)

for i in d[N]:
    print(i)


Measured memory_bytes: 14560
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n: u32 = read();
    let sum = n.to_string()
                .chars()
                .map(|c| (c as u8 - b'0') as u32)
                .sum::<u32>();
    if n % sum == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N, X, Y, Z;
LL dp[2][1<<18];
bool ok(int x){
  if(!(x>>X&1)) return true;
  if(!(x>>(X+Y)&1)) return true;
  if(!(x>>(X+Y+Z)&1)) return true;
  return false;
}

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

  cin >> N >> X >> Y >> Z;
  int crt = 0, nxt = 1, n = X+Y+Z;
  FOR(i,1,11)
	dp[crt][1<<i] = 1;
  REP(i,N-1){
	fill((LL*)dp[nxt], (LL*)dp[nxt]+(1<<18), 0);
	REP(b,1<<18){
	  FOR(k,1,11){
		int b_ = (b << k)&((1<<18)-1);
		b_ |= 1<<k;
		if(ok(b_))
		  (dp[nxt][b_] += dp[crt][b]) %= MOD;
	  }
	}
	swap(crt, nxt);
  }

  LL ans = 1;
  REP(i,N) (ans *= 10) %= MOD;
  REP(i,1<<18) (ans += MOD - dp[crt][i]) %= MOD;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4352
N,K=(int(i) for i in input().split())
S =input()
if S[0]=="0" :biti=0
else:biti=1
if S[-1]=="0" :bitf=0
else:bitf=1
a=[0]
for i in range(0,len(S)-1):
  if S[i]!=S[i+1]:
    a.append(i+1)
a.append(len(S))

def func():
  maxanswer=0
  for i in range(0,len(a)-2*K-1*bitf):
    if biti==0 and i==0:
      if maxanswer<a[i+K*2]-a[i]:maxanswer=a[i+K*2]-a[i]
    elif bitf==0 and i==len(a)-2*K-1:
      if maxanswer<a[i+K*2]-a[i]:maxanswer=a[i+K*2]-a[i]
    elif maxanswer<a[i+K*2+((i%2)^(biti))]-a[i+((i%2)^(not biti))]:maxanswer=a[i+K*2+((i%2)^(biti))]-a[i+((i%2)^(not biti))]
  print(maxanswer)


if biti==bitf:
  if biti==0:
    if len(a)<=(K*2-1):print(a[-1])
    else:
      func()
  else:
    if len(a)<=(K*2+1):print(a[-1])
    else:
      func()
else:
  if len(a)<=K*2:print(a[-1])
  else:
    func()





Measured memory_bytes: 7160
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define PI                      3.1415926535897932384626
#define int                     long long int
#define fi                      first
#define se                      second
#define pq                      priority_queue
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define fill(x,y)               memset(x,y,sizeof(x));
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define hash                    _H
#define lg                      long double         
#define vi                      std::vector<int>
#define sz(x)                   ((int)x.size())
 
 
 
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
template<typename T>T InverseMod(T a,int m){return pow(a,m-2,m);}
template<typename T>int SquareDist(T a,T b){int x = abs(a.fi - b.fi),y = abs(a.se - b.se); return x*x + y*y;}
 
const int N = 1e5+2;
int dp[N][100+2];
void solve() {
    int n,w;
    cin >> n >> w; 
    std::vector<pii> v;
    for(int i = 0 ; i < n; ++i) {
        pii temp;
        cin >> temp.fi >> temp.se;
        v.pb(temp);
    }
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= n; ++j) {
            dp[i][j] = 2e18;
        }
    }
    fill(dp[0],0);
    for(int i = 1; i < N; ++i) {
        for(int j = 1; j <= n; ++j) {
            if( i-v[j-1].se >= 0) {
                
                //cout << i << " " << j << " ";
                dp[i][j] = min({dp[i][j], dp[i-v[j-1].se][j-1] + v[j-1].fi});
                //cout << dp[i][j] << endl;
            }
            dp[i][j] = min(dp[i][j],dp[i][j-1]);
        }
    }
    for(int i = N; i >= 1; --i) {
        if(dp[i][n] > 0 and dp[i][n] <= w) {
            cout << i << endl;
            exit(0);
        }    
    }
}   
 
 
 
 
signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
} 

Measured memory_bytes: 80000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, j, n) for (int i = j; i < (n); ++i)
#define SORT(a) sort(a.begin(), a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1001001001;
vector<vi> Graph;
int da[100000];
int dt[100000];
void dfs(int v, int p, int dist)
{
    for (auto e : Graph[v])
    {
        dt[e] = dist;
        if (e == p)
            continue;
        else
            dfs(e, v, dist + 1);
    }
}

int main()
{
    int n, u, v;
    fill(dt, dt + 10000, inf);
    cin >> n >> u >> v;
    u--;
    v--;
    Graph.assign(n, vi());
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    vi dist(n, -1);
    vi dist2(n, -1);
    queue<int> que;
    dist[u] = 0;
    que.push(u);
    while (!que.empty())
    {
        int p = que.front();
        que.pop();

        for (int nv : Graph[p])
        {
            if (dist[nv] != -1)
                continue;
            dist[nv] = dist[p] + 1;
            que.push(nv);
        }
    }

    dist2[v] = 0;
    que.push(v);
    while (!que.empty())
    {
        int p = que.front();
        que.pop();

        for (int nv : Graph[p])
        {
            if (dist2[nv] != -1)
                continue;
            dist2[nv] = dist2[p] + 1;
            que.push(nv);
        }
    }
    int max_dist = 0;
    rep(i,n){
        if(dist2[i]>dist[i]){
            max_dist = max(max_dist,dist2[i]);
        }
        //cout<<dist[i]<<":" << dist2[i] <<":" <<dist2[i] - dist[i] << endl;
    }
    cout<<max_dist-1<<endl;
}

Measured memory_bytes: 6656
n, a, b, c, d = [int(i) for i in input().split()]

ok = False
for i in range(n):
    j = n - 1 - i
    x, y = a + c * i - d * j, a + d * i - c * j
    if x <= b <= y:
        ok = True

if ok:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 40556
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=5e5+5;
int n,q;
struct data{
	int w;
	double t;
};

namespace utils{
	inline int nxi(FILE *fd=stdin){
		int x=0;
		char c;
		while(((c=fgetc(fd))>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=fgetc(fd));
		while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
		return f?-x:x;
	}

	template <class T>
		inline void apx(T &x,const T y){
			x<y?x=y:0;
		}

	template <class T>
		inline void apn(T &x,const T y){
			x>y?x=y:0;
		}
}
using namespace utils;

int main(){
	static data dq[N];
	double sumt=0;
	int hd=0,tl=0,sumw=0;
	n=nxi(),q=nxi();
	for(int i=1; i<=n; ++i){
		int t=nxi(),w=nxi();
		dq[tl++]=(data){w,(double)t};
		sumw+=w;
		sumt+=(lint)t*w;
		for(; tl-1>hd&&dq[tl-1].t<dq[tl-2].t; --tl){
			int oflow=std::max(0,dq[tl-2].w+dq[tl-1].w-q);
			sumw-=oflow;
			sumt-=dq[tl-2].t*oflow;
			assert(oflow<=dq[tl-2].w);
			int w0=dq[tl-2].w-oflow,w1=dq[tl-1].w;
			dq[tl-2].t=(dq[tl-2].t*w0+dq[tl-1].t*w1)/(w0+w1);
			dq[tl-2].w+=dq[tl-1].w-oflow;
		}
		for(; sumw>q&&hd<tl; ++hd){
			int wgt=std::min(sumw-q,dq[hd].w);
			dq[hd].w-=wgt;
			sumw-=wgt;
			sumt-=wgt*dq[hd].t;
			if(sumw==q) break;
		}
		assert(hd<tl);
		printf("%.8lf\n",sumt/sumw);
	}
	return 0;
}


Measured memory_bytes: 17280
#include<iostream>
using namespace std;
   
struct Card {char suit, value;};
 
void bubble(struct Card A[], int N) {
 
   for (int i = 0; i < N; i++) {
      for (int j = N-1; j >= i+1; j--) {
         if (A[j].value < A[j-1].value) {
            Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
         }
      }
   }
}
 
 
void selection(struct Card A[], int N) {
 
   for (int i = 0; i < N; i++) {
      int minj = i;
      for( int j = i; j < N; j++) {
         if (A[j].value < A[minj].value) minj = j;
      }
      Card t = A[i]; A[i] = A[minj]; A[minj] = t;
   }
}
 
 
void print(struct Card A[], int N) {
 
   for (int i = 0; i < N; i++) {
      if (i > 0) cout << " ";
      cout << A[i].suit << A[i].value;
   }
   cout << endl;
}
   
 
bool isStable(struct Card C1[], struct Card C2[], int N) {
 
   for (int i = 0; i < N; i++) {
      if (C1[i].suit != C2[i].suit) return false;
   }
   return true;
}
 
 
int main() {
 
   Card C1[100], C2[100];
   int N;
   char ch;
 
   cin >> N;
   for (int i = 0; i < N; i++) {
      cin >> C1[i].suit >> C1[i].value;
   }
 
   for (int i = 0; i < N; i++) C2[i] = C1[i];
 
   bubble(C1, N);
   selection(C2, N);
 
   print(C1, N);
   cout << "Stable" << endl;
   print (C2, N);
   if (isStable(C1, C2, N)) {
      cout << "Stable" << endl;
   } else {
      cout << "Not stable" << endl;
   }
 
 
   return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  while(1){
    int n;
    cin>>n;
    if(n == 0) break;
    string s;
    int nums[40];
    REP(i,0,n){
      cin>>s;
      nums[i] = (int)s.size();
    }
    REP(i,0,n){
      int p = 0;
      int ch[5] = {};
      bool flag = false;
      REP(j,i,n){
        ch[p] += nums[j];
        if((p==0 || p==2) && ch[p]==5){
          p++;
        }else if((p==1 || p==3 || p==4) && ch[p]==7){
          p++;
        }
        if(p==5){
          cout<<i+1<<endl;
          flag = true;
          break;
        }
      }
      if(flag) break;
    }

  }

  return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 998'244'353LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 N, M, K;
  cin >> N >> M >> K;

  vi fractal(N);
  fractal.at(0) = 1;
  rep(i,1,N){
    fractal.at(i) = fractal.at(i-1) * i;
    fractal.at(i) %= MOD;
  }

  i64 ans = 0;
  rep(i,K+1){
    i64 tmp;
    if(i==0 or i==N-1) tmp = 1;
    else{
      tmp = fractal.at(N-1);
      tmp *= pow_mod(fractal.at(N-1-i),MOD-2,MOD);
      tmp %= MOD;
      tmp *= pow_mod(fractal.at(i),MOD-2,MOD);
      tmp %= MOD;
    }
    tmp *= M;
    tmp %= MOD;
    tmp *= pow_mod(M-1,N-1-i,MOD);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 4768
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, K, Q;
  cin >> N >> K >> Q;
  unordered_map<long, long> mp;
  rep (i, Q) {
    long A;
    cin >> A;
    mp[A]++;
  }
  rep (i, N) {
    long A = i + 1;
    long score = K - Q + mp[A];
    if (score > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i = (a);i <= (b);++i)
#define LOCAL
typedef long long ll;
const int maxn = 1e5+5;
int main()
{
#ifdef LOCALa
    freopen("simple.in","r",stdin);
    freopen("simple.out","w",stdout);
#endif
    int a[4];
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+1+3);
    if(a[1]==a[2]&&a[2]!=a[3]){
        printf("Yes\n");
    }
    else if(a[2]==a[3]&&a[1]!=a[2])printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())

import heapq

def main():
  n, m = an()
  a = [-int(x) for x in stdin.readline().split()]
  heapq.heapify(a)
  ans = 0
  for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, x / 2)
  print(-sum(int(x) for x in a))

main()

Measured memory_bytes: 14168
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n,i,red=0,counter=0;
string s;
scanf("%d",&n);
cin>>s;
for(i=0;i<n;++i){
    if(s[i]=='R'){
        red++;
    }
}
for(i=0;i<n;++i){
    if(s[i]=='R'&&i+1>red){
        counter++;
    }
}
cout<<counter<<endl;



    return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back
#define vs vector<string>

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll n;
    cin>>n;
    vl o(n/2);
    vl e(n/2);
    rep(i,n){
        if(i%2) cin>>e[i/2];
        else cin>>o[i/2];
    }
    ll me=0;
    ll se=-1;
    ll mo=0;
    ll so=-1;
    ll ce=0;
    ll sce=0;
    ll co=0;
    ll sco=0;
    {
        map<ll,ll> m;
        rep(i,n/2){
            m[e[i]]++;
        }
        for(auto p:m){
            if(p.second>ce){
                se=me;
                sce=ce;
                ce=p.second;
                me=p.first;
            }else if(p.second>sce){
                sce=p.second;
                se=p.first;
            }
        }
    }
    {
        map<ll,ll> m;
        rep(i,n/2){
            m[o[i]]++;
        }
        for(auto p:m){
            if(p.second>co){
                so=mo;
                sco=co;
                co=p.second;
                mo=p.first;
            }else if(p.second>sco){
                sco=p.second;
                so=p.first;
            }
        }
    }
    if(me==mo){
        cout<<n-max(co+sce,ce+sco)<<endl;
    }else{
        cout<<n-co-ce<<endl;
    }
}

Measured memory_bytes: 4096
#!/usr/bin/env python3
import sys

def solve(A: int, B: int):
    if B % A == 0:
        return A + B
    return B - A

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	char x, y;

	cin >> x >> y;

	if (x == y) {
		cout << "=" << endl;
	}
	else if (x < y) {
		cout << "<" << endl;
	}
	else {
		cout << ">" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
py=[[0,0,0]]*m
for i in range(m):
  py[i]=list(map(int,input().split()))+[i]
ans=['']*m
a=sorted(py)
j=0
for i in range(len(a)):
  if i>0 and a[i-1][0]<a[i][0]:
    j=1
  else:
    j+=1
  ans[a[i][2]]='{:06}'.format(a[i][0])+'{:06}'.format(j)
for i in range(m):
  print(ans[i])

Measured memory_bytes: 32628
from collections import defaultdict

N, M = map(int, input().split())

years = []
for i in range(M):
    P, Y = map(int, input().split())
    years.append((P, Y))

d = defaultdict(int)
b = dict()
for p, y in sorted(years, key=lambda x: x[1]):
    d[p] += 1
    b[y] = '{:06d}{:06d}'.format(p, d[p])

for p, y in years:
    print(b[y])


Measured memory_bytes: 41068