akhauriyash/Code-Regression huggingface dataset:
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: &Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<usize>();
    let mut D = Vec::new();
    for n in 0..N {
        let d = read::<i32>();
        D.push(d);
    }
    D.sort();
    let mut diff = 1;
    for i in 1..N {
        if D[i-1] != D[i] {
            diff += 1;
        }
    }
    println!("{}", diff);
}


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

int main(){
 int n;
 long long a;
 long long minValue = 1000000;
 long long maxValue = -1000000;
 long long sum = 0;

 cin >> n;

 for ( int i = 0; i < n; i++ ){
  cin >> a;
  if ( a < minValue ) minValue = a;
  if ( a > maxValue ) maxValue = a;
  sum += a;
 }

 cout << minValue << " " << maxValue << " " << sum << endl;
 return 0;
}

Measured memory_bytes: 3092
#include <iostream>
using namespace std;
 
#define MAX_W 100
#define MAX_H 100
char farm[MAX_W][MAX_H];
int W, H;
const int direction[4][2] = {
	{ -1, 0 },
	{ 1, 0 },
	{ 0, -1 },
	{ 0, 1 },
};
 
void dfs(const int& x, const int& y, const char tree)
{
	farm[x][y] = 'x';
	for (int i = 0; i < 4; ++i)
	{
		int nx = x + direction[i][0];
		int ny = y + direction[i][1];
		if (nx >= 0 && nx < W && ny >= 0 && ny < H && farm[nx][ny] == tree)
		{
			dfs(nx, ny, tree);
		}
	}
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	while (cin >> H >> W, W > 0)
	{
		int res = 0;
		int x, y;
		for (y = 0; y < H; ++y)
		{
			for (x = 0; x < W; ++x)
			{
				cin >> farm[x][y];
			}
		}
 
		for (y = 0; y < H; ++y)
		{
			for (x = 0; x < W; ++x)
			{
				if (farm[x][y] != 'x')
				{
					dfs(x, y, farm[x][y]);
					++res;
				}
			}
		}
		cout << res << endl;
	}
 
	return 0;
}


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

int main(int argc, char *argv[])
{
	int t;
	int a1, a2, a3;

	int result;

	cin >> a1 >> a2 >> a3;

	if (a1 > a2) {
		t = a1;
		a1 = a2;
		a2 = t;
	}

    if (a1 > a3) {
		t = a1;
		a1 = a3;
		a3 = t;
	}

	if (a2 > a3) {
		t = a2;
		a2 = a3;
		a3 = t;
	}

	result = (a3 - a2) + (a2 - a1);
   
	cout << result << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<int> line(3, 0);
	vector<vector<int> > vec(3, line);
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			cin>>vec[i][j];
		}
	}
	for(int i = 0; i <= 100; ++i){
		for(int j = 0; j <= 100; j++){
			for(int k = 0; k <= 100; ++k){
				vector<int> v(3, 0);
				v[0] = i;
				v[1] = j;
				v[2] = k;
				vector<int> w(3, 0);
				for(int am = 0; am < 3; ++am){
					for(int pm = 0; pm < 3; ++pm){
						w[pm] = vec[am][pm] - v[am];
					}	
					bool ok = true;
					for(int ci = 0; ci < 3; ++ci){
						for(int cj = 0; cj < 3; ++cj){
							if(vec[ci][cj] != v[ci] + w[cj]){
								ok = false;
							}
						}
					}
					if(ok){
						cout<<"Yes"<<endl;
						return 0;
					}
				}
			} 
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 2005
using namespace std;
int n,k;
long long c[maxn][maxn];
long long da=1000000000+7;

void getc(){
    for(int i=0;i<=n;i++){
        c[i][i]=1;
        c[i][1]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++)
            if(c[i][j]==0) c[i][j]=(c[i-1][j]%da+c[i-1][j-1]%da)%da;
    }
}

int main(int argc, const char * argv[]) {
    //ios::sync_with_stdio(false);
    cin>>n>>k;
    cout<<n-k+1<<endl;
    getc();
    for(int i=2;i<=k;i++){
        long long ans= c[n-k+1][i] * c[k-1][i-1] % da;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 30208
#include<stdio.h>
#include<math.h>
int main(void) {
  long N,K,ans;
  scanf("%ld %ld",&N,&K);
  ans=((N-N%K)/K)*((N-N%K)/K)*((N-N%K)/K);
  if(K%2==0) {
    ans+=(((N-N%(K/2))/(K/2)+((N-N%(K/2))/(K/2))%2)/2)*(((N-N%(K/2))/(K/2)+((N-N%(K/2))/(K/2))%2)/2)*(((N-N%(K/2))/(K/2)+((N-N%(K/2))/(K/2))%2)/2);
  }
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
  #define FASTIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  using namespace std;
  #define endl '\n'
  #define deb cout<<"sab_badhiya"<<endl;
  typedef long long int ll;
  // const long long INF = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
  const long INF = 1000 * 1000 * 1000 + 7;
  vector<int>v[30000];
  int d[3000];
  map<int, int>mp;
  int main() {
    int n, x, y, s;
    cin >> n >> x >> y;
    for (int i = 1; i < n; i++) {
      v[i].push_back(i + 1);
      v[i + 1].push_back(i);
    }
    v[x].push_back(y);
    v[y].push_back(x);
    queue<pair<int, int>>q;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        d[j] = 1e9;
      }
      d[i] = 0;
      q.push({i, 0});
      while(!q.empty()) {
        x = q.front().first;
        y = q.front().second;
        q.pop();
        for (auto it : v[x]) {
          if (d[it] > d[x] + 1) {
            q.push({it, d[x] + 1});
            d[it] = d[x] + 1;
          }
        }
      }
      for (int i = 1; i <= n; i++) {
        mp[d[i]]++;
      }
    }
    for (int i = 0; i <= n - 1; i++) {
      mp[i]++;
    }
    for (auto it : mp) {
      if (it.first == 0) {
        continue;
      }
      cout << (it.second - 1) / 2 << endl;
    }
  }


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

#define ll long long
#define pb push_back

using namespace std;

int vis[200005];
int freq[200005];
vector<int> arr[200005];
int k;

void dfs(int i){
    vis[i] = 1;
  	freq[k]++;
    for(int e : arr[i]){
        if(!vis[e]) dfs(e);
    }
}

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

    int n, m, a, b;
    cin >> n >> m;

    while(m--){
        cin >> a >> b;

        arr[a].pb(b);
        arr[b].pb(a);
    }

    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            dfs(i);
            k++;
        }
    }

  	int mx = 0;
    for(int i = 0; i < k; i++) mx = max(mx, freq[i]);
  
  	cout << mx;

    return 0;
}


Measured memory_bytes: 21560
def main():
  from collections import deque
  n,m=map(int,input().split())
  g=[[] for _ in range(n)]
  for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1;
    g[a].append((b,i))
    g[b].append((a,i))
  
  bfs=deque([])
  def check(j):
    res=1
    used=[False]*n
    used[0]=True
    bfs.append(0)
    while bfs:
      cur=bfs.popleft()
      for to,num in g[cur]:
        if num!=j and not used[to]:
          used[to]=True
          res+=1
          bfs.append(to)
    return res!=n
  
  ans=0
  for i in range(m):
    if check(i):
      ans+=1
  
  print(ans)
  
if __name__=='__main__':
  main()


Measured memory_bytes: 70100
n, x = gets.split.map(&:to_i)
want_candy = gets.split.map(&:to_i).first(n)
cnt = 0

want_candy.sort.each.with_index(1) do |wc, i|
  break if wc > x
  x -= wc
  break if i == n && !x.zero?
  cnt += 1
end

puts cnt


Measured memory_bytes: 1788
N=int(input())
X=input()
num_X = int(X, base=2)
pop_x = X.count("1")
if pop_x <= 1:
    mod0 = pop_x + 1
    res0 = num_X % mod0
else:
    mod1 = pop_x - 1
    mod0 = pop_x + 1
    res1 = num_X % (mod1)
    res0 = num_X % (mod0)

# pops = [0]*(N+20)
for i in range(N):
    tmp = 0
    if X[i] == "0":
        # +
        tmp = (res0 + pow(2, N-i-1, mod0))%mod0
    else:
        if pop_x == 1:
            print(0)
            continue
        tmp = (res1 - pow(2, N-i-1, mod1))%mod1
    
    if tmp == 0:
        print(1)
        continue
    cnt = 1
    while tmp != 0:
        pop = bin(tmp).count("1")
        tmp %= pop
        cnt += 1
    print(cnt)

Measured memory_bytes: 82148
#include <stdio.h>
int a[200010];
int main() {
    int n, i, x;
    scanf("%d", &n);
    for (i = 1; i < n; i++) {
        scanf("%d", &x);
        a[x]++;
    }
    for (i = 1; i <= n; i++) printf("%d\n", a[i]);
    return 0;
}


Measured memory_bytes: 2464
#coding: shift_jis


N = int(raw_input())
S = raw_input()
x = 0
y = [x]
for i in range(N):
    if S[i] == 'I':
        x += 1
    elif S[i] == 'D':
        x -= 1
    y.append(x)
print max(y)

Measured memory_bytes: 2692
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, M = sc.nextInt
    val A = new Array[Int](M)
    val B = new Array[Int](M)
    for (i <- 0 until M) {
      A(i) = sc.nextInt - 1
      B(i) = sc.nextInt - 1
    }

    val uf = new UnionFind(N)
    val result = new Array[Long](M + 1)
    result(M) += N.toLong * (N - 1) / 2
    for (i <- M - 1 to 0 by -1) {
      if (uf.same(A(i), B(i))) {
        result(i) = result(i + 1)
      } else {
        result(i) = result(i + 1) - uf.size(A(i)) * uf.size(B(i))
      }
      uf.unite(A(i), B(i))
    }

    for (i <- 1 to M) {
      println(result(i))
    }
  }

  class UnionFind(n: Int) {
    val par = new Array[Int](n)
    private val siz: Array[Int] = Array.fill[Int](n)(1)

    for (i <- 0 until n) {
      par(i) = i
    }

    def root(x: Int): Int = {
      if (par(x) == x)
        x
      else {
        par(x) = root(par(x))
        par(x)
      }
    }

    def unite(x: Int, y: Int): Unit = {
      val rootX = root(x)
      val rootY = root(y)
      if (rootX == rootY) return
      if (siz(rootX) < siz(rootY)) {
        siz(rootY) += siz(rootX)
        par(rootX) = rootY
      } else {
        siz(rootX) += siz(rootY)
        par(rootY) = rootX
      }
    }

    def same(x: Int, y: Int): Boolean = {
      root(x) == root(y)
    }

    def groupCount: Int = {
      (0 until n).count(x => x == par(x))
    }

    def size(x: Int): Int = {
      siz(root(x))
    }
  }

}

Measured memory_bytes: 73224
#include<bits/stdc++.h>
#define H 30
using namespace std;

string s[H][2], S[H][2], t[3][2][2], T[3][2][2];
int h, n, ans, f, cnt=1;

void change(int x, int dy, int dx){
  
  string tmp[2][2];
  
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++) tmp[i][j]="..";
  
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
	
	if(t[x][i][j][k]=='.') continue;
	
	int nj=dy+j, nk=dx+k;
	
	if(nj<0||nk<0||2<=nj||2<=nk){
	  f=1;
	  return;
	}
	
	tmp[i][nj][nk]='#';
	
      }
    }
  
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++) t[x][i][j]=tmp[i][j];

}

int del(){

  int res=0;
  
  for(int i=0;i<H-1;i++){
    
    int flag=0;
    
    for(int j=0;j<2;j++)
      for(int k=0;k<2;k++)
	if(s[i][j][k]=='.') flag=1;
    
    if(!flag){
      
      for(int j=i;j<H-1;j++)
	
	for(int k=0;k<2;k++)
	  for(int l=0;l<2;l++) s[j][k][l]=s[j+1][k][l];
      
      i--;
      res++;
    }
    
  }

  return res;
}

int sim(){
  
  int res=0;
  
  for(int num=0;num<n;num++){

    int F=0, idx=0;
    
    for(int i=H-2;i>=0;i--){
      
      for(int j=0;j<2;j++){
	
	for(int k=0;k<2;k++){
	  
	  for(int l=0;l<2;l++){
	    
	    if(s[i+j][k][l]=='#'&&s[i+j][k][l]==t[num][j][k][l]){
	      F=1;
	      idx=i+1;
	      break;
	    }	    
	    
	  }
	  
	  if(F) break;
	  
	}

	if(F) break;
	
      }
      
      if(F) break;
    }
    
    for(int j=0;j<2;j++)
      
      for(int k=0;k<2;k++)
	
	for(int l=0;l<2;l++)
	  if(t[num][j][k][l]=='#')
	    s[idx+j][k][l]=t[num][j][k][l];
    
    res+=del();
    
  }
  
  for(int i=0;i<H;i++)
    for(int j=0;j<2;j++)
      for(int k=0;k<2;k++)
	s[i][j][k]=S[i][j][k];
  
  return res;
}

void dfs(int x){
  
  if(x==n){
    
    ans=max(ans,sim());
    
    return;
  }
  
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      
      for(int k=0;k<2;k++)
	for(int l=0;l<2;l++)
	  t[x][k][l]=T[x][k][l];
      
      f=0;
      change(x,i,j);
      if(f) continue;
      dfs(x+1);
    }
}

void solve(){
  
  ans=0;
  
  dfs(0);
  
  cout<<ans<<endl;

}

int main(){
  
  while(1){
    
    cin>>h>>n;
    if(!h&&!n) break;
    
    for(int i=0;i<H;i++)
      for(int j=0;j<2;j++) s[i][j]=S[i][j]="..";
    
    for(int i=0;i<h;i++)
      for(int j=0;j<2;j++){
	cin>>s[i][j];
	S[i][j]=s[i][j];
      }
    
    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++)
	for(int k=0;k<2;k++) cin>>t[i][j][k];
    
    for(int i=0;i<n;i++){
      if(t[i][0][0]==".."&&t[i][0][1]==".."){
	swap(t[i][0][0],t[i][1][0]);
	swap(t[i][0][1],t[i][1][1]);
      }
    }
    
    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++)
	for(int k=0;k<2;k++) T[i][j][k]=t[i][j][k];
    
    solve();
    
  }
  
  return 0;
}

Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main()
{
    long long k,num,s,i,j,q,cnt=0;
	while(cin>>k>>s)
	{
		cnt=0;
		for(int i=0;i<=k;i++)
		for(int j=0;j<=k;j++)
		{
			num=s-i-j;
			if(num>=0&&num<=k)
		    cnt++;
		}
		cout<<cnt<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int M = cin.nextInt();
        int[] X, Y, Z;
        X = new int[M];
        Y = new int[M];
        Z = new int[M];

        for (int i = 0; i < M; i++)
        {
            X[i] = cin.nextInt() - 1;
            Y[i] = cin.nextInt() - 1;
            Z[i] = cin.nextInt();
        }

        init(N);
        for (int i = 0; i < M; i++)
        {
            connect(X[i], Y[i]);
        }

        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (root(i) == i) ans++;
        }
        Console.WriteLine(ans);

    }

    int[] uni;
    void init(int N)
    {
        uni = new int[N];
        for (int i = 0; i < N; i++)
        {
            uni[i] = -1;
        }
    }

    int root(int a)
    {
        if (uni[a] < 0) return a;
        else return uni[a] = root(uni[a]);
    }

    bool connect(int a, int b)
    {
        a = root(a);
        b = root(b);
        if (a == b) return false;
        if (uni[a] > uni[b]) swap(ref a, ref b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    }  
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
        
    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}





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

using namespace std;

int main(){
    int N;
    cin >> N;
    bool flag = false;
    for(int i = 1; i < 10; i++){
        if ((N % i == 0) && (N / i < 10)){
            flag = true;
        }
    }
    if(flag==true){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-6;

int main(){
	int n;
	while(~scanf("%d",&n)){
		printf("3C%02d\n",n%39 == 0 ? 39 : n%39);
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string S;
  cin >> S;
  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
}

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

int main(){
  int n, i, j;
  cin >> n;
  string s, t;
  cin >> s >> t;
  
  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n - i; j++ ){
      if ( s[i + j] != t[j] ) break;
    }
    if( j == n - i ){
      cout << n + i << endl;
      return 0;
    }
  }
  cout << 2 * n <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

signed main(){

    fastIO

   	int a, b, c, d;
   	cin >> a >> b >> c >> d;
   	int sum = 0;
   	if (d > a){
	   	d -= a;
	   	sum += a; 
   	}
	else{
		sum += d;
		d = 0;
	}
	if (d == 0){
		cout << sum << endl;
		exit(0);
	}
	if (d > b){
		d-=b;
	}else{
		d = 0;
	}
	if (d == 0){
		cout << sum << endl;
		exit(0);
	}
	sum -= d;
	cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 2000010;
    private static int MOD = 1000000007;
    public static void main(String[] args) {
        Main main = new Main();
        main.COMinit();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int r1 = scan.nextInt();
        int c1 = scan.nextInt();
        int r2 = scan.nextInt();
        int c2 = scan.nextInt();
        long ans = g(c2, r2);
        ans %= MOD;
        long x = g(r2, c1 - 1);
        ans = (ans + MOD - x) % MOD;
        long y = g(r1 - 1, c2);
        ans = (ans + MOD - y) % MOD;
        ans += g(r1 - 1, c1 - 1);
        ans %= MOD;
        System.out.println(ans);
    }
    long g(int r, int c) {
        long x = COM(r+c+2, c+1);
        return x % MOD;
    }
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; i++) {
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n <0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
}


Measured memory_bytes: 71124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

ll n;

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    ll pw=1;
    for(int i=0; i<=17; i++){
        ll x=(((n/pw*pw)%(pw*10))+pw)%(pw*10);
        if(x>n) continue;
        n-=x;
        pw*=10;
    }
    int ans=0;
    while(n>0) ans+=n%10, n/=10;
    cout<<ans;
    return 0;
}

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    string s;
    cin >> n >> k >> s;

    if(s[k-1]=='A'){
        s[k-1] = 'a';
    }else if(s[k-1]=='B'){
        s[k-1] = 'b';
    }else{
        s[k-1] = 'c';
    }

    cout << s << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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--)
typedef long long LL;
int N;
LL M;
int V,P;
LL A[100001];
LL X;
vector<LL>v;
bool check(LL mid){
	if(mid+M<X){
		return false;
	}
	LL sum=0;
	for(int i=P-1;i<N;i++){
		sum+=min(M,mid+M-v[i]);
	}
	sum-=M;
	if(sum>=V*M){
		return true;
	}else{
		return false;
	}
}


int main(){
	cin>>N>>M>>V>>P;
	V=max(0,V-P);
	REP(i,N){
		cin>>A[i];
		v.push_back(A[i]);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());

	X=v[P-1];
	//2部探
	LL ub=1e10;
	LL lb=-1;
	while(ub-lb>1){
		LL mid=(ub+lb)/2;
		if(check(mid)){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	LL ans=0;
	REP(i,N){
		if(v[i]>=ub)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	long long a,b,c,d;
	//double x,y,z;
	cin>>a>>b>>c;
	d=c-a-b;
	if(d<0)
	{
		cout<<"No"<<endl;
		return 0;
	}
	if(a*b*4<d*d)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}






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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	int n=s.size(),m=t.size();
	vector<vector<int>> dp(n+1,vector<int>(m+1));
	vector<vector<pii>> memo(n+1,vector<pii>(m+1));
	rep(i,n){
		rep(j,m){
			if(s[i]==t[j]){
				dp[i+1][j+1]=dp[i][j]+1;
				memo[i+1][j+1]=mp(i,j);
			}
			else{
				if(dp[i+1][j]>dp[i][j+1]){
					dp[i+1][j+1]=dp[i+1][j];
					memo[i+1][j+1]=mp(i+1,j);
				}
				else{
					dp[i+1][j+1]=dp[i][j+1];
					memo[i+1][j+1]=mp(i,j+1);
				}
			}
		}
	}
	string ans="";
	int i=n,j=m;
	while(i>=1 && j>=1){
		pii tmp=memo[i][j];
		if(dp[i][j]>dp[tmp.first][tmp.second]) ans+=s[i-1];
		i=tmp.first;
		j=tmp.second;
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 105984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int x[n];
  rep(i,0,n) cin>>x[i];
  int p=0;
  rep(i,0,n) p+=x[i];
  p/=n;
  int a=0;
  rep(i,0,n) a+=(x[i]-p)*(x[i]-p);
  p++;
  int b=0;
  rep(i,0,n) b+=(x[i]-p)*(x[i]-p);
  cout<<min(a,b)<<endl;
}

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

using namespace std;

int main(){
  int x,n;
  vector<int> a(201);
  
  cin >> x >> n;
  vector<int> p(n);

  
  if(n==0){
    cout << x << endl;
    return 0;
  }
      
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  
  for(int i=0;i<n;i++){
    a.at(x-p.at(i)+100)++;
  }
  
  int answer = 0;
  int j;
  for(int i=0;i<n+1;i++){
    j = i * (-1);
    if(a.at(i+100) == 0){
      answer = x - i;
      cout << answer << endl;
      break;
    }
    if(a.at(j+100) == 0){
      answer = x - j;
      cout << answer << endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#define MAX 2000
using namespace std;

int num[MAX+1][MAX+1];
int ans[MAX];
int route[3]={};

int minimum(int n){
  for(int i=0;i<n-1;i++){
    if(route[n-i-1] < route[n-i-2]){
      int tmp = route[n-i-1];
      route[n-i-2] = route[n-i-1];
      route[n-i-1] = tmp;
    }
  }
  return route[0];
}
int main(void){
  int N,X,Y;
  cin >> N >> X >> Y;
  //mapうめ
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      route[0] = abs(i-j);
      route[1] = abs(X-i) + 1 + abs(Y-j);
      route[2] = abs(Y-i) + 1 + abs(X-j);
      int minv = minimum(3);
      //cout << "i:" << i << ",j:" << j << ":" << minv << endl;
      ans[minv] += 1;
    }
  }
  for(int k=1;k<=N-1;k++){
    cout << ans[k]/2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

def make_divs(n):
    divs = []
    i = 1
    
    while i*i<=n:
        if n%i==0:
            divs.append(i)
            
            if i!=n//i:
                divs.append(n//i)
        
        i += 1
    
    return divs

N = int(input())
ds = make_divs(N)
ans = 0

for d in ds:
    if d==1:
        continue
    
    N2 = N
    
    while N2%d==0:
        N2 //= d
    
    if (N2-1)%d==0:
        ans += 1
    
ans += len(make_divs(N-1))-1
print(ans)

Measured memory_bytes: 67800
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

struct Block {
	long long int w, s, v;
	bool operator <(const Block&b)const {
		return make_pair(w + s, s) < make_pair(b.w + b.s, b.s);
	}
	bool operator >(const Block&b)const {
		return make_pair(w + s, s) > make_pair(b.w + b.s, b.s);
	}
};

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

	cin >> N;
	vector<Block>v(N);
	for (int i = 0; i < N; i++) {
		cin >> L >> R >> K;
		v[i] = { L,R,K };
	}
	vector<vector<long long int>>dp(N, vector<long long int>(20001));
	sort(v.begin(), v.end());
	for (int i = 20000; i >= v[0].w; i--)dp[0][i] = v[0].v;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 20001; j++)dp[i][j] = dp[i - 1][j];
		for (int j = min(20000LL,v[i].s + v[i].w); j >= v[i].w; j--) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i].w] + v[i].v);
		}
	}
	cout << *max_element(dp.back().begin(), dp.back().end()) << endl;
	return 0;
} 

Measured memory_bytes: 160512
n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

a.sort()
bc.sort(reverse=True, key=lambda x:x[1])
i = 0
ans = 0
for b, c in bc:
    for _ in range(b):
        if i > n-1: break
        if a[i] < c:
            ans += c 
            i += 1
        else: break
print(ans + sum(a[i:]))

Measured memory_bytes: 32960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){ 
  ll k=1;
  char c;
  int f=0;
  for(ll i=0;i<11;i++){
    cout<<"? "<<k<<endl;
    cin>>c;
    if(c=='N'){
	 f=1;
	 break;
    }
    k*=10;
  }
  if(f==0){
    ll a=1;
    ll b=9;
    for(int i=0;i<11;i++){
	 cout<<"? "<<b<<endl;
	 cin>>c;
	 if(c=='Y'){
	   cout<<"! "<<a<<endl;
	   return 0;
	 }
	 a*=10;
	 b*=10;
    }
  }
  ll ok=k-1,ng=k/10-1,mid;
  while(ok-ng>1){
    mid=(ng+ok)/2;
    cout<<"? "<<mid<<"000"<<endl;
    cin>>c;
    if(c=='Y')ok=mid;
    else ng=mid;
  }
  cout<<"! "<<ok<<endl;
  return 0;
}


Measured memory_bytes: 652
import java.util.Scanner;
 
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 cnt = 1;
 
		if (a != b) {
            cnt++;

            if (b != c && a != c) {
            cnt++;
            }
		}
		else {
		    if (b != c) {
		    cnt++;
		    }
		}

		System.out.println(cnt);
	}
}

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

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

/*
    state := 0 foots are on the earth, 1 stepping up,
             2 foots are on the step, 3 stepping down.
*/

int n, state = 0, ans = 0;
string s, prefoot = "";

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

    while (cin >> n, n) {
        state = ans = 0;
        prefoot = "";
        
        rep(i,n) {
            cin >> s;
            if (state == 0) {
                prefoot = s;
                state = 1;
            } else if (state == 1) {
                if (prefoot == "lu") {
                    if (s == "ru") {
                        ans++;
                        state = 2;
                    } else {
                        state = 0;
                    }
                } else if (prefoot == "ru") {
                    if (s == "lu") {
                        ans++;
                        state = 2;
                    } else {
                        state = 0;
                    }
                }
            } else if (state == 2) {
                prefoot = s;
                state = 3;
            } else if (state == 3) {
                if (prefoot == "ld") {
                    if (s == "rd") {
                        ans++;
                        state = 0;
                    } else {
                        state = 2;
                    }
                } else if (prefoot == "rd") {
                    if (s == "ld") {
                        ans++;
                        state = 0;
                    } else {
                        state = 2;
                    }
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<iomanip>
using lint=int64_t;
using namespace std;

int main()
{
	const int dv[]={1,0,-1};
	
	int N;
	int t[110]={};
	int v[110]={};

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> t[i];
	for(int i=1;i<N;i++)
		t[i]+=t[i-1];
	for(int i=0;i<N;i++)
		t[i]*=2;
	for(int i=0;i<N;i++)
	{
		cin >> v[i];
		v[i]*=2;
	}

	int dp[50010][210]={};
	dp[0][0]=1;
	dp[t[N-1]][0]=1;
	int index=0;
	for(int i=0;i<t[N-1];i++)
	{
		for(int j=0;j<=v[index];j++)
		{
			if(dp[i][j]==1)
			{
				for(int k=0;k<3;k++)
				{	
					int nv=j+dv[k];
					if(i+1==t[index])
					{
						if(0<=nv && nv<=min(v[index],v[index+1]))
							dp[i+1][nv]=1;
					}
					else
					{
						if(0<=nv && nv<=v[index])
							dp[i+1][nv]=1;
					}
				}
			}
		}
		if(i+1==t[index])
			index++;
	}

	int mv[50010]={};
	mv[t[N-1]]=0;
	for(int i=t[N-1]-1;i>=0;i--)
	{
		for(int j=0;j<3;j++)
		{
			int pv=mv[i+1]-dv[j];
			if(0<=pv && dp[i][pv]==1)
				mv[i]=max(mv[i],pv);
		}
	}

	double ans=0;
	for(int i=0;i<t[N-1];i++)
	{
		ans+=abs(mv[i+1]-mv[i])/2.0;
		ans+=min(mv[i+1],mv[i]);
	}

	cout << fixed << setprecision(5);
	cout << ans/4.0 << endl;
	return 0;
}


Measured memory_bytes: 41472
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }
ll MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    // rep(i, N-1)rep2(j, i+1, N)
    // {
    //     ll a = A[i]%MOD;
    //     ll b = A[j]%MOD;
    //     ll c = (a*b)%MOD;
    //     ans += c;
    //     ans %= MOD;
    // }
    // ll sub = 0;
    // rep2(i, 1, N)
    // {
    //     sub += A[i];
    // }
    // sub %= MOD;
    // rep(i, N-1)
    // {
        
    //     ans += ((A[i]*sub)%MOD);
    //     sub -= A[i+1];
    //     sub %= MOD;
    // }
    // cout << ans << endl;
    vector<ll> S(N);
    S[0] = 0;
    S[1] = A[0];
    rep2(i, 2, N)
    {
        S[i] = (S[i-1] + A[i-1])%MOD;
        //cout << S[i] << endl;
    }
    rep2(i, 0, N-1)
    {
        ll x = A[i+1]*S[i+1];
        ans += (x%MOD);
    }
    ans %= MOD;
cout << ans << endl;
     return 0;
}

Measured memory_bytes: 6368
def getSquareFootage(height, width)
  return height * width
end

def getSquareLength(height, width)
  return (height + width) * 2
end

nums = $stdin.gets.split
puts "#{getSquareFootage(nums[0].to_i, nums[1].to_i)} #{getSquareLength(nums[0].to_i, nums[1].to_i)}"

Measured memory_bytes: 8544
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for(int i=0; i<N; i++) cin >> V[i];
  for(int i=0; i<N; i++) cin >> C[i];
  
  int ans=0;
  for(int i=0; i<N; i++){
    if(V[i]>C[i]) ans+=V[i]-C[i];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		Arrays.sort(a);
		ou.println(a[n - 1] - a[0]);
		ou.flush();
	}
}

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

int main(){
	int d, j, m, jp, mp;
	cin >> d;
	cin >> j >> m;
	cin >> jp >> mp;
	j = j / jp  + (j % jp > 0); m = m / mp + (m % mp > 1);

	cout << d - max(j, m) << endl;
}

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define INF INT_MAX
#define NINF INT_MIN
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\n";
    err(++it, args...);
}

const int N = 307+5;

long double dp[N][N][N];
int n;
int c1, c2, c3;

int main() {

	cin >> n;
	tik(i,0,n) {
		int x;
		cin >> x;
		if(x == 1)
			c1++;
		else if(x == 2)
			c2++;
		else
			c3++;
	}

	tik(k,0,n+1) {
		tik(j,0,n+1) {
			tik(i,0,n+1) {
				if(i+k+j == 0)
					continue;
				dp[i][j][k] += 1.0*n/(i+j+k);
				if(i)
					dp[i][j][k] += (1.0*i/(i+j+k))*dp[i-1][j][k];
				if(j)
					dp[i][j][k] += (1.0*j/(i+j+k))*dp[i+1][j-1][k];
				if(k)
					dp[i][j][k] += (1.0*k/(i+j+k))*dp[i][j+1][k-1];
			}
		}
	}

	cout.precision(10);

	cout << fixed << dp[c1][c2][c3];
}

Measured memory_bytes: 458880
/*
                    Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
            
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }     
signed main()
{   jaldi
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    cout<<"bust";
    else
    {   cout<<"win";
    }
    
}

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

const int maxn = 100010;
char s[maxn], t[maxn];
int sum1[maxn], sum2[maxn];

int main()
{
	//freopen("E.in","r",stdin);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;i++)
	{
		if (i) sum1[i] = sum1[i-1] + (s[i] == 'A' ? 1 : 2);
		else sum1[i] = (s[i] == 'A' ? 1 : 2);
		sum1[i] %= 3;
	}
	for (int i=strlen(s);i>=1;i--) sum1[i] = sum1[i-1];
	sum1[0] = 0;
	
	scanf("%s",t);
	len = strlen(t);
	for (int i=0;i<len;i++)
	{
		if (i) sum2[i] = sum2[i-1] + (t[i] == 'A' ? 1 : 2);
		else sum2[i] = (t[i] == 'A' ? 1 : 2);
		sum2[i] %= 3;
	}
	for (int i=strlen(t);i>=1;i--) sum2[i] = sum2[i-1];
	sum2[0] = 0;
	
	int q;
	scanf("%d",&q);
	while (q--)
	{
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int mod1 = (sum1[b] - sum1[a-1]) % 3;
		if (mod1 < 0) mod1 += ((-mod1)/3+1) * 3;
		int mod2 = (sum2[d] - sum2[c-1]) % 3;
		if (mod2 < 0) mod2 += ((-mod2)/3+1) * 3;
		puts(mod1==mod2 ? "YES" : "NO");
	}
	return 0;
}


Measured memory_bytes: 1664
n = int(input())
B = list(map(int,input().split()))
A = [B[0]]
for i in range(n-1):
  if i+1 == n-1:
    A.append(B[-1])
  elif B[i] >= B[i+1]:
    A.append(B[i+1])
  else:
    A.append(B[i])
print(sum(A))
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const ll INF = 1e16;

void solver(int N, map<ll, ll> &ab, bool &flg){

    ll t_limit{}, t_done{};
    for(auto p: ab){
        auto b = p.first;
        auto a = p.second;

        t_limit = b;
        t_done += a;

        if(t_limit < t_done){
            flg = false;
        }
    }
    return;
}

int main(){

    int N;
    cin >> N;
    map<ll, ll> ab;
    for(int i=0; i<N; ++i){
        ll a,b;
        cin >> a >> b;
        ab[b] += a;
    }

    bool flg = true;
    solver(N, ab, flg);

    if(flg){
        cout << "Yes"s << endl;
    }
    else{
        cout << "No"s << endl;
    }
    return 0;
}


Measured memory_bytes: 16088
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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() { 
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];

    ll res = 1e18+10;
    //正,負,正,負,...
    ll sum = 0, cost = 0;
    rep(i, n){
        sum += A[i];
        if(i%2==0 && sum <= 0){
            ll num = -sum + 1;
            sum += num; cost +=num;
        }else if(i%2==1 && sum >= 0){
            ll num = sum + 1;
            sum -= num; cost += num;
        }
    }
    chmin(res, cost);
    //負,正,負,正,...
    sum = 0, cost = 0;
    rep(i, n){
        sum += A[i];
        if(i%2==1 && sum <= 0){
            ll num = -sum + 1;
            sum += num; cost +=num;
        }else if(i%2==0 && sum >= 0){
            ll num = sum + 1;
            sum -= num; cost += num;
        }
    }
    chmin(res, cost);

    cout << res << ln;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        char op = sc.NextChar();
        int b = sc.NextInt();

        int answer = op == '+' ? a + b : a - b;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

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

    double ans;
    if (n % 2 == 0) {
        ans = 0.5;
    }
    else {
        ans = (double) (n / 2 + 1) / n;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s;
	cin >> s;
	int answer = 0;
	for (char c : s) {
		if (c == '1') {
			++answer;
		}
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
s=[]
p=[]
md=[[None,float('INF')] for i in range(n)]
for i in range(n):
    t1,t2=map(int,input().split())
    s.append([t1,t2])
for i in range(m):
    t1,t2=map(int,input().split())
    p.append([t1,t2])
for i in range(n):
    for j in range(m):
        if md[i][1]>abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1]):
            md[i][0]=j+1
            md[i][1]=abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1])
for i in range(n):
    print(md[i][0])

Measured memory_bytes: 3064
L=int(input());S=bin(L);N=len(S)-2;print(N,N+N+S.count("1")-3)
for i in range(N-1):
 print(i+1,i+2,1<<i,i+1,i+2,0)
 if int(S[-i-1]):L^=1<<i;print(i+1,N,L)

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

int main(){
    string y,k;
    int ans=0;
    cin>>y>>k;
    for(int i=0;i<3;i++){
    if(y.at(i)==k.at(i)){
        ans++;
        }
    }
    cout<<ans<<endl;
    }


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

using namespace std;

int main()  {
    double n, m, d;
    cin >> n >> m >> d;

    if(d >= n || m < 2)
        return 0 * puts("0");

    double add = 2 * min(d,n - d);

    if(2 * d <= n)  add += 2 * (n - 2 * d);
    if(d == 0)      add /= 2;

    cout << fixed << setprecision(10) << (m - 1) * add / (n * n) << endl;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);

	cout<<a<<' '<<b<<' '<<c; 

	return 0;
}

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

int cnt=0;

void merge(int A[], int l, int mid,int r){
  int n1 = mid-l;
  int n2 = r-mid;
  int L[n1+1], R[n2+1];
  for(int i=0;i<n1;i++){
    L[i] = A[l+i];
  }
  for(int i=0;i<n2;i++){
    R[i] = A[mid+i];
  }
  L[n1] = INT_MAX;
  R[n2] = INT_MAX;
  int i=0, j=0;
  for(int k=l;k<r;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
    cnt++;
  }
}

void mergesort(int A[], int l, int r){
  if(l+1<r){
    int mid = (l + r) / 2;
    mergesort(A, l, mid);
    mergesort(A, mid, r);
    merge(A, l, mid, r);
  }
}

int main(){
  int n, S[500000];
  cin>>n;
  for(int i=0;i<n;i++) cin>>S[i];
  mergesort(S, 0, n);
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<S[i];
  }
  cout<<endl<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 6980