akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N; cin >> N;
    vector<long long> B(N-1);
    for (int i = 0; i < N-1; ++i) cin >> B[i];

    long long res = B[0] + B.back();
    for (int i = 0; i + 1 < B.size(); ++i) {
        res += min(B[i], B[i+1]);
    }
    cout << res << endl;
}

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

int main() {
    int a, b;
    string s;
    cin >> a >> b >> s;
    for (int i = 0; i < a + b + 1; i++) {
        char ch = s[i];
        if (i == a && ch != '-') {
            puts("No");
            return 0;
        }
        if (i != a && !isdigit(ch)) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    
    int S,h,m,s;
    cin >> S; 
    h = S / 3600 ;
    m = S % 3600 / 60;
    s = S % 3600 % 60;
    cout << h << ":" << m << ":" << s << endl;

    return 0;
}

Measured memory_bytes: 1164
N=int(input())
a=list(map(int,input().split()))
s=sum(a)
if N==0:
    print(1 if a[0]==1 else -1)
    exit()
lim=1
ans=0
for i in range(N+1):
    ans+=lim
    if lim-a[i]<0:
        print(-1)
        exit()
    lim=(lim-a[i])*2
    s-=a[i]
    lim=min(lim,s)
print(ans)


Measured memory_bytes: 20164
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long Int;

priority_queue<Int, vector<Int>, greater<Int> > pq[108000], rest;
Int a[108000];
Int u[108000];
Int x, y;
Int n, m;
bool done[108000];
Int res;
void init(){
	for(int i = 0;i < 108000;i++)u[i] = i;
}

int r(int x){
	if(u[x] == x)return x;
	return u[x] = r(u[x]);
}

void unite(int x, int y){
	x = r(x);
	y = r(y);
	u[x] = y;
}

int main(){
	init();
	cin >> n >> m;
	int need = (n-1-m) * 2;
	if(need > n){
		cout << "Impossible" << endl;
		return 0;
	}
	if(need == 0){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	for(int i = 0;i < m;i++){
		cin >> x >> y;
		unite(x,y);
	}

	for(int i = 0;i < n;i++){
		pq[r(i)].push(a[i]);
	}

	for(int i = 0;i < n;i++){
		if(done[r(i)])continue;
		done[r(i)] = true;
		res += pq[r(i)].top();pq[r(i)].pop();
		while(!pq[r(i)].empty()){
			rest.push(pq[r(i)].top());
			pq[r(i)].pop();
		}
		need--;
	}
	while(need--){
		res += rest.top();rest.pop();
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 8056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>

int main() {
  string S,T;
  cin >> S >> T;

  cout << T << S << endl;

  return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC =[]

for i in range(M):
    BC.append(list(map(int,input().split())))

A.sort()
BC_sorted = sorted(BC, key=itemgetter(1), reverse=True)
# print(BC_sorted)

cur = 0

for i in range(M):
    if cur == N or A[cur]>= BC_sorted[i][1]:
        break
    for j in range(BC_sorted[i][0]):
        for k in range(cur, N):
            if A[k] < BC_sorted[i][1]:
                A[k] = BC_sorted[i][1]
                cur = k+1
                break
            elif A[k] > BC_sorted[i][1]:
                cur = k+1
                break
    # print(i, ':', A, 'cur:', cur)


print(sum(A))

Measured memory_bytes: 33744
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    ll x, a, b;
    cin >> x;
    int f = 0;
    for(ll i=8000; i>=-8000; i--){
        for(ll j=i; j>=-8000; j--){
            if(i*i*i*i*i - j*j*j*j*j == x){
                a = i;
                b = j;
                f = 1;
                break;
            }
        }
        if(f == 1) break;
    }
    cout << a << ' ' << b << endl;
    return 0;
}

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

int main(){
  int n; cin >> n;
  vector<long> a(n); rep(i,n) cin >> a[i];
  vector<vector<long>> ans(n+1,vector<long>(n+1,0));
  loop(i,1,n) loop(left,0,n-i){
    int right = i + left;
    ans[left][right] = max(a[left]-ans[left+1][right], a[right-1]-ans[left][right-1]);
  }
  cout << ans[0][n] << endl;
}

Measured memory_bytes: 73744
#include <algorithm>
#include <iostream>
#include <vector>

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

    std::string s;
    std::cin >> s;

    int k;
    std::cin >> k;
    k--;

    for (int i = 0; i < n; i++) {
        if (s[i] != s[k]) {
            s[i] = '*';
        }
    }

    std::cout << s << std::endl;
}


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

int main(void)
{
    int n, cnt=0, a;

    scanf("%d" ,&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d" ,&a);
        if(i%2==1 && a%2==1)
            cnt++;
    }

    printf("%d" ,cnt);

    return 0;
}


Measured memory_bytes: 3752
A,B,C = list(map(int,input().split()))
import sys
listA = " ".join(sys.stdin.readlines()).replace("\n","").split()
listA = list(map(int,listA))
m_n=0
N = 0
B = B-C
max_n=10**10
while max_n-m_n>1:
    N = 0
    mid=(m_n+max_n) //2
    for i in listA:
        N += (max(i-C*mid,0)-1) // B+1
    if N <= mid:
        max_n = mid
    else:
        m_n  = mid
print(max_n)

Measured memory_bytes: 14096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadInts();
            var ans = 10000;
            for (int i = 0; i < input[0]; i++)
            {
                var a = ReadInts();
                if (a[1] <= input[1]&&ans>a[0])
                {
                    ans = a[0];
                }
            }
            if (ans == 10000)
            {
                WriteLine("TLE");
            }
            else
            {
                WriteLine(ans);
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 11092
#!/usr/bin/env python3
def main():
    S = input()

    lst = set(['A', 'C', 'G', 'T'])
    cnt = 0
    ans = 0
    for s in S:
        if s in lst:
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){

    int N;
    cin >> N;
    vector<uint64_t> A(N);

    rep (i, N) cin >> A[i];
    sort(A.begin(), A.end());
    if (A[0] == 0){
        cout << 0 << endl;
        return 0;
    }
    reverse(A.begin(), A.end());

    uint64_t ans = 1;
    rep(i, N){
        if (ans <= 1000000000000000000/A[i]){
            ans *= A[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3984
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTravelingSalesmanAroundLake solver = new CTravelingSalesmanAroundLake();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTravelingSalesmanAroundLake {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            int n = in.nextInt();
            int[] a = new int[n];
            int max = -1;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            for (int i = 0; i < n - 1; i++) {
                max = Math.max(max, a[i + 1] - a[i]);
            }
            max = Math.max(max, k - (a[n - 1] - a[0]));
            out.println(k - max);


        }

    }
}



Measured memory_bytes: 78708
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+1
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

string S,T;
string dp[3001][3001];

string max(string A, string B, string C){
	if(A.size() >= B.size() && A.size() >= C.size()) return A;
	if(B.size() >= C.size()) return B;
	return C;
}

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

	cin >> S >> T;
    for(int i=0; i<=S.size(); i++) dp[i][T.size()] = "";
    for(int j=0; j<=T.size(); j++) dp[S.size()][j] = "";
    for(int i=S.size()-1; i>=0; i--){
        for(int j=T.size()-1; j>=0; j--){
            dp[i][j] = max(dp[i+1][j], dp[i][j+1], S[i]==T[j] ? S[i]+dp[i+1][j+1] : "");
        }
    }
    cout << dp[0][0] << endl;

	return 0;
}

Measured memory_bytes: 841600
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<fstream>
#include<stdio.h>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define PI  3.141592
//----------------------------------------

ll d = pow(10,9)+7;


long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


ll com[200005];

int main(void)
{

	ll n, a, b;

	cin >> n >> a >> b;

	n %= d;


	ll ans = 0;
	ans = modpow(2, n, d);
	ans --;

	
	com[1] = n;
	n %= d;

	for (ll i = 2; i <= b; i++)
	{
		ll div;
		div = modpow(i, d - 2, d);
		com[i] = com[i - 1] * (n - i + 1);
		com[i] %= d;
		com[i] *= div;
		com[i] %= d;
	}



	ll fans = ans - com[a] - com[b];

	fans %= d;

	if (fans < 0) fans = d + fans;
	cout << fans << endl;

}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

/**
 * 0-1 ナップザック問題
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=ja">DPL_1_B</a>
 */
public class Main {
	private static int n, w;
	private static int c[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		w = sc.nextInt();
		Item item[] = new Item[n + 1];
		c = new int[n + 1][w + 1];

		for (int i = 0; i < n; i++) {
			Arrays.fill(c[i], 0);
		}

		for (int i = 1; i < n + 1; i++) {
			item[i] = new Item();
			item[i].value = sc.nextInt();
			item[i].weight = sc.nextInt();
		}

		knapsackProblem01(item);

		System.out.println(c[n][w]);

		sc.close();
	}

	private static void knapsackProblem01(Item item[]) {
		for (int i = 1; i < n + 1; i++) {
			for (int j = 1; j < w + 1; j++) {
				if (0 <= j - item[i].weight) {
					c[i][j] = Math.max(c[i - 1][j], c[i - 1][j - item[i].weight] + item[i].value);
				} else {
					c[i][j] = c[i - 1][j];
				}
			}
		}
	}

}

class Item {
	int value, weight;
}


Measured memory_bytes: 31048
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l;
  cin >> n >> l;
  int realsum;
  for(int i=1; i<=n; i++){
    realsum += l + i - 1;
  }
  int min = abs(l); 
  int a = l;
  for(int i=1; i<=n; i++){
    
    if(min > abs(l + i - 1)) {
      min = abs(l + i - 1);
      a = l + i - 1;
    }
    
  }
  cout << realsum - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, a[200];
	cin>>n;
	for (int i=0; i<n;i++) cin>>a[i];
	sort(a,a+n);
	double s=0; 
	for (int i=n-1;i>=0;i--) 
		s+=1.0L/a[i];
	s=1/s;
	printf("%.8lf\n", s);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int price = Integer.MAX_VALUE;
    for (int i = 0; i <= 100000; i++) {
      int tmp = 2 * C * i;
      if (X > i) {
        tmp += A * (X - i);
      }
      if (Y > i) {
        tmp += B * (Y - i);
      }
      if (tmp < price) {
        price = tmp;
      }
    }
    System.out.println(price);
  }
}

Measured memory_bytes: 21844
N,x = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
ans += max(0,A[0]-x)
A[0] -= max(0,A[0]-x)
for i in range(N-1) :
    ans += max(0,A[i]+A[i+1]-x)
    A[i+1] -= max(0,A[i]+A[i+1]-x)
print(ans)


Measured memory_bytes: 14052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,W;
	cin>>n>>W;
	ll dp[1001*n+2];int wi,vi;
	const ll inf=9999999999999;
	fill(dp, dp+1001*n+2, inf);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		cin>>wi>>vi;
		for(ll val=1000*n;val>=vi;val--)
		{
			dp[val]=min(dp[val-vi]+wi, dp[val]);
			//cout<<dp[val]<<"\n";
		}
	}
	ll a=-1;
	for(int i=1000*n;~i;i--)
	if(dp[i]<=W){cout<<i;break;}
}

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

typedef vector <int> VI;
typedef vector <VI> VVI;

int time_to_minutes( int n )
{
	int minutes = n % 100;
	n /= 100;
	minutes += ( n % 100 ) * 60;
	return minutes;
}

int main( void )
{
	int n, p, q;
	while ( cin >> n >> p >> q && n && p && q )
	{
		int most_left = time_to_minutes( p );
		int most_right = time_to_minutes( q );
		VVI time_table( n, VI( most_right-most_left+1, 0 ) );

		for ( int i = 0; i < n; i++ )
		{
			int k; cin >> k;
			for ( int j = 0; j < k; j++ )
			{
				int a, b; cin >> a >> b;
				int left = time_to_minutes( a );
				int right = time_to_minutes( b );
				for ( int k = left - most_left; k < right - most_left; k++ ) time_table[i][k] = 1;
			}
		}


		int answer = 0;
		int cnt = 0;
		for ( int i = 0; i < most_right-most_left; i++ )
		{
			bool not_found = true;
			for ( int j = 0; not_found && j < n; j++ )
			{
				if ( time_table[j][i] == 0 ) not_found = false;
			}
			if ( not_found == false )
			{
				cnt++;
				answer = max( answer, cnt );
			}
			else
			{
				cnt = 0;
			}
		}

		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N,K=map(int,input().split())
kouho=[i for i in range(1,N+1)]
kari=[]
count = 0
j=0
while j<len(kouho):
    if kouho[j]<K:
        count+=1
        kouho[j]*=2
    else:
        kari.append(((1/2)**count)*1/N)
        j+=1
        count=0
print(sum(kari))


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

int h,w,k;
char a[10][10];
int ans = 0; //count answer

void func(int r, int c)
{
	//first loop row, second loop column
	//r, c = current row, current column
	if(r<h) //r<h => looking at a row r
	{
		//process row
		//choose not paint
		func(r+1,c); 
		//choose paint
		char original[10]; //store the original colors of row r
		for(int i=0;i<w;i++) //paint the row
		{
			original[i] = a[r][i];
			a[r][i]='R'; //R = red
		}
		func(r+1,c);
		for(int i=0;i<w;i++) //return to original color (unpaint)
		{
			a[r][i] = original[i];
		}
	}
	else //r>=h => rows finish processing
	{
		if(c<w) //c<w => looking at column c
		{
			func(r,c+1);
			char original[10]; //store the original colors of row r
			for(int i=0;i<h;i++) //paint the row
			{
				original[i] = a[i][c];
				a[i][c]='R'; //R = red
			}
			func(r,c+1);
			for(int i=0;i<h;i++) //return to original color (unpaint)
			{
				a[i][c] = original[i];
			}
		}
		else //processed everything, update answer
		{
			//count number of black squares
			int cnt = 0;
			for(int i=0;i<h;i++)
			{
				for(int j=0;j<w;j++)
				{
					if(a[i][j]=='#') cnt++;
				}
			}
			if(cnt==k) ans++; //found valid way
		}
	}
}

int main()
{
	cin>>h>>w>>k;
	//read input
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>a[i][j];
		}
	}
	//recursive call
	func(0,0); //start from 0th row, 0th column
	cout<<ans<<'\n';
}	


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;
const llong INF = 1ll << 60ll;

llong N, A, B, C;
llong len[10];

llong dfs(llong i, llong a, llong b, llong c, llong cost) {
    if (i == N) {
        if (a && b && c)
            return cost + labs(A - a) + labs(B - b) + labs(C - c);
        else
            return INF;
    }

    llong v1, v2, v3, v4;

    if (!a) v1 = dfs(i + 1, len[i], b, c, cost);
    else v1 = dfs(i + 1, a + len[i], b, c, cost + 10);

    if (!b) v2 = dfs(i + 1, a, len[i], c, cost);
    else v2 = dfs(i + 1, a, b + len[i], c, cost + 10);

    if (!c) v3 = dfs(i + 1, a, b, len[i], cost);
    else v3 = dfs(i + 1, a, b, c + len[i], cost + 10);

    v4 = dfs(i + 1, a, b, c, cost);

    return min({v1, v2, v3, v4});
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) cin >> len[i];

    cout << dfs(0, 0, 0, 0, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int c(int a)
{
	if(a<400)return 0;
	else if(a<800)return 1;
	else if(a<1200)return 2;
	else if(a<1600)return 3;
	else if(a<2000)return 4;
	else if(a<2400)return 5;
	else if(a<2800)return 6;
	else if(a<3200)return 7;
	else return 8;
}
main()
{
	int n;cin>>n;
	int cnt[9]={};
	for(int i=0;i<n;i++)
	{
		int a;cin>>a;
		cnt[c(a)]++;
	}
	int ans=0;
	for(int i=0;i<8;i++)
	{
		ans+=!!cnt[i];
	}
	int nans=ans;
	if(cnt[8]&&ans==0)ans=1;
	cout<<ans<<" "<<(nans+cnt[8])<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int b = 0;
        long ans = 0;
        for(char c : s){
            if(c == 'B'){
                b++;
            }else{
                ans += b;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25892
import math
from itertools import combinations

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

X = []
for i in range (N):
    X.append([int(num) for num in input().split()])
    
combination = list(combinations(X, 2))

count = 0;
for combi in combination:
    row_combi = list(zip(*combi))
    
    num = 0
    for row in row_combi:
        num += abs(row[0] - row[1]) ** 2
        
    if (math.sqrt(num).is_integer()):
        count += 1
        
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000007;
ll INF=1e18;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

void solve()
{
     ll n;
     cin>>n;
     vector<ll> v(n+1);
     ll i;
     ll s=0;
     for(i=1;i<=n;i++)
     {
          cin>>v[i];
          s=(s%mod+v[i]%mod)%mod;
     }
     ll ans =0;
     for(i=1;i<=n;i++)
     {
          s=(s%mod - v[i]%mod + mod)%mod;
          ans = (ans%mod + ((s%mod)*(v[i]%mod))%mod)%mod;
     }
     cout<<ans;
}

     
     


int main()
{
    ios;
    ll t;
//    cin>>t;
     t=1;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 4760
import java.util.*;
 
public class Main {
  public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long k = sc.nextLong();
      long[] box = new long[100010];
      for (int i = 0; i < n; i++) {
         int a  = sc.nextInt();
         int b = sc.nextInt();
         box[a] += b;
      }
      
      for(int i = 0; i < 100010; i++) {
             k -= box[i];
             if(k <= 0) {
                   System.out.println(i);
                   return;
             }
      }
  }
}

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

int main() {
    // エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    // 2017-like 数かどうか
    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    // 累積和
    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

    // クエリ処理
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
}

Measured memory_bytes: 4476
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] NM = Console.ReadLine().Split(' ');
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);
            List<int> H = new List<int>();
            String[] strH = Console.ReadLine().Split(' ');
            foreach(String inH in strH){
                H.Add(int.Parse(inH));
            }

            List<bool> isGoodObs = Enumerable.Repeat(true, N).ToList();
            for(int i=0; i<M; i++){
                String[] strLoad = Console.ReadLine().Split(' ');
                int A = int.Parse(strLoad[0])-1;
                int B = int.Parse(strLoad[1])-1;
                if(H[A] <= H[B]) isGoodObs[A] = false;
                if(H[A] >= H[B]) isGoodObs[B] = false;
            }
            Console.WriteLine(isGoodObs.Count(isGood => isGood == true));
        }
    }
}


Measured memory_bytes: 49536
#一文字ずつ区切る
chars = list(input())
#文字列で入っているぽい[internationalization]
#len(chars)で文字の長さを数える
#最初の文字と真ん中の数と最後の文字を出力させる
#strでInt型をStringに変換する
print(chars[0]+str(len(chars)-2)+chars[len(chars)-1])


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

int main(){
    int n, sum = 0;
    cin >> n;
    vector<int> p(n, 0);
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }

    sort(p.begin(), p.end(), greater<int>());
    sum += p[0] / 2;

    for (int i = 1; i < n; i++){
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
while true
  n = gets.to_i
  break if n==0

  s = 2*n
  x = 2  
  ptn = 0
  while x<=n
    if s%x == 0
      y = s/x
      l2 = y-x+1
      ptn += 1 if l2>0 && l2%2==0
    end
    x += 1
  end

  puts ptn
end

Measured memory_bytes: 8472
N = int(input())
S = [input() for i in range(N)]
S_march = []
MARCH = ["M", "A", "R", "C", "H"]

cmb = []
ans = 0

N_march = [0]*5

for Si in S:
  for j in range(5):
    if Si[:1] == MARCH[j]:
      N_march[j] += 1

for i in range(2**5):
  check = [False]*5
  for j in range(5):
    if (i>>j) & 1:
      check[j] = True
  if check.count(True) == 3:
    cmb.append(check)

for i in cmb:
  tmp_list = []
  for j in range(5):
    if i[j]:
      tmp_list.append(N_march[j])
  ans += tmp_list[0]*tmp_list[1]*tmp_list[2]
  
print(ans)
      
      
#for i in range(2*N):
#  for j in range(N):
#    if (i>>j) & 1:
#      if S[j][:1] in MARCH:
#        check[j] = True
#        MARCH.pop(S[j][:1])
#  if check.count(True) == 3:
#    ans += 1
#print(ans)

Measured memory_bytes: 9772
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N, long long Z, long long W, std::vector<long long> a){
	int res = abs(W - a.back());
	if (N > 1) {
		res = max(res, abs(a.back() - a[N - 2]));
	}
	cout << res << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long Z;
    scanf("%lld",&Z);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, Z, W, std::move(a));
    return 0;
}


Measured memory_bytes: 256
/// 11:57 AM 02/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll k,a,b;;
    cin>>k>>a>>b;
    for(ll i=a;i<=b;i++) {
        if(i%k==0) {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



Measured memory_bytes: 3652
import java.io.*;

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

		String[] line = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);

		int d = a / b;
		int r = a % b;
		String f = String.format("%.5f", ((double)a / (double)b));

		System.out.println(d + " " + r + " " + f);
	}
}

Measured memory_bytes: 24704
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define jloop(n) for(int j=0; j<(n); j++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
const ll N = 2e5+9;
const ll INF = 2e17+423;
const ll mod = /*1e9+7;*/ 998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
#define endl '\n'
ll po(ll,ll);













int main(){
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  #endif // ONLINE_JUDGE*/
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  string s[n]; int t[n];
  loop(n){
    cin >> s[i] >> t[i];
  } string x; cin >> x; int id;
  loop(n) if(s[i] == x){
    id = i;
    B;
  } int ans = 0;
  for(int i = id+1; i<n; i++) ans+=t[i];
  cout << ans << endl;
  R 0;
}
/*

*/























ll po(ll x, ll n){
  if(n==0) R 1%mod;
  ll y = po(x, n/2);
  y = ((y%mod)*(y%mod))%mod;
  if(n%2) y = (y*(x%mod))%mod;
  R y;
}


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

int main(){
    string s;
    cin>>s;
    vector<char>mihon1(s.size());
    vector<char>mihon2(s.size());
    int now=0;
    for(int i=0;i<s.size();i++){
        if(now==0){
            mihon1[i]='0';
            mihon2[i]='1';
            now+=1;
        }
        else{
            mihon1[i]='1';
            mihon2[i]='0';
            now-=1;
        }
    }
    int one=0; int two=0;
    rep(i,s.size()){
        if(s[i]!=mihon1[i]) one+=1;
        else if(s[i]!=mihon2[i])two+=1;
    }
    cout<<min(one,two)<<endl;
}

    



Measured memory_bytes: 512
N = int(input())
A = [a for a in map(int, input().split())]
R = {}
for i in range(1,N+1):
    R[i] = A[i-1]

R_sorted = sorted(R.items(), key=lambda x: x[1])

Ans = ""
for a in R_sorted:
    Ans = Ans + "{0} ".format(str(a[0]))

print(Ans)




Measured memory_bytes: 26176
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
template<typename T>
bool chmin(T &a,T b){
    if(b<a){
        a=b;
        return true;
    }
    return false;
}
int main(){
    string s;cin>>s;
    int ans=1e9;
    s.insert(s.begin(),'0');
    int dp[1000010][10][2][2];
    REP(i,s.size()+1) REP(j,10) REP(k,2) REP(l,2) dp[i][j][k][l]=1e9;
    dp[s.size()][0][0][1]=0;
    for(int i=s.size()-1;i>=0;--i) {
        int num=s[i]-'0';
        REP(j,10)  REP(k,2) REP(l,2){
            int b1=j-k<num,b2=!(j<num||(l==0&&j<=num)),pl=j-k-num+10;
            if(pl>=10) pl-=10;
            REP(c,10) chmin(dp[i][j][b1][b2],dp[i+1][c][k][l]+j+pl);
        }
    }
    REP(j,10) REP(k,2) {
        chmin(ans,dp[0][j][k][1]);
    }
    cout<<ans<<endl;
}

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

int main(){
  // 入力
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  	cin >> vec.at(i);
  
  int counter = 0;
  bool all_even_flag = true;
  
 
  while(all_even_flag){
    //全て偶数かチェック
    for(int num: vec){
      if(num % 2 != 0){
        all_even_flag = false;
        break;
      }
    }
    
    //全て偶数でなければ脱出
    if(all_even_flag == false)
      break;
    
    //全て偶数なら2で割る操作
    for(int i = 0; i < N; i++)
      vec.at(i) /= 2;
    counter++;
  }
  cout << counter << endl;
}

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

using namespace std;

const int N = 2e5 + 5, mod = 1e9 + 7;

long long powmod(long long b, long long p) {
  long long r = 1;
  for (; p; p >>= 1, b = b * b % mod)
    if (p & 1)
      r = r * b % mod;
  return r;
}

long long fac[N], inv[N];

long long C(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  assert(n < N);
  return  (1LL * fac[n] * inv[k] % mod) * inv[n-k] % mod;
}

long long invers(long long b, long long p = 1) {
  return powmod(b, mod - 1 - p);
}

int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = 1LL * fac[i-1] * i % mod;
    inv[i] = invers(fac[i]);
  }
  int b, w;
  scanf("%d %d", &b, &w);
  long long sum = 0, cnt = 1, last = 0;;
  for (int i = 0; i < b + w; ++i) {
    int left = i, right = b + w - i - 1;
    if (left >= w) {
      cnt -= C(left-1, w-1);
    }
    if (right < w) {
      int mi = w - right - 1;
      cnt -= C(left-1, mi);
    }
    cnt %= mod;
    if (cnt < 0) cnt += mod;
    if (right == 0)
      cnt = 0;
    long long ans = invers(2, left + 1) * cnt % mod;
    if (left >= w) {
      sum = (sum + 1LL * invers(2, left) * C(left-1, w-1)) % mod;
    }
    ans = (ans + sum) % mod;
    if (ans < 0)
      ans += mod;
    printf("%lld\n", ans);
    cnt = (2LL * cnt) % mod;
  }
  return 0;
}

Measured memory_bytes: 5376
def calc(blue, red):
	lst = []
	
	for ch in blue:
		if ch in red:
			lst.append(blue[ch] - red[ch])
		else:
			lst.append(blue[ch])

	return max(lst)


def main():
	N = int(input())
	blue = {}

	for _ in range(N):
		ch = input()
		if ch in blue:
			blue[ch] += 1
		else:
			blue[ch] = 1

	M = int(input())
	red = {}

	for _ in range(M):
		ch = input()
		if ch in red:
			red[ch] += 1
		else:
			red[ch] = 1

	value = calc(blue, red)

	if value >= 0:
		print(value)
	else:
		print(0)	

  
if __name__ == "__main__":
  	main()

Measured memory_bytes: 9120
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, m;
  rd(n, m);
  import std.math : sqrt;

  if (n == 1) {
    writeln(m);
    return;
  }
  for (long k = 6 * 10L ^^ 8; k >= 1; k--) {
    if (m >= k * n && (m - k * n) % k == 0) {
      writeln(k);
      return;
    }
  }

  import std.exception : enforce;

  enforce(false);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 200010
#define top 1000000000
#define ld long double
#define pi acos(-1)
#define x1 xx1
#define y1 yy1
#define x2 xx2
#define y2 yy2
using namespace std;

struct tt{int l, r, mx;}t[7000010];
struct aa{int x, y;}a[N], b[N];
int x1, x2, y1, y2, n, l, f[N], l1, sum, ff;
ld ans;

inline bool cmp(aa a, aa b){return a.x<b.x;}
inline bool cmp1(aa a, aa b){return a.y<b.y;}

inline void ins(int i, int x, int y, int L, int R){
	t[i].mx=max(t[i].mx, y); if(L==R)return;
	int mid=(L+R)>>1;
	if(x<=mid){
		if(!t[i].l){l++; t[l].l=t[l].r=t[l].mx=0; t[i].l=l;}
		ins(t[i].l, x, y, L, mid);
	}else{
		if(!t[i].r){l++; t[l].l=t[l].r=t[l].mx=0; t[i].r=l;}
		ins(t[i].r, x, y, mid+1, R);
	}
	t[i].mx=max(t[t[i].l].mx, t[t[i].r].mx);
}
inline int cmx(int i, int a, int b, int L, int R){
	if(!i)return 0;
	if(a<=L&&R<=b)return t[i].mx;
	int mid=(L+R)>>1, mx=0;
	if(a<=mid)mx=max(mx, cmx(t[i].l, a, b, L, mid));
	if(mid<b)mx=max(mx, cmx(t[i].r, a, b, mid+1, R));
	return mx;
}

int main(){
	scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
	if(x1>x2){swap(x1, x2); swap(y1, y2);}
	for(int i=1; i<=n; i++)scanf("%d%d", &b[i].x, &b[i].y);
	if(y1>y2){
		y1=top-y1; y2=top-y2;
		for(int i=1; i<=n; i++)b[i].y=top-b[i].y;
	}
	l=0; for(int i=1; i<=n; i++)if(x1<=b[i].x&&b[i].x<=x2&&y1<=b[i].y&&b[i].y<=y2)a[++l]=b[i];
	sort(a+1, a+1+l, cmp); l1=l;
	l=1; t[1].l=t[1].r=t[1].mx=t[0].mx=0;
	for(int i=l1; i; i--){
		f[i]=cmx(1, a[i].y, top, 0, top)+1;
		ins(1, a[i].y, f[i], 0, top);
	}
	sum=0; for(int i=1; i<=l1; i++)sum=max(sum, f[i]);
	ans=(ld)100.0*(x2-x1+y2-y1); ans-=(ld)1.0*sum*(20-5*pi);
	if(a[1].x==x1&&a[l1].x==x2){
		ff=1;
		for(int i=2; i<=l1; i++)if(a[i-1].x+1<a[i].x||a[i-1].y>a[i].y){ff=0; break;}
		if(ff)ans+=5*pi;
	}
	sort(a+1, a+1+l1, cmp1);
	if(a[1].y==y1&&a[l1].y==y2){
		ff=1;
		for(int i=2; i<=l1; i++)if(a[i-1].y+1<a[i].y||a[i-1].x>a[i].x){ff=0; break;}
		if(ff)ans+=5*pi;
	}
	printf("%.15Lf", ans);
	return 0;
}

Measured memory_bytes: 28800
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

void bfs(int node);
vector< vector<int> > Adj(100, vector<int>(100));
vector<int> dist(100, -1);
int n;

int main() {

    // input
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v; v--;
            Adj[i].push_back(v);
        }
    }

    dist[0] = 0;
    bfs(0);

    for (int i = 0; i < n; i++) {
        cout << i + 1 << ' ' << dist[i] << '\n';
    }

}

void bfs(int node) {

    queue<int> q;
    q.push(node);

    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (auto v : Adj[cur]) {
            // visited
            if (dist[v] != -1) {
                continue;
            }
            // not visited
            else {
                dist[v] = dist[cur] + 1;
                q.push(v);
            }
        }
    }

}



Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define M 1000000007
typedef long long LL;
//#define int long long

/*
//booooooooooooost
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/

int inv_mod(int a, int m)
{
	int b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}



signed main() {


	int N;
	cin >> N;
	cout << N * (N + 1) / 2 << endl;

	return 0;
}

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

int main(){
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a.at(i);
	}
	
	int res = 0;
	
	while(true){
		bool e_odd = false;
		for(int i = 0; i < n; ++i){
			if(a.at(i) % 2 != 0){
				e_odd = true;
			}
		}
		
		if(e_odd) break;
		
		for(int i = 0; i < n; ++i){
			a.at(i) /= 2;
		}
		++res;
	}
	
	cout << res << endl;
	
	return 0;
}
		
		

Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())

tmp = 0
ans_A = 0
ans_B = 0
for a in range(31):
    for b in range(31):
        x = 100 * (a * A + b * B)
        if x > F:
            break
        for c in range((x // 100 * E) // C + 1):
            for d in range(((x // 100 * E) - c) // D + 1):
                y = c * C + d * D
                if x + y > F or y > x * E // 100:
                    break
                if x + y != 0:
                    if y / (x + y) > tmp:
                        ans_A = x + y
                        ans_B = y
                        tmp = y / (x + y)

if ans_A == 0:
    print(100 * A, 0)
else:
    print(ans_A, ans_B)


Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn replace(n: i64, k: i64) -> i64 {
    (n-k).abs()
}
fn main() {
    let input = read_vec::<i64>();
    let mut n = input[0];
    let k = input[1];

    n %= k;

    loop {
        let temp = replace(n, k);
        if temp < n {
            n = temp;
        } else {
            break;
        }
    }

    println!("{}", n);

}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

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

// Segment Tree {{{
template <typename T>
class SegTree {
 private:
    int _n;
    T _init_val;
    std::vector<T> _data;
    std::function<T(T, T)> _f;

    T _query(int a, int b, int k, int l, int r) {
        // [a b)と[l r]が交差しない
        if (r <= a || b <= l) return _init_val;

        // [a b)が[l r]を含む
        if (a <= l && r <= b) return _data[k];

        T vl = _query(a, b, k*2+1, l, (l+r)/2);
        T vr = _query(a, b, k*2+2, (l+r)/2, r);

        return _f(vl, vr);
    }

 public:
    SegTree(int n, T init_val, std::function<T(T, T)> f) {
        _init_val = init_val;
        _n = 1;
        _f = f;

        while (_n < n)
            _n *= 2;
        _data.resize(2 * _n, init_val);
    }

    T get(int k) {
        return _data[k + _n - 1];
    }

    void update(int k, T a) {
        k += _n-1;
        _data[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            _data[k] = _f(_data[k*2+1], _data[k*2+2]);
        }
    }

    // [a b)の範囲でfを適用
    T query(int a, int b) {
        return _query(a, b, 0, 0, _n);
    }

    // 先頭からチェックし，はじめてxを満たしたインデックス
    int lower_bound(T x) {
        return _lower_bound(x, 0);
    }

    int _lower_bound(T x, int k) {
        if (k >= _n-1) {
            return k - (_n - 1);  // 葉
        } else if (_data[k] < x) {
            return _n;  // 該当なし
        } else if (x <= _data[k * 2 + 1]) {
            return _lower_bound(x, k * 2 + 1);
        } else {
            return _lower_bound(x - _data[k * 2 + 1] , k * 2 + 2);
        }
    }
};
// }}}

SegTree<ll> st(400000, 0, [](const ll x, const ll y) { return max(x, y); });
vector<ll> xs[400000]; // xs[y]: あるyに属するxの集まり

void solve() {
  ll Y, X, M;
  cin >> Y >> X >> M;
  rep(_, M) {
    ll y, x;
    cin >> y >> x;
    xs[y].push_back(x);
    st.update(x, st.get(x) + 1);
  }
  ll ans = 0;
  rep(y, 400000) {
    ll t = xs[y].size() + st.query(0, 400000);
    for (auto x : xs[y]) {
      st.update(x, st.get(x) + 1);
    }
    if (y+1 < 400000) {
      for (auto x: xs[y+1]) {
        st.update(x, st.get(x) - 1);
      }
    }
    chmax(ans, t);
  }
  cout << ans << endl;
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 30096
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

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

    int ans = INF;
    int t = 0;
    for (int i = 0; i < N; i++) {
        t += W[i];
        ans = min(ans, abs(t - (s - t)));
    }

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


Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n,k;
  cin >> n >> k;
  int rem = n%k;
  int ans = min(rem,k-rem);
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    char C;
    while(scanf("%c",&C)==1){
        if('A'<=C && C<='Z'){
            printf("%c",C+32);
        }
        else if('a'<=C && C<='z'){
            printf("%c",C-32);
        }
        else{
            printf("%c",C);
        }
    }
    return 0;
}


Measured memory_bytes: 2052
#include<iostream>
using namespace std;
int main(){
    int n,a,t;
    cin>>n>>t>>a;
    int h;
    int ans,tmp1=2e9;
    for(int i=1;i<=n;i++){
        cin>>h;
        int d=(t*1000-h*6)-a*1000;
        if(d<0)d=-d;
        if(tmp1>d){
            tmp1=d;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
X,N=map(int,input().split())
d=[0]*201
P=list(map(int,input().split()))
for p in P:
    d[p]=1
a=X
for i in range(101):
    if d[X-i]==0:
        a=X-i
        break
    elif d[X+i]==0:
        a=X+i
        break
print(a)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    int n;
    cin >> n;
    int ans = (n + 1) / 2;
    cout << ans << endl;

    return 0;
}



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

string a;
int q,t,f,x;
char c;
deque <char> dq;

int main()
{
	cin>>a;
	for(int i=0;i<a.size();i++)
		dq.push_back(a[i]);

	cin>>q;
	while(q--)
	{
		cin>>t;
		if(t==2)
		{
			cin>>f>>c;
			f--;
			if((x^f)==1) dq.push_back(c);
			else dq.push_front(c);
		}
		else x^=1;
	}

	if(x)
		while(not dq.empty()) cout<<dq.back(),dq.pop_back();
	else
		while(not dq.empty()) cout<<dq.front(),dq.pop_front();
}

Measured memory_bytes: 4024