akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
ll INF = (1 << 30);
ll MOD = 1e9 + 7;
ll cnt = 0;


int main() {
    int n,q; ll k;
    cin >> n >> k >> q;
    vector<ll> point(n);
    rep(i,q){
        int a; cin >> a;
        a--;
        point[a]++;
    }
    rep(i,n){
        point[i] = point[i] - q + k;
        if(point[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}

Measured memory_bytes: 1408
def q2():
    S = list(input())
    ans = 'Yes'
    for i in range(len(S)):
        if i % 2 == 0 and S[i] not in ['R', 'U', 'D']:
            ans = 'No'
        elif i % 2 == 1 and S[i] not in ['L', 'U', 'D']:
            ans = 'No'

    print(ans)


if __name__ == '__main__':
    q2()


Measured memory_bytes: 3060
a=list(map(int, input().split()))
b=list(map(int, input().split()))
if len(a) > len(b):
    print('GREATER')
    exit()
elif len(a) < len(b):
    print('LESS')
    exit()
else:
    for i in range(len(a)):
        if a[i] > b[i]:
            print('GREATER')
            exit()
        elif a[i] < b[i]:
            print('LESS')
            exit()
print('EQUAL')

Measured memory_bytes: 9216
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	q := getNextInt(scanner)
	for i := 0; i < q; i++ {
		b := getNextInt(scanner)
		e := getNextInt(scanner) - 1
		for b < e {
			aa[b], aa[e] = aa[e], aa[b]
			b++
			e--
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Fprint(writer, " ")
		}
		fmt.Fprint(writer, aa[i])
	}
	fmt.Fprintln(writer, "")
}



Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
int H,W;
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

struct Solver{
  int _N;
  int _gy;
  int _gx;
  int _ans;
  queue< vector<int> > _que;
  vector< vector<char> > _grid;
  explicit Solver(int ans, int N, int gy, int gx, vector< vector<char> > grid)
    : _ans(ans), _N(N), _gy(gy), _gx(gx), _grid(grid){
    vector<int> vec_start=vector<int>(3);
    vec_start.at(0) = 0;
    vec_start.at(1) = 0;
    vec_start.at(2) = 1;
    _que.push(vec_start);
  }
  bool check(int i, int j){
    if(_grid[i][j]=='#'){
      return false;
    }else{
      return true;
    }
  }
  int solve(){
    while(!_que.empty()){
      vector<int> vec = _que.front();
      for(int k=0; k<4; k++){
        int y = vec[0]+dir[k][0];
        int x = vec[1]+dir[k][1];
        if(y<0 || x<0 || y>=H || x>=W) continue;
        int count = vec[2];
        if(check(y,x)){
          _grid[y][x] = '#';
          vector<int> vec_new=vector<int>(3);
          vec_new.at(0)=y;
          vec_new.at(1)=x;
          vec_new.at(2)=count+1;
          _que.push(vec_new);
        }
      }
      //cout << _que.size() << "\n";
      //cout << "goal : " << _grid[_gy][_gx] << "\n";
      _que.pop();
      if(_grid[_gy][_gx]=='#') break;
    }
    if(_grid[_gy][_gx]=='#'){
      return _N - _ans - _que.back()[2];
    }else{
      return -1;
    }
  }
};

int main(){  
  cin >> H >> W;
  int num_black = 0;
  vector< vector<char> > grid(50, vector<char>(50));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> grid[i][j];
      if(grid[i][j]=='#'){
        num_black++;
      }
    }
  }
  Solver solver(num_black,H*W,H-1,W-1,grid);
  cout << solver.solve() << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  string a,b;
  cin>>a>>b;
  if(a==b)
  cout<<"EQUAL"<<endl;
  if(a.size()>b.size())
  cout<<"GREATER"<<endl;
  if(a.size()<b.size())
  cout<<"LESS"<<endl;
  if(a.size()==b.size()&&a>b)
  cout<<"GREATER"<<endl;
  if(a.size()==b.size()&&a<b)
  cout<<"LESS"<<endl;
}



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

int main(){
  int A, B, K, i, num = 0;
  cin >> A >> B >> K;
  // if(K == 1){
  //   cout << 1 << endl;
  //   return 0;
  // }
  if(A < B){
    int tmp = A;
    A = B;
    B = tmp;
  }
  for(i = A; i > 0; i--){
    if(A % i == 0){
      if(B % i == 0){
        if(num < K)num++;
      }
    }
    if(num == K){
      break;
    }
  }
  cout << i << endl;
  return 0;
}


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

int main() {
  int n,d,k,count;
  cin>>n>>d>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    for(int j=1;j<=d;j+=a.at(i)){
      count++;
    }
  }
  cout<<count+k<<endl;
}


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

using namespace std;

#define ll long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005

int main()
{
	
	int t,coun = 1;
	string ch;
	cin >> t >> ch;
	for(int i=1; i < t; i++)
	{
		if(ch[i]!=ch[i-1]) coun++;
	}
	cout << coun << endl;
	return 0;
}

Measured memory_bytes: 512
module AOJ_Volume0117;

import std.stdio,std.string,std.conv,std.algorithm;

int main()
{
	int n,m;
	int cost[21][21];
	foreach(i;0..21)
	{
		foreach(j;0..21)
		{
			cost[i][j] = 100000;
		}
	}

	n = readln.chomp.to!int;
	m = readln.chomp.to!int;

	foreach(i;0..m)
	{
		string[] s = readln.chomp.split(",");
		int a = s[0].to!int;
		int b = s[1].to!int;
		int c = s[2].to!int;
		int d = s[3].to!int;
		cost[a][b] = c;
		cost[b][a] = d;
	}

	foreach(k;1..n+1)
	{
		foreach(i;1..n+1)
		{
			foreach(j;1..n+1)
			{
				cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
			}
		}
	}

	string[] s = readln.chomp.split(",");
	int x1 = s[0].to!int;
	int x2 = s[1].to!int;
	int y1 = s[2].to!int;
	int y2 = s[3].to!int;
	int ans = y1 - y2;
	ans -= cost[x1][x2] + cost[x2][x1];
	ans.writeln;
	return 0;
}

Measured memory_bytes: 1060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
ll a[N];

ll gcd(ll x, ll y) {
    return !y ? x : gcd(y, x % y);
}

int main() {
    int n, m;
    cin >> n >> m;
    ll lcm = 1;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(lcm <= 2*m) {
            lcm = a[i] * lcm / gcd(a[i], lcm);
        }
    }
    for(int i = 0; i < n; i++) {
        if(!((lcm / a[i]) & 1)) {
            cout << 0 << endl;
            return 0;
        }
    }
    lcm /= 2;
    ll ans = m / lcm;
    if(ans & 1) ans = ans / 2 + 1;
    else ans = ans / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    H = list(map(int, input().split()))

    for i in range(N - 1, 0, -1):
        if H[i - 1] <= H[i]:
            continue
        elif H[i - 1] - 1 == H[i]:
            H[i - 1] -= 1
        else:
            print('No')
            exit(0)

    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 14224
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
lim = max(A)+1
cnt = [0]*lim
is_prime = [1]*lim

for x in A:
	cnt[x] += 1

for i in range(2, lim):
	if not is_prime[i]: continue
	for j in range(2*i, lim, i):
		is_prime[j] = 0
	for j in range(1, -(-lim//i)):
		cnt[i*j] += cnt[j]

ans = 0

for a in A:
    if cnt[a] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 36552
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	long long N; cin >> N;
	VLL r(N), l(N);
	string S; cin >> S;
	bool ok = true;
	ll WW=0;
	//for (int i = 0;i < N - 1;i++) if (S[i] == 'W')W++;
	ll EE=0 ;
	//long long r=999999999,rr, l=999999999,lll, ans = 9999999999;
	l[N - 1] = 0;
	r[0] = 0;
	for (int i = N - 2;i >= 0;i--) {
		if (S[i + 1] == 'E') EE++;
			l[i] += EE;
	}
	for (int i = 1;i < N;i++) {
		if (S[i - 1] == 'W') WW++;
			r[i] += WW;
	}
	for (int i = 0;i < N;i++) {
		r[i] += l[i];
		//cout << r[i] << endl;
	}
	ll ans = *MIN(all(r));
	cout << ans << endl;
}


Measured memory_bytes: 5508
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>P(N,0);
  int tmp=0;
  int sum=0;
  for (int i=0;i<N;i++){
    cin>>P[i];
    tmp=max(tmp,P[i]);
    sum+=P[i];
  }
  cout<<sum-tmp/2<<endl;
}
    
  

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

int main() {
  int a[] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int x, y;
  cin >> x >> y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//在 POJ 和小白菜中，该库禁用！
//在 USACO中请用文件。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#define inf 1<<29
//data:
using namespace std;
char c,d,e,f;
int main(){
	ios::sync_with_stdio(false);
	cin>>c>>d>>e>>f;
	if(c==d&&d==e||d==e&&e==f){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

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

  if (x == "a" || x == "e" || x == "i" || x == "o" || x == "u") {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


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

int main()
{
    int N;
    cin >> N;
    char c;
    int i;
    int cnt = 0;
    bool flag[4] = {0};
    for (i = 0; i < N; i++)
    {
        cin >> c;
        if (c == 'P')
            if (flag[0] == false)
            {
                cnt++;
                flag[0] = true;
            }
        if (c == 'W')
            if (flag[1] == false)
            {
                cnt++;
                flag[1] = true;
            }
        if (c == 'G')
            if (flag[2] == false)
            {
                cnt++;
                flag[2] = true;
            }

        if (c == 'Y')
        {
            if (flag[3] == false)
            {
                cnt++;
                flag[3] = true;
            }
        }
    }
    if (cnt == 4)
        cout << "Four" << endl;
    else if (cnt == 3)
        cout << "Three" << endl;
    // ここにプログラムを追記
}


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

int main(){
	int i,j;
	cin>>i>>j;
	if(i>j){
		cout<<"a > b"<<endl;
 	}else if(i==j){
		cout<<"a == b"<<endl;
	}else{
		cout<<"a < b"<<endl;
	}
}


Measured memory_bytes: 3092
import java.util.Scanner;

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

    int h, w, area, syu;
    h = scan.nextInt();
    w = scan.nextInt();
    area = h * w;
    syu = (h + w) * 2;
    System.out.println(area + " " + syu);
  }
}

Measured memory_bytes: 25884
#include<stdio.h>
#include<string.h>
#include<stack>
#include<stdlib.h>
using namespace std;
char s[1000006];
stack<int> st;
int a,b;
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        if(*s=='+')
        {
            a=st.top();
            st.pop();
            b=st.top();
            st.pop();
            st.push(a+b);
        }
        else if(*s=='-')
        {
            b=st.top();
            st.pop();
            a=st.top();
            st.pop();
            st.push(a-b);
        }
        else if(*s=='*')
        {
            a=st.top();
            st.pop();
            b=st.top();
            st.pop();
            st.push(a*b);
        }
        else
        {
            st.push(atoi(s));
        }
    }
    printf("%d\n",st.top());
    return 0;
}



Measured memory_bytes: 2760
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

Measured memory_bytes: 3316
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
  int n = scan!int, m = scan!int;
  auto uf = new UnionFind(n);
  foreach(j; 0 .. m){
    int a = scan!int - 1, b = scan!int - 1;
    uf.unite(a, b);
  }
  int ans = 0;
  foreach(i; 0 .. n){
    ans.raiseTo(uf.getSize(i));
  }
  ans.writeln;
}
import std.conv;
class UnionFind{
    int[] rootOf;
    int[][] kidsOf;
    this(int n){
        rootOf = new int[](n);
        kidsOf = new int[][](n);
        foreach(i; 0 .. n) rootOf[i] = i, kidsOf[i] = [i];
    }
    void unite(int a, int b){
        int ra = rootOf[a], rb = rootOf[b];
        if(ra == rb) return;
        if(kidsOf[ra].length < kidsOf[rb].length) unite(b, a);
        else foreach(k; kidsOf[rb]) rootOf[k] = ra, kidsOf[ra] ~= k;
    }
    int find(int a){
        return rootOf[a];
    }
    int getSize(int a){
        return kidsOf[rootOf[a]].length.to!int;
    }
}

Measured memory_bytes: 30252
N = int(input())
listA = list(map(int,input().split()))
n = 0
cont = True
while 1:
    for i in range(N):
        if listA[i] % 2 == 1:
            cont = False
            break
        else:
            listA[i] = listA[i]/2
    
    if cont:
        n +=1
    else:
        break

print(n)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int A, B, C; cin>>A>>B>>C;
  cout << max(max(A*10+B+C,	A+B*10+C), A+B+C*10) << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
 ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 string s;
 cin >> s;
 int n = s.size();
 for(int i = 1; i < n; i++)
 {
   if(s[i] == s[i - 1])
   {
     cout << (i - 1) + 1 << ' ' << i + 1;
     return 0;
   }
 }
 for(int i = 2; i < n; i++)
 {
   if(s[i] == s[i - 2])
   {
     cout << (i - 2) + 1 << ' ' << i + 1;
     return 0;
   }
 }
 cout << -1 << ' ' << -1;
 return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> C)
{
    ll dp[200010];
    dp[0] = 1;
    ll left[200010];

    for (int i = 0; i < 200010; i++)
    {
        left[i] = -1;
    }

    for (int i = 0; i < N; i++)
    {
        dp[i + 1] = dp[i];
        int c = C[i];

        if (left[c] >= 0 && left[c] < i - 1)
            dp[i + 1] = (dp[i + 1] + dp[left[c] + 1]) % MOD;

        left[c] = i;
    }

    cout << dp[N] << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> C(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &C[i]);
    }
    solve(N, std::move(C));
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;

int n;
vector<long> a, b;

int main(){

  cin >> n;
  a = vector<long>(n+1);
  b = vector<long>(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];

  long sum = 0;
  rep(i,n){
    if(a[i] <= b[i]){
      sum += a[i];
      long rest = 0;
      if(a[i+1] - (b[i] -a[i]) < 0) rest = a[i+1];
      else rest = b[i] - a[i];
      a[i+1] -= rest;
      sum += rest;
    }
    else sum += b[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e3 + 5;
ll sum=1e16+5;
ll a[maxn];
ll b[maxn][maxn];//b[i][j],i表示获得ai的代价,j表示进行j次第二种操作 
int main()
{
	ll n,x;
	scanf("%lld %lld",&n,&x);
	for(ll i = 1;i <= n; i++)scanf("%lld", &a[i]);
	for(ll i = 1;i <= n; i++)
	{
		b[i][0] = a[i];
		for(ll j = 1;j <= n - 1;j++)
		{
			ll pos = i - j;
			if(pos <= 0)pos = n + pos;
			b[i][j] = min(b[i][j - 1],a[pos]);	
		 } 
	}
	for(ll i = 0;i <= n - 1;i++)
	{
		ll ans = 0;
		for(ll j = 1;j <= n;j++)
		{
			ans += b[j][i];
		}
		sum=min(sum,ans + x * i);
		
		
	}
	printf("%lld\n",sum);
	return 0;
 } 

Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <vector>
#define rep(i,N) for(int i=0;i<(N);i++)
using namespace std;

int main(){
	long long D,T,S;
	cin>>D>>T>>S;
	if(S*T>=D){
		cout<<"Yes"<<endl;
		}else{cout<<"No"<<endl;}
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import math
 
K = int(input())
ans_list = []
ans = 0
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans_list = [a, b, c]
            gcd_ans = ans_list[0]
            for item in ans_list:
                gcd_ans = math.gcd(gcd_ans, item)
            ans += gcd_ans
print(ans)

Measured memory_bytes: 68492
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n;
    cin >> n;
    int p;
    bool t=0;
    int ans=0;
    rep(i,n) {
        cin >> p;
        if (i==p-1) {
            if (t==0) ++ans;
            t=!t;
        } else t=0;
    }
    cout << ans << endl;
}

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

void main()
{
  auto rd = readln.split, n = rd[0].to!size_t, x = rd[1].to!long;
  auto a = readln.split.to!(long[]);

  auto ans = 0L;
  foreach (i; 1..n) {
    auto s = a[i-1] + a[i];
    if (s <= x) continue;
    auto r = min(s - x, a[i]);
    a[i] -= r;
    ans += r;
    auto t = s - x - r;
    if (t > 0) {
      ans += t;
      a[i-1] -= t;
    }
  }

  writeln(ans);
}


Measured memory_bytes: 4436
//#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
 
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>
 
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
 
#define eps 1e-9
#define bs 1000000007
#define bsize 256
 
using namespace std;
 
const int INF = 1e9;
const int N = 3000002;
 
string st;
int tests;
int cur_size;
int whr[N];
int done[N];
vector<int> memo[N];
 
int DIF;
 
long long Pw[N];
 
long long fact[N], invf[N];
 
long long pw(long long a, long long b)
{
	if (b == 0)
		return 1;
	if (b % 2)
		return a*pw(a, b - 1) % bs;
	return pw(a*a%bs, b / 2);
}
 
long long inv(long long x)
{
	return pw(x, bs - 2);
}
 
long long C(long long n, long long m)
{
	long long res = fact[n];
	res *= invf[m];
	res %= bs;
	res *= invf[n - m];
	return res%bs;
}
long long count_ways(int n, int m)
{
	if (n < m)
		return 0;
	long long picks = C(n, m);
	return picks*Pw[n - m] % bs;
}
	
void run_solver(int sz)
{
	if (done[sz])
		return;
	done[sz] = 1;
	long long total = 0;
 
	++DIF;
 
	vector<int> v;
	v.push_back(0);
	for (int len = 1; len <N; len++)
	{
		total = total * 26 % bs;
		//if (len<10)
			//cout << count_ways(len - 1, sz - 1) << endl;
 
		total += count_ways(len - 1, sz - 1);
		total %= bs;
		v.push_back(total);
	}
	
	memo[DIF] = v;
	whr[sz] = DIF;
}
 
int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif 
   
	ios_base::sync_with_stdio(0);
	//cin.tie(0);
	
	Pw[0] = 1;
	for (int i = 1; i < N; i++)
	{
		Pw[i] = Pw[i - 1] * 25 % bs;
	}
 
	fact[0] = 1;
	for (int i = 1; i < N; i++)
	{
		fact[i] = fact[i - 1] * i%bs;
	}
 
	for (int i = 0; i < N; i++)
	{
		invf[i] = inv(fact[i]);
	}
 
	tests=1;
	int len;
	cin>>len;
	cin >> st;
 	len+=st.length();
	run_solver(st.size());
 
	cur_size = st.size();
 
	for (; tests; --tests)
	{
		int tp;
		tp=2;
		if (tp == 1)
		{
			cin >> st;
			run_solver(st.size());
			cur_size = st.size();
		}
		else
		{
			int id = whr[cur_size];
			cout << memo[id][len] << endl;
		}
	}
 
	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 168792
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mi = [0]*(1 << n)
for bit in range(1 << n):
  for i in range(n-1):
    if bit & (1 << i):
      for j in range(i+1, n):
        if bit & (1 << j):
          mi[bit] += a[i][j]
for bit in range(1 << n):
  v = bit
  while v > (bit//2):
    if mi[bit] < mi[v] + mi[bit^v]:
      mi[bit] = mi[v] + mi[bit^v]
    v = (v-1) & bit
print(mi[-1])

Measured memory_bytes: 44072
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto&& e: a) {
    cin>>e;
  }
  sort(a.begin(), a.end(),greater<int>());
  int max=*max_element(a.begin(), a.end());
  vector<pair<int,int>> tmp;
  for (int i = 1; i < n; ++i)
  {
    tmp.emplace_back(make_pair(abs(2*a[i]-max),a[i]));
  }
  sort(tmp.begin(), tmp.end());
  cout<<a[0]<<" "<<tmp[0].second;
}

Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <algorithm>//binary_search
using namespace std;

int main() {
	// your code goes here
	vector<int> v;
	int count=0;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		v.push_back(tmp);
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int tmp;
		cin>>tmp;
		if(binary_search(v.begin(),v.end(),tmp)){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
using namespace std;
const int MM=100013;
const int inf=2000000013;
long long dp[113][MM];
pair<int,int> T[MM];
int main()
{
    ios_base::sync_with_stdio(0);
    int n,W;
    cin>>n>>W;
    for(int i=1;i<=n;i++)   cin>>T[i].first>>T[i].second;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=W;j++)   dp[i][j]=dp[i-1][j];
        for(int j=T[i].first;j<=W;j++)
        {
            dp[i][j]=max(dp[i][j],dp[i-1][j-T[i].first]+T[i].second);
        }
    }
    cout<<dp[n][W]<<endl;
    return 0;
}


Measured memory_bytes: 78592
n = int(input())
a = list(map(int, input().split()))
b = [0] * (n+1)
m = max(a)
c = [0] * (m+1)
for i in a:
    c[i] += 1
for j in range(1, m+1):
    c[j] = c[j] + c[j-1]
#print(c)
for k in reversed(a):
    #print(k)
    #print(b)
    b[c[k]] = k
    c[k] -= 1

for i in range(1,n):
    print(b[i], end=' ')
print(b[n])


Measured memory_bytes: 224380
#include<stdio.h>
#define H 500000

void maxHeapify(int*,int);
void buildMaxHeap(int*);

int num;


int main(){
  int h[H],i;

  scanf("%d",&num);

  for(i=1; i<=num; i++) scanf("%d",&h[i]);

  buildMaxHeap(h);

  for(i=1; i<=num; i++) printf(" %d",h[i]);
  printf("\n");

  return 0;
}

void maxHeapify(int *h,int i){
  int left,right,largest,tmp;
  left = i*2;
  right = i*2+1;
  
  if(left<=num && h[left]>h[i]) largest = left;
  else largest = i;
  
  if(right<=num && h[right]>h[largest]) largest = right;
  
  if(largest != i){
    tmp = h[i];
    h[i] = h[largest];
    h[largest] = tmp;
    maxHeapify(h,largest); 
  }
  
}


void buildMaxHeap(int *h){
  int i;
  for(i=num/2; i>0; i--) maxHeapify(h,i);

}

Measured memory_bytes: 2552
def main():
    N = int(input())
    P = [int(i) for i in input().split()]
    A = [30000*(i+1) for i in range(1, N+1)]
    B = [30000*(N-i+1) for i in range(1, N+1)]
    for i, p in enumerate(P):
        B[p-1] += i
    print(*A)
    print(*B)


if __name__ == '__main__':
    main()


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


int main(){
	int N;
	cin >> N;
	if(N == 1){
		cout << "Yes" << endl;
		return 0;
	}
	vector<long long> H(N);
	for(int i = 0; i < N; i++) cin >> H.at(i);
	
	bool jdg = true;
	
	for(int i = N - 1; i > 0; i--){
		if(H[i] < H[i - 1]){
			H[i - 1]--;
		} else {
			continue;
		}
		if(H[i] < H[i - 1]){
			jdg = false;
			break;
		}
	}
	
	if(jdg) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = [0]
for i in range(1, N):
    if A[i - 1] - A[i] > 0:
        B.append(A[i - 1] - A[i])
        A[i] += A[i - 1] - A[i]
print(sum(B))


Measured memory_bytes: 32372
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
typedef pair<ll,ll> pll;
#define F first
#define S second
#define printer(v) for(auto f: v) cout<<f<<" "
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define ipair pair<int,int>
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    // cout << setprecision(12) << fixed;

    string s; cin>>s;
    if(s=="ABC")cout<<"ARC\n";
    else cout<<"ABC\n";
    return 0;
}

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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define V vector<int>

using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;
    int i, j, k, l, m, n = 0, count = 0;
    for(i = A / 10000; i < B / 10000 + 1; i++) {
        for(j = 0; j < 10; j++) {
            for(k = 0; k < 10; k++) {
                for(l = 0; l < 10; l++) {
                    for(m = 0; m < 10; m++) {
                        n = 10000*i + 1000*j + 100*k + 10*l + m;
                        if(A > n || B < n) continue;
                        if(i == m && j == l) count++;
                    }
                }
            }
        }
    }
    OUT(count);
}

Measured memory_bytes: 256
n = int(input())
a = (int(x) for x in input().split())
count2 = 0
count = 0
for num in a:
    if (num % 2) == 0:
        count2 += 1
        if (num % 3) == 0 or (num % 5) == 0:
            count += 1

if count2== count  :
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <stdio.h>}
#include <string.h>
#include <stdlib.h>

int stack[200];
int it = 0;

void push(int x){
	stack[it] = x;
	it++;
}

int pop(){
	it--;
	return stack[it];
}

int main(void){
		
	int a,b,i;
	
	char str[1000000];
	while(scanf("%s",str)!=EOF){
		if(strcmp(str,"+")==0){
			a = pop();
			b = pop();
			push(a+b);
			
		}else if(strcmp(str,"-")==0){
			a = pop();
			b = pop();
			push(b-a);
			
		}else if(strcmp(str,"*")==0){
			a = pop();
			b = pop();
			push(a*b);
			
		}else if(strcmp(str,"/")==0){
			a = pop();
			b = pop();
			push(a/b);
			
		}else{
			i = atoi(str);
			push(i);
			
		}
	}
	printf("%d\n",stack[0]);

	return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
using namespace std;
int N, M, K;
int main(){
  cin >> N >> M >> K;
  bool f = false;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= M; j++){
      int t = j * (N - i) + i * (M - j);
      // cout << t << endl;
      if( t == K ){
	f = true;
	break;
      }
    }
    if( f ) break;
  }
  if( f )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())

ans = 0

if A == B == C and A % 2 == 0:
    ans = -1
else:
    while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        A, B, C = (B + C) // 2, (C + A) // 2, (A + B) // 2
        ans += 1

print(ans)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
a = [0] + list(map(int, input().split()))

ans = 0
for i, v in enumerate(a):
    if i == 0:
        continue
    if i == a[v]:
        ans += 1
print(ans // 2)


Measured memory_bytes: 84160
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    double res;
    for(int n, w; cin >> n >> w, n; cout << res << endl){
        vi v(n);
        rep(i, n) cin >> v[i];
        vi hist(*max_element(all(v)) / w + 1);

        rep(i, n){
            hist[v[i] / w]++;
        }
        int ub = *max_element(all(hist));

        double diff = hist.size() != 1 ? 1. / (hist.size() - 1):1.;
        double dens = 1.;
        res = 0.01;

        rep(i, hist.size()){
            res += dens * hist[i] / ub;
            dens -= diff;
        }
    }

	return 0;
}

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

using namespace std;

int main()
{
    int e,y;
    cin >> e >> y;
    if(e==0)
    {
        if(y<=1911)
        {
            cout << "M" << y-1867 << endl;
        }
        else if(y>=1912&&y<=1925)
        {
            cout << "T" << y-1911 << endl;
        }
        else if(y>=1926&&y<=1988)
        {
            cout << "S" << y-1925 << endl;
        }
        else if(y>=1989&&y<=2016)
        {
            cout << "H" << y-1988 << endl;
        }
    }
    else if(e==1)
    {
        cout << 1867+y << endl;
    }
    else if(e==2)
    {
        cout << 1911+y << endl;
    }
    else if(e==3)
    {
        cout << 1925+y << endl;
    }
    else if(e==4)
    {
        cout << 1988+y << endl;
    }
    return(0);
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    long long int n, k;
    cin >> n >> k;
    long long int ans = k;
    for (int i = 0; i < n - 1; i++)
    {
        ans *= (k - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

 
int main()
{
	int n;
	cin >> n;
	int flag = 1;
	vector<int> v(n);
	
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	
	sort(v.begin(),v.end());
	
	for(int i=0;i<n-1;i++){
		if(v[i] == v[i+1])flag = 0;
	}
	
	if(flag == 0){
		cout << "NO" << endl;
	}else cout << "YES" << endl;
	
    
    return 0;
}

Measured memory_bytes: 1024
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut a: Vec<usize> = sc.vec(n);
    a.sort();
    let max = a[n - 1];
    let mut count: Vec<u32> = vec![0; max + 1];
    for a in a.into_iter() {
        count[a] += 1;
    }

    for d in 0..(max + 1) {
        if d * 2 < max {
            if count[d] > 0 {
                println!("Impossible");
                return;
            }
        } else if d * 2 - 1 == max {
            if count[d] != 2 {
                println!("Impossible");
                return;
            }
        } else if d * 2 == max {
            if count[d] != 1 {
                println!("Impossible");
                return;
            }
        } else {
            if count[d] < 2 {
                println!("Impossible");
                return;
            }
        }
    }
    println!("Possible");
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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 ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll x,t;
  cin >> x >> t;
  cout << max(x-t,0ll) << endl;
}


Measured memory_bytes: 12160
N = gets.to_i
E = N.times.map{ gets.split.map(&:to_i) }
a = E.minmax_by{|x,y| x + y }.then{|min, max| (min[0] - max[0]).abs + (min[1] - max[1]).abs }
b = E.minmax_by{|x,y| x - y }.then{|min, max| (min[0] - max[0]).abs + (min[1] - max[1]).abs }
puts [a,b].max

Measured memory_bytes: 28252
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int n,h,w;
	cin>>n>>h>>w;
	if(n-h==0 || n-w==0)
	cout<<max(n-h+1,n-w+1)<<endl;
	else
	cout<<(n-h+1)*(n-w+1)<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int Max=3e5+100;
int get_root(int *f, int root){
    return f[root]==root?root:f[root]=get_root(f, f[root]);
}
void merge(int *f, int x,int y){
    int i=get_root(f, x);
    int j=get_root(f, y);
    f[i]=j;
}
int f[Max], g[Max];
void init(int n){
    for(int a=0; a<=n; a++)f[a]=a, g[a]=a;
}
int vis[Max], num[Max];
vector<int> vec[Max];
map<int, int>ma;
int main(){
    int n, m, k, u, v;
    scanf("%d%d%d", &n, &m, &k);
    init(n);
    for(int a=0; a<m; a++){
        scanf("%d%d", &u, &v);
        merge(f, u, v);
    }
    for(int a=0; a<k; a++){
        scanf("%d%d", &u, &v);
        merge(g, u, v);
    }
    for(int a=1; a<=n; a++)vec[get_root(f, a)].push_back(a);
    for(int a=0; a<=n; a++){
        ma.clear();
       // memset(num, 0, sizeof(num));
        for(int b=0; b<vec[a].size(); b++){
            ma[get_root(g, vec[a][b])]++;
            //num[get_root(g, vec[a][b])]++;
        }
        for(int b=0; b<vec[a].size(); b++){
            vis[vec[a][b]]+=ma[get_root(g, vec[a][b])];
        }
    }
    for(int a=1; a<=n; a++)printf("%d%c", vis[a], a==n?'\n':' ');
    return  0;
}

Measured memory_bytes: 18040
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)    (x).begin(),(x).end()
# define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
# define mp        make_pair
# define eb        emplace_back
# define REP(i, a) for (int i = 0; i < (a); i++)
# define INIT      std::ios::sync_with_stdio(false);std::cin.tie(0);

int n;
bool solve(const vector<pair<int, int>>&bi, LL mid) {
	LL foo = 0;
	priority_queue<int> fo;
	if (mid == 0) {
		return true;
	}
	for (int i = 0; i < mid; i++) {
		fo.push(bi[i].second);
		foo += bi[i].second;
	}
	if (bi[mid - 1].first*mid >= foo) {
		return true;
	}
	for (int i = mid; i < n; i++) {
		foo += bi[i].second;
		fo.push(bi[i].second);
		foo -= fo.top();
		fo.pop();
		if (bi[i].first*mid >= foo) {
			return true;
		}
	}
	return false;
}
int main() {
	int i, j; cin >> n;
	vector<pair<int, int>>bi(n);
	for (i = 0; i < n; i++) {
		cin >> bi[i].second >> bi[i].first;
	}
	sort(bi.rbegin(), bi.rend());
	int bmax = n + 1, bmin = 0;
	while (bmax - bmin > 1) {
		int mid = (bmax + bmin) / 2;
		if (solve(bi, mid)) {
			bmin = mid;
		}
		else {
			bmax = mid;
		}
	}
	cout << bmin << endl;
}

Measured memory_bytes: 8268
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

typedef pair<long long int, long long int> P;

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

    vector<P> ab(n);
    for (long long int i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ab.begin(), ab.end());

    long long int ans = 0;
    for (long long int i = 0; i < n; i++) {
        if (ab[i].second <= m) {
            ans += ab[i].first * ab[i].second;
            m -= ab[i].second;
        } else {
            ans += ab[i].first * m;
            m = 0;
        }
    }

cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int A[MAXN], lf[MAXN], rt[MAXN];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &A[i]);
	}
	stack <int> S;
	S.push(0);
	for (int i = 1; i <= n; ++i)
	{
		while(A[i] < A[S.top()])
			S.pop();
		lf[i] = S.top();
		S.push(i);
	}
	while(!S.empty())
		S.pop();
	S.push(n+1);
	for (int i = n; i >= 1; --i)
	{
		while(A[i] < A[S.top()])
			S.pop();
		rt[i] = S.top();
		S.push(i);
	}
	long long int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		ans+=1ll*(rt[i] - i)*(i - lf[i])*A[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3456
N = int(input())
a = [int(x) for x in input().split()]
b = [0]*N
for i in range(N-1,-1,-1):
    if a[i] != sum([b[x] for x in range(i,N,i+1)]) % 2:
        b[i] = 1
print(b.count(1))
if b.count(1) != 0:
    print(" ".join([str(x+1) for x in range(N) if b[x]==1]))

Measured memory_bytes: 14772