akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int M=1e4+10;
typedef long long ll;
const ll mod=1e9+7;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return b/gcd(a,b)*a;
}
int a[M],mn,mx;
map<int,int> mp;
ll quick_mod(ll a,ll b)
{
	ll ans=1;
	a%=mod;
	while(b){
		if(b&1)ans=(ans%mod * a%mod)%mod;
		a=(a%mod * a%mod)%mod;
		b>>=1;
	}
	return ans%mod;
}
ll get_inv(ll x){
	return quick_mod(x,mod-2);
}

void sol(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			int c=0;
			mn=min(mn,i);mx=max(mx,i);
			while(x%i==0){c++;x/=i;}
			mp[i]=max(mp[i],c);
		}
	}
	if(x>1){mp[x]=max(1,mp[x]);mn=min(mn,x);mx=max(mx,x);}
	return;
}
int main(int argc, char const *argv[])
{
	mp.clear();
	mn=1e6+10;
	mx=-1;
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)sol(a[i]);
	
	ll sum=1;
	for(int i=mn;i<=mx;i++){
		if(mp[i]>0){
			for(int j=1;j<=mp[i];j++)sum=(sum%mod * i%mod)%mod;
		}
	}
	
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll tmp=(sum%mod * get_inv(a[i])%mod)%mod;
		ans=(ans+tmp)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 47104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>
#include <math.h>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
void printhoge(set<int> v) {
	ALL(it, v) {
		cout << *it << " ";
	}
	cout << endl;

}

int main() {
	int m, n;
	cin >> n >> m;
	ll res = 1;
	int mm = m;

	if (n == 1) {
		cout << m << endl;
		return 0;
	}
	while (mm > n) {
		int tmp = mm / n;
		int yakusu = 1;
		for (int i = tmp; i >= 2;i--) {
			if (mm % i == 0) {
				yakusu = i;
				break;
			}
		}
		if (yakusu == 1)
			break;
		res *= yakusu;
		mm /= tmp;
	}
	cout << res << endl;

}



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

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min (abs(a - b) + abs(b-c), min(abs(a - c) + abs(a-b), abs(b - c) + abs(a-c))) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

b = 0
c = 0
for i in a:
    if b <= i:
        b = i
        c += 1

print(c)

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

using namespace std;

int main(void) {
  int N, A, B;
  string S;
  cin >> N >> A >> B >> S;

  int ps = 0, fs = 0;
  for (int i = 0; i < N; ++i) {
    
    if (S[i] == 'a') {
      if (ps < A + B) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
      ps++;
    } else if (S[i] == 'b') {
      if (ps < A + B) {
        if (fs < B) {
          cout << "Yes" << endl;
          fs++; ps++;
        } else {
          cout << "No" << endl;
        }
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }

  } 

  return 0;
}

Measured memory_bytes: 896
num_of_match=int(input())
poi_of_1=0
poi_of_2=0
for i in range(num_of_match):
    car_1,car_2=input().split()
    if car_1==car_2:
        poi_of_1+=1
        poi_of_2+=1
    elif car_1>car_2:
        poi_of_1+=3
    elif car_1<car_2:
        poi_of_2+=3
print(poi_of_1,poi_of_2)

Measured memory_bytes: 7568
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input!{
      _n: usize,
      mut c: Chars,
    };
    let red = c.iter().filter(|&s| *s == 'R').count();
    let mut result = 0;
    for i in 0..red {
        if c[i as usize] == 'W' {
            result += 1;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=0,o,p,aa[110000],cntl=0,ab[110000];
pair<int,int> pp[110000];
string s,ss[220000];
char c,cc[5000][5000]={};
queue<int> que;
signed main(){
    cin>>n>>m;
    rep(i,n){
        cin>>aa[i];
    }
    rep(i,m){
        cin>>pp[i].first>>pp[i].second;
        if(aa[pp[i].first-1]>aa[pp[i].second-1]){
            ab[pp[i].second-1]=1;
        }elif(aa[pp[i].first-1]<aa[pp[i].second-1]){
            ab[pp[i].first-1]=1;
        }else{
            ab[pp[i].second-1]=1;
            ab[pp[i].first-1]=1;
        }
    }
    rep(i,n){
        if(ab[i]==0){
            cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 13656
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    mean = sum(A)/N
    ans = []
    for i in range(N):
        ans.append(abs(A[i]-mean))
    min_ = min(ans)
    for i in range(N):
        if ans[i]==min_:
            print(i)
            exit()
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
def find_cycle(N, AB):
  for c in range(N):
    stack = [(c, [])]
    while stack:
      # print("stack:", stack)
      curr, visited = stack.pop()
      if curr in visited:
        # print("cycle found:", curr)
        return visited
      else:
        # print("adding in visited:", curr)
        for i in AB[curr]:
          stack.append((i, visited+[curr]))
  return False

 
 
def find_smaller_cycle(cycle, AB):
    i = 0
    while i < len(cycle):
        v = cycle[i]
        if AB[v]:
            n = AB[v].pop()
            if n in cycle:
                r = cycle.index(n)
                if i < r:
                    cycle = cycle[:i+1] + cycle[r:]
                else:
                    cycle = cycle[r:i+1]
                i = cycle.index(v)
        else:
            i += 1
            
    return cycle
 
 
N, M = [int(i) for i in input().split()]
 
AB = [[] for _ in range(N)]
for _ in range(M):
    A, B = [int(i) - 1 for i in input().split()]
    AB[A].append(B)

cycle = find_cycle(N, AB)
# print("cycle:", cycle)
if not cycle:
    print(-1)
else:
    cycle = find_smaller_cycle(cycle, AB)
            
    print(len(cycle))
    for v in cycle:
        print(v + 1)

Measured memory_bytes: 3316
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv,
       std.format;

void main()
{
auto ip = readln.split.to!(int[]);
int count;
foreach(i; ip[0]..ip[1]+1){
	if(ip[2] % i == 0) count++;
}
writeln(count);
}


Measured memory_bytes: 2488
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long N = sc.nextInt();
		long M = sc.nextInt();
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		long g = gcd(N,M);
		long L = (N * M) / g;
		boolean flag = true;

		for(long i = 0;i<g;i++) {
			if(S[(int)(N/g * i)] != T[(int)(M/g *i)]) {
				flag = false;
			}
		}

		if(flag) {
			System.out.println(L);
		}else {
			System.out.println("-1");
		}
	    sc.close();
	}


    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }


}


Measured memory_bytes: 28364
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
 
#define ll long long
#define ll128 __uint128_t
#define ld long double
#define pll pair <ll, ll>
 
#define vll vector <ll>
#define vld vector<ld>
#define vpll vector<pll>
 
#define vvll vector <vll>
 
#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
#define per(i, a, b) for(ll i = (ll)a - 1; i >= (ll)b; --i)
 
#define endl "\n"
#define pb push_back
#define pf push_front
 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define sorta(v) sort(all(v))
#define sortd(v) sort(rall(v))
 
#define debug if (1)
#define log(val) debug {cout << "\n" << #val << ": " << val << "\n";}
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(name) freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
 
#define mod (ll)(1e9 + 7)
#define inf (mod * mod)
 
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
 
ostream & operator << (ostream & out, vll & a) {
    for(auto i : a) out << i << " ";
    return out;
}
 
istream & operator >> (istream & in, vll & a) {
    for(auto &i : a) in >> i;
    return in;
}
 
int main() {
    ll q;
    cin >> q;
    ll curt, cura, cursum;
    cin >> curt >> cura >> cursum;
 
    set<pll> cur;
    cur.insert(make_pair(cura, 0));
    auto it = cur.begin();
    ll sum1 = 0, sum2 = cura, cnt1 = 0, cnt2 = 1;
    q--;
    ll num = 1;
    while(q--) {
        ll type, a, b;
        cin >> type;
        if (type == 1) {
            cin >> a >> b;
            cursum += b;
            pll newEl = make_pair(a, num);
            cur.insert(newEl);

            if (newEl < *it) {
                sum1 += newEl.first;
                cnt1++;
            } else {
                sum2 += newEl.first;
                cnt2++;
            }

            if (cur.size() % 2 == 0) {
                if (newEl < *it) {
                    it--;
                    cnt2++;
                    sum2 += it -> first;
                    cnt1--;
                    sum1 -= it -> first;
                }
            } else {
                if (*it < newEl) {
                    cnt2--;
                    sum2 -= it -> first;
                    cnt1++;
                    sum1 += it -> first;
                    ++it;
                }
            }
        } else {
            ll med = it -> first;
            ll sum = (cnt1 * med - sum1);
            sum += (sum2 - cnt2 * med);
            sum += cursum;
            cout << med << " " << sum << endl;
        }
        num++;
    }
    return 0;
}

Measured memory_bytes: 16036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.length();
    if(s[n-1]=='2' || s[n-1]=='4' || s[n-1]=='5' || s[n-1]=='7' || s[n-1]=='9')
    {
        cout<<"hon"<<endl;
    }
    else if(s[n-1]=='0' || s[n-1]=='1' || s[n-1]=='6' || s[n-1]=='8')
    {
        cout<<"pon"<<endl;
    }
    else 
    {
        cout<<"bon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
 
int main(void)
{
    int a,n,sum=0,i=0;
    int counter[26] = {0};
    /* ??¢???????????????????????°???????´????????????? */

    char number = 0;
    char c = 97;
    while(scanf("%c",&number) != EOF)
    /* EOF?????§????????? */
    {
        if(number - 'a' < 0)
        {
            sum = number - 'A';
        }
        else
        {
            sum = number - 'a';
        }
        if(sum <= 26 && sum >= 0)
        {
            counter[sum]++;
            i++;
        }
        else
        {
            i++;
        }
    }
    for(a = 0;a < 26;a++)
    {
        printf("%c : %d\n",c,counter[a]);
        /* ???????????????????????§???????????£?¶???§?????? */
        c++;
    }
         
    return 0;
}

Measured memory_bytes: 540
s = list(input())
t = list(input())

s.sort()
t.sort(reverse=True)

if len(s) < len(t):
    f1 = 'Yes'
else:
    f1 = 'No'


for i in range(min(len(s), len(t))):
    if ord(s[i]) < ord(t[i]):
        ans = 'Yes'
        break

    elif ord(s[i]) > ord(t[i]):
        ans = 'No'
        break

    else:
        if i == min(len(s), len(t))-1:
            ans = f1

print(ans)


Measured memory_bytes: 3064
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] H = new int[N];
		for(int i = 0; i < N; i++)
			H[i] = sc.nextInt();
		int zantei = 0, ans = 0;
		for(int i = 0; i < N-1; i++) {
			if(H[i+1] <= H[i])
				zantei++;
			else {
				ans = Math.max(zantei, ans);
				zantei = 0;
			}
		}
		ans = Math.max(zantei, ans);
		System.out.println(ans);

	}

}

Measured memory_bytes: 50764
#include<stdio.h>
#include<iostream>
using namespace std;


int main()
{	
	int S,h,m,s;
	cin >> S;
	h=S/3600;
	S = S - (S / 3600)*3600;
	m = S / 60;
	S = S - (S / 60) * 60;
	s=S;
	cout << h << ":" << m << ":" <<s  <<endl;
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

int n;
int ans;

int cnt[10];

bool is_good(long long val){
	rep(i, 10){
		cnt[i]=0;
	}
	while (val){
		cnt[val%10]++;
		val/=10;
	}
	return (cnt[3]>0&&cnt[5]>0&&cnt[7]>0);
}

void solve(long long val){
	if (val>n)
		return;
	if (is_good(val))
		++ans;
	solve(val*10+3);
	solve(val*10+5);
	solve(val*10+7);
}

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

	cout<<ans<<endl;
}


Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
def f(A):
    P=[0]*(N+1)
    S=[(-1,0)]
    for i,a in enumerate(A):
        while S[-1][1]>a:
            S.pop()
        t=i-S[-1][0]
        P[a]=t
        S.append((i,a))
    return P
P=f(A)
Q=f(A[::-1])
print(sum(a*P[a]*Q[a] for a in A))

Measured memory_bytes: 43528
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define INF (1 << 30)
#define fr first
#define sc second
using namespace std;

typedef pair<int,int> S;
typedef pair<S,int> P;
struct edge{
    int to,cost; edge(){}
    edge(int to,int cost):to(to),cost(cost){}
};

int n,m,costed[128][2];
vector< vector<edge> > info(128);

void init(){
    for(int i=0;i<128;i++){
        for(int j=0;j<2;j++) costed[i][j] = INF;
    }
    info.resize(0); info.resize(128); //なぜかclear()で初期化できない
}

void add_info(){
    int a,b,c;
    cin >> a >> b >> c;
    info[a].push_back(edge(b,c));
    info[b].push_back(edge(a,c));
}

int Dijkstra(){
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(S(0,1),1)); costed[1][1] = 0;
    while(!que.empty()){
        P p = que.top(); que.pop();
        int now = p.fr.sc,c = p.fr.fr,tic = p.sc;
        if(now == n) return c;
        for(int i=0;i<info[now].size();i++){
            edge e = info[now][i];
            if(e.cost + c < costed[e.to][tic]){
                que.push(P(S(e.cost + c,e.to),tic));
                costed[e.to][tic] = e.cost + c;
            }
            if(tic != 0){
                for(int j=0;j<info[e.to].size();j++){
                    edge e2 = info[e.to][j];
                    if(c < costed[e2.to][0]){
                        que.push(P(S(c,e2.to),0));
                        costed[e2.to][0] = c;
                    }
                }
            }
        }
    }
}

int main(){
    while(cin >> n >> m,n||m){
        init();
        for(int i=0;i<m;i++) add_info();
        cout << Dijkstra() << endl;
    }
}

Measured memory_bytes: 1212
#include <iostream>
#include <cmath>

using namespace std;
int main() {
  int N;
  int money = 100;
  cin >> N;
  for (int i = 0; i < N; i++) {
    money = ceil(money * 1.05);
  }
  cout << money * 1000 << endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
    void run(){

	Scanner sc = new Scanner(System.in);
	while(sc.hasNext()){
	    int A = sc.nextInt();
	    int B = sc.nextInt();
	    if(A==0 && B==0) break;
	    //100 500 1000

	    int remaining = B-A;

	    int m1000 = 0;
	    int m500 = 0;
	    int m100 = 0;
	    while(remaining - 1000 >=0){
		m1000++;
		remaining -= 1000;
	    }

	    while(remaining - 500 >=0){
		m500++;
		remaining -= 500;
	    }

	    while(remaining - 100 >=0){
		m100++;
		remaining -= 100;
	    }

	    System.out.printf("%d %d %d\n",m100,m500,m1000);

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

Measured memory_bytes: 31552
import java.util.*;
import java.io.*;

class Main {

	static int size;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		size = Integer.parseInt(br.readLine());
		String line = br.readLine();

		String[] str = line.split(" ");
		int[] a = new int[size+1];
		for (int i=0; i<size; i++) {
			a[i+1] = Integer.parseInt(str[i]);
		}

		buildMaxHeap(a);

		StringBuilder sb = new StringBuilder();
		for (int i=1; i<size+1; i++) {
			sb.append(" ").append(a[i]);
		}
		System.out.println(sb);
	}

	static void maxHeapify(int[] a,int i){
		int left = i*2;
		int right = i*2+1;
		int largest;
		if (left <= size && a[left] > a[i])
			largest = left;
		else
			largest = i;
		if (right <= size && a[right] > a[largest])
			largest = right;
		if (largest != i) {
			swap(a,i,largest);
			maxHeapify(a,largest);
		}
	}

	static void buildMaxHeap(int[] a){
		for (int i=size/2; i>0; i--) {
			maxHeapify(a,i);
		}
	}

    static void swap(int[] a,int idx1,int idx2){
        int temp = a[idx1];
        a[idx1] = a[idx2];
        a[idx2] = temp;
    }
}

Measured memory_bytes: 126800
s = gets().chomp!

ans = s.length
temp = nil
len = s.length 

0.upto(len - 2) { |i|
	if s[i] != s[i+1]
		temp = [i+1, len-(i+1)].max
		if temp < ans
			ans = temp
		end
	end	
}
puts ans


Measured memory_bytes: 1916
using System;
namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            String str;
		    while((str=Console.ReadLine())!=null){
                int d=int.Parse(str);
			    int s=0;
			    for(int x=0;x<600;x=x+d){
				    s=s+x*x*d;
			    }
			    Console.WriteLine(s);
            }
        }
    }
}

Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll size;

  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) size.push_back(1);
    return;
  }

  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  bool is_united(ll a, ll b) {
    return (root(a) == root(b));
  }

  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    size[root(a)] += size[root(b)];
    parent[root(b)] = root(a);
    return;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;

  vll a(m), b(m);
  for (ll i = 0; i < m; i++) cin >> a[i] >> b[i];

  struct union_find uf;
  uf.init(n);

  ll unconv = n * (n - 1) / 2;
  vll ans(1, unconv);

  for (ll i = m - 1; i > 0; i--) {
    ll x = uf.root(a[i] - 1), y = uf.root(b[i] - 1);
    if (!uf.is_united(x, y)) {
      unconv -= uf.size[x] * uf.size[y];
      uf.unite(x, y);
    }
    ans.push_back(unconv);
  }

  for (ll i = 0; i < m; i++) cout << ans[m - 1 - i] << endl;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  int c = -a + b;
  string ans;
  if (c <= 0) {
    ans = "delicious";
  } else if (c <= x) {
    ans = "safe";
  } else {
    ans = "dangerous";
  }
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toLong() }
    val A = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    var n = N.toInt()

    val all = LongArray(n, { 0 })
    val onlyAfter = LongArray(n, { 0 })

    val MOD = 1000000000 + 7
    var answer = 0L

    (0 until n).forEach { i ->
        (0 until n).forEach { j ->
            if (A[i] > A[j]) {
                if (j >= i) {
                    onlyAfter[i] = (onlyAfter[i] + 1) % MOD
                }
                all[i] = (all[i] + 1) % MOD
            }
        }
    }

    (0 until n).forEach { i ->
        answer = (answer + (onlyAfter[i] * K)) % MOD
        answer = (answer + ((K * (K - 1) / 2 % MOD) *  (all[i]))) % MOD
    }

    println(answer)
}


Measured memory_bytes: 40516
#include <stdio.h>

#define N 1000

int main(){
  int A[N];
  int i,j,n,v,k;
  scanf("%d",&n);
  
  for(i = 0;i < n;i++)scanf("%d ",&A[i]);
  for(k = 0;k < n-1;k++)printf("%d ",A[k]);
  printf("%d\n",A[n-1]);
  for(i = 1;i < n;i++){
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(k = 0;k < n-1;k++)printf("%d ",A[k]);
    printf("%d\n",A[n-1]);
  }
  return 0;
}


Measured memory_bytes: 2712
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int N, ans = 0;
	string S;
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		char a[4];
		sprintf(a, "%03d", i);
		vector<bool> b(3);
		for (char& i : S) {
			if (i == a[0] && !b[0]) b[0] = true;
			else if (i == a[1] && b[0] && !b[1]) b[1] = true;
			else if (i == a[2] && b[0] && b[1] && !b[2]) b[2] = true;
		}
		if (all_of(b.begin(), b.end(), [](bool a) { return a; })) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除) 追加削除検索O(log(N))
using A = vector<vector<long long>>;
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)
using PQL = priority_queue<long long>; //erase  (でキーごと削除) push pop top 
using PQG = priority_queue<long long,L,greater<long long>>; //erase  (でキーごと削除) push pop top 

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define stablesorted(vector) stable_sort(vector.begin(), vector.end())
#define stablesortedreverce(vector) stable_sort(vector.rbegin(), vector.rend())
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define max max<unsigned long>
#define min min<unsigned long>
#define inf 1000000000000000000+10
#define setans long long ans=0;

long long MOD=1000000007;

template <typename PQ>
long long pqsum(PQ pq){long long tmp=0;while(!pq.empty()){tmp+=pq.top();pq.pop();};return tmp;};

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(unsigned long a){cout<<a<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}



//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君




int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n;
    
    cin>>n;
    vector<pair<string,pair<long long,long long>>> v;

    string s;
    long long tmp;
    for(long long i=0  ;i<n  ;i++){
        cin>>s>>tmp;
        v.push_back({s,{-tmp,i+1}});
    }
    sorted(v);
//    stablesorted(v);
    for(long long i=0  ;i<n  ;i++){
        print(v[i].second.second);
    }
}

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

int main(){
  int n,x;
  cin >> n >> x;
  int a=0;
  long long int ans = 0;
  cin >> a; 
  if(a>x){ans = ans + (a-x); a = x;}
  for(int i=1;i<n;i++){
    int c;
    cin >> c;
    if(c>x){ ans = ans + (c-x); c = x;}
	if(a+c > x) {ans = ans + (a+c-x); c = c - (a+c-x);}
    a = c;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<double> p(N);
  rep(i,N){
    cin >> p[i];
  }
  vector<double> e(N);
  for(int i = 0;i<N;i++){
    e[i] = (p[i]+1)/2;//p[i]のサイコロの期待値
  }
  double ans = 0;
  vector<double> es(N);
  es[0] = e[0];

  for(int i = 1;i<N;i++){
    es[i] = es[i-1] + e[i];//eの累積和
  }
 
  for(int i = 0;i<=N-K;i++){
    double sum = es[i+K-1] - es[i-1];//K個の区間和
    ans = max(ans,sum);
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
  
}

Measured memory_bytes: 4992
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<int,int> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;

int main()
{
	int n;
	read(n);
	if(lowbit(n)==n)
	{
		printf("No\n");
		return 0;
	}
	std::vector<pi> ans;
	for(int i=2;i<n;i+=2)
	{
		ans.pb(mkpr(1,i));
		ans.pb(mkpr(1,i+1));
		ans.pb(mkpr(i,i+n+1));
		ans.pb(mkpr(i+1,i+n));
	}
	ans.pb(mkpr(n+2,n+1));
	if(!(n&1))
	{
		for(int i=0;;++i)
		{
			if((n>>i)&1)
			{
				ans.pb(mkpr(n,1<<i));
				ans.pb(mkpr(n+n,n^(1<<i)^1));
				break;
			}
		}
	}
	printf("Yes\n");
	for(auto it:ans) printf("%d %d\n",it.first,it.second);
	return 0;
}


Measured memory_bytes: 3952
#include <stdio.h>
#include <stdlib.h>

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

Measured memory_bytes: 2728
#include<stdio.h>

int main()
{	
	int a, b,c;
	scanf("%d %d %d",&a, &b, &c);
	
	if(a < b && b < c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

		return 0;
	
} 


Measured memory_bytes: 2600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll A[200200];
ll N,K;

bool isOK(ll x){
    ll cnt = 0;
    rep(i,0,N){
        if(A[i] <= x) continue;
        cnt += (A[i] - 1) / x;
    }
    return (cnt <= K);
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i,0,N) cin >> A[i];

    ll ok = 1000000000;
    ll ng = 0;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(isOK(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 5180
#n=int(input())
n,m,q=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

al=[]
bl=[]
cl=[]
dl=[]
l=[]
ansl=[0 for i in range(n+1)]
for i in range(q):
    a,b,c,d=map(int,input().split())
    al.append(a)
    bl.append(b)
    cl.append(c)
    dl.append(d)
    l.append([a,b,c,d])

def score(seq):
    temp=0
    for a,b,c,d in zip(al,bl,cl,dl):
        if seq[b-1]-seq[a-1]==c:
            temp+=d
    return temp

def dfs(seq):
    if len(seq)==n:
        return score(seq)
    res=0
    prev_last=seq[-1] if len(seq)>0 else 1
    for v in range(prev_last,m+1):
        seq.append(v)
        res=max(res,dfs(seq))
        seq.pop()
    return res
print(dfs([]))


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int h, w;
  cin >> h >> w;
  vector<vector<ll>> c(10, vector<ll>(10)), a(h, vector<ll>(w));
  REP(i, 10) REP(j, 10) cin >> c[i][j];
  REP(i, h) REP(j, w) cin >> a[i][j];
  REP(k, 10) REP(i, 10) REP(j, 10){
    chmin(c[i][j], c[i][k]+c[k][j]);
  }
  ll ans = 0;
  REP(i, h) REP(j, w){
    if(a[i][j] == -1) continue;
    ans += c[a[i][j]][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int a,b;
    cin >> a >>b;
    cout << a*b-b-a+1 << endl;
    return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN,"%s",$s);
fscanf(STDIN,"%d",$q);
$revers_flag = -1;
for($i=0;$i<$q;$i++){
  $command = explode(" ",trim(fgets(STDIN)));
  if($command[0] == 1){
    $revers_flag *= -1;
  }else{
    if($revers_flag == 1){
      if($command[1]==1){
        $s .= $command[2];
      }else{
        $s = $command[2].$s;
      }
      //echo $i." ".$s."\n";
    }else{
      if($command[1]==1){
         $s = $command[2].$s;
       
      }else{
 		$s .= $command[2];
      }
    }
  }
}
      

if($revers_flag == 1){
  for($i=strlen($s)-1;$i>=0;$i--){
    echo $s[$i];
  }
}else{
  echo $s;
}
      


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

namespace ConsoleApp11
{
    class Class50
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = (int)Math.Ceiling((double)(I[0] - 1) / (I[1] - 1));
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 19552
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Info{
	Info(int arg_sum,int arg_state){
		sum = arg_sum;
		state = arg_state;
	}
	bool operator<(const struct Info &arg) const{

		return sum < arg.sum;
	}
	int sum,state;
};

int N;
int POW[30];
vector<Info> info;

int main(){

	POW[0] = 1;
	for(int i = 1; i < 30; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d",&N);

	int num;
	scanf("%d",&num);

	int tmp;
	vector<int> V;

	for(int i = 0; i < num; i++){

		scanf("%d",&tmp);
		V.push_back(tmp);
	}

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

	for(int state = 0; state < POW[V.size()]; state++){
		int sum = 0;
		for(int i = 0; i < V.size(); i++){
			if(state & POW[i]){

				sum += POW[V[i]];
			}
		}
		info.push_back(Info(sum,state));
	}

	for(int i = 0; i < info.size(); i++){

		printf("%d:",info[i].sum);
		for(int k = 0; k < V.size(); k++){
			if((info[i].state&POW[k])){
				printf(" %d",V[k]);
			}
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 4876
#include<bits/stdc++.h>
using namespace std;
int me[10],soft[10],n;
char str[10][21];
void serch(int num,int now,int sum,int point,int co)
{
    if(num==0)return;
    else if(n==now){
        soft[point]=-10000;
        cout<<str[point]<<endl;;
        serch(num-1,0,sum-me[point],0,0);
    }
    else if(sum-me[now]<=soft[now]&&co==0)serch(num,now+1,sum,now,1);
    else if(sum-me[now]<=soft[now]&&me[point]<me[now])serch(num,now+1,sum,now,1);
    else serch(num,now+1,sum,point,co);
}
int main()
{
    while(cin>>n,n){
        int sum=0;
        for(int i=0;i<n;i++){
            cin>>str[i]>>me[i]>>soft[i];
            sum+=me[i];
        }
        serch(n,0,sum,0,0);
    }

}

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    lli n, m, ans=1 ;
    cin>> n >> m ;
    if(abs(n-m)>1)
      {
        cout<< 0 ;
        return 0 ;
      }
    if(n<m) swap(n, m) ;
    for(int i=1 ; i<=n ; i++)
      ans=(ans*i)%mod ;
    for(int i=1 ; i<=m ; i++)
      ans=(ans*i)%mod ;
    if(n==m) ans=(ans*2)%mod ;
    cout<< ans ;
  }


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	int n, a;
	cin >> n >> a;
	vector<int> x(n);
	int mx = 0;
	for(int i = 0; i < n; i++) {
		cin >> x[i];
		mx = max(mx, x[i]);
	}
	mx = mx * n + 1;
	vector<vector<vector<long long>>> dp(n + 1, vector<vector<long long>>(n + 1, vector<long long>(mx)));
	dp[0][0][0] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= i; j++) {
			for(int k = 0; k < mx; k++) {
				if(k < x[i - 1]) dp[i][j][k] = dp[i - 1][j][k];
				else if(j >= 1) dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
			}
		}
	}
	long long ans = 0;
	for(int j = 1; j <= n; j++) {
		ans += dp[n][j][a * j];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 52224
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[300010];
int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		for(int i=1;i<=3*n;i++)
		scanf("%d", &a[i]);
		
		sort(a+1, a+1+3*n);
		
		long long sum = 0ll;
		
		for(int i=3*n-1, j=1;j<=n;i-=2,j++)
		sum += 1ll*a[i];
		
		printf("%lld", sum);
	}
	return 0;
}

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

const int A=0,G=1,C=2,T=3;
long long dp[111][4][4][4];
int main()
{
    int n;
    cin>>n;
    int mod=1000000007;
   // dp[0][T][T][T]=1;
    for(int i=0 ; i<4 ; ++i)
    {
        for(int j=0 ; j<4 ; ++j)
        {
            for(int k=0 ; k<4 ; ++k)
            {
                if(i==A && j==G && k==C)
                    continue;
                if(i==A && j==C && k==G)
                    continue;
                if(i==G && j==A && k==C)
                    continue;
                dp[3][i][j][k]=1;
            }
        }
    }

    for(int i=3 ; i<n ; ++i)
    {
        for(int j=0 ; j<4 ; ++j)
        {
            for(int k=0 ; k<4 ; ++k)
            {
                for(int l=0 ; l<4 ; ++l)
                {
                    for(int m=0 ; m<4 ; ++m)
                    {
                        if(k==A && l==G && m==C)
                            continue;
                        if(k==G && l==A && m==C)
                            continue;
                        if(k==A && l==C && m==G)
                            continue;
                        if(j==A && l==G && m==C)
                            continue;
                        if(j==A && k==G && m==C)
                            continue;
                        (dp[i+1][k][l][m] += dp[i][j][k][l]) %= mod;
                    }
                }
            }
        }
    }
    long long ans=0;
    for(int i=0 ; i<4 ; ++i)
    {
        for(int j=0 ; j<4 ; ++j)
        {
            for(int k=0 ; k<4 ; ++k)
            {
                ans += dp[n][i][j][k];
            }
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pint;
typedef pair<double,int> pdi;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(ll i = n;i > 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define INF (2147483647)

int NN = (1<<20);
vector<double> SegTree(NN*2-1,INF);

void update(int i, int x){
  i += NN - 1;
  SegTree[i] = x;
  while(i > 0){
    i = (i-1)/2;
    SegTree[i] = min(SegTree[i*2+1],SegTree[i*2+2]);
  }
}

int main(void) {
  int N, Q;
  cin >> N >> Q;
  vector<vector<double>> DD(Q+N*2, vector<double>(4));

  int s,t,x;
  double l,r;
  REP(i,N){
    cin >> s >> t >> x;
    l = x - (t-0.5);
    r = x - (s-0.5);
    DD[Q+i][0] = l; DD[Q+i][1] = 3; DD[Q+i][2] = x; DD[Q+i][3] = i;
    DD[Q+N+i][0] = r; DD[Q+N+i][1] = 2; DD[Q+N+i][2] = x; DD[Q+N+i][3] = i;
  }

  double d;
  REP(i,Q){
    cin >> d;
    DD[i][0] = -d; DD[i][1] = 1; DD[i][2] = i; DD[i][3] = i;
  }

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

  int ans[Q];
  double k,q,j;
  REP(i,N*2+Q){
    k = DD[i][0]; q = DD[i][1]; x = DD[i][2]; j = DD[i][3];
    if(q==1){
      ans[x] = SegTree[0];
    }else if(q == 3){
      update((int)j,(int)x);
    }else if(q == 2){
      update((int)j,INF);
    }
  }

  REP(i,Q){
    if(ans[i]==INF){
      cout << -1 << endl;
    }else{
      cout << ans[i] << endl;
    }
  }

}


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

int main(){
    int n;
    cin >> n ;
    long long a[100010], b[100010];
    for(int i = 0 ; i < n ; ++ i ){
        cin >> a[i] >> b[i];
    }
    long long ans = 0;
    for(int i = n - 1; i >= 0; -- i){
        ans += b[i] - ((a[i] + ans) % b[i] == 0 ? b[i]:(a[i] + ans) % b[i]);
    }
    cout << ans << endl;
  return 0;
}


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

int main(){
  int N, L;
  vector<string> S(110);

  cin >> N >> L;
  for (int i=0; i<N; i++) cin >> S[i];

  sort(S.begin(), S.begin()+N);

  for (int i=0; i<N; i++){
    cout << S[i];
  }
  cout << endl;
}

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

using namespace std;

char s[1005];

int main() {
	scanf("%s", s);
	
	int l = strlen(s);
	
	bool gg = 0;
	
	for (int i = 0; i < l / 2; i++) {
		if (s[i] != s[l - 1 - i]) gg = 1;
	}
	
	for (int i = 0; i < l / 4; i++) {
		if (s[i] != s[l / 2 - 1 - i]) gg = 1;
	}
	
	if (gg) printf("No\n");
	else printf("Yes\n");
}


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



int main()
{
	long long int n;
	cin>>n;
	for(int i=sqrt(n); i>=1; i--)
	{
		if(n%i==0)
		{
			int t=i,l=n/i;
			int s=1;
			while(l>=10)
			{
				s++;
				l/=10;
			}
			cout<<s;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

class UnionFind:
    def __init__(self, N):
        self.rank = [0] * N
        self.parent = [i for i in range(N)]
        self.n = N
        self.size = [1 for i in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

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

        if (self.rank[x] < self.rank[y]):
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                self.size[x] += self.size[y]
            else:
                self.size[x] += self.size[y]

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

    def get_parents(self):
        count = 0
        for i in range(self.n):
            if self.find(i) == i:
                count += 1

        return count

    def get_size(self, x):
        root = self.find(x)
        return self.size[root]



N, M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    a, b = map(int, input().split())
    A[i] = a-1
    B[i] = b-1

uf = UnionFind(N)

i = M-1
ans = [0] * M
x = (N*(N-1)//2)
while i >= 0:
    ans[i] = x

    if not uf.same(A[i], B[i]):
        x -= uf.get_size(A[i]) * uf.get_size(B[i])

    uf.unite(A[i], B[i])
    i -= 1


for i in ans:
    print(i)

Measured memory_bytes: 19316
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  ll n = in();
  ll m = in();
  vector<ll> c(n);
  REP(i, m){
    ll a = in();
    ll b = in();
    a--;
    b--;
    c[a]++;
    c[b]++;
  }

  REP(i, n){
    if(c[i] % 2 == 1){
      puts("NO");
      return 0;
    }
  }

  puts("YES");
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  char x,y;
  cin >> x >> y;
  int a,b;
  if(x=='A')a=1;
  if(x=='B')a=2;
  if(x=='C')a=3;
  if(x=='D')a=4;
  if(x=='E')a=5;
  if(x=='F')a=6;
  if(y=='A')b=1;
  if(y=='B')b=2;
  if(y=='C')b=3;
  if(y=='D')b=4;
  if(y=='E')b=5;
  if(y=='F')b=6;

  if(a>b)cout << '>';
  if(a<b)cout << '<';
  if(a==b)cout << '=';
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans = a * b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

signed main()
{
	char S[10];
	cin >> S;
	for (int i = 0; i < strlen(S) - 1; i++)
	{
		if (S[i] == 'A' && S[i + 1] == 'C')
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,ans=0;
int main(){
    ll n,k,x;
    cin>>n>>k;

    rep(i,k){
        cin>>a>>b;
        x=fminl(fminl(a,b),fminl(n+1-a,n+1-b));
        cout<<(x+2)%3+1<<endl;
    }
}


Measured memory_bytes: 3164
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define N 200000

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

    int sum = 0;
    for(int i=1;i<=a;++i){
        sum += i;
    }
    cout<<sum;
}

Measured memory_bytes: 256