akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var l = Console.ReadLine()
               .Split(' ')
               .Select(int.Parse)
               .ToArray();
            var n = l[0];
            var m = l[1];
            var a = Enumerable
                .Range(0, m)
                .Select(x => Console
                    .ReadLine()
                    .Split(' ')
                    .Select(int.Parse))
                .Select(x => x
                    .Skip(1)
                    .ToArray())
                .ToArray();
            var p = Console
                .ReadLine()
                .Split(' ')
                .Select(int.Parse)
                .ToArray();
            var swDict = new Dictionary<int, bool>();
            int count = 0;
            var max = (int)Pow(2, n);
            for (int i = 0; i < max; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    swDict[j + 1] = ((i >> j) & 0x1) == 1;
                }

                var allOn = true;
                for (int j = 0; j < m; j++)
                {
                    var swArray = a[j];
                    var mod = p[j];
                    var c = swArray.Count(x => swDict[x]) % 2;
                    allOn &= (c == mod);
                }
                if (allOn)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13652
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
using int64 = long long;

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

    vector<int> r, g, b;
    for (int i=0; i<n; i++) {
        if (s[i] == 'R') r.push_back(i);
        if (s[i] == 'G') g.push_back(i);
        if (s[i] == 'B') b.push_back(i);
    }

    int64 ans = r.size() * g.size() * b.size();
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());

    int64 cnt = 0;
    for (auto i : r) {
        for (auto j : g) {
            int rr = max(i, j) + abs(i - j);
            int ll = min(i, j) - abs(i - j);
            if (binary_search(b.begin(), b.end(), rr)) cnt++;
            if (binary_search(b.begin(), b.end(), ll)) cnt++;
            if ((i+j) % 2) continue;
            if (binary_search(b.begin(), b.end(), (i+j)/2)) cnt++;
        }
    }

    cout << ans - cnt << endl;
}


Measured memory_bytes: 3232
S = input()
op_cnt = len(S) - 1
ops = []
ans = 0
for i in range(2 ** op_cnt):
    op = [""] * op_cnt 
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"
    formula = ""
    for p_n, p_o in zip(S, op + [""]):
        formula += (p_n + p_o)
    ans += eval(formula)

print(ans)
  

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int a, b, c;
  cin >> a >> b >> c;

  if (a <= c && c <= b)
  {
      cout << "Yes" << endl;    
  }
  else
  {
      cout << "No" << endl;
  }
  return 0;
}




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

typedef long l;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1e9 + 7
#define INF 999999999
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  cin >> str;
  cout << str[0] << str.size() - 2 << str[str.size() - 1] << endl;

}



Measured memory_bytes: 256
/*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
	public static void main (String[] args) {
// 		System.out.println("GfG!");
        Scanner input=new Scanner(System.in);
       char[] array=new char[26];
       array[0]='z';
       for(int i=1;i<26;i++)
            array[i]=(char)(i+96);
        /*for(int i=0;i<26;i++)
            System.out.print(array[i] + " ");*/
        long n=input.nextLong();
        List<Integer> list=new ArrayList<Integer>();
        while(n>0)
        {
            long x=n%26;
            list.add((int)x);
            if(x==0)
                n=n-26;
            n=n/26;
        }
        // System.out.println(list);
        int size=list.size();
        for(int i=size-1;i>=0;i--)
        {
            int x=list.get(i);
            System.out.print(array[x]);
        }
       input.close();
	}
}

Measured memory_bytes: 35704
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int W=Integer.parseInt(sc.next());
int H=Integer.parseInt(sc.next());
int x=Integer.parseInt(sc.next());
int y=Integer.parseInt(sc.next());
int r=Integer.parseInt(sc.next());
if((r<=x&&x<=(W-r)&&(r<=y&&y<=H-r))){System.out.println("Yes");}else{System.out.println("No");}
}
}


Measured memory_bytes: 26152
#!/usr/bin/ruby
def lightsout(x,y)
  now=Time.now.to_f
  succ=0
  a=Array.new(x*y)
  a.length.times{|i| a[i]=Array.new(2)}

  #create problem
  x.times {|i|
    y.times {|j|
      a[i+j*x][0]=1<<(i+j*x)
      a[i+j*x][1]= 0 +
        (1<<(i+j*x)) +
        (i>0   ? 1<<(i-1+j*x) : 0) +
        (i<x-1 ? 1<<(i+1+j*x) : 0) +
        (j>0   ? 1<<(i+(j-1)*x) : 0) +
        (j<y-1 ? 1<<(i+(j+1)*x) : 0) +
=begin
        (i>0   && j>0   ? 1<<(i-1+(j-1)*x) : 0) +
        (i<x-1 && j>0   ? 1<<(i+1+(j-1)*x) : 0) +
        (i>0   && j<y-1 ? 1<<(i-1+(j+1)*x) : 0) +
        (i<x-1 && j<y-1 ? 1<<(i+1+(j+1)*x) : 0) +
=end
        0
    }
  }

  #solve
  (x*y).times {|i|
    if a[i][1]&1<<i==0
      (i+1).step(x*y-1) {|j|
        if a[j][1]&1<<i!=0
          a[i],a[j]=a[j],a[i]
          succ=1
          break
        end
      }
      if succ==0 then break end #in 6*5 succ is always 1
      succ=0
    end

    (x*y).times {|j|
      if i==j then next end
      if a[j][1]&1<<i!=0
        a[j][0]^=a[i][0]
        a[j][1]^=a[i][1]
      end
    }

    #$stderr.printf("%d/%d passes\r",i+1,x*y)
  }
  #$stderr.print "\n"

	gets.to_i.times{
		prob=[];ans=[0]*x*y
		y.times{prob+=gets.split.map(&:to_i)}
		(x*y).times{|i|if prob[i]>0 then (x*y).times{|j|ans[j]^=a[j][0][i]}end}
		y.times{|i|puts ans[i*x,x].map(&:to_s).join(' ')}
	}

=begin
  #output as C
  print <<"EOM"
#include <stdio.h>
int table[#{x*y}][#{x*y}] = {
EOM

  a.each {|b|
    print "  {"
    a.length.times {|c|
      print "#{b[0][c]},"
    }
    print "},\n"
  }

  print <<"EOM"
};
int prob[#{x*y}], ans[#{x*y}];

main(b,c,i,j){
  for(scanf("%d",&c);b<=c;b++){
    for(i=0;i<#{x*y};i++)
      scanf("%d",prob+i),ans[i]=0;
    for(i=0;i<#{x*y};i++)
      if(prob[i])
        for(j=0;j<#{x*y};j++)
          ans[j]^=table[i][j];
    for(j=0;j<#{y};printf("\\n"),j++)
      for(i=0;i<#{x};i++)
        printf(i<#{x-1}?"%d ":"%d",ans[i+j*#{x}]);
  }
  return 0;
}
EOM
$stderr.printf("%.3f ms\n",Time.now.to_f-now)
=end
end

lightsout(10,10)

Measured memory_bytes: 2632
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s1 = input()
s2 = input()
ans = 1
M = 10**9+7
if n==1:
    ans = 3
else:
    p = []
    prev = s1[0]
    count = 1
    for c in s1[1:]:
        if prev==c:
            count += 1
        else:
            p.append(count)
            count = 1
        prev = c
    p.append(count)
    if p[0]==1:
        ans = 3
    else:
        ans = 3*2
    prev = p[0]
    for num in p[1:]:
        if num==1:
            if prev==1:
                ans *= 2
            else:
                ans *= 1
        else:
            if prev==2:
                ans *= 3
            else:
                ans *= 2
        prev = num
        ans %= M
print(ans)

Measured memory_bytes: 62076
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
    return 0;
}

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

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);
        Unstoppable solver = new Unstoppable();
	//	int t=in.nextInt();
	//	while(t-->0)
        solver.solve(in, out);
        out.close();
    }
 
    static class Unstoppable {
        
     
        public void solve(InputReader in, PrintWriter out) {
         int a=in.nextInt();
         int b=in.nextInt();
         int c=in.nextInt();
         out.println(c+" "+a+" "+b);
        
        }
    } 

 
    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 long nextLong(){
            return Long.parseLong(next());
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }
}
 

Measured memory_bytes: 23380
n=int(input())
x=list(map(int,input().split()))
x.sort()
m=10000000000
for i in range(x[0],x[n-1]+1):
  ans=0
  for j in range(n):
    ans+=(i-x[j])**2
  m=min(m,ans)

print(m)

Measured memory_bytes: 9144
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int X=stdIn.nextInt();
		int Y=stdIn.nextInt();
		int ans=0;
		if(X<4)
			ans+=300000/X;
		if(X==2)
			ans+=50000;
		if(Y<4)
			ans+=300000/Y;
		if(Y==2)
			ans+=50000;
		if(X==1&&Y==1)
			ans+=400000;
		System.out.println(ans);
	}
}


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i] == b[i] && b[i] == c[i])continue;
		else if(a[i] == b[i] && b[i] != c[i])ans++;
		else if(a[i] == c[i] && a[i] != b[i])ans++;
		else if(b[i] == c[i] && a[i] != b[i])ans++;
		else ans +=2;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200010
#define int long long 
#define mod 1000000007
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
inline int qpow(int bas,int pw)
{
	int ret=1; for(;pw;pw>>=1,bas=1ll*bas*bas%mod)
		if(pw&1) ret=1ll*ret*bas%mod; return ret; 
}
int n,p[N],spe,fac[N],inv[N];
inline int C(int n,int m)
{
	if(n>m) return 0;
	int x=1ll*fac[m]*inv[n]%mod*inv[m-n]%mod;
	return x;
}
signed main()
{
	fac[0]=1; for(int i=1;i<=100010;i++) 
		fac[i]=1ll*fac[i-1]*i%mod;
	inv[100010]=qpow(fac[100010],mod-2);
	for(int i=100009;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
	n=read();
	for(int i=1;i<=n+1;i++)
	{
		int k=read();
		if(!p[k]) p[k]=i;
		else spe=n-i+p[k];
	}
	for(int i=1;i<=n+1;i++)
		printf("%d\n",((C(i,n+1)-C(i-1,spe))%mod+mod)%mod);
	return 0 ;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int X,Y,Z;
ll K;
ll A[1010],B[1010],C[1010];

bool solve(ll mid){
  ll sum=0;
  rep(i,X) rep(j,Y){
    int k=lower_bound(C,C+Z+1,mid-(A[i]+B[j]))-C;
    sum+=Z-k;
  }
  return (sum>=K);
}

void ans(ll l){
  vector<ll> res;
  rep(i,X) rep(j,Y){
    int tmp=upper_bound(C,C+Z+1,l-(A[i]+B[j]))-C;
    for(int k=tmp;k<Z;k++) res.push_back(A[i]+B[j]+C[k]);
  }
  int siz=res.size();
  for(int i=0;i+siz<K;i++) res.push_back(l);
  sort(res.rbegin(),res.rend());
  for(ll r:res) cout<<r<<endl;
}

int main(){
  cin>>X>>Y>>Z>>K;
  rep(i,X) cin>>A[i];
  rep(i,Y) cin>>B[i];
  rep(i,Z) cin>>C[i];
  sort(C,C+Z);
  C[Z]=1e15;
  ll l=0,r=1e11;
  while(r-l>1){
    ll mid=(l+r)/2;
    if(solve(mid)) l=mid;
    else r=mid;
  }
  ans(l);
  return 0;
}

Measured memory_bytes: 384
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
S = 0
for i in range(N-1):
  for j in range(i+1, N):
    S += ((X[i][0]-X[j][0])**2+(X[i][1]-X[j][1])**2)**.5
print(S/(N/2))

Measured memory_bytes: 9424
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string x; cin >> x;
	stack<char> s;
	for (char a : x)
	{
		if (a == 'S')s.push('S');
		else if (!s.empty() && s.top() == 'S')s.pop();
		else s.push('T');
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 644
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    long M, Rd, Rr, Cd, Cr;
    scanf("%lld %lld %lld %lld %lld\n", &M, &Rd, &Rr, &Cd, &Cr);
    long x = (100 * Cd + (Rd - 1)) / Rd;
    long y = (100 * Cr + (Rr - 1)) / Rr;
    long Ans = M - (x + y);
    if (Ans < 0) Ans = -1;
    writeln(Ans);
}

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

const int MAX_N = 110000;

int memo[MAX_N]; // memo[i] が i についての答え
int rec(int n) {
    if (n == 0) return 0; // 終端条件
    if (memo[n] != -1) return memo[n]; // すでに探索済みならリターン

    int res = n; // INF の気持ち

    // 1, 6, 6^2, ..., を試す (n を超えない範囲で)
    for (int pow6 = 6; pow6 <= n; pow6 *= 6) res = min(res, rec(n - pow6) + 1);

    // 1, 9, 9^2, ..., を試す (n を超えない範囲で)
    for (int pow9 = 9; pow9 <= n; pow9 *= 9) res = min(res, rec(n - pow9) + 1);

    // メモしながらリターン
    return memo[n] = res;
}

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

    // テーブルを -1 で初期化
    for (int i = 0; i < MAX_N; ++i) memo[i] = -1;
    cout << rec(N) << endl;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(void){
  int n, m, x[100000] = {0}, sum = 0;
  scanf("%d %d", &n, &m);getchar();
  if(n >= m){
    printf("0\n");
    return 0;
  }
  for(int i = 0; i < m; i++){
    scanf("%d", &x[i]);getchar();
  }
  qsort(x, m, sizeof(int), compare_int);
  for(int i = 0; i < m - 1; i++){
    x[i] = x[i + 1] - x[i];
  }
  qsort(x, m - 1, sizeof(int), compare_int);
  for(int i = 0; i < m - n; i++){
    sum += x[i];
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,c;
    cin >> n;
    for(int i=n;i>0;i=i/10)
    {
      if(i%10==7)
      {
        cout << "Yes" << endl;
        c=1;
        break;
      }
      else
        c=0;
    }
    if(c==0)
      cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<vector>
#include <map>
#include<cstring>
#include<algorithm>
#include<list>

using namespace std;

short node[10001];
short state_before[10001];
short map_before[10001];


map<int,list<pair<int,int>>> points;



void read_points(int tate){
    memcpy(map_before,node,sizeof node);
    memset(node,0,sizeof(node));    
    for(auto tmp:points[tate]){
        node[tmp.first]+=tmp.second;
    }
}
int main(){
    int n,r;
    int S=0;
    int L=0;
    int deltaS=0,deltaL=0;
    ios::sync_with_stdio(false);
  
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        
        points.clear();
        int x1,y1,x2,y2;
        int max_x=0,min_x=10000,max_y=0,min_y=10000;
        for(int i=0;i<n;i++){
            cin>>x1>>y1>>x2>>y2;
 
            if(points.find(y1)==points.end()){
                list<pair<int,int> > tmp;
                points[y1]=tmp;
            }
            if(points.find(y2)==points.end()){
                list<pair<int,int> > tmp;
                points[y2]=tmp;
            }
            points[y1].push_back(make_pair(x1,1));
            points[y1].push_back(make_pair(x2,-1));
            points[y2].push_back(make_pair(x1,-1));
            points[y2].push_back(make_pair(x2,1));
            if(max_x<x2)max_x=x2;
            if(max_y<y2)max_y=y2;
            if(min_x>x1)min_x=x1;
            if(min_y>y1)min_y=y1;
            
        }
        
        
        S=0;
        L=0;

        for(int h=min_y;h<=max_y;h++){
            if(points.find(h)==points.end()){
                S+=deltaS;
                L+=deltaL;
                continue;
            }
            deltaL=0,deltaS=0;
            read_points(h);
            int yoko_state=0;
            for(int w=min_x;w<=max_x;w++){
                yoko_state+=node[w];
                node[w]=yoko_state;
                if(h!=0){
                    node[w]+=state_before[w];
                }
                state_before[w]=node[w];
                //std::cout << node[w] ;
                if(node[w]>0){
                   S++;
                   deltaS++;
                   if(w==0){L+=2;deltaL+=2;}
                   else if(node[w-1]==0){L+=2;deltaL+=2;}
                   if(h==0){L+=2;}
                   else if(map_before[w]==0){L+=2;}
                }
                
                
            }
            //cout<<endl;
            
        }


        cout<<S<<endl;
        if(r==2){
            cout<<L<<endl;
        }
        
        

    }

    

}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;

int main(){
    int n;
    std::cin >> n;
    std::vector<ll> a(n),b(n);
    rep(i,n)std::cin >> a[i]>>b[i];
    ll d=0;
    irep(i,n){
        a[i]+=d;
        if(a[i]%b[i]==0)continue;
        else d+=b[i]-(a[i]%b[i]);
    }
    std::cout << d << std::endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	
	cin >> a >> b;
	
	if ((a + b) % 2 == 0) {
		cout << (a + b) / 2 << endl;
	}
	else {
		cout << (a + b) / 2 + 1 << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
X, Y = map(int, input().split())

ans = 0
money = [100000,200000,300000]
if X==1 and Y==1:
    ans += 400000

if X==1: ans += money[2]
elif X==2: ans += money[1]
elif X==3: ans += money[0]

if Y==1: ans += money[2]
elif Y==2: ans += money[1]
elif Y==3: ans += money[0]

print(ans)


Measured memory_bytes: 38384
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
lis=[]
for i in range(h):
    lis+=list(SI())
c=Counter(lis)
count1,count2=0,0
if h%2==0 and w%2==0:
    for x in c.keys():
        if c[x]%4!=0:
            print("No")
            sys.exit()
    print("Yes")
    
if h%2==0 and w%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    if count2>h//2 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==0 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count2>w//2 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==1 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count1>1 or count2>h//2+w//2:
        print("No")
    else:
        print("Yes")
        
    

    
        
    
    
    

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

template <class T>
struct SegTree {
    using F = function<T(T, T)>; // operator type
    const int n; // array size
    const T id; // identity element
    F op; //operator
    vector<T> dat; // data array
    SegTree(int n, T id, F op) :n(n), id(id), op(op), dat(n * 2, id) {}
    T operator[](int i) { return dat[i + n]; }
    void modify(int i, const T& v) { // set v at position i
        dat[i += n] = v;
        while(i >>= 1) dat[i] = op(dat[i * 2], dat[i * 2 + 1]);
    }
    T query(int l, int r) { // query on interval [l, r)
        T a{ id }, b{ id };
        for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) a = op(a, dat[l++]);
            if(r & 1) b = op(dat[r - 1], b);
        }
        return op(a, b);
    }
};

constexpr int N_MAX{ 200002 };

SegTree<int> st(N_MAX, numeric_limits<int>::max(), [](int a, int b) { return min(a, b); });
int N, Q, b[N_MAX], c[N_MAX], ans;
set<int> q[N_MAX];
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> N;
    for(int i{ 1 }; i <= N; ++i) {
        cin >> b[i];
        c[i] = c[i - 1] + !b[i];
    }
    cin >> Q;
    for(int i{}; i < Q; ++i) {
        int l, r; cin >> l >> r;
        q[l].insert(r);
    }
    for(int i{ 1 }; i <= N; ++i) {
        for(auto& x : q[i])
            st.modify(x, min(st.query(i, x + 1), ans + c[N] - c[i - 1]));
        ans = min(ans + b[i], st[i] - c[N] + c[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 22144
using System;
     
    class Problem
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            decimal m;
            string u;
            decimal money=0;
            for (int i=0; i<N; i++)
            {
                string[] a = Console.ReadLine().Split(' ');
                m = decimal.Parse(a[0]);
                if (a[1] == "BTC")
                {
                    money += 380000 * m;
                }
                else
                {
                    money += m;
                }
            }
            Console.WriteLine(money);
        }
    }

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    dcout << sqrt((a * a + b * b) - 2 * a * b * cos(abs(min(h * 30 + m * 0.5 - m * 6, 360 - (h * 30 + m * 0.5 - m * 6))) * 3.14159265358979 / 180));

    // cout << cos(abs(min(h * 15 - m * 3, 180 - (h * 15 - m * 3))));
    // dcout << sqrt(a * a + b * b - 2 * a * b * cos(abs(min(h * 15 - m * 3, 180 - (h * 15 - m * 3)))));
    return 0;
}

Measured memory_bytes: 4192
#include <stdio.h>

int g[2][200005];

int main()
{
	int n, m;
	int a, b;
	int f = 0;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a, &b);
		
		if (a == 1) {
			g[0][b] = 1;
		} else if (b == n) {
			g[1][a]= 1;
		}
	}

	for (int i = 1; i <= n; i++) {
		if (g[0][i] == 1 && g[1][i] == 1) {
			f = 1;
		}
	}

	if (f) {
		puts("POSSIBLE");
	} else {
		puts("IMPOSSIBLE");
	}

	return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (3006)
ll n, m, mod=1e9+7, memo[MAXN][MAXN], sum[MAXN], f[MAXN], inv[MAXN];
string S;
vector<pi> ranges;
int main()
{
	FAST
	cin>>m>>n>>S; S='*'+S; FOR(i,1,m) sum[i]=sum[i-1]+S[i]-'0';
	FOR(i,0,n-1) {
		ll a, b; cin>>a>>b; ranges.eb(a, b);
	}
	sort(all(ranges), [](pi x,pi y){return (x.f!=y.f?x.f<y.f:x.s>y.s); });
	vector<pi>final;
	ll mx=0;
	FOR(i,0,n-1) {
		if(mx >= ranges[i].s) {
			continue;
		}
		mx=ranges[i].s;
		final.eb(ranges[i]);
	}
	swap(ranges,final), n=siz(ranges);
	mmst(memo,-1);
	f[0]=1; FOR(i,1,MAXN-1) f[i]=f[i-1]*i%mod;
	function<ll(ll,ll)>qexp=[&](ll x,ll e){
		if(e==0)return 1ll;
		ll half=qexp(x,e>>1); half*=half, half%=mod;
		if(e&1) half*=x,half%=mod;
		return half;
	};
	FOR(i,0,MAXN-1) inv[i]=qexp(f[i],mod-2);
	auto C=[&](ll n,ll k) {
		if(n<k) return 0ll;
		return f[n] * inv[k] % mod * inv[n-k] % mod;
	};
	auto ones=[&](ll x,ll y) {
		return sum[y]-sum[x-1];
	};
	auto zeros=[&](ll x,ll y) {
		return (y-x+1) - ones(x,y);
	};
	function<ll(ll,ll)>dp=[&](ll x,ll y) {
		if(~memo[x][y]) return memo[x][y];
		ll &ans=memo[x][y]=0;
		ll one=ones(ranges[x].f,ranges[x].s), zero=zeros(ranges[x].f,ranges[x].s);
		if(x && ranges[x-1].s >= ranges[x].f) {
			ll inter = ranges[x-1].s - ranges[x].f + 1;
			one -= ones(ranges[x].f, ranges[x].f+inter-1);
			zero -= zeros(ranges[x].f, ranges[x].f+inter-1);
			one += y;
			zero += inter-y;
		}
		if(x == n-1 || ranges[x+1].f > ranges[x].s) { // independent case
			ans = C(ranges[x].s-ranges[x].f+1, one);
		} else {
			ll inter = ranges[x].s - ranges[x+1].f + 1;
			FOR(i,0,min(one,inter)) {
				if(inter-i > zero) continue;
				one -= i;
				ans += C(ranges[x].s-ranges[x].f+1-inter,one) * dp(x+1, i) % mod, ans%=mod; 
				one += i;
			}
		}
		// cerr<<x<<" "<<y<<" "<<ans<<' '<<one<<' '<<zero<<'\n';
		return ans;
	};
	ll ans=1;
	FOR(i,0,n-1) {
		if(i == 0 || ranges[i-1].s < ranges[i].f) {
			ans*=dp(i, 0),ans%=mod;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 71168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <algorithm>
#define CHAR_NUM 201
using namespace std;

int main(void) {
    char str[20];
    int i;
    
    scanf("%s", str);
    
    int len = (int)strlen(str);
    
    for(i = len - 1; i >= 0; i--)
        printf("%c", str[i]);
    putchar('\n');
    
    return(0);
}

Measured memory_bytes: 1104
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#define ll long long
//for (auto &x : a) { cin >> x; }
using namespace std;

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

    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        cout << "ACL";
    }
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    
    #とりあえず重複ありで，個数を数える
    cnt=[0]*(K+1)
    
    for i in range(1,K+1):
        aa=K//i
        cnt[i]=pow(aa,N,mod)
        
    for i in range(K,0,-1):
        pn=-1
        for j in range(2*i,K+1,i):
            #print(i,j,cnt)
            cnt[i]+=cnt[j]*pn
            
    #print(cnt)
    ans=0
    for i in range(1,K+1):
        ans+=(i*cnt[i])%mod
        ans%=mod
        
    print(ans)
    

main()


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

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

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

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

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

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

vector<ll>relation[20], money(20, 1);

int main() {
	string s;
	int k;
	cin >> s >> k;
	int n = s.length();
	map<string, int>mp;
	for (int i = 1;i <= 5;++i) {
		for (int j = 0;j < n;++j) {
			string target = s.substr(j, i);
			mp[target]++;
		}
	}
	int l = 0;
	for (auto p : mp) {
		l++;
		string x = p.first;
		if (l == k) {
			cout << x << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define forn(i,n) for(int i = 0; i < n; i++)
#define forr(i,a,n) for(int i = a; i<= n; i++)
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(u) u.begin(),u.end()
#define lli long long int
#define ld long double

using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vi> vvi;

int main(){__
	int n;
	cin >> n;
	cout << (n >= 30? "Yes\n" : "No\n");
	return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr int max_n = 100005;

int N,M;
vector<int> g[max_n];
bool used[max_n];

int main(){
    cin >> N >> M;
    rep(i,M){
        int a,b; cin >> a >> b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }


    int l = 0 , r = g[0][0];
    used[l] = used[r] = true;

    deque<int> deq;
    deq.push_back(l);
    deq.push_back(r);

    // rから伸ばす
    while(1){
        bool ok = false;
        for(auto nxt : g[r]) if(!used[nxt]){
            ok = true;
            r = nxt;
            break;
        }
        if(!ok) break;
        used[r] = true;
        deq.push_back(r);
    }

    // lから伸ばす
    while(1){
        bool ok = false;
        for(auto nxt : g[l]) if(!used[nxt]){
            ok = true;
            l = nxt;
            break;
        }
        if(!ok) break;
        used[l] = true;
        deq.push_front(l);
    }


    cout << deq.size() << endl;
    for(auto v : deq) cout << (v+1) << endl;
}


Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    long long N,M;
    cin >> N >> M;
    
    if ( N == 1 && M == 1 ){
        cout << 1 << endl;
    }
    else if ( N == 1 || M == 1 ) {
        cout << N*M-2 << endl;
    }
    else {
        cout << (N-2)*(M-2) << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

int num[3] = {0};
int j, k, temp = 0;

scanf ("%d %d %d", &num[0], &num[1], &num[2]);

for (j=0; j<3; j++) {
    for (k=j; k<3; k++) {
        if (num[j] > num[k]) {
            temp = num[k];
            num[k] = num[j];
            num[j] = temp;
         }
     }
}

printf ("%d %d %d\n", num[0], num[1], num[2]);

return 0;

}


Measured memory_bytes: 2056
require 'set'

N, K = gets.split(' ').map(&:to_i)
td_list = N.times.map { gets.split(' ').map(&:to_i) }

sorted_td_list = td_list.sort_by { |(_, d)| -d }
current_td_list = sorted_td_list.take(K)
t_to_size = Hash.new(0).tap do |h|
  current_td_list.each { |k, _| h[k] += 1 }
end
t_set = Set.new(t_to_size.keys)
d_sum = current_td_list.reduce(0) do |acc, (_, d)|
  acc + d
end
max_score = d_sum + t_set.size ** 2

removed_i = K - 1
rest_sorted_td_list = sorted_td_list.drop(K)
rest_sorted_td_list.each.with_index do |(t, d), i|
  break if t_set.size >= K
  next if t_set.include?(t)
  while removed_i >= 0
    break if t_to_size[sorted_td_list[removed_i][0]] >= 2
    removed_i -= 1
  end
  break if removed_i < 0
  dt, dd = sorted_td_list[removed_i]
  removed_i -= 1
  t_set.add(t)
  t_to_size[dt] -= 1
  t_to_size[t] = 1
  d_sum += d - dd
  current_score = d_sum + t_set.size ** 2
  max_score = current_score if max_score < current_score
end
puts max_score


Measured memory_bytes: 20140
#include<bits/stdc++.h>
using namespace std;
#define maxn 55
#define mod 1000000007
typedef long long LL;
struct matrix
{
	int sz;
	int m[maxn][maxn];
	matrix(){}
	matrix(int n) : sz(n) { memset(m,0,sizeof(m)); }
	void operator = (const matrix &A)
	{
		for(int i=0; i<sz; i++)
			for(int j=0; j<sz; j++)
				m[i][j] = A.m[i][j];
	}
	matrix operator*(const matrix& A)
	{
		matrix B(sz);
		for(int i=0; i<sz; i++)
			for(int j=0; j<sz; j++)
			{
				B.m[i][j] = 0;
				for(int k=0; k<sz; k++)
					B.m[i][j] = (B.m[i][j] + (LL)m[i][k] * A.m[k][j] % mod) % mod;
			}
		return B;
	}
};
matrix pow(matrix A, LL k)
{
	matrix ans(A.sz);
	for(int i=0; i<A.sz; i++)
		ans.m[i][i] = 1;
	while(k)
	{
		if(k&1)
			ans = ans * A;
		k >>= 1;
		A = A*A;
	}
	return ans;
}
int main()
{
	int n;
	LL k;
	scanf("%d%lld", &n, &k);
	matrix A(n);
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			scanf("%d",&A.m[i][j]);
	matrix ans = pow(A, k);
	int cnt = 0;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cnt = (cnt + ans.m[i][j]) % mod;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*
 
 5/5/2020
 
 10:48-
 
 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N,T;

void solve() {
  
  map<int,int> gaps1;
  int mina=A[0];
  REP(i,N) {
    int a=A[i];
    if(a-mina>0) gaps1[a-mina]++;
    if(a<mina) mina=a;
  }
  int maxa=A[N-1];
  map<int,int> gaps2;
  for(int i=N-1; i>=0; --i) {
    int a=A[i];
    if(maxa-a>0) gaps2[maxa-a]++;
    if(a>maxa) maxa=a;
  }
  if(SZ(gaps1)==0) {
    cout<<0<<endl;
    return;
  }
  assert(gaps1.rbegin()->first==gaps2.rbegin()->first);
  cout<<min(gaps1.rbegin()->second,gaps2.rbegin()->second)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>T;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 9984
d = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(d):
    s.append([int(j) for j in input().split()])
t = []
for i in range(d):
    t.append(int(input())-1)

last = [-1] * 26
satis = 0
for i in range(d):
    satis += s[i][t[i]]
    last[t[i]] = i;
    for j in range(26):
        satis -= c[j] * (i - last[j])
    print(satis)



Measured memory_bytes: 68424
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	// cin.ignore(); must be there when using getline(cin, s)
	int d, t, s;
	cin >> d >> t >> s;

	string ans = "Yes";
	if (d > t * s) {
		ans = "No";
	}

	cout << ans << '\n';

	return 0;
}


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

using namespace std;

int main() {
	char A[10];
	char B[10];
	cin >> A >> B;
	

	if (A[0] == B[2] && A[1] == B[1] && A[2] == B[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n="0"+input()
k=int(input())
dp=[[[0]*(k+1) for i in range(len(n))] for _ in range(2)]
dp[0][0][0]=1
dp[1][1][0]=1
for i in range(1,len(n)):
    x=int(n[i])
    dp[1][i][0]+=dp[1][i-1][0]
    for j in range(1,k+1):
        if x==0:
            dp[0][i][j]+=dp[0][i-1][j]
            dp[1][i][j]+=dp[1][i-1][j]+dp[1][i-1][j-1]*9
        else:
            dp[0][i][j]+=dp[0][i-1][j-1]
            dp[1][i][j]+=dp[1][i-1][j]+dp[1][i-1][j-1]*9+dp[0][i-1][j-1]*(x-1)+dp[0][i-1][j]
print(dp[1][-1][-1]+dp[0][-1][-1])

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

int N;

void dfs(string s, char end){
  if(s.size()==N){
    cout<<s<<endl;
    return ;
  }
  for(char c='a';c<=end;c++){
    if(c!=end) dfs(s+c, end);
    else dfs(s+c, char(end+1));
  }
}

int main() {
cin>>N;

dfs("", 'a');
}


Measured memory_bytes: 1536
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

let left i = 2*i + 1

let right i = 2*i + 2

let to_pow_of_2 n =
  let rec doit i =
    if i >= n then i
    else doit (i * 2) in
  doit 1

let solve n q =
  let n = to_pow_of_2 n in
  let s = Array.make (2*n-1) 2147483647 in
  let update i x =
    let j = n + i - 1 in
    s.(j) <- x;
    let rec doit j =
      if j > 0 then begin
        let j = parent j in
        s.(j) <- min s.(left j) s.(right j);
        doit j
      end in
    doit j in
  let rec find a b k l r =
    if r <= a || b <= l then 2147483647
    else if a <= l && r <= b then s.(k)
    else min (find a b (left k) l ((l + r) / 2)) (find a b (right k) ((l + r) / 2) r) in
  let find a b = find a b 0 0 n in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> update x y
      | 1 :: x :: y :: _ -> Printf.printf "%d\n" (find x (y + 1))
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 6468
package main

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

var (
	sc = bufio.NewReader(os.Stdin)
	ts = []string{"dream", "dreamer", "erase", "eraser"}
	s  = ""
)

func main() {
	s = readLine()
	if rec(0) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func rec(i int) bool {
	if i == len(s) {
		return true
	}
	for _, t := range ts {
		if len(s[i:]) >= len(t) && s[i:i+len(t)] == t {
			if rec(i + len(t)) {
				return true
			}
		}
	}
	return false
}

func scan(a ...interface{}) {
	_, err := fmt.Fscan(sc, a...)
	pnc(err)
}

func readLine() (s string) { scan(&s); return }

func pnc(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 5904
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if(N%2==1){
        cout << 0 << endl;
        return 0;
    }
    N /= 2;
    ll five = 5;
    ll ans = 0;
    while(five<=N){
        ans += N/five;
        five *= 5;
    }   
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> v(N);
  int max = -1;
  for(int i=0; i<N ;i++)
  { cin >> v.at(i);
    for(int j = i-1 ; j >= 0; j--)
       max = ( max > abs(v.at(j)-v.at(i)) )? max : abs(v.at(i)-v.at(j));
  }   
  cout<<max;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
print(n-k+1)
a=1
t=1
r=n-k+1
b=1
for i in range (2,k+1):
  a=a*(k-i+1)
  t=t*(i-1)
  r=r*(n-k-i+2)
  b=b*i
  o=(a*r)//(b*t)
  print(o%1000000007)

Measured memory_bytes: 3316