akhauriyash/Code-Regression huggingface dataset:
import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let input1 = readLine()!.split(" ")
let H = input1[0]
let W = input1[1]
let input2 = readLine()!.split(" ")
let h = input2[0]
let w = input2[1]

print((H-h)*(W-w))

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

const int maxn = 2e5 + 10;
int n, a[maxn]; 
LL ans;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++)
        scanf("%d", &a[i]);

    for(int i = 1; i <= n; i ++) {
        if(a[i] > i - 1)
            return !printf("-1");
        if(i >= 2) {
            if(a[i] > a[i - 1] + 1)
                return !printf("-1");
            if(a[i] == a[i - 1] + 1)
                ans ++;
            else
                ans += (LL) a[i];
        }
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back

using namespace std;
using ll=long long;
// using ll=int;

const ll mod = (ll)(1e9+7);

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

int main(){

    /*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("myoutput.txt", "w", stdout);
    #endif
    */

    fast;
    ll t = 1;
    // cin >> t;
    while(t--){
        ll n, m; cin >> n >> m;
        cout << n*(n-1)/2+m*(m-1)/2 <<endl;
        
    }
    // cerr << (double)clock()/CLOCKS_PER_SEC << endl;
    return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    string S, T;
    cin >> S;
    cin >> T;
    int n = S.size();
    for_(i,0,n) {
        if (S[i] != T[i]) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

Measured memory_bytes: 3624
import java.util.Scanner

object Main {

  def solve(sc: => Scanner): Unit = {
    val D, L = sc.nextInt
    println(((D / L): Int) + D % L)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 44996
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
x = [input() for _ in range(int(input()))]
c = Counter(x)
mx = max(c.values())
ans = []
for i,j in c.items():
    if j==mx:
        ans.append(i)

print("\n".join(sorted(ans)))

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

bool binary_search(vector<int> A,int key){
    int n = A.size();
    int left = 0,right = n;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(A[mid] == key) return true;
        else if(key < A[mid]) right = mid;
        else left = mid + 1;
    }
    return false;
}

int main(){
    int n,q;
    cin >> n;
    vector<int> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> q;
    vector<int> t(q);
    int sum = 0;
    for(int i=0;i<q;i++){
        cin >> t[i];
    }
    for(int i=0;i<q;i++){
        if(binary_search(s,t[i])) sum++;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3936
#include<queue>
#include <iostream>
#include <string>
#include<map>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if (s=="SUN") cout<<7;
   else if(s=="MON")  cout<<6;
   else if(s=="TUE")  cout<<5;
   else if(s=="WED")  cout<<4;
   else if(s=="THU")  cout<<3;
   else if(s=="FRI")  cout<<2;
   else if(s=="SAT")  cout<<1;
   return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
P = [*map(lambda x: int(x)-1, input().split())]
C = [*map(int, input().split())]

INF = 10**18
max_score = -INF
for st in range(n):
    lc = 0 # lap count
    lap_sc = 0 # lap score
    nx = st
    while True:
        lc += 1
        lap_sc += C[nx]
        nx = P[nx]
        if nx == st: break

    lap_sc = max(0, lap_sc)
    sum_sc = 0
    kc = 0
    while True:
        kc += 1
        if k < kc: break
        sum_sc += C[nx]
        score = sum_sc + lap_sc * ((k - kc) // lc)
        max_score = max(max_score, score)
        nx = P[nx]
        if nx == st: break

print(max_score)


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

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def dist(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

def main():
	N = int(input())
	vAB = [linput() for _ in [0,]*N]

	res = 0
	for a,b in reversed(vAB):
		c = (a+res)%b
		if c:
			res += b-c
	
	print(res)
	#sT = "No Yes".split()
	#print(sT[res])
	

if __name__ == "__main__":
	main()


Measured memory_bytes: 28008
integer :: n,l(100),x
      integer :: i,ans,d
      
      read*,n,x
      read*,l(1:n)
      
      d = 0
      ans = 0
      if( d<=x ) ans = ans + 1
      
      do i = 2,n+1
        d = d + l(i-1)
        if( d<=x ) ans = ans + 1
      end do
      
      print*,ans
      
      end program

Measured memory_bytes: 256
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define debug(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    string s;
    ll k;
    cin >> k >> s;

    if (s.size()<=k) cout << s << endl;
    else cout << s.substr(0,k) + "..." << endl; 
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;

ll n, m, k, t;

int main() {
    pyshnapyshnakaa
    ll q, w, e, a, b, c;
    cin >> n;
    // cout << n * (n - 1) / 2 << endl;
    vector <pll> ANS;
    if (n % 2 == 0) {
        for (q = 0; q < n; q++) {
            for (w = q + 1; w < n; w++) {
                if (q + w != n - 1) {
                    ANS.pb(mp(q, w));
                    // cout << q + 1 << " " << w + 1 << endl;
                }
            }
        }
    }
    else {
        for (q = 0; q < n - 1; q++) {
            ANS.pb(mp(q, n - 1));
        }
        for (q = 0; q < n - 1; q++) {
            for (w = q + 1; w < n - 1; w++) {
                if (q + w + 2 != n) {
                    ANS.pb(mp(q, w));
                }
            }
        }
    }
    cout << ANS.size() << endl;
    for (auto p : ANS) {
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3752
import sys
input=sys.stdin.readline
from collections import deque
n,m=map(int,input().split())
Edges=[[] for _ in range(n)]
for _ in range(m):
    u,v=map(lambda x: int(x)-1,input().split())
    Edges[u].append(v)
s,t=map(lambda x: int(x)-1,input().split())
q=deque()
q.append((s,0))
Flag=[[False]*n for _ in range(3)]
while q:
    v,dist=q.popleft()
    if Flag[dist%3][v]==True:
        continue
    if dist%3!=0:
        for to in Edges[v]:
            q.append((to,dist+1))
        Flag[dist%3][v]=True
        continue
    elif v==t:
        print(dist//3)
        exit()
    else:
        for to in Edges[v]:
            q.append((to,dist+1))
        Flag[0][v]=True
print(-1)

Measured memory_bytes: 59908
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b, r = c + d;
  if(l > r) cout << "Left" << endl;
  else if(l == r) cout << "Balanced" << endl;
  else cout << "Right" << endl;
  return 0;
}

Measured memory_bytes: 384
/*
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
*/

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#define N_MAX 100001
using namespace std;

int dp[N_MAX];
int h[N_MAX];
int n;

int res;

void solve()
{
    dp[1] = 0;

    for(int i = 1;i<=n;i++)
    {
        if(i-1>=1 && i-2>=1){
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
        else if(i-1>=1){
            dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        }
    }
    res = dp[n];

}

int main()
{
    cin>>n;
    for(int i = 1;i<=n;i++)cin>>h[i];
    solve();
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
    Q.append(input().split())
t=0
res=[]
while Q!=[]:
    if int(Q[0][1])<=q:
        res.append([Q[0][0],int(Q[0][1])+t])
        t+=int(Q[0][1])
    else:
        Q.append([Q[0][0],int(Q[0][1])-q])
        t+=q
    del Q[0]
for i in res:
    print(i[0]+" "+str(i[1]))

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

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
    int N;
    cin >> N;
    int nt = 1, na = 1;
    int n;
    rep(i, N)
    {
        int T, A;
        cin >> T >> A;
        n = max((nt + T - 1) / T, (na + A - 1) / A);
        nt = n * T;
        na = n * A;
    }
    cout << na + nt << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int min(int a, int b) {
  if (a < b) return a;
  else return b;
}
int ze(int a) {
  if (a > 0) return a;
  else return -a;
}
int main () {
  int N, K;
  cin >> N >> K;
  K = min(N, K);
  int h[100004];
  for (int i = 0; i < N; i ++) {
    cin >> h[i];
  }
  int cost[100004];
  cost[1] = 0;
  cost[2] = ze(h[1] - h[0]);
  if (N == 2) {
    cout << cost[2] << endl;
    return 0;
  }
  int k = cost[2] + ze(h[2] - h[1]);
  int j;
  if (K > 1) {
    j = ze(h[2] - h[0]); 
  }
  else j = 10000000;
  cost[3] = min(k, j);
  if (N == 3) {
    cout << cost[3] << endl;
    return 0;
  }
  for (int i = 4; i <= N; i ++) {
    long int m = 1000002000;
    for (int l = 1; l <= K; l ++) {
      if (l > i - 1) break;
      int p = cost[i - l] + ze(h[i -1] - h[i - l - 1]);
      if (m > p) m = p;
    }
    cost[i] = m;
  }
  cout << cost[N] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using namespace std;

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >>N;
  vi A(N);
  rep(i,0,N) {cin >>A[i];}
  int sum=accumulate(all(A),0);
  cout <<(sum%2==0 ? "YES":"NO") <<'\n';
  return 0;
}


Measured memory_bytes: 3728
#include<stdio.h>


int main(){

  int i;
  int n;
  long long int a, sum = 0, min, max;

  scanf("%d", &n);

  for(i = 0;i < n;i++){
    scanf("%lld", &a);
    if(i == 0){
      min = a;
      max = a;
    }

    if(min > a){
      min = a;
    }

    if(max < a){
      max = a;
    }
    
    sum += a;
  }
  
  printf("%lld %lld %lld\n",min, max, sum);

  return 0;
  
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

ll fac[1000010], finv[1000010], inv[1000010];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000010; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll N,K;
    cin >> N >> K;
    COMinit();
    for(int i = 1;i <= K;i++) {
        cout << COM(K - 1, i - 1) * COM(N - K + 1, i) % MOD << endl;
    }
}

Measured memory_bytes: 23680
#!/usr/bin/env python3
ans=0
n=int(input())
A=list(map(int,input().split()))
B=[0]*(n+1)
for i in range(n):
    B[A[i]]=i+1
LL=[int(i) for i in range(n+2)]
RR=[int(i) for i in range(n+2)]
for i in range(n,0,-1):
    l=LL[B[i]]
    r=RR[B[i]]
    ans+=(B[i]-l+1)*(r-B[i]+1)*i
    LL[r+1]=l
    RR[l-1]=r
print(ans)


Measured memory_bytes: 35776
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  long long int N;
  string S;
  long long int i,j,k;
  cin >> N;
  long long int num[5] = {0};
  for(i=0;i<=N-1;i++){
    cin >> S;
    if(S.at(0) == 'M') num[0]++;
    if(S.at(0) == 'A') num[1]++;
    if(S.at(0) == 'R') num[2]++;
    if(S.at(0) == 'C') num[3]++;
    if(S.at(0) == 'H') num[4]++;
    }  
  long long int sum = 0;
  for(i=0;i<=2;i++)
    for(j=i+1;j<=3;j++)
      for(k=j+1;k<=4;k++)
        sum += num[i]*num[j]*num[k];
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		HashMap<Integer,Integer> cards=new HashMap<Integer,Integer>();
		for(int i=0; i<N; i++) {
			int tmp=sc.nextInt();
			if(cards.containsKey(tmp)) {
				cards.put(tmp, cards.get(tmp)+1);
			}
			else {
				cards.put(tmp, 1);
			}
		}
		int[][] cards_cpy=new int[cards.size()][2];
		int i=0;
		for(Entry<Integer,Integer> e:cards.entrySet()) {
			cards_cpy[i][0]=e.getValue();
			cards_cpy[i][1]=e.getKey();
			//pl(cards_cpy[i][0]+" "+cards_cpy[i][1]);
			i++;
		}
		quick_sort(cards_cpy,0,cards.size()-1);
		int itimai=0;
		int fukusu=0;
		int fukusyu=0;
		for(i=0; i<cards.size(); i++) {
			if(cards_cpy[i][0]>1) {
				fukusyu++;
				fukusu+=cards_cpy[i][0];
			}
			else if(cards_cpy[i][0]==1) {
				itimai++;
			}
		}
		if((fukusu-fukusyu)%2==0) {
			pl(itimai+fukusyu);
		}
		else {
			pl(itimai+fukusyu-1);
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	static void quick_sort(int[][] d, int left, int right) {
		if (left>=right) {
			return;
		}
		int p = d[(left+right)/2][0];
		int l = left, r = right;
		int tmp,tmp1,tmp2;
		while(l<=r) {
			while(d[l][0] < p) { l++; }
			while(d[r][0] > p) { r--; }
			if (l<=r) {
				tmp = d[l][0]; d[l][0] = d[r][0]; d[r][0] = tmp;
				tmp1=d[l][1]; tmp2=d[r][1]; d[l][1]=tmp2; d[r][1]=tmp1;
				l++; r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
}

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

    vector<int> A(n);
    vector<int> B(n);
    int maxwk=0;
    int index;
    for(int i=0;i<n;i++){
      cin>>A.at(i)>>B.at(i);
      if(A.at(i)>maxwk){
        maxwk=A.at(i);
        index=i;
      }
    }
  
  cout<<A.at(index)+B.at(index)<<endl;
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    REP(i,n){
        cin>>a[i];
    }
    map<int,int> mp;
    map<int,int> pm;
    REP(i,n){
        mp[-a[i]-i]+=1;
    }
    ll ans  = 0;
    for(int i=n;i>0;i--){
        mp[-a[i]-i] -=1;
        int t = mp[a[i]-i];
        ans+=t;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 21208
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9
int main() {
    int a;
    cin >> a;
    if (a < 30)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

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

const int maxi = 200001;
vector<int> p;
int isP[maxi], cum[maxi];

void sieve() {
    int ok[maxi], lim = 100000;
    int limn = sqrt(lim);
    memset(ok, 0, sizeof(ok));

    for(int i = 4; i<=lim; i+=2) ok[i] = 1;

    for(int i=3; i<=limn; i+=2) {
        if(!ok[i]) {
            for(int j = i*i; j<=lim; j+=2*i) {
                ok[j] = 1;
            }
        }
    }

    p.push_back(2);
    isP[2] = 1;
    for(int i=3; i<=lim; i+=2) {
        if(!ok[i]) {
            isP[i] = 1;
            p.push_back(i);
        }
    }
}

int main() {
    sieve();

    for(int i=0; i<p.size(); i++) {
        int a = p[i];
        int b = (a + 1) / 2;
        if(isP[a] && isP[b]) cum[a] = 1;
    }

    for(int i=1; i<maxi; i++) cum[i] += cum[i - 1];

    int q;
    scanf("%d", &q);

    while(q--) {
        int l, r;
        scanf("%d %d", &l, &r);
        printf("%d\n", cum[r] - cum[l - 1]);
    }

    return 0;
}


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

int main() {
	int a, b;
	char c;
	int l[100];
	for (int i = 0;; i++) {
		cin >> a >> c >> b;
		if (c == '+') {
			l[i] = a + b;
		}else if (c == '-') {
			l[i] = a - b;
		}else if (c == '*'){
			l[i] = a * b;
		}else if (c=='/'){
			l[i] = a / b;
		}else if (c=='?'){
			for (int j = 0; j < i; j++){
				cout << l[j] << endl;
			}
			break;
		}
	}
}

Measured memory_bytes: 3084
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
for i in range(len(x)):
   a.append(int(x[i]))
if a[0] == 1:a[0] = 14
if a[1] == 1:a[1] = 14

if a[0] == a[1]:print("Draw")
elif a[0] < a[1]:print("Bob")
else :print("Alice")

Measured memory_bytes: 5916
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9+7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


int num[1010], A[1010][1010];
bool used[1010];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	REP(i, N) {
		REP(j, N - 1) {
			cin >> A[i][j];
			A[i][j]--;
		}
	}
	int ans = 0;
	bool ok = false;
	while (!ok) {
		bool done = false;
		REP(i, 1010)used[i] = false;
		REP(i, N) {
			if (num[i] == N - 1)continue;
			if (used[i])continue;
			int pai = A[i][num[i]];
			if (A[pai][num[pai]] == i) {
				if (used[pai])continue;
				num[i]++;
				num[pai]++;
				used[i] = true;
				used[pai] = true;
				done = true;
			}
		}
		ans++;
		ok = true;
		REP(i, N) {
			if (num[i] != N - 1) {
				ok = false;
				break;
			}
		}
		if (!done) {
			print(-1);
			return 0;
		}
	}
	print(ans);
}



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

int n;
vector<int> a;

int main() {
    while (scanf("%d", &n) == 1) {
        a.assign(n, 0);
        for (auto &x : a) scanf("%d", &x);

        sort(a.begin(), a.end());
        reverse(a.begin(), a.end());
        long long res = 0;
        for (int i = 1; i < n; i++) res += a[i / 2];
        printf("%lld\n", res);
    }
}


Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef pair<string, int>P;

int main() {
	int n;
	while (cin >> n, n) {
		vector<P>v;
		for (int i = 0;i < n;i++) {
			string sa;
			int a;
			cin >> sa >> a;
			v.push_back(P(sa, a));
		}

		int m;
		cin >> m;
		for (int i = 0;i < m;i++) {
			string s;
			cin >> s;
			int a;
			cin >> a;

			int it=-1;
			int mny = 0;
			for (int j = 0;j < a;j++) {
				string sb;
				cin >> sb;
				for (int k = 0;k < n;k++) {
					if (sb == v[k].first) {
						mny += v[k].second;
					}
				}
			}
			for (int j = 0;j < v.size();j++) {
				if (s == v[j].first)it = j;
			}
			if (it == -1)v.push_back(P(s, mny));
			else v[it].second = min(v[it].second,mny);
		}

		string ans;
		cin >> ans;
		for (int i = 0;i < v.size();i++) {
			if (ans == v[i].first) {
				cout << v[i].second << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3120
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c;
string s, t;

int main()
{
	cin >> a >> b;
	if (500 * a >= b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] l = new int[n];

        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        Arrays.sort(l);
        int sum = 0;
        for (int i = 0; i < n-1; i++) {
            sum += l[i];
        }

        System.out.println(l[n-1] < sum ? "Yes" : "No");
    }
}


Measured memory_bytes: 23124
import sys
def input(): return sys.stdin.readline().rstrip()

def pl(n):
    if n > 0:
        return n
    else:
        return 0

def main():
    MOD = 1000000007
    n, m = map(int, input().split())

    dp = [0] * (n+1)
    dp[0] = 1
    
    for _ in range(m):
        dp[int(input())] = -1

    for i in range(1, n+1):
        if dp[i] < 0:
            continue
        dp[i] += pl(dp[i-1])
        if i >= 2:
            dp[i] += pl(dp[i-2])
        dp[i] %= MOD
    print(max(dp[-1], 0))

if __name__ == '__main__':
    main()


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

#define y1 as214
#define ii pair < int , ll >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)

#define ll long long
#define oo INT_MAX

const int N = 1e2 + 5;
const int K = 1e5 + 5;
ll n , k;
ll mod = 1e9 + 7;
ll a[N];
ll dp[N][K] , dp1[N][K];

/// dp[i][j] là số cách chia kẹo cho i đưa nhỏ đầu tiên và tốn đúng j viên kẹo.
/// dp1[i][j] là số cách chia kẹo cho i đứa nhỏ đầu tiên và tốn ko quá j viên kẹo.

int main()
{
    //freopen("M.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    FOR(i , 1 , n)
        cin >> a[i];
    FOR(i , 0 , a[1])
    {
        dp1[1][i] = i + 1;
        dp[1][i] = 1;
    }
    FOR(i , a[1] + 1 , k)
        dp1[1][i] = dp1[1][i - 1];

    FOR(i , 1 , n)
    {
        dp1[i][0] = 1;
        dp[i][0] = 1;
    }

    FOR(i , 2 , n)
    {
        FOR(j , 1 , k)
        {
            dp[i][j] = (dp[i][j] + (dp1[i - 1][j] - ((j - a[i] - 1 >= 0) ? dp1[i - 1][j - a[i] - 1] : 0))) % mod;
            dp1[i][j] = (dp[i][j] + dp1[i][j - 1]) % mod;
        }
    }
    if(dp[n][k] < 0)
        cout << dp[n][k] + mod << endl;
    else
        cout << dp[n][k];
}


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

void print(int A[], int N);
void InsertionSort(int A[], int N);

void print(int A[], int N) {
    for (int i = 0; i < N; i++) {
        printf("%d", A[i]);
        if (i != N-1) printf(" ");
    }
    printf("\n");
}

void InsertionSort(int A[], int N) {
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while(0 <= j && v < A[j]) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        print(A, N);
    }
}

int main () {
    int N; cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    print(A, N);
    InsertionSort(A, N);
}


Measured memory_bytes: 3224
n = int(input())
if n < 10:
  print(1)
else:
  sqn = int(n**0.5)
  c = float("inf")
  for i in range(1, sqn+1):
    if n%i == 0:
      d = max(len(str(i)), len(str(n//i)))
      c = min(c, d)
  print(c)

Measured memory_bytes: 3060
n = int(input())
h = [int(i) for i in input().split()]
c, m = 0, 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    c += 1
  else:
    m = max(c, m)
    c = 0
print(max(c, m))

Measured memory_bytes: 14224
//118B (2)
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n=0, m=0, k=0, menu=0, cnt=0;
    cin >> n >> m;
    map<int, int>mp;
    rep(i, n){
        cin >> k;
        rep(j, k){
            cin >> menu;
            mp[menu] +=1;
        }
    }
    rep(i, m+1){
        if (mp[i]==n) cnt+=1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[9];
bool ok[9];
vector<vector<int>> ls = {{0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}, {0,4,8}, {2,4,6}};
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	for(int i=0; i<9; i++) {
		cin >> a[i];
	}
	int n;
	cin >> n;
	for(int i=0; i<n; i++) {
		int t;
		cin >> t;
		for(int j=0; j<9; j++) {
			if(a[j] == t) {
				ok[j] = 1;
			}
		}
	}
	for(auto& v: ls) {
		bool yes = 1;
		for(int i: v) {
			if(!ok[i]) {
				yes = 0;
			}
		}
		if(yes)
			return !(cout << "Yes");
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <iostream> 

using namespace std; 
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long int
#define REPI(a, b, i, inc) for(ll i = a; i < b; i = i + inc)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define test ll t; cin>>t; while(t--)
#define testi ll t; cin>>t; REP(tc,1,t+1)
#define vec vector
#define veci vector<ll>
#define pi pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define uset unordered_set
#define umap unordered_map

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
int main() {
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int n,k;
	cin>>n;
	int arr[n];
	int c=0;
	REP(i,0,n){ cin>>arr[i]; if((i+1)%2==1 && arr[i]%2==1) c++;}
	cout<<c;

        return 0;
    }

Measured memory_bytes: 3180
s = int(input())
l = [s]
i = 0
while True:
    if s % 2 == 0:
        s //= 2
        if s in l:
            print(i+2)
            exit()
        else:
            l.append(s)
    else:
        s = 3 * s + 1
        if s in l:
            print(i+2)
            exit()
        else:
            l.append(s)
    i += 1

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
		int N = in.nextInt();
		int[] t = new int[N + 1];
		int[] x = new int[N + 1];
		int[] y = new int[N + 1];
		t[0] = 0;
		x[0] = 0;
		y[0] = 0;
		String ans = "Yes";
		
		for(int i = 0; i < N; i++) {
			t[i] = in.nextInt();
			x[i] = in.nextInt();
			y[i] = in.nextInt();
		}
		
		for(int i = 1; i <= N; i++) {
			int dif_t = Math.abs(t[i] - t[i - 1]);
			int dif_x = Math.abs(x[i] - x[i - 1]);
			int dif_y = Math.abs(y[i] - y[i - 1]);
			
			if(dif_t >= dif_x + dif_y && (dif_t - dif_x + dif_y) % 2 == 0) {
				
			}else{
				ans = "No";
			}
		}
		out.println(ans);
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}


Measured memory_bytes: 45076
// atcoder/abc125/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> a(n);
    cin >> a;

    const lli inf = 1LL << 60;
    const int N = 1e5 + 5;
    lli dp[N][2];
    fill(&dp[0][0], &dp[N - 1][2 - 1] + 1, -inf);
    dp[0][0] = 0;

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 2; ++j) {
        for (int k = 0; k < 2; ++k) {
          setmax(dp[i + 1][k], dp[i][j] + a[i] * (j ^ k ? -1 : +1));
        }
      }
    }
    lli x = dp[n - 1][1] + a.back() * -1;
    lli y = dp[n - 1][0] + a.back();
    cout << max(x, y) << endl;
  }

  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll K;
    cin >> K;

    if (K % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll cnt = 1;
    ll n = 7;
    rep (i, 1000000) {
        if (n%K == 0) {
            cout << cnt << endl;
            return 0;
        }

        n = (n*10+7)%K;
        cnt++;
    }

    cout << -1 << endl;
}


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

using namespace std;

using ll = long long;

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

    int q;
    cin >> q;
    map<string, int> mp;
    while (q--)
    {
        int aaa;
        cin >> aaa;
        string key = "";
        int x = -1;
        if (aaa == 0)
        {
            cin >> key >> x;
            mp[key] = x;
        }
        else if (aaa == 1)
        {
            cin >> key;
            cout << mp[key] << endl;
        }
        else
        {
            cin >> key;
            mp.erase(key);
        }
    }
}



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

namespace ABC176
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            decimal ans = 0;
            for (var i = 1; i < n; i++)
            {
                if (a[i] >= a[i - 1]) continue;

                ans += a[i - 1] - a[i];
                a[i] = a[i - 1];
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 47064
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto Q = RD;
	auto s = RD!string;
	auto t = new char[](Q);
	auto d = new char[](Q);
	foreach (i; 0..Q)
	{
		t[i] = RD!char;
		d[i] = RD!char;
	}

	long[256] cnt1, cnt2;
	long l, r = s.length - 1;
	foreach_reverse (i; 0..Q)
	{
		auto num = t[i] - 'A';
		if (d[i] == 'L')
		{
			if (t[i] == s[l])
				++l;
			if (r != s.length - 1)
			{
				if (s[r+1] == t[i])
					++r;
			}
		}
		else if (d[i] == 'R')
		{
			if (t[i] == s[r])
				--r;
			if (l != 0)
			{
				if (s[l-1] == t[i])
					--l;
			}
		}
	}

	writeln(r - l + 1);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 3964
_ = int(input())
bef_time = 0
bef_x = 0
bef_y = 0
ans = True

for i in range(_):
    next = input().split()
    next_time = int(next[0])
    next_x = int(next[1])
    next_y = int(next[2])
    time = next_time - bef_time
    range = abs(next_x - bef_x) + abs(next_y - bef_y)

    if (next_time - bef_time) < range:
        ans = False
        break

    if time % 2 == 0:
       if range % 2 != 0:
          ans = False
          break
    else:
       if range % 2 == 0 or range == 0:
          ans = False
          break

    bef_time = next_time
    bef_y = next_y
    bef_x = next_x



if ans == True:
    print('Yes')
else:
    print('No')


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

const int N = 505;

int n, m, a[N][N];
char c;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		a[i][0] = 1, a[i][m - 1] = 2;
	for (int i = 0; i < n; i++)
		for (int j = 1; j < m - 1; j++)
			a[i][j] = (i & 1) + 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			cin >> c;
			if(c == '#')
				a[i][j] = 3;
		}
	for (int i = 0; i < n; i++, cout << '\n')
		for (int j = 0; j < m; j++)
			cout << (a[i][j] & 1? '#': '.');
	cout << '\n';
	for (int i = 0; i < n; i++, cout << '\n')
		for (int j = 0; j < m; j++)
			cout << (a[i][j] & 2? '#': '.');
	return 0;
}

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

using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;

    vector<long long> H(N);
    unordered_map<long long, bool> ng;

    for (int i = 0; i < N; ++i) {
        long long h;
        cin >> h;
        H.at(i) = h;
    }

    for (int i = 0; i < M; ++i) {
        long long A, B;
        cin >> A >> B;

        if (H.at(A - 1) < H.at(B - 1)) {
            ng[A] = true;
        } else if (H.at(A - 1) > H.at(B - 1)) {
            ng[B] = true;
        } else {
            ng[A] = true;
            ng[B] = true;
        }
    }

    long long count = 0;

    for (int i = 1; i <= N; ++i) {
        if (!ng[i]) {
            count++;
        }
    }

    cout << count << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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 modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string S;
  cin >> S;
  
  bool ok1 = (S[0] == S[1]) && (S[1] == S[2]);
  bool ok2 = (S[1] == S[2]) && (S[2] == S[3]);

  if(ok1 || ok2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


  return 0;
}



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

int main()
{
    int n,h;
    cin >> n >> h;
    vector<int> a(n),b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int maxa = a[n - 1];
    long long ans = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if(b[i] > maxa)
        {
            h -= b[i];
            ans++;
        }
        else
        {
            break;
        }
        if(h <= 0)break;
    }

    if(h > 0)ans += (h + maxa - 1) / maxa;

    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int dp[3010][3010];
string s, t;

void rev(int i, int j) {
  if (1 <= i && 1 <= j) {
    if (s[i - 1] == t[j - 1]) {
      rev(i - 1, j - 1);
      cout << s[i - 1];
    } else if (dp[i - 1][j] > dp[i][j - 1]) rev(i - 1, j);
    else rev(i, j - 1);
  }
}

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

  REP (i, s.size() + 1) {
    REP (j, t.size() + 1) {
      dp[i][j] = 0;
    }
  }

  REP (i, s.size()) {
    REP (j, t.size()) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
      }
    }
  }

  rev(s.size(), t.size());
  cout << endl;
}


Measured memory_bytes: 35968
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <assert.h>
using namespace std;
typedef long long ll;
const long long MOD = 1e9+7;
long long powmod(long long a,long b){ll res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){
    if(b&1)res=res*a%MOD;a=a*a%MOD;}
    return res;
}
void solve(){
//    long long n;
//    cin >> n;
//    for(int i = 1;i < n ;i++)if(n%i==0)cout << i << endl;
     int N,ans=0;
     cin>>N;
     vector<int> a(N);
     for(auto &x:a)cin>>x;
     while(1){
        int i=0;
        while(i<N&&a[i]==0)i++;
        if(i==N)break;
        while(i<N&&a[i])a[i]--,i++;
        ans++;
     }
     cout<<ans;
}
int main(){
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

constexpr int MaxN = 110;
int A[MaxN];

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

    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    sort(A, A + n);
    int ans = A[n - 1] - A[0];
    cout << ans << endl;
}

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

using namespace std;

using l = long;
using ll = long long;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using pii = vector<pair<int, int>>;

int main()
{
    int N, K, res = 0;
    cin >> N >> K;
    vi a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        if (a[i] >= K) res++;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using M = atcoder::modint998244353;
struct S { M a; int s; };
struct F { M a, b; };
S op(S l, S r) { return S{l.a + r.a, l.s + r.s}; }
S e() { return S{0, 0}; }
S m(F l, S r) { return S{r.a * l.a + r.s * l.b, r.s}; }
F c(F l, F r) { return F{l.a * r.a, r.b * l.a + l.b}; }
F id() { return F{1, 0}; }
int main() {
	int n, q; cin >> n >> q;
	vector<S> a(n);
	for (auto& i : a) {
		int x; cin >> x;
		i = S{x, 1};
	}
	atcoder::lazy_segtree<S, op, e, F, m, c, id> seg(a);
	while (q--) {
		int t, l, r, c, d;
		cin >> t >> l >> r;
		if (t == 0) {
			cin >> c >> d;
			seg.apply(l, r, F{c, d});
		} else {
			cout << seg.prod(l, r).a.val() << endl;
		}
	}
}

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

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

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

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

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

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

    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> num(30);
    for (int i=2; i<30; i++) {
        num[i] = num[i-1] + i-1;
    }

    ll ans = N;
    int l = 0, r = 0, used = A[0];
    for (;;) {
        while (r < N-1) {
            if ((used & A[r+1]) == 0) {
                used |= A[r+1];
                r++;
                ans++;
            } else {
                break;
            }
        }
        DUMP2(l, r);
        used &= ~A[l];
        l++;
        ans += r - l;
        if (l >= N) break;
    }
    cout << ans+1 << endl;
}



Measured memory_bytes: 1024