akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int l,r;
		int[] sum = new int[N];
		for (int i=1;i<N;i++) {
			if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
				sum[i] = sum[i-1] +1;
			} else {
				sum[i] = sum[i-1];
			}
		}
		for (int i=0;i<Q;i++) {
			l = sc.nextInt();
			r = sc.nextInt();
			System.out.println(sum[r-1]-sum[l-1]);
		}
 
	}
 
}
 
class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
 
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
 
    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
 
    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
 
        return tokenizer.nextToken("\n");
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public double nextDouble() {
         return Double.parseDouble(next());
     }
 
    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }
 
    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 51228
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	int H, W, K;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &K);
	getchar_unlocked();

	int kara[300] = {};
	int hajimete = 500;
	int k = 0;
	int kotae[300][300];
	rep(i, H) {
		int aru = 0;
		k++;
		rep(j, W) {
			if (getchar_unlocked() == '#') {
				if (aru == 0) aru = 1;
				else k++;
			}
			kotae[i][j] = k;
		}

		getchar_unlocked();
		if (!aru) {
			kara[i] = 1;
			k--;
			if (hajimete < i) {
				rep(j, W) kotae[i][j] = kotae[i - 1][j];
			}
		}
		if (aru && hajimete == 500) hajimete = i;
	}

	for (int i = H - 1; i >= 0; i--) {
		if (kara[i] && hajimete > i) {
			rep(j, W) kotae[i][j] = kotae[i + 1][j];
		}
	}

	rep(i, H) rep(j, W) putint(kotae[i][j]);

	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll a, b, c;
  cin>>a>>b>>c;
  if(a%2==1 || b%2==1 || c%2==1){
    cout<<0<<endl;
    return 0;
  }
  if(a==b && b==c){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=1; i<31; i++){
    ll x=(b+c)/2, y=(c+a)/2, z=(a+b)/2;
    a=x, b=y, c=z;
    if(a%2==1 || b%2==1 || c%2==1){
      cout<<i<<endl;
      return 0;
    }
  }
  assert(0);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
  
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
 
typedef long long int64;
const int INF = 1 << 30;

string S, tmp = "JOI";
int Jsum[1000000], Isum[1000000];

int main(){

  cin >> S;
  Jsum[0] = S[0] == 'J';
  Isum[S.length() - 1] = S[S.length() - 1] == 'I';

  for(int i = 1; i < S.length(); i++){
    if(S[i] == 'J') Jsum[i] += Jsum[i - 1] + 1;
    else Jsum[i] = 0;
  }
  for(int i = S.length() - 2; i >= 0; i--){
    if(S[i] == 'I') Isum[i] = Isum[i + 1] + 1;
    else Isum[i] = 0;
  }
  int Osum = 0, ret = 0;
  for(int i = 1; i < S.length() - 1; i++){
    if(S[i] == 'O'){
      Osum += S[i] == 'O';

      if(Jsum[i - Osum] < Osum || Isum[i + 1] < Osum) continue;
      ret = max( ret, Osum);
    } else {
      Osum = 0;
    }
  }
  cout << ret << endl;
}

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

int main() {
	int Array[1000][2];
	int i;
	for (i = 0;; i++){
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0)
			break;
		Array[i][0] = a;
		Array[i][1] = b;
	}
	for (int n = 0; n < i; n++)
	{
		for (int k = 0; k < Array[n][0]; k++) {
			for (int i = 0; i < Array[n][1]; i++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3052
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n;

	cin>>n;

	vi p(n), ans;

	vPi pa, pa2;

	rep(i, n){
		cin>>p[i];
		pa.push_back(mp(p[i], i+1));
	}
	sort(all(pa));

	/*rep(i, n){
		cout<<pa[i].first<<" "<<pa[i].second<<endl;
	}
	cout<<endl;*/

	int count=1;
	rep(i, n-1){
		if(pa[i].second>pa[i+1].second){
			//pa2.push_back(mp(front, pa[i].second));
			ans.push_back(count);
			count=1;
		}else{
			count++;
		}
	}
	ans.push_back(count);

	/*rep(i, ans.size()){
		cout<<ans[i]<<endl;
	}*/
	sort(all(ans));

	cout<<n-ans[ans.size()-1]<<endl;
}


Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,a,b;
	cin>>a>>b;
	k=__gcd(a,b);
	ll an=(a*b)/k;
	cout<<an;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            if (s.equals("AC")) {
                ac++;
            } else if (s.equals("WA")) {
                wa++;
            } else if (s.equals("TLE")) {
                tle++;
            } else {
                re++;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
}

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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

/**
 * @title Graph template
 * @docs graph_template.md
 */
template <typename Cost = int> class Edge{
public:
  int from,to;
  Cost cost;
  Edge() {}
  Edge(int to, Cost cost): to(to), cost(cost){}
  Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){}
};

template <typename T> using Graph = std::vector<std::vector<Edge<T>>>;
template <typename T> using Tree = std::vector<std::vector<Edge<T>>>;

template <typename T, typename C> void add_edge(C &g, int from, int to, T w = 1){
  g[from].emplace_back(from, to, w);
}

template <typename T, typename C> void add_undirected(C &g, int a, int b, T w = 1){
  add_edge<T, C>(g, a, b, w);
  add_edge<T, C>(g, b, a, w);
}

/**
 * @title 0-1 BFS
 * @docs bfs_0_1.md
 */
std::vector<std::optional<int>> bfs_0_1(const Graph<int> &g, const std::vector<int> &src){
  int n = g.size();
  std::vector<std::optional<int>> ret(n);
  std::vector<bool> visited(n);

  for(auto i : src) ret[i] = 0;
  std::deque<int> dq(src.begin(), src.end());

  while(not dq.empty()){
    int cur = dq.front(); dq.pop_front();

    if(visited[cur]) continue;
    visited[cur] = true;

    for(auto &e : g[cur]){
      if(not ret[e.to] or *ret[e.to] > *ret[e.from] + e.cost){
        ret[e.to] = *ret[e.from] + e.cost;
        
        if(e.cost == 0) dq.push_front(e.to);
        else dq.push_back(e.to);
      }
    }
  }
  
  return ret;
}





namespace solver{
  const int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  
  void solve(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    
    int H, W; std::cin >> H >> W;
    int Ch, Cw; std::cin >> Ch >> Cw;
    int Dh, Dw; std::cin >> Dh >> Dw;

    std::vector<std::string> S(H);
    for(int i = 0; i < H; ++i) std::cin >> S[i];

    Graph<int> g(H * W);
    std::vector<std::vector<int>> index(H, std::vector<int>(W));

    {
      int k = 0;
      for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
          index[i][j] = k;
          ++k;
        }
      }
    }

    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
        for(auto d : dir){
          int x = i + d[0];
          int y = j + d[1];

          if(x < 0 or x >= H or y < 0 or y >= W or S[x][y] == '#') continue;
          add_edge(g, index[i][j], index[x][y], 0);
        }

        for(int dx = -2; dx <= 2; ++dx){
          for(int dy = -2; dy <= 2; ++dy){
            int x = i + dx;
            int y = j + dy;

            if(x < 0 or x >= H or y < 0 or y >= W or S[x][y] == '#') continue;
            //dump(x, y);
            add_edge(g, index[i][j], index[x][y], 1);
          }
        }
      }
    }

    auto res = bfs_0_1(g, {index[Ch-1][Cw-1]});

    auto ans = res[index[Dh-1][Dw-1]];

    std::cout << ans.value_or(-1) << "\n";
  }
}

int main(){
  solver::solve();
  return 0;
}


Measured memory_bytes: 287984
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int c[55][55],seen[55][55];
int dfs(int x,int y){
  int i,j;
  seen[x][y]=1;
  for(i=x-1;i<=x+1;i++){
    for(j=y-1;j<=y+1;j++){
      if(i==x && j==y){
        continue;
      }
      if(seen[i][j]==0 && c[i][j]==1){
        dfs(i,j);
      }
    }
  }
};
int main(){
  int w,h,i,j,z;
  while(1){
    z=0;
    scanf("%d %d\n",&h,&w);
    if(w==0 && h==0){
      break;
    }
    for(i=0;i<=w+1;i++){
      for(j=0;j<=h+1;j++){
        c[i][j]=0;
        seen[i][j]=0;
      }
    }
    for(i=1;i<=w;i++){
      for(j=1;j<=h;j++){
        scanf("%d",&c[i][j]);
      }
      scanf("\n");
    }
    for(i=1;i<=w;i++){
      for(j=1;j<=h;j++){
        if(seen[i][j]==0 && c[i][j]==1){
          dfs(i,j);
          z++;
        }
      }
    }
    printf("%d\n",z);
  }
  return 0;
}


Measured memory_bytes: 3380
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_tasai(S):
    appare_set = set([])
    for s in S:
        if s in appare_set:
            return False
        appare_set.add(s)
    return True

table = {}
def comb(n, r):
    a = 1L
    b = 1L
    for i in range(r):
        a *= n - i
        b *= r - i
    return a/b

##    if (n, r) in table:
##        return table[(n, r)]
##    if n == r:
##        table[(n, r)] = 1L
##        return 1L
##    if r == 0:
##        table[(n, r)] = 1L
##        return 1L
##    if n == 0:
##        return 0L
##    table[(n, r)] = comb(n-1, r-1)+ comb(n-1, r)
##    return table[(n, r)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    initial_dict = {}
    initial_dict["M"] = 0
    initial_dict["A"] = 0
    initial_dict["R"] = 0
    initial_dict["C"] = 0
    initial_dict["H"] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        if input_raw[0][0] in initial_dict:
            initial_dict[input_raw[0][0]] += 1
    M = 0
    for s in initial_dict:
        M += initial_dict[s]
    remove_num = 0L
    for s in initial_dict:
        remove_num += comb(initial_dict[s], 2) * (M - initial_dict[s])
        remove_num += comb(initial_dict[s], 3)
    print comb(M, 3) - remove_num


if __name__ == '__main__':
    main()


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

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define MOD 1000000007

using namespace std;

lli factorial(lli n){
	lli ans = 1;
	while(n>1){
		ans *= n;
		ans %= MOD;
		n--;
	}
	return ans;
}


int main(){

	lli n;
	string s;
	cin>>n>>s;

	n *= 2;

	vector<bool> is_right(n);
	REP(i,0,n){
		if(i%2 == 0 && s[i] == 'W')is_right[i] = true;
		if(i%2==1 && s[i] == 'B')is_right[i] = true;
	}

	lli ans = 1;
	lli left_sum = 0;

	REP(i,0,n){
		if(is_right[i]){
			if(left_sum == 0){
				cout<<0<<endl;
				return 0;
			}
			ans *= left_sum;
			ans %= MOD;
			left_sum--;
		}else{
			left_sum++;
		}
	}
	if(left_sum)cout<<0<<endl;
	else cout<<ans*factorial(n/2)%MOD<<endl;

	return 0;



}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,a,b,k;

int main(){

    cin>>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;i++){
        int x;

        cin>>h[i];
    }
    sort(h.begin(),h.end());
    long long sm=0;
    for(int i=0;i<n-k;i++)sm+=h[i];
    cout<<sm;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<char,char> P;
typedef pair<int,P> PP;

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

void mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int N,Q;
string S;
vector<P> vec;

int solve(int a) {
    for(int i = 0;i < Q;i++) {
        if(vec.at(i).first == S.at(a)) {
            if(vec.at(i).second == 'L') {
                a--;
            }
            else {
                a++;
            }
        }
    }
    return a;
}

int main() {
    cin >> N >> Q;
    vec.assign(Q,P(0,0));
    cin >> S;
    S.insert(S.begin(),'a');
    S += 'a';
    for(int i = 0;i < Q;i++) {
        cin >> vec.at(i).first >> vec.at(i).second;
    }
    int ret1,ret2;
    int left = 0;
    int right = N + 2;
    int mid;
    while(right - left > 1) {
        mid = (left + right) / 2;
        if(solve(mid) == 0) {
            left = mid;
        }
        else {
            right = mid;
        }
    }
    ret1 = left;
    left = 0;
    right = N + 2;
    while(right - left > 1) {
        mid = (left + right) / 2;
        if(solve(mid) == N + 1) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    ret2 = right;
    cout << ret2 - ret1 - 1 << endl;
}

Measured memory_bytes: 4028
function main()
  
  (H,W) = map(x -> parse(Int,x), split(readline()))
  
  S = ["" for i in 1:H,j in 1:W]
  nums = zeros(Int,H,W)
  
  for i in 1:H
    S[i,:] = split(chomp(readline()),"")
  end
  
  for i in 1:H,j in 1:W
    
    if S[i,j] == "#"
      
      if i-1 > 0
        nums[i-1,j] +=1
      end
      if i-1 > 0 && j+1 <= W
        nums[i-1,j+1] +=1
      end
      if j+1 <= W
        nums[i,j+1] +=1
      end
      if i+1 <= H && j+1 <= W
        nums[i+1,j+1] +=1
      end
      if i+1 <= H
        nums[i+1,j] +=1
      end
      if i+1 <= H && j-1 > 0
        nums[i+1,j-1] +=1
      end
      if j-1 > 0
        nums[i,j-1] +=1
      end
      if i-1 > 0 && j-1 > 0
        nums[i-1,j-1] +=1
      end
      
    end
    
  end
  
  for i in 1:H,j in 1:W
    
    if S[i,j] == "#"
      print("#")
    else
      print(nums[i,j])
    end
    
    if j == W
      println()
    end
    
  end
  
end

main()

Measured memory_bytes: 126632
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const ll inf = 4e18 +123;
//const int inf = 1e9 + 123;
const ll MAX = 1e6;

ll a,b,c,d,n;
map<ll,ll> m;
ll dfs(ll n)
{
	if(m.find(n)!=m.end())
		return m.find(n)->second;
	ll ret = inf;
	if(d<=(inf/n))
		ret = d*n;
	ret = min(ret, dfs(n/5) + (n%5)*d+c);
	ret = min(ret, dfs(n/3) + (n%3)*d+b);
	ret = min(ret, dfs(n/2) + (n%2)*d+a);

	if(n%5!=0)
	ret = min(ret, dfs(n/5+1) + (5-n%5)*d+c);
	if(n%3!=0)
	ret = min(ret, dfs(n/3+1) + (3-n%3)*d+b);
	if(n%2!=0)
	ret = min(ret, dfs(n/2+1) + (2-n%2)*d+a);
	m.insert({n, ret});
	return ret;
}
void solve()
{
	cin >> n >> a >> b >> c >> d;
	m.clear();
	m.insert({0, 0});
	m.insert({1, d});
	cout << dfs(n) << endl;
}
int main()
{    
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	while(t--)
	solve();
}

Measured memory_bytes: 4340
#include <iostream>

#define SIZE 20

int N, M;
int a[SIZE][SIZE], b[SIZE], c;

void solve() {
    int  ans = 0;
    for (int i=0; i<N; ++i) {
        long total = 0;
        for (int j=0; j<M; ++j) {
            total += a[i][j]*b[j];
        }
        if (total + c > 0) ++ans;
    }
    std::cout << ans << std::endl;
}

int main() {
    std::cin >> N >> M >> c;
    for (int i=0; i<M; ++i) std::cin >> b[i];
    for (int i=0; i<N; ++i) {
        for (int j=0; j<M; ++j) std::cin >> a[i][j];
    }
    solve();
    return 0;
}

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

int main(void){
  int n;
  cin >> n;
  string s[n];
  for(int i = 0; i < n; i++) cin >> s[i];
  bool flag = true;
  for(int i = 0; i < n - 1; i++){
    if(s[i][s[i].length() - 1] != s[i + 1][0]){
      flag = false;
      break;
    }
  }
  int c = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(s[i] == s[j]) c++;
    }
    if(c != 1){
      flag = false;
      break;
    }
    c = 0;
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int[] a = new int[n];

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

    Arrays.sort(a);

    int b = a[n / 2];

    long res = 0;
    for (int i = 0; i < n; i++) {
      res += Math.abs(a[i] - b);
    }

    os.println(res);
  }

  private static class Scanner {

    private final InputStream is;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    Scanner(InputStream is) {
      this.is = is;
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = is.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) {
        return buffer[ptr++];
      } else {
        return -1;
      }
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
        ptr++;
      }
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
        throw new NumberFormatException();
      }
      return (int) nl;
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}


Measured memory_bytes: 25076
#include <bits/stdc++.h>
using namespace std;
int main()
{
  vector <int> a(5);
  for (int i = 0; i < 5; i++)
  {
    cin >> a[i];
  }
  int k; cin >> k;
  sort(a.begin(),a.end());
  if (a[4]-a[0] > k)
    cout << ":(";
  else
     cout << "Yay!";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  int R; std::cin >> R;
  if ( R < 1200 ) std::cout << "ABC" << std::endl;
  else if ( R < 2800 ) std::cout << "ARC" << std::endl;
  else std::cout << "AGC" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,i;
    scanf("%d",&n);
    int num[n];
    for(i = 0;i<n;i++){
        scanf("%d",&num[i]);
    }
    for(i = 1;i<=n;i++){
        if(i != 1) printf(" ");
        printf("%d",num[n - i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
a = input()
c = 0
tmp = a[0]
for i in range(len(a)):
  if tmp == a[i]:
    c += 1
    
if a[0] == a[1] or a[0] == a[2] or a[0] == a[3]:
  if a[1] == a[2] or a[1] == a[3] or a[2] == a[3]:
    if c == 2:
      print("Yes")
    else:print("No")
  else:print("No")
else:print("No")

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

int main(void){
	int a, b, c, d;
	cin >> a;
	d = a%10;
	a /= 10;
	c = a%10;
	a /= 10;
	b = a%10;
	a /= 10;
	if(a+b+c+d==7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	else if(a+b+c-d==7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if(a+b-c+d==7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	else if(a+b-c-d==7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	else if(a-b+c+d==7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	else if(a-b+c-d==7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	else if(a-b-c+d==7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	else if(a-b-c-d==7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
}

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

int main(){

    string s;
    cin >> s;
 
    int a = s[0]-'0', b = s[1]-'0', c = s[2]-'0', d = s[3]-'0';
 
    if(a+b+c+d == 7)cout << a <<'+'<< b <<'+'<< c <<'+'<< d<< "=7" << endl;
    else if(a+b+c-d == 7)cout << a <<'+'<< b <<'+'<< c <<'-'<< d<< "=7" << endl;
    else if(a+b-c-d == 7)cout << a <<'+'<< b <<'-'<< c <<'-'<< d<< "=7" << endl;
    else if(a-b-c-d == 7)cout << a <<'-'<< b <<'-'<< c <<'-'<< d<< "=7" << endl;
    else if(a-b+c+d == 7)cout << a <<'-'<< b <<'+'<< c <<'+'<< d<< "=7" << endl;
    else if(a-b+c-d == 7)cout << a <<'-'<< b <<'+'<< c <<'-'<< d<< "=7" << endl;
    else if(a-b-c+d == 7)cout << a <<'-'<< b <<'-'<< c <<'+'<< d<< "=7" << endl;
    else if(a+b-c+d == 7)cout << a <<'+'<< b <<'-'<< c <<'+'<< d<< "=7" << endl;
 
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        string N;
        cin >> N;

        string ans = "";

        rep(i, N.size())
        {
                if (N[i] == '0')
                {
                        ans += '0';
                }
                else if (N[i] == '1')
                {
                        ans += '1';
                }
                else
                {
                        if (ans.size() > 0)
                        {
                                ans.pop_back();
                        }
                }
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
// 2011/01/10 Tazoe

#include <iostream>
using namespace std;

void swp(int abt[20][3], int i, int j)
{
	abt[19][0] = abt[i][0];  abt[19][1] = abt[i][1];  abt[19][2] = abt[i][2];
	abt[i][0] = abt[j][0];  abt[i][1] = abt[j][1];  abt[i][2] = abt[j][2];
	abt[j][0] = abt[19][0];  abt[j][1] = abt[19][1];  abt[j][2] = abt[19][2];
}

void DFS(int abt[20][3], int N, int a, int t, int& t_max)
{
	if(t_max<t)
		t_max = t;

	for(int i=0; i<N-1; i++)
		if(abt[i][0]==a)
			DFS(abt, N, abt[i][1], t+abt[i][2], t_max);
}

int main()
{
	while(true){
		int N;
		cin >> N;
		if(N==0)
			break;

		int abt[20][3];
		for(int i=0; i<N-1; i++)
			cin >> abt[i][0] >> abt [i][1] >> abt[i][2];

		int que[20] = {1};
		int quh = 0;
		int qut = 1;
		for(int i=0; i<N-1; i++){
			bool flg = false;
			for(int j=i; j<N-1; j++){
				if(abt[j][0]!=que[quh]&&abt[j][1]!=que[quh])
					continue;
				if(abt[j][1]==que[quh]){
					int tmp = abt[j][0];
					abt[j][0] = abt[j][1];
					abt[j][1] = tmp;
				}
				swp(abt, i, j);
				que[qut++] = abt[i][1];
				flg = true;
				break;
			}
			if(!flg){
				quh++;
				i--;
			}
		}

		for(int i=0; i<N-1; i++){
			bool flg = false;
			for(int j=i+1; j<N-1; j++)
				if(abt[i][1]==abt[j][0]){
					flg = true;
					break;
				}
			if(flg)
				abt[i][2] *= 2;
			else
				abt[i][2] = 0;
		}

		int t_max = -1;
		DFS(abt, N, 1, 0, t_max);

		int sum = 0;
		for(int i=0; i<N-1; i++)
			sum += abt[i][2];
		sum -= t_max/2;

		cout << sum << endl;
	}

	return 0;
}

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

int main() {
  int K, S, res = 0;
  cin >> K >> S;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) { 
        if (S - x - y >= 0 && S - x - y <= K) res++;
    }
  }
  cout << res << endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define mp make_pair
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define scfl(xx) scanf("%I64d",&xx)
#define All(a) a.begin(), a.end()
#define debug(i,r) cout<<"i= "<<(int)i<<" r="<<(lli)r<<endl;
#define fil(dp) memset(dp,-1,sizeof dp);
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
const double PI = 4*atan(1);
const int MX = 100000;

typedef long long ll;
typedef long long int  lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, ll> ii;
typedef pair<int, int> pi;
typedef long double ld;

int t[300005];
char tab[1001][1001];

bool verify(int i,int j,int n,int m)
{
if(i>=0 && i<n && j>=0 && j<m)return 1;
else return 0;
}
int main()
{

    int n,m;
    cin>>n>>m;
    rep(i,n)
    {
    rep(j,m)cin>>tab[i][j];
    }
    int res=0;
    queue<pi> v;
    rep(i,n)
    {
    rep(j,m){if(tab[i][j]=='#')v.push(mp(i,j));}
    }
    bool flag =0;
    int h=v.size();
    while(h)
    {
    rep(j,h)
    {
    pi a=v.front();v.pop();
    if(verify(a.first-1,a.second,n,m) && tab[a.first-1][a.second]=='.'){tab[a.first-1][a.second]='#';v.push(mp(a.first-1,a.second));}
    if(verify(a.first,a.second-1,n,m) && tab[a.first][a.second-1]=='.'){tab[a.first][a.second-1]='#';v.push(mp(a.first,a.second-1));}
    if(verify(a.first+1,a.second,n,m) && tab[a.first+1][a.second]=='.'){tab[a.first+1][a.second]='#';v.push(mp(a.first+1,a.second));}
    if(verify(a.first,a.second+1,n,m) && tab[a.first][a.second+1]=='.'){tab[a.first][a.second+1]='#';v.push(mp(a.first,a.second+1));}
    }
    res++;
     h=v.size();
     //if(flag)res++;
     //flag=0;
    }

     cout<<max(0,res-1)<<endl;

    return 0;
}



Measured memory_bytes: 9360
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
using P = pair<int, int>;

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

    while (N > 0)
    {
        N -= 1000;
    }

    N *= -1;
    cout << N << endl;

    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  bool flag=false;
  for(int i=0;i<26;i++){
    for(int j=0;j<15;j++){
      if(4*i+7*j==N){
        flag=true;
        break;
      }
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

vector<int> func(vector<int> X) {
  int N = X.size();
  sort(X.begin(), X.end());
  return { X.at(N/2-1), X.at(N/2) };
}

int main() {
  int N; cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++) cin >> X.at(i);
  vector<int> median = func(X);
  for (int i = 0; i < N; i++) {
    if (X.at(i) <= median.at(0)) cout << median.at(1) << endl;
    else cout << median.at(0) << endl;
  }
}

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

char tolower(char ch){
 if( 'A'<=ch && ch<='Z'){
 return ch-'A'+'a';
 }else{
 return ch;
 }
}

int main(){
int count=0;
 string W;
 cin>>W;
 string str;
 while(1){
 cin>>str;
 if(str=="END_OF_TEXT")break;
 for(int i=0;i<(int)str.size();i++){
 str[i]=tolower(str[i]);
 }
 if(str==W){
 count++;
}
}
cout<<count<<endl;
 return 0;

}


Measured memory_bytes: 3140
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int, int> a, pair<int, int> b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c - a + b < 0)cout << 0 << endl;
	else {
		cout << c - a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1LL)
//0=r 1=s 2=p
int winhand(int h){
  return ( (2+h) % 3);
}
int main(){
  int n, k; vector<pair<int,int>> pt(3); string t;
  cin >> n >> k >> pt[0].first >> pt[1].first >> pt[2].first >> t;
  FOR(i,0,3) pt[i].second = i;
  //sort(pt.begin(),pt.end());
  //reverse(pt.begin(), pt.end());
  ll ans = 0;
  vector<int> myh(n,-1);
  vector<vector<int>> tbl(k);
  FOR(i,0,n){
    int h_;
    if(t[i]=='r') h_ = 0;
    if(t[i]=='s') h_ = 1;
    if(t[i]=='p') h_ = 2;
    h_ = winhand(h_);
    myh[i] = h_;
    tbl[i%k].push_back(h_);
  }
  FOR(i,0,k){
    int n_ = tbl[i].size();
    vector<vector<ll>> dp(max(n_,1), vector<ll>(3,0));
    if(n_!=0) dp[0][tbl[i][0]] = pt[tbl[i][0]].first;
    FOR(j,1,n_){
      FOR(l,0,3){
        if(l==tbl[i][j]){
          //if(l==tbl[i][j-1]) dp[j][l] = max(dp[j-1][(l+1)%3], dp[j-1][(l+2)%3] )+pt[l].first;
          //else  dp[j][l] = max(dp[j-1][(l+1)%3], dp[j-1][(l+2)%3] )+pt[l].first; 
          dp[j][l] = max(dp[j-1][(l+1)%3], dp[j-1][(l+2)%3] )+pt[l].first; 
        }else{
          dp[j][l] = max(dp[j-1][(l+1)%3], dp[j-1][(l+2)%3] );
        }
      }
    }
    if(n_!=0)ans += max({dp[n_-1][0], dp[n_-1][1], dp[n_-1][2] });//cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 1;
//---------------------------------//

int n, cnt;
int v[112345];

int main() {
	cin >> n;
	REP(i, n) scanf("%d", v + i);
	
	map<int, int> mm[2];
	REP(i, n) mm[i & 1][v[i]]++;
	
	pii dat[3][3];
	
	REP(i, 2) {
		vector<pii> tmp;
		for (map<int, int>::iterator it = mm[i].begin(); it != mm[i].end(); it++)
			tmp.push_back(pii(it->se, it->fi));
		
		sort(tmp.begin(), tmp.end(), greater<pii>());
		
		REP(j, 3) if (j < tmp.size()) dat[i][j] = tmp[j];
	}
	
	int ans = INF;
	REP(i, 3) REP(j, 3) {
		if (i >= mm[0].size()) continue;
		if (j >= mm[1].size()) continue;
		
		if (dat[0][i].se == dat[1][j].se) chmin(ans, n - max(dat[0][i].fi, dat[1][j].fi));
		else chmin(ans, n - dat[0][i].fi - dat[1][j].fi);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll x;
    cin>>x;
    for(ll i=1;;i++){
        if(i*(i+1)/2>=x){
            cout<<i<<endl;
            break;
        }   
    }
    return 0;
}

Measured memory_bytes: 256
s = str(input())
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 38384
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
int main() {
	int n, x, t; read(n), read(x), read(t);
	cout << (n + x - 1) / x * t << endl;
	return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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(int argc, const char * argv[]) {
    
   
    
    string s; cin >> s;
    
    ll n = s.size();
    ll LocR;
    ll LocL;
    ll sumR = 0;
    ll sumL = 0;
    vector<ll> Ans(n,0);
    
    
    
    for (int i = 0; i < n; i++) {
        //find a part of RL
        if(s[i]=='R' && s[i+1]=='L') {
            LocR = i;
            LocL = i+ 1;
            //count the number of R at the left  side of RL := sumR
            while(s[LocR] == 'R' && 0 <= LocR) {
                sumR++;
                LocR--;
            }
            //count the number of L at the right side of RL := sumL
            while(s[LocL] == 'L' && LocL < n) {
                sumL++;
                LocL++;
            }
            
            
            Ans[i]     = sumR/2 + sumL/2 + sumR%2;
            Ans[i + 1] = sumR/2 + sumL/2 + sumL%2;
            
            sumR = 0;
            sumL = 0;
        }
    }
    
    
    //Answer
    for (int i = 0; i < n; i++) {
        if(i>0) cout << " ";
        cout << Ans[i];
    }
    cout << endl;
        
    
}


Measured memory_bytes: 1408
def LI():return list(map(int,input().split()))
n,m=LI()
h=LI()
edge=[[] for i in range(n)]
for i in range(m):
  a,b=LI()
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
ans=0
for i in range(n):
  if all([h[i]>h[j] for j in edge[i]]):
    ans+=1
print(ans)

Measured memory_bytes: 29864
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int count = scan.nextInt();

        List<String> inputs = new ArrayList<>();
        for(int i = 0; i <= count; i++) {
            String value = scan.nextLine();
            String[] values = value.split(" ");
            if(value.startsWith("2")) {
                inputs.remove(inputs.size()-1);
            } else if(value.startsWith("0")) {
                inputs.add(values[1]);
            } else if(value.startsWith("1")) {
                System.out.println(inputs.get(Integer.parseInt(values[1])));
            }
        }

        scan.close();
    }
}


Measured memory_bytes: 200952
#include<iostream>
#include<string>
using namespace std;
int sum_of_days(int m, int d){
  int sum = 0;
  int mon[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,};
  for(int i = 0; i < m; i++) sum += mon[i];
  return sum + d - 1;
}
string what_day(int s){
  string day[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
  return day[s % 7];
}
int main(){
  int m, d;
  while(cin >> m >> d, !(m==0 && d==0)){
    cout << what_day(sum_of_days(m, d)) << endl;
  }
}

Measured memory_bytes: 3140
# 解説を読んでからrun-length
# TLEだったので見て修正

import bisect

S = input()
RL = []
for i in range(len(S) - 1):
    if S[i] == 'R' and S[i + 1] == 'L':
        RL.append(i)


ans = [0] * len(S)
for i in range(len(S)):
    idx = bisect.bisect_left(RL, i)
    if S[i] == 'L':  # Lだと見つかった場所の←へ行く
        mark = RL[idx - 1]
    else: # Rだと見つかった場所の→へ行く
        mark = RL[idx]

    if (i - mark) % 2 == 0: # Rの位置から偶数離れていればRの方
        ans[mark] += 1
    else: # 奇数離れていればLの位置へ行く
        ans[mark + 1] += 1

print(*ans)

Measured memory_bytes: 51036
#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;
      }
      else if(a + b  > c + d){
        cout << "Left" << endl;
     }
    else {
        cout << "Right" << endl;
     }
  }

Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

int limit;
int arr[41][2], c[41], Ma, Mb;
int dp[41][401][401];

int rec(int ind, int A, int B)
{
	if(ind == limit)
	{
		int gg = __gcd(A, B);
		if(gg == 0)
			return 100000;
		A /= gg;
		B /= gg;
		if(A == Ma && B == Mb)
			return 0;
		return 100000;
	}

	int &ret = dp[ind][A][B];
	if(ret != -1)
		return ret;
	ret = 100000;

	ret = min(ret, rec(ind + 1, A, B));
	ret = min(ret, c[ind] + rec(ind + 1, A + arr[ind][0], B + arr[ind][1]));
	return ret;
}

int main()
{
	int i, j;

	mem(dp, -1);

	si(limit);	si(Ma);	si(Mb);
	int gg = __gcd(Ma, Mb);
	Ma = Ma / gg;
	Mb /= gg;

	fl(i,0,limit)
	{
		si(arr[i][0]);	si(arr[i][1]);	si(c[i]);
	}

	int ans = rec(0,0,0);
	if(ans >= 100000)
		ans = -1;

	printf("%d\n", ans);


	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main()
{
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int cnt = 0;
    int k = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '-') {
            cnt++;
            k = i;
        }
    }
    if (cnt == 1 && k == a && a + b + 1 == s.size()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))

s = int(input())
YY = s // 100
MM = s % 100
if 1 <= YY <= 12 and 1 <= MM <= 12:
    print("AMBIGUOUS")
elif 0 < MM <= 12:
    print("YYMM")
elif 0 < YY <= 12:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3060