akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,p=1e9+7;
int mul(int x,int y){return 1ll*x*y%p;}
int power(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=mul(x,x))
		if (y&1) ans=mul(ans,x);
	return ans;
}
int n,m,x,y,pre[N],suf[N],Min[N],size[N],fac[N],ifac[N];
priority_queue<int,vector<int>,greater<int> > Q[N];
pair<int,int> a[N];
int main()
{
	scanf("%d%d%d",&n,&x,&y);
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=mul(fac[i-1],i);
	ifac[n]=power(fac[n],p-2);
	for (int i=n;i;i--) ifac[i-1]=mul(ifac[i],i);
	for (int i=1;i<=n;i++) Min[i]=1e9+1;
	for (int i=1;i<=n;i++){
		int c,w;
		scanf("%d%d",&c,&w);
		Q[c].push(w);
		Min[c]=min(Min[c],w);
	}
	pre[0]=1e9+1;
	for (int i=1;i<=n;i++) pre[i]=min(pre[i-1],Min[i]);
	suf[n+1]=1e9+1;
	for (int i=n;i;i--) suf[i]=min(suf[i+1],Min[i]);
	for (int i=1;i<=n;i++)
	if (!Q[i].empty()){
		int Max=max(x-Min[i],y-min(pre[i-1],suf[i+1]));
		Q[i].push(1e9+1);
		for (Q[i].pop(),size[i]++;Q[i].top()<=Max;Q[i].pop(),size[i]++);
		a[++m]=make_pair(Min[i],size[i]);
	}
	sort(a+1,a+m+1);
	int size=a[1].second,ans=ifac[size];
	for (int i=2;i<=m;i++)
	if (a[i].first+a[1].first<=y){
		size+=a[i].second;
		ans=mul(ans,ifac[a[i].second]);
	}
	ans=mul(ans,fac[size]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16768
N = int(input())
T = list(map(int, input().split()))
M = int(input())
#print(type(sum(T)))
PX = []
drink_list = list()
for i in range(M):
    PX.append(input().split())
    #print(PX)
    PX[i][0] = int(PX[i][0])
    PX[i][1] = int(PX[i][1])
#print(type(PX[0][0]))
for i in range(M):
    drink_list.append(sum(T) -T[PX[i][0]-1] + PX[i][1])
    print(drink_list[i])

Measured memory_bytes: 3064
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
       int[,] a = new int[n, 3];
       int[,] K = new int[n, 3];
        for (int i = 0; i < n; i++)
        {
            int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int j = 0; j < 3; j++)
            {
                a[i, j] = s[j];
                K[i, j] = s[j];
            }
        }
        for (int i = 0; i < 3; i++)
        {
            for (int k = 0; k < n; k++)
            {
                for (int j = 0; j < k; j++)
                {
                    if (a[k, i] == a[j, i])
                    {
                      //  int u = a[k, i];
                        //int y = a[j, i];
                        K[k, i] = 0;
                        K[j, i] = 0;
                       // a[k, i] += u;
                       // a[j, i] += y;
                    }
                }
            }


        }
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(K[i, 0] + K[i, 1] + K[i, 2]);
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 9660
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
ll  n,a[1000000];
using namespace std;
bool check()
{
	if(a[1]!=0) return 1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]-a[i-1]>1) return 1;
	}
	return 0;
}
int main()
{
	scanf("%lld",&n);
	ll sum=0;
	ll now=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	if(check())
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==a[i-1]+1) sum++;
		else sum+=a[i]; 
	}
	printf("%lld",sum);
	return 0;
}

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

using namespace std;
 
int main(){
    int n, y;
    cin >> n >> y;

    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n;j++){
            if(10000*i + 5000*j + 1000*(n-i-j) == y && n-i-j >= 0){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	_ = readInt()
	s := readString()
	x := 0

	var ans int
	for _, r := range s {
		if r == 'I' {
			x++
		} else if r == 'D' {
			x--
		}
		ans = maxInt(ans, x)
	}
	println(ans)
}


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

long long int prime[100005], nprime;
int mark[100005];
int cum[100005];
void seive(long long int n)
{
    mark[0] = 1;
    long long int i,j,limit = sqrt(n*1.)+2;
    mark[1] = 1;
    for(i=4;i<=n;i+=2) mark[i] = 1;
    prime[nprime++] = 2;
    for(i=3;i<=n;i+=2){
        if(!mark[i])

            prime[nprime++] = i;
            if(i<=limit)
            {
                for(j=i*i;j<=n;j+=i*2)
                {
                    mark[j] = i;
                }
            }

    }
}
int main()
{
    int q;
    cin>>q;
    seive(100002);
    for(int i=1;i<=100000;i++)
    {
        if(mark[i]==0 && mark[(i+1)/2]==0)
        {
            cum[i] = cum[i-1] + 1;
        }
        else cum[i] = cum[i-1];
        //cout<<i<<" "<<cum[i]<<endl;
    }
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        cout<<cum[r] - cum[l-1]<<endl;


    }
    return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

bool cmp(pair<int,int>a,pair<int,int>b){
    return a.second<b.second;
}


int main(){

int n,m;
cin>>n>>m;


vector<pair<int,int>>bridge;
rep(i,m){
    int a,b;
    cin>>a>>b;
    bridge.emplace_back(make_pair(a,b));
}

sort(bridge.begin(),bridge.end(),cmp);


int right=-1;
int ans=0;
for(int i=0;i<m;i++){

    if(bridge[i].first>=right){
    ans++;
    right=bridge[i].second;
    }
}
cout<<ans<<endl;


    return 0;

}
/*


*/


Measured memory_bytes: 1400
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD =1000000007;


     signed main(){
       int n,k;
       cin>>n>>k;
       int p[n];
       for(int i=0;i<n;i++){
           cin>>p[i];p[i]--;
       }
       int c[n];
       for(int i=0;i<n;i++)cin>>c[i];
       int ans=-MOD*MOD;
       vector<int> v;
       bool used[n]={};
        for(int i0=0;i0<n;i0++){
            if(used[i0])continue;
            int x=i0,y=0;
            while(true){
                v.push_back(x);
                used[x]=true;
                x=p[x];
                y+=c[x];
                if(x==i0)break;
         
            }
            int w=v.size();
            for(int i=0;i<v.size();i++){
                int p=0;
                for(int j=1;j<=v.size();j++){
                    p+=c[v[(i+j)%(v.size())]];
                    if(j>k)continue;
                    if(y>0)ans=max(ans,((k-j)/w)*y+p);
                    else ans=max(ans,p);
               
                }
            }
            v.clear();
        }
        cout<<ans<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 3816
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int w,h,x,y,r;
		w=sc.nextInt();
		h=sc.nextInt();
		x=sc.nextInt();
		y=sc.nextInt();
		r=sc.nextInt();
		
		if((x+r)<=w && (x-r)>=0 && (y+r)<=h && (y-r)>=0) System.out.println("Yes");
		else System.out.println("No");
		
	}

}

Measured memory_bytes: 17348
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
 
int main() {
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++)
    {
      cin>>A[i];
    }
    //vector<int> a = A;
    for(int t=0;t<K;t++)
    {
      vector<int> B(N+1,0);
      for(int i=0;i<N;i++)
      {
        B[max(0,i-A[i])]++;
        B[min(N,i+A[i]+1)]--;
      }
      for(int i=0;i<N;i++) B[i+1]+=B[i];
      B.pop_back();
      if(A==B)break;
      A=B;
    }
    for(int i=0;i<N;i++)
    {
      cout<<A[i]<< (i == N - 1 ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 4820
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int[][] cc = new int[4][4];
		for( int i=1; i<=3; i++ ){
			for( int k=1; k<=3; k++ ){
				cc[i][k] = sc.nextInt();
			}
		}
		loop:for( int i=0; i<=100; i++ ){
			for( int j=0; j<=100; j++ ){
				for( int k=0; k<=100; k++ ){
					int a = cc[1][1]-i;
					int b = cc[1][2]-i;
					int c = cc[1][3]-i;
					int d = cc[2][1]-j;
					int e = cc[2][2]-j;
					int f = cc[2][3]-j;
					int g = cc[3][1]-k;
					int h = cc[3][2]-k;
					int l = cc[3][3]-k;
					if( a==d && d==g && b==e && e==h && c==f && f==l ){
						System.out.println("Yes");
						break loop;
					}
				}
			}
			if( i==100 ){
				System.out.println("No");
				break;
			}
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  ll N; cin >> N;
  vector<ll> a(5);
  rep(i, 0, 5) cin >> a[i];
  ll mx = 0;
  rep(i, 0, 5) {
    mx = max(mx, (N + a[i] - 1) / a[i]);
  }
  cout << mx + 4 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
  
class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
      
    String[] strAry = str.split(" ");
      
    int x = Integer.parseInt(strAry[0]);
    int y = Integer.parseInt(strAry[1]);
    int z = Integer.parseInt(strAry[2]);
     
    int i, cnt = 0;
     
    for(i = x; i <= y; i++){
        if(z % i == 0)
            cnt++;
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 24428
# 入力を受け取る
list_num = int(input())
places = list(map(int, input().split()))

# すべてをINFで初期化
dp_table = [99999999] * (list_num+1)

# 初期条件の作成
dp_table[0] = 0
dp_table[1] = abs(places[1] - places[0])


for i in range(2, list_num):
    dp_table_pre_1 = dp_table[i-1] + abs(places[i] - places[i-1])
    dp_table_pre_2 = dp_table[i-2] + abs(places[i] - places[i-2])
    dp_table[i] = min(dp_table_pre_1, dp_table_pre_2)

print(dp_table[list_num-1])


Measured memory_bytes: 13924
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scanf("%d %d", &x, &y)
	rem := y - 2*x
	if y <= 4*x && rem >= 0 && rem%2 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;

  long L[N];
  for (long i = 0; i < N; i++) {
      cin >> L[i];
  }
  
  long count = 0;

  for (long i = 0; i < N-2; i++) {
      for (long j = i + 1; j < N-1; j++){
          for (long k = j + 1; k < N; k++){
            if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j] && L[i] != L[j] && L[j] != L[k] && L[k] != L[i]){
                count += 1;
            }  
          }
      }
  }
  cout << count <<endl;
}

   
    


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int cnt = 0;
		for (int i = 0; i < n - 2; i++) {
			if (s.substring(i, i + 3).matches("ABC"))
				cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
}



Measured memory_bytes: 21716
n, a = map(int, input().split())
flag = 0

for i in range(n+1):
  for j in range(0, n-i+1):
    if 10000*i + 5000*j + 1000*(n-i-j) == a:
      x = i
      y = j
      z = n-i-j
      flag = 1
      break
      
if flag == 1:
  print(x, y, z)
else:
  print(-1,-1,-1)

Measured memory_bytes: 3064
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

const M: usize = 998244353;

#[fastout()]
fn main() {
    input! {
        a: usize, b: usize, c: usize, d: usize,
    }

    let mut dp = vec![vec![vec![0usize; d+1]; c+1]; 2];
    dp[1][a][b] = 1;
    for y in a..=c {
        for x in b..=d {
            if y != a {
                dp[0][y][x] = (dp[0][y-1][x] + dp[1][y-1][x]) * x;
                dp[0][y][x] %= M;
            }
            if x != b {
                dp[1][y][x] = dp[0][y][x-1] + dp[1][y][x-1] * y;
                dp[1][y][x] %= M;
            }
        }
    }
    let ans = (dp[0][c][d] + dp[1][c][d]) % M;
    println!("{}", ans);
}


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

ll INF = 1e+18;
using G = vector<map<int, int>>;

int 
main()
{
  int N; cin >> N;
  ll K; cin >> K;
  set<int> s;
  vector<ll> arr(100001);
  rep(i, 0, N){
    int a, b; cin >> a >> b;
    s.insert(a);
    arr[a] += b;
  }

  for(auto x : s){
    K -= arr[x];
    if(K <= 0){
      cout << x << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 6948
import scala.io.StdIn

object Main extends App {
  val Array(a, b) = StdIn.readLine().split(" ").map(_.toLong)
  val gcd_v = gcd(a, b)

  println(primeDivSize(gcd_v))
  

  def isPrime(i: Long) : Boolean = {
    if (i == 2l)
      true
    else
      !(2l to (i-1l)).exists(x => i % x == 0l)
  }

  def primeDivSize(i: Long) : Int = {
    val range :Long = Math.sqrt(i).ceil.toLong
    var target = i
    val ans :scala.collection.mutable.Set[Long] = scala.collection.mutable.Set[Long](1)
    var j = 2
    while (j <= range) {
      if (target % j == 0) {
        ans += j
        target = target / j }
      else j = j + 1
    }

    if (target != 1) ans += target

    ans.size
  }
  
  def gcd(a: Long,b: Long): Long = {
    if(b ==0l) a  else gcd(b, a%b)
  }
}
  



Measured memory_bytes: 25540
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  var x = o.a();
  var c = x/a;
  if(c <= a*b/2){
    var d = c/b*2;
    return Math.atan(b/d)*180/Math.PI;
  }
  var d = 2*b-2*c/a;
  return Math.atan(d/a)*180/Math.PI;
}

Measured memory_bytes: 25160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
  ll S;
  cin>>S;
  ll digit=0;
  ll d=S;
  while(d!=0){
    digit++;
    d/=10;
  }
  vector<ll> s(digit);
  rep(i,digit){
    s[i]=S%10;
    S/=10;
  }
  reverse(s.begin(),s.end());
  ll ans;
  ll cnt;
  ll cnt2;
  rep(i,digit-2){
    cnt=0;
    cnt2=0;
    cnt=s[i]*100+s[i+1]*10+s[i+2];
    cnt2=abs(753-cnt);
    if(i==0){
      ans=cnt2;
    }
    if(i>0){
      if(cnt2<ans){
        ans=cnt2;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>

using namespace std;

typedef long double ld;

const ld r = 6378.1;

ld dist(ld n1, ld n2, ld we) {
    ld h1 = r * sin(n1);
    ld h2 = r * sin(n2);
    ld p1 = r * cos(n1);
    ld p2 = r * cos(n2);
    ld sp = p1*p1 + p2*p2 - 2*p1*p2*cos(we);
    ld dh = h2 - h1;
    ld sl = dh*dh + sp;
    ld theta = acos(1-sl/(2*r*r));
    return r*theta;
}

ld rad(ld deg) {
    return deg / 180 * M_PI;
}

int main() {
    ld an, ae, bn, be;
    while (cin >> an >> ae >> bn >> be) {
        if (an == ae && ae == bn && bn == be && be == -1) break;
        cout << round(dist(rad(an), rad(bn), rad(ae-be))) << endl;
    }
    return 0;
}

Measured memory_bytes: 1308
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var charas = new HashSet<string>();
        var alfa = "abcdefghijklmnopqrstuvwxyz";
        var result = "";
        for(var i = 0; i < str.Length; i++)
        {
            charas.Add(str.Substring(i, 1));
        }
        for(var i = 0; i < alfa.Length; i++)
        {
            if (!charas.Contains(alfa.Substring(i, 1))){ result = alfa.Substring(i, 1);break; }
        }
        if (result=="") WriteLine("None");
        else WriteLine(result);
    }
}

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

int main(){
  int a=0;
  string S,T;
  cin >> S >> T;
  int N=S.size();
  if(S==T){
    cout << "Yes" << endl;
    return 0;
  }
  for(int i=0;i<N;i++){
    S = S[N-1] + S;
    S.pop_back();
    if(S==T){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

index_set=set(range(26))
for d in range(D):
  max_index=-1
  max_sd=-1
  for i in index_set:
    if max_sd<smat[d][i]:
      max_index=i
      max_sd=smat[d][i]
      
  max_index2=-1
  max_sd2=-1
  for i in range(26):
    if max_sd2<smat[d][i]:
      max_index2=i
      max_sd2=smat[d][i]
      
  if max_index==max_index2:
    print(max_index+1)
    index_set.remove(max_index)
  else:
    if max_sd2>16*max_sd:
      print(max_index2+1)
    else:
      print(max_index+1)
      index_set.remove(max_index)      
      
  if not index_set:
    index_set=set(range(26))
  else:
    sum_c=0
    for i in index_set:
      sum_c+=clist[i]
    if sum_c==0:
      index_set=set(range(26))

Measured memory_bytes: 75036
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

class BIT {
  private:
	vector<int> v;
	int n;

  public:
	BIT(int m) {
		n = m;
		v = vector<int>(n + 1, 0);
	}

	void add(int x, int val) {
		while (x <= n) {
			v[x] += val;
			x += (x & -x);
		}
	}

	// x以下の値の数を返す
	int getCntOfLTEX(int x) {
		int ans = 0;
		while (x > 0) {
			ans += v[x];
			x -= (x & -x);
		}
		return ans;
	}
};

vector<long long int> compress(vector<long long int> v) {
	set<long long int> s;
	for (int i = 0; i < v.size(); i++) {
		s.insert(v[i]);
	}
	map<long long int, int> m;
	int cnt = 1;
	for (auto itr = s.begin(); itr != s.end(); itr++) {
		m[*itr] = cnt;
		cnt++;
	}
	for (int i = 0; i < v.size(); i++) {
		v[i] = m[v[i]];
	}
	return v;
}

int main() {
	long long int n, k;
	cin >> n >> k;
	// suma[i] = a_0 + a_1 + ... a_{i - 1}
	vector<long long int> suma(n + 1, 0);
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		suma[i + 1] = suma[i] + a;
	}
	//   a[l] ... a[r - 1]間の平均は(suma[r] - suma[l]) / (r - l)
	// よって (suma[r] - suma[l]) / (r - l) >= k
	// となるような(l,r)のペアを探せば良い
	//   (suma[r] - suma[l]) / (r - l) >= k
	// <=> suma[r] - suma[l] >= k * (r - l)
	// <=> suma[r] - k * r >= suma[l] - k * l
	// <=> suma[r] >= suma[l] (suma[i] = suma[i] - k * i)
	for (long long int i = 1; i <= n; i++) {
		suma[i] = suma[i] - k * i;
	}
	suma = compress(suma);
	BIT bit(n + 1);
	long long int ans = 0;
	for (int i = 0; i <= n; i++) {
		ans += bit.getCntOfLTEX(suma[i]);
		bit.add(suma[i], 1);
		// cout << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 25216
#距離が同じときに注意，次を踏まえた方向に移動しないとダメ
#最寄りの神社/寺まで移動したときに寺/神社をすでに通過したか判定

import bisect
import sys
input = sys.stdin.readline

A,B,Q=map(int,input().split())
s=[0]*A
t=[0]*B

for i in range(A):
    s[i]=int(input())

for i in range(B):
    t[i]=int(input())
    
#神社/寺から最寄りの寺/神社のインデックスを記憶
ns=[0]*A
nt=[0]*B

def bi_se(L,x):
    k=bisect.bisect_left(L,x)
    if k==len(L):
        return k-1
    d1=abs(x-L[k])
    d2=abs(x-L[k-1])
    kk=k
    if d2<d1:
        kk=k-1
    return kk
    

for i in range(A):
    ns[i]=bi_se(t,s[i])
    
for i in range(B):
    nt[i]=bi_se(s,t[i])
    
for i in range(Q):
    x=int(input())
    ai=bi_se(s,x)
    la=abs(x-s[ai])#最寄りの神社まで移動
    k_start=bisect.bisect_left(t,x)
    k_next=bisect.bisect_left(t,s[ai])
    if k_start==k_next:
        la+=abs(s[ai]-t[ns[ai]])
    
    bi=bi_se(t,x)
    lb=abs(x-t[bi])
    k_start=bisect.bisect_left(s,x)
    k_next=bisect.bisect_left(s,t[bi])
    if k_start==k_next:
        lb+=abs(t[bi]-s[nt[bi]])
    print(min(la,lb))
    
    

Measured memory_bytes: 118108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int n, m;
  cin >> n >> m;

  vector<int> red(n, 0);
  vector<int> white(n, 1);
  red[0] = 1;
  white[0] = 0;

  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    if (red[x] > 0) {
      red[x]--;
      red[y]++;
      red[y] += white[y];
      white[y] = 0;
    } else {
      white[x]--;
      if (red[y] > 0) red[y]++;
      else white[y]++;
    }
  }

  int ans = 0;
  rep(i, n) {
    if (red[i] > 0) ans++;
  }

  cout << ans << endl;  

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n,k;
const LL mod=1e9+7;
LL dd(LL x){//n+1选x个 重复的数量
	LL l=0,r=x-1;
	LL L=(l+r)*(r-l+1)/2;
	r=n,l=n-x+1;
	LL R=(l+r)*(r-l+1)/2;
	return R-L+1;

}
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>k;
  LL ans=0;
  for(int i=k;i<=n+1;i++){
  	ans=ans+dd(i);
  	ans=ans+mod;
  	ans%=mod;
  }
  cout<<ans<<'\n';
 	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dict = new Dictionary<int, int>();

            foreach (var e in Enumerable.Range(1, nm[0]))
                dict[e] = 0;

            for (var i = 0; i <nm[1]; i++)
            {
                var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                dict[tmp[0]]++;
                dict[tmp[1]]++;
            }

            foreach (var d in dict.OrderBy(o => o.Key))
                Console.WriteLine(d.Value);
        }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n, t; cin >> n >> t;
    vector<ll> cand;
    for (int i = 0; i < n; ++i) {
        ll c, ti; cin >> c >> ti;
        if (ti <= t) cand.push_back(c);
    }
    sort(cand.begin(), cand.end());
    if (cand.size() == 0) {
        cout << "TLE" << endl;
    }
    else {
        cout << cand[0] << endl; 
    }
}

Measured memory_bytes: 3600
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();
      int sum = 0;
      
      for(int i=0;i<n;i++){
      	if(i<k){
        	sum+= x;
        }else{
        	sum+= y;
        }
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 35340
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min({a+b,b+c,a+c})<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL);
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007

int32_t main(){
IOS;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

int dp[n+1][n+1][2];
for(int i=1;i<=n;i++)
{
    dp[i][i][0] = a[i-1];
    dp[i][i][1] = 0;
}

for(int k=1;k<=n;k++)
for(int i=0;i+k<=n;i++)
{
   
   int j = i+k;
   

if(a[i-1] + dp[i+1][j][1] - dp[i+1][j][0] >= a[j-1] + dp[i][j-1][1] - dp[i][j-1][0])
{
    dp[i][j][0] = a[i-1] + dp[i+1][j][1];
    dp[i][j][1] = dp[i+1][j][0];
}

else 
{
    dp[i][j][0] = a[j-1] + dp[i][j-1][1];
    dp[i][j][1] = dp[i][j-1][0];
}


}

cout<<dp[1][n][0] - dp[1][n][1]<<endl;

}


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

int main(void) {
    string s, t, op;
    int ans = 0;
    cin >> s >> op >> t;
    if (op == "+") {
        ans = stoi(s) + stoi(t);
    } else {
        ans = stoi(s) - stoi(t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>plus, minus;
std::bitset<33> resP, resM, ans;

int main()
{
	in >> N;
	rep(bit, (1LL << 16))
	{
		LL resN = 0;
		rep(k, 16)
		{
			if (bit&(1LL << k)) resN += (1LL << (2 * k));
		}
		plus.push_back(resN);
	}
	rep(bit, (1LL << 16))
	{
		LL resN = 0;
		rep(k, 16)
		{
			if (bit&(1LL << k)) resN += (1LL << (2 * k + 1));
		}
		minus.push_back(resN);
	}
	std::sort(plus.begin(), plus.end());
	std::sort(minus.begin(), minus.end());
	rep(i, plus.size())
	{
		auto it = std::lower_bound(minus.begin(), minus.end(), plus[i] - N);
		if (it != minus.end())
		{
			if (*it == plus[i] - N)
			{
				resP = plus[i];
				resM = *it;
				break;
			}
		}
	}
	ans = resP | resM;
	bool flag = false;
	rep(i, 33)
	{
		if (ans[33 - i - 1] == 1) flag = true;
		if (flag) out << ans[33 - i - 1];
	}
	if (!flag) out << 0;
	out << std::endl;
	return 0;
}


Measured memory_bytes: 1528
import java.util.Scanner;

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

		char[] a = sc.next().toCharArray();
		sc.close();

		if (Character.isUpperCase(a[0])) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}
}


Measured memory_bytes: 26996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;

int main() {
	long long x;
	cin >> x;

	long long p=100;
	long long n=0;

	while (x>p)
	{
		p = p * 1.01;
		n++;
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  if (A==1 || B==1) {
    if (A==B) {
      cout << "Draw" << endl;
    }
    else {
      if (B!=1) {
        cout << "Alice" << endl;
      }
      else {
        cout << "Bob" << endl;
      }
    }
  }
  else {
    if (A>B) {
      cout << "Alice" << endl;
    }
    else {
      if (A<B) {
        cout << "Bob" << endl;
      }
      else {
        cout << "Draw" << endl;
      }
    }
  }
}


Measured memory_bytes: 3652
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10 ** 9 + 7

def main():
    result = 1
    i = -1
    j = -1
    used_area = 0

    A.sort(reverse=True)
    B.sort(reverse=True)

    for x in range(N * M, 0, -1):
        expanded_row = 0
        expanded_col = 0
        while i < N-1:
            if A[i+1] >= x:
                i += 1
                expanded_row += 1
            else:
                break

        while j < M-1:
            if B[j+1] >= x:
                j += 1
                expanded_col += 1
            else:
                break

        marked_row = False
        marked_col = False

        if expanded_row > 1:
            return(0)
        if expanded_row == 1:
            usable_row = 1
            marked_row = True
        else:
            usable_row = i+1

        if expanded_col > 1:
            return(0)
        if expanded_col == 1:
            usable_col = 1
            marked_col = True
        else:
            usable_col = j+1

        if marked_row or marked_col:
            usable_area = usable_row * usable_col
        else:
            usable_area = usable_row * usable_col - used_area

        # print('x:', x)
        # print('usable_row:', A[0:i+1])
        # print('usable_col:', B[0:j+1])
        # print('usable_area:', usable_area)

        if usable_area <= 0:
            return(0)

        result = result * usable_area % mod
        used_area += 1

    return(result)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int32_t main(){
	int n;
	cin>>n;
	cout<<(n+1)/2;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        mut a: [usize; n]
    }
    for _ in 0..k {
        if a.iter().all(|&x| x == n) {
            break;
        }
        let mut sum = vec![0; n + 1];
        for i in 0..n {
            sum[i.saturating_sub(a[i])] += 1;
            sum[cmp::min(i + a[i] + 1, n)] -= 1;
        }
        for i in 0..n {
            sum[i + 1] += sum[i];
            a[i] = sum[i] as usize;
        }
    }

    for &x in &a {
        print!("{} ", x);
    }
    println!();
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
template<typename T> T abs(T x){ return ((x < 0) ? -x : x);}

int main(){
	long long int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(max(a*c,a*d),max(b*c,b*d)) << endl;
}


Measured memory_bytes: 3648
package main

import "fmt"

var h, w int
var s []string

func main() {
	fmt.Scan(&h, &w)

	s = make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&s[i])
	}

	ans := 0
	// 全行ループ
	for sy := 0; sy < h; sy++ {
		// 全列ループ
		for sx := 0; sx < w; sx++ {
			// 壁ならば飛ばす
			if s[sy][sx] == '#' {
				continue
			}

			c := bfs(sy, sx)
			if ans < c {
				ans = c
			}
		}
	}
	fmt.Println(ans)
}

func bfs(sy, sx int) int {
	// 各地点までの距離を格納する
	dist := make([][]int, h)
	// 各地点の値の初期化
	for i := 0; i < h; i++ {
		dist[i] = make([]int, w)
		for j := 0; j < w; j++ {
			dist[i][j] = -1 // 訪れていない場所
		}
	}
	dist[sy][sx] = 0
	// bfs用のqueueを作成
	q := make([][]int, 0)
	// start地点を挿入
	q = append(q, []int{sy, sx})
	for len(q) > 0 {
		y, x := q[0][0], q[0][1]
		q = q[1:]
		// 上下左右移動用のスライスを作成
		dd := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
		for _, d := range dd {
			ny, nx := y+d[0], x+d[1]
			if 0 <= ny && ny < h && 0 <= nx && nx < w {
				// 道かつまだ訪れていない場所であれば距離を書き込む
				if s[ny][nx] == '.' && dist[ny][nx] == -1 {
					// 次の地点の値を設定
					dist[ny][nx] = dist[y][x] + 1
					q = append(q, []int{ny, nx})
				}
			}
		}
	}

	max := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			c := dist[i][j]
			if max < c {
				max = c
			}
		}
	}

	return max
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string n;
    cin>>n;
    int k;
    cin>>k;
    int len = n.size();
    vector<vector<vector<ll>>> dp(len+1,vector<vector<ll>>(2,vector<ll>(k+2)));
    dp[0][0][0] = 1;
    for(int i=0;i<len;++i)for(int j=0;j<=1;++j)for(int w=0;w<=k;++w){
        int ma = j ? 9 : n[i] - '0';
        for(int cur = 0; cur <= ma ; cur++){
            dp[i+1][j || cur < ma][w + (cur != 0)] += dp[i][j][w];
        }
    }
    cout << dp[len][0][k] + dp[len][1][k] << endl;
    return 0;
}

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

int main() {
    long long n,m;
    cin >>n>>m;
    {
        long long sum=1;
        if (n==1&&m==1) sum=1;
        else if (n==1||m==1) sum=max(n,m)-2;//true;
        else if (n==2||m==2) sum=0;
        else sum=(n-2)*(m-2);
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int main(){
    string s;
    cin>>s;

    int L=s.length();
    dp[0][0]=1;

    for(int i=0;i<L;i++)
    {
        if(s[i]=='?'){
            for(int k=0;k<10;k++)
            {
                for(int j=0;j<N;j++)
                {
                    dp[i+1][(10*j+k)%N] += dp[i][j];
                    dp[i+1][(10*j+k)%N] %= mod;
                }
            }

        }else{
            int k = s[i]-'0';
            for(int j=0;j<N;j++)
            {
                dp[i+1][(10*j+k)%N] += dp[i][j];
                dp[i+1][(10*j+k)%N] %= mod;
            }
        }
    }
    ull ans = dp[L][5]%mod;
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 10624
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;



int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	set<int> possible;
	for (int i = 1; i <= 9; i++)
		for (int j = 1; j <= 9; j++)
			possible.insert(i * j);
	int n;
	cin >> n;
	if (possible.count(n))
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int p[300];

int main() {
  rep (i, 10) p['0' + i] = i;
  p['T'] = 10;
  p['J'] = 11;
  p['Q'] = 12;
  p['K'] = 13;
  p['A'] = 14;
  while (true) {
    string trump;
    cin >> trump;
    if (trump == "#") break;
    string cards[4][13];
    rep (i, 4) rep (j, 13) cin >> cards[i][j];
    int ew = 0, ns = 0, now = 0;
    rep (j, 13) {
      int ii = 0, r = 0;
      rep (i, 4) {
	int rr = 0;
	if (cards[i][j][1] == trump[0]) {
	  rr = 20 + p[(int)cards[i][j][0]];
	} else if (cards[i][j][1] == cards[now][j][1]) {
	  rr = p[(int)cards[i][j][0]];
	} else {
	  rr = 0;
	}
	if (rr > r) {
	  r = rr;
	  ii = i;
	}
      }
      if (ii % 2 == 0) ++ns;
      else ++ew;
      now = ii;
    }
    if (ns > ew) cout << "NS " << ns - 6 << endl;
    else cout << "EW " << ew - 6 << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 100000
#define ll long long
#define rint register int
#define gc() getchar()
inline ll read(ll ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
int N, Q, tmp; ll X[MAXN+5], D[MAXN+5], R[MAXN+5], V, x;
void DFS(ll T){if(T <= X[1]){R[T] += V; return;} tmp = lower_bound(X+1,X+Q+1,T)-X-1, D[tmp] += T/X[tmp]*V, DFS(T%X[tmp]);}
int main()
{
	N = read(); X[Q=1] = N; for(int i = read(); i--; X[++Q] = x) for(x = read(); Q && x <= X[Q]; Q--);
	D[Q] = 1; for(rint i = Q; i > 1; D[i-1] += X[i]/X[i-1]*D[i], V = D[i], DFS(X[i]%X[i-1]), i--); R[X[1]] += D[1];
	for(rint i = N; i; R[i-1] += R[i], i--); for(rint i = 1; i <= N; printf("%lld\n",R[i]), i++); return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>   
using namespace std;      
int main(){
    while(true){
        int n; int m; int t; int p;
        cin >> n >> m >> t >> p;
        if(n==0&&m==0&&t==0&&p==0)break;

        int dc[t][2];
        int xy[p][2];

        for(int i=0;i<t;i++){
            cin>>dc[i][0]>>dc[i][1];
        }
        for(int i=0;i<p;i++){
            cin>>xy[i][0]>>xy[i][1];
        }
    int kasanari[n][m];

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            kasanari[i][j] = 1;
        }
    }

    for(int i=0;i<t;i++){
        int nw[n][m];
        if(dc[i][0]==1){
            for(int j=0;j<n;j++){
                for(int k=0;k<m;k++){
                    if(dc[i][1]-j-1<0){
                        if(dc[i][1]+j>n-1){
                            nw[j][k] = 0;
                        }else{
                            nw[j][k] = kasanari[dc[i][1]+j][k];
                        }
                    }
                    else{
                        if(dc[i][1]+j>n-1){
                            nw[j][k] = kasanari[dc[i][1]-j-1][k];
                        }
                        else{nw[j][k] = kasanari[dc[i][1]-j-1][k] + kasanari[dc[i][1]+j][k];
                            }
                    }
                }
            }
        }else{
            for(int j=0;j<n;j++){
                for(int k=0;k<m;k++){
                    if(dc[i][1]-k-1<0){
                        if(dc[i][1]+k>m-1){
                            nw[j][k] = 0;
                        }else{
                            nw[j][k] = kasanari[j][dc[i][1]+k];
                        }
                    }
                    else{
                        if(dc[i][1]+k>m-1){
                            nw[j][k] = kasanari[j][dc[i][1]-k-1];
                        }else{
                        nw[j][k] = kasanari[j][dc[i][1]-k-1] + kasanari[j][dc[i][1]+k];
                        }
                    }
                }
            }
        }

        for(int j=0;j<n;j++){
            for(int k=0;k<m;k++){
                kasanari[j][k] = nw[j][k];
            }
        }
    }


    for(int i=0;i<p;i++){
        cout << kasanari[xy[i][0]][xy[i][1]] << endl;
    }
    }
}


Measured memory_bytes: 3108
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    var min = Int.MIN_VALUE
    var max = Int.MAX_VALUE
    for (i in 0 until m) {
        val l = sc.nextInt()
        val r = sc.nextInt()
        min = Math.max(min, l)
        max = Math.min(max, r)
    }
    println(Math.max(0, max - min + 1))
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 40768
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;


int main()
{
    int a, b;
    cin>>a>>b;
    int n = 0, B = b, A = a;
    while(B)
    {
        B /= 10;
        A *= 10;
    }
    long long sum = A + b;
    long long q = sqrt(sum);
    if(q * q == sum)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	printf("%d\n",b+b-a); 
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		StringBuilder builder = new StringBuilder();
		Deque<Integer> S = new ArrayDeque<Integer>();
		Deque<int[]> L = new ArrayDeque<int[]>();

		char[] g = reader.readLine().toCharArray();
		int sum = 0;
		for (int i = 0; i < g.length; i++) {
			if (g[i] == '\\')
				S.add(i);
			else if (!S.isEmpty() && g[i] == '/') {
				int s = i - S.getLast();
				sum += s;
				while (!L.isEmpty() && S.getLast() < L.getLast()[0]) {
					s += L.getLast()[1];
					L.removeLast();
				}
				int[] data = { S.pollLast(), s };
				L.add(data);
			}
		}
		builder.append(sum).append('\n').append(L.size());
		for (int[] t : L) {
			builder.append(' ').append(t[1]);
		}
		System.out.println(builder);

	}
}

Measured memory_bytes: 22764
class dice:
    def __init__(self, li = [0] * 6):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
        else:
            print("▲err")
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
def solve():
    saikoro1 = dice(list(map(int, input().split())))
    li = list(map(int, input().split()))
    for i in range(6):
        saikoro3 = dice(li)
        if i:
            saikoro3.move("_SWENOOO"[i])
        if saikoro3.men == saikoro1.men:
            return "Yes"
        for _ in range(3):
            saikoro3.move("L")
            if saikoro3.men == saikoro1.men:
                return "Yes"
    return "No"
print(solve())



Measured memory_bytes: 5620
class combination():
    #素数のmod取るときのみ　速い
    def __init__(self, n, mod):
        self.n = n
        self.fac = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for j in range(1, n + 1):
            self.fac[j] = self.fac[j - 1] * j % mod

        self.inv[n] = pow(self.fac[n], mod - 2, mod)
        for j in range(n - 1, -1, -1):
            self.inv[j] = self.inv[j + 1] * (j + 1) % mod

    def comb(self, n, r, mod):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.inv[n - r] * self.inv[r] % mod

def examD(mod):
    X, Y = LI()
    if (X+Y)%3!=0:
        ans = 0
    else:
        N = (X+Y)//3
        if N>Y:
            ans = 0
        else:
            k = (N-(X-Y))//2
            C = combination(N,mod)
            ans = C.comb(N,k,mod)
    print(ans)


import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(mod)


Measured memory_bytes: 49136