akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

int N;
pair<int, int> goal;
int p;
// bool vert[15][15];
// bool horiz[15][15];
// int answer[15][15];

template <class T>
void display(T a[16][16]) {
	for (int i = 0; i < 16; i++) {
		for (int j = 0; j < 16; j++) {
			cout << a[j][i] << "\t";
		}
		cout << endl;
	}
	cout << endl << endl;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		bool vert[16][16] = {};
		bool horiz[16][16] = {};
		int answer[16][16] = {};
		cin >> goal.first >> goal.second >> p;
		for (int j = 0; j < 16; j++) {
			vert[j][0] = true;
			horiz[0][j] = true;
		}
		for (int j = 0; j < p; j++) {
			pair<int, int> matatabi1, matatabi2;
			cin >> matatabi1.first >> matatabi1.second >> matatabi2.first >> matatabi2.second;
			if (matatabi1.first == matatabi2.first) {
				vert[matatabi1.first][max(matatabi1.second, matatabi2.second)] = true;
			} else {
				horiz[max(matatabi1.first, matatabi2.first)][matatabi1.second] = true;
			}
		}
		
		// display<bool>(vert);
		// display<bool>(horiz);
		for (int x = 0; x <= goal.first; x++) {
			for (int y = 0; y <= goal.second; y++) {
				if (x == 0 && y == 0) answer[x][y] = 1;
				else {
					answer[x][y] = (vert[x][y] ? 0 : answer[x][y-1]) + (horiz[x][y] ? 0 : answer[x-1][y]);
				}
			}
		}

		// display<int>(answer);

		if (answer[goal.first][goal.second] == 0) {
			cout << "Miserable Hokusai!" << endl;
		} else {
			cout << answer[goal.first][goal.second] << endl;
		}
	}
	return 0;	
}

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

double pi = acos(-1);
typedef complex<double> P;
int main(){
	string kw[] = {"the","this","that"};
	string s;
	while(getline(cin,s)){
		for(int k = 0 ; k < 26 ; k++){
			string t = s;
			for(int i = 0 ; i < s.size() ; i++){
				if( s[i] == 32 ) continue;
				if( s[i] == '.' ) continue;
				t[i] = (s[i] - 'a' + k) % 26 + 'a';
			}
			if( t.find(kw[0]) != -1 or t.find(kw[1]) != -1 or t.find(kw[2]) != -1 ){
				cout << t << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 2956
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: - int(x), input().split()))
heapq.heapify(a)
for i in range(m):
    b = heapq.heappop(a) * (-1)
    b //= 2
    heapq.heappush(a, -b)
print(-sum(a))


Measured memory_bytes: 14252
n = int(input())
t = []
time = 0
ans = "Yes"
for i in range(n):
    t1 = list(map(int,input().split()))
    t.append(t1)
t.sort(key=lambda x:x[0],reverse=True)
t.sort(key=lambda x:x[1])
for i in range(n):
    time = time + t[i][0]
    if time > t[i][1]:
        ans = "No"
        break
print(ans)

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

bool solve(int n, int A[], int p, int sum, int t ){
  if ( sum == t ) return true;
  if ( p == n ) return false;
  if ( solve(n, A, p+1, sum, t) ) return true;
  if ( solve(n, A, p+1, sum+A[p], t) ) return true;
  return false;
}

main(){
  int n, q, M, T[50];
  cin >> n;
  for ( int i = 0; i < n; i++ ){
    cin >> T[i];
  }
  cin >> q;
  for ( int i = 0; i < q; i++ ){
    cin >> M;
    if ( solve(n, T, 0, 0, M) ) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}




Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;



namespace CSharpSample01
{

    struct Act
    {
        public int s;
        public int t;
    }
    
    class Program
    {
        
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Act[] act = new Act[n];
            for(int i = 0; i < n; i++)
            {
                int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                int s = input[0];
                int t = input[1];
                act[i] = new Act() { s = s, t = t };
            }
            
            int time = 0;
            int cnt = 0;

            foreach(var a in act.OrderBy(x => x.t))
            {               
                if (time >= a.s) continue;
                time = a.t;
                cnt++;
            }

            Console.WriteLine(cnt);
        }
    }

}


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

const int mod = 1e9+7 ; 
typedef long long ll ; 

int n , m ;
ll dp[1001][1001] ; 
char c[1001][1001] ; 

ll calc (int x , int y){
	if (x == n-1 && y == m-1)
		return 1 ; 
	if (x >= n || x<0 || y>=m || y<0 || c[x][y] == '#')
		return 0 ; 
	
	ll &ret = dp[x][y]; 
	if (ret != -1)
		return ret ; 
	
	ret = (calc(x+1 , y)%mod + calc(x , y+1)%mod) ;
	ret %= mod ; 
	return ret ; 
}
int main() {

	memset(dp , -1 , sizeof dp) ; 
	scanf("%d %d" , &n , &m) ; 
	for (int i = 0 ; i<n ; ++i) {
		for (int j = 0 ; j<m  ; ++j) {
			cin>>c[i][j] ; 
		}
	}
	ll ans = calc(0 , 0)%mod ; 
	
	printf("%lld\n" , ans) ; 
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  ll n,a,b; cin>>n>>a>>b;
  

  
  
  cout<<min(a*n,b)   <<endl;
  return 0;
}

Measured memory_bytes: 764
#include <stdio.h> 

int main(void)
{	
	int H, W, i, j;

	while(1)
	{
		scanf("%d %d",&H, &W);

		if(H != 0 && W != 0)
		{
			for(i = 0; i < H; i++)
			{
				for(j = 0; j < W; j++)
				{
					if((i%2 == 0 && j%2 == 0) || (i%2 == 1 && j%2 == 1))
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
				printf("\n");
			}
			printf("\n");
		}
		else
		{
			break;
		}
	}
	 

	return 0;
}

Measured memory_bytes: 572
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;
 
 
signed main()
{
int N, T;
int ans = INF;
 
cin >> N >> T;
for (int i = 0; i < N; ++i) {
int c, t;
cin >> c >> t;
if (t <= T) {
chmin(ans, c);
}
}
 
if (ans >= INF) {
puts("TLE");
} else{
cout << ans << endl;
}
return 0;
}

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

typedef long long ll;
typedef long double ld;

ll niz[2005];
ll dp[2005][2005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    ll n, x;
    cin >> n >> x;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    ll mn = 1000000000000000000LL;
    for(ll k=0; k<=n-1; k++){
        ll sum = 0;
        for(int i=1; i<=n; i++){
            if(k == 0) dp[k][i] = niz[i];
            else dp[k][i] = min(niz[i], dp[k-1][i-1]);
            sum += dp[k][i];
        }
        dp[k][0] = dp[k][n];
        mn = min(mn, sum+k*x);
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include<string>
#include<math.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !

int a,b,n;
while(cin>>a>>b){

n=a+b;
n=log10(n)+1;

cout<<n<<endl;
}
return 0;
}

Measured memory_bytes: 1204
#include <iostream>

using namespace std;

int N;

int main(){
    cin >> N;
    if(N < 10){
        cout << N << endl;
        return 0;
    }
    if(N < 100){
        cout << 9 << endl;
        return 0;
    }
    if(N < 1000){
        cout << N - 99 + 9 << endl;
        return 0;
    }
    if(N < 10000){
        cout << 909 << endl;
        return 0;
    }
    if(N < 100000){
        cout << N - 9999 + 909 << endl;
        return 0;
    }
    cout << 90909 << endl;
    return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;
const double PI = 3.141592653589793238;
int cnt[200000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for (ll i = K; i <= N + 1; i++) {
        ll low = i * (i - 1) / 2;
        ll high = i * (2 * N - i + 1) / 2;
        (ans += high - low + 1) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <iomanip>
using namespace std;
long Nchoose2(long n){
    return n*(n-1)/2;
}
int main(){
  int n;
  cin >> n;
  int ans = 0;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
      cin >> a[i];
      a[i]--;
  }
  vector<int> cnt(n);
  for(int i = 0; i < n; i++){
      cnt[a[i]]++;
  }
  long tot = 0;
  for(int i = 0; i < n; i++){
      tot += Nchoose2(cnt[i]);
  }
  

  for(int i = 0; i < n; i++){
      long ans = tot;
      ans -= Nchoose2(cnt[a[i]]);
      ans += Nchoose2(cnt[a[i]]-1);
      cout << ans << endl; 
  }
  
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,C;
  cin >> N >> C;
  int s[N],t[N],c[N];
  bool u[N];
  vector<P> start;
  vector<P> stop;
  for (int i = 0; i < N; i++) {
    u[i] = false;
    cin >> s[i] >> t[i] >> c[i];
    c[i]--;
    start.push_back(make_pair(s[i],c[i]));
    stop.push_back(make_pair(t[i],c[i]));
  }
  sort(start.begin(),start.end());
  sort(stop.begin(),stop.end());

  vector<int> Data(33);
  bool used[33];
  for (int i = 0; i <= 32; i++) {
    Data[i] = -1;
    used[i] = false;
  } 
  

  for (int i = 1; i <= 100060; i++) {
    if (lower_bound(stop.begin(),stop.end(),make_pair(i+1,-100)) - lower_bound(stop.begin(),stop.end(),make_pair(i,-100)) != 0) {
      for (int j = lower_bound(stop.begin(),stop.end(),make_pair(i,-100)) - stop.begin(); j < N; j++) {
        if (stop[j].F != i) {
          break;
        }
        if (lower_bound(start.begin(),start.end(),make_pair(i+1,-100)) - lower_bound(start.begin(),start.end(),make_pair(i,-100)) != 0) {
          
        for (int s = lower_bound(start.begin(),start.end(),make_pair(i,-100)) - start.begin(); s < N; s++) {
          if (start[s].S == stop[j].S) {
            u[j] = true;
          }
          if (s == N-1) {
            break;
          }
          if (start[s+1].F != i) {
            break;
          }
        }
        if (!u[j]) {
          break;
        }
        for (int k = 0; k <= 32; k++) {
          if (Data[k] == stop[j].S) {
            used[k] = true;
            Data[k] = -1;
            break;
          }
        }
        }
        if (j == N-1) {
          break;
        }
        if (stop[j+1].F != i) {
          break;
        }
      }
    }
    
    if (lower_bound(start.begin(),start.end(),make_pair(i+1,-100)) - lower_bound(start.begin(),start.end(),make_pair(i,-100)) != 0) {
      for (int j = lower_bound(start.begin(),start.end(),make_pair(i,-100)) - start.begin(); j < N; j++) {
        for (int k = 0; k <= 32; k++) {
          if (Data[k] == -1) {
            used[k] = true;
            Data[k] = start[j].S;
            break;
          }
        }
        if (j == N-1) {
          break;
        }
        if (start[j+1].F != i) {
          break;
        }
      }
    }

    if (lower_bound(stop.begin(),stop.end(),make_pair(i+1,-100)) - lower_bound(stop.begin(),stop.end(),make_pair(i,-100)) != 0) {
      for (int j = lower_bound(stop.begin(),stop.end(),make_pair(i,-100)) - stop.begin(); j < N; j++) {
        if (u[j]) {
          break;
        }
        for (int k = 0; k <= 32; k++) {
          if (Data[k] == stop[j].S) {
            used[k] = true;
            Data[k] = -1;
            break;
          }
        }
        if (j == N-1) {
          break;
        }
        if (stop[j+1].F != i) {
          break;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 32; i++) {
    if (used[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define debug(args...) fprintf(stderr,args)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int N = 5e6 + 5;
const ll inf = 1791791791;
const ll mod = 1e9+7;

int a[N];

int main() {
	int n; scanf("%d", &n);
	for (int i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	ll mn = inf;
	for (int j=-100;j<=100;j++) {
		ll cost = 0;
		for (int i=0;i<n;i++) {
			cost += (a[i]-j)*(a[i]-j);
		}
		mn = min(mn, cost);
	}
	printf("%lld\n", mn);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct BIT{
  ll M=1;
  vector<ll> dat;
  BIT(ll N){
    while(N>M) M*=2;
    dat.resize(M*2-1, 0);
  }
  void update(ll x, ll k){
    for(int i=k+1;i<=M;i+=(i&(-i))){
      dat[i] += x;
    }
  }
  ll sum(ll r){
    ll ret = 0;
    for(int k=r;k>0;k-=(k&(-k))) ret += dat[k];
    return ret;
  }

  ll query(ll l, ll r){
    return sum(r) - sum(l);
  }
};

int main(int argc, char const *argv[]) {
  ll n, q;std::cin >> n >> q;
  vll c(n);
  vvl x = VV(n, 0, 0, ll);
  re(i, n) {
    scanf("%lld",&c[i]);
    c[i]--;
    x[c[i]].push_back(i);
  }
  BIT seg(n+1);

  vll ans(q, 0);
  vector<vector<pair<ll, ll>>> d(n);
  for(int i=0;i<q;i++){
    ll l, r;std::cin >> l >> r;
    l--, r--;
    d[r].push_back(pair<ll, ll>(l, i));
  }
  for(int i=0;i<n;i++){
    ll now = c[i];
    auto itr = lower_bound(all(x[now]), i);
    ll pre = 0;
    if(itr!=x[now].begin()){
      itr--;
      pre = (*itr) + 1;
    }

    seg.update(1, i);
    if(pre!=0) seg.update(-1, pre-1);
    for(auto v:d[i]){
      ll l = v.first;
      ll idx = v.second;
      ans[idx] = seg.query(l, i+1);
    }
  }
  re(i, q) std::cout << ans[i] << '\n';
  return 0;
}


Measured memory_bytes: 72044
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 2019
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
int dp[2][2019];
int main()
{
	IOS;
	string s;
	cin>>s;
	if(s.size()<4)
	return cout<<0,0;
	ll ans=0;
	for(int i=0;i<s.size();i++)
	{
		dp[1][s[i]-'0']++;
		for(int j=0;j<2019;j++)
		{
			dp[1][((j*10)+s[i]-'0')%M]+=dp[0][j];
		}
		for(int j=0;j<2019;j++)
		{
			dp[0][j]=dp[1][j];
			dp[1][j]=0;
		}
		ans+=dp[0][0];
	}
	cout<<ans<<endl;
	
}



Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  char A,B;
  cin >> A >> B;
  if (A > B) {
    cout << ">" << endl;
  } else if (A < B) {
    cout << "<" << endl;
  } else {
    cout << "=" << endl;
  }
}

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

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

using namespace std;

pair<int,int> expr(const string &s, int i, bool top = false);

pair<int,int> num(const string &s, int i) {
  if (i >= s.size()) throw "invalid expr";
  int v = 0;
  while(i < s.size() && '0' <= s[i] && s[i] <= '9') {
    v *= 2;
    v += s[i] - '0';
    if (v < 0 || v >= 1024) throw "invalid number";
    ++i;
  }
  return make_pair(v, i);
}

pair<int,int> factor(const string &s, int i) {
  if (i >= s.size()) throw "invalid expr";
  if (s[i] == '(') {
    auto p = expr(s, i+1);
    if (p.second >= s.size() || s[p.second] != ')') throw "invalid expr";
    ++p.second;
    return p;
  }
  if (s[i] < '0' || '9' < s[i]) throw "invalid expr";
  return num(s, i);
}

tuple<int,int,bool> term(const string &s, int i, bool top) {
  if (i >= s.size()) throw "invalid expr";
  int v;
  tie(v, i) = factor(s, i);
  while(i < s.size() && s[i] == '*') {
    top = true;
    auto p = factor(s, i+1);
    v *= p.first;
    if (v < 0 || v >= 1024) throw "invalid number";
    i = p.second;
  }
  return make_tuple(v, i, top);
}

pair<int,int> expr(const string &s, int i, bool top) {
  if (i >= s.size()) throw "invalid expr";
  int v;
  tie(v, i, top) = term(s, i, top);
  while(i < s.size() && (s[i] == '+' || s[i] == '-')) {
    top = true;
    auto p = term(s, i+1, true);
    if (s[i] == '+') v += get<0>(p);
    else v -= get<0>(p);
    if (v < 0 || v >= 1024) throw "invalid number";
    i = get<1>(p);
  }
  if (i < s.size() && s[i] != ')') throw "invalid expr";
  if (!top) throw "invalid expr";
  return make_pair(v, i);
}

int maxv(string &s, int i) {
  if (i == s.size()) {
    try {
      auto p = expr(s, 0, true);
      if (p.second != s.size()) return -1;
      return p.first;
    } catch(...) {
      return -1;
    }
  }
  if (s[i] == '.') {
    string chars = "01+-*()";
    int mx = -1;
    REP(j,7) {
      s[i] = chars[j];
      mx = max(mx, maxv(s, i+1));
    }
    s[i] = '.';
    return mx;
  } else {
    return maxv(s, i+1);
  }
}

int main() {
  string s;
  cin>>s;
  cout << maxv(s, 0) << endl;
  return 0;
}

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

main() {
  int n, k;
  cin >> n >> k;
  int a=1,b,c;
  for(int i = 0;i < n;i++){
    b = a*2;
    c = a+k;
    a = min(b,c);
  }
  cout << a <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int f(int n1)
{
	int tmp=0;
	while(n1)
	{
		tmp+=1;
		n1/=10;
	} 
	return tmp;
}
int main()
{
	int a,b,c,n,m=1,i,j;
	scanf("%d %d",&a,&b);
	n=f(b);
	for(i=0;i<n;i++)
	{
		m*=10;
	}
	c=a*m+b;
	for(i=1;i<=c;i++)
	{
		if(c==i*i)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
} 

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

int main(){
  int H, W, N; cin >> H >> W >> N;
  int M = max(H, W);
  int ans = N / M;
  if (N % M != 0) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<climits>
#include<cmath>

using namespace std;

void show( int arr[], unsigned int size )
{
	cout<<arr[0]<<flush;
	for( unsigned int i=1; i<size; i++ ){
		cout<<' '<<arr[i]<<flush;
	}
	cout<<endl;
}


int merge( int arr[], int arr_s, int lft, int md, int rgt)
{
	int cntr=0;

	int left_s=md-lft, right_s=rgt-md;
	int *left=new int[left_s+1], *right=new int[right_s+1]; //????????????????????¨???????????????????????????

	for( int i=0; i<left_s; i++ ){
		left[i]=arr[lft+i];
	}
	for( int i=0; i<right_s; i++ ){
		right[i]=arr[md+i];
	}

	left[left_s]=INT_MAX;
	right[right_s]=INT_MAX;
	
	for( int i=0, j=0, k=lft ; k<rgt; k++, cntr++ ){
		if( left[i] <= right[j] ){
			arr[k]=left[i];
			++i;
		}else{
			arr[k]=right[j];
			++j;
		}
	}
	return cntr;
}

int mergeSort(int arr[], int arr_s, int lft, int rgt)
{
	static int cntr=0;
	
	if( lft+1 < rgt ){
		int md= (lft + rgt)/2;
		mergeSort(arr, arr_s, lft, md);
		mergeSort(arr, arr_s, md, rgt);
		cntr+= merge(arr, arr_s, lft, md, rgt);
	}
	return cntr;
}

int main()
{
	int *arr, arr_s;
	cin>>arr_s;
	arr=new int[arr_s];
	for( int i=0; i<arr_s; i++ ){
		cin>>arr[i];
	}

	int cnt=mergeSort( arr, arr_s, 0, arr_s );
	show( arr, arr_s );
	cout<<cnt<<endl;
}

Measured memory_bytes: 63932
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,count = 0, min_m = 10000;
  cin >> N >> X;
  vector<int> m(N);
  for(int i = 0; i< N; i++){
    cin >> m.at(i);
    int a = m.at(i);
    X = X - a;
    count++;
    if(min_m > a){
      min_m = a;
    }
  }
  count = count + (X/min_m);
  cout << count << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
	int a,b;
	bool flag = false;
	scanf("%d %d",&a,&b);
	int sum = 1;
	int cnt = 0;
	while(sum<b){
		sum += a;
		sum -= 1;
		cnt++;
		flag = true;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define next next239
#define prev prev239
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve()
{
	ll n,m;
    cin>>m>>n;
    ll t=n*m;
    cout<<t<<endl;
}

int main()
{
    fastIO();
    int t;
    t=1;
    while (t--)
    {
        Solve();
    }
    return 0;
}

Measured memory_bytes: 3688
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    S = sum(A)
    if S > N:
        print(-1)
    else:
        print(N-S)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10132
import java.util.*
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val a = Array(n) { 0L }
        val b = Array(n) { 0L }
        for (i in 0 until n) {
            a[i] = sc.nextLong()
            b[i] = sc.nextLong()
        }
        val pq1 = PriorityQueue<Int>(16, compareBy({ -a[it] - b[it] }, { a[it] }))
        val pq2 = PriorityQueue<Int>(16, compareBy({ -b[it] - a[it] }, { b[it] }))
        for (i in 0 until n) {
            pq1.add(i)
            pq2.add(i)
        }
        

        var ans = 0L
        val f = Array(n) { false }
        for (i in 0 until n) {
            if (i % 2 == 0) {
                var p = pq1.poll()!!
                while (f[p]) p = pq1.poll()
                ans += a[p]
                f[p] = true
            } else {
                var p = pq2.poll()!!
                while (f[p]) p = pq2.poll()
                ans -= b[p]
                f[p] = true
            }
        }

        println(ans)
    }
}


class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A_in(N);
    map<ll, ll> A_cnt;
    rep(i, N) {
        cin >> A_in[i];
        A_cnt[A_in[i]]++;
    }

    ll cnt = 0;
    // kを無視したときの総数
    for (const auto& a : A_cnt) {
        cnt += a.second * (a.second - 1) / 2;
    }

    // k = 1 から順番に出力
    // ひとつ減ると、5個から2個選ぶ -> 4個から2個選ぶになる。
    // 5*4/2 -> 4*3/2
    rep(k, N) {
        switch (A_cnt[A_in[k]]) {
            case 1:
                cout << cnt << endl;
                break;
            case 2:
                cout << cnt - 1 << endl;
                break;
            default:
                // 全体 - nC2 + (n-1)C2
                ll calc = cnt;
                calc -= A_cnt[A_in[k]] * (A_cnt[A_in[k]] - 1) / 2;
                calc += (A_cnt[A_in[k]] - 1) * (A_cnt[A_in[k]] - 2) / 2;
                cout << calc << endl;
                break;
        }
    }

    return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <string>
#include <list>
#include <limits>
#include <type_traits>
#include <vector>

using namespace std;

int main(void) {

    int a, b;
    cin >> a;
    cin >> b;

    a -= b * 2;
    if ( a < 0) {
        a = 0;
    }

    cout << a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,j,N,M,K,ans=0,x,bf;
  cin>>N>>M>>K;
  cin>>bf;
  rep1(i,N){
    cin>>x;
    ans+=min((x-bf)*M,K);
    bf=x;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
vector < pair < ll , ll > > v;
ll pw[62];
ll bar,a,b,foo,ans=0;
int main()
{
	ios_base::sync_with_stdio(false);
	
	cin>>a>>b;
	if(a==b){
		cout << 1 << endl;
		return 0;
	}
	int i,r;
	pw[0]=1;
	for(i=1;i<62;i++) pw[i]=2*pw[i-1];

	for(i=61;i>=0;i--){
		foo=pw[i];

		if((foo&a) != (foo&b)){
			r=i;
			break;
		}
	}
	foo=pw[r];
	a=a%(pw[r+1]);
	b=b%(pw[r+1]);
	ans+=foo-a;
	v.pb(mkp(foo+a,2*foo-1));	
	for(i=r-1;i>=0;i--){
		bar=pw[i];
		if((bar&b)!=0){
			break;
		}
	}
	v.pb(mkp(foo,foo + pw[i+1] -1));
	sort(v.begin(),v.end());
	if(v[0].se < v[1].fi){
		ll aa =ans+ v[0].se-v[0].fi+1 + v[1].se-v[1].fi+1; 
		cout <<aa << endl;
	}
	else{
		ll aa =ans+ max(v[0].se,v[1].se) - v[0].fi +1;
		cout <<aa << endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
def f(t,i,j,ans):
  #print(t,i,j,ans)
  ft=0
  #print("f1")
  if j>0:
    ft+=a[i-1][j-1]
    #print(ft)
    if ft>=t:
      ans+=str(j-1)
      if i-1==0:
        return ans
      return f(t-(ft-a[i-1][j-1]),i-1,j-1,ans)
    
  ft+=a[i-1][j]
  #print(ft)
  if ft>=t:
    ans+=str(j)
    if i-1==0:
      return ans
    return f(t-(ft-a[i-1][j]),i-1,j,ans)
  
  if j<9:
    ft+=a[i-1][j+1]
    #print(ft)
    if ft>=t:
      ans+=str(j+1)
      if i-1==0:
        return ans
      return f(t-(ft-a[i-1][j+1]),i-1,j+1,ans)
  
      


k=int(input())

a=[[1,1,1,1,1,1,1,1,1,1]]
t=9
i=0
while 1:
  i+=1
  a+=[[0,0,0,0,0,0,0,0,0,0]]
  for j in range(10):
    if j==0:
      a[i][0]=a[i-1][0]+a[i-1][1]
    elif j==9:
      a[i][9]=a[i-1][8]+a[i-1][9]
      t+=a[i][9]
    else:
      a[i][j]=a[i-1][j-1]+a[i-1][j]+a[i-1][j+1]
      t+=a[i][j]
    if t>=k:
      ai=i
      aj=j
      break
  if t>=k:
    break
if k>9:
  ans=""
  ans+=str(j)
    
  ans=f(k-(t-a[ai][aj]),ai,aj,ans)
  print(ans)
else:
  print(k)

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int dp[2010][2010];

int main(){
  char buff[2010];
  char ans[2010];
  int anspos;

  while(~scanf("%s", buff)){
    int len = strlen(buff);

    REP(i,len+1) REP(j,len+1) dp[i][j] = 0;

    REP(i,len) REP(j,len){
      if(buff[i] == buff[len - 1 - j]){
	dp[i+1][j+1] = dp[i][j] + 1;
      }
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
    }
    REP(i,len) dp[i+1][len] = max(dp[i+1][len], dp[i][len]);
    REP(j,len) dp[len][j+1] = max(dp[len][j+1], dp[len][j]);
    
    int p1 = len;
    int p2 = len;
    anspos = 0;

    while(p1 != 0 || p2 != 0){
      if(p2 != 0 && dp[p1][p2-1] == dp[p1][p2]){
	p2 = p2 - 1;
      }else if(p1 != 0 && dp[p1-1][p2] == dp[p1][p2]){
	p1 = p1 - 1;
      }else{
	assert(p1 != 0 && p2 != 0);
	assert(dp[p1-1][p2-1] + 1 == dp[p1][p2]);
	ans[anspos++] = buff[p1-1];

	if((dp[len][len]+1)/2 == anspos){
	  for(int i = anspos - 1 - (dp[len][len] % 2); i >= 0; i--)
	    ans[anspos++] = ans[i];
	  ans[anspos] = '\0';
	  break;
	}
	
	p1 = p1 - 1;
	p2 = p2 - 1;
      }
    }

    puts(ans);
  }
  

  return 0;
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

 #define rep(i, a, b) for (int i = a; i <= b; i++)
 #define dep(i, a, b) for (int i = a; i >= b; i--)
 #define vep(i, v) for (int i = 0; i < (int)v.size(); i++)
 #define fill(a, x) memset(a, x, sizeof(a))
 #define pb push_back

 typedef vector<int> Vi;

 const int N = 2000 + 5, M = N * N, INF = 0x3f3f3f3f;

 int n, es;
 int a[N], pre[N];
 Vi all, cur;
 bool vis[N];

 struct Edge { int from, to, pre; } e[M];
 inline void init_graph() { es = 0; fill(vis, 0); fill(pre, 0); }
 inline void ine(int a, int b) {
 	int i = ++es;
 	e[i].from = a; e[i].to = b; e[i].pre = pre[a];
 	pre[a] = i;
 }
 inline void ine2(int a, int b) { ine(a, b); ine(b, a); }
 #define reg(i, x) for (int i = pre[x]; i; i = e[i].pre)

 inline bool cmp(int x, int y) { return x >= y; }
 inline int gcd(int x, int y) { return (!y) ? x : gcd(y, x % y);}

 inline void merge(Vi &v1, Vi v2) {
 	Vi tmp;
 	int p1 = 0, p2 = 0, s1 = v1.size(), s2 = v2.size();
 	tmp.clear();
 	while (p1 < s1 && p2 < s2) {
 		int x = v1[p1], y = v2[p2];
 		if (a[x] > a[y]) tmp.pb(x), p1++; else tmp.pb(y), p2++;
 	}
 	if (p1 < s1) rep(i, p1, s1 - 1) tmp.pb(v1[i]);
 	else rep(i, p2, s2 - 1) tmp.pb(v2[i]);
 	v1 = tmp;
 }

 inline Vi dfs(int x) {
 	vis[x] = true;
 	Vi ret, cur;
 	ret.clear();
 	ret.pb(0);
 	reg(i, x) {
 		int y = e[i].to;
 		if (!vis[y]) {
 			cur = dfs(y);
 			merge(ret, cur);
 		}
 	}
 	ret[0] = x;
 	return ret;
 }

int main()
{
	scanf("%d", &n);
	a[0] = INF;
	rep(i, 1, n) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, cmp);

	init_graph();
	rep(i, 1, n - 1) rep(j, i + 1, n)
		if (gcd(a[i], a[j]) > 1) ine2(i, j);

	all.clear();
	dep(i, n, 1) if (!vis[i]) {
		cur = dfs(i);
		merge(all, cur);
	}
	rep(i, 0, n - 2) printf("%d ", a[all[i]]);
	printf("%d\n", a[all[n - 1]]);
	return 0;
}


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

int x[202020];
int l[202020][20], r[202020][20];
int dpl[1 << 20], dpr[1 << 20];

void solve() {
        int n, v;
        cin >> n >> v;
        for (int i = 0; i < n; i ++) cin >> x[i];
        int p;
        for (int i = 0; ; i ++) if ((1 << i) > v) {
                p = i + 1;
                break;
        }
        for (int i = 0; i < n; i ++) {
                int vv = v;
                for (int j = 0; j < p; j ++) {
                        if (i == 0 || x[i] - x[i - 1] > vv) l[i][j] = i;
                        else l[i][j] = l[i - 1][j];
                        vv /= 2;
                }    
        }
        for (int i = n - 1; i >= 0; i --) {
                int vv = v;
                for (int j = 0; j < p; j ++) {
                        if (i == n - 1 || x[i + 1] - x[i] > vv) r[i][j] = i;
                        else r[i][j] = r[i + 1][j];
                        vv /= 2;
                }
        }
        for (int i = 0; i < (1 << p); i ++) {
                if (i & 1) continue;
                for (int j = 1; j < p; j ++) {
                        if ((i >> j) & 1) continue;
                        if (dpr[i] == n) dpr[i | (1 << j)] = n;
                        else dpr[i | (1 << j)] = max(dpr[i | (1 << j)], r[dpr[i]][j] + 1);
                }
        }
        for (int i = 0; i < (1 << p); i ++) dpl[i] = n - 1;
        for (int i = 0; i < (1 << p); i ++) {
                if (i & 1) continue;
                for (int j = 1; j < p; j ++) {
                        if ((i >> j) & 1) continue;
                        if (dpl[i] == -1) dpl[i | (1 << j)] = -1;
                        else dpl[i | (1 << j)] = min(dpl[i | (1 << j)], l[dpl[i]][j] - 1);
                }
        }
        bool ok = false;
        for (int i = 0; i < n; i ++) {
                if (l[i][0] == i) {
                        int c = 0;
                        for (int j = 0; j < (1 << p); j ++) {
                                c ++;
                                if (j & 1) continue; 
                                if (i > 0 && dpr[j] < i) continue;
                                if (r[i][0] < n - 1 && dpl[((1 << p) - 1 - j) - 1] > r[i][0]) continue;
                                break;
                        }
                        if (c < (1 << p)) ok = true;
                        else ok = false;
                }
                if (ok) cout << "Possible" << endl;
                else cout << "Impossible" << endl;
        }
        return;
}

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


Measured memory_bytes: 42752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;




int main(){
    ll N;
    cin >> N;
    vector<double> A(N,0);
    for(int i=0;i<N;i++){
        cin>>A[i]
    ;}
    vector<double> B(N,0.00000000000);
    for(int i=0;i<N;i++){
        B[i]=1/A[i]
    ;}
    double bunbo=0.0000000000;
    for(int i=0;i<N;i++){bunbo+=B[i]
    ;}
    double ans=1/bunbo;
    cout << fixed << setprecision(10);
    cout<<ans<<endl;

return 0;


}  



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

using namespace std;

int n, A, B, C, l[10], minim=1e9;

void bkt(int a, int b, int c, int lvl, int cost)
{
    if (lvl==n+1)
    {
        if (b==B || a==A || c==C)
            return;
        minim=min(minim, abs(a)+abs(b)+abs(c)+cost-30);
        return ;
    }
    bkt(a, b, c, lvl+1, cost);
    if (a>0)
        bkt(a-l[lvl], b, c, lvl+1, cost+10);
    if (b>0)
        bkt(a, b-l[lvl], c, lvl+1, cost+10);
    if (c>0)
        bkt(a, b, c-l[lvl], lvl+1, cost+10);
}

int main()
{
    cin>>n>>A>>B>>C;
    for (int i=1; i<=n; i++)
        cin>>l[i];
    bkt(A, B, C, 1, 0);
    cout<<minim;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp

4.73[s]??§????????????AC
"""
from enum import Enum
from heapq import heappush, heappop


class Sssp(object):
    """ single source shortest path """
    class Status(Enum):
        """ ?????????????¨??????¶??? """
        white = 1  # ????¨????
        gray = 2  # ?¨???????
        black = 3  #?¨???????

    def __init__(self, V, data):
        num_of_nodes = V
        self.color = [Sssp.Status.white] * num_of_nodes  # ????????????????¨??????¶???
        self.d = [float('inf')] * num_of_nodes  # ?§???????????????????
        self.p = [-1] * num_of_nodes  # ????????????????????????????¨?????????????????????????
        self.adj = [[] for _ in range(num_of_nodes)]
        self.make_adj(data)


    def make_adj(self, data):
        # ??£??\??????????????????
        for f, t, c in data:
            self.adj[f].insert(0, (t, c))
            # self.adj[t].insert(0, (f, c))

    def dijkstra(self, start):
        self.d[start] = 0
        pq = []
        heappush(pq, (0, start))

        while pq:
            cost, u = heappop(pq)
            self.color[u] = Sssp.Status.black
            if self.d[u] < cost:
                continue

            for v, cost in self.adj[u]:
                if self.color[v] == Sssp.Status.black:
                    continue
                if self.d[v] > self.d[u] + cost:
                    self.d[v] = self.d[u] + cost
                    heappush(pq, (self.d[v], v))
                    self.color[v] = Sssp.Status.gray


def solve(V, r, data):
    WHITE = 0
    GRAY = 1
    BLACK = 2
    num_of_nodes = V
    color = [WHITE] * num_of_nodes  # ????????????????¨??????¶???
    d = [float('inf')] * num_of_nodes  # ?§???????????????????
    adj = [[] for _ in range(num_of_nodes)]

    for f, t, c in data:
        adj[f].insert(0, (t, c))

    # dijkstra
    d[r] = 0
    pq = []
    heappush(pq, (0, r))

    while pq:
        cost, u = heappop(pq)
        color[u] = BLACK
        if d[u] < cost:
            continue

        for v, cost in adj[u]:
            if color[v] == BLACK:
                continue
            if d[v] > d[u] + cost:
                d[v] = d[u] + cost
                heappush(pq, (d[v], v))
                color[v] = GRAY

    # ???????????¨???
    for i in range(V):
        if d[i] == float('inf'):
            print('INF')
        else:
            print('{}'.format(d[i]))


if __name__ == '__main__':
    # ??????????????\???
    V, E, r = [int(x) for x in input().split(' ')]
    data = []
    for i in range(E):
        data.append(list(map(int, input().split(' '))))

    # ???????????¢?´¢
    solve(V, r, data)

Measured memory_bytes: 195896
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w,n=map(int,input().split())
    i0,j0=map(int,input().split())
    S=input()
    T=input()

    u,d,l,r=1,h,1,w
    for t,s in zip(T[::-1],S[::-1]):
        if(t=='U'): d=min(h,d+1)
        elif(t=='D'): u=max(1,u-1)
        elif(t=='L'): r=min(w,r+1)
        elif(t=='R'): l=max(1,l-1)

        if(s=='U'): u+=1
        elif(s=='D'): d-=1
        elif(s=='L'): l+=1
        elif(s=='R'): r-=1
        if(u>d or l>r):
            print("NO")
            return

    print("YES" if(u<=i0<=d and l<=j0<=r) else "NO")
resolve()

Measured memory_bytes: 47148
#include<stdio.h>
int main()
{
    int K,A,B,i=1,mul;
    scanf("%d %d %d",&K,&A,&B);
    while(mul<=B)
    {

       mul=K*i;
       i++;
if(mul>=A&&mul<=B)
    break;
    }
    if(mul>=A&&mul<=B)
       printf("OK\n");
       else
        printf("NG\n");
       return 0;
}


Measured memory_bytes: 1640
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingDeque;

public class Main {

	public static class Insect implements Comparable<Insect>{
		char[] ch;
		int sec;
		
		public Insect(char[] ch, int sec) {
			super();
			this.ch = ch;
			this.sec = sec;
		}

		@Override
		public int compareTo(Insect arg0) {
			return this.sec - arg0.sec;
		}
		
		@Override
		public int hashCode(){
			int hash = 0;
			
			for(int i = 0; i < ch.length; i++){
				if(ch[i] == 'r'){
					hash += 1;
				}else if(ch[i] == 'g'){
					hash += 2;
				}else{
					hash += 3;
				}
				
				if(i != ch.length - 1){
					hash <<= 2;
				}
			}
			
			return hash;
		}
		
		@Override
		public boolean equals(Object o){
			return o instanceof Insect && o.hashCode() == this.hashCode();
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		
		while (true) {
			String str = sc.next();
			
			if("0".equals(str)){
				break;
			}
			
			PriorityQueue<Insect> queue = new PriorityQueue<Insect>();
			HashSet<Insect> visited = new HashSet<Insect>((int) Math.pow(3, str.length()));
			
			
			queue.add(new Insect(str.toCharArray(), 0));
			
			int min = -1;
			
			while(!queue.isEmpty()){
				Insect is = queue.poll();
				
				if(visited.contains(is)){
					//System.out.println("!!! duplicate !!! " + Arrays.toString(is.ch) + " " + is.hashCode() + " " + is.sec);
					continue;
				}
				visited.add(is);
				
				boolean flag = true;
				for(int i = 0; i < is.ch.length - 1; i++){
					if(is.ch[i] != is.ch[i+1]){
						flag = false;
						break;
					}
				}
				
				if(flag){
					min = is.sec;
					break;
				}
				
				for(int i = 0; i < is.ch.length - 1; i++){
					if(is.ch[i] != is.ch[i+1]){
						char[] tmp = new char[is.ch.length];
						System.arraycopy(is.ch, 0, tmp, 0, is.ch.length);						
						
						if(is.ch[i] == 'r'){
							if(is.ch[i+1] == 'g' ){
								tmp[i] = tmp[i+1] = 'b';
							}else if(is.ch[i+1] == 'b' ){
								tmp[i] = tmp[i+1] = 'g';
							}
						}else if(is.ch[i] == 'g'){
							if(is.ch[i+1] == 'r' ){
								tmp[i] = tmp[i+1] = 'b';
							}else if(is.ch[i+1] == 'b' ){
								tmp[i] = tmp[i+1] = 'r';
							}
						}else{
							if(is.ch[i+1] == 'r' ){
								tmp[i] = tmp[i+1] = 'g';
							}else if(is.ch[i+1] == 'g' ){
								tmp[i] = tmp[i+1] = 'r';
							}
						}
						
						Insect t = new Insect(tmp,is.sec+1);
						
						if(!visited.contains(t)){
							queue.add(t);
						}else{
							//System.out.println("!!! duplicate !!! " + Arrays.toString(is.ch) + " " + is.hashCode() + " " + is.sec);
						}
					}
				}
				
			}
			
			if(min != -1){
				System.out.println(min);
			}else{
				System.out.println("NA");
			}
			
			
		}

	}
}

Measured memory_bytes: 17000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i, sz(s)) {
        s[i] += n;
        if (s[i] > 'Z') s[i] -= 26;
    }
    cout << s << endl;
}


Measured memory_bytes: 3680