akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int a[200010]={};
  int ans[200010]={};
  
  for(int i=2;i<=N;i++)scanf("%d",&a[i]);
  for(int i=2;i<=N;i++)ans[a[i]]++;
  for(int i=1;i<=N;i++)printf("%d\n",ans[i]);

  return 0;
}


Measured memory_bytes: 3272
N, X, T = map(int, input().split())
count = 1
check = X
if X > 1:
    while True:
        value = int(N / X)
        re = N % X
        if re == 0:
            count = value
            TotalTime = T * count
            break
        else:
            count += value
            TotalTime = T * count
            break
else:
    TotalTime = T * N

print(TotalTime)

Measured memory_bytes: 9124
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int>monster(N+1);
  vector<int>hero(N);
  for(int i=0;i<=N;i++){
  
    cin>>monster[i];
  }
  for(int i=0;i<=N-1;i++){
  
    cin>>hero[i];
  }
  long long ans=0;
  for(int i=0;i<=N-1;i++){
  
    if(hero[i]>=monster[i]){
    
      ans+=monster[i];
      hero[i]-=monster[i];
      monster[i]=0;
      if(hero[i]>=monster[i+1]){
      
        ans+=monster[i+1];
        hero[i]-=monster[i+1];
        monster[i+1]=0;
      }
      else{
      
        monster[i+1]-=hero[i];
        ans+=hero[i];
        hero[i]=0;
      }
    }
    else{
    
      ans+=hero[i];
      monster[i]-=hero[i];
      hero[i]=0;
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 4004
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int y,m,d;
  char c1,c2;
  cin >> y >> c1 >> m >> c2 >> d;
  if(m <= 4){
    cout << "Heisei";
  }else{
    cout << "TBD";
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		if(S.equals("SUN")) {
			System.out.println("7");
		}else if(S.equals("MON")) {
			System.out.println("6");
		}else if(S.equals("TUE")) {
			System.out.println("5");
		}else if(S.equals("WED")) {
			System.out.println("4");
		}else if(S.equals("THU")) {
			System.out.println("3");
		}else if(S.equals("FRI")) {
			System.out.println("2");
		}else if(S.equals("SAT")) {
			System.out.println("1");
		}
		sc.close();
	}

}


Measured memory_bytes: 21844
import sys
n,m,x,y=map(int,input().split())
listx=list(map(int,input().split()))
listy=list(map(int,input().split()))
listx.sort(reverse=True)
listy.sort()
for i in range(x+1,y+1):
    if listx[0]<i<=listy[0]:
        print('No War')
        sys.exit()
print('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  stack<char> st;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'S') st.push(s[i]);
    else if (s[i] == 'T' && (st.empty() || st.top() == 'T')) st.push(s[i]);
    else if (s[i] == 'T' && st.top() == 'S') st.pop();
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 644
n, l = map(int, input().split())
a = list(map(int, input().split()))

pos = -1

for i in range(n-1):
    if a[i] + a[i+1] >= l:
        pos = i
        break
if pos == -1:
    print('Impossible')
    exit()

print('Possible')
for i in range(pos):
    print(i+1)

for i in reversed(range(pos+1,n-1)):
    print(i+1)

print(pos+1)



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

using namespace std;

int main(void) {
    long d, g;
    cin >> d >> g;
    g /= 100;

    vector<long> p(d), c(d);
    for(long i=0; i<d; i++)
        cin >> p[i] >> c[i], c[i] /= 100;

    long r = 1e9;
    for(long i=0; i<1l<<d; i++) {
        long s = 0, t = 0;
        for(long j=0; j<d; j++) {
            if((i>>j)&1) {
                s += (j+1) * p[j] + c[j];
                t += p[j];
            }
        }
        for(long j=d-1; g>s && j>=0; j--) {
            if((i>>j)&1) {
                continue;
            }
            long pp = min((g - s + (j+1 -1)) / (j+1), p[j]);
            s += (j+1) * pp;
            t += pp;
        }
        if(g <= s)
            r = min(r, t);
    }
    cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    ll N;
    cin >> N;
    ll ans = 2000000000000;
    for (ll i = 1; i * i <= N; i++)
    {
        if (N % i == 0) // i * j = N
        {
            ll j = N / i;
            ans = min(ans, i + j - 2);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
   long long int A, B, C, D;
   scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
   long long int N;
   scanf("%lld", &N);
   long long int num1 = 4 * A;
   long long int num2 = 2 * B;
   long long int mini3 = min(min(num1, num2), C);
   long long int ans;

   if(N % 2 == 0){
    if(mini3*2 <= D){
        ans = N * mini3;
    }
    else ans = (N/2) * D;
    printf("%lld\n", ans);
    return 0;
   }

   if(N % 2 == 1){
    if(mini3*2 <= D){
        ans = N * mini3;
    }
    else ans = ((N / 2) * D) + mini3;
    printf("%lld\n", ans);
    return 0;
   }

return 0;
}


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

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  string s;
  cin >> s;
  vector<bool> op(3,false);

  for(int i = 0; i < 2<<(3); i++){
    int x = i;
    int cnt = 0;
    while(x != 0){
      if(x % 2 == 1) op[cnt] = true;
      else op[cnt] = false;
      x /= 2;
      cnt++;
    }
    int ans = s[0] - '0';
    for(int j = 0; j < 3; j++){
      if(op[j]) ans += s[j+1] - '0';
      else      ans -= s[j+1] - '0';
    }
    if(ans == 7){
      cout << s[0];
      for(int j = 0; j < 3; j++){
        if(op[j]) cout << '+';
        else      cout << '-';
        cout << s[j+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N, D;
    cin >> N >> D;
    cout << (N + 2 * D + 1 - 1) / (2 * D + 1) << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
string i2s(int a){
	string s="";
	while (a!=0){
		s+=char(a%10+'0');
		a/=10;
	}
	return s;
}
int main()
{
	int a,b,ans=0;
	cin>>a>>b;
	for (;a<=b;a++){
		string s=i2s(a);
		int f=0;
		for (int i=0;i<s.size()/2;i++) if (s[i]!=s[s.size()-i-1]) f=1;
		if (f==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;



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

int H,W;
cin >> H >> W;

vector<string> fi(H);
rep(h,H) cin >> fi[h];


int dp[105][105];
rep(h,H) rep(w,W) dp[h][w] = INF;
if(fi[0][0] == '#') dp[0][0] = 1;
else dp[0][0] = 0;

rep(h,H) rep(w,W) {
    
    if(fi[h][w] == '.') {
        if(h < H-1 && fi[h+1][w] == '#') chmin(dp[h+1][w], dp[h][w] + 1);
        else chmin(dp[h+1][w], dp[h][w]);
        if(w < W-1 && fi[h][w+1] == '#') chmin(dp[h][w+1], dp[h][w] + 1);
        else chmin(dp[h][w+1], dp[h][w]);
    }
    else {
        chmin(dp[h+1][w], dp[h][w]);
        chmin(dp[h][w+1], dp[h][w]);
    }
}
cout << dp[H-1][W-1] << endl;
return 0;
}

Measured memory_bytes: 384
h, w, a, b = [int(i) for i in input().split()]

mod = 10 ** 9 + 7
kkai = [1]
for i in range(1, 210000):
    kkai.append(kkai[-1] * i % mod)


def kai(x, p=mod):
    return kkai[x]


def comb(a, b, p=mod):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a, p)
    c *= pow(kai(b, p), p - 2, p)
    c *= pow(kai(a - b, p), p - 2, p)
    return c % p


ans = 0
for i in range(b, w):
    ans += comb(i+(h-a)-1, i)*comb((w-i)+a-2, a-1)
    ans %= mod
print(ans)


Measured memory_bytes: 52464
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {

			while (true) {
				int n = sc.nextInt();
				int x = sc.nextInt();
				int cnt = 0;

				if (n == 0 && x == 0) {break;}

				for (int i = 1; i <= n; i++) {
					for (int j = 1; j <= n; j++) {
						if (i >= j) {continue;}
						for (int k = 1; k <= n; k++) {
							if (i >= k || j >= k) {continue;}
							if (i + j + k == x) {
								cnt++;
							}
						}
					}
				}
				System.out.println(cnt);
			}
		}
	}
}


Measured memory_bytes: 26700
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    int e,f,g,h;
    cin >> a >> b >> c >> d;
    cin >> e >> f >> g >> h;
    int x = a+b+c+d;
    int y = e+f+g+h;
    if(x>y){
        cout << x << endl;
    }
    else{
        cout << y << endl;
    }
}


Measured memory_bytes: 3080
n, m = gets.split.map(&:to_i)
a = []
b = []
n.times do
  a.push gets.chomp
end
m.times do
  b.push gets.chomp
end
0.upto(n-m) do |i|
  0.upto(n-m) do |j|
    matched = true
    0.upto(m-1) do |k|
      matched &&= a[i+k][j..m+j-1] == b[k]
    end
    if matched
      puts 'Yes'
      exit
    end
  end
end
puts 'No'


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<P,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++)cin>>A[i];
    ll sum=0;
    ll now=0;
    for(ll i=0;i<N;i++){
        sum+=abs(now-A[i]);
        now=A[i];
    }
    sum+=abs(now);
    print(sum-abs(A[0])-abs(A[0]-A[1])+abs(A[1]))
    for(ll i=1;i<N-1;i++){
        print(sum-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
    }
    print(sum-abs(A[N-1])-abs(A[N-2]-A[N-1])+abs(A[N-2]))

    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include <cmath>
#include<string.h>
#include <stdio.h>
#include <unordered_map>
#include <queue>
#include<climits>
#include <iomanip>
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include <cmath>
#include<string.h>
#include <stdio.h>
#include <unordered_map>
#include <queue>
#include<climits>
#include <iomanip>
#include <unordered_set>




using namespace std;
#define ll long long
#define clr(x) memset(x, 0, sizeof(x))
#define tcase ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define GCJ ll t;cin>>t;for(ll H=1;H<=t;H++){cout<<"CASE #"<<H<<": ";solve();}
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define endl "\n"
//comment out the above line when coding probs which require flushing the output
#define prarr(a,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define remDup(v) sort(all(v));v.resize(unique(all(v))-v.begin());
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define vvi vector<vector<ll>>
#define rep(i,n) for(ll i=0;i<n;i++)
#define crep(i,x,n) for(ll i=x;i<n;i++)
#define revrep(n,i) for(ll i=n-1;i>=0;i--)
#define crevrep(n,x,i) for(ll i=n-1;i>=x;i--)
#define ss second
#define ff first
#define incr(x,y) x=max(x, y)
#define decr(x,y) x=min(x, y)
#define pb push_back


/*
 void USACO(string s) {
 fast;
 
 freopen((s+".in").c_str(),"r",stdin);
 freopen((s+".out").c_str(),"w",stdout);
 }
 */


const ll mod = 1000000007;
ll n,k;
ll dp[101][100010];
ll pre[101][100010]={{0}};
ll a[101]={0};




void solve()
{
    memset(dp, 0, sizeof(dp));
    cin>>n>>k;
    crep(i,1,n+1)
    {
        cin>>a[i];
    }
    
    crep(i,1,n+1)
    {
        dp[i][0]=1;
        pre[i][0]=1;
        
    }
    
    rep(i,k+1)
    {
        dp[1][i]=(i<=a[1]);
        pre[1][i]=dp[1][i];
    }
    
    crep(i,1,n+1)
    {
        crep(j,1, k+1)
        {
            pre[i][j]=pre[i][j-1]+dp[i][j];
        }
        
    }

    
    for(ll i=2;i<=n;i++)
    {
        for(ll j=1;j<=k;j++)
        {

            ll l=min(a[i], j);
            
            //dp[i][j]=(((pre[i-1][j]%mod)-(pre[i-1][j-l]%mod)%mod)+dp[i-1][j-l]%mod)%mod;
            dp[i][j]=(((pre[i-1][j]+mod-pre[i-1][j-l])%mod)+(dp[i-1][j-l]%mod))%mod;
            
            pre[i][j]=((pre[i][j-1]%mod)+(dp[i][j]%mod))%mod;
        }
    }
    
    
    cout<<dp[n][k]%mod<<endl;

}


int main()
{
    //tcase
    //{
    solve();
    //}
}




















Measured memory_bytes: 160568
#include<cstdio>
int a[200000];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=n-1;i>=0;i-=2)printf("%d ",a[i]);
    for(int i=n%2;i<n;i+=2)printf("%d ",a[i]);
    return 0;
}

Measured memory_bytes: 2816
main(){float f;for(;~scanf("%f",&f);)puts(f>91?"heavy":f>81?"light heavy":f>75?"middle":f>69?"light middle":f>64?"welter":f>60?"light welter":f>57?"light":f>54?"feather":f>51?"bantam":f>48?"fly":"light fly");exit(0);}

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



int main() {
  int ans=1;
  rep(i, 5) {
    int n;
    cin >> n;
    if(n==0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
  
  return 0;
}

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

class MainClass
{
    static void Main()
    {
        var NY = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = NY[0], Y = NY[1];

        
        for(int i = 0; i <= N; i++)
        {
            for(int j = 0; j <= N - i; j++)
            {
                int k = (N - i - j);
                int m = 10000 * i + 5000 * j + k * 1000;
                if (m == Y)
                {
                    Console.WriteLine($"{i} {j} {k}");
                    return;
                }
            }
        }
        Console.WriteLine("-1 -1 -1");
    }
}

Measured memory_bytes: 13396
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::HashMap;

use itertools::Itertools;

use maplit::*;

use proconio::{input, fastout};
use proconio::marker::*;

const INF: usize = 1_000_000_007;

#[fastout]
fn solve() {
  input!{
    n: usize,
    a: [usize; n],
  };

  let mut l: HashMap<usize, usize> = HashMap::new();
  let mut r: HashMap<usize, usize> = HashMap::new();
  for i in 0..n {
    l.entry(i + a[i])
      .and_modify(|e| *e += 1 )
      .or_insert(1);
    if i >= a[i] {
      r.entry(i - a[i])
        .and_modify(|e| *e += 1 )
        .or_insert(1);
    }
  }
  let mut res = 0usize;
  for (rk, rv) in r.iter() {
    res += rv * l.get(&rk).unwrap_or(&0);
  }
  println!("{}", res);
}

fn main() {
  std::thread::Builder::new()
    .name("big stack size".into())
    .stack_size(32 * 1024 * 1024)
    .spawn(|| {
      solve();
    })
    .unwrap()
    .join()
    .unwrap();
}


Measured memory_bytes: 14324
#include <stdio.h>

int main() {
  int n,a[101],i,j;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  int cnt=0;
  for(i=0; i<n; i++) {
    for(j=n-1; j>i; j--) {
      if(a[j]<a[j-1]) {
	int tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
	cnt++;
      }
    }
  }
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}


Measured memory_bytes: 2096
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
seen = []
for i in a:
    for j in seen:
        if i<j:
            cnt1 += 1
    seen.append(i)
for i in a:
    for j in seen:
        if i<j:
            cnt2 += 1
ans = cnt1*k+cnt2*k*(k-1)//2
print(ans%(10**9+7))

Measured memory_bytes: 3188
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = Integer.parseInt(scanner.nextLine());

        PriorityQueue<Restaurant> pq = new PriorityQueue<>();

        for(int i=0; i<N; i++){
            StringTokenizer stringTokenizer = new StringTokenizer(scanner.nextLine());

            String s = stringTokenizer.nextToken();
            int p = Integer.parseInt(stringTokenizer.nextToken());

            pq.add(new Restaurant(s, p, i+1));
        }

        for(int i=0; i<N; i++){
            Restaurant r = pq.poll();
            System.out.println(r.id);
        }
    }


    public static class Restaurant implements Comparable<Restaurant>{

        String city;
        int point;
        int id;

        public Restaurant(String city, int point, int id){
            this.city = city;
            this.point = point;
            this.id = id;
        }

        @Override
        public int compareTo(Restaurant r) {
            if(this.city.equals(r.city)){
                if(this.point > r.point){
                    return -1;
                }else{
                    return 1;
                }
            }else{
                if(this.city.compareTo(r.city) < 0){
                    return -1;
                }else{
                    return 1;
                }
            }
        }
    }
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N,M=map(int,input().split())
    X, Y = [0] * M, [0] * M
    for i in range(M):
        X[i], Y[i] = map(int, input().split())

    red=[True]+[False]*(N-1)
    cnt=[1]*N

    for i in range(M):
        cnt[X[i]-1]-=1
        cnt[Y[i]-1]+=1
        if red[X[i]-1]:
            red[Y[i]-1]=True
        if cnt[X[i]-1]==0:
            red[X[i] - 1]=False

    print(red.count(True))


resolve()

Measured memory_bytes: 45916
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
#include <functional>
#include <iomanip>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	cout << std::fixed << std::setprecision(10);

	for (;;) {
		int N;
		string S;

		cin >> S >> N;
		if (cin.fail()) break;

		set<string> SS;
		for (int i = 0; i < S.length(); i++) {
			for (int j = i; j < min((int) S.length(), i + N); j++) {
				SS.insert(S.substr(i, j - i + 1));
			}
		}

		cout << *next(SS.begin(), N - 1) << endl;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>

int main(){
  char str[1000],ord[10],work[1000];
  int q,a,b,i,k;

  scanf("%s%d",str,&q);
  
  for(i=0; i<q; ++i){
    scanf("%s",ord);
    memset( work , '\0' , 1000);
    if(strcmp(ord,"replace") == 0){
      
      scanf("%d%d%s",&a,&b,work);
      for(k=a; k <= b; ++k)
	str[k]=work[k-a];
      
    }else if(strcmp(ord,"reverse") == 0){
      
      scanf("%d%d",&a,&b);
      for(k=a; k <= b; ++k)
	work[k-a]=str[k];
      for(k=a; k <= b; ++k)
	str[k]=work[b-k];

    }else{
      
      scanf("%d%d",&a,&b);
      for(k=a; k <= b; ++k)
	work[k-a]=str[k];
      printf("%s\n",work);
      
    }
  }
  


  return 0;
}



Measured memory_bytes: 2684
import copy
n,m = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a.sort()
#print(a)

money = 0
for i in range(n):
    for j in range(a[i][1]):
        money += a[i][0]
        m -= 1
        #print(money,m,a)
        if m == 0:
            break
    if m == 0:
        break
print(money)

Measured memory_bytes: 28364
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static final int MOD = 1000000007;

	static int add(int a, int b) {
		int res = a + b;
		return res >= MOD ? res - MOD : res;
	}

	static int sub(int a, int b) {
		int res = a - b;
		return res < 0 ? res + MOD : res;
	}

	static int mul(int a, int b) {
		int res = (int) ((long) a * b % MOD);
		return res < 0 ? res + MOD : res;
	}

	static int pow(int a, int e) {
		if (e == 0) {
			return 1;
		}
		int r = a;
		for (int i = 30 - Integer.numberOfLeadingZeros(e); i >= 0; i--) {
			r = mul(r, r);
			if ((e & (1 << i)) != 0) {
				r = mul(r, a);
			}
		}
		return r;
	}

	static int h[];

	static void solve() throws Exception {
		int n = scanInt();
		h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = scanInt();
		}
		out.print(solve(0, n, 0));
	}

	static int resAlt;
	static int solve(int from, int to, int level) {
		int nextLevel = Integer.MAX_VALUE;
		for (int i = from; i < to; i++) {
			nextLevel = min(nextLevel, h[i]);
		}
		int rTotal = 1, rAlt = 2;
		for (int i = from, j; i < to;) {
			if (h[i] == nextLevel) {
				rTotal = add(rTotal, rTotal);
				++i;
				continue;
			}
			for (j = i + 1; j < to && h[j] != nextLevel; j++) { }
			int curTotal = solve(i, j, nextLevel);
			int curAlt = resAlt;
			rTotal = mul(rTotal, add(curTotal, curAlt));
			rAlt = mul(rAlt, curAlt);
			i = j;
		}
		rTotal = sub(rTotal, rAlt);
		rAlt = mul(rAlt, pow(2, nextLevel - level - 1));
		rTotal = add(rTotal, rAlt);
		resAlt = rAlt;
		return rTotal;
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

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

int main(){
  
  int a,b,c,d;
  cin >>a >> b >> c >> d;
  int right = 0;
  int left = 0;
  
  left = a+b;
  right = c+d;
  
  string ans = "Right";
  if(right == left)ans = "Balanced";
  if(right < left)ans = "Left";
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  long c,x[n],v[n];
  cin >> c;
  for(int i = 0;i < n;i++){
    cin >> x[i] >> v[i];
  }
  long maxr[n],maxl[n];
  long cur = 0,sum = 0;
  for(int i = 0;i < n;i++){
    sum += v[i];
    cur = max(cur,sum - 2*x[i]);
    maxr[i] = cur;
  }
  long ans = sum - (c-x[0]);
  ans = max(ans,sum-x[n-1]);
  sum = 0;
  for(int i = n-1;i > 0;i--){
    sum += v[i];
    long y = maxr[i-1] + sum - (c - x[i]);
    ans = max(ans,y);
    //cout << ans << endl;
  }
  
  sum = 0;
  cur = 0;
  for(int i = n-1;i >= 0;i--){
    sum += v[i];
    cur = max(cur,sum-2*(c-x[i]));
    maxl[i] = cur;
  }
  
  sum = 0;
  for(int i = 0;i < n-1;i++){
    sum += v[i];
    long y = maxl[i+1]+sum-x[i];
    ans = max(ans,y);
    //cout << ans << endl;
  }
  if(ans >= 0){
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;

ll int get_hcf(ll int a, ll int b){
	if(a == 0LL)
		return b;
	if(b==0LL)
		return a;
	if(a==b)
		return a;
	// trace2(a, b-a)
	if (a > b)
		return get_hcf(a- b , b);
	return get_hcf(a, b-a);
}

int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int n;
	cin >> n;
	vector<ll> a(n);
	ll int min_e = 10000000000LL;
	for(int i = 0; i < n ;i++){
		cin >> a[i];
		min_e = min(min_e, a[i]);
	}

	int flag = 1;
	for(int i = 0; i < n ; i++){
		if(a[i] % min_e != 0LL){
			flag = 0;
			break;
		}
	}

	if(flag == 1){
		cout << min_e;
	}
	else{
		ll int hcf = min_e;
		for(int i = 0 ; i< n ; i++){
			hcf = get_hcf(a[i], hcf);
			// trace1(hcf)
			if (hcf == 1)
				break;
		}
		cout << hcf;
	}

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
struct node
{
	string s;
	int val;
}a[200001];
map<string,int>ma;
map<string,int>::iterator it;
int n;
int cmp(const node &p,const node &q)
{
	if(p.val==q.val)
		return p.s<q.s;
	return p.val>q.val;
}
int main()
{
	string str;
	int i,cnt=0,x;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>str;
		ma[str]++;
	}
	for(it=ma.begin();it!=ma.end();it++)
	{
		cnt++;
		a[cnt].s=it->first;
		a[cnt].val=it->second;
	}
	sort(a+1,a+cnt+1,cmp);
	x=a[1].val;
	for(i=1;i<=cnt;i++)
		if(a[i].val==x)
			cout<<a[i].s<<endl;
	return 0;
}

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

const string dig[10] = { "0111111",
			 "0000110",
			 "1011011",
			 "1001111",
			 "1100110",
			 "1101101",
			 "1111101",
			 "0100111",
			 "1111111",
			 "1101111" };

int main(){
  int n;
  while(cin >> n, n>=0){
    string cur = "0000000";

    for(int i=0;i<n;i++){
      int a; cin >> a;
      string nxt = dig[a];

      for(int j=0;j<7;j++){
	if(cur[j] == nxt[j])cout << "0";
	else cout << "1";
      }
      cout << endl;

      cur = nxt;
    }
  }
}

Measured memory_bytes: 1200
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数
vector<long long> fact, fact_inv, inv;

//二項係数前処理計算量O(SIZE)
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
    
//nCk　計算量(1)
ll nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}


ll jun(ll n,ll k){
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[n-k] % MOD) % MOD;
}
// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N,M;
    cin>>N>>M;
    init_nCk(500100);
    ll ans=0;
    if(M>=N){
        REP(k,N+1){
            ans+=(mod_pow(-1,k,MOD)*(nCk(N,k)*jun(M,k))%MOD*mod_pow(jun(M-k,N-k),2,MOD))%MOD;
            ans%=MOD;
        }
        while(ans<0) ans+=MOD;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 14816
#include<iostream>
#include<climits>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int arr[n],sol[n];
for(int i=0;i<n;i++) 
{
cin>>arr[i];
sol[i]=INT_MAX;
}
sol[0]=0;
sol[1]=abs(arr[1]-arr[0])+sol[0];
for(int i=2;i<n;i++)
{
for(int ki=i-1,jump=0; jump < k && ki >= 0 ;ki--,jump++)
{
sol[i]=min(sol[i],abs(arr[i]-arr[ki])+sol[ki]);
}
}
cout<<sol[n-1]<<"\n";
return 0;
}


Measured memory_bytes: 1024
n,c,k=map(int,input().split())
t=[]
for i in range(n):
  t.append(int(input()))
t.sort()

bus=0
arr=0
que=0
for i in range(n):
  tt=t[i]
  if que==0:
    #print('que=0,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
    arr=tt
    que+=1
    bus+=1
  else:
    if que==c:
      #print('q==c,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
      bus+=1
      arr=tt
      que=1
    else:
      if arr+k<tt:
        #print('dep,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        bus+=1
        arr=tt
        que=1
      else:
        #print('waiting,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        que+=1

print(bus)

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

int main(){
	int n,m;
	cin >> n >> m;
	int k;
	int a;
	int existLike[m+1] = {};
	for(int i = 0; i < n; i++){
		cin >> k; 
		for(int j = 0; j < k; j++){
			cin >> a;
			existLike[a]++;
		}
	}
	int count = 0;
	for(int i = 1; i <= m; i++){
		if(existLike[i] == n)count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,p[1000],s,i,j,t;
  while(1){
    scanf("%d %d",&n,&m);
    if(n==0&&m==0)break;
    s=0;
    for(i=0;i<n;i++){
      scanf("%d",&p[i]);
      s+=p[i];
    }
    for(i=0;i<n;i++){
      for(j=1;i+j<n;j++){
	if(p[j-1]<p[j]){
	  t=p[j];
	  p[j]=p[j-1];
	  p[j-1]=t;
	}
      }
    }
    for(i=m-1;i<n;i+=m){
      s-=p[i];
    }
    printf("%d\n",s);
  }
  return 0;
}

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

ll fact(ll N) {
  ll ans = 1;
  for (ll i = 1; i <= N; ++i) ans *= i;
  return ans;
}

int main() {
  ll N,x,y;
  double ans = 0.0;
  cin >> N;
  const ll routenum = fact(N);
  vector<vector<ll>> pvec;
  for (ll i = 0; i < N; ++i) {
    cin >> x >> y;
    vector<ll> v = {x,y};
    pvec.push_back(v);
  }
  for (ll i = 0; i < N-1; ++i) {
    const vector<ll> iv = pvec[i];
    for (ll j = i+1; j < N; ++j) {
       const vector<ll> jv = pvec[j];
       double d = sqrt((iv[0]-jv[0])*(iv[0]-jv[0])+(iv[1]-jv[1])*(iv[1]-jv[1]));
       ans += d;
    }
  }
  ans = ans*fact(N-1)*2/routenum;
  printf("%.10f",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int N, K;
    std::string S;
    std::cin >> N >> K >> S;
    K--;
    if (S.at(K) == 'A') {
        S.at(K) = 'a';
    }
    if (S.at(K) == 'B') {
        S.at(K) = 'b';
    }
    if (S.at(K) == 'C') {
        S.at(K) = 'c';
    }
    std::cout << S << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i=0,n=0,m[3]={0,0,0},h,w;
  char s[4];
  scanf("%s",s);
  for(i=0;i<3;i++){
   if(s[i]=='a')
     m[0]=1;
   if(s[i]=='b')
     m[1]=1;
   if(s[i]=='c')
     m[2]=1;  
  }
  for(i=0;i<3;i++)
    if(m[i]==1)
      n++;
  if(n==3)
  printf("Yes");
  else
    printf("No");
  return 0; 
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 4e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[3][maxn], b[maxn], pos[maxn], fen[maxn];

bool good(int val, int x)
{
	bool okay = true;
	for (int i = 0; i < 3; i++)
		okay &= (a[i][x] == val + i);
	if (okay)
	{
		b[x] = (val - 1) / 3 + 1;
		return true;
	}

	okay = true;
	for (int i = 0; i < 3; i++)
		okay &= (a[2 - i][x] == val + i);
	if (okay)
	{
		b[x] = -((val - 1) / 3 + 1);
		return true;
	}

	return false;
}

void update(int x)
{
	for (int i = x; i < maxn; i += (i & -i))
		fen[i]++;
}

int query(int x)
{
	int sum = 0;
	for (int i = x; i; i -= (i & -i))
		sum += fen[i];
	return sum;
}

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

	cin >> n;
	for (int row = 0; row < 3; row++)
		for (int col = 0; col < n; col++)
		{
			cin >> a[row][col];
			pos[a[row][col]] = col;
		}

	for (int i = 0; i < n; i++)
	{
		int now = 3 * i + 1;
		int col = pos[now];
		if (!good(now, col))
		{
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = 0; i < n; i += 2)
		if (b[i] % 2 == 0)
		{
			cout << "No" << endl;
			return 0;
		}
	for (int i = 1; i < n; i += 2)
		if (b[i] % 2 == 1)
		{
			cout << "No" << endl;
			return 0;
		}

	/*for (int i = 0; i < n; i++)
		cerr << '_' << b[i];
	cerr << endl;*/

	ll invO = 0, invE = 0, flipO = 0, flipE = 0;
	for (int i = 0; i < n; i += 2)
	{
		update(abs(b[i]));
		invE += query(n) - query(abs(b[i]));
		flipE += (b[i] < 0);
	}
	memset(fen, 0, sizeof(fen));
	for (int i = 1; i < n; i += 2)
	{
		update(abs(b[i]));
		invO += query(n) - query(abs(b[i]));
		flipO += (b[i] < 0);
	}

	//cerr << "INV " << invE << ' ' << invO << endl;
	//cerr << "FLIP " << flipE << ' ' << flipO << endl;

	if ((flipE & 1) == (invO & 1) && (flipO & 1) == (invE & 1))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



Measured memory_bytes: 8576
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(h: usize, w: usize, m: usize, hw: [[u32; 2]; m]);

    let mut w_sum = vec![0u32; h];
    let mut h_sum = vec![0u32; w];

    let mut hw_map = std::collections::HashMap::<String, u32>::new();

    for v in hw {
        w_sum[(v[0] - 1) as usize] += 1;
        h_sum[(v[1] - 1) as usize] += 1;
        let s = format!(
            "{}{}{}",
            (v[0] - 1).to_string(),
            "_".to_string(),
            (v[1] - 1).to_string()
        );

        if hw_map.contains_key(&s) {
            let a = hw_map.get(&s).unwrap();
            hw_map.insert(s, a + 1);
        } else {
            hw_map.insert(s, 1u32);
        }
    }

    let mut w_max = 0;
    let mut w_max_index = Vec::new();
    for i in 0..w_sum.len() {
        if w_max == w_sum[i] {
            w_max_index.push(i);
        } else if w_max < w_sum[i] {
            w_max_index = Vec::new();
            w_max_index.push(i);
            w_max = w_sum[i];
        }
    }

    let mut h_max = 0;
    let mut h_max_index = Vec::new();
    for i in 0..h_sum.len() {
        if h_max == h_sum[i] {
            h_max_index.push(i);
        } else if h_max < h_sum[i] {
            h_max_index = Vec::new();
            h_max_index.push(i);
            h_max = h_sum[i];
        }
    }
    let mut mainasu = 1;
    for v in h_max_index {
        for vw in &w_max_index {
            let s = format!("{}{}{}", vw.to_string(), "_".to_string(), v.to_string());
            if !hw_map.contains_key(&s) {
                mainasu = 0;
                break;
            }
        }
        if mainasu == 0 {
            break;
        }
    }

    println!("{}", w_max + h_max - mainasu);
}


Measured memory_bytes: 50284
import sys
from random import randint
input = sys.stdin.readline
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

t = [0] * D
last = [0] * 26
def score(day, score):
  for i in range(26): score -= (day - last[i]) * c[i]
  return score
def run(day):
  global last
  last = [0] * 26
  res = 0
  for d in range(day):
    contest = t[d] - 1
    last[contest] = d + 1
    res = score(d + 1, res) + s[d][contest]
  return res


for d in range(1, D + 1):
  mx = -float("inf")
  mxx = randint(1, 27)
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx
for d in range(1, D + 1):
  mx = -float("inf")
  mxx = t[d - 1]
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx

for x in t: print(x + 1)

Measured memory_bytes: 79612
#include <stdio.h>

int main()
{
	int i, H, W;
	char c[302][302];
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(c[i][1]));
	
	int j, k, l, ans = 0, dp[302][302], cost[302][302];
	for (i = 1; i <= W - 1; i++) {
		for (j = -H; j <= H; j++) {
			for (k = 0; j + k < 0; k++);
			for (cost[k][j+k] = 0, k++; k <= H && j + k <= H; k++) cost[k][j+k] = cost[k-1][j+k-1] + ((c[k][i] == c[j+k][i+1])? 1: 0);
		}
		
		dp[H][H] = cost[H][H];
		for (j = H - 1; j >= 0; j--) dp[j][H] = dp[j+1][H] + cost[j][H];
		for (k = H - 1; k >= 0; k--) dp[H][k] = dp[H][k+1] + cost[H][k];
		for (j = H - 1; j >= 0; j--) {
			for (k = H - 1; k >= 0; k--) {
				if (dp[j+1][k] < dp[j][k+1]) dp[j][k] = dp[j+1][k] + cost[j][k];
				else dp[j][k] = dp[j][k+1] + cost[j][k];
			}
		}
		
		ans += dp[0][0];
	}
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){cout << "Yes" << endl;}
inline void No(){cout << "No" << endl;}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){cout << "YES" << endl;}
inline void NO(){cout << "NO" << endl;}
inline void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    ll n;
    scanf("%lld", &n);

    ll ans = LINF;
    for(ll l = 1; l*l <= n; ++l){
        if(n%l == 0)
            chmin(ans, l+n/l-2);  
    }  
    ppp(ans); 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int x;
    cin>>x;
    cout << ((x == 0) ? 1 : 0) << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

class Mint
{
private:
	ll x;
public:
	Mint(ll x = 0) :x((x% mod + mod) % mod) {}
	ll Get() const { return x; }
	Mint operator-() const { return Mint(-x); }
	Mint& operator+=(const Mint a)
	{
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	Mint& operator-=(const Mint a)
	{
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	Mint& operator*=(const Mint a) { (x *= a.x) %= mod; return *this; }
	Mint operator+(const Mint a) const { return Mint(*this) += a; }
	Mint operator-(const Mint a) const { return Mint(*this) -= a; }
	Mint operator*(const Mint a) const { return Mint(*this) *= a; }
	Mint pow(ll t) const
	{
		if (!t) return 1;
		Mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	Mint inv() const { return pow(mod - 2); }
	Mint& operator/=(const Mint a) { return *this *= a.inv(); }
	Mint operator/(const Mint a) const { return Mint(*this) /= a; }
};
inline ostream& operator<<(ostream& os, const Mint& a) { return os << a.Get(); }

class Combination
{
	//  1 <= k <= n <= 1e7、modは素数
public:
	vector<Mint> fact, ifact;
private:
	Combination(int n) :fact(n + 1), ifact(n + 1)
	{
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	Mint operator()(int n, int k)
	{
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

template<class Type>
Mint inv_nCk(Type n, Type k)
{
	//  1<= n <= 1e9 (nは固定値), 1 <= k <= 1e7
	Mint x = 1, y = 1;
	for (Type i = 0; i < k; i++) {
		x *= n - i;
		y *= i + 1;
	}
	return x / y;
}

template<class Type>
Type pascal_nCk(Type n, Type k, Type mod)
{
	//  1 <= k <= n <= 2e7、modは素数以外でも可
	vector<vector<Type>> dp(n + 1, vector<Type>(n + 1, 0));
	for (int i = 0; i <= n; i++) {
		dp[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
		}
	}
	return dp[n][k];
}

int main()
{
	int n;
	cin >> n;
	Mint ans(1);
	for (int i = 0; i < n; i++) ans *= 10;
	Mint sub1(1);
	for (int i = 0; i < n; i++) sub1 *= 9;
	Mint sub2(1);
	for (int i = 0; i < n; i++) sub2 *= 9;
	Mint sub3(1);
	for (int i = 0; i < n; i++) sub3 *= 8;
	cout << ans - sub1 - sub2 + sub3 << endl;
}


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

int main() {
  int n,k;
  int ans=0;

  cin >> n >> k;

  vector<int> p(n,0);

  for(int i=0;i<n;i++) {
    cin >> p[i];
  }
  sort(p.begin(),p.end());

  for(int i=0;i<k;i++) {
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
use proconio::*;

fn main() {
    input! {
        n:usize,
        d:[(i64, i64); n],
    }

    let mut f = false;
    for i in 0..n - 2 {
        if d[i].0 == d[i].1 && d[i + 1].0 == d[i + 1].1 && d[i + 2].0 == d[i + 2].1 {
            f = true;
            break;
        }
    }

    if f {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>
#include <ctime>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> s(n), t(n), p(m);
	rep(i, n) cin >> s[i] >> t[i];
	rep(i, m) cin >> p[i];

	vector<int> x;
	x.insert(x.end(), ALL(p));

	sort(ALL(x));

	vector<int> first(n), last(n);

	map<int, int> be, en;
	rep(i, n){
		if (s[i] < t[i]){
			int cnt = lower_bound(ALL(x), t[i]) - lower_bound(ALL(x), s[i]);
			first[i] = 1;
			last[i] = !(cnt & 1);
		}
		else{
			swap(s[i], t[i]);
			int cnt = lower_bound(ALL(x), t[i]) - lower_bound(ALL(x), s[i]);
			first[i] = !(cnt & 1);
			last[i] = 1;
		}

		be[s[i]] = i;
		en[t[i]] = i;

	}
	x.insert(x.end(), ALL(s));
	x.insert(x.end(), ALL(t));
	sort(ALL(x));

	ll ans = 0, sum = 0, valid = 0, prv = 0;
	for (auto pos : x){
		ans += valid*(pos - prv);
		if (be.count(pos)){
			++sum;
			valid += first[be[pos]];
		}
		else if (en.count(pos)){
			--sum;
			valid -= last[en[pos]];
		}
		else{
			valid = sum - valid;
		}
		prv = pos;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 14320