akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int r, c, sum, sumOfAll;
		int[][] sheet;
		String[] size = in.readLine().split(" ");
		r = Integer.parseInt(size[0]);
		c = Integer.parseInt(size[1]);
		StringBuilder sb = new StringBuilder((r + 1) * (c + 1));
		sheet = new int[r][c];
		for (int i = 0; i < r; i += 1) {
			sum = 0;
			String[] array = in.readLine().split(" ");
			for (int j = 0; j < c; j += 1) {
				sheet[i][j] = Integer.parseInt(array[j]);
				sb.append(sheet[i][j]).append(" ");
				sum += sheet[i][j];
			}
			sb.append(sum + System.getProperty("line.separator"));
		}
		in = null;
		sumOfAll = 0;
		for (int m = 0; m < c; m += 1) {
			sum = 0;
			for (int n = 0; n < r; n += 1) {
				sum += sheet[n][m];
			}
			sumOfAll += sum;
			sb.append(sum).append(" ");
		}
		sb.append(sumOfAll);
		System.out.println(sb);
	}
}

Measured memory_bytes: 23136
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

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

  vector<int> ua(n);
  ua[0]=a[0];
  for(int i=1;i<n;i++){
    if(a[i]!=a[i-1]){
      ua[i]=a[i];
    }else{
      ua[i]=1;
    }
  }

  vector<int> ub(n);
  ub[n-1]=b[n-1];
  for(int i=n-2;i>=0;i--){
    if(b[i]!=b[i+1]){
      ub[i]=b[i];
    }else{
      ub[i]=1;
    }
  }

  vector<int> anso(n);
  vector<int> ansu(n);
  for(int i=0;i<n;i++){
    anso[i]=min(a[i],b[i]);
    ansu[i]=max(ua[i],ub[i]);
  }

  int ans=1;
  for(int i=0;i<n;i++){
    ans*=(anso[i]-ansu[i]+1);
    if(ans<0){
      cout<<0<<endl;
      return 0;
    }
    ans%=mod;
  }
  cout<<ans%mod<<endl;
}


Measured memory_bytes: 4992
N, M = list(map(int, input().split()))
AB = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x:x[0])

m, p = 0, 0
for a, b in AB:
    if m+b>=M:
        p += (M-m)*a
        break
    m += b
    p += b*a

print(p)

Measured memory_bytes: 18892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const double inf=1e8;	
ll x=1145141919;
vi a,A;
int main(){
	int n,m;
	cin>>n>>m;
	a=A=vi(n+1);
	string s;
	cin>>s;
	
	A[0]=a[0]=x;
	rep(i,n)a[i+1]=a[i]*x;
	rep(i,n)A[i+1]=(A[i]+s[i]*a[i+1]);
	int l=0,r=1;
	set<ll>se;
	rep(i,m){
		string t;
		cin>>t;
		if(t=="L++")l++;
		if(t=="L--")l--;
		if(t=="R++")r++;
		if(t=="R--")r--;
		ll w=(A[r]-A[l])*a[n-r];
		se.insert(w);
	}
	cout<<se.size()<<endl;
}

Measured memory_bytes: 21936
#include<cstdio>
#include<cstring>
#define ll long long

int main()
{
    char sa[110],sb[110],sc[110];
    scanf("%s%s%s",&sa,&sb,&sc);
    int lena=strlen(sa),lenb=strlen(sb),lenc=strlen(sc);
    int i,j,k;
    int c=sa[0];
    j=k=0;
    i=1;
    while(1)
    {
        if(c=='a')
        {
           c=sa[i];
           i++;
        }
        else if(c=='b')
        {
            c=sb[j];
            j++;
        }
        else if(c=='c')
        {
            c=sc[k];
            k++;
        }
        if(i>lena)
        {
            printf("A\n");
            break;
        }
        else if(j>lenb)
        {
            printf("B\n");
            break;
        }
        else if(k>lenc)
        {
            printf("C\n");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    int h[100005];
    for(int i = 0; i < n; ++i)
        scanf("%d", &h[i]);
    int dp[100005][2] = {0};
    dp[0][0] = 1; dp[0][1] = 1;
    for(int i = 1; i < n; ++i)
    {
        if(h[i] >= h[i-1])
            dp[i][1] = max(dp[i-1][1] + 1, dp[i][1]);
        if(h[i] >= h[i-1] - 1)
            dp[i][1] = max(dp[i-1][0] + 1, dp[i][1]);
        if(h[i] - 1 >= h[i-1])
            dp[i][0] = max(dp[i-1][1] + 1, dp[i][0]);
        if(h[i] - 1 >= h[i-1] - 1)
            dp[i][0] = max(dp[i-1][0] + 1, dp[i][0]);
    }
    if(dp[n-1][0] == n || dp[n-1][1] == n)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
bitset<4010000> B;
int n,a[2020],csu = 0;
int main() {
	B[0] = 1;
	read(n);
	for(int i=0;i<n;i++){
		read(a[i]);
		csu+=a[i];
		B|=(B<<(a[i]));
	}
	for(int i=(csu+1)/2;;i++){
		if(B[i]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	ss := make([]int64, n+1)
	for i := 1; i < n+1; i++ {
		a := getNextInt64(scanner)
		ss[i] = ss[i-1] + a
	}

	var ans int64

	ans = 1 << 62
	for i := 1; i < n; i++ {
		diff := ss[n] - ss[i]*2
		if diff < 0 {
			diff = -diff
		}
		if ans > diff {
			ans = diff
		}
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 4096
/*#include<utility>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<iostream>
#include<string.h>*/
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
using namespace std;
typedef long long LL;
int main(){
    char c[200005];
    scanf("%s",c);
    LL ans=0;
    int cnt=0;
    for(int i=0;c[i]!=0;i++){
        if(c[i]=='B')
        cnt++;
        else
        ans+=cnt;
    }
    printf("%lld\n",ans);
}
/*
0 1 0
0 0 1
1 0 1
*/

Measured memory_bytes: 384
package main

import "fmt"

func main() {
  var n int
  var s = 0
  fmt.Scan(&n)
  a := make([]int, n)
  b := make([]int, n)
  c := make([]int, n-1)

  for i:=0; i<n; i++ {
    fmt.Scan(&a[i])
  }
  for i:=0; i<n; i++ {
    fmt.Scan(&b[i])
  }
  for i:=0; i<n-1; i++ {
    fmt.Scan(&c[i])
  }

  prev_eat := 0
  for _, eat := range a {
    s += b[eat-1]
    if eat == prev_eat+1 && prev_eat != 0{
      s += c[prev_eat-1]
    }
    prev_eat = eat
  }

  fmt.Println(s)
}


Measured memory_bytes: 512
n = int(input())

t = [0]*1001001
x = [0]*1001001
y = [0]*1001001


for i in range(n):
    a, b, c = map(int, input().split())
    t[i+1] = a
    x[i+1] = b
    y[i+1] = c

flag = 1    
for  i in range(n):
    dt = t[i+1] - t[i]
    dist = abs(x[i+1]-x[i]) + abs(y[i+1] - y[i])
    if dt < dist:
        flag = 0
    if dist % 2 != dt % 2:
        flag = 0

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    char c[3][3];
    for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin >> c[i][j];

    for(int i=0; i<3; i++) cout << c[i][i];
    cout << endl;
}

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 train = a < b ? a : b;

		int c = sc.nextInt();
		int d = sc.nextInt();
		int bus = c < d ? c : d;

		System.out.println(train + bus);
	}
}


Measured memory_bytes: 21972
#!/usr/bin/env python3
#全国統一プログラミング王決定戦予選 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ab = [LI() for _ in range(n)]
ab = sorted(ab,key = lambda x:x[0]+x[1],reverse = True)
ans = 0
for i in range(n):
    a,b = ab[i]
    if i % 2:
        ans -= b
    else:
        ans += a
print(ans)


Measured memory_bytes: 63836
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        a: i32,
        b: i32,
    }

    let mut num = 0;
    for i in 0..(n + 1) {
        let d1 = i % 10;
        let d2 = (i / 10) % 10;
        let d3 = (i / 100) % 10;
        let d4 = (i / 1000) % 10;
        let d5 = (i / 10000) % 10;
        let dsum = d1 + d2 + d3 + d4 + d5;

        if a <= dsum && dsum <= b {
            num += i;
        }
    }
    println!("{}", num);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string.h>
#include<limits.h>

using namespace std;

int n, S;
const int MAXN = 1e5 + 2;
const long long INF = LONG_MAX;
vector<long long> w,v;
long long dp[MAXN][102];
long long memo[MAXN][102];


long long ganacia(int S, int k){
	if(S < 0) return -INF;
	if(S == 0) return 0;
	if(k >= n) return 0;
	if(memo[S][k] != -1) return memo[S][k];

	return memo[S][k] = max(ganacia(S - w[k], k + 1) + v[k], ganacia(S, k + 1));
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> S;
	memset(memo, -1, sizeof(memo));
	w = vector<long long>(n);
	v = vector<long long>(n);
	for(int i=0 ; i<n ; i++){
		cin >> w[i] >> v[i];
	}

	for(int s= 1 ; s<=S ; s++){
		for(int k = n - 1; k >=0 ; k--){
			long long x = -INF;
			if(s - w[k] >= 0) x = dp[s - w[k]][k + 1] + v[k];
			long long y = 0;
			if( k < n) y = dp[s][k + 1];
			dp[s][k] = max(x,y);
		}
	}
	cout << dp[S][0] <<"\n";
//	cout << ganacia(S,0) <<"\n";
	return 0;
}


Measured memory_bytes: 162516
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	aca := make([]int, n)
	waa := make([]int, n)
	for i := 0; i < m; i++ {
		var p int
		var s string
		fmt.Scan(&p, &s)
		if aca[p-1] == 0 && s == "AC" {
			aca[p-1]++
		} else if aca[p-1] == 0 && s == "WA" {
			waa[p-1]++
		}
	}
	wa := 0
	ac := 0
	for i := 0; i < n; i++ {
		ac += aca[i]
		if aca[i] != 0 {
			wa += waa[i]
		}
	}
	fmt.Println(ac, wa)
}


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

int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<int> b(n-k+1);
  for(int i = 0; i < k; i++) b[0] += a[i];
  for(int i = 1; i < n-k+1; i++) b[i] = b[i-1]-a[i-1]+a[k+i-1];
  double p = b[0];
  for(int i = 1; i < n-k+1; i++) p = max(p, double(b[i]));
  
  cout << fixed << setprecision(10);
  cout << (p+k)/2 << endl;
}


Measured memory_bytes: 1792
#include <iostream>

bool isPrime(int n)
{
	/* 1???????????¨????´???°??§????????? */
	if( n < 2 )
	{
		return false;
	}
	
	/* 2????´???° */
	if( n == 2 )
	{
		return true;
	}
	
	/* 2??\????????¨????????¶??°????´???°??§????????? */
	if( n % 2 == 0 )
	{
		return false;
	}
	
	/* n ????´???°??§?????????????????°??????n ?????§???????????????????????§?????????????????? */
	for( int i = 3; i * i <= n; i += 2 )
	{
		if( n % i == 0 )
		{
			return false;
		}
	}
	
	return true;
}

void ALDS1_1_C(void)
{
	int prime_count = 0;
	int num, loop;
	
	std::cin >> loop;

	for(int i = 0; i < loop; i++)
	{
		std::cin >> num;
		if( isPrime( num ) )
		{
			prime_count++;
		}
	}
	
	std::cout << prime_count << std::endl;
	
	return;
}

int main(void)
{
    ALDS1_1_C();
	return 0;
}

Measured memory_bytes: 3084
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

template <class T>
class cumulativeSum
{
private:
    int ny, nx;
    vector<vector<T> > sum;
public:
    cumulativeSum(const vector<vector<T> >& a)
    {
        ny = a.size();
        nx = a[0].size();
        sum.assign(ny+1, vector<T>(nx+1, 0));
        for(int i=0; i<ny; ++i){
            for(int j=0; j<nx; ++j){
                sum[i+1][j+1] = a[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
            }
        }
    }
    T getSum(int y1, int x1, int y2, int x2)
    {
        y1 = max(y1, 0);
        x1 = max(x1, 0);
        y2 = min(y2, ny-1);
        x2 = min(x2, nx-1);
        if(y1 > y2 || x1 > x2)
            return 0;
        return sum[y2+1][x2+1] - sum[y1][x2+1] - sum[y2+1][x1] + sum[y1][x1];
    }
};

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

    vector<vector<int> > v(n, vector<int>(n, 0));
    for(int i=0; i<m; ++i){
        int l, r;
        cin >> l >> r;
        -- l;
        -- r;
        ++ v[l][r];
    }

    cumulativeSum<int> cs(v);
    while(--q >= 0){
        int p, q;
        cin >> p >> q;
        -- p;
        -- q;
        cout << cs.getSum(p, p, q, q) << endl;
    }

    return 0;
}


Measured memory_bytes: 2944
import numpy as np
N, M, X = map(int, input().split())
A = []
C = []
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)
A = np.array(A,dtype=int)
ans = 10 ** 7
for bit in range(2 ** N):
    B = np.zeros(M, dtype=int)
    cost = 0
    for i in range(N):
        if bit & (1<<i):
            B += A[i]
            cost += C[i]
    if np.all(B >= X):
        ans = min(ans, cost)
print(ans if ans < 10**7 else -1)


Measured memory_bytes: 27240
#include <stdio.h>

int n, A[50];

int solve(int i, int m)  {
  if (m == 0)
    return 1;
  if (i >= n)
    return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main(void)  {
  int i, q, m;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)  
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for (i = 0; i < q; i++)  {
    scanf("%d", &m);
    if (solve(0, m))
      printf("yes\n");
    else 
      printf("no\n");
  }  
  return 0;  
}  

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

int main()
{
	int n;
	cin >> n;
	int *a= new int[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	int *b= new int[n];
	b[0] =0;
	b[1]= abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		b[i]= min(b[i-1]+ abs(a[i-1]-a[i]), b[i-2]+ abs(a[i-2]-a[i]));
	}
	cout << b[n-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define INF 1<<30
typedef long long ll;
typedef pair<int, int> pi;

vector<pi>G[100005];
bool used[100005];

vector<pi>X;
vector<pi>Y;
int N;

int prim(){
  for(int i=0;i<N;i++){
    used[i] = false;
  }

  ll res = 0;

  priority_queue<pi, vector<pi>, greater<pi> >Q;
  Q.push(pi(0, 0));

  while(!Q.empty()){
    pi q = Q.top(); Q.pop();
    int p = q.second;
    int cost = q.first;
    if(used[p]) continue;

    res += cost;
    used[p] = true;

    for(int i=0;i<G[p].size();i++){
      pi next = G[p][i];
      Q.push(pi(next.second, next.first));
    }
  }

  return res;
}

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    int x, y; cin >> x >> y;
    X.push_back(pi(x, i));
    Y.push_back(pi(y, i));
  }

  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());

  for(int i=0;i<N-1;i++){
    G[X[i].second].push_back(pi(X[i+1].second, X[i+1].first-X[i].first));
    G[Y[i].second].push_back(pi(Y[i+1].second, Y[i+1].first-Y[i].first));
    G[X[i+1].second].push_back(pi(X[i].second, X[i+1].first-X[i].first));
    G[Y[i+1].second].push_back(pi(Y[i].second, Y[i+1].first-Y[i].first));        
  }

  cout << prim() << endl;
  return 0;
}


Measured memory_bytes: 11632
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

template<class Monoid>
class SegmentTree{
private:
  using T = typename Monoid::T;
  const size_t n;
  vector<T> d;

  void build(){
    for(size_t b = n - 1; b > 0; b--) d[b] = Monoid::op(d[b << 1], d[b << 1 | 1]);
  }

public:
  SegmentTree(size_t n)
    : n(n), d(2 * n, Monoid::identify()) {}

  template<typename InputItr>
  SegmentTree(InputItr first, InputItr last)
    : n(distance(first - last)), d(2 * n, Monoid::identify()){
    copy(first, last, next(d.begin(), n));
    build();
  }

  void modify(size_t k, T v){
    for(d[k += n] = v; k > 1; k >>= 1) d[k >> 1] = Monoid::op(d[k], d[k ^ 1]);
  }

  T query(T l, T r){
    T res {Monoid::identify()};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l&1) res = Monoid::op(res, d[l++]);
      if (r&1) res = Monoid::op(res, d[--r]);
    }
    return res;
  }

  void dump(){
    FOR(i, n, 2 * n) cout << i - n << ": " << d[i] << endl;
  }
};

template<typename U = ll>
struct RSQ{
  using T = U;
  static T op(const T& a, const T& b){ return a + b; };
  static constexpr T identify(){ return T(0); };
};

template<typename U = ll>
struct RMQ{
  using T = U;
  static T op(const T& a, const T& b){ return min<T>(a, b); };
  static constexpr T identify(){ return numeric_limits<T>::max(); };
};

int main() {
  int n, q; cin >> n >> q;
  SegmentTree<RMQ<int>> tree(n);

  while(q--){
    int c, x, y;
    cin >> c >> x >> y;

    switch(c){
      case 0:
        tree.modify(x, y);
        break;
      case 1:
        cout << tree.query(x, y+1) << endl;
        break;
    }

  }
  return 0;
}



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

using namespace std;

int main(){
    string S;
    int g=0,p=0,ans=0;
    cin >> S;
    for(int i=0;i<S.size();i++){
        if(p<g && S[i]=='g'){
            ans++;
            p++;
        }else if(p<g && S[i]=='p'){
            p++;
        }else if(S[i]=='g'){
            g++;
        }else{
            ans--;
            g++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[4444];
ll cnt[2222];
ll memo[2222];
signed main() {
	ll n, k, ans = 0;
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] > a[j])memo[a[i]]++;
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (a[i] > a[j])cnt[a[i]]++;
		}
	}
	rep(i, 2002) {
		ans += (memo[i] * k % inf + cnt[i] * (k * (k - 1) / 2 % inf) % inf);
		ans %= inf;
	}
	cout << ans << endl;
	ggr
}


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

int main(){
  int d,t,s;
  cin >> d >> t >> s;
  if(d<=t*s)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>

 int  main() {

	 int twn = 0;
	 int n;
	 std::vector<int> vec;
	 int ans = 1;
	 int ans2 = 1;

	 std::cin >> n;

	 for (int i = 0; i < n; ++i) {
		 
		 int a;

		 std::cin >> a;

		 if (a % 2 == 0) {
			 twn += 1;
		 }

	 }

	 for (int i = 0; i < n; ++i) {
		 ans *= 3;
	 }
	 for (int i = 0; i < twn; ++i) {
		 ans2 *= 2;
	 }

	 std::cout << ans - ans2 << std::endl;

}

Measured memory_bytes: 256
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = 0
for i in range(p):
  m = cnt[i]
  if i == 0 and m > 0:
    ans +=  (m*(m+1))//2
  else:
    ans += (m*(m-1))//2
print(ans)

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

int main() {
  string s;
  cin >> s;
  
  reverse(s.begin(), s.end());
  string tmp = "";
  int cnt = 0;
  for(const auto& e: s) {
    tmp = e + tmp;
    if(tmp == "dream" || tmp == "dreamer" || tmp == "erase" || tmp == "eraser") {
      cnt += tmp.size();
      tmp = "";
    }
  }
  
  if(cnt == s.size()) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include <map>
#include <cmath>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		int h;cin>>h;
		arr[i] = h;
	}
	int dp[n];
	dp[0] = 0; dp[1] = dp[0] + abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
C = []
c = 0
for i in range(n+1):
  c += abs(A[i+1] - A[i])
for i in range(1, n+1):
  print(c - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]))

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	char arr[h + 1][w + 1];
	int level[h + 1][w + 1];
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			cin >> arr[i][j], level[i][j] = 1e9;
	level[r1][c1] = 0;

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

	deque <int> dq;

	dq.push_back(r1);
	dq.push_back(c1);

	while (!dq.empty()) {
		int x = dq.front();
		dq.pop_front();
		int y = dq.front();
		dq.pop_front();
		for (int i = 0; i < 4; ++i) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx > 0 and nx <= h and ny > 0 and ny <= w and arr[nx][ny] == '.' and level[nx][ny] > level[x][y]) {
				level[nx][ny] = level[x][y];
				dq.push_front(ny);
				dq.push_front(nx);
			}
		}
		for (int nx = x + 2; nx >= x - 2; --nx) {
			for (int ny = y + 2; ny >= y - 2; --ny) {
				if (nx > 0 and nx <= h and ny > 0 and ny <= w and arr[nx][ny] == '.' and level[nx][ny] > level[x][y] + 1) {
					level[nx][ny] = level[x][y] + 1;
					dq.push_back(nx);
					dq.push_back(ny);
				}
			}
		}
	}
	cout << (level[r2][c2] == 1e9 ? -1 : level[r2][c2]) << endl;
}

Measured memory_bytes: 8460
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion


void printout(vector<int> v, int N){
    rep(i, N){
        if(i > 0){
            cout << " ";
        }

        cout << v.at(i);
    }

    cout << endl;
}

void insertionSort(vector<int> &v, int &N){
    int k,j;
    rep1(i, N - 1){

        k = v.at(i);
        j = i - 1;

        while(j >= 0 && v.at(j) > k){
            v.at(j + 1) = v.at(j);
            j--;
        }
        v.at(j + 1) = k;

       printout(v, N);
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);

    rep(i, N){
        cin >> v.at(i);
    }

    printout(v,N);
    insertionSort(v, N);
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll D;

int main() {
  cin >> N >> D;
  ll dd;
  dd = D * D;
  int ans = 0;
  for (int i = 0; i < N; i++) {
  	ll x, y;
    cin >> x >> y;
    if (((x * x) + (y * y)) <= dd ) ans += 1;
  }
  cout << ans;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	n %= 10;
	if( n == 3 ) cout << "bon" << endl;
	else if( n == 0 or n == 1 or n == 6 or n == 8 ) cout << "pon" << endl;
	else cout << "hon" << endl;
}

Measured memory_bytes: 3624
N = int(input())
s_list = []
t_list = []
for i in range(N):
    s, t = input().split()
    s_list.append(s)
    t_list.append(int(t))

x = input()
ans = 0
for i in range(N):
    ans += t_list[i]
    if x == s_list[i]:
        break
print(sum(t_list) -  ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	int h,w;
	do{
		scanf("%d%d",&h,&w);
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				printf("#");
			}
			printf("\n");
		}
		if(!(h&&w))break;
		printf("\n");
	}while(1);
	return 0;

}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

lli getLisLength(vector<lli> a) {
  vector<lli> dp(a.size() + 3, 1e18);
  rep(i, a.size()) { *lower_bound(dp.begin(), dp.end(), a[i]) = a[i]; }
  return lower_bound(dp.begin(), dp.end(), 1e18) - dp.begin();
}
vector<lli> dp;
vector<int> e[200005];
int par[200005][20];
lli a[200005];
int ans[200005];
void dfs(int u, int p) {
  auto it = lower_bound(dp.begin(), dp.end(), a[u]);
  lli prev = *it;
  *it = a[u];
  ans[u] = lower_bound(dp.begin(), dp.end(), 1e18) - dp.begin();
  for (auto s : e[u]) {
    if (s == p)
      continue;
    dfs(s, u);
  }
  *it = prev;
}

void solve(long long N, std::vector<long long> u, std::vector<long long> v) {
  rep(i, N - 1) e[u[i] - 1].push_back(v[i] - 1);
  rep(i, N - 1) e[v[i] - 1].push_back(u[i] - 1);
  dp.assign(200005, 1e18);
  dfs(0, -1);
  rep(i, N) cout << ans[i] << endl;
}

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

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 32600
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    int flag = 0;

    if(S[A] != '-') {
        flag = 1;
    }
    else {
        for(int i = 0; i <= A+B; i++) {
            if(i == A) {
                continue;
            }
            
            if(S[i] == '-') {
                flag = 1;
            }
        }
    }

    if(flag == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        System.out.println(n * a < b ? n * a : b);

    }
}

Measured memory_bytes: 22228
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();

        double ans = 0;
        for (int i = 0; i < n; i++) {
            double value = std.nextDouble();
            String unit = std.next();
            if (unit.equals("BTC")) {
                double btcRate = 380000.0;
                ans += value * btcRate;
            } else if (unit.equals("JPY")) {
                ans += value;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[][] miti=new int[N][2];
		int[] diff=new int[N];
		int wa=0;

		for(int i=0; i<2; i++) {
			for(int j=0; j<N; j++) {
				miti[j][i]=sc.nextInt();
			}
		}
		int c_max=-114514;
		int tmp=0;
		for(int i=0; i<N; i++) {
			tmp=0;
			for(int j=0; j<N; j++) {
				if(j<=i) {
					tmp+=miti[j][0];
				}
				else {
					tmp+=miti[j][1];
				}
				if(j==i) {
					tmp+=miti[j][1];
				}
			}
			if(tmp>c_max) {
				c_max=tmp;
			}
		}
		System.out.println(c_max);
	}
}

Measured memory_bytes: 23764
#!/mnt/c/Users/moiki/bash/env/bin/python
N,P = list(map(int, input().split()))
import math

if N == 1:
    print(P)
    exit(0)

def get_prime(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

primax = int(1e7) + 9 * int(1e6)
primes = get_prime(primax)
# print(primes)
# print(len(primes))



def df(P, p):
    if P >= p:
        cnt = 0
        while P >= p and P % p == 0:
            P = int(P//p)
            cnt += 1
        return cnt
    else:
        raise "P , p error."

gc = []
for p in primes:
    if P % p == 0:
        cnt = df(P, p)
        P = int( P // int(p**cnt))
        gc.append([p, cnt])
ans = 1
for g,cnt in gc:
    if cnt >= N:
        ans *= g**(cnt//N)

debug = 1
for g,cnt in gc:
    debug *= g**cnt

# N > 100:  why WA
# debug < P: under 3 RE
# debug*2 > P:  None
if P > 1e9 and debug != P and  debug < P and N == 1:
    raise "errror"
print(ans)


Measured memory_bytes: 219660
#include<vector>
#include<cstdio>
#include<queue>
using namespace std;

#define f first
#define s second
#define Pii pair<int,int>

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

int bfs(vector< vector<int> > &wall, vector< vector<int> > &done) {
  queue<Pii> Q;
  Q.push(Pii(0, 0));
  done[0][0] = 1;

  while(!Q.empty()) {
    Pii p = Q.front();
    Q.pop();

    if(p.f == w-1 && p.s == h-1)
      return done[h-1][w-1];

    for(int i=0; i<4; ++i) {
      if(p.f+dx[i] >= 0 && p.f+dx[i] < w && p.s+dy[i] >= 0 && p.s+dy[i] < h)
	if((wall[p.s][p.f]>>i)%2 == 0 && done[p.s+dy[i]][p.f+dx[i]] == 0) {
	  Q.push( Pii(p.f+dx[i], p.s+dy[i]) );
	  done[p.s+dy[i]][p.f+dx[i]] = done[p.s][p.f]+1;
	}
    }
  }
  return 0;
}

int main() {

  int tmp;
  while(scanf("%d %d", &w, &h), w&&h) {
    vector< vector<int> >wall (h, vector<int>(w, 0));
    vector< vector<int> >done (h, vector<int>(w, 0));
    for(int i=0; i<2*h-1; ++i) {
      if(!(i%2))
	for(int j=0; j<w-1; ++j) {
	  scanf("%d",&tmp);
	  if(tmp) {
	    wall[i/2][j] |= 4;
	    wall[i/2][j+1] |= 8;
	  }
	}
      else
	for(int j=0; j<w; ++j) {
	  scanf("%d",&tmp);
	  if(tmp) {
	    wall[i/2][j] |= 1;
	    wall[i/2+1][j] |= 2;
	  }
	}
    }
    printf("%d\n", bfs(wall,done) );
  }
}

Measured memory_bytes: 0
public class Main {

  private static void solve() {
    long n = nl();
    System.out.println(f(n));

  }

  private static long f(long n) {
    if (n % 2 == 1) {
      return 0;
    } else {
      n /= 2;

      long ret = 0;
      while (n > 0) {
        ret += n / 5;
        n /= 5;
      }
      return ret;
    }
  }


  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 23252
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int R = sc.nextInt();
        //String[] str = new String[N];
        int ans = 0;
        
        if(N >= 10){
            ans = R;
        }else{
            ans = R + 100*(10-N);
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 35852
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll N, M, v, p;
V A;
ll tmp[NUM];
ll check(ll idx){
    rep1(i, N)tmp[i] = A[i];
    ll sum = M * v;
    for(ll i = idx; i <= N; i++, sum -= M){
        if(sum <= 0)break;
        tmp[i] += M;
    }
    for(ll i = 1; i < p; i++, sum -= M){
        if(sum <= 0)break;
        tmp[i] += M;
    }
    for(ll i = p; i < idx; i++){
        if(sum <= 0)break;
        ll hoge = tmp[idx] - tmp[i];
        if(hoge < 0)return 0;
        tmp[i] += hoge;
        sum -= hoge;
    }

    if(sum > 0)return 0;
    if(tmp[idx] < tmp[p])return 0;
    return 1;
}

int main(){
    cin >> N >> M >> v >> p;
    A = V(N);
    rep(i, N)cin >> A[i];
    A.push_back(INF);
    sort(A.begin(), A.end(), greater<ll>());
    ll ok = 1, ng = N + 1;
    while(ok + 1 < ng){
        ll mid = (ok + ng) / 2;
        if(check(mid))ok = mid;
        else ng = mid;        
    }
    cout << ok << endl;

    return 0;
}



Measured memory_bytes: 1792
//abc122_c.cpp
//Sat Apr  6 18:42:02 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;

	int ac[s.length()];
	ac[0]=0;
	for (int i=1;i<s.length();i++){
		if (s[i-1]=='A' && s[i]=='C'){
			ac[i]=ac[i-1]+1;
		}else{
			ac[i]=ac[i-1];
		}
	}

	int l[q],r[q];
	for (int i=0;i<q;i++){
		cin >> l[i] >> r[i];
		l[i]--;
		r[i]--;
		if (l[i]==0){
			cout << ac[r[i]] << endl;
		}else {
			int temp = ac[r[i]]-ac[l[i]-1];
			if (s[l[i]-1]=='A' && s[l[i]]=='C'){
				temp--;
			}
			cout << temp << endl;
		}
	}
}

Measured memory_bytes: 2176
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], t;

void dfs_visit(int u) {
   int i;
   color [u] = GRAY;
   d[u] = ++t;

   for ( i = 0; i < n; i++ ) {
      if (M[u][i] == 0 ) continue;
      if ( color[i] == WHITE ) {
         dfs_visit(i);
      }
   }

   color[u] = BLACK;
   f[u] = ++t;
}

void dfs() {
   int u;

   for ( u = 0; u < n; u++ ) color[u] = WHITE;
   t = 0;

   for ( u = 0; u < n; u++ ) {
      if ( color[u] == WHITE ) dfs_visit(u);
   }

   for ( u = 0; u < n; u++ ) {
      printf("%d %d %d\n", u + 1, d[u], f[u]);
   }
}

int main() {
   int u, v, k, i, j;

   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
      for ( j = 0; j < n; j++ ) M[i][j] = 0;
   }

   for ( i = 0; i < n; i++ ) {
      scanf("%d %d", &u, &k );
      u--;
   
      for ( j = 0; j < k; j++) {
         scanf("%d", &v);
         v--;
         M[u][v] = 1;
      }
   }

   dfs();

   return 0;
}

Measured memory_bytes: 1808
using System;
using System.Collections.Generic;

namespace tokiomarine2020_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var A = CIn.ReadInt();
      var V = CIn.ReadInt();
      var B = CIn.ReadInt();
      var W = CIn.ReadInt();
      var T = CIn.ReadInt();

      var dist = Math.Abs(A - B);
      var speed = V - W;

      Console.WriteLine(speed > 0 && (double)dist / speed <= T ? "YES" : "NO");
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 27776
#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 long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) out("Case #" << i << ": " << solve());
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())
#define findsm(u, x) (u.find(x) != u.end())
#define findstr(s, x) (s.find(x) != string::npos)
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 2e5, MOD = 998244353, SIZE = 2e7, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
ll n, a[MAXN], x;

//<<-----Implement Functions Here---->>//
void solve()
{
    in(n)
	x = 0;
	FOR(i, 0, n)
		cin >> a[i], x ^= a[i];
	FOR(i, 0, n)
		cout << (a[i] ^ x) << ' ';
}

//<<----------Start of Main---------->>//
int main()
{
    fastio
    //ts
    solve();
    return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

vector<int> e1[200000], e2[200000];
int par1[200000], par2[200000], visit1[200000], visit2[200000];

void dfs1(int now, int par){
	visit1[now] = 1;
	par1[now] = par;
	REP(i,e1[now].size()){
		int next = e1[now][i];
		if (visit1[next]) continue;
		dfs1(next, par);
	}
}

void dfs2(int now,int par){
	visit2[now] = 1;
	par2[now] = par;
	REP(i,e2[now].size()){
		int next = e2[now][i];
		if (visit2[next]) continue;
		dfs2(next, par);
	}
}

int main(){
	int n,k,l;
	cin >> n >> k >> l;
	
	REP(i,k){
		int p,q;
		scanf("%d %d",&p, &q);
		p--;
		q--;
		e1[p].push_back(q);
		e1[q].push_back(p);
	}
		REP(i,l){
		int p,q;
		scanf("%d %d",&p,&q);
		p--;
		q--;
		e2[p].push_back(q);
		e2[q].push_back(p);
	}
	
	
	REP(i,n){
		if (!visit1[i]) dfs1(i,i);
	}
	REP(i,n){
		if (!visit2[i]) dfs2(i,i);
	}
	
	map<pair<int, int>,int> mp;
	REP(i,n){
		mp[make_pair(par1[i],par2[i])]++;
	}
	
	REP(i,n){
		cout << mp[make_pair(par1[i], par2[i])] << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 29440
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans = 0;
		for(long i = 1; i < N; i++) {
			ans += i;
		}
		System.out.println(ans);
	}
}


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

ll N, Q;

int main(){
  cin >> N >> Q;
  vector<vector<ll> > g(N+1);
  vector<ll> ans(N+1, 0);
  vector<bool> vsd(N+1, 0);
  
  for(ll i = 1; i <= N-1; i++){
    ll a, b; cin >> a >> b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  for(ll i = 1; i <= Q; i++){
    ll p, x; cin >> p >> x;
    ans[p] += x;
  }
  
  queue<ll> que;
  que.push(1);
  vsd[1] = true;
  
  while(!que.empty()){
    ll now = que.front(); que.pop();
    for(auto e: g[now]){
      if(vsd[e]) continue;
      ans[e] += ans[now];
      que.push(e);
      vsd[e] = true;
    }
  }
  
  for(ll i = 1; i <= N; i++){
    cout << ans[i] << ' ';
  }
}

Measured memory_bytes: 17904