akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

void _main() {
  ll L; int N;
  cin >> L >> N ;
  vl x(N);
  rep(i,N) cin >> x[i] ;
  auto rotate = [&]{
    vl temp = x;
    rep(i,N) x[i] = L - temp[N-i-1];
  };
  auto solve = [&](){
    vl s1(N+1),s2(N+1);
    ll res = 0;
    ll t = x[N-1];
    int s = N-1; // s~s+1を通らない
    RREP(i,N-1,0){
      // x[i] まで直進
      chmax(res,t);
      if(i%2==(N-1)%2){
        s--;
        t -= x[s+1]-x[s];
      }
      if(i!=0) t += (L-x[s+1])-(x[s]-x[i-1])+x[i-1];
    }
    return res;
  };
  ll ans = solve();
  rotate();
  chmax(ans,solve());
  cout << ans << endl;
}

Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while (true) {
			String[] str = br.readLine().split(" ");
			int H = Integer.parseInt(str[0]);
			int W = Integer.parseInt(str[1]);
			if (H == 0 && W == 0) {
				break;
			}
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					sb.append("#");
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 25176
#![allow(non_snake_case)]

use proconio::input;
use proconio::marker::Usize1;
use std::vec::Vec;

fn main() {
  input! {
    n: usize,
    m: usize,
    lrd: [(Usize1, Usize1, isize); m],
  }
  let mut g = vec![vec![]; n];
  for (l, r, d) in lrd {
    g[l].push((r, d));
    g[r].push((l, -d));
  }
  let mut nanachi = vec![None; n];
  let mut visited = vec![false; n];
  for i in 0..n {
    if !dfs(i, &g, &mut nanachi, &mut visited) {
      println!("No");
      return;
    }
  }
  println!("Yes");
}

fn dfs(
  v: usize,
  g: &Vec<Vec<(usize, isize)>>,
  nanachi: &mut Vec<Option<isize>>,
  visited: &mut Vec<bool>,
) -> bool {
  if visited[v] {
    return true;
  }
  if !nanachi[v].is_some() {
    nanachi[v] = Some(0);
  }
  let x = nanachi[v].unwrap();
  for &(w, d) in &g[v] {
    if let Some(y) = nanachi[w] {
      if x + d != y {
        return false;
      }
    } else {
      nanachi[w] = Some(x + d);
      if !dfs(w, g, nanachi, visited) {
        return false;
      }
    }
  }
  true
}


Measured memory_bytes: 22860
N, M = map(int, input().split())

ans = {}
for i in range(8):
    ans[i] = []
for i in range(N):
    x, y, z = map(int, input().split())
    ans[0].append(x+y+z)
    ans[1].append(x+y-z)
    ans[2].append(x-y+z)
    ans[3].append(x-y-z)
    ans[4].append(-x+y+z)
    ans[5].append(-x+y-z)
    ans[6].append(-x-y+z)
    ans[7].append(-x-y-z)

max_ans = 0
for i in range(8):
    ans[i].sort(reverse=True)
    max_ans = max(max_ans, sum(ans[i][:M]))
print(max_ans)

Measured memory_bytes: 39024
import itertools

N, M, Q = map(int, input().split())
ABCD = []
ans = 0

prob_list = itertools.combinations_with_replacement(range(1,M+1), N)

for _ in range(Q):
    a,b,c,d = map(int, input().split())
    ABCD.append((a,b,c,d))

for prob in prob_list:
    tmp = 0
    for i in range(Q):
        a,b,c,d = ABCD[i]
        if prob[b-1] -prob[a-1] == c:
            tmp += d
    ans = max(ans, tmp)

print(ans)


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

const long long mod = 1E9 + 7;

int main() {
	int h, w;
	while ( cin >> h >> w ) {
		string grid[h];
		bool cont = true;
		
		for (int i = 0; i < h; ++i) cin >> grid[i];
		
		long long ways[ h+5 ][ w+5 ];
		
		for (int i = 0; i < h; ++i) if ( cont and grid[i][0] == '.' ) ways[i][0] = 1; else cont = false, ways[i][0] = 0; cont = true;
		for (int i = 0; i < w; ++i) if ( cont and grid[0][i] == '.' ) ways[0][i] = 1; else cont = false, ways[0][i] = 0; cont = true;
		
		for (int i = 1; i < h; ++i) {
			for (int j = 1; j < w; ++j) {
				if ( grid[i][j] == '#' ) ways[i][j] = 0;
				else ways[i][j] = ( ways[ i-1 ][j] + ways[i][ j-1 ] ) % mod;
			}
		}
		
//		for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) cout << ways[i][j] << ' '; cout << '\n'; }
		
		cout << ways[ h-1 ][ w-1 ] << '\n';
	}
	return 0;
}

Measured memory_bytes: 9088
/*
  || Shree Ganeshay Namah ||

     || Jai Shree Ram ||
  || Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define mod 1000000000000000001
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
int jai_shree_ram()
{
    return 1;
}
int shree_ganeshay_namah()
{
    return 1;
}
ll power(ll x,ll y)
{
    ll r=1;
    while(y>0)
    {
        if(y%2!=0)
            r=r*x;
        x=x*x;
        y=y/2;
    }
    return r;
}
ll ncr(ll n,ll k)
{

    ll c[k+1];
    memset(c,0,sizeof(c));
    c[0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=min(i,k);j>0;j--)
            c[j]=c[j]+c[j-1];
    }
    return c[k];
}

bool prime[500001];
void sieve()
{
    ll i,j;
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(i=2;i<=sqrt(100001);i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=100001;j=j+i)
                prime[j]=false;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j;
    cin>>n;
    ll f=0;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            f=f+i;
    }
    cout<<f;
    return 0;

}


Measured memory_bytes: 3652
#include <stdio.h>
int main()
{
  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  
  if(a>=0 && a<=100 && b>=0 && b<=100 && c>=0 && c<=100){
  if(a<b && b<c)printf("Yes\n");
  else printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

using namespace std;


int main(){
	string input = ""; 
	map<string, int> dictionary;

	cin >> input;
	dictionary.insert(pair<string, int>(input, 1));
	string maxString = input;
	int maxCount = 1;


	while(cin >> input){
		for(map<string, int>::iterator it = dictionary.begin(); it != dictionary.end(); it++){
			if(input != it->first){
				dictionary.insert(pair<string, int>(input, 1));
				if(maxString.length() < input.length()){
					maxString = input;
				}
			}
			else{
				it->second++;
				if(maxCount < it->second){
					maxCount = it->second;
				}
			}
		}
	}

	for(map<string, int>::iterator it = dictionary.begin(); it != dictionary.end(); it++){
		if(it->second == maxCount){
			cout << it->first;
			break;
		}
	}

	cout << " " << maxString << endl;
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
using namespace std;
#define MAX_N 4000

int num[MAX_N/2+1];

int main(int argc, char const *argv[])
{
	// a+b=nの(a,b)の組み合わせ数を計算 0<=a<=1000, 0<=b<=1000
	for(int i=0;i<=MAX_N/4;i++){
		for(int j=0;j<=MAX_N/4;j++){
			num[i+j]++;
		}
	}
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=0;i<=MAX_N/2;i++){
			int cd = n-i;
			if(cd<0)break;
			if(cd>2000)continue;
			ans += num[i] * num[cd];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    int n;
    int a[100001];
    long long int sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0||(i%3==0&&i%5==0))
        {
            continue;
        }
        else
            sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  N %= 10;
  if (N == 3) return cout << "bon" << "\n", 0;
  if (N == 0) return cout << "pon" << "\n", 0;
  if (N == 1) return cout << "pon" << "\n", 0;
  if (N == 6) return cout << "pon" << "\n", 0;
  if (N == 8) return cout << "pon" << "\n", 0;
  cout << "hon" << "\n";
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0;
    bool poss = true;
    cin >> n;
    vll a(n);
    for(i = 0; i < n; i++)
        cin >> a[i];
    for(i = 1; i < n; i++)
    {
        if(a[i] - a[i - 1] > 1)
        {
            poss = false;
            break;
        }
        if(a[i] == a[i - 1] + 1)
            ans++;
        else
            ans += a[i];
    }
    poss = poss && (a[0] == 0);
    cout << (poss ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[200010],c[200010];
int main()
{
	int n,k,i,s;
	bool f;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>a[i];
	while(k--)
	{
		memset(c,0,sizeof c);
		for(i=1;i<=n;i++)
		{
			c[max(1,i-a[i])]++;
			c[min(n+1,a[i]+i+1)]--;
		}
		s=0;
		f=true;
		for(i=1;i<=n;i++)
		{
			s+=c[i];
			a[i]=s;
			if(a[i]<n)
				f=false;
		}
		if(f)
			break;
	}
	for(i=1;i<=n;i++)
		cout<<a[i]<<' ';
	return 0;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std ;
 
#define lli long long int
#define pb push_back
 
int main ()
{
    string a , b ;
  	int n ;
  	cin >> n ;
    cin >> a ;
    cin >> b ;

    for (int i = 0 ; i < a.size() ; i++)
    {
        cout << a[i] ;
        cout << b[i] ;
    }
    
    return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(;;){
                int a=0;
                for(;;){
                        char c;
                        scanf("%c",&c);
                        if(c=='\n') break;
                        else a+=(int(c)-48);
                }
                if(a) printf("%d\n",a);
                else break;
        }
        return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,t;
  cin >> n >> t;
  --t;
  vector<pair<int,int>> p(n);
  rep(i,n){
    cin >> p[i].first >> p[i].second;
  }

  sort(p.begin(), p.end());
  
  vector<vector<int>> dp(n+1,vector<int>(t+1,0));

  rep(i,n){
    rep(j,t+1){
      int a = p[i].first;
      int b = p[i].second;
      if(j-a>=0){
	dp[i+1][j] = max(dp[i][j],dp[i][j-a]+b);
      }
      else{
	dp[i+1][j] = dp[i][j];
      }
    }
  }
  
  int res=0;
  rep(i,n){
    res=max(res,dp[i][t]+p[i].second);
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int M = N;
  int sum = 0;
  while (M) {
    sum += M % 10;
    M /= 10;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
    ll n;
    cin >> n;
    ll ans[n + 1];
    for (ll i = 1; i <= n; i++) {
        ans[i] = 0;
    }
    for (ll i = 2; i <= n; i++) {
        ll x;
        cin >> x;
        ans[x]++;
    } 
    for (ll i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    } 
    return 0;
}

Measured memory_bytes: 5196
#include <cstdio>
#include <cstring>
using namespace std;

const int MAX_N = 100;
int values[MAX_N];

int main(){
	int n;
	while(scanf("%d", &n), n != 0){
		// target: 探す値, ans: 探索が終わるまでの比較回数
		int target, ans = 0;
		// 二分探索の範囲
		int l = 0, r = n - 1;
		
		memset(values, 0, sizeof(values));
		for (int i = 0; i < n; i++) {
			scanf("%d", &values[i]);
		}
		scanf("%d", &target);
		
		while(l <= r) {
			ans++;
			int m = (l + r) / 2;
			if (values[m] == target) break;
			else if (values[m] < target) l = m + 1;
			else r = m - 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m, s;
  in2(n, m);
  if(n >= m / 2)
    s = m / 2;
  else
    s = n + (m - n * 2) / 4;
  out(s);
  memi;
}

Measured memory_bytes: 256
//Generated at 2020-03-22 20:02:45 UTC+8
//Created by Alphagocc
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a + b, min(b + c, c + a)) << endl;
  return 0;
}

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

using namespace std;

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

	int n, m;
	cin >> n >> m;
	int a[300][300];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
		{
			cin >> a[i][j];
			a[i][j]--;
		}
	int ret = (n != 1 ? 300 : 1);
	bool lot[300] = {false};
	for(int i = 0; i < m - 1; i++)
	{
		int reg[300] = {0};
		for(int j = 0; j < n; j++)
			for(int k = 0; k < m; k++)
			{
				if(!lot[a[j][k]])
				{
					reg[a[j][k]]++;
					break;
				}
			}
		int mp = 0, mr = -1;
		for(int j = 0; j < m; j++)
		{
			if(mp < reg[j])
			{
				mp = reg[j];
				mr = j;
			}
		}
		ret = min(ret, mp);
		lot[mr] = true;
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace bla
{
    class Program
    {
        static void Main()
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int x = int.Parse(s[1]);
            List<int> a = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
            a.Sort();
            int u = 0;
            int i;
            for (i = 0; i < a.Count && u <= x; i++)
            {
                u += a[i];
            }
            if(u < x)
                Console.WriteLine(a.Count - 1);
            else if(u == x)
                Console.WriteLine(a.Count);
            else
                Console.WriteLine(i - 1);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,ans;
  cin>>A>>B;
  ans=0;
  for (int i=A;i<=B;i++){
    if (i/10000==i%10 && (i/1000)%10==(i/10)%10)
      ans+=1;
  }
  cout<<ans<<endl;
}

      


Measured memory_bytes: 256
r, c = map(int, input().split())
tabl = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
    print(" ".join(map(str, tabl[i])) + " " + str(sum(tabl[i])))
ss = ""
for i in range(c):
    ans = 0
    for j in range(r):
        ans += tabl[j][i]
    ss += str(ans) + " "
print(ss+str(sum([int(i) for i in ss.split()])))


Measured memory_bytes: 5688
N=int(input().strip())
T=list(map(int,input().split()))
V=list(map(int,input().split()))
vtmax=[0]
tmp=0
Tsum=sum(T)
for t,v in zip(T,V):
    vtmax[-1]=min(tmp,v) #境界は小さい方が制約
    vtmax+=[v]*(t*2)
    tmp=v
vtmax[-1]=0

for i in range(1,2*Tsum):
    vtmax[i]=min(vtmax[i],vtmax[i-1]+0.5)
for i in range(2*Tsum-1,0,-1):
    vtmax[i]=min(vtmax[i],vtmax[i+1]+0.5)
area=0
for i,vt in enumerate(vtmax):
    if i==0:continue
    area+=0.5*(vt+vtmax[i-1])/2
print(area)

Measured memory_bytes: 3504
// C - Grand Garden
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

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

	vi H(N);
	rp(i, N) cin>>H[i];

	int ans = 0, active = 0;
	rp(i, N){
		active = min(active, H[i]);
		ans += H[i] - active;
		active = H[i];
	}
	cout<< ans <<endl;
}

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

const int cnMaxArray = 1000033;

long long fnStrToInt(string sKey)
{
  int iElement;
  int iBase = 1;
  int llKey  = 0;
  for (int i = sKey.size() - 1; i >= 0; i--)
  {
    switch (sKey[i])
    {
      case  'A': iElement = 1;
                 break;
      case  'C': iElement = 2;
                 break;
      case  'G': iElement = 3;
                 break;
      case  'T': iElement = 4;
                 break;
      default:   iElement = 0;
    }
    llKey += iBase * iElement;
    iBase *= 5;
  }
  return llKey;
}

int fnHash1(long long a_llKey) { return (a_llKey % cnMaxArray); }
int fnHash2(long long a_llKey) { return (1 + (a_llKey % (cnMaxArray - 1))); }

void fnDictionary(string a_stasDictionary[])
{
  int iCommandCnt;
  cin >> iCommandCnt;

  for (int i = 0; i < iCommandCnt; i++)
  {
    string sCommand;
    string sKey;
    cin >> sCommand >> sKey;

    long long llKey = fnStrToInt(sKey);
    int iCnt = 0;
    for (iCnt = 0; ;iCnt++)
    {
      int ix = (fnHash1(llKey) + iCnt * fnHash2(llKey)) % cnMaxArray;
      if (a_stasDictionary[ix] == sKey)
      {
        if (sCommand[0] == 'i')
          break;
        else if (sCommand[0] == 'f')
        {
          cout << "yes" << endl;
          break;
        }
      }
      else if (a_stasDictionary[ix].size() == 0)
      {
        if (sCommand[0] == 'i')
        {
          a_stasDictionary[ix] = sKey;
          break;
        }
        else if (sCommand[0] == 'f')
        {
          cout << "no" << endl;
          break;
        }
      }
    }
  }
}

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

  static string stasDictionary[cnMaxArray];
  fnDictionary(stasDictionary);
  
  return 0;
}

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


int main() {
    string s;
    stack<int> st;
    while(cin >> s) {
        if(s == "+") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b + a);
        } else if(s == "-") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b - a);
        } else if(s == "*") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b * a);
        } else {
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;
}



Measured memory_bytes: 3236
n, m = gets.chomp.split(" ").map(&:to_i)
box = Struct.new("Box", :red, :n)
boxes = Array.new(n+1){box.new(false, 1)}
boxes[1][:red] = true
m.times do
  x, y = gets.chomp.split(" ").map(&:to_i)
  if boxes[x][:red] then
    boxes[y][:red] = true
  end
  boxes[x][:n] = boxes[x][:n] - 1
  if boxes[x][:n] == 0 then
    boxes[x][:red] = false
  end
  boxes[y][:n] = boxes[y][:n] + 1  
end
res = 0
boxes.each do |bx|
  res += 1 if bx[:red] && (bx[:n] != 0)
end
puts res


Measured memory_bytes: 9340
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N), b(N);
	vector<pair<ll, ll>> numpair;
	map<ll, ll> numtoans;
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a.begin(), a.end());
	ll num = a[0];
	ll count = 0;
	for (ll i = 0; i < N; i++)
	{
		if (num == a[i]) {
			count++;
		}
		else {
			numpair.push_back(make_pair(num, count));
			count = 1;
			num = a[i];
		}
	}
	numpair.push_back(make_pair(num, count));
	ll sum = 0;
	for (auto var : numpair) {
		sum += var.second * (var.second - 1) / 2;
	}
	for (auto var : numpair) {
		ll ans = sum;
		ans -= var.second * (var.second - 1) / 2;
		ans += (var.second - 1) * (var.second - 2) / 2;
		numtoans[var.first] = ans;
	}
	for (ll i = 0; i < N; i++)
	{
		cout << numtoans[b[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 14576
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  ll x;
  ll y = 0;
  ll m = 100;
  cin >> x;
  while (m < x) {
	  m += m / 100;
	  y++;
	}
  cout << y << endl;
  return 0;
}


Measured memory_bytes: 3636
Module P1
Sub main()

    Dim RD As String
    Dim SD() As String
    
    Dim a() As Long
    Dim nowI As Long
    Dim CheckI As Long
    Dim CheckNum As Long
    Dim haken As Boolean
    
    ReDim Preserve a(0)
    RD = Console.Readline()
    a(0) = RD
    nowI = 0
    haken = False
    Do While nowI < 1000000
        ReDim Preserve a(nowI + 1)
        If a(nowI) Mod 2 = 0 Then
            a(nowI + 1) = a(nowI) / 2
        Else
            a(nowI + 1) = a(nowI) * 3 + 1
        End If
        CheckNum = a(nowI + 1)
        For CheckI = 0 To UBound(a) - 1
            If a(CheckI) = CheckNum Then
                Exit Do
            End If
        Next
        
        nowI = nowI + 1
    Loop
    
    Console.Writeline (nowI + 2)

End Sub

end Module


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

int main(){
  int a;
  vector<int> v;

  for (unsigned int i = 0; i < 10; i++) {
    cin >> a;
    v.push_back(a);
    if (cin.eof()) { break; }
  }

  sort(v.begin(), v.end(), greater<int>());

  for (unsigned int i = 0; i < 3; i++) {
    cout << v[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void)
{
	int n, i, j, num;
	
	while (1){
		num = 0;
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (i = n; i > 0; i--){
			j = i;
			while (j % 5 == 0){
				num++;
				j /= 5;
			}
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 87;
int A[MAXN][MAXN];
int B[MAXN][MAXN];
bool dp[MAXN][MAXN][MAXN * MAXN * 2];

int main() {
    int H, W;
    scanf("%d %d", &H, &W);
    for (int i = 1; i <= H; i++)
        for (int j = 1; j <= W; j++)
            scanf("%d", &A[i][j]);
    for (int i = 1; i <= H; i++)
        for (int j = 1; j <= W; j++)
            scanf("%d", &B[i][j]);
    dp[1][1][0] = 1;
    for (int i = 1; i <= H; i++)
        for (int j = 1; j <= W; j++) {
            int x = max(A[i][j], B[i][j]);
            int y = min(A[i][j], B[i][j]);
            for (int w = 0; w <= 80 * 80 * 2; w++) {
                if (dp[i][j][w]) {
                   dp[i][j + 1][abs(x - y + w)] = 1;
                   dp[i][j + 1][abs(x - y - w)] = 1;
                   dp[i + 1][j][abs(x - y + w)] = 1;
                   dp[i + 1][j][abs(x - y - w)] = 1;
                }
            }
        }
    int ans = 80 * 80 * 2;
    for (int i = 0; i <= 80 * 80 * 2; i++) {
        if (!dp[H][W][i]) continue;
        int x = max(A[H][W], B[H][W]);
        int y = min(A[H][W], B[H][W]);
        ans = min(ans, abs(x - y + i));
        ans = min(ans, abs(x - y - i));
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

#define P pair<int,int>

const int nmax = 50;
char maze[nmax][nmax];
int cost[nmax][nmax];

void bfs(int H,int W){
    queue<P> q;
    P pos;
    int n_x,n_y,x,y;
    int direction[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
    q.push(P(0,0));
    cost[0][0] = 1;
    while(!q.empty()){
        pos = q.front();
        q.pop();
        n_x = pos.first;
        n_y = pos.second;
        if(n_x == W - 1 && n_y == H - 1){
            return;
        }

        for(int i = 0;i < 4;i++){
            x = n_x + direction[i][0];
            y = n_y + direction[i][1];
            if(x < 0 || W <= x || y < 0 || H <= y) continue;
            if(cost[y][x] < INT_MAX) continue;
            if(maze[y][x] == '#') continue;
            cost[y][x] = min(cost[y][x],cost[n_y][n_x] + 1);
            q.push(P(x,y));
        }
    }
}

int main(){
    int H,W,b,w;
    char c;

    cin >> H >> W;

    b = w = 0;
    for(int y = 0;y < H;y++){
        for(int x = 0;x < W;x++){
            cin >> c;
            maze[y][x] = c;
            cost[y][x] = INT_MAX;
            if(c == '.'){
                w++;
            }else{
                b++;
            }
        }
    }

    bfs(H,W);

    if(cost[H - 1][W - 1] == INT_MAX){
        cout << "-1" << endl;
        return 0;
    }
    cout << w - cost[H - 1][W - 1] << endl;

}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m>>v;
  cout<<int((n-v)/(m+v))<<endl;

}

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


Measured memory_bytes: 256
n=int(input())
a=list(map(lambda x:int(x), input().split()))
a.insert(0,0)
a.append(0)
count=0
s=sum([abs(a[i]-a[i+1]) for i in range(0, n+1)])
for i in range(1, n+1):
    c=s+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))
    print(c)


Measured memory_bytes: 14048
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef pair<ll, ll>P;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

ll par[100000], depth[100000];
static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}
#define yo 100001
//------------------変数-----------------------//
string str;
//-------------------関数----------------------//

int main() {
	cin >> str;
	if (str[0] == str.back()) {
		if (str.size() % 2) { cout << "Second" << endl; }
		else { cout << "First" << endl; }
	}
	else {

		if (!(str.size() % 2)) { cout << "Second" << endl; }
		else { cout << "First" << endl; }
	}
	return 0;
}

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

using namespace std;
int main() {
  long A, B, K;
  cin >> A >> B >> K;

  A -= K;
  if (A < 0) {
    B += A;
    A = 0;
  }
  if (B < 0) {
    B = 0;
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int k;
    String s;
    k=sc.nextInt();
    sc.nextLine();
    s=sc.nextLine();
    char ar[]=s.toCharArray();
    for(int i=0;i<ar.length;i++)
    ar[i]=(char)((ar[i]-65+k)%26+65);
    s=new String(ar);
    System.out.println(ar);
  }
}

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

int main() {
  int a;
  int s1,s2,s3;
  cin >> a;
  s3 = a%10;
  s2 = ((a-s3)/10)%10;
  s1 = (a-s2-s3)/100;
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <climits>
#include <cstdlib>

using namespace std;

int main(void)
{
    int n;
    cin >> n;

    vector<int> costs;
    for(int i = 0; i < n; i++){
        int h;
        cin >>h;
        costs.push_back(h);
    }

    vector<long long int> costSum(n, LLONG_MAX);
    costSum[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <=2; j++){
            if(i - j < 0){
                continue;
            }
            if( costSum[i] > costSum[i - j] + abs(costs[i-j] - costs[i])){
                costSum[i] = costSum[i - j] + abs(costs[i-j] - costs[i]);
            }
        }
    }
    printf("%lld\n", costSum[n-1]);
    return 0;
}

Measured memory_bytes: 1528
def get_primes(x):
    if x < 2:
        return list()
    primes = [2]
    n = 3
    while n <= x:
        is_prime = True
        for p in primes:
            if n % p == 0:
                is_prime = False
                break
            if p**2 > n:
                break
        if is_prime:
            primes.append(n)
        n += 2
    return primes


def main():
    X = int(input())
    if X <= 1:
        print(2)
        exit(0)
    primes = get_primes(X)
    while True:
        is_prime = True
        for p in primes:
            if X % p == 0 and X > p:
                is_prime = False
                break
        if is_prime:
            break
        X += 1
    print(X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3388
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int H, A;
  cin >> H >> A;
  cout << (H + A -1) / A << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let T: usize = sc.get();
    let t: Vec<usize> = sc.vec(N);
    let mut ans = 0;
    for i in 0..N-1 {
        let dt = t[i+1] - t[i];
        ans += min(T, dt);
    }
    ans += T;
    println!("{}", ans);
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    int n;
    cin>>n;
    int ans=0;
    rep(i,n){
        int l, r;
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout << ans <<endl;
    
    return 0;
}


Measured memory_bytes: 256
list = ["1", "1", "1", "2", "1", "2", "1", "5", "2", "2", "1", "5", "1", "2", "1", "14", "1", "5", "1", "5", "2", "2", "1", "15", "2", "2", "5", "4", "1", "4", "1", "51"]
K = input()
a = int(K)-1
print(list[a])

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<string> 
#include<vector>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
int n,m,sx,sy,ex,ey;
char a[1005][1005];
int d[1005][1005];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};

bool check(int x,int y){
	if(x<1||y<1||x>n||y>m||a[x][y]=='#') return false;
	return true;
}
void bfs(){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) d[i][j]=1e9;
	d[sx][sy]=0;
	deque<pair<int,int> > q;
	q.push_front(make_pair(sx,sy));
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;
		q.pop_front();
		for(int i=0;i<4;i++){
			int x1=x+dir[i][0],y1=y+dir[i][1];
			if(check(x1,y1)&&d[x1][y1]>d[x][y]) q.push_front(make_pair(x1,y1)),d[x1][y1]=d[x][y];
		}
		for(int i=-2;i<=2;i++){
			for(int j=-2;j<=2;j++){
				int x1=x+i,y1=y+j;
				if(check(x1,y1)&&d[x1][y1]>d[x][y]+1){
					q.push_back(make_pair(x1,y1));
					d[x1][y1]=d[x][y]+1;
				} 
			}
		}
	}
} 

int main()
{
	cin>>n>>m>>sx>>sy>>ex>>ey;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) cin>>a[i][j];
	bfs();
	if(d[ex][ey]==1e9) cout<<-1;
	else cout<<d[ex][ey];
	return 0;	
} 

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int MAXN = 2 * 105000;

int n;
int color[MAXN];
vector<int> g[MAXN];
int sum[MAXN];
long long rem[MAXN];
int sz[MAXN];

void dfs(int v, int par = -1) {
    int curSum = sum[color[v]];
    sz[v] = 1;

    int prev = sum[color[v]];
    for (int to : g[v]) {
        if (to == par)
            continue;

        dfs(to, v);
        if (color[to] != color[v]) {
            int num = sz[to] - (sum[color[v]] - prev);
            rem[color[v]] += 1ll * num * (num + 1) / 2;
        }

        sz[v] += sz[to];
        prev = sum[color[v]];
    }

    sum[color[v]] = curSum + sz[v];
}

int main() {

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &color[i]);
        color[i]--;
    }

    for (int i = 0; i < n - 1; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    dfs(0);
    for (int i = 0; i < n; i++) {
        if (color[0] == i) continue;

        int num = sz[0] - sum[i];
        rem[i] += 1ll * num * (num + 1) / 2;
    }

    for (int i = 0; i < n; i++) 
        printf("%lld\n", 1ll * n * (n + 1) / 2 - rem[i]);

    return 0;
}


Measured memory_bytes: 37712
import java.io.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    br.lines()
      .parallel()
      .map(line -> line.split(" "))
      .map(ar -> Stream.of(ar).mapToInt(Integer::parseInt).sum())
      .map(String::valueOf)
      .mapToInt(str -> str.length())
      .sequential()
      .forEach(System.out::println);
  }
}

Measured memory_bytes: 31008
#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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pint e[100001];
#define MAX_N 100002
struct UnionFind{
    int data[MAX_N]; 
    void init(int n){memset(data,-1,sizeof(data));}
    int find(int x){return data[x]<0?x:data[x]=find(data[x]);}
    void unite(int x, int y){
        x=find(x);y=find(y);       
        if(x!=y){
            if(data[y]<data[x]) swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return;
    } 
    bool same(int x, int y){return (find(x) == find(y));}
    int size(int x){return -data[find(x)];}
};
ll n,m,ai,bi;
ll ans[100001];
int main(){
    cin>>n>>m;
    rep(i,m){
        cin>>ai>>bi;
        e[i]={ai,bi};
    }
    UnionFind uf;
    uf.init(n+1);
    ll cur=n*(n-1)/2;
    rep(i,m){
        int id=m-i-1;
        ans[id]=cur;
        if(!uf.same(e[id].first,e[id].second)){
            cur-=(ll)uf.size(e[id].first)*uf.size(e[id].second);
            uf.unite(e[id].first,e[id].second);
        }
    }
    rep(i,m) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 3200
N,M,X,Y = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
flag = 0
a = max(A)
b = min(B)
for i in range(X+1,Y) :
    if i > max(A) and i <= Y and i <= min(B) and i > X :
        flag += 1
if flag >= 1 :
    print("No War")
else :
    print("War")
   

Measured memory_bytes: 3060
//not my submission
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 7;

int n, x;

struct node {
    int b, l, u;
    ll sorce;
    friend bool operator < (const node& x, const node& y) {
        return x.sorce > y.sorce;
    }
} a[maxn];

ll check(ll t) {
    ll tim = t / x;
    ll res = t - tim * x;
    ll sum = 0;
    for (int i = 1; i <= tim; i++) {
        sum += a[i].sorce;
    }
    ll ans = 0; //최댓값을 return
    //ans = sum;
    for (int i = 1; i <= n; i++) {
        ll now = 0;
        if (res <= a[i].b)
            now = res * a[i].l;
        else
            now = (long long)a[i].b * a[i].l + (long long)(res - a[i].b) * a[i].u;
//    if (i <= tim) ans = max(ans, sum - a[i].sorce + now + a[tim + 1].sorce);
//    else ans = max(ans, sum + now);
        if (i <= tim)//i sorce를 다 사용하지 않고 tim+1 값을 다 사용 하고 i번째 것을 부분적으로 사용
            ans = max(ans, sum - a[i].sorce + now + a[tim + 1].sorce); 
        else
            ans = max(ans, sum + now);

    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    cin >> n >> x;
    ll goal = 0, maxx = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].b >> a[i].l >> a[i].u;
        goal += (long long)a[i].b * a[i].l;
        a[i].sorce =(long long )a[i].b * a[i].l + (long long) a[i].u * (x - a[i].b); //실제로 영향이 있는 값
    }
    sort(a + 1, a + n + 1);
    ll l = 0, r = (long long)n * x; //최대 비용
    while (l < r) {
        ll mid = (l + r) / 2;
        if (check(mid) >= goal)
            r = mid;
        else
            l = mid + 1;
    }
    cout << r << endl;
}


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

using namespace std;

const long long INF = LONG_LONG_MAX;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<long long> > dp(n);
    for (int i = 0; i < n; ++i) {
        dp[i].resize(3, -1);
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; ++i) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";
    return 0;
}

Measured memory_bytes: 6912