akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    string s;
    cin >> s;
    ll N = stoi(s);
    int p = 0;
    FOR(i,0,s.size())p += ctoi(s[i]);
    Yes(N%p == 0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  vint a(3);
  vint b(3);
  vint c(3);
  rep(i,3) cin >> a[i] >> b[i] >> c[i];
  bool judge = true;
  for(int i = 0;i<2;i++){
    for(int j = i;j<3;j++){
      if(a[i] - a[j] == b[i] - b[j] && a[i] - a[j] == c[i] - c[j] && b[i] - b[j] == c[i] - c[j]){
      }
      else{
        judge = false;
      }
    }
  }
  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
///
// File:  1125.cpp
// Author: ymiyamoto
//
// Created on Fri Nov 10 20:46:16 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  while (true) {
    uint32_t N, W, H;
    cin >> N;
    if (N == 0) break;
    cin >> W >> H;

    vector<pair<uint32_t, uint32_t>> trees;
    for (uint32_t i = 0; i < N; i++) {
      uint32_t x, y;
      cin >> x >> y;
      trees.push_back({x - 1, y - 1});
    }
    uint32_t U, T;
    cin >> U >> T;

    uint32_t max_count = 0;
    for (uint32_t i = 0; i < W; i++) {
      for (uint32_t j = 0; j < H; j++) {
        uint32_t count = 0;
        for (auto tree = trees.begin(); tree < trees.end(); tree++) {
          if (i <= tree->first && tree->first <= (i + U - 1) && j <= tree->second && tree->second <= (j + T - 1)) {
            count++;
          }
        }
        max_count = max(max_count, count);
      }
    }
    cout << max_count << endl;
  }

  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())	//昇順
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())	//降順
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF 1000000000000000000


using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

ll mod = 998244353;

int main()
{
	ll N;
	cin>>N;

	vec D(N,-1);
	REP(i,N){
		cin>>D[i];
	}

	if(D[0]!=0){
		cout<<0<<endl;
		return 0;
	}
	SORT(D);

	if(D[1]==0){
		cout<<0<<endl;
		return 0;
	}
	ll ans=1;
	ll current_level=1;
	ll current_num=0;
	ll previous_num=1;
	FOR(i,1,N){
		if(D[i]==current_level){
			current_num++;
		} else{
			if(D[i]==current_level+1){
				ans%=mod;
				REP(i,current_num){
					ans*=previous_num;
					ans%=mod;
				}
				previous_num=current_num;
				current_num=1;
				current_level++;
			}
			else {
				ans=0;
				cout<<ans<<endl;
				return 0;
			}
		}

	}
	REP(i,current_num){
		ans*=previous_num;
		ans%=mod;

	}


	ans %=mod;

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
s = list(input())
n = len(s)
k = int(input())

for i in range(n):
    x = ord(s[i]) - ord('a')
    if x == 0 or 26 -x > k: continue
    k -= 26 - x
    s[i] = 'a'

if k:
    s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))

print(''.join(s))


Measured memory_bytes: 4156
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <string>
#include <algorithm>



using namespace std;


int main()
{
    int a,co;
    co = 0;
    
    for (int i = 0; i < 5; i++)
    {
        cin >> a;
        if (a < 40)
        {
            a = 0;
            a = 40;
        }
        co += a;
        a = 0;
    }
    cout << co / 5 << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int num = 1;
  for (int i = 0; i < n; i++) {
    if (num * 2 < num + k) {
      num *= 2;
    }
    else {
      num += k;
    }
  }
  cout << num << endl;
}
    


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

namespace Contest20191030
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int r = n[0];
            int d = n[1];
            int x2000 = n[2];
            int ans = r * x2000 - d;
            Console.WriteLine(ans);
            for (int i = 2; i <= 10; i++) 
            {
                ans = r * ans - d;
                Console.WriteLine(ans);
   
            }


            



        }
    }
}


Measured memory_bytes: 11348
N=int(input())
ans=0
for i in range(1,N+1):
    ans+=(N-i+1)*i
for i in range(N-1):
    s,t=map(int,input().split())
    if s>t:
        s,t=t,s
    ans-=(N-t+1)*s
print(ans)

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

int main(){
  int a,b;cin >> a >> b;
  if(a<10&&b<10)cout << a*b << endl;
  else cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 256
n,a,b= map(int, input().split())
s=input()

allcnt=0
b_cnt=0

for i in range(n):
  if s[i]=="c":
    print("No")
  elif s[i]=="a":
    if allcnt<a+b:
      print("Yes")
      allcnt+=1
    else:
      print("No")
  else:
    if allcnt<a+b and b_cnt<b:
      print("Yes")
      b_cnt+=1
      allcnt+=1
    else:
      print("No")
    

Measured memory_bytes: 75896
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 1;
        for (int i = 0; i < N; i++) {
            int n1 = ans * 2;
            int n2 = ans + K;
            ans = Math.min(n1, n2);
        }

        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 21972
import copy

def main():
    h, w, k = map(int, input().split())
    c = [None for _ in range(h)]
    for i in range(h):
        c[i] = list(input())

    ans = 0
    for i in range(1 << h):
        c1 = copy.deepcopy(c)
        x = i
        p = 0
        while x > 0:
            if x & 1 == 1:
                c1[p] = ['x'] * w
            x = x >> 1
            p += 1
        for j in range(1 << w):
            c2 = copy.deepcopy(c1)
            x = j
            p = 0
            while x > 0:
                if x & 1 == 1:
                    for l in range(h):
                        c2[l][p] = 'x'
                x = x >> 1
                p += 1
            count = 0
            for l in range(h):
                for m in range(w):
                    if c2[l][m] == '#':
                        count += 1
            if count == k:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n, p;

vector<P> factorize(int n){
   vector<P> v;
   for (int i = 2; i*i <= n; ++i)
   {
      if(n%i)continue;
      int expo = 0;
      while(n%i == 0){
         expo++;
         n /= i;
      }
      v.pb({i, expo});
   }
   if(n > 1){
      v.pb({n, 1});
   }
   return v;
}

int32_t main(){_

   cin>>n>>p;
   vector<P> v = factorize(p);

   int ans = 1;
   for(auto it: v){
      if(it.S >= n){
         for (int i = 0; i < (it.S/n); ++i)
            ans *= (it.F);
      }
   }

   cout<<ans;
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,P;
	cin >> N>>P;
	ll count_odd = 0;
	for (ll i = 0; i < N; ++i){
		ll a;cin >>a;
		if (a%2==1) count_odd++;
	}
	ll ans = 0;
	if (P%2==1 and count_odd==0){// 食べる個数が奇数で奇数の袋がない
		ans = 0;
	}
	else if (P%2==1){ // 食べる個数が奇数なら
		ans += ll(pow(2, N-count_odd)); // 偶数個のビスケットは好きな数食べる = 2**n
		// 奇数個のビスケットは奇数個食べる
		// n-1個を自由に選んだら最後の袋nは自動で決まる
		ans *= ll(pow(2, count_odd-1));
	}
	else{ // 食べる個数が偶数なら
		ans += ll(pow(2, N-count_odd)); // 偶数個のビスケットは好きな数食べる = 2**n
		// 奇数個のビスケットは奇数個食べる
		// n-1個を自由に選んだら最後の袋nは自動で決まる
		ans *= max(ll(1), ll(pow(2, count_odd-1)));
	}
	
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
lights = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0

for i in range(1<<N):
    on = 0
    onoff = bin(i)[2:].zfill(N)
    for j, switches in enumerate(lights):
        if sum(onoff[s-1] == '1' for s in switches[1:]) % 2 == p[j]:
            on += 1
    if on == M:
        ans += 1

print(ans)

Measured memory_bytes: 75152
import math

a, b, c = [int(i) for i in input().split()]
s = 0.5 * a * b * math.sin(math.radians(c))
l = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(c)))
h = 2 * s / a
print(s)
print(l)
print(h)

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<pii> p(m);
    for(int i = 0; i < m; ++i){
        cin >> p[i].second >> p[i].first;
    }
    sort(begin(p), end(p), greater<pii>());
    int cnt = 0;
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < p[i].second; ++j){
            a.push_back(p[i].first);
            ++cnt;
            if(cnt >= n) goto END;
        }
    }
    END:;
    sort(begin(a), end(a), greater<int>());
    cout << accumulate(a.begin(), a.begin() + n, 0LL) << "\n";
    return 0;
}

Measured memory_bytes: 1792
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int h, a;
	cin >> h >> a;
	int ans = (h + (a - 1)) / a;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <complex>
using namespace std;
typedef long long LL;
void guan() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls (rt<<1)
#define rs (rt<<1|1)
#define F first
#define S second
#define mst(x,a) memset(x,a,sizeof(x))
#define Pr pair<LL,LL>
#define root 1,cnum,1
#define For(i,b,c) for(int i=b;i<=c;i++)
const int maxn = 400040;
const LL mod = 1e9 + 7;
const double pi = acos(-1.0);

int n;
int a[maxn];

void solve() {
    for(int i = 1;i <= n;i++) cin >> a[i];
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        int sum = 0;
        ans += a[i] - 1;
    }
    cout << ans << endl;
}

int main() {
    guan();
    int t = 1;
    while(t--) {
        while(cin >> n)
            solve();
    }

    //cin >> t;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

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

  int H,W; cin >> H >> W;
  vector<string> board(H);
  rep(i,H) cin >> board[i];

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

  rep(i,H)rep(j,W) {
    if(board[i][j] == '#') continue;

    int cnt = 0;
    rep(k, 8) {
      // マスの座標
      int x = i + dx[k];
      int y = j + dy[k];
      // 座標のマスが存在するか
      if(x<0 || x>=H) continue;
      if(y<0 || y>=W) continue;
      // 爆弾であればカウントアップ
      if(board[x][y] == '#') ++cnt;
    }

    board[i][j] = cnt+'0';
  }

  rep(i,H) cout<<board[i]<<endl;

  return 0;
}


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

using ll= long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

vector<int> seen;
vector<int> size;

void dfs(vector<vector<int>> &G,  int v, int index){
    seen[v]=index;
    for(auto nv: G[v]){
        if(seen[nv] != -1) continue;
        dfs(G, nv, index);
    }
    size[index]++;
}

int main(){
    int N, M, K;  cin >> N >> M >> K;
    vector<vector<int>> G(N);
    for(int i=0; i<M; i++){
        int A, B; cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<int> C(K), D(K);
    for(int i=0; i<K; i++){
        cin >> C[i] >> D[i];
        C[i]--, D[i]--;
    }
    seen.assign(N, -1);
    int index=0;
    for(int i=0; i<N; i++){
        if(seen[i] != -1) continue;
        size.push_back(0);
        dfs(G, i, index);
        index++;
    }
    vector<int> block_num(N, 0);
    for(int i=0; i<K; i++){
        if(seen[C[i]] == seen[D[i]]){
            block_num[C[i]]++;
            block_num[D[i]]++;
        }
    }
    int res;
    for(int i=0; i<N; i++){
        res=size[seen[i]]-block_num[i]-G[i].size()-1;
        if(i != 0) cout << " ";
        cout << res;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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



int N;
string s;

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

  if (N % 2 == 1) {
    cout << "No\n";
  } else {
    if (s.substr(0, N/2) == s.substr(N/2, N/2)) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

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

  string S;

  cin >> S;

  bool n = false;
  bool s = false;
  bool w = false;
  bool e = false;

  rep(i, S.size()) {
    if (S[i] == 'N') n = true;
    if (S[i] == 'S') s = true;
    if (S[i] == 'W') w = true;
    if (S[i] == 'E') e = true;
  }

  if (n == s && w == e) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int a, b;
	a = 0;
	b = N;

	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		a = max(a, L);
		b = min(b, R);
	}

	int ret = b - a;
	if (ret < 0) ret = 0;
	else ret++;

	cout << ret << endl;
}

Measured memory_bytes: 3600
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n,m = LI()
a = LI()
b = LI()
li = list(set(a)|set(b))
li2 = list(set(a)&set(b))
li.sort()
li2.sort()
print(len(li2),len(li))
for i in li2:
    print(i)
for i in li:
    print(i)
"""

#B
"""
n = I()
p = LI()
ans = [None for i in range(2*n)]
ind = [i for i in range(n)]
for i in range(n):
    ind[p[i]-1] = i
l = 0
print(ind)
for i in range(n):
    while ans[l] != None:l += 1
    ans[l] = "("
    r = n+ind[i]
    while ans[r] != None:r += 1
    ans[r] = ")"
    print(ans)
k = []
q = []
a = 1
print(ans)
for i in range(2*n):
    if ans[i] == "(":
        q.append(a)
        a += 1
    else:
        k.append(q.pop(-1))
if k != p:
    print(":(")
else:
    for i in range(2*n-1):
        print(ans[i],end = "")
    print(ans[-1])
"""

#C
"""
def fact(n):
    i = 2
    a = n
    if n < 4:
        return [1,n],[n]
    li = [1,n]
    while i**2 <= a:
        if n%i == 0:
            li.append(i)
            if i != n//i:
                li.append(n//i)
        i += 1
    li.sort()
    i = 2
    if len(li) == 2:
        return li,[a]
    k = []
    b = a
    while i**2 <= b:
        if a%i == 0:
            k.append(i)
            while a%i == 0:
                a//= i
        i += 1
    if a!=1:
        k.append(a)
    return li,k
n = I()
l,k = fact(n)
if len(l) == 2:
    print(1,1)
else:
    print(len(k),len(l)-1)
"""

#D
n,m = LI()
a = LI()
f = [0 for i in range(n+1)]
for i in range(1,m):
    f[a[i]-a[i-1]-1] += 1
f[n-a[-1]] += 1
s = 0
k = [0 for i in range(n+1)]
for i in range(n)[::-1]:
    s += f[i]
    k[i] += s+k[i+1]
for i in range(n+1):
    k[i] += a[0]-1
q = I()
p = LI()
for i in p:
    l = 0
    r = n
    while r-l>1:
        m = (l+r)//2
        if k[m] > i:
            l = m
        else:
            r = m
    if k[r] > i:
        print(-1)
    else:
        print(r)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T



Measured memory_bytes: 24948
#include <bits/stdc++.h>
using namespace std;
bool bb[110][110];
int a,b,n,x,y,m,sum=0;//a,b=H,W; m=ai;
void turn1()
{
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<x;j++)
		{
			bb[i][j]=1;
		}
	}
}
void turn2()
{
	for(int i=0;i<=a;i++)
	{
		for(int j=x+1;j<=b;j++)
		{
			bb[i][j]=1;
		}
	}
}
void turn3()
{
	for(int i=0;i<y;i++)
	{
		for(int j=0;j<=b;j++)
		{
			bb[i][j]=1;
		}
	}
}
void turn4()
{
	for(int i=y+1;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			bb[i][j]=1;
		}
	}
}
void count()
{
	int s=0,w=0;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
			if(!bb[i][j])	s++;
		if(s>0) break;
	}
	for(int i=0;i<=b;i++)
	{
		for(int j=0;j<=a;j++)
			if(!bb[j][i]) w++;
		if(w>0) break;
	}
	s=max(s-1,0); w=max(w-1,0);
	sum=s*w;
	//cout<<s<<' '<<w<<endl;		
}
int main()
{
	memset(bb,0,sizeof(bb));
	cin>>b>>a>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y>>m;
		if(m==1)
			turn1();
		if(m==2)
			turn2();
		if(m==3)
			turn3();
		if(m==4)
			turn4();
	}
	count();
	cout<<sum;
	return 0;
}


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

int main()
{
  vector<pair<int,pair<int,int> > > PC;
  int N,M,t,s,d,c,start;
  bool p[20001];

  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    PC.clear();
    start=0;
    for(int i=0;i<N+1;i++)p[i]=false;
    for(int i=0;i<M;i++){
      cin>>t>>s>>d;
      PC.push_back(make_pair(t,make_pair(s-1,d-1)));
    }
    c=1;
    p[0]=true;
    sort(PC.begin(),PC.end());

    for(int i=0;i<M;i++){
      if(p[PC[i].second.first])p[PC[i].second.second]=true;
    }
    for(int i=1;i<N+1;i++)if(p[i])c++;
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1696
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

a, b = Is()
l = a * b / gcd(a, b)
print(int(l))

Measured memory_bytes: 63724
#include <iostream>
using namespace std;
int main()
{
    int a,b;cin>>a>>b;
    if((a*b)>(a+b)&&(a*b)>(a-b)){
        cout<<a*b;
    }
    else if((a+b)>(a*b)&&(a+b)>(a-b)){
        cout<<a+b;
    }
    else cout<<a-b;

   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int N = 1e5+10;
string s;
ll k;
int main()
{
	cin>>s;
	cin>>k;
	ll cnt1=0;
	ll cur1=1;
	if(s.length()==1)
	{
		cout<<(k/2)<<endl;
		return 0;
	}
	bool flag=1;
	for(int i=1;i<s.length();i++)
	{
		if(s[i]!=s[i-1])
		{
			flag=0;
			break;
		}
	}
	if(flag)
	{
		ll num=(ll)(s.length())*k;
		cout<<num/2<<endl;
		return 0;
	}
	for(int i=1;i<s.length();i++)
	{
		if(s[i]==s[i-1])
		cur1++;
		else
		{
			cnt1+=cur1/2;
			cur1=1;
		}
	}
	cnt1+=cur1/2;
	if(k==1)
	{
		cout<<cnt1<<endl;
		return 0;
	}
	ll kk=0;
	if(s[s.length()-1]==s[0])
	{
		int z1=0,z2=0;
		for(int i=s.length()-1;i>=0;i--)
		{
			if(s[i]==s[s.length()-1])
			z1++;
			else
			break;
		}
		for(int i=0;i<=s.length();i++)
		{
			if(s[i]==s[0])
			z2++;
			else
			break;
		}
		if(z1%2==1&&z2%2==1)
		kk++;
		ll ans=k*cnt1+(k-1)*kk;
		cout<<ans<<endl;
	}
	else
	{
		
		cout<<k*cnt1<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N;
	cin >> N;
	vector<int> d(N);
	for(int i = 0; i < N; i++) cin >> d[i];

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

	cout << d[N/2] - d[N/2 - 1] << '\n';

	return 0;
}

Measured memory_bytes: 640
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=map(int,input().split())

ans=0
for t in T:
    if S[-1]<t or S[0]>t: continue
    U=n
    L=0
    while True:
        x=(U+L)//2
        if S[x]==t:
            ans+=1
            break
        elif U-L==1:
            break
        elif S[x]>t:
            U=x
        else:
            L=x
print(ans)


Measured memory_bytes: 16712
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  string s1,s2;
  cin>>s1>>s2;
  ll a,b;
  cin>>a>>b;
  string s3;
  cin>>s3;
  if(s1==s3){
    cout << a-1 << " " << b << endl;
  }
  else{
    cout << a << " " << b-1 << endl;
  }
  return 0;
}

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

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine();
            if (x == "A")
            {
                Console.WriteLine("T");
            }
            else if(x == "T")
            {
                Console.WriteLine("A");
            }
            else if(x == "C")
            {
                Console.WriteLine("G");
            }
            else
            {
                Console.WriteLine("C");
            }
        }
    }
}

Measured memory_bytes: 13140
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f(1, X) :- X =:= 1 ; X =:= 3 ; X =:= 5 ; X =:= 7 ; X =:= 8 ; X =:= 10 ; X =:= 12.
f(4, X) :- X =:= 4 ; X =:= 6 ; X =:= 9 ; X =:= 11.
f(2, X) :- X =:= 2.

main :-
    get_number(X, Y),
    (f(A, X), f(A, Y)) -> writeln("Yes") ; writeln("No").


Measured memory_bytes: 8056
s=input()*2;n=len(s)//2;X=[(0,0)]*4
for j in range(n+1):
 for k in range(3,-1,-1):
  a=int(s[n-j])
  X[k]=(X[k][0]+9*X[k-1][0],X[k][0]+(a-1)*X[k-1][0]+X[k-1][1]if a else X[k][1])if k else(1,1)
print(X[int(input())][1])

Measured memory_bytes: 38384
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
126

output:
126: 2 3 3 7
"""

import sys


def is_prime(n):
    if n == 2:
        return True
    elif n < 2 or not n % 2:
        return False

    return pow(2, n - 1, n) == 1


def prime_factorize(n):
    if is_prime(n):
        return [n]

    ans = list()
    d = 2

    while pow(d, 2) <= n:
        while not n % d:
            ans.append(d)
            n //= d
        d += 1

    if n > 1:
        ans.append(n)

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1 = int(_input[0])
    print(str(n1) + ':', *prime_factorize(n1))

Measured memory_bytes: 7732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner ss = new Scanner(System.in);
        for (;;) {
            int n = ss.nextInt();
            if (n == 0) {
                break;
            }
            StringBuffer t = new StringBuffer();
            String s = ss.next();
            while (n-- > 0) {
                t = new StringBuffer();
                for (int i = 0; i < s.length(); i++) {
                    int count = 1;
                    char kazu = s.charAt(i);
                    while (i + 1 < s.length() && kazu == s.charAt(i + 1)) {
                        count++;
                        i++;
                    }
                    t.append(count + "" + kazu);
}
                s = t.toString();
}
            System.out.println(s);
}

}
}


Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int a[maxn],b[maxn],c[maxn*3],d[maxn*3];
int main(){
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++)scanf("%d",b+i);
	for(int i=0;i<n;i++)c[i]=a[i]^a[(i+1)%n],c[i+n*2]=c[i+n]=b[i]^b[(i+1)%n];
	int j;d[0]=c[n]=j=-1;
	for(int i=0;i<3*n;d[++i]=++j)while(j>=0&&c[i]!=c[j])j=d[j];
	for(int i=0;i<n;i++){
		if(d[n*3-i]==n)printf("%d %d\n",i,a[i]^b[0]);
	}
	return 0;
} 

Measured memory_bytes: 9728
import sys
input = sys.stdin.readline

import math

def main():
    a,b,h,m = map(int, input().split())

    x = abs((h*30+(m/2)) - m*6)

    if x == 0 or x== 360:
        print(abs(a-b))
    elif x == 180:
        print(a+b)
    else:
        if x > 180:
            x = 360 - x

        rad = math.radians(x)

        ans_2 = a*a + b*b - 2*a*b*(math.cos(rad))

        print(math.sqrt(ans_2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9584
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),m=nxt();
    multiset <int,greater<int> > s;
    for(int i=0;i<n;i++)
    {
        int x=nxt();
        s.insert(x);
    }
    while(m--)
    {
        auto it=s.begin();
        int val=*(it)/2;
        s.erase(it);
        s.insert(val);
    }
    ll test=0;
    for(auto it=s.begin();it!=s.end();it++)
        test+=*it;
    cout<<test<<endl;
    
    
    return 0;   
}


 
 


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
ll INF=1e18+5;
//cout << std::fixed << std::setprecision(15) << y << endl;

int main(){
  ll N; string S;
  cin >> N >> S;
  ll cnte = 0, cntw = 0;
  VL e(N,0); VL w(N,0);
  rep(i,0,N){
    if(S[i] == 'E') cnte++;
    e[i] = cnte;
  }
  rep(i,0,N){
    if(S[N-1-i] == 'W') cntw++;
    w[N-1-i] = cntw;
  }

  ll ans = INF;
  ll tmp;
  rep(i,0,N){
    tmp = (N-1) - (e[i]+w[i]-1);//自分を引く
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8268
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;
    }
    if(res<0)res+=mod;
    return res; 
}

int main()
{
    fastio;
    lli n;
    cin>>n;
    lli a[n],ina[n];
    f(i,0,n){cin>>a[i];ina[i]=power(a[i],mod-2);}
    m64 mp;
    f(i,0,n){
        vt <pair<lli,lli>> primes;
        for(lli j=2;j*j<=a[i];j++){
            if(a[i]%j==0){
                primes.push_back({j,0});
                while(a[i]%j==0){
                    primes[primes.size()-1].second++;
                    a[i]/=j;
                }
            }
        }
        if(a[i]>1)primes.push_back({a[i],1});
        f(j,0,primes.size()){
            if(mp[primes[j].first]<primes[j].second)mp[primes[j].first]=primes[j].second;
        }
    }
    lli ans=0;
    f(i,0,n)ans=(ans+ina[i])%mod;
    // cout<<mp.size()<<"\n";
    for(auto it:mp){
        // cout<<it.first<<" "<<it.second<<"\n";
        if(it.first==0)continue;
        ans=(ans*power(it.first,it.second))%mod;
    }
    cout<<tmod(ans,mod);
    return 0;
}


Measured memory_bytes: 1024
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define int long long
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 10000003;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,bol[li];
int cev;
string s;
bool vis[li];
vector<int> v;

inline void sieve(){
	for(int p=2;p<=n;p++){
		if(vis[p])continue;
		bol[p]=2;
		for(int i=p*2;i<=n;i+=p){
			vis[i]=1;
			int at=i;
			int say=0;
			while(at%p==0){say++;at/=p;}
			bol[i]*=say+1;
		}
	}
}

main(void){
	scanf("%lld",&n);
	FOR bol[i]=1;
	sieve();
	FOR{
		cev+=i*bol[i];
	}
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 91708
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1100;
const ll mod = 1e9 + 7;
char maze[maxn][maxn];
ll dp[maxn][maxn];
int n, m;

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

	dp[1][1] = 1LL;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			if(i == 1 && j == 1) continue;
			if(maze[i][j] == '#') continue;

			dp[i][j] = dp[i-1][j] + dp[i][j-1];
			if(dp[i][j] > mod) dp[i][j] -= mod;
		}
	}
	cout<<dp[n][m]<<"\n";
}

Measured memory_bytes: 10752
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# 有理数クラス
class MyFraction:

    def __init__(self, a, b):
        assert b != 0, "分母が0です"

        if b < 0:
            a, b = -a, -b
        if a == 0:
            b = 1

        g = math.gcd(a, b)
        self.numerator = a // g
        self.denominator = b // g

    def __str__(self):
        return "{0}/{1}".format(self.numerator, self.denominator)


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            continue

        if str(MyFraction(a, b)) in AB:
            AB[str(MyFraction(a, b))] += 1
        else:
            AB[str(MyFraction(a, b))] = 1

    C = defaultdict(lambda: ())
    ans = 1
    flag = True
    for ab, k in list(AB.items()):
        a, b = ab.split("/")
        a = int(a)
        b = int(b)
        if a > 0:
            if str(MyFraction(-b, a)) in AB:
                t = AB[str(MyFraction(-b, a))]
            else:
                t = 0
        elif a < 0:
            if str(MyFraction(b, -a)) in AB:
                continue
            t = 0
        else:
            flag = False
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD

    if flag:
        tmp = pow(2, Y, MOD)
        ans = ans * tmp % MOD
    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 179292
from itertools import accumulate
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
# a=[0]+a
acc=accumulate(a)
acc=list(acc)

sunuke=0
arai=0
ans=10**18
for i in range(1,n):
    sunuke=acc[i-1]
    arai=s-sunuke
    t=abs(sunuke-arai)
    ans=min(t,ans)
print(ans)

Measured memory_bytes: 24176
#include <iostream>
#include <numeric>
using namespace std;
typedef long long int ll;

ll gcd(ll x,ll y){
    
    if(x%y==0){
        return y;
    } else {
        return gcd(y,x%y);
    }
    
}

ll abnf(ll x,ll y,ll z){
    ll num1=x/y;
    ll num2=x/z;
    ll g=gcd(y,z);
    ll l=y*z/g;
    
    return x-num1-num2+x/l;
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll on1=abnf(b,c,d);
    ll on2=abnf(a-1,c,d);
    
    cout << on1-on2 << endl;
    return 0;
}


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


void solve(std::string S){
    int ret = 0;
    if(S=="SUN") ret = 7;
    if(S=="MON") ret = 6;
    if(S=="TUE") ret = 5;
    if(S=="WED") ret = 4;
    if(S=="THU") ret = 3;
    if(S=="FRI") ret = 2;
    if(S=="SAT") ret = 1;

    cout << ret << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3476
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		sum += A[i];
	}
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] * 4 * M >= sum) {
			++cnt;
		}
	}
	cout << (cnt >= M ? "Yes" : "No") << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 3e3 + 10;

ll dp[N][N][2];

ll solve(int l, int r, bool player, vector<int> &a, ll s)
{
	if(l > r)
		return 0;

	ll &ans = dp[l][r][player];

	if(ans != -1)
		return ans;

	ans = s - solve(l + 1, r, !player, a, s - a[l]);
	ans = max(ans, s - solve(l, r - 1, !player, a, s - a[r]));

	return ans;
}

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

	vector<int> a(n);
	ll s = 0;

	for(int &x : a)
	{
		cin >> x; 
		s += x;
	}

	memset(dp, -1, sizeof(dp));

	ll f = solve(0, n - 1, 1, a, s);

	cout << 2ll * f  - s << endl;

	return 0;
}

Measured memory_bytes: 142080
#include<iostream>

using namespace std;

int main() {
    int N;

    cin >> N;

    int A[N];

    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int first = 0, second = 0;

    for(int i = 0; i < N; i++) {
        if(A[i] > first) {
            first = A[i];
            continue;
        }
        if(A[i] > second) {
            second = A[i];
        }
    }

    // 出力
    for(int i = 0; i < N; i++) {
        if(A[i] != first) {
            cout << first << endl;
        } else {
            cout << second << endl;
        }
    }

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    vector<int> C(10);
    for (const auto &a: A)
        C[min(8, a / 400)]++;
    
    int ans = 0;
    for (int i = 0; i < 8; i++){
        if (C[i])
            ans++;
    }
    
    if (ans > 0)
        cout << ans << " " << ans + C[8] << endl;
    else
        cout << 1 << " " << C[8] << endl;
}

Measured memory_bytes: 256