akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
int main(){
   int n, cnt, ans=0;
   string x;
   cin >> n;
   vector<pair<string, int>> k(n);
   REP(i,n){
       cin >> k[i].first >> k[i].second;
   }
   cin >> x;
   REP(i, n){
       if(k[i].first==x){
           cnt=i+1;
           break;
       }
   }
    FOR(i, cnt, n){
        ans+=k[i].second;
    }
    cout << ans << endl;

}

    



Measured memory_bytes: 256
op = {"+": lambda a,b: b + a, "-": lambda a,b: b - a, "*": lambda a,b: b * a}
stack = []

for c in input().split():
    if c in op:
        stack.append(op[c](stack.pop(),stack.pop()))
    else:
        stack.append(int(c))
print(stack[-1])



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

using namespace std;

void solve(int N, vector<int> h)
{
  int ans = 0;
  int cnt = 0;
  for (;;)
  {
    for (int i = 0; i < N; i++)
    {
      if (h[i] > 0)
      {
        cnt += 1;
        h[i] -= 1;
      }
      else
      {
        if (cnt != 0)
        {
          ans += 1;
          cnt = 0;
        }
      }
    }
    if (cnt != 0)
    {
      ans += 1;
    }
    cnt = 0;
    if (*max_element(h.begin(), h.end()) <= 0)
    {
      break;
    }
  }
  printf("%d\n", ans);
}

int main()
{
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++)
  {
    cin >> h[i];
  }
  solve(N, h);
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
bool isacgt(char c){
    return (
        c=='A' || c=='C' || c=='G' || c=='T'
    );
}

int main() {

    string s;
    cin >> s;
    int n = s.size();

    int len=0, ans=0;
    rep(i,n){
        if(isacgt(s[i])){
            len++;
        }else{
            len=0;
        }
        ans = max(len,ans);
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3596
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	ll h;
	cin >> h;
	if (h == 1) { 
		cout << 1 << endl; return 0; 
	}
	ll c = 1;
	map<ll, ll> m;
	m[1] = 1;
	while (true) {
		if (c == h) {
			cout << m[c] << endl;
			return 0;
		}
		else if (c > h) {
			cout << m[c/2] << endl;
			return 0;
		}
		m[c * 2] = m[c] * 2 + 1;
		c = c * 2;
	}
	return 0;
}


Measured memory_bytes: 256
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 100 + 8;

int n,minj;
int selectSort(int a[])
{
    int num = 0;
    for(int i = 0; i < n; ++i){
        minj = i;
        for(int j = i; j < n; ++j){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        if(minj != i) {
            swap(a[minj],a[i]);
            num++;
        }
    }
    return num;
}
int a[maxn];
int main()
{
    fill(a,a+n,0);
    scanf("%d",&n);
    for(int i = 0; i < n; ++i){
        scanf("%d",&a[i]);
    }
    int ans = selectSort(a);

    for(int i = 0; i < n; ++i){
        printf("%s%d",i == 0 ? "":" ",a[i]);
    }
    printf("\n%d\n",ans);
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int h,w;cin>>h>>w;
    vector<vector<int>> t(h,vector<int>(w));
    rep(i,h)rep(j,w) cin>>t[i][j];
    vector<pair<int,int>> p,p2;
    rep(i,h){
        rep(j,w-1){
            if(t[i][j]%2==1){
                p.push_back({i+1,j+1});
                p2.push_back({i+1,j+2});
                t[i][j+1]++;
            }
        }
        if(i==h-1) break;
        if(t[i][w-1]%2==1){
            p.push_back({i+1,w});
            p2.push_back({i+2,w});
            t[i+1][w-1]++;
        }
    }
    cout<<p.size()<<endl;
    rep(i,p.size()){
        cout<<p[i].first<<" "<<p[i].second<<" "<<p2[i].first<<" "<<p2[i].second<<endl;
    }
}

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

int main()
{
    int r,c,t[110][110]={};

    cin>>r>>c;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin>>t[i][j];
        }
    }

    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            t[r+1][j]+=t[i][j];
            t[i][c+1] += t[i][j];
            t[r+1][c+1] += t[i][j];
        }
    }

    for(int i=1;i<=r+1;i++){
        for(int j=1;j<=c+1;j++){
            cout<<t[i][j];
            if(j!=c+1){
                cout<<" ";
            }else{
                cout<<endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include<vector>
#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 srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()

using namespace std;



int main() {
    char alpha;
    cin>>alpha;
    string alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char ans = 'a';
    rep(i,27){
        if(alpha==alphabet[i]){
            ans = 'A';
            break;
        }
        
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }
  
  vector<int> cnt(N, 1);
  for(int i=0;i<N-1;i++){
    if(cnt.at(i)==-1) continue;
    for(int j=i+1;j<N;j++){
      if ( blue.at(i) == blue.at(j)){
        cnt.at(i) +=1;
        cnt.at(j) = -1;   
        }
    }
  }
  
  for(int i=0;i<N;i++){
    if(cnt.at(i) == -1) continue;
    for(int j=0; j<M;j++){
      if (blue.at(i) == red.at(j)){
        cnt.at(i)-=1;
      }
    }
  }

  int maxval = 0;
  for(int i=0;i<N;i++){
    //cout << i << "," <<blue.at(i) << ": "<< cnt.at(i)<< endl;
    if (cnt.at(i) < 0 ) continue;
    if (maxval < cnt.at(i)) maxval=cnt.at(i);
  }
  cout << maxval << endl;
}
  

Measured memory_bytes: 384
n,k = map(int,input().split())
nList = list(map(int,input().split()))
nSet = list(set(nList))
nDic = {}

for i in nList:
  if not(i in nDic.keys()):
    nDic[i] = 1
  else:
    nDic[i] += 1

countList = sorted(nDic.values())
print(sum(countList[:(len(nSet)-k)]))

   




Measured memory_bytes: 38452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()

int main() {
  int l,r,d,n1,n2,n;
  cin >> l >> r >> d;
  n1=(l-1)/d;
  n2=r/d;
  n=n2-n1;
  cout << n << endl;
}



Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#define MAXV 101
#define INF 2001
using namespace std;

int n, total = 0, mine, minj;
int mst[MAXV] = {}; //1 origin
int edge[MAXV][MAXV] = {}; //1 origin

void prim(void);
bool doesFinished(void);

int main() {
	int i, j;
	
	cin >> n;
	for (i = 1; i <= n; i++) {
		
		for (j = 1; j <= n; j++) {
			cin >> edge[i][j];
		}
	}

	mst[1] = 1;
	while (!doesFinished()) {
		prim();
	}

	cout << total << endl;

	return 0;
}

void prim(void) {
	int i, j;
	mine = INF;
	for (i = 1; i <= n; i++) {
		if (mst[i] == 0)continue;
		for (j = 1; j <= n; j++) {
			if (edge[i][j] == -1 || mst[j] == 1)continue;
			if (edge[i][j] < mine) {
				mine = edge[i][j];
				minj = j;
			}
		}
	}
	mst[minj] = 1;
	if(mine != INF)total += mine;
}

bool doesFinished(void) {
	for (int i = 1; i <= n; i++) {
		if (mst[i] == 0)return false;
	}
	return true;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,b;
    float a,c=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        {
            cin>>b;
            if(b>=k)
            c++;
        }
    cout<<c;
}














			

Measured memory_bytes: 256
n = int(input())
s = ''
value = 0
count = 0
while value != n:
    r = n % 2**(count+1)
    if (value + (-2)**count)%(2**(count+1)) == r:
        s += '1'
        value += (-2)**count
    else:
        s += '0'
    count += 1
if n == 0:
    print(0)
else:
    print(int(s[::-1]))
        

Measured memory_bytes: 3060
// A / B Problem

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cassert>

int main()
{
  int a, b;
  std::cin >> a >> b;

  assert(b != 0);

  const int    d = a / b;
  const int    r = a % b;
  const double f = static_cast<double>(a) / b;

  printf("%d %d %.5f\n", d, r, f);

  return 0;
}

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

const long long INF = 1e16;

long long go(int i, int v, vector<int>& weights, vector<int>& values, vector<vector<long long>>& dp) {
    if (v < 0) return INF;
    if (v == 0) return 0;
    if (i == weights.size()) return INF;
    long long& ans = dp[i][v];
    if (ans != -1) return ans;
    return ans = min(go(i + 1, v, weights, values, dp), weights[i] + go(i + 1, v - values[i], weights, values, dp));
}

void testcase() {
    int n, w;
    cin >> n >> w;
    vector<int> weights(n), values(n);
    for (int i = 0; i < n; i++) {
        cin >> weights[i] >> values[i];
    }
    long long sum_value = accumulate(values.begin(), values.end(), 0LL);
    vector<vector<long long>> dp(n, vector<long long>(sum_value + 1, -1));
   
 	// dp[i][v] -> min. weight of items to achieve value exactly v using any subset of items [i...n-1]
    // dp[0][v] -> min. weight of items to achieve value exactly v using any subset of items [0...n-1]
    
	for (long long v = sum_value; v >= 0; v--) {
        go(0, v, weights, values, dp);
    }
    long long ans = 0;
    for (long long v = sum_value; v >= 0; v--) {
        if (dp[0][v] <= w) {
            ans = v;
            break;
        }
    }
    cout << ans << "\n";
}

int main(){
#ifdef AKP
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--){
    	testcase();
    }
    return 0;
}


Measured memory_bytes: 79488
#[allow(dead_code)]
mod scanner {
    use std::io::StdinLock;
    use std::str::FromStr;
    use std::io::BufRead;
    pub struct Scanner<'a> {
        stdin: StdinLock<'a>,
        token: Vec<String>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(stdin: StdinLock) -> Scanner {
            Scanner {
                stdin: stdin,
                token: vec![],
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.token.pop() {
                    return token.parse().ok().expect("Scanner : Parse Error");
                }
                let mut s = String::new();
                self.stdin.read_line(&mut s).unwrap();
                self.token = s.trim().split_whitespace().rev().map(String::from).collect();
            }
        }
    }
}

fn main() {
    let stdin = std::io::stdin();
    let sc = scanner::Scanner::new(stdin.lock());
    run(sc);
}

use std::cmp::max;

fn calc(a: &Vec<i64>) -> Vec<i64> {
    let n = a.len() / 3;
    let mut h = std::collections::BinaryHeap::new();
    let mut sum = 0i64;
    let mut ans = vec![0; 3 * n];
    for (i, &a) in a.iter().enumerate() {
        sum += a;
        h.push(-a);
        if h.len() > n {
            sum -= -h.pop().unwrap();
        }
        ans[i] = sum;
    }
    ans
}

fn run(mut sc: scanner::Scanner) {
    let n: usize = sc.read();
    let mut a: Vec<i64> = (0..(3 * n)).map(|_| sc.read()).collect();
    let left = calc(&a);
    a.reverse();
    for a in a.iter_mut() {
        *a = -*a;
    }
    let right = calc(&a);
    let mut ans = -100_000 * 1_000_000_000;
    for i in (n - 1)..(2 * n) {
        ans = max(ans, left[i] + right[3 * n - 2 - i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 27016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

struct Dice{
	string me[6];
	
	void Init(string a[6]){
		for (int i = 0; i < 6; i++){
			me[i] = a[i];
		}
	}

	bool check(Dice d2){
		for (int i = 0; i < 6; i++){
			if (d2.me[i] != me[i])return false;
		}
		return true;
	}

	void print(){
		for (int i = 0; i < 6; i++){
			cout << me[i] << " ";
		}
		cout << endl;
	}
};

int n;
string a[6];
Dice d[110];
bool F[100];

int main(){
	while (cin >> n&&n){
		fill(F, F + 100, 1);
		REP(i, n){
			REP(j, 6)cin >> a[j];
			d[i].Init(a);
		}
		bool f = 0;
		REP(k, n){
			if (F[k]){
				FOR(l, k + 1, n){
					REP(i, 4){
						REP(j, 4){
							if (d[k].check(d[l]))F[l] = 0;
							swap(d[k].me[1], d[k].me[2]);
							swap(d[k].me[2], d[k].me[4]);
							swap(d[k].me[4], d[k].me[3]);
						}
						REP(j, 4){
							if (d[k].check(d[l]))F[l] = 0;
							swap(d[k].me[0], d[k].me[1]);
							swap(d[k].me[1], d[k].me[5]);
							swap(d[k].me[5], d[k].me[4]);
						}
						swap(d[k].me[0], d[k].me[2]);
						swap(d[k].me[2], d[k].me[5]);
						swap(d[k].me[5], d[k].me[3]);
					}
				}
			}
		}
		int co = 0;
		REP(i, n)if (F[i])co++;
		cout << n - co << endl;
	}
}

Measured memory_bytes: 1228
n,m = gets.chomp.split(" ").map(&:to_i)
a = Array.new(n,nil)
flag = 1
m.times do
  s,c = gets.chomp.split(" ").map(&:to_i)
  if a[s-1] == nil
    a[s-1] = c
  else
    if a[s-1] == c
      next
    else
      flag = 0
      break
    end
  end
end

flag = 2 if n == 1 && m == 0


if flag == 1
  a.each_with_index do |val,i|
    if i == 0 && val == nil
      a[i]=1
      next
    end
    if val == nil
      a[i]=0
    end
  end
  if a[0] == 0 && a.size != 1
    puts -1
  else
    str=""
    a.each do |val|
      str+=val.to_s
    end
    puts str.to_i
  end
else
  if flag == 2
    puts 0
  else
    puts -1
  end
end

Measured memory_bytes: 1788
x1, y1, x2, y2 = map(int, input().split())
a = x2 - x1
b = y2 - y1
x3 = x2 - b
y3 = y2 + a
x4 = x3 - a
y4 = y3 - b
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#!/usr/bin/env python
from collections import deque

def main():
    n = int(input())
    c = input()

    cnt = 0
    que = deque(c)

    while que:
        r = que.pop()
        if r == 'R':
            while que:
                l = que.popleft()
                if l == 'W':
                    cnt += 1
                    break

    print(cnt)

if __name__ == '__main__':
    main()


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

    int result = 0;

    for (int i = 1; i <= int(sqrt(N)); i++) {
        for (int j = N; j >= int(sqrt(N)); j--) {
                if (N - j*i > 0) {
                    if (i > j) {
                        continue;
                    }else if (i == j) {
                      	result++;
                    } else {
                        result++;
                        result++;
                    }
                }
        }
    }

    cout << result + int((int(sqrt(N))-1) * (int(sqrt(N))-1)) << endl;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int c = scanner.nextInt();
        int [] b = new int[m];
        for (int i = 0; i < m; ++i) {
            b[i] = scanner.nextInt();
        }
        int  [][] a = new int[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                a[i][j] = scanner.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; ++i) {
            long res = c;
            for (int j = 0; j < m; ++j) {
                res += a[i][j] * b[j];
            }
            if (res > 0) {
                ++count;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(int i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
template<class T>
T gcd(T a,T b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
template<class T>
T lcm(T a,T b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

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

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

ll yakusu(ll n){
    ll res = 0;
    for(ll i = 2;i * i <= n;i++){
        if(n % i == 0){
            if(i * i == n)res++;
            else res += 2;
        }
    }
    res++;
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    if(N == 2){
        cout << "1\n";
        return 0;
    }
    ll ans = 1;
    ans += yakusu(N - 1);
    for(ll i = 2;i * i <= N;i++){
        if(N % i == 0){
            ll n = N;
            while(n > 1){
                if(n % i == 0){
                    n /= i;
                }
                else break;
            }
            if(n % i == 1)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  string N;
  cin >> N;
  ll K;
  cin >> K;
  ll len = N.size();
  vector<vector<vector<ll>>> dp(len + 1, vector<vector<ll>>(K + 2, vector<ll>(2, 0)));
  ll cnt = 0;
  ll temp = -1;
  while (cnt <= K && (temp != len)) {
    temp += 1;
    dp.at(temp).at(cnt).at(0) = 1;
    if (N[temp] == '0') {
      continue;
    }
    cnt += 1;
  }
  for (ll i = 0; i < len; ++i) {
    for (ll j = 0; j <= K; ++j) {
      dp.at(i + 1).at(j + 1).at(1) += dp.at(i).at(j).at(1) * 9;
      dp.at(i + 1).at(j).at(1) += dp.at(i).at(j).at(1);

      if (N[i] != '0') {
        dp.at(i + 1).at(j).at(1) += dp.at(i).at(j).at(0);
        dp.at(i + 1).at(j + 1).at(1) += dp.at(i).at(j).at(0) * (N[i] - '0' - 1);
      }
    }
  }
  // for (ll i = 0; i < len + 1; ++i) {
  //   for (ll j = 0; j < K + 1; ++j) {
  //     for (ll k = 0; k < 2; ++k) {
  //       cout << dp.at(i).at(j).at(k) << ' ';
  //     }
  //     cout << endl;
  //   }
  //   cout << endl;
  //   cout << endl;
  // }
  ll ans = 0;
  for (ll i = 0; i < 2; ++i) {
    ans += dp.at(len).at(K).at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(i%j==0) cnt++;
    }
    if(cnt==8){
      ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
int R, G, B;

void input() {
  ;

  cin >> N >> M;
  ;
}
void solve() {
  if (N / 2019 < M / 2019) {
    cout << 0 << endl;
    return;
  }
  N %= 2019;
  M %= 2019;
  int ans = INF;
  rep(i, N, M) {
    rep(j, i + 1, M) { chmin(ans, (i * j) % 2019); }
  }
  rep(i, M, N) {
    rep(j, i + 1, N) { chmin(ans, (i * j) % 2019); }
  }
  cout << ans << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
int main() {
  int x,y;
  cin >> x >> y;
  if((y-2*x)%2==0 && (y-2*x)>=0 && y<=4*x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    ll A, B, N; cin >> A >> B >> N;
    ll x = N;
    if (N >= B) x = B - 1;
    cout << (x * A / B) << endl;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long k, n, a[200100], i, diff[200100]={0}, ans=0;
    cin >> k >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    } 
    for(i=0;i<n-1;i++){
        diff[i]=a[i+1]-a[i];
    }
    diff[i]=k-a[n-1]+a[0];
    sort(diff, diff+n);
    for(i=0;i<n-1;i++){
        ans=ans+diff[i];
    }
    cout << ans <<endl;
    return 0;
}

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

typedef long long ll;

struct node{
	int id;
	ll val;
	bool operator<(const node&n)const
	{
		return val > n.val;
	}
}a[2005];

ll dp[2005][2005][2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		a[i].id = i;
		cin >> a[i].val;
	}
	sort(a+1,a+1+n);
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if( i == 1 )
		{
			dp[i][1][0] = abs(1-a[i].id) * a[i].val;
			dp[i][0][1] = abs(n-a[i].id) * a[i].val;
			continue;
		}
		for (int j = 0; j <= i; j++)
		{
			if( j == 0 )
			{
				ll v = abs((n-(i-1))-a[i].id) * a[i].val; 
				dp[i][j][1] = dp[i-1][j][1] + v;
			}else if( j == i )
			{
				ll v = abs(i - a[i].id ) * a[i].val;
				dp[i][j][0] = dp[i-1][j-1][0] + v;
			}else
			{
				ll v1 = abs(j - a[i].id) * a[i].val;
				ll v2 = abs((n - (i-1-j)) - a[i].id ) * a[i].val;
				dp[i][j][0] = max(dp[i-1][j-1][0], dp[i-1][j-1][1]) + v1;
				dp[i][j][1] = max(dp[i-1][j][0],dp[i-1][j][1]) + v2;
				
			}
			if( i == n )
			{
				ans = max(ans,dp[i][j][0]);
				ans = max(ans,dp[i][j][1]);
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 42016
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	long long int N, ans = 0;
	bool flag = true;
	cin >> N;
	vector<long long int>a(N);
	vector<long long int>beki(N, 0);
	for (long long int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	for (long long int i = N-1; i >= 0; --i)
	{
		long long int k = 0;
		for (long long int j = 0; j < N/(i+1); j++)
		{
			if (beki[(i + 1)*(j + 1) - 1] == 1)k++;
		}
		if (k % 2 != a[i])beki[i]=1;
	}
	
	for (long long int i = 0; i < N; i++)
	{
		long long int k = 0;
		for (long long int j = 0; j < N/(i+1); j++)
		{
			if (beki[(i+1)*(j + 1)-1] == 1)k++;
		}
		if (k % 2 != a[i])flag = false;
	}
	if (flag) {
		for (long long int i = 0; i < N; i++)if (beki[i] == 1)ans++;
		cout << ans << endl;
		for (long long int i = 0; i < N; i++)
		{
			if (beki[i] == 1)cout << i + 1 << " ";
		}
	}
	else cout << -1;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int a,b,c,d,m,n;
	cin >> a >> b;
	c = a;
	d = b;
	while(d != 0){
		m = c % d;
		c = d;
		d = m;
	}
	long long int tar = a * b / c;
	cout << tar;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const ll inf = 9e18;
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void vpd(vector<pair<int, int>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vd(vector<T> vec)
{
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T> void debug::vd2(vector<vector<T>> vec)
{
    for(auto vv : vec) for(auto vvv : vv) cout << vvv << " ";
    cout << endl;
}

template<typename T> void debug::vpd(vector<pair<int, int>> vec) {
    for(auto const& vv : vec) {
        cout << vv.first << " " << vv.second << endl;
    }
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

class CDistinctOrNot {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    vector<ll> a(n);
	    for(int i=0; i<n; i++){
	        in >> a[i];
	    }

	    set<ll> s;
	    for(int i=0; i<n; i++){
	        s.insert(a[i]);
	    }

	    ans2(s.size() == n, out);
	}
};


int main() {
	CDistinctOrNot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 11136
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    n,k = readInts()
    print(k*(k-1)**(n-1))
if __name__ == '__main__':
  main()


Measured memory_bytes: 5256
s = int(input())
a = [0,s]  
for i in range(1,1000010):
    if a[i]%2 == 0:
        a.append(a[i]//2)
    else:
        a.append(3*a[i]+1) 
        
for i in range(1,1000009):
    if a[i] in a[:i]:
        print(i)
        break


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;


ll N, W;
ll weight[110], value[110];

ll dp[110][100010];

int main() {
	
	cin >> N >> W;
	REP(i, N) cin >> weight[i] >> value[i];

	REP(i, 110)REP(j, 100010)dp[i][j] = 0;

	for (int i = 0; i < N; ++i) {
		for (int w = 0; w <= W; ++w) {
			if (w >= weight[i]) dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
			else dp[i + 1][w] = dp[i][w];
		}
	}

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


Measured memory_bytes: 86144
N = int(input())
A = list(map(int, input().split()))

for k in range(N-1):
    print(A[k], end=" ")
print(A[N-1])
for i in range(1, N):
    v = A[i]
    j = i - 1
    while(j>=0 and A[j] > v):
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    for k in range(N-1):
        print(A[k], end=" ")
    print(A[N-1])

Measured memory_bytes: 7952
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n;
	ll ans = 1;
	bool flag = true;
	int cnt0 = 0;
	cin >> n;
	vector<int>a(n);
	REP(i, n) {
		cin >> a[i];
		if (n % 2 == 0 && a[i] == 0) {
			flag = false;
		}
		if (a[i] >= n) {
			flag = false;
		}
		if (a[i] == 0) {
			cnt0++;
		}
	}
	if (n%2!=0&&cnt0 != 1) {
		flag = false;
	}
	sort(a.begin(), a.end());
	int i;
	if (n % 2 == 0) {
		i = 0;
		while (i <= n-2) {
			if (i % 2 == 0) {
				if (a[i] != a[i + 1]) {
					flag = false;
				}
			}
			else {
				if (a[i] != a[i + 1] - 2) {
					flag = false;
				}
			}
			i++;
		}
	}
	else {
		i = 1;
		while (i <= n - 2) {
			if (i % 2 != 0) {
				if (a[i] != a[i + 1]) {
					flag = false;
				}
			}
			else {
				if (a[i] != a[i + 1] - 2) {
					flag = false;
				}
			}
			i++;
		}
	}
	REP(i, n / 2) {
		ans *= 2;
		if (ans >= MOD) {
			ans %= MOD;
		}
	}
	if (flag) {
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >>A >>B >>C >>D;
  
  if (A + B == C + D)
    cout << "Balanced" << endl;
  
  if (A + B > C + D) 
    cout << "Left" << endl;
  
  if (A + B < C + D)
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
   int y,m,d;
   char a,b;
   cin >> y >> a >> m >> b >> d;
   
   if(m <= 4){
       cout << "Heisei" << endl;
   }else{
       cout << "TBD" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<bool>checker(n+1,false);
    int ac=0,pe=0;
    vector<int>cnt(n+1,0);
    for(int i=0;i<m;i++){
        int prob;
        string status;
        cin>>prob>>status;
        if(status=="AC"){
            if(checker[prob]==false){
                pe+=cnt[prob];
                checker[prob]=true;
                ac++;
            }

        }else{
            cnt[prob]++;
        }
    }
    cout<<ac<<" "<<pe<<endl;
}


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

int main() {
	int N;
	cin >> N;
	if (N % 10 == 3) cout << "bon" << endl;
	else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>
#include <cctype>


using namespace std;

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

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    bool is_ac = true;
    string S;
    cin >> S;
    if(S[0] != 'A'){
        is_ac = false;
    }

    int cnt_C = 0;
    int ind_c;
    for(int i = 2; i < S.length()-1; i++){
        if(S[i] == 'C'){
            cnt_C++;
            ind_c = i;
        }
    }
    if(cnt_C != 1){
        is_ac = false;
    }

    bool all_lower = true;
    for(int i = 1; i < S.length(); i++){
        if(i != ind_c && !islower(S[i])){
            all_lower = false;
        }
    }

    if(!all_lower){
        is_ac = false;
    }

    if(is_ac){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
sum = 0
min_num = 10**10
num = [0]*3
for c in range(max(X, Y)+1):
    sum += C*c*2
    num[0] = c*2
    sum += A*max(0,X-c) + B*max(0, Y-c)
    num[1] = max(0, X-c)
    num[2] = max(0, Y-c)
    if min_num > sum:
        min_num = sum
    sum = 0
print(min_num)

Measured memory_bytes: 3064
def main():
    while True:
        n = int(input())
        if n == -1:
            break
        mp = [list(map(int, input().split())) for _ in range(5)]
        scores = list(map(int, input().split()))
    
        vec = ((1, 0), (0, -1), (-1, 0), (0, 1))
    
    
        def simulate():
            use_mp = [[mp[y][x] for x in range(5)] for y in range(5)]
            bonus = 1
            score = 0
            while True:
                delete_set = set()
                for y in range(5):
                    for length in range(5, 2, -1):
                        for left in range(5 - length + 1):
                            if use_mp[y][left] == 0:continue
                            if all([use_mp[y][left] == num for num in use_mp[y][left:left+length]]):
                                for add in range(length):
                                    delete_set.add((left + add, y))
    
                for x in range(5):
                    for length in range(5, 2, -1):
                        for top in range(5 - length + 1):
                            if use_mp[top][x] == 0:continue
                            if all([use_mp[top][x] == num for num in [use_mp[y][x] for y in range(top, top + length)]]):
                                for add in range(length):
                                    delete_set.add((x, top + add))
    
                if not delete_set:
                    break
    
                for x, y in delete_set:
                    score += scores[use_mp[y][x] - 1] * bonus
                    use_mp[y][x] = 0
    
                for x in range(5):
                    line = [use_mp[y][x] for y in range(5) if use_mp[y][x] != 0]
                    line = [0] * (5 - len(line)) + line
                    for y in range(5):
                        use_mp[y][x] = line[y]
    
                bonus += 1
    
            return score
    
        def search(x, y, n):
            ret = simulate()
            if n == 0:return ret
            for dx, dy in vec:
                nx, ny = x + dx, y + dy
                if 0 <= nx < 5 and 0 <= ny < 5:
                    mp[y][x], mp[ny][nx] = mp[ny][nx], mp[y][x]
                    ret = max(ret, search(nx, ny, n - 1))
                    mp[y][x], mp[ny][nx] = mp[ny][nx], mp[y][x]
            return ret
    
    
        ans = 0
        for y in range(5):
            for x in range(5):
                ans = max(ans, search(x, y, n))
    
        print(ans)
    
main()


Measured memory_bytes: 5624
main = interact (unlines.map solve.lines)

data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec deriving (Show, Eq, Ord, Enum)

data Era = Meiji | Taisho | Showa | Heisei deriving (Eq, Ord)

instance Show Era where
        show Meiji = "meiji"
        show Taisho = "taisho"
        show Showa = "showa"
        show Heisei = "heisei"

data DateTime = DT { year :: Int
                   , month :: Month
                   , day :: Int
                   } deriving (Show, Eq)

data Wareki = Wa { era :: Era
                 , waYear :: Int
                 , waMonth :: Month
                 , waDay :: Int
                 }

toDateTime :: Int -> Int -> Int -> DateTime
toDateTime y m d = DT y m' d
    where m' = toEnum (m-1)

instance Ord DateTime where
        compare (DT y1 m1 d1) (DT y2 m2 d2)
            | y1 < y2 = LT
            | y1 > y2 = GT
            | y1 == y2 = case compare m1 m2 of
                             LT -> LT
                             GT -> GT
                             EQ -> compare d1 d2

solve :: String -> String
solve = showWareki.toWareki.(\[y,m,d] -> toDateTime y m d).map read.words

meijiStart = DT 1868 Sep 8
taishoStart = DT 1912 Jul 30
showaStart = DT 1926 Dec 25
heiseiStart = DT 1989 Jan 8

toEra :: DateTime -> Maybe Era
toEra dt
    | dt < meijiStart  = Nothing
    | dt < taishoStart = Just Meiji
    | dt < showaStart  = Just Taisho
    | dt < heiseiStart = Just Showa
    | otherwise        = Just Heisei

toWareki :: DateTime -> Maybe Wareki
toWareki dt
    | dt < meijiStart = Nothing
    | dt < taishoStart = Just (Wa Meiji (year dt - year meijiStart + 1) (month dt) (day dt))
    | dt < showaStart  = Just (Wa Taisho (year dt - year taishoStart + 1) (month dt) (day dt))
    | dt < heiseiStart = Just (Wa Showa (year dt - year showaStart + 1) (month dt) (day dt))
    | otherwise        = Just (Wa Heisei (year dt - year heiseiStart + 1) (month dt) (day dt))

showWareki :: Maybe Wareki -> String
showWareki Nothing = "pre-meiji"
showWareki (Just wa) = unwords.map (\f -> f wa) $ [show.era, show.waYear, show.(+1).fromEnum.waMonth, show.waDay]


Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



bool comp(pii a, pii b) {
    if (a.F != b.F) return a.F < b.F;
    return a.S > b.S;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    // 愚直には, 右端から左端へ1以上のとこ全部1にする
    // 次2以上のとこ...
    
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pii> v(n);
    rep(i, n) {
        cin >> a[i];
        v[i] = pii(a[i], i);
    }
    if (a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    sort(all(v), comp);
    
    vector<int> x(n);
    ll cnt = 0;
    /*
    rep(i, n) {
        pii now = v[i];
        
        if (now.F == 0) continue;
        if (now.F != x[now.S - 1] + 1) {
            cout << -1 << endl;
            return 0;
        }
        cnt++;
        x[now.S] = now.F;
        rep(_, n) cout << x[_] << " "; cout << endl;
    }
     */
    rep(i, n) {
        if (a[i] == 0) continue;
        if (i && a[i] == a[i - 1] + 1) cnt++;
        else if (i && a[i] - a[i - 1] >= 2) {
            cout << -1 << endl;
            return 0;
        } else {
            cnt += a[i];
        }
        
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(int i = k; i < n; i++)  
#define repp(i,k,n) for(int i = k; i <= n; i++) 
#define per(i,k,n) for(int i = k; i >= n; i--)

#define int long long
#define all(a) a.begin(),a.end()       

#define pb push_back
typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<int,ii > iii; 
typedef vector<ii> vii;
typedef vector<char> vchar;
typedef vector<int> vi;
#define ff first
#define ss second

#define INF 1000000000
//#define mod 998244353
#define mod 1000000007
#define endl "\n"

   //=\/=\/=\/=\/=\/=\/=\/=\/=\/=\        Jai Hind Dosto        /=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\
  //=\/=\/=\/=\                    ̿̿ ̿̿ ̿̿ ̿'̿'\̵͇̿̿\з= ( ▀ ͜͞ʖ▀) =ε/̵͇̿̿/’̿’̿ ̿ ̿̿ ̿̿ ̿̿                             /=\/=\/=\/=\\
 //=\/=\/=\/=\                                                                               /=\/=\/=\/=\\
//=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\

ii a[105];
int dp[105][100005];

int fun(int n,int W){
    if(n==-1|| W<=0)return 0;
    if(dp[n][W]!=-1)return dp[n][W];
    dp[n][W]= fun(n-1,W);
    if(W-a[n].ff>=0)dp[n][W] = max(dp[n][W],a[n].ss + fun(n-1, W-a[n].ff));
    return dp[n][W];
}

void solve(){
    int n,W;
    cin >> n >> W;
    rep(i,0,n+1)rep(j,0,W+1)dp[i][j]=-1;
    rep(i,0,n)cin >> a[i].ff >> a[i].ss;
    cout << fun(n-1,W);

}

signed main(){

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//   cout << fixed;  cout << setprecision(9);
//   freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout);
    
  //  int test; cin >> test;  while(test--)
    solve();
}



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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> C(10, vector<int>(10));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> C[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
            }
        }
    }

    int res = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int a;
            cin >> a;
            if (a != 1 && a != -1) {
                res += C[a][1];
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256