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

int dx1[] = {0, 1, 0, -1, -1, -1};
int dy1[] = {-1, 0, 1, 1, 0, -1};

int dx2[] = {1, 1, 1, 0, -1, 0};
int dy2[] = {-1, 0, 1, 1, 0, -1};

int h, w, ans;
int t[110][110];

void solve(int x, int y){
  t[y][x] = -1;

  for(int i = 0; i < 6; i++){
    int nx = x + (y % 2 == 0 ? dx1[i] : dx2[i]);
    int ny = y + (y % 2 == 0 ? dy1[i] : dy2[i]);

    if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
    if(t[ny][nx] == 1) ans++;
    else if(t[ny][nx] == 0) solve(nx, ny);
  }
}

int main(){
  while(cin >> w >> h){
    memset(t, 0, sizeof(t));

    for(int i = 1; i <= h; i++){
      for(int j = 1; j <= w; j++){
        cin >> t[i][j];
      }
    }

    h += 2;
    w += 2;
    ans = 0;

    solve(0, 0);

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
N = int(input())

A = [int(x) for x in input().split()]

ans = 0
A.sort(reverse=True)
#print(A)
ans += sum(A[:(N+1)//2-1])
for i in range((N+1)//2 - 1):
    ans += min(A[i],A[i+1])
    
if N%2 == 0:
    ans += A[N//2 - 1]

print(ans)

Measured memory_bytes: 31624
def flog():
  n = int(input())
  h = list(map(int,input().split()))
  costs = [0]*n
  if n == 2:
      print(abs(h[1]-h[0]))
      return
  if n==3:
      print(abs(h[2]-h[0]))
      return
  costs[n-2] = abs(h[n-1]-h[n-2])
  costs[n-3] = abs(h[n-1]-h[n-3])
  for i in reversed(range(n-3)):
      costs[i] = min( costs[i+1]+abs(h[i+1]-h[i]), costs[i+2]+abs(h[i+2]-h[i]) )
  print(costs[0])
  return

if __name__ == '__main__':
    flog()

Measured memory_bytes: 13776
import * as fs from 'fs';

namespace AtCoder.abc096 {
    class ProgramA {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        main(): void {
            const [a, b] = this.args[0].split(' ').map(Number);

            if (a <= b) {
                console.log(a);
            } else {
                console.log(a - 1);
            }
        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    new ProgramA(args).main();

}

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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  map<long, long> MA;
  for (long i = 0; i < N; i++) MA[A.at(i)]++;
  long sum = 0;
  for (auto ma : MA) sum += ma.second * (ma.second - 1) / 2;
  for (long i = 0; i < N; i++) {
    cout << sum - MA[A.at(i)] * (MA[A.at(i)] - 1) / 2 + (MA[A.at(i)] - 1) * (MA[A.at(i)] - 2) / 2 << "\n";
  }
}

Measured memory_bytes: 11008
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int N, D, A;
pair<int,int> monster[200000];
long long del_attack[200001];
long long attack_sum[200001];

int main() {
	cin >> N >> D >> A;
	for (int i = 0; i < N; i++) {
		int X, H;
		cin >> X >> H;
		monster[i].first = X;
		monster[i].second = H;
	}

	sort(monster, monster + N);

	long long ans = 0;
	int utan = 0;
	long long attack;
	long long attack_num;
	for (int i = 0; i < N + 1; i++) {
		del_attack[i] = 0;
		attack_sum[i] = 0;
	}

	for (int satan = 0; satan < N; satan++) {
		while (monster[utan].first <= monster[satan].first + 2*D && utan < N) {
			utan++;
		}
		attack_num = attack_sum[satan] + del_attack[satan];
		/*[satan, utan)に入る番号のモンスターを攻撃*/
		attack = (monster[satan].second - 1) / A + 1 - attack_num;
		if (attack > 0) {
			ans += attack;
			del_attack[satan] += attack;
			del_attack[utan] -= attack;
		}
		attack_sum[satan + 1] = attack_sum[satan] + del_attack[satan];
		//cout << "(" << satan << ", " << utan << "), " << ans << "\n";
	}

	cout << ans;
}

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int N;
vector<int> A;

int main() {

    cin >> N;
    A.resize(N);
    REP(i,N) cin >> A[i];

    int ans = 0;
    int top = -1;
    int dir = 0;
    REP(i,N) {
        if (top == -1) {
            top = A[i];
            ans++;
            dir = 0;
        } else {
            if (dir == 0) {
                if (A[i - 1] < A[i]) dir = 1;
                else if (A[i - 1] > A[i]) dir = 2;
            } else {
                if (dir == 1) {
                    if (A[i - 1] > A[i]) {
                        dir = 0;
                        top = A[i];
                        ans++;
                    }
                } else {
                    if (A[i - 1] < A[i]) {
                        dir = 0;
                        top = A[i];
                        ans++;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  cout << (h2 * 60 + m2) - (h1 * 60 + m1) - k << endl;
}

Measured memory_bytes: 3636
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim X As Long = Console.ReadLine()
        Dim cur As Long = 100
        Dim ans As Integer = 0
        While cur < X
            cur += Math.Floor(CType(cur, Decimal) / 100)
            ans += 1
        End While
        Console.WriteLine(ans)
        Return
    End Sub
End Class


Measured memory_bytes: 28320
# coding: utf-8
# Your code here!

S_list = list(input())
counter = 0

for i in range(len(S_list) - 1):
    if S_list[i] == S_list[i + 1]:
        counter = 1
        print("Bad")
        break
    
if counter == 0:
    print("Good")

Measured memory_bytes: 2940
S = input()

N = len(S)
ans = [0] * N

for i in range(N-1):
  if S[i] == "R" and S[i+1] == "L":
    # search left
    left = 0
    cur = i - 1
    while 0 <= cur:
      if S[cur] == "R":
        left += 1
        cur -= 1
      else:
        break
    # search right
    right = 0
    cur = (i+1) + 1
    while cur <= N-1:
      if S[cur] == "L":
        right += 1
        cur += 1
      else:
        break
    # aggregate results
    ans[i]   = 1 + left//2 + (right+1)//2
    ans[i+1] = 1 + (left+1)//2 + right//2

print(" ".join(map(str, ans)))


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

int i_gcd(int a, int b) {
    if (a%b == 0) {
        return b;
    } else {
        return i_gcd(b, a%b);
    }
}

int main(void) {
    int a, b;
    cin >> a >> b;
    printf("%d\n", i_gcd(a, b));

    return 0;
}


Measured memory_bytes: 3148
import copy
Z=[]

def dfs(A,n,m):
    global Z
    if len(A)==n:
        Z.append(copy.deepcopy(A))
        return
    
    first = A[-1] if len(A)>0 else 1
    
    for i in range(first, m+1):
        
        A.append(i)
        
        dfs(A,n,m)
        A.pop()
    

n,m,q = map(int,input().split()) 

dfs([],n,m)


A=[]
B=[]
C=[]
D=[]

for _ in range(q):
    a,b,c,d = map(int,input().split()) 
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)
    
ans = 0    
for z in Z:
    score=0
    for i in range(q):
        if z[B[i]-1] - z[A[i]-1] == C[i]:
            score += D[i]
            
    ans=max(ans,score)
        
    
print(ans)


Measured memory_bytes: 113024
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;

int CountDigit(ll num);

int main()
{
    ll N;

    cin >> N;

    int ans = CountDigit(N);
    for (ll A = 1LL; A * A <= N; A++)
    {
        if (N % A != 0) continue;
        int cur;
        ll B = N / A;
        cur  = max(CountDigit(A), CountDigit(B));
        if (cur < ans) ans = cur;
    }
    cout << ans << endl;

    return 0;
}

int CountDigit(ll num)
{
    int cnt = 0;
    while (num != 0)
    {
        num /= 10;
        cnt++;
    }

    return cnt;
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

print(sum(A)-N)


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

int main() {
  string S; cin >> S;
  if (S == "A") {
    cout << "T";
  }
  else if (S == "T") {
    cout << "A";
  }
  else if (S == "G") {
    cout << "C";
  }
  else {
    cout << "G";
  }
  cout << endl;
}



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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        var d = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            int a = sc.NextInt();
            if (!d.ContainsKey(a)) d.Add(a, 0);
            d[a]++;
        }
        int ans = 0;
        foreach(var item in d)
        {
            int res = item.Value - item.Key;
            ans += res < 0 ? item.Value : res;
        }
        Console.WriteLine(ans);
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 24160
#include <bits/stdc++.h>
using namespace std;
#define lson  (i<<1)
#define rson  ((i<<1)|1)
typedef long long ll;
typedef unsigned int ul;
const int INF = 0x3f3f3f3f;
const int  maxn = 100000 + 10;
const int mod = 1e9 + 7;

int t1[maxn], t2[maxn], c[maxn];
bool cmp(int *r, int a, int b, int l) {
    return r[a] == r[b] && r[l + a] == r[l + b];
}

void get_sa(int str[], int sa[], int Rank[], int height[], int n, int m) {
    n++;
    int p, *x = t1, *y = t2;

    for(int i = 0; i < m; i++) c[i] = 0;

    for(int i = 0; i < n; i++) c[x[i] = str[i]]++;

    for(int i = 1; i < m; i++) c[i] += c[i - 1];

    for(int i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;

    for(int j = 1; j <= n; j <<= 1) {
        p = 0;

        for(int i = n - j; i < n; i++) y[p++] = i;

        for(int i = 0; i < n; i++) if(sa[i] >= j) y[p++] = sa[i] - j;

        for(int i = 0; i < m; i++) c[i] = 0;

        for(int i = 0; i < n; i++) c[x[y[i]]]++ ;

        for(int i = 1; i < m; i++) c[i] += c[i - 1];

        for(int i = n - 1; i >= 0; i--)  sa[--c[x[y[i]]]] = y[i];

        swap(x, y);
        p = 1;
        x[sa[0]] = 0;

        for(int i = 1; i < n; i++)
            x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;

        if(p >= n) break;

        m = p;
    }

    int k = 0;
    n--;

    for(int i = 0; i <= n; i++)
        Rank[sa[i]] = i;

    for(int i = 0; i < n; i++) {
        if(k) k--;

        int j = sa[Rank[i] - 1];

        while(str[i + k] == str[j + k]) k++;

        height[Rank[i]] = k;
    }

}

int Rank[maxn], height[maxn];
int sa[maxn];
char str[maxn];
int r[maxn];
ll num[maxn];
int lpos, rpos;
int len ;


void fin(ll x) {
    int l = 1 , r = len;
    int cur = 0;

    while(l <= r) {
        int mid = (l + r) >> 1;

        if(num[mid] >= x) {
            cur = mid;
            r = mid - 1;
        } else
            l = mid + 1;
    }

    x = x - num[cur - 1];
    lpos = sa[cur] + 1;
    rpos = sa[cur] + height[cur] + x;
    int tlen = rpos - lpos + 1;

    if(cur + 1 <= len && tlen <= height[cur + 1]) {
        for(int i = cur + 1; i <= len; i++) {
            if(height[i] >= tlen) {
                if(lpos > sa[i] + 1) {
                    lpos = sa[i] + 1;
                    rpos = lpos + tlen - 1;
                }
            } else
                break;
        }
    }

    return ;
}

int main() {
	scanf("%s",str);
    len = strlen(str);

    for(int i = 0; i < len; i ++) {
        r[i] = str[i];
    }

    r[len] = 0;
    num[0] = 0;
    get_sa(r, sa, Rank, height, len, 200);

    for(int i = 1; i <= len; i++) {
        num[i] = (ll)(len - sa[i] - height[i]);
        num[i] += num[i - 1];
    }

    ll x;
    cin >> x; --x;
    ll k = (ll)(lpos ^ rpos ^ x) + 1LL;
    lpos = rpos = 0;

    fin(k);
    for (int i=lpos-1;i<rpos;++i) printf("%c",str[i]); puts("");
    return 0;
}

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

int main(){
 string a;
  cin>>a;
  int b;
  b=(a[0]-'0')*100+(a[1]-'0')*10+a[2]-'0';
  for(int i=0;i<10;i++){
if(b<=i*111){
b=i*111;
  break;
}
    
       }
  cout<<b<<endl;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	//A
	/*
	int h;
	int w;
	cin >> h;
	cin >> w;

	char a[9][9];
	int i, j;
	int count1 = 0;
	int count2 = 0;
	for (i = 0; i < h+1; i++) {
		for (j = 0; j < w+1; j++) {
			a[i][j]='.';
		}
	}

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	i = 0;
	j = 0;
	while ((i < h) && (j < w)){
		if (a[i+1][j] == '#') {
			a[i][j] = '.';
			i++;
		}
		else if (a[i][j + 1] == '#') {
			a[i][j] = '.';
			j++;
		}
		else {
			break;
		}
	} 
	a[i][j] = '.';
	if ((i >= h - 1) && (j >= w - 1)) {
		for (count1 = 0; count1 < h; count1++) {
			for (count2 = 0; count2 < w; count2++) {
				if (a[count1][count2] == '#') {
					cout << "Impossible";
					return 0;
				}
			}
		}
		cout << "Possible";
		return 0;
	}
	else {
		cout << "Impossible";
		return 0;
	}
		

	return 0;*/

	int n;
	int p[20001];
	int pin[20001];
	cin >> n;
	int i;
	for (i = 1; i <= n; i++) {
		cin >> p[i];
		pin[p[i]] = i;
	}
	int a[20001] , b[20001];
	for (i = 1; i <= n; i++) {
		a[i] = i * 20001 + pin[i];
		b[i] = (20001 - i) * 20001 + pin[i];
	}
	for (i = 1; i <= n; i++) {
		cout << a[i];
		cout<<' ';
	}
	cout << '\n';
	for (i = 1; i <= n; i++) {
		cout << b[i];
		cout << ' ';
	}
	return 0;
}

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

int main(){
	char ch[1200];
	int i=0;

	while (1){
		i++;
		scanf("%c", &ch[i]);

		if (isupper(ch[i])){
			ch[i] = tolower(ch[i]);
		}
		else if (islower(ch[i])){
			ch[i] = toupper(ch[i]);
		}

		if (ch[i] == '\n')break;
		cout << ch[i];
	}

	cout << endl;


	return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define rep(i,n)for(int i=0;i<n;i++)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int n,c,k;scanf("%d %d %d",&n,&c,&k);
    int t[n];rep(i,n)scanf("%d",&t[i]);

    qsort(t,n,sizeof(int),asc_cmp);
    //rep(i,n)printf(">%d\n",t[i]);
    int ans=1,head=t[0],cnt=1;
    for(int i=1;i<n;i++){
        cnt++;
        if(head+k<t[i]||cnt>c){
            //printf("%d:%d\n",i,t[i]);
            ans++;
            head=t[i];
            cnt=1;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 892
n,m=map(int,input().split())
#n,mの偶奇で場合分け
#n,mがともに偶数の時は全部４の倍数個なきゃダメ
#n,mの片方のみ奇数の時は、例えばnが奇数の時は個数が偶数だが４の倍数でない組みがm//2組みまで許される
#n,mがともに奇数の時は個数が偶数だが４の倍数でない組みが(n+m)//2組み許され、ただ一つ奇数が必要
l=[]
for i in range(n):
  l.append(list(input()))
from collections import defaultdict
d=defaultdict(int)
for i in range(n):
  for j in range(m):
    d[l[i][j]]+=1
b=True
count2=0
count1=0
for i in d:
  if d[i]%4==0:
    pass
  elif d[i]%2==0:
    count2+=1
  else:
    if count1!=0:
      b=False
    else:
      count1=1
if not b:#奇数個あるのが２組以上
  print("No")
else:
  if n%2==0 and m%2==0:
    if count2>0 or count1>0:
      print("No")
    else:
      print("Yes")
  elif n%2==0 and m%2==1:
    if count1>0 or count2>n//2:
      print("No")
    else:
      print("Yes")
  elif n%2==1 and m%2==0:
    if count1>0 or count2>m//2:
      print("No")
    else:
      print("Yes")
  else:
    if (count1-1)%4==2:
      count2+=1
    if count2>(n+m-2)//2:
      print("No")
    else:
      print("Yes")

Measured memory_bytes: 3440
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String[] list1 = s1.split("");
      	String[] list2 = s2.split("");
      	String ans = "NO";
      	if(list1[0].equals(list2[2]) && list1[1].equals(list2[1]) && list1[2].equals(list2[0])) ans = "YES";
      	System.out.println(ans);
	}
}


Measured memory_bytes: 35484
import java.math.BigDecimal;
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int Harr[] = new int[N];
		boolean H[]  = new boolean[N];
		int road[][] = new int[M][2];
		for (int i = 0; i < N; i++) {
			Harr[i] = sc.nextInt();
			H[i] = true;
		}
		for (int i = 0; i < road.length; i++) {
			road[i][0] = sc.nextInt();
			road[i][1] = sc.nextInt();
		}
		for (int i = 0; i < road.length; i++) {
			int H1 = Harr[road[i][0]-1];
			int H2 = Harr[road[i][1]-1];
			if (H1<H2) {
				H[road[i][0]-1] = false;
			} else if(H1==H2){
				H[road[i][0]-1] = false;
				H[road[i][1]-1] = false;
			} else{
				H[road[i][1]-1] = false;
			}
		}
		int cnt = 0;
		for (int i = 0; i < H.length; i++) {
			if(H[i]){
				cnt++;
			}
		}

		
		System.out.println(cnt);
		sc.close();
    }
		
		
}


Measured memory_bytes: 53068
//#include <iostream>
//#include <vector>
//#include <set>
//#include <map>
//#include <algorithm>

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll len = 2 * (int) 1e5 + 1;

ll n, m, l;
ll from, to, cost;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> l;
    vector<vector<ll>> g(n, vector<ll>(n, (ll) 1e15 + 1));
    for (int i = 0; i < m; i++) {
        cin >> from >> to >> cost;
        from--;
        to--;
        g[from][to] = g[to][from] = cost;
    }
    for (int i = 0; i < n; i++) {
        g[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
            }
        }
    }

    vector<vector<int>> res(n, vector<int>(n));

    for (int i = 0; i < n; i++) {
        vector<bool> check(n, false);
        queue<int> q;
        vector<ll> ans(n, (ll) 1e15 + 1);
        ans[i] = 0;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();

            check[v] = true;
            for (int j = 0; j < n; j++) {
                if (g[v][j] <= l && check[j] == false) {
                    ans[j] = ans[v] + 1;
                    check[j] = true;
                    q.push(j);
                }
            }
        }
        for (int j = 0; j < n; j++) {
            res[i][j] = (ans[j] == (ll) 1e15 + 1 ? -1 : max(ans[j] - 1, 0ll));
        }
    }

    int q;
    cin >> q;
    while (q--) {
        cin >> from >> to;
        from--;
        to--;
        cout << res[from][to] << endl;
    }

}


Measured memory_bytes: 1664
#include <stdio.h>

int main(void) {

  int a, b, c;
  int count = 0;
  int i = 0;

  scanf("%d %d %d", &a, &b, &c);

  for (i = a; i < b + 1; i++) {
    if (c % i == 0)
      count++;
  }

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

  return 0;
}



Measured memory_bytes: 2140
input = defined?(DATA) ? DATA : STDIN
_ = input.gets.to_i
a = input.gets.split(' ').map(&:to_i)
sum = a.sum
list = Array.new(10 ** 5 + 1, 0)
a.each do |i|
  list[i] += 1
end

q = input.gets.to_i
q.times do
  b, c = input.gets.split(' ').map(&:to_i)
  count = list[b]
  list[b] = 0
  list[c] += count
  sum = sum - b * count + c * count
  puts sum
end


Measured memory_bytes: 22196
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 100005;

int n,a[N],b[N];
int sum[N<<2];
LL aim;

inline void ins(int x,int val) { x+=n+1; while (x<=n*2+1) {sum[x]+=val; x+=x&-x;}}
inline int query(int x) {x+=n+1; int ret=0; while (x) {ret+=sum[x]; x-=x&-x;} return ret;}

inline LL calc(int lim) {
	int tmp=0;
	LL ret=0;
	rep(i,1,n) {
		if (a[i]<=lim) tmp++; else tmp--;
		ret+=query(tmp-1);
		ins(tmp,1);
	}
	tmp=0;
	rep(i,1,n) {
		if (a[i]<=lim) tmp++; else tmp--;
		ins(tmp,-1);
	}
	return ret;
}

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(); rep(i,1,n) b[i]=a[i]=read(); sort(b+1,b+n+1);
	int tot=unique(b+1,b+n+1)-b-1;
	int l=1,r=tot; aim=(LL)n*(n+1)/2; aim=aim/2+1;
	int ans; ins(0,1);
	while (l<=r) {
		int mid=(l+r)>>1;
		LL now=calc(b[mid]);
		if (now>=aim) ans=b[mid],r=mid-1;
		else l=mid+1;
		
	}
	printf("%d\n",ans);

	return 0;
	
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
    int N,tmp,G1=0,G2=0;
    cin >>N;
    int a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    for(int i=0; i<N; i++){
        for(int j= i+1; j<N; j++){
            if( a[i] < a[j]){
                tmp = a[j];
                a[j] = a[i];
                a[i] = tmp;
                }
            }
        }
        for(int j=0; j<N; j++){
        if( j % 2 == 0){
            G1 += a[j];
        } else {
            G2 += a[j];
        }
    }
    cout << G1 - G2 << endl;
    return 0;
}

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

#define gc getchar
#define pc putchar
#define ll long long
#define iL inline
#define R0 register

template <class T>
iL void read(T&x) {
  R0 char c = gc();
  R0 bool f = 0;
  while ((c < '0' || c > '9') && c != '-') c = gc();
  (c == '-') && (f = 1, c = gc());
  x = 0;
  while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = gc();
  f && (x = -x);
}
template <class T>
iL void print(T x) {
  (x < 0) && (pc('-'), x = -x);
  if (x >= 10) print(x / 10);
  pc((x % 10) ^ 48);
}
template <class T>
iL void priln(T x) {
  print(x);
  pc('\n');
}
template <class T>
iL void prisp(T x) {
  print(x);
  pc(' ');
}

int n;
std::string s;

int main() {
  read(n);
  std::cin >> s;
  if (n & 1) {
    puts("No");
    return 0;
  }
  for (R0 int i = 0; i < (n >> 1); ++i) {
    if (s[i] != s[i + (n >> 1)]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
char s[1001],c[1001];
int ans;
main() {
	cin>>s;
	cin>>c;
	ans=(s[0]==c[0])+(s[1]==c[1])+(s[2]==c[2]);
	cout<<ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=350;
int n,m,l,T;
int a[maxn][maxn],f[maxn][maxn];
int main()
{
	cin>>n>>m>>l;
	memset(a,0x3f,sizeof(a));
	for(int i=1;i<=n;i++) a[i][i]=0;
	for(int i=1;i<=m;i++)
	{
		int x,y,z;cin>>x>>y>>z;
		a[x][y]=a[y][x]=z;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
	
	memset(f,0x3f,sizeof(f));
	for(int i=1;i<=n;i++) f[i][i]=0;		
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i][j]<=l) f[i][j]=f[j][i]=1;
	
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
				
	cin>>T;
	while(T--)
	{
		int x,y;cin>>x>>y;
		if(f[x][y]==inf) puts("-1");
		else cout<<f[x][y]-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define pint pair<int,int>
#define pdouble pair<double,double>
using namespace std;
typedef long long ll;

int main(){
    int n, ni = 1;
    double l = 0;
    cin >> n;
    rep(i,n) ni *= i+1;
    int xy[2][10];
    rep(i,n) cin >> xy[0][i] >> xy[1][i];
    rep(i,n){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            l += sqrt((xy[0][i]-xy[0][j])*(xy[0][i]-xy[0][j])+(xy[1][i]-xy[1][j])*(xy[1][i]-xy[1][j]));
        }
    }
    printf("%.7f\n", l/n);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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 INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int a = F / (100 * A);
    int ans_sw = 100*A, ans_s = 0;
    for (int i = 0; i <= a; i++) {
        int f = F - 100 * i * A;
        int b = f / (100 * B);
        for (int j = 0; j <= b; j++) {
            int nf = f - 100 * j * B;
            int ne = (i * A + j * B) * E;
            int max_sugar = min(nf, ne);
            int x_d = max_sugar / D;
            for (int k = 0; k <= x_d; k++) {
                int x_c = (max_sugar - k * D) / C;
                int sugar = x_c * C + k * D;
                int sugar_water = 100 * (i*A + j*B) + sugar;
                if (sugar * ans_sw > sugar_water * ans_s) {
                    ans_sw = sugar_water;
                    ans_s = sugar;
                }
            }
        }
    }
    cout << ans_sw << " " << ans_s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  vector<int> v;
  vector<int> cash(100003, 0);
  int n;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int max_cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    max_cnt = max(max_cnt, ++cash[v[i] + 1]);
    max_cnt = max(max_cnt, ++cash[v[i]]);
    max_cnt = max(max_cnt, ++cash[v[i] + 2]);
  }
  cout << max_cnt << endl;
  return 0;
}


Measured memory_bytes: 1276
T = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
base = 10**4
while 1:
    m, n = map(int, input().split())
    if m == 0:
        break
    m **= n
    cur = 1
    ans = []
    for i, t in enumerate(T):
        d = (m // cur) % base
        if d:
            ans.append(t)
            ans.append(str(d))
        cur *= base
    ans.reverse()
    print(*ans, sep='')



Measured memory_bytes: 5600
a, b, k = map(int, input().split())
if b - a - 2*k + 1 > 0:
    for x in (list(range(a, a+k)) + list(range(b-k+1, b+1))):
        print(x)
else:
    for x in (range(a, b+1)):
        print(x)

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

bool isprime(int x) {
  bool flag = true;
  for (int i = 2; i < x; i++) {
    if (x % i == 0) flag = false;
  }
  return flag;
}

int main() {
  int x;
  cin >> x;
  while (!isprime(x)) x++;
  cout << x << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  deque<int> a;
  for(int i=0;i<N;i++){
    if(i%2==0){
      int x;
      cin >> x;
      a.push_back(x+1);
    }
    else{
      int x;
      cin >> x;
      a.push_front(x+1);
    }
  }
  if(N%2==1)reverse(a.begin(),a.end());
  for(int i=0;i<a.size();i++){
    if(a[i]!=0)cout << a[i]-1 << ' ';
  }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size()-1){
        if(s[i]!=s[i+1])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}




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

int main() {

long long int n,a[200000],d=0;
long long int k=0;
cin >> n;
for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
        if(a[j]<a[i])
            {
                k=k+(a[i]-a[j]);
                 if(j==n-1)
                    {
                        d=1;
                    }
            }
            else
            {
                i=j-1;
                if(j==n-1)
                    {
                        d=1;
                    }
                break;
            }
            
        }
            if(d==1)
                {
                    break;
                }
        
    }
    
    cout << k;
        return 0;
        
}


Measured memory_bytes: 5140
N = int(input())
AS = [int(x) for x in input().split()]

AS.sort(reverse=True)
MAX_AS = AS[0]
table = [0] * (MAX_AS + 1)  # 1..max(AS)

alreadyVisited = {}
for i in range(N):
    x = dx = AS[i]
    if alreadyVisited.get(x, False):
        table[x] = 0
        continue
    alreadyVisited[x] = True

    table[x] = 1
    while True:
        x += dx
        if x > MAX_AS:
            break
        table[x] = 0

print(sum(table))


Measured memory_bytes: 43700
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;
int dy[]={1,-1,0,0,1,1,-1,-1,0};
int dx[]={0,0,1,-1,1,-1,1,-1,0};

int main(){
	int N,K;
	string s;
	cin >> N >> K >> s;
	s[K-1] = char(s[K-1]+32);
	cout << s << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

int main() {
    char s;
    cin >> s;
    if(isupper(s)) cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}

Measured memory_bytes: 3616
# coding: utf-8
import sys
A = input()
B = input()

ans="EQUAL"
if len(A)>len(B):
    ans="GREATER"
elif len(A)<len(B):
    ans="LESS"
else:
    for a, b in zip(A, B):
        a, b = int(a), int(b)
        if a>b:
            ans="GREATER"
            break
        elif a<b:
            ans="LESS"
            break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr,0,sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9+7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t  main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        string s;
        cin >> s;
        int q;
        cin >> q;
        int flag = 0;
        deque<char> dq;
        for(char i : s){
            dq.push_back(i);
        }
        while(q--){
            int t;
            cin >> t;
            if(t == 1){
                flag = 1 - flag;
            }else{
                int f;
                char c;
                cin >> f >> c;
                if(f + flag == 2){
                    dq.push_back(c);
                }else{
                    dq.push_front(c);
                }
            }
        }
        string ans;
        for(auto i : dq){
            ans += i;
        }
        if(flag){
            reverse(all(ans));
        }
        cout << ans << '\n';
    } 
}

Measured memory_bytes: 32600
#include <iostream>

int main() {
	int n;
	
	while (std::cin >> n, n) {
		int ans = 0;

		for (int i = 0; i < n / 4; ++i) {
			int x;
			std::cin >> x;

			ans += x;
		}

		std::cout << ans << std::endl;
	}
}

Measured memory_bytes: 2972
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    map<int,int> mp_s;
    map<int,int> mp_p;
    int s_num;
    int t_num;
    int flag=0;
    for(int i=0;i<s.length();i++){
        s_num=s[i]-'a'+1;
        t_num=t[i]-'a'+1;
        if(mp_s[s_num]==0)mp_s[s_num]=t_num;
        else if(mp_s[s_num]!=t_num)flag++;
        if(mp_p[t_num]==0)mp_p[t_num]=s_num;
        else if(mp_p[t_num]!=s_num)flag++;
        if(flag>0)break;
    }
    if(flag>0)cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

const double EPS = 1e-10;
const double PI = 3.14159265358979;

int a, b, x;

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d %d %d", &a, &b, &x);
	if(2 * x == a * a * b) {
		puts("45.000000");
		return 0;
	} else if(2 * x > a * a * b) {
		double y = 2.0 * x / (1.0 * a * a) - b;
		double t = 1.0 * (b - y) / a;
		printf("%.7lf", atan(t) / PI * 180);
	} else {
		double t = 2.0 * x / b / a;
		t = b / t;
		printf("%.7lf\n", atan(t) / PI * 180);
	}
	return 0;
}

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

int main(){
int N,M,t=0,s=0;
cin >> N >> M;
vector<int> A(N);

for(int i=0; i<N; i++){
	cin >> A.at(i);
	t += A.at(i);
}
for(int i=0; i<N; i++){
	if(4*M*A.at(i) >= t) s++;
}
if(s>=M) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 3592
import sys
input = sys.stdin.readline


def main():
    abcd = [int(x) for x in list(input().strip())]

    for i in range(8):
        s = abcd[0]
        bs = [int(x) for x in list('{0:03b}'.format(i))]

        for j, b in enumerate(bs, 1):
            if b == 0:
                s -= abcd[j]
            else:
                s += abcd[j]

        if s == 7:
            ans = str(abcd[0])
            for j, b in enumerate(bs, 1):
                ans += '+' if b == 1 else '-'
                ans += str(abcd[j])
            ans += '=7'
            print(ans)
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
 
dp = [0]*(1005)
frm = 0
cnt = 0
Lcopy = [1001] + L[::-1]
while Lcopy:
  to = Lcopy.pop()
  for i in range(frm, to):
    dp[i] = cnt
  frm = to
  cnt += 1
  
ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]

  x = b - dp[sub]
  if x > 0:
    ans += x
  else:
    b += 1
    c = b
    
  c += 1
  if c >= N:
    b += 1
    c = b + 1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i[] = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main(){
   int n, k;cin >> n >> k;
   vec sunuke(n, 0);
   rep(i, k){
       int d;cin >> d;
       rep(j, d){
           int a;cin >> a;
           sunuke[a-1] = 4;
       }
   }
   int ans = 0;
   rep(i, n){
       if(sunuke[i] == 0){
           ans++;
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
 
using namespace std;
 
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
 
#define equal equalll
#define less lesss
#define matr vector<vector<int>>

int main() {
	// freopen("input.txt", "r", stdin);
	string s;
	cin >> s;
	cout << s.substr(0, 4) << " " << s.substr(4) << endl;	
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll Mod=1e9+7;
int x[10],y[10],n;
ll fac[2000010],inv[2000010];
void upd(ll &x,ll v)
{
	x=(x+v)%Mod;
}
ll pw(ll x,ll y)
{
	ll res=1;
	while (y)
	{
		if (y&1)
		{
			res=res*x%Mod;
		}
		y>>=1;
		x=x*x%Mod;
	}
	return res;
}
ll c(int n,int m)
{
	return fac[n+m]*inv[n]%Mod*inv[m]%Mod;
}
ll f(int xa,int ya,int xb,int yb)
{
	return (c(xa,ya)+c(xb+1,yb+1)-c(xa,yb+1)-c(xb+1,ya)+Mod+Mod)%Mod;
}
int main()
{
	n=2000002;
	fac[0]=1;
	for (int i=1;i<=n;i++)
	{
		fac[i]=fac[i-1]*i%Mod;
	}
	inv[n]=pw(fac[n],Mod-2);
	for (int i=n-1;i>=0;i--)
	{
		inv[i]=inv[i+1]*(i+1)%Mod;
	}
	for (int i=1;i<=6;i++)
	{
		scanf("%d",&x[i]);
	}
	for (int i=1;i<=6;i++)
	{
		scanf("%d",&y[i]);
	}
	ll ans=0;
	for (int i=x[3];i<=x[4];i++)
	{
		upd(ans,1LL*(i+y[4]+1)*f(i-x[2],y[4]-y[2],i-x[1],y[4]-y[1])%Mod*f(x[5]-i,y[5]-y[4]-1,x[6]-i,y[6]-y[4]-1));
		upd(ans,Mod-1LL*(i+y[3])*f(i-x[2],y[3]-y[2]-1,i-x[1],y[3]-y[1]-1)%Mod*f(x[5]-i,y[5]-y[3],x[6]-i,y[6]-y[3])%Mod);
	}
	for (int i=y[3];i<=y[4];i++)
	{
		upd(ans,1LL*(x[4]+i+1)*f(x[4]-x[2],i-y[2],x[4]-x[1],i-y[1])%Mod*f(x[5]-x[4]-1,y[5]-i,x[6]-x[4]-1,y[6]-i));
		upd(ans,Mod-1LL*(x[3]+i)*f(x[3]-x[2]-1,i-y[2],x[3]-x[1]-1,i-y[1])%Mod*f(x[5]-x[3],y[5]-i,x[6]-x[3],y[6]-i)%Mod);
	}
	printf("%lld\n",ans);
	return 0;
}
//江山如梦，人在梦中，深魇未醒，何时走出？

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n;
    cin >> n;
    vector<ll> num(n, 0);
    REP(i, n - 1){
        ll ai;
        cin >> ai;
        ai--;
        num.at(ai)++;
    }

    REP(i, n){
        cout << num.at(i) << endl;
    }
    return 0;
}


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

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





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    vector<int> f(4);
    for (int i=0; i<3; i++) {
	int u,v;cin>>u>>v;
	--u; --v;
	f[u]++;
	f[v]++;
    }

    int hi=*max_element(f.begin(), f.end());
    cout<<(hi>2?"NO\n":"YES\n");
    
    
    return 0;
}


Measured memory_bytes: 3624
/*
[agc038] B - Sorting a Segment
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 200000;

int N, K;
int P[MAX_N];
vector<int> g[MAX_N];
bool visited[MAX_N];

void dfs(int v) {
    if (visited[v]) {
        return;
    }
    visited[v] = true;
    for (int to : g[v]) {
        dfs(to);
    }
}

ll solve() {
    int ord = 1, pre = -1;
    for (int i = 1; i < N; i++) {
        ord = (P[i - 1] < P[i]) ? ord + 1 : 1;
        if (ord >= K) {
            if (pre != -1) {
                int u = pre - K + 1;
                int v = i - K + 1;
                g[u].push_back(v);
                g[v].push_back(u);
            }
            pre = i;
        }
    }

    set<int> s;
    for (int i = 0; i < K; i++) {
        s.insert(P[i]);
    }
    for (int i = 0; i + K < N; i++) {
        s.insert(P[i + K]);
        if (P[i] == *s.begin() && P[i + K] == *s.rbegin()) {
            g[i].push_back(i + 1);
            g[i + 1].push_back(i);
        }
        s.erase(P[i]);
    }

    int ans = 0;
    for (int i = 0; i + K <= N; i++) {
        if (!visited[i]) {
            ans++;
        }
        dfs(i);
    }

    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }

    cout << solve() << endl;

    return 0;
}


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

int main(){
 int N,c = 0;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  std::sort(a.begin(),a.end(),std::greater<int>());
  if((N - 1) % 2 == 0){
    c += a.at(N - 1);
  }
  for(int j = 0; j <= N - 2; j += 2){
    if(j >= N - 1){
      break;
    }
    c += a.at(j) - a.at(j + 1);
  }
  cout << c << endl;
}
  

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 1000 + 5;

int n , m; char A[N][N];

int S[N][N] , T[N][N];

int main()
{
    read(n) , read(m);
    rep(i , 1 , n)
        scanf("%s" , A[i] + 1);
    rep(i , 1 , n) rep(j , 1 , m)
    {
        if(A[i][j] == '#')
            S[i][j] = T[i][j] = 1;
    }
    rep(j , 1 , m)
    {
        S[1][j] = T[n][j] = 1;
    }
    rep(i , 2 , n - 1) rep(j , 1 , m)
    {
        if(j % 2 == 0)
            S[i][j] = 1;
        else
            T[i][j] = 1;
    }
    rep(i , 1 , n)
    {
        rep(j , 1 , m)
        {
            if(S[i][j])
                putchar('#');
            else
                putchar('.');
        }
        puts("");
    }
    puts("");
    rep(i , 1 , n)
    {
        rep(j , 1 , m)
        {
            if(T[i][j])
                putchar('#');
            else
                putchar('.');
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  int a[n],b[n],c[m],d[m];
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  for(int j=0;j<m;j++)cin>>c[j]>>d[j];
  vector<vector<pair<int,int> > >v(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      int dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      v[i].push_back(make_pair(dis,j));
    }
    sort(v[i].begin(),v[i].end());
  }
  for(int i=0;i<n;i++){
    cout<<v[i][0].second+1<<endl;
  }
}
                             

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll q;
    cin>>q;
    string h,t;
    ll is_even = 0;
    FOR(i,0,q){
        ll in;
        cin>>in;
        if(in == 1) is_even = (is_even+1)%2;
        else{
            ll f;
            char c;
            cin>>f>>c;
            if((is_even+f)%2==0)t.push_back(c);
            else h.push_back(c);
        }
    }
    string ans;
    reverse(h.begin(),h.end());
    ans = h + s + t;
    if(is_even==1){
        reverse(ans.begin(),ans.end());
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1300
#include<iostream>
using namespace std;
int main(){
long N;int K;
cin >> N;
cin >> K;
long s = 0;
for (int i = K ; i <= N +1; ++i){
s += i*(N -i +1) +1;
  s = s % 1000000007;
}
  cout << s << endl;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int result(char str[]);
int main()
{
    char str[11];
    cin >> str;
    if (result(str) == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

int result(char str[])
{
    int result = 0, i;
    for (i = 0; str[i] != '\0'; i++)
    {
        if (i % 2 == 0 && str[i] != 'h')
        {
            result = 1;
        }
        if (i % 2 == 1 && str[i] != 'i')
        {
            result = 1;
        }
    }
    if (i % 2)
    {
        result = 1;
    }
    return result;
}

Measured memory_bytes: 256