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

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;

	cin >> A >> B;

	cout << (max(A, B) <= 8 ? "Yay!" : ":(") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int x;
  cin>>x;
  cout << !x << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>

#include <algorithm>
using namespace std;
main()
{  int start1, end1 ,start2, end2;
      cin>>start1>>end1>>start2>>end2;

      if(start1<=start2){
      if(end1-start2>0){
      if(end1-end2>0){ cout<<end2-start2;}
        else {cout<<end1-start2;}
      }
   else{cout<<"0";}
 }
 
 else {
    if(end2-start1>0){
      if(end2-end1>0){ cout<<end1-start1;}
        else {cout<<end2-start1;}
      }
   else{cout<<"0";}
 }


   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
string S;

void solve() {
    //cout.precision(10);
    cin >> N >> S;
    S.push_back('#');
    int ans = 0;
    for(int i = 0; i + 1 < S.size(); i++) {
        if(S[i] != S[i+1]) ans++;
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
int main(){
	for(;;){
		string words,sorce;
		getline(cin,words);
		if(words == ""){break;}
		for(int i=0; i<words.size(); i++){
			if(words[i] == '@'){
				for(int j=0; j<((int)words[i+1])-48; j++){
					sorce+=words[i+2];
				}
				i+=2;
			}
			else{sorce+=words[i];}
		}
		cout<<sorce<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
using namespace std;
string lcs(string s, string t)
{
    int n = s.length();
    int m = t.length();

    int dp[n + 1][m + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    string ans = "";
    int i = n, j = m;
    while (i > 0 && j > 0)
    {
        if (s[i-1] == t[j-1])
        {
            ans += s[i-1];
            i--;
            j--;
        }
        else if (dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t);
    return 0;
}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define fore_(i, s, e) for(int i = s; i > e; i--)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FAIL cout << -1 << endl; return 0
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

ll dp[1001][1001];
ll cota = 1e9 + 7;
ll h, w; char c;

ll solve(int x, int y) {
    if(dp[y][x] == -1) return 0;
    if(dp[y][x] != -2) return dp[y][x];
    if(x == w - 1 && y == h - 1) return 1;

    ll ret = 0;

    if(x != w - 1)
        ret += solve(x + 1, y) % cota;
    if(y != h - 1)
        ret += solve(x, y + 1) % cota;

    dp[y][x] = ret % cota;

    return ret;
}

int main() {
    FIN;
    cin >> h >> w;
    fore(i, 0, h) 
        fore(j, 0, w) {
            cin >> c;
            if(c == '.') dp[i][j] = -2;
            else dp[i][j] = -1;
        }
    
    cout << solve(0, 0) % cota << endl;
    return 0;
}


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

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

    vector<int> v[N];

    REP(i,M){
        int a,b;
        cin >> a >> b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }

    bool visited[N] = {false};

    queue<int> queue;
    queue.push(0);
    visited[0] = true;

    int sign[N];
    sign[0] = 0;

    while(!queue.empty()){
        int x;
        x = queue.front();
        queue.pop();
        for(int y:v[x]){
            if(!visited[y]){
                queue.push(y);
                visited[y] = true;
                sign[y] = x;
            }
        }
    }
    bool flag = true;
    REP(i, N){
        if(!visited[i]){
            flag = false;
            break;
        }
    }

    if(flag){
        cout << "Yes" << "\n";
        for(int i = 1; i < N; i++){
            cout << sign[i]+1 << "\n";
        }
    }
    else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 10504
#include<iostream>

using namespace std;

int main(){
    int n;
    char c;
    bool find = false;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> c;
        if(c=='Y'){
            find = true;
            break;
        }
    }

    cout << (find?"Four":"Three") << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int H = cin.nextInt();
        int W = cin.nextInt();

        string[] C = new string[H];
        for (int i = 0; i < H; i++)
        {
            C[i] = cin.next();
        }

        for (int i = 0; i < 2 * H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                Console.Write(C[i / 2][j]);
            }
            Console.WriteLine();
        }

    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2776
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    boolean flag1 =  false;
    int num;
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      num = sc.nextInt();
      if(num%2==0){
        array[count] = num;
        count++;
      }
    }



    for(int i=0; i<count; i++){
      if((array[i]%3!=0)&&(array[i]%5!=0)){
        System.out.println("DENIED");
        return;
      }
    }

    System.out.println("APPROVED");




  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main()
{
    ll X, K, D, ans;
    cin >> X >> K >> D;
    if((abs(X) - 1) / D + 1 > K){
        ans = abs(X) - D * K;
    }
    else{
        ll count = abs(X) / D;
        ll x = abs(X) - D * count;
        K -= count;
        if(K % 2 == 0) ans = x;
        else ans = abs(D - x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 5;
const long long mod = 1e9 + 7;
long long dp[MAX_N][MAX_N];
long long calc[MAX_N][MAX_N];
int n, a, b, c, d;

long long power(long long x, long long y, long long p){
    long long res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
long long fact[MAX_N], inv_fact[MAX_N];
void pre(){
    fact[0] = 1;
    inv_fact[0] = 1;
    int i = 0;
    for(i = 1; i < MAX_N; i++){
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
        inv_fact[i] = power(fact[i], mod - 2, mod);
    }
}
long nCr(int n, int r){
    if(n < r)
        return 0;
    long long ans = fact[n];
    ans *= inv_fact[r];
    ans %= mod;
    ans *= inv_fact[n - r];
    ans %= mod;
    return ans;
}

long long go(int size, int till_now){
    if(size == b + 1){
        if(till_now == n) {
            //cout << size << " " << till_now << "\n";
            return 1;
        }
        else
            return 0;
    }
    if(dp[size][till_now] != -1)
        return dp[size][till_now];
    long long ans = go(size + 1, till_now);
    long long ways = 1;
    //if(c != 1)
        //ways = calc[size][till_now];
    int rem = n - till_now;
    for(int i = 1; i < c; i++){
        if(rem - (i - 1) * size < size)
            break;
        ways *= nCr(rem - (i - 1) * size, size);
        ways %= mod;
    }
    for(int i = c; i <= d; i++){
        if(rem - (i - 1) * size < size)
            break;
        ways *= nCr(rem - (i - 1) * size, size);
        ways %= mod;
        ans += ((ways * inv_fact[i]) % mod * go(size + 1, till_now + size * i)) % mod;
        ans %= mod;
    }
    return dp[size][till_now] = ans;
}
void solve(){
    int i = 0, j = 0;
    for(i = a; i <= b; i++){
        for(j = 0; j <= n; j++){
            int rem = n - j;
            if(rem - (c - 1) * i < 0)
                break;
            calc[i][j] = power(power(fact[i], c - 1, mod), mod - 2, mod);
            calc[i][j] *= fact[n];
            calc[i][j] %= mod;
            calc[i][j] *= inv_fact[rem - (c - 1) * i];
            calc[i][j] %= mod;
        }
    }
    memset(dp, -1, sizeof(dp));
    cout << go(a, 0) << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    int t = 1;
    //cin >> t
    while(t--){
        cin >> n >> a >> b >> c >> d;
        solve();
    }

    return 0;
}


Measured memory_bytes: 16128
#include<stdio.h>
#define MOD 1000000009+7

int main(){
	int N,i,j,ans=0,tmp;
	scanf("%d",&N);
	int a[N],b[N],c[N],d[N];
	for(i=0;i<N;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<N;i++){
		scanf("%d %d",&c[i],&d[i]);
	}
	
	for(i=0;i<N-1;i++){
		for(j=0;j<N-i-1;j++){
			if(a[j]>a[j+1]){
				tmp=a[j];
				a[j]=a[j+1];
				a[j+1]=tmp;
				tmp=b[j];
				b[j]=b[j+1];
				b[j+1]=tmp;
			}
			if(c[j]>c[j+1]){
				tmp=c[j];
				c[j]=c[j+1];
				c[j+1]=tmp;
				tmp=d[j];
				d[j]=d[j+1];
				d[j+1]=tmp;
			}
		}
	}
	
	for(i=0;i<N;i++){
		tmp=-1;
		for(j=0;a[j]<c[i];j++){
			if(b[j]<d[i] && b[j]>(tmp==-1 ? -1 : b[tmp])) tmp=j;
		}
		if(tmp>=0){
			ans++;
			b[tmp]=200;
		}
	}
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
import sys
def mul_matrix(a, b):
   n = len(a)
   m = len(b)
   l = len(b[0])
   ans = []
   for i in range(n):
      s = []
      for j in range(l):
         sum = 0
         for k in range(m):
            sum += a[i][k] * b[k][j]
         s.append(sum)
      ans.append(s)      #行列の積を計算した結果をansに追加
   return ans

def main():
   n,m,l = [int(i) for i in sys.stdin.readline().strip().split(' ')]
   a = []
   b = []
   for i in range(n):
      data = [int(j) for j in sys.stdin.readline().strip().split(' ')]
      a.append(data)
   for i in range(m):
      data = [int(j) for j in sys.stdin.readline().strip().split(' ')]
      b.append(data)
   ans = mul_matrix(a, b)
   for i in ans:
      print(' '.join([str(j) for j in i]))
        
if __name__ == '__main__':
   main()


Measured memory_bytes: 6880
# 56

W, A, B = map(int, input().split())

dif = abs(A-B)

A = [A, A+W]
B = [B, B+W]

if dif <= W:
  print(0)
elif min(B) - min(A) > 0:
  print(min(B)-max(A))
else:
  print(min(A)-max(B))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
    int a, b;
    string s;
    cin >> a >> b >> s;
    string ans = "Yes";
    if((a+b+1) == s.size() && s[a] == '-');
    else ans = "No";
    for (size_t i = 0; i < s.size(); i++)
    {
        int c = s[i] - '0';
        if(0 <= c && c <= 9) continue;
        else if(i==a && s[a] == '-') continue;
        else {
            ans = "No";
            break;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");
		final int H = Integer.parseInt(in[0]);
		final int W = Integer.parseInt(in[1]);
		final int N = Integer.parseInt(in[2]);
		
		int[][] map = new int[H][W];
		int sx=0;  int sy=0;
		for(int i=0; i<H; ++i){
			char[] str = sc.nextLine().toCharArray();
			for(int j=0; j<W; ++j){
				switch(str[j]){
				case 'S':
					map[i][j] = 0;
					sy = i;
					sx = j;
					break;
				case 'X':
					map[i][j] = -1;
					break;
				case '.':
					map[i][j] = 0;
					break;
				default:
					map[i][j] = Integer.parseInt(str[j] + "");
				}
			}
		}
		
		//algorithm(BFS)
		final int[][] ofs = {
				{1, 0}, {0, 1}, {-1,0}, {0,-1}
		};
		boolean visited[][] = new boolean [H][W];
		int d[][] = new int[H][W];
		Queue<int[]> que = new LinkedList<int[]>();
		int ne[] = {sx, sy};
		que.offer(ne);
		visited[ne[1]][ne[0]] = true;
		d[ne[1]][ne[0]] = 0;
		int n = 0;
		int count = 0;
		while(n!=N){
			ne = que.poll();
			
			for(int i=0; i<ofs.length; ++i){
				final int[] e = {
						ne[0] + ofs[i][0], ne[1] + ofs[i][1]
				};
				boolean f = true;
				for(int j=0; j<e.length; ++j){
					if(e[j] < 0 || (j==1 && H<=e[j]) || (j==0 && W<=e[j]) ){ f=false; }	//はみ出し防止
				}
				if(f){
					if(map[ e[1] ][ e[0] ] >= 0 && !visited[ e[1] ][ e[0] ]){
						que.offer(e);
						visited[ e[1] ][ e[0] ] = true;
						d[ e[1] ][ e[0] ] = d[ ne[1] ][ ne[0] ] +1;
						if(map[ e[1] ][ e[0] ] == n+1){
							++n;
							count += d[ e[1] ][ e[0] ];
							que.clear();
							visited = new boolean[H][W];
							d = new int[H][W];
							que.offer(e);
							visited[ e[1] ][ e[0] ] = true;
							d[ e[1] ][ e[0] ] = 0;
							break;
						}
					}
				}
			}
		}
		System.out.println(count);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 28000
n,k = map(int,input().split())
 
s = input().rstrip().split(' ')
st = []
 
for i in range(0,n):
  a = int(s[i]) 
  st.append(a)
 
new_st = sorted(st)
sum = 0
for j in range(0,k):
  sum += new_st[j]
  
print(sum)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int n;
  cin>>n;
  vector<int> r(n), s(n), p(n), c(n);
  rep(i,n) cin>>r[i];
  rep(i,n) cin>>s[i]>>p[i]>>c[i];
  rep(i,n) s[i]*=-1,p[i]*=-1,c[i]*=-1;

  auto calc = [&](){
    vector<int> ss(s), pp(p), cc(c);
    sort(all(ss)); sort(all(pp)); sort(all(cc));
    vector<pair<int,int>> vec(n);
    rep(i,n) vec[i] = mp(0,((i==0)?n:i));
    rep(i,n) vec[i].fi += r[lower_bound(all(ss),s[i])-ss.begin()];
    rep(i,n) vec[i].fi += r[lower_bound(all(pp),p[i])-pp.begin()];
    rep(i,n) vec[i].fi += r[lower_bound(all(cc),c[i])-cc.begin()];
    sort(all(vec), greater<pair<int,int>>());
    rep(i,n) if(vec[i].se==n) return i+1;
  };

  assert(calc()==9);

  auto f = [&](vector<int> &v){
    int org = v[0];
    for(int i=v[0]-1; i>=-110; i--){
      v[0] = i;
      if(calc()<9){v[0]=org; return org-i;}
    }
    v[0]=org;
    return INF;
  };

  int ans = INF;
  ans = min(f(s), f(p));
  ans = min(ans, f(c));

  if(ans==INF) cout <<"Saiko"<<endl;
  else cout<<ans << endl;

  return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  ll n, a, b;
  cin >> n >> a >> b;

  ll nblue;
  ll wa=a+b;
  ll amari=n%wa;
  nblue = a*((n-amari)/wa) + min(a, amari);
//  cout << amari << endl;
    
  cout << nblue << endl;
  
  return 0;
}


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

int main(){
  string s,t;
  cin >> s >> t;
  ll n,m;
  n=s.size();
  m=t.size();
  ll i,j;
  vector<vector<ll>> dp(n+1,vector<ll>(m+1,0));
  vector<vector<ll>> par(n+1,vector<ll>(m+1,-1));
  for(i=0;i<=n;i++){
    dp[i][0]=0;
  }
  for(i=0;i<=m;i++){
    dp[0][i]=0;
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      if(s[i-1]==t[j-1]){
        dp[i][j]=1+dp[i-1][j-1];
        par[i][j]=3;
      }
      else{
        if(dp[i-1][j] > dp[i][j-1]){
          dp[i][j]=dp[i-1][j];
          par[i][j]=1;
        }
        else{
          dp[i][j]=dp[i][j-1];
          par[i][j]=2;
        }
      }
    }
  }
  string ans="";
  // backtracking;
  i=n;
  j=m;
  while(par[i][j] != -1){
    if(par[i][j]==3){
      ans= s[i-1] + ans;
      i=i-1;
      j=j-1;
    }
    else if(par[i][j]==1){
      i=i-1;
    }
    else{
      j=j-1;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 144484
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d%d",&a,&b,&c);
	if(a==b)
	printf("%d\n",c);
		if(b==c)
	printf("%d\n",a);
		if(a==c)
	printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 128
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  long long int N, K, ans = 0, check = 0,  power = 1 ;
  cin >> N ;
  K = N ;
  char Name ;
  while(1){
    power *= 26;
    check++ ;
    if(K <= power) break ;
    K -= power ;
  }
  K-- ;
  long long int digit[check] ;
  for(int i=0;i<check;i++){
    digit[i] = K % 26ll ;
    K /= 26ll ;
  }
  while(check>0){
    Name = 'a' + (char)digit[check-1] ;
    cout << Name ;
    check-- ;
  }
  cout << endl ;
  return 0 ;
}  

Measured memory_bytes: 3616
import heapq
n,m = map(int,input().split())
A = list(map(int,input().split()))
H = []
for c in A:
    heapq.heappush(H,-c)
for i in range(m):
    b = -heapq.heappop(H)
    b = b//2
    heapq.heappush(H,-b)
print(-sum(H))

Measured memory_bytes: 14180
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

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

    // int T;cin>>T;while(T--) 
    {
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll> m;
        ifr(i,0,n) cin>>a[i],m[a[i]]++;
        ll ans = 0;
        for(auto it:m) ans += (it.ss*(it.ss-1))/2;
        ll x;
        ifr(i,0,n) {
            x = m[a[i]];
            ans -= (x*(x-1))/2;
            m[a[i]]--;
            x = m[a[i]];
            ans += (x*(x-1))/2;
            cout<<ans<<endl;
            x = m[a[i]];
            ans -= (x*(x-1))/2;
            m[a[i]]++;
            x = m[a[i]];
            ans += (x*(x-1))/2;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORd(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
#define II pair<int,int>

const int N=1e6+10;
const ll maxN=1e18+10;
const double pi=3.14159265;

int n,m;
ll a[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> m;
    ll ans=0;
    FOR(i,1,m) {
        int h; cin >> h;
        ans+=h;
    } 
    if (ans<=n) cout << n-ans;
    else cout << -1;
}
    

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

int ma[10] = { 0,2,5,5,4,5,6,3,7,6 };

// dp[i] : i本使った時の最大値
string dp[10020];

void str_max( string& a, string b ) {
  if ( a.size() < b.size() ) {
    a = b;
  } else if ( a.size() == b.size() ) {
    if ( b > a ) a = b;
  }
  return;
} 
int main() {
  int N, M;
  cin >> N >> M;
  vector< int > A(M);
  REP(i,M) {
    cin >> A[i];
  }
  // "-"を初期値とする。初期値の場合は、その本数になることがないことを示す。
  // はじめは不要かと思ってたけど、dp[0] = "" の状態と、存在しないは違う。
  // 存在しない場合はそのdp[i]を起点とすることができない。
  REP(i,N) dp[i] = "-";

  dp[0] = "";
  REP(i,N+1) {
    for ( auto x: A ) {
      // 存在しない場合は飛ばす
      if ( dp[i] == "-" ) continue;
      string b = dp[i] + (char)('0'+x);
      str_max( dp[i+ma[x]], b );
    }
  }
  
  cout << dp[N] << endl;
}


Measured memory_bytes: 45056
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, s = sc.nextInt()
  val a = IndexedSeq.fill(n)(sc.nextInt())

  val mod = 998244353
  def plus(a: Long, b: Long): Long = (a + b) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  def pow(a: Long, n: Int, res: Long = 1): Long = {
    if (n == 0) {
      res
    } else if ((n&1) == 0) {
      pow(times(a,a), n >> 1, res)
    } else {
      pow(times(a,a), n >> 1, times(res,a))
    }
  }

  val dp = Array.fill((n+1) * (s+1))(-1L)
  dp(0) = pow(2, n)
  for (j <- 1 to s) dp(j) = 0

  def solve(i: Int, j: Int): Long = {
    if (dp(i * (s+1) + j) != -1L) {
      dp(i * (s+1) + j)
    } else {
      val ans = if (j >= a(i-1)) {
        plus(solve(i-1, j), times(solve(i-1, j - a(i-1)), 499122177))
      } else {
        solve(i-1, j)
      }
      dp(i * (s+1) + j) = ans
      ans
    }
  }

  println(solve(n,s))
}


Measured memory_bytes: 129364
n, k = map(int, input().split())
*p, = map(int, input().split())

*ev, = map(lambda x: (x*(x+1)/2)/x, p)
cusum = [0]*(n+1)
for i in range(n):
    cusum[i+1] = cusum[i] + ev[i]

ans = 0
for i in range(n-k+1):
    ans = max(ans, cusum[i+k] - cusum[i])
print(ans)


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long n = sc.nextInt();
        long m = sc.nextInt();

        int tmp = (int)Math.pow(2, m);
        long ans = (1900 * m + 100 * (n - m)) * tmp;

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

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

  int n;
  cin >> n;
  int c[600], s[600], f[600];
  rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

  int cnt = 0;
  rep(i, n) {
    int ans = 0;
    FOR(j, i, n-1) {
      for (int k = 0 ;; k++) {
        if (s[j]+f[j]*k >= ans) {
//          cout << i << " " << j << " " << k << endl;
          ans = s[j]+f[j]*k+c[j];
 //         cout << "     " << ans << endl;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}

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

int sq(int x){return x*x;}
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(sq(max(a,max(b,c)))*2==sq(a)+sq(b)+sq(c) ? "YES" :"NO")<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    map<ll,int> mp;
    int n;
    cin >> n;
    ll tot=0, sum=0;
    ++mp[0];
    rep(i,0,n) {
        int a;
        cin >> a;
        sum+=a;
        tot+=mp[sum];
        ++mp[sum];
    }
    cout<<tot<<"\n";
}


Measured memory_bytes: 12800
#include<stdio.h>
int main(void)
{
  int N;
  scanf("%d",&N);
  int b=2;
  int r,tmp;
  int x=N*b;
  if(N<b){
    tmp=N;
    N=b;
    b=tmp;
  }
  r=N%b;
  while(r!=0)
  {
    N=b;
    b=r;
    r=N%b;
  }
  printf("%d",x/b);
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n; cin >> n;
    vector<ll> A(n), B(n);
    for(int i=0; i<n; i++){
        cin >> A[i] >> B[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    
    ll A_med, B_med, ans;
    if(n % 2 != 0){
        A_med = A[(n-1)/2];
        B_med = B[(n-1)/2];
        ans = B_med - A_med + 1LL;
        cout << ans << endl;
    }

    else if(n % 2 == 0){
        A_med = (A[n/2] + A[(n/2)-1]);
        B_med = (B[n/2] + B[(n/2)-1]);
        ans = B_med - A_med + 1LL;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6408
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,k,ans=1;
    cin>>n>>k;
    while (n)
    {
        if (ans*2<=ans+k)
            ans*=2;
        else
            ans+=k;
        n--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

dp = [[0]*(m+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

res = ''
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        res = s[n] + res
print(res)

Measured memory_bytes: 112860
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}




signed main(){
	// cin.tie(nullptr);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int ans = 0;
	int H, W;
	vector<vector<int>> c;
	vector<vector<int>> dp;
	
	
	cin>>H>>W;
	
	c.resize(H, vector<int>(W+1));
	dp.resize(H, vector<int>(W));
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin>>c[i][j];
			c[i][j] = !c[i][j];
		}
	}
	
	
	for(int i = 1; i < H; i++){
		for(int j = 0; j < W; j++){
			if(!c[i][j]) continue;
			
			c[i][j] = c[i-1][j] + 1;
		}
	}
	
	for(int i = 0; i < H; i++){
		stack<pair<int,int>> st;
		
		st.push({-1,-1});
		
		for(int j = 0; j <= W; j++){
			int a = c[i][j], b = j, d = c[i][j];
			
			while(true){
				pair<int,int> p = st.top();
				
				ans = max(ans, (j - p.second - 1) * d);
				
				if(p.first >= a) {
					st.pop();
				} else {
					break;
				}
				
				d = p.first;
			}
			
			st.push({a,b});
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 33340
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[200010],b[200010];
inline int readin(void)
{
	int sum = 0;
	int sign = 1;
	char ch = getchar();
	while(ch > '9' || ch < '0')
	{
		if(ch == '-')
		{
			sign = -1;
		}
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
	{
		sum = sum*10+ch-'0';
		ch = getchar();
	}
	return sum*sign;
}
int main()
{
	int n;
	cin>>n;
	int count=0,t=1;
	for(int i=1;i<=n;i++)
		a[i]=readin();
		for(int i=1;i<=n;i++)
		{
			if(a[i]==t)
			{
				count++;
				t++;
			}
		}
	sort(a,a+n);
	if(a[1]!=1)
	{
		cout<<-1;
		return 0;
	}
	cout<<n-t+1;
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int main()
{
	int n; scanf("%d", &n);
	LL sum = 0, MiN = 1 << 30;
	for (int i = 1; i <= n; i++) {
		LL a, b; scanf("%lld%lld", &a, &b); sum += a;
		if (a > b) MiN = min(MiN, b);
	}
	if (MiN == 1 << 30) printf("0\n"); else printf("%lld\n", sum - MiN);
	return 0;
}

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

int main() {
  int K, S; 
  cin >> K >> S;
  int cnt = 0;
  for (int x = 0; x <= K; x++){
    for (int y = 0; y <= K & x + y <= S; y++) {
      if (S - (x + y) <= K) {
        cnt++;        
      }
    }
  }
  cout << cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n;
	cin>>n;
	ll a[1000];
	for(ll i=0;i<1000;i++){
		a[i]=pow(i,5);
	}
	for(ll i=0;i<1000;i++){
		ll now=a[i];
		now-=n;
		bool mi=false;
		if(now<0){
			now=abs(now);
			mi=true;
		}
		for(ll j=0;j<1000;j++){
			if(now==a[j]){
				cout << i<<" ";
				if(mi==true){
					cout << j*-1;
				}
				else{
					cout <<j;
				}
				return 0;
			}
		}
	}
	// your code goes here
	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N1 100001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountl(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int dp[22][1<<21];
void func()
{
    ios
    int k,n,i,j,l;
    cin>>n;
    int a[n][n];
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>a[i][j];


    dp[0][0]=1;
    for(j=0;j<n;j++)
    {
        if(a[0][j])
        {
            dp[0][1<<j]=1;
        }
    }

    for(i=1;i<n;i++)
    {

        for(j=0;j<(1<<n);j++)
        {
            int mask=j;
            if(dp[i-1][j]==0)continue;

            for(k=0;k<n;k++)
            {
                if(a[i][k]==1&&(((mask>>k)&1)==0))
                {
                    dp[i][mask|(1<<k)]+=dp[i-1][mask];
                    dp[i][mask|(1<<k)]%=hell;
                }
            }
        }

    }

    cout<<dp[n-1][(1<<n)-1];
}
main()
{

int n,m,i;
int j;
int u,v,q;
int test=1;
//si(test);

while(test--)
{
string s;
int d;
func();
}

}


Measured memory_bytes: 183800
#include <iostream>

void solve() {
    int a, b, c;
    std::cin >> a >> b >> c;

    for (int d = 1;; ++d) {
        c -= a;
        if (d % 7 == 0) c -= b;
        if (c <= 0) {
            std::cout << d << "\n";
            break;
        }
    }
}

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

    solve();

    return 0;
}



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

int main() {
	int N, T, A, H, minP = 0, minH = 100000000;
	cin >> N >> T >> A;
	for (int i = 0; i < N; i++) {
		cin >> H;
		int t = T * 1000 - H * 6;
		int d = abs(A * 1000 - t);
		if (d < minH) {
			minH = d;
			minP = i;
		}
	}
	cout << minP + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void init_comb() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long comb(int n, int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init_comb();
  int n;
  cin >> n;
  vector<int> a(n, -1);
  int idx1, idx2;
  rep(i, n+1) {
    int tmp;
    cin >> tmp;
    tmp--;
    if (a[tmp] >= 0) {
      idx1 = a[tmp];
      idx2 = i;
      break;
    } else
      a[tmp] = i;
  }
  for (int i = 1; i <= n+1; i++) {
    ll ans = comb(n, i); //重複数を含まないまたはidx1のみ含む
    ans = (ans+comb(n-1, i-1)-comb(n-idx2+idx1, i-1)+MOD)%MOD; //idx2のみ含む
    ans = (ans+comb(n-1, i-2))%MOD; //どちらも含む
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 13568
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
	ll N,M;
	cin >> N >> M;
	if (N==1 & M==1){
		cout << 1 << endl;
	}
	else if(N==1){
		cout << M-2 << endl;
	}
	else if(M==1){
		cout << N-2 << endl;
	}
	else{
		cout << (N-2)*(M-2) << endl;
	}
	return 0;
}

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

#define ll long long int
#define vi vector<int>

int main() {

    ll X;
    cin >> X;

    ll amount = 100;
    int year = 0;
    while (amount < X) {
        amount = floor(amount * 1.01);
        year++;
    }

    cout << year << endl;

    return 0;
}


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

int main(){
    int n;
    int count=0;
    int a[100];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[minj]>a[j]){
                minj=j;
            }
        }
        if(minj != i){
            int z=a[minj];
            a[minj]=a[i];
            a[i]=z;
            count++;
        }
    }
    for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?'\n':' ');
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3088
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		//エラトステネスの篩により、素数を列挙する。
		int sieves[] = sieve(55555);
		
		List<Integer> primes_end1 = new ArrayList<Integer>();
		for(int i=0;i<sieves.length;i++) {
			if(sieves[i]==1&&i%5==1)primes_end1.add(i);
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<N;i++) {
			sb.append(primes_end1.get(i)+" ");
		}
		System.out.println(sb.toString());
	}
	
	//引数以下の素数を列挙し返すメソッド
	static int[] sieve(int N) {
		int primes[] = new int[N+1];
		Arrays.fill(primes, -1);
		primes[0]=primes[1]=0;
		for(int i=2;i<=N;i++) {
			if(primes[i]==-1) {
				primes[i]=1;
				for(int j=2*i;j<=N;j+=i) primes[j]=0;
			}
		}
		return primes;
	}
}


Measured memory_bytes: 22732
def zero_origin(s: str) -> int:
  return int(s) - 1

h, w = map(int, input().split())
ch, cw = map(zero_origin, input().split())
dh, dw = map(zero_origin, input().split())
s = [input() for _ in range(h)]
active = [
  [True if s[i][j] == '.' else False for j in range(w)]
  for i in range(h)]

magic = 0
stack = [(ch, cw)]
active[ch][cw] = False
visited = []
while stack:
  cur_i, cur_j = stack.pop()
  visited.append((cur_i, cur_j))
  for di, dj in [(0, 1), (0, -1), (-1, 0), (1, 0)]:
    i = cur_i + di
    j = cur_j + dj
    if 0 <= i < h and 0 <= j < w and active[i][j]:
      stack.append((i, j))
      active[i][j] = False
  if not active[dh][dw]:
    print(magic)
    break
  if not stack:
    magic += 1
    while visited:
      cur_i, cur_j = visited.pop()
      for i in range(cur_i - 2, cur_i + 3):
        for j in range(cur_j - 2, cur_j + 3):
          if 0 <= i < h and 0 <= j < w and active[i][j]:
            stack.append((i, j))
            active[i][j] = False
else:
  print(-1)

Measured memory_bytes: 85948
# 累積和(2次元)を用いた解法
from itertools import accumulate
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,Q,*lr = map(int, read().split())

    LR = [[0]*(N+1) for _ in range(N+1)]
    query = []
    for i, (l, r) in enumerate(zip(*[iter(lr)]*2)):
        if i < M:
            LR[l][r] += 1
        else:
            query.append((l, r))
    
    for i in range(1,N+1):
        LR[1][i] += LR[1][i-1]
        LR[i][1] += LR[i-1][1]
    
    for i in range(2, N+1):
        for j in range(2,N+1):
            LR[i][j] += LR[i-1][j] + LR[i][j-1] - LR[i-1][j-1]
    
    for p, q in query:
        ans = LR[q][q] - LR[p-1][q] - LR[q][p-1] + LR[p-1][p-1]
        print(ans)


if __name__ == "__main__":
    main()


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

int main(){
    int a,b;
    cin >> a >> b;
    int ans=-1;
    rep(i,10000){
        if(floor(i*0.08)==a){
            if(floor(i*0.1)==b){
                ans=i;
                break;
            }
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for ai in range(a+1):
  for bi in range(b+1):
    for ci in range(c+1):
      if 500 * ai + 100 * bi + 50 * ci == x:
        ans += 1
print(ans)
  

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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,ans=0;
int l[4000];

signed main(){
    cin>>n;
    rep(i,n)cin>>l[i];
    sort(l,l+n);
    for(int i=1;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int minv=l[j]-l[i];
            int left=lower_bound(l,l+n,minv+1)-l;
            if(left>=0&&left<i){
                ans+=i-left;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
h1,m1,h2,m2,k = map(int,input().split())
h = (h2 - h1)* 60
m = (m2 - m1)
if (m2 - m1) > 0 :
    print((h+m)-k)
else:
    print(h-60+60-m1+m2-k)

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

	
			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var Aarray = retreiveLongArray().OrderByDescending(x => x).ToArray();
			var aidaQ = new Queue<Tuple<long, long>>();

			long happines = 0;

			//最初の二人は特別な処理が必要
			var first = Aarray[0];
			var secound = Aarray[1];
			happines += first;

			aidaQ.Enqueue(new Tuple<long, long>(first, secound));//item1 >= item2になるようにする
			aidaQ.Enqueue(new Tuple<long, long>(first, secound));//item1 >= item2になるようにする

			for (int i = 2; i < N; i++) {

				var friendly = Aarray[i];
				var aida = aidaQ.Dequeue();

				happines += aida.Item2;
				aidaQ.Enqueue(new Tuple<long, long>(aida.Item1, friendly));
				aidaQ.Enqueue(new Tuple<long, long>(aida.Item2, friendly));

			}

			//答えの出力
			var ans = happines;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}

Measured memory_bytes: 70724
#include <iostream>
using namespace std;
main () {
	 long long n, res = 1;
	cin>>n;
	for (long long i=2;i<=n;i++) {
		if (i % 3 == 0 || i % 5 == 0) {
		} else {
			res+=i;
		}
	}
	cout<<res<<endl;
}

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

using namespace std;

typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=3e5+5,LG=26,SM=600,inf=1e9+1;
ll mod=95542721;

ll n;
ll a[M];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	For(i,0,2*n) cin >> a[i];
	sort(a,a+2*n);
    ll cnt=0;
    For(i,0,n) cnt+=min(a[2*i],a[2*i+1]);	
    cout << cnt;
}

Measured memory_bytes: 256
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(N):
    tmp = input()
    if tmp == 'AC':
        ac += 1
    elif tmp == 'WA':
        wa += 1
    elif tmp == 'TLE':
        tle += 1
    else:
        re += 1
print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))


Measured memory_bytes: 69856
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define RANGE(n) for(int _=0; _<n ; _++)
#define FOR(i, m, n) for(int i = m; i < n; i++)

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

const long long INF = 1LL << 60;
const int INT_INF = 1 << 29;

const int MAX = 100010;
long long dp[MAX];

void solve() {
  int N;
  cin >> N;
  REP(i,MAX) dp[i] = INT_INF;
  dp[0] = 0;
  REP(i,N){
    chmin(dp[i+1],dp[i]+1);
    for(int k=1; k<log(N-i+1)/log(6); k++){
      chmin(dp[(int)(i+pow(6,k))], dp[i]+1);
    }
    for(int k=1; k<log(N-i+1)/log(9); k++){
      chmin(dp[(int)(i+pow(9,k))], dp[i]+1);
    }    
  }
  // REP(i,N+1){
  //   cout << i << " : " <<  dp[i] << endl;
  // }
  cout << dp[N] << endl;
  
  return;
}
 
int main() {
    solve();
    return 0;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

li n, m;
li x[100100];
li dx[100100];

int main(void)
{
	cin >> n >> m;
	rep(i, m) {
		cin >> x[i];
	}
	sort(x, x + m);
	rep(i, m - 1) {
		dx[i] = x[i + 1] - x[i];
	}
	sort(dx, dx + m - 1);
	li res = 0;
	rep(i, m - n) {
		res += dx[i];
	}
	cout << res << endl;
}

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

typedef long long ll;

ll F(ll a, ll b) {
  ll c1 = 0, c2 = 0;
  while (a) {
    c1++;
    a /= 10;
  }
  while (b) {
    c2++;
    b /= 10;
  }
  return max(c1, c2);
}

int main() {
  ll n;
  cin >> n;
  ll ans = 9999999999;
  for (ll i = 1; i*i <= n; i++) {
    if (n%i == 0) {
      ll tmp = F(i, n/i);
      if (tmp < ans) {
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256