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

struct Node{
  struct Node *right;
  struct Node *left;
  struct Node *parent;
  int key;
};

Node *root,*NIL;

Node *treeMinimum(Node *x){
    while(x->left!=NIL)x=x->left;
    return x;
}

Node *treeMaximum(Node *x){
    while(x->right!=NIL)x=x->right;
    return x;
}

Node *treeSearch(Node *u, int k){
    while(u!=NIL && k!=u->key){
        if(k<u->key)u=u->left;
        else u=u->right;
    }
    return u;
}

Node *treeSuccessor(Node *x){
    if(x->right!=NIL)return treeMinimum(x->right);
    Node *y=x->parent;
    while(y!=NIL&&x==y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(Node *z){
  Node *y;
  Node *x;
  
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL){
      x=y->left;
  }else{
      x=y->right;
  }
  
  if(x!=NIL){
      x->parent=y->parent;
  }
  
  if(y->parent==NIL){
      root=x;
  }else{
      if(y==y->parent->left){
          y->parent->left=x;
      }else{
          y->parent->right=x;
      }
  }
  
  if(y!=z){
      z->key=y->key;
  }
  
  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node*)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
      y=x;
      if(z->key<x->key){
          x=x->left;
      }else{
          x=x->right;
      }
  }
  z->parent=y;
  if(y==NIL){
      root=z;
  }else{
      if(z->key<y->key){
          y->left=z;
      }else{
          y->right=z;
      }
  }
}

void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node *t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 26584
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	let c = v[2];
	let mut cnt = 0;
	let v:Vec<i32> = procon_read();
	let b = v.clone();
	for i in 0..n {
		let v:Vec<i32> = procon_read();
		let a = v.clone();
		let mut d = 0;
		for j in 0..m {
			d += a[j as usize]*b[j as usize];
		}
		if d + c > 0 {
			cnt += 1;
		}
	}
	println!("{}", cnt);
}

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

int main() {
  string s;
  cin >> s;
  if (s=="RRR") cout << 3 << endl;
  else if (s=="SRR" || s=="RRS") cout << 2 << endl;
  else if (s=="SSS") cout << 0 << endl;
  else cout << 1 << endl;

  return 0;
}

Measured memory_bytes: 3616
import math
Q=int(input())
ab=[list(map(int,input().split())) for _ in range(Q)]

for a,b in ab:
    
    if a>b:
        a,b=b,a
    if a==b:
        print(2*(a-1))
        continue
        
    c = math.ceil((a*b)**0.5-1)
    
    if c*(c+1)>=a*b:
        print(2*(c-1))
    else:
        print(2*c-1)

Measured memory_bytes: 3060
s = int(input())

def f(n):
    return int(n/2) if n%2==0 else 3*n+1

# パリティがあるのかな？
a = [s]
while(not f(a[-1]) in a):
    a.append(f(a[-1]))
else:
    print(len(a)+1)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C,D,E,x,y,cou=0,v[3];
    char S[3],s[3],X,Y;
    scanf("%d %d",&A,&B);
    printf("%d",(B-A)*2+A);
    return 0;
}

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

a = list(map(int, input().split()))

# 負の数が偶数の時、全てのを非負に変換可能
# 奇数の時、一つを除いて非負に変換可能、絶対値が最小の値を選択する

cnt_minus = sum([1 if v < 0 else 0 for v in a])

list_abs = list(map(abs, a))
sum_abs = sum(list_abs)
min_abs = min(list_abs)

if cnt_minus % 2 == 0:
    ans = sum_abs
else:
    ans = sum_abs - 2*min_abs

print(ans)
    

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, m;
    cin>> n;
    if(n== 0)
    {
        cout<<  "No\n";
        return 0;

    }
    if(n%4== 0 || n%7== 0)
    {
        cout<<  "Yes\n";
        return 0;
    }

    m= n/ 7;


    while (m> 0)
    {
        if((n- (m*7)) % 4== 0)
        {
            cout<<  "Yes\n";
            return 0;
        }
        m--;
    }
    cout<<  "No\n";

    return 0;
}




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

int main()
{
    int a,b,c,d;
    while(~scanf("%d",&a))
    {
        if(a==1)
            printf("Hello World\n");
        if(a==2)
        {
            scanf("%d %d",&c,&d);
            printf("%d\n",c+d);
        }

    }
}


Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		// 読み込み
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = (X / 500) * 1000;
      	int b = ((X % 500) / 5) * 5;
      
      	System.out.println(a + b);
	}
}

Measured memory_bytes: 22612
import java.util.Scanner;
import java.io.*;

public class Main {
	public static void main(String[] args)throws IOException {
		Scanner scan = new Scanner(System.in);
		InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
		char smallL[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		int A[] = new int[smallL.length];
		String str;
		char[] charArray;

		while((str = br.readLine()) != null){
			str = str.toLowerCase();
			charArray = str.toCharArray();
			for(int i = 0 ; i < charArray.length ; i++){
				for(int j = 0 ; j < smallL.length ; j++){
					if(charArray[i] == smallL[j]){
						++A[j];
						break;
					}
				}
			}
		}

		for(int i = 0 ; i < smallL.length ; i++){
			System.out.println(smallL[i] + " : " + A[i]);
		}

	}
}

Measured memory_bytes: 26172
two_num = input()
two_num = two_num.split(' ')

for i in range(2):
    two_num[i] = int(two_num[i])

if two_num[0] < two_num[1]:
    print("a < b")
elif two_num[0] > two_num[1]:
    print("a > b")
else:
    print("a == b")

Measured memory_bytes: 7628
def jam(n,k):
    return((n*(n+1)/2)-((n-k)*(n-k+1)/2)-(k*(k-1)/2)+1)
n,k=map(int,input().split( ))
s=0
for i in range(k,n+2):
    s+=jam(n,i)
print(int(s%(10**9+7)))


Measured memory_bytes: 67556
n = int(input())
A = list(map(int, input().split()))

B = [0]*n

for i in reversed(range(n)):
    j = i+1
    cnt = 0
    while j <= n:
        cnt += B[j-1]
        j += i+1
    if cnt%2 != A[i]:
        B[i] = 1

m = 0
ans = []
for i, b in enumerate(B):
    if b != 0:
        m += 1
        ans.append(i+1)
print(m)
if len(ans) > 0:
    print(*ans)

Measured memory_bytes: 66780
N,x = list(map(int,input().split(' ')))
a = list(map(int,input().split(' ')))

count = 0

i = 0
pre = 0
while i < N:
    if pre + a[i] > x:
        pre = x - pre
        count += a[i] - pre
    else:
        pre = a[i]
    i += 1

print(count)

Measured memory_bytes: 14288
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        forr(i,0,5) {
            readint(kk);
            if (kk==0) {
                cout << i+1 << endl;
            }
        }                
    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 3624
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
i = 0
mi = x[-1] - x[0] + min(abs(x[-1]),abs(x[0]))
if n == 1:
    print(abs(x[0]))
    exit()
while i <= n - k:
    if mi >= ( x[i + k - 1] - x[i]) + min(abs(x[i + k - 1]),abs(x[i])):
        mi = (x[i + k - 1] - x[i]) + min(abs(x[i + k - 1]),abs(x[i]))
    i += 1
print(mi)

Measured memory_bytes: 14844
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define INF 1<<25
 
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}


int main(){
	int A,B,C,D,E,F;
	double mx=-1,ans1,ans2;
	cin>>A>>B>>C>>D>>E>>F;
	for(int i=0;A*100*i<=F;i++){
	  for(int j=0;A*100*i+B*100*j<=F;j++){
	    for(int k=0;A*100*i+B*100*j+C*k<=F;k++){
		  for(int l=0;A*100*i+B*100*j+C*k+D*l<=F;l++){
			int w=A*100*i+B*100*j;
			int s=C*k+D*l;
			if(w*E/100<s)break;
			if(w+s==0)break;
			if(mx<((double)100*s/(w+s))){
				ans1=w+s;
				ans2=s;
				mx=(double)100*s/(w+s);
			}
		  }
		}
	  }
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1e+9;

int main(){
	int n,m,dist[21][21];
	
	for(int i=0 ; i < 21 ; i++ )
		for(int j=0 ; j < 21 ; j++ )
			dist[i][j] = INF;

	scanf("%d %d", &n, &m);
	for(int i=0 ; i < m ; i++ ){
		int a,b,c,d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		dist[a][b] = c;
		dist[b][a] = d;
	}
	for(int k=1 ; k <= n ; k++ ){
		for(int i=1 ; i <= n ; i++ ){
			for(int j=1 ; j <= n ; j++ ){
				dist[i][j] = min( dist[i][j] , dist[i][k]+dist[k][j] );
			}
		}
	}
	int x1,x2,y1,y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	int ans = y1 - (y2 + dist[x1][x2] + dist[x2][x1]);
	printf("%d\n", ans );
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
	int a,w,b;
	scanf("%d%d%d",&w,&a,&b);
	if(a+w<b)
	printf("%d\n",b-a-w);
	else if(a>b+w)
	printf("%d\n",a-b-w);
	else 
	printf("0\n");
}

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

int main(){
    string S;
    cin>>S;
    bool flag = true; 

    for(int i=0;i<S.size();i++){
        if((i+1)%2 != 0){
            if(S[i] == 'L'){
                flag = false;
                //cout<<i<<"word"<<S[i]<<endl;
              	//cout<<S.size();
                break;
            }
        }
        else
        {
            if(S[i] == 'R'){
                flag = false;
                //cout<<i<<"word"<<endl;
                break;
            }
        }
    }

    if(flag == true)
        cout<<"Yes"<<endl;
    if(flag == false)
        cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
f = 0
l = []
for i in range(n):
  l.append(list(map(int, input().split())))
for i in range(n-2):
    if (l[i][0] == l[i][1]) and (l[i+1][0] == l[i+1][1]) and (l[i+2][0] == l[i+2][1]):
        f = 1
if f == 1:
    print("Yes")
else:
    print("No")

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n,k,a[maxn];

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

  cin>>n>>k;
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ll tot=0;
  for (int i=k; i<n; i++) tot+=a[i];
  out(tot);
  

  return 0;
}


Measured memory_bytes: 1024
<?php
$s = trim(fgets(STDIN));

$arr = [];
$arr['a'] = 0;
$arr['b'] = 0;
$arr['c'] = 0;

for ($i = 0; $i < 3; $i++) {
    $arr[$s[$i]]++;

    if ($arr[$s[$i]] > 1) {
        echo 'No' . PHP_EOL;
        exit;
    }
}

echo 'Yes' . PHP_EOL;

Measured memory_bytes: 4856
N=int(input())
K=int(input())
dp1=[[0 for _ in range(4)] for _ in range(101)]
dp2=[[0 for _ in range(4)] for _ in range(101)]
dp1[0][0]=1
for i in range(1, 101):
    dp1[i][0]=1
    for j in range(1, 4):
        dp1[i][j]=dp1[i-1][j-1]*9+dp1[i-1][j]
dp2[0][1]=1
for i in range(1, 101):
    dp2[i][1]=dp1[i][1]+1
    dp2[i][2]=dp1[i][2]
    dp2[i][3]=dp1[i][3]
ans=0
i=len(str(N))-1
cnt=0
while i>=0:
    k=int(str(N)[len(str(N))-1-i])
    if k==0:
        i-=1
        continue
    ans+=dp2[i][K-cnt]
    cnt+=1
    if K-cnt<0:
        break
    ans+=dp1[i][K-cnt]*(k-1)
    i-=1
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
int main() {
	
	int panjang1;
	int panjang2;
	int panjang3;
	
	scanf("%d", &panjang1);
	scanf("%d", &panjang2);
	scanf("%d", &panjang3);
	
	printf("%d", (panjang1*panjang2)/2);
	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N;
    cin >> N;
    vector<int> r(N),l(N);

    ll ans = 0 ;
    
    for(int i = 0;i < N;i++){
        cin >> r.at(i) >> l.at(i);
        ans += l.at(i) - r.at(i) + 1; 
    }

    cout << ans << endl;

}

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

def solve(N, A, x):
    W=sum(x)
    dp=[[[0]*(W+1) for _ in range(N+1)] for _ in range(N+1)]
    for j in range(N+1):
        dp[j][0][0]=1
    for j in range(1,N+1):
        xj=x[j-1]
        for k in range(1, N+1):
            for s in range(1, W+1):
                if s<xj:
                    dp[j][k][s]=dp[j-1][k][s]
                else:
                    dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-xj]

    ans=0
    for k in range(1,N+1):
        if k*A<=W:
            ans+=dp[N][k][k*A]
        else:
            break
    return ans


def main(args):
    N,A=map(int, input().split())
    x=[int(x) for x in input().split()]
    ans=solve(N,A,x)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define fst first
#define scd second
#define PB push_back

using data=tuple<int,int,int>;
using P=pair<int,data>;

const int inf = 1e9;

struct edge{int to,cost;};
vector<edge> G[10010];

int d[10010][2][205];

int n,m,x;
int t[10010];

signed main()
{
    cin>>n>>m>>x;

    rep(i,n){
        cin>>t[i];
        if (t[i]==2)t[i]=1;
        else if (t[i]==1)t[i]=2;
    }

    rep(i,m) {
        int a,b,d;cin>>a>>b>>d;
        --a,--b;
        G[a].PB(edge{b,d});
        G[b].PB(edge{a,d});
    }

    priority_queue<P,vector<P>,greater<P>> q;

    rep(i, n) rep(j, 2) rep(k, 205) d[i][j][k] = inf;
    d[0][0][0] = 0;

    q.push(P(0, data(0, 0, 0)));

    while (q.size()) {
        P p = q.top(); q.pop();

        int dist = p.fst;
        int v, type, tim;
        tie(v,type,tim) = p.scd;

        if (d[v][type][tim] < dist) continue;

        if (v == n-1) {
            cout << dist << endl;
            return 0;
        }

        //for (edge &e : G[v]) {
        //    int u, ntype, ntim;
        //    if (t[e.to] == 2) {
        //        u = e.to, ntype = type, ntim = min(x, tim+e.cost);
        //    } else {
        //        if (t[v] != t[e.to] && tim + e.cost < x) continue;
        //        u = e.to, ntype = t[e.to], ntim = 0;
        //    }

        //    if (d[u][ntype][ntim] > d[v][type][tim] + e.cost) {
        //        d[u][ntype][ntim] = d[v][type][tim] + e.cost;
        //        q.push(P(d[u][ntype][ntim], data(u, ntype, ntim)));
        //    }
        //}
        for (edge &e : G[v]) {
            if (t[e.to] == 2) {
                int ntim = min(x, tim+e.cost);
                if (d[e.to][type][ntim] > d[v][type][tim] + e.cost) {
                    d[e.to][type][ntim] = d[v][type][tim] + e.cost;
                    q.push(P(d[e.to][type][ntim], data(e.to, type, ntim)));
                }
            } else {
                if (type != t[e.to] && tim + e.cost < x) continue;
                if (d[e.to][t[e.to]][0] > d[v][type][tim] + e.cost) {
                    d[e.to][t[e.to]][0] = d[v][type][tim] + e.cost;
                    q.push(P(d[e.to][t[e.to]][0], data(e.to,t[e.to],0)));
                }
            }
        }
    }
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int d,t,s;
    cin >> d >> t >> s;
    if(d > t * s) No();
    else Yes();
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define nax (int)2e5+2
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
using namespace std;
 



int main() 
{ 
	ll n;
	cin>>n;
	vector<ll> values;
	for(ll i=0;i<n;i++){
		ll temp;
		cin>>temp;
		values.pb(temp);
	}
	map<ll,ll> m;
	ll ans = 0;
	for(ll i=0;i<n;i++){
		m[values[i]]++;
	}
	for(auto it: m){
		ll temp = (it.y)*(it.y-1);
		temp =temp/2;
		ans += temp;
	}
	//deb(ans);
	for(ll i =0;i<n;i++){
		ll temp = (m[values[i]])*(m[values[i]]-1);
		temp =temp/2;
		ll anstemp = ans - temp;
		//deb(anstemp);
		temp = (m[values[i]]-1)*(m[values[i]]-2);
		temp = temp/2;
		anstemp += temp;
		cout<<anstemp<<"\n";
	}
	
	
	return 0; 
} 


Measured memory_bytes: 11120
n=int(input())
a=list(map(int,input().split()))
a.reverse()
l=[0]*n
l[0]=a[0]
for i in range(n-1):
  l[i+1]=l[i]+a[i+1]
ans=0
mod=10**9+7
for j in range(1,n):
  ans+=(a[j]*l[j-1])%mod
print(ans%mod)

Measured memory_bytes: 31824
import java.util.*;
public class Main {
	public static void main(String[] args) {
		B();
	}
	
	public static void A() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		System.out.println(Math.min(A*N, B));
	}
	
	//calc harshad
	public static int calchar(int x) {
		int sum = 0;
		String num = ((Integer) x).toString();
		for(int i=0;i<num.length();i++) {
			sum += Character.getNumericValue(num.charAt(i));
		}
		return sum;
	}
	
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = calchar(n);
		if(n%sum==0) System.out.println("Yes");
		else System.out.println("No");
	}
	/*
	 *  F i,j,k 店iが曜日jの時間帯kに開いているか
	 *  ci 本店と店iが同時に開いている時間帯の数
	 *  店の利益 P_1,c1 + Pncn  利益の最大値を求める
	 *  全部で 2^10通り 1000なので容易に行うことが可能
	 *  というか、時間帯ごとに関係はないので、10こ確かめる　（利益が正ならひらく）
	 *  また、利益が最大の時間帯を保持しておき、どうやっても利益がマイナスならそれを返す
	 *  ではない、何個かぶるかが重要 以下では、2^10
	 */
	public static void C() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int F[][] = new int[N][10];
		int P[][] = new int[N][11];
		for(int i=0;i<N;i++) {
			for(int j=0;j<10;j++) {
				F[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<N;i++) {
			for(int j=0;j<11;j++) {
				P[i][j] = sc.nextInt();
			}
		}
		int counter = 1;
		int ret = Integer.MIN_VALUE;
		for(;counter<1024;counter++) {
			int nowsc = calcscore(counter,F,P);
			//System.out.println(nowsc);
			if(ret < nowsc) ret = nowsc;
		}
		System.out.println(ret);
	}
	// 2進数を受け取り、対応する曜日、時間帯が開催されているとして、スコアを返す 10桁 0001.. ~ 111.. 00000はない
	public static int calcscore(int bin, int[][] F, int [][] P) {
		int score = 0;
		int[] c = new int[F.length]; // 各店と同時に開いている回数
		for(int i=0;i<10;i++) {
			// if open
			if((bin & (1<<i)) != 0) {
				for(int j=0;j<F.length;j++) {
					if(F[j][i] == 1) c[j]++; 
				}
			}
		}
		for(int i=0;i<F.length;i++) {
			score += P[i][c[i]];
		}
		return score;
	}
	
	public static void D() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		List[] lis = new List[C];
		for(int i=0;i<C;i++) {
			lis[i] = new ArrayList<Integer>();
		}
		for(int i=0;i<N;i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			int c = sc.nextInt()-1;
			//if(c>C) System.out.println("N");
			lis[c].add(s);
			lis[c].add(t);
		}
		int[] sum = new int[20000];
		for(int i=0;i<C;i++) {
			updatesum(sum,lis[i]);
		}
		int max = 0;
		for(int i=0;i<20000;i++) {
			if(max < sum[i]) max = sum[i];
		}
		System.out.println(max);
		
	}
	//チャネルのsitiのlistを受け取り、sumの配列を更新する
	public static void updatesum(int[] sum, List<Integer> sche) {
		int[] temp = new int[sum.length];
		for(int i=0;i<sche.size();i+=2) {
			int st = sche.get(i)*2-1;
			int ed = sche.get(i+1)*2;
			for(int j=st;j<ed;j++) {
				temp[j] = 1;
			}
		}
		for(int i=0;i<sum.length;i++) {
			sum[i] += temp[i];
		}
	}
}

Measured memory_bytes: 23252
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
from itertools import permutations
l = list(range(1, n + 1))
np = 0
for x in permutations(l, n):
    np += 1
    if p == list(x): break
l = list(range(1, n + 1))
nq = 0
for x in permutations(l, n):
    nq += 1
    if q == list(x): break
print(abs(nq - np))

Measured memory_bytes: 3064
import heapq

x, y, a, b, c = map(int, input().split())

p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list.sort()
q_list.sort()
r_list.sort()

p_list.reverse()
q_list.reverse()
r_list.reverse()

p_ls = p_list[:x]
q_ls = q_list[:y]
r_ls = r_list[:min(x+y, c)]

heapq.heapify(p_ls)
heapq.heapify(q_ls)
r_ls = list(map(lambda x: x*(-1), r_ls))
heapq.heapify(r_ls)

while True:
    if len(r_ls) == 0:
        break
    elif (-r_ls[0]) < p_ls[0] and (-r_ls[0]) < q_ls[0]:
        break
    elif p_ls[0] < q_ls[0]:
        heapq.heappop(p_ls)
        heapq.heappush(p_ls, -heapq.heappop(r_ls))
    else:
        heapq.heappop(q_ls)
        heapq.heappush(q_ls, -heapq.heappop(r_ls))

print(sum(p_ls) + sum(q_ls))


Measured memory_bytes: 121424
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}

bool comp(const Pll &a, const Pll &b){
  return a.first + a.second > b.first + b.second;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n)cin >> a[i] >> b[i];
  vector<Pll> vec(n);
  rep(i, n){
    vec[i] = mk(a[i], b[i]);
  }
  sort(all(vec), comp);
  ll res = 0;
  rep(i, n){
    if(i % 2 == 0)res += vec[i].first;
    else res -= vec[i].second;
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
 }

int main(){
  int n, i, j,key;
  int A[N+1];
  scanf("%d", &n);

  for (i=1;i<=n;i++) scanf("%d", &A[i]);
  for(i=1;i<=n;i++){
    key=A[i]; 
    j=i-1;
    while(j>=0 && A[j]>key){
      A[j+1]=A[j];
      j--;}
    A[j+1]=key; 
    trace(A,n);
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define rep(j, n) for(int j = 0; j < (n); j++)
typedef long long ll;
typedef long double ld;
using namespace std;


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

  int n;
  string s;
  cin >> n >> s;
  int b = 0;
  for (char c : s) if (c == '#') b++;
  int mn = min(b, n - b);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    cur += s[i] == '#';
    mn = min(mn, cur + n - (i + 1) - (b - cur));
  }

  cout << mn << endl;
  return 0;
}

Measured memory_bytes: 720
#https://mirucacule.hatenablog.com/entry/2020/04/27/090908
#https://drken1215.hatenablog.com/entry/2020/04/29/171300

S=str(input())[::-1]#逆順で格納
N=len(S)
counter=[0]*2019
counter[0]=1
ans=0
num,d=0,1
for c in S:
    num += int(c) * d
    num %= 2019
    d *= 10
    d %= 2019
    counter[num]+=1
for i in counter:
    ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 9328
#include <stdio.h>
int main(void){
	int t;
	scanf("%d",&t);
	int byou;
	byou = t%60;
	int mina;
	int min;
	mina = (t - byou)/60;
	min = mina%60;
	int hour;
	hour = (mina - min)/60;
	printf("%d:%d:%d\n",hour,min,byou);
        return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 5010


int main(){
  int n,h[SIZE], p[SIZE];
  pair<pair<int,int>,pair<int,int> > player[SIZE];
  map<int,int> mm;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d%d",h+i,p+i);
    player[i] = {{h[i]+p[i], i},{h[i],p[i]}};
  }

  sort(player,player+n);
  

  ll dp[SIZE] = {};

  for(int i=0;i<=n;i++)
    dp[i] = LLINF;
  dp[0] = 0;

  for(int i=0;i<n;i++){
    int hi = player[i].second.first;
    int pi = player[i].second.second;
    
    for(int j=i;j>=0;j--){
      if(dp[j] <= hi){
        dp[j+1] = min(dp[j+1], dp[j]+pi);
      }
    }
    
  }

  int ans = 0;
  
  for(int i=0;i<=n;i++){
    if(dp[i] < LLINF)
      ans = i;
  }

  printf("%d\n",ans);

  
  
  return 0;
}



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

int main(){
    int k, n;
    cin >> k >> n;
    int a[n];
    for(int i = 0; i < n; i++)
       cin >> a[i];
       
    int ans=int(1e9);
    for(int i = 0; i < n; i++){
        int l = a[i];
        int r = a[(i+n-1)%n];
        if(l > r) r += k;

        ans = min(ans, r-l);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final long MOD = 1000000007;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long count = 1;
        boolean[] sieve = new boolean[1001];
        Arrays.fill(sieve, true);
        sieve[0] = false;
        sieve[1] = false;
        int index = 2;
        while(index * index <= 1000){
            if(sieve[index]){
                for (int i = index * index; i <= 1000 ; i += index) {
                    sieve[i] = false;
                }
            }
            index += 1;
        }
        ArrayList<Integer> prime = new ArrayList<>();
        for(int i = 2; i <= 1000; i++)
            if(sieve[i])  prime.add(i);
         index = 0;
         while(index < prime.size()){
             int curr = prime.get(index);
             int exp = curr;
             if(curr > n)
                 break;
             int factor = 0;
             while(exp <= n){
                 factor += n / exp;
                 exp *= curr;
             }
             count = (count * (factor + 1)) % MOD;
             index += 1;
         }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int h, w;
	cin >> h >> w;
	rep(i, h) {
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// Union-Find; 素集合データ構造
class UnionFind {
public:
    vector<long long> parent;
    long long n;
    UnionFind(long long x) :parent(x, -1), n(x){}
    bool unite(long long x, long long y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y]; parent[y] = x;
        return true; }
    bool same(long long x, long long y){ return find(x) == find(y); }
    long long find(long long x){ return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    long long size(long long x){ return -parent[find(x)]; }
};

int main(){
    Init();
    ll n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m){
        ll s, t;
        cin >> s >> t;
        s--, t--;
        uf.unite(s, t);
    }
    ll ans = 0;
    rep(i, n) chmax(ans, uf.size(i));
    cout << ans << endl;
}

Measured memory_bytes: 4780
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    lint ans=0;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
        int lo=A[j]-A[i]+1,hi=A[j]+A[i]-1;
        int bottom=lower_bound(A,A+N,lo)-A;
        int top=upper_bound(A,A+N,hi)-A;
        ans+=top-bottom;
        if(A[i]>=lo && A[i]<=hi) ans--;
        if(A[j]>=lo && A[j]<=hi) ans--;
    }
    cout << ans/3 << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

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

int N;
int A[2222];

vint G[22222];

bool ex[22222];
bool ok[22222];
bool vis[22222];

int dfs(int v){
    vis[v]=true;
    int ret=INF;
    if(ok[v])ret=A[v];
    for(auto u:G[v]){
        if(vis[u]||!ex[u])continue;
        chmin(ret,dfs(u));
    }
    return ret;
}

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];

    vint ps;
    rep(i,N){
        int a=A[i];
        for(int j=2;j*j<=a;j++){
            if(a%j)continue;
            ps.pb(j);
            while(a%j==0)a/=j;
        }
        if(a!=1)ps.pb(a);
    }
    sort(all(ps));ps.erase(unique(all(ps)),ps.end());

    rep(k,ps.size()){
        rep(i,N){
            if(A[i]%ps[k]==0){
                G[N+k].pb(i);
                G[i].pb(N+k);
            }
        }
    }

    rep(i,N)ok[i]=true;
    rep(i,N+ps.size())ex[i]=true;

    rep(i,N){
        memset(vis,0,sizeof(vis));

        int ei=-1;
        rep(j,N){
            if(vis[j]||!ex[j])continue;
            int tmp=dfs(j);
            if(tmp!=INF)chmax(ei,tmp);
        }
        int k=-1;
        rep(j,N)if(A[j]==ei&&ex[j])k=j;


        ex[k]=false;
        rep(j,N)if(ex[j]&&A[j]>A[k])ok[j]=false;
        rep(j,N)if(ex[j]&&gcd(A[j],A[k])!=1)ok[j]=true;


        if(i)cout<<" ";
        cout<<A[k];
    }cout<<endl;
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<PII> X(N);
    int NN = N*N;
    vector<int> ans(NN);
    rep(i, N) {
        int tmp; cin >> tmp;
        X[i] = PII(tmp-1, i+1);
    }
    sort(ALL(X));

    bool ok = true;

    for (auto x : X) {
        ans[x.first] = x.second;
        if (x.second == 1) continue;

        int cnt = 0;
        for (int i=0; i<x.first; i++) {
            if (ans[i] == 0) {
                ans[i] = x.second;
                cnt++;
            }

            if (cnt == x.second - 1) break;
        }

        if (cnt < x.second-1) {
            ok = false;
            break;
        }
    }

    for (int j=N-1; j>=0; j--) {
        PII x = X[j];
        if (x.second == N) continue;

        int cnt = 0;
        for (int i=NN-1; i>x.first; i--) {
            if (ans[i] == 0) {
                ans[i] = x.second;
                cnt++;
            }

            if (cnt == N - x.second) break;
        }

        if (cnt < N - x.second) {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "Yes" << endl;
        rep(i, NN) {
            if (i > 0) cout << " ";
            cout << ans[i];
        }
        cout << endl;
    } else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 2176
N,M = map(int,input().split())

through_list = []
for i in range(M):
    L,R = map(int,input().split())
    through_list.append([L,R])
through_list.sort()
ans_range = through_list[0]
for i in range(M-1):
    ans_range = [max(ans_range[0],through_list[i+1][0]),min(ans_range[1],through_list[i+1][1])]
ans = ans_range[1]-ans_range[0]+1 
ans = max(0,ans)
print(ans)

Measured memory_bytes: 20956
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
using namespace std;

int main()
{
    map<string, int> M;
    int query;
    scanf("%d", &query);

    int commend, value;
    string key;
    for (int i = 0; i < query; i++)
    {
        scanf("%d", &commend);
        if (0 == commend)
        {
            cin >> key >> value;
            M[key] = value;
        }
        else if (1 == commend)
        {
            cin >> key;
            if (M.count(key) != 0)
            {
                printf("%d\n", M[key]);
            }
            else
            {
                printf("%d\n", 0);
            }
        }
        else
        {
            cin >> key;
            //M<string, int>::iterator itr = M.find(key);
            M.erase(key);
        }
    }
    return 0;
}



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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int h, w, d;
	cin >> h >> w >> d;
	vector<PI> v(900009, { 0,0 });
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int a;
			cin >> a;
			v[a] = { j, i };
		}
	}
	VI dd(900009, 0);
	for (int i = 0; i < h * w; i++) {
		dd[i + d] = dd[i] + abs(v[i].first - v[i + d].first) + abs(v[i].second - v[i + d].second);
	}
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << dd[r] - dd[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  long a,b;
  cin >> a >> b;
  long ans = 0;
  if (a%2) ans ^= a++;
  if (!(b%2)) ans ^= b--;
  long n = (b-a+1)/2;
  ans ^= n%2;

  cout << ans << endl;
}


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

using namespace std;

int main()
{
    string a, b, u;
    int c, d;
    cin >> a >> b >> c >> d >> u;

    map<string, int> mp;
    mp[a] = c;
    mp[b] = d;
    --mp[u];

    cout << mp[a] << " " << mp[b] << endl;   
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

char num[1001];
int i=0;
int sum=1;
	while(sum!=0){
	sum=0;
	i=0;
		scanf("%c",&num[i]);
		while(num[i]!='\n'){
		i++;
		scanf("%c",&num[i]);
}
num[i]='\0';
i=0;
while(num[i]!='\0'){
sum+=num[i]-'0';
i++;
}
		if(sum!=0){
printf("%d\n",sum);
	}
}
return 0;
}

Measured memory_bytes: 536
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll f(ll n){
    ll k=1;
    rep(i,n) k*=3;
    return k;
}

int main(){
    ll b;
    cin>>b;
    string s;
    s=to_string(b);
    ll n=s.size();
    ll ans=0;
    for(int i=0;i<n;i++){
        ll m=f(i+1);
        for(int j=0;j<m;j++){
            ll a=j;
            V<bool> ok(3,0);
            string t;
            for(int k=0;k<i+1;k++){
                if(a%3==0){
                    t+='3';
                    ok[0]=1;
                }
                else if(a%3==1){
                    t+='5';
                    ok[1]=1;
                }
                else if(a%3==2){
                    t+='7';
                    ok[2]=1;
                }
                a/=3;
            }
            ll u=stoll(t);
            if(u<=b&&ok[0]&&ok[1]&&ok[2]) ans++;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    int k,p,z=0,c=0;

    cin >> k;



    for(int i=0;i<k;i++)
    {
        cin >> p;

        z++;

        if(p!=z)
        {
            c++;
        }


    }

    if(c<=2)
    {
        cout << "YES";
    }

    else

        cout << "NO";


    return 0;
}


Measured memory_bytes: 256
/*****include*****/
#include <iostream>
#include <fstream>
#include <queue>

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
/*****その他関数置き場*****/
/*****main関数*****/
int main(){
	/*****変数置き場*****/
	int width;
	int height;
	int pField[101][101];
	int pVisited[101][101];
	int xs,ys;
	int xg,yg;
	int xn,yn;
	int x2,y2;
	int c,d,x,y;
	int n;
	queue<int> Qx;
	queue<int> Qy;
	int cs;
	int dx[] = {0,1,0,-1};
	int dy[] = {-1,0,1,0};
	/*****ファイルオープン*****/	
	/*ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}*/
	
	/*****処理部*****/
	while(1){
		xn = 0;
		yn = 0;
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				pVisited[i][j] = 0;
				pField[i][j] = 0;
			}
		}
		cin >> width >> height;
		if(width == 0 && height == 0)	break;
		//int *pField = new int [height][width];
		//int *pVisited = new int [height][width];
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> c >> d >> x >> y;
			if(d==0){
				for(int j=0;j<2;j++){
					for(int k=0;k<4;k++){
						pField[j+y][k+x] = c;
					}
				}
			}else{
				for(int j=0;j<4;j++){
					for(int k=0;k<2;k++){
						pField[j+y][k+x] = c;
					}
				}
			}
		}
		/*for(int i=0;i<21;i++){
			for(int j=0;j<21;j++){
				cout << pField[i][j];
			}
			cout << endl;
		}*/
		cs = pField[ys][xs];
		//cout << cs << endl;
		Qx.push(xs);
		Qy.push(ys);
		pVisited[ys][xs] = 1;
		while(!(Qx.empty() && Qy.empty())){
			xn = Qx.front();
			Qx.pop();
			yn = Qy.front();
			Qy.pop();
			//cout << yn << " " << xn << endl;
			/*if(xn == xg && yn == yg){
				break;
			}*/
			for(int i=0;i<4;i++){
				x2 = xn + dx[i];
				y2 = yn + dy[i];
				if(pField[y2][x2]==cs){
					if(!pVisited[y2][x2]){
						Qx.push(x2);
						Qy.push(y2);
						pVisited[y2][x2] = 1;
					}
				}
			}
		}
		/*for(int i=0;i<21;i++){
			for(int j=0;j<21;j++){
				cout << pVisited[i][j];
			}
			cout << endl;
		}*/
		if(pVisited[yg][xg]){
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		}
	}
	/*****処理終了後*****/
	/*fout.close();
	fin.close();*/
	//delete[] pField;
	//delete[] pVisited;
	return 0;
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {
		UL X, Y, Z; cin >> X >> Y >> Z;
		cout << Z << " " << X << " " << Y << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  
  map<string, int> m;
  string cur, prev;
  for (int i = 0; i < n; ++i) {
    cin >> cur;
    if (m[cur] > 0) {
      cout << "No" << endl;
      return 0;
    }
    m[cur] = 1;

    if (prev != "") {
      if (prev[prev.size()-1] != cur[0]) {
        cout << "No" << endl;
        return 0;
      }
    }
    prev = cur;
  }

  cout << "Yes" << endl;

  return 0;
}

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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long count = 0;
		while (H > 0) {
			count++;
			H /= 2;
		}
		long answer = 1;
		for (int i = 0; i < count; i++) {
			answer *= 2;
		}

		System.out.println(answer - 1);
	}
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
long long int fact5(long long int n)
{
    return (n==1)? 5 : 5*fact5(n-1);
}

int main()
{
    long long int n;
    while(cin >> n)
    {
        if(n==0)break;
        int ans = 0;
        for(int i=1;fact5(i)<=n;i++)
        {
            ans += (n/fact5(i));
        }
    cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1];
  auto g = new bool[][](n, n);
  foreach (_; 0..m) {
    auto rd2 = readln.split.to!(size_t[]), a = rd2[0]-1, b = rd2[1]-1;
    g[a][b] = g[b][a] = true;
  }

  auto isValid(size_t[] p)
  {
    if (!g[0][p[0]]) return false;
    foreach (i; 0..n-2)
      if (!g[p[i]][p[i+1]]) return false;
    return true;
  }

  auto p = iota(1, n).array, ans = 0;
  do {
    if (isValid(p)) ++ans;
  } while (p.nextPermutation);

  writeln(ans);
}


Measured memory_bytes: 256