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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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


int main() {
	int a, b, c, d, e,k;
	cin >> a >> b >> c >> d >> e >> k;

	if (e - a <= k) {
		ANS("Yay!");
	}
	else {
		ANS(":(")
	}

	return 0;
}


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

int main()
{
    std::vector<int> a;
    a.resize(3);

    std::cin >> a[0] >> a[1] >> a[2];

    std::sort(a.begin(), a.end());

    std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;

    return 0;
}


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

int main(){
  int m, r, f, sum;
  for(;;){
    cin >> m >> f >> r;
    sum = m + f;
    if( m == -1 && r == -1 && f == -1 ) break;
    if( m == -1 || f == -1 ) cout << "F" << endl;
    else if( sum >=  80 ) cout << "A" << endl;
    else if( sum <  80 && sum >= 65 ) cout << "B" << endl;
    else if( sum < 65 && sum >= 50 ) cout << "C" << endl;
    else if( sum < 50 && sum >= 30){
      if( r >= 50 ) cout << "C" << endl;
      else cout << "D" << endl;
    }
    else cout << "F" << endl;
  }
  return 0;
}


Measured memory_bytes: 3084
n,m=map(int,input().split())
l=list(range(2,n+1))
v=[[] for i in range(1+n)]
for i in range(m):
    a,b=map(int,input().split())
    v[a].append(b)
    v[b].append(a)

def check(ls):
    fr=1
    for to in ls:
        if int(to) not in v[fr]:
            return 0
        fr=int(to)
    return 1

def gen(ls):
    if not ls:
        return [[]]
    return [[a]+b for i,a in enumerate(ls) for b in gen(ls[:i]+ls[i+1:])]
    
print(sum([check(i) for i in gen(l)]))

Measured memory_bytes: 49880
def nC2(n):
    return n*(n-1)//2


N = int(input())
A = list(map(int, input().split()))
combi = {}

for i in A:
    try:
        combi[i] += 1
    except KeyError:
        combi[i] = 1

total = sum(nC2(i) for i in combi.values())

for i in range(N):
    ans = total - nC2(combi[A[i]])
    ans += nC2(combi[A[i]] - 1)
    print(ans)


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    bool ok = true;
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<ll> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    if(x >= y) ok = false;
    sort(ALL(a));
    sort(ALL(b));
    if(a[n-1] >= b[0]) ok = false;
    if(a[n-1] >= y) ok = false;
    if(b[0] <= x) ok = false;

    if(ok) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define END(a) {cout << (a) << "\n"; return 0;}
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

VL a, f;
int n; ll k; 
bool check(ll x) {
    ll cnt = 0;
    FOR(i, 0, n) {
        if (a[i] * f[i] <= x)continue;
        cnt += a[i] - x / f[i];
    }
    return cnt <= k;
}

int main() {
    init();

    cin >> n >> k;
    a.resize(n), f.resize(n);
    cin >> a >> f;
    rSORT(f, greater<ll>()), SORT(a);
    ll ng = -1, ok = 1000000000001LL;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int a;
    cin >> a;
    cout << "ABC" << a << endl;
}

Measured memory_bytes: 256
#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;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long 
#define int ll
//#define slld(t) scanf("%lld",&t)
// #define sd(t) scanf("%d",&t)
// #define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define pdd pair<double , double>
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N    200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
#define s3   1.73205080757          // square root 3
const  int inf = (int)1e18+10 ;
const int MAX= 100;

 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set S;

int powmod(int x , int y){
	int res = 1;
	while(y > 0){
		if(y%2==1)
			res = (res*x)%mod;
		x = (x*x)%mod;
		y/=2;
	}
	return res;
}
int mul(int x , int y){
	return (x*y)%mod;
}



signed main(){
  fast;
 
  int n , p , q;
  cin >> n >> p >> q;
  int diff = abs(p - q);
  if(diff%2 == 0){
  	cout << (diff / 2) << endl;
  	return 0;
  }
  int a = p , b = q;
  if(a > b) swap(a , b);
  int ans = 0;
  ans += a;
  b-=a;
  ans += (b-1)/2;
  a = p;
  b = q;
  if(a > b) swap(a , b);
  int ans2 = 0;
  ans2 += (n-b) + 1;
  a += (n-b) + 1;
  ans2 += (n-a)/2;
  cout << min(ans , ans2)<< endl;
 }

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> fi(H);
	rep(i, H) cin >> fi[i];
	rep(i, H) rep(j, 2) cout << fi[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,X,T;
  cin >> N >> X >> T;
  
  int time;
  
  if( N%X == 0) time=N/X;
  else time= N/X+1;
  
  cout << T*time << endl;
}  

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count = 0;
  int Y = X;
  
  for (int i = 0; i < A+1; i++) {
    
    if (Y - i * 500 >= 0) {
      Y = Y - i * 500;
      
      for (int j = 0; j < B+1; j++) {
        if (Y - j * 100 >= 0 && (Y - j * 100) / 50 <= C) {
          count++;
        }
      }
    }
    Y = X;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n+1];
		for(int i = 0; i < m; i++){
		    a[sc.nextInt()] = 1;
    }
		// 計算
		long result = 0;
		long[] dp = new long[n+1];
		for(int i = 1; i < n+1; i++){
		    if(a[i] == 1){
		        dp[i] = 0;
		    }else if(i == 1){
		        dp[i] = 1;
		    }else if(i == 2){
		        dp[i] = dp[i-1] + 1;
		    }else{
            dp[i] = dp[i-1] + dp[i-2];
            dp[i]%=1000000007;
		    }
    }
		result = dp[n];
		// 出力
		System.out.println(result);
		
	}
}


Measured memory_bytes: 49580
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int sum =0;
		if (A>B) {
			sum +=B;
		} else {
			sum +=A;
		}
		if (C>D) {
			sum +=D;
		} else {
			sum +=C;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23764
from collections import deque
n=int(input())
a=list(map(str,input().split()))
d=deque()
for i in range(n):
    if i%2==0:
        d.appendleft(a[i])
    else:
        d.append(a[i])
d=list(d)
if n%2==0:
    d=d[::-1]
print(" ".join(d))

Measured memory_bytes: 26564
#include <cstdio>

constexpr long long mod = 1000000007;
long long dp[10002][100][2];

int main()
{
  char s[100002];
  int D;
  scanf("%s%d", s, &D);

  dp[0][0][0] = 1;
  int i;
  for (i = 0; s[i]; ++i)
  {
    int d = s[i] - '0';
    for (int j = 0; j < 2; ++j)
    {
      for (int m = 0; m < D; ++m)
      {
        for (int k = 0; k <= (j ? 9 : d); ++k)
        {
          (dp[i + 1][(m + k) % D][j || k < d] += dp[i][m][j]) %= mod;
        }
      }
    }
  }
  printf("%lld\n", (dp[i][0][0] + dp[i][0][1] + mod - 1) % mod);
  return 0;
}

Measured memory_bytes: 15744
#include <stdio.h>
#include <string.h>
void rev(char* s) {
    int i, l = strlen(s);
    for (i = 0; i < l / 2; i++) {
        char t = s[i];
        s[i] = s[l - i - 1];
        s[l - i - 1] = t;
    }
 
 
}
int main(void) {
    char T[4][8]={"dream","dreamer","erase","eraser"};
    char buf[100001];
    int i;
    int k, c = 0;
 
    scanf("%s",buf);
    rev(buf);
  
    for (i = 0; i < 4; i++)
        rev(T[i]);
  
    int l=strlen(buf);
while(c<l){
  k=-1;
    for (i = 0; i < 4; i++) {
        if (!strncmp(buf + c, T[i], strlen(T[i]))) {
            k = strlen(T[i]);
            break;
        }
    }
        if(k<0){
            printf("NO");
            return 0;
        }
        c += k;
    }
  printf("YES");
        return 0;
    }

Measured memory_bytes: 1832
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int H, W;
  cin >> H >> W;

  vector<string> C(H);
  REP(i, H) cin >> C[i];
  
  REP(i,H){
    cout << C.at(i) << endl;
    cout << C.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = acos(-1);
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second


int main() {
	ll n, b[200010], sum = 0, ans;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> b[i];
		b[i] -= i;
	}
	sort(b+1, b + n+1);
	for (int i = 1;i <= n;i++) {
		sum += abs(b[i] - b[n / 2 + 1]);
	}
	ans = sum;
	sum = 0;
	for (int i = 1;i <= n;i++) {
		sum += abs(b[i] - b[n / 2]);
	}
	ans = min(ans, sum);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[105];

int cnt[105];
vector <int> Vl;

vector <int> Va;
void vpush(int x) {
	in[x]--;
	Va.push_back(x);
}

vector <int> Vu;
int main() {
	int N, K, i, j, k;
	scanf("%d %d", &N, &K);

	for (i = 1; i <= N; i++) scanf("%d", &in[i]);

	int s = 0;

	vector <pii> Vx;
	for (i = 1; i <= N; i++) {
		int t = max(0, K+1 - in[i]);
		s += t;
		if (t > (K + 1) / 2 || s > K) return !printf("-1\n");

		Vx.emplace_back(t, i);
	}

	for (i = 1; i <= N; i++) {
		if (s == K) break;
		if (in[i] >= K + 1) {
			int t = min((K + 1) / 2, K - s);
			Vx.emplace_back(t, i);
			s += t;
		}
	}
	for (auto &it : Vx) {
		if (s == K) break;
		int t = min((K + 1) / 2 - it.first, K - s);
		s += t;
		it.first += t;
	}

	sort(all(Vx));
	reverse(all(Vx));
	Vl.resize(K);

	vector <int> Vo;
	int p = 0;
	for (i = 1; i < K; i += 2) Vo.push_back(i);
	for (i = 0; i < K; i += 2) Vo.push_back(i);
	reverse(all(Vo));

	for (auto it : Vx) {
		for (i = 1; i <= it.first; i++) Vl[Vo[p++]] = it.second;
	}
	
	for (i = 1; i <= N; i++) if (i != Vl[0]) vpush(i);
	Va.push_back(Vl[0]);

	for (i = 1; i < Vl.size(); i++) {
		for (j = 1; j <= N; j++) if (j != Vl[i - 1] && j != Vl[i]) vpush(j);
		vpush(Vl[i]);
	}
	for (i = 1; i <= N; i++) if (i != Vl.back()) vpush(i);

	printf("%d\n", (int)Va.size());
	for (auto it : Va) printf("%d ", it);
	return !printf("\n");
}

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

bool check(int tn, int tn_1, int xn, int xn_1, int yn, int yn_1){
  int t = tn_1 - tn, x = xn_1 - xn, y = yn_1 - yn, length;
  length = abs(x) + abs(y);
  bool ans = false;
  if(t % 2 == 0){
    if (length <= t && length % 2 == 0){
      ans = true;
    }
  }
  if(t % 2 == 1){
    if (length <= t && length % 2 == 1){
      ans = true;
    }
  }
  return ans;
}

int main(){
  int N;
  cin >> N;
  bool tmp_bool, ans_bool = true;
  vector<vector<int>> vec(N, vector<int>(3));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 3; j++){
      cin >> vec.at(i).at(j);
    }
  }
  tmp_bool = check(0, vec.at(0).at(0), 0, vec.at(0).at(1), 0, vec.at(0).at(2));
  if (tmp_bool == false) ans_bool = false;
  for(int i = 0; i < N - 1; i++){
    tmp_bool = check(vec.at(i).at(0), vec.at(i + 1).at(0), vec.at(i).at(1), vec.at(i + 1).at(1), vec.at(i).at(2), vec.at(i + 1).at(2));
    if (tmp_bool == false) ans_bool = false;
  }
  if (ans_bool) cout << "Yes";
  else cout << "No";
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef vector<ll> vi;
ll n,w, tv =0;
ll weights[101];
ll values[101];

// unordered_map<string,int> dpmap;
// ll dp(int pos, ll weight)
// {

// if(weight<0)
// 		return INT_MIN;
// 	if(pos<0||weight==0)
// 		return 0;
	
// 	string key = to_string(pos)+"|"+to_string(weight);
// 	if(dpmap.find(key)==dpmap.end())
// 	{
// 		ll takeit = dp(pos-1, weight-weights[pos]) + values[pos];
// 		ll thankunext  = dp(pos-1, weight);
// 		dpmap[key] = max(takeit, thankunext);
// 		//cout<<key<<" "<<dpmap[key]<<endl;
// 	}
// 	return dpmap[key];
// } 
// ll dp(int pos, int value)
// {
// 	if(pos==n)
// 		return 0;
// 	if(memo[pos][value]!=-1)
// 		return memo[pos][value];
// 	ll ans = min(dp(pos+1, value + values[pos])-weights[pos], dp(pos+1, value));
// 	return memo[pos][value] = ans;

// }
int main()
{
	cin>>n>>w;
	
	
	for(ll i = 0 ; i < n; i++)
	{
    	cin>>weights[i]>>values[i];
    	tv+=values[i];
	}
	vi memo(tv+5, INT_MAX);
	memo[0] = 0;
	for(int i = 0 ; i < n ; i++)
		for( int j = tv; j>=0; j--)
		{
			if(j>=values[i])
				memo[j]= min(memo[j-values[i]]+weights[i], memo[j]);
		}
	ll ans =0;
	for(ll i = 0; i<=tv ; i++)
		if(memo[i]<=w)
			ans = max(ans, i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int result;
    long int X;

    cin >> X;
    double X_d = (double)X;
	double s = sqrt(X_d*2.0);
	int s_i = (int)s;
	
	
    
    if((1 + s_i)*s_i/2 >= X)
    {
        result = s_i;
        
    }else{
        result = s_i + 1;
    }
    ;
    cout << result << endl;;
    
    
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N;  cin >> N;
    vi A(N);
    REP(i, N) cin >> A[i];
    
    multiset<int> ms;
    REP(i,N) {
        auto it = ms.lower_bound(A[i]);
        if (it != ms.begin()) {
            it--;
            ms.erase(it);
        }
        
        ms.insert(A[i]);
    }

    int ans = ms.size();
    cout << ans << endl;

    return 0;
}


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


int main(void){
//	FILE* fp_in = freopen("data.txt", "r", stdin);
	for(int i=1; i<10; i++){
		for(int j=1; j<10; j++) cout << i << "x" << j << "=" << i*j << endl;
	}
	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};



int main(){
  int n, m;
  std::cin >> n >> m;
  std::vector<long long> x(n), y(m);
  std::vector<Mint > X(n-1), Y(m-1);
  long long tmp;
  for (int i=0; i<n; i++) {
    std::cin >> x[i];
  }
  for (int i=0; i<m; i++) {
    std::cin >> y[i];
  }
  for (int i=0; i<n-1; i++) {
    X[i] = Mint(x[i+1] - x[i]);
  }
  for (int i=0; i<m-1; i++) {
    Y[i] = Mint(y[i+1] - y[i]);
  }

  Mint xsum(0);
  for (int i=0; i<n; i++) {
    xsum += Mint((2*i-n+1)*(x[i]));
    //std::cout << xsum.x << std::endl;
  }
  Mint ysum(0);
  for (int i=0; i<m; i++) {
    ysum += Mint((2*i-m+1)*y[i]);
  }
  Mint ans = xsum * ysum;
  std::cout << ans.x << std::endl;
  return 0;
}

Measured memory_bytes: 5920
#include<stdio.h>
int main(void){
	int n;
	long long  sum = 0;
	int i;
	int money;
	scanf("%d",&n);
	for(i = 0;i < n ;i++){
		scanf("%d",&money);
		sum += (long long)money;
	}
	printf("%d\n",(int)(sum / (long long)n));
	return 0;
}

Measured memory_bytes: 592
'use strict';
function Main(input) {
	input = parseInt(input.trim());
  	let b = 1;
  	let count = 0;
  	for(let a = 1; a< input; a++){
      for(let b = 1; b < input; b ++){
        if( a * b > input){break;}
        if(input-a*b !==0){
          count ++;
        }
      }
    }
	console.log(count);
}



//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32348
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct Point{
    int h,w;
}A[100005];
inline bool cmp_hsws (const struct Point &a, const struct Point &b){
    return a.h<b.h||(a.h==b.h&&a.w<b.w);
}
int Ans[10],n,H,W;
int G[6][6];
void Quest(int h,int w){
    if(h<=0||h>H||w<=0||w>W)return ;
    struct Point t;
    for(int x=-2;x<=2;x++)
        for(int y=-2;y<=2;y++){
            t.h = h+x;
            t.w = w+y;
            int i = lower_bound(A,A+n,t,cmp_hsws)-A;
            if(i<n&&A[i].h==t.h&&A[i].w==t.w)G[x+2][y+2]=1;
            else G[x+2][y+2]=0;
        }
    for(int x=-1;x<=1;x++)
        for(int y=-1;y<=1;y++)
            if(x+h>1&&x+h<H&&y+w>1&&y+w<W){
                int cnt=0;
                for(int tx = -1; tx<=1;tx++)
                    for(int ty=-1;ty<=1;ty++)
                        cnt+=G[tx+x+2][ty+y+2];
                Ans[cnt]++;
                //printf("%d %d %d\n",x+h,y+w,cnt);
            }
    return ;
}
int main(){
    int i,j,k,l;
    scanf("%d%d%d",&H,&W,&n);
    for(i=0;i<n;i++)
        scanf("%d%d",&A[i].h,&A[i].w);
    memset(Ans,0,sizeof(Ans));
    sort(A,A+n,cmp_hsws);
    for(i=0;i<n;i++){
       Quest(A[i].h,A[i].w);
    }
    if(H<2)H=2;
    if(W<2)W=2;
    long long ans0 = ((long long)H-2)*(W-2);
    for(i=1;i<=9;i++)ans0-=Ans[i]/i;
    printf("%lld\n",ans0);
    for(i=1;i<=9;i++)printf("%d\n",Ans[i]/i);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
typedef long long int LL;
int main(){
	LL n,m,a,b;
	int i,j;
	int s=1;
	cin>>n>>m;
	if(n==1){
		cout<<m<<endl;
		return 0;
	}
	if(n>100){
		cout<<1<<endl;
		return 0;
	}
	for(a=1;;a++){
		for(b=1,i=0;i<n;i++){
			b*=a;
			if(b>m){
				cout<<s<<endl;
				return 0;
			}
		}
		if(b>m)break;
		if(m%b==0)s=a;
	}
	cout<<s<<endl;
	return 0;
}
			


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  string t;
  cin >> t;
  int N = s.size();
  int M = t.size();
  vector<set<int>> pos(26);
  for (int i = 0; i < N; i++){
    pos[s[i] - 'a'].insert(i);
  }
  bool ok = true;
  for (int i = 0; i < M; i++){
    if (pos[t[i] - 'a'].empty()){
      ok = false;
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    long long ans = -1;
    for (int i = 0; i < M; i++){
      auto itr = pos[t[i] - 'a'].upper_bound(ans % N);
      if (itr != pos[t[i] - 'a'].end()){
        ans += *itr - ans % N;
      } else {
        ans += N - ans % N;
        auto itr2 = pos[t[i] - 'a'].begin();
        ans += *itr2;
      }
    }
    cout << ans + 1 << endl;
  }
}

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

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

Measured memory_bytes: 256
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

void Flash(){
	ll L, R, d;
	cin>>L>>R>>d;
	ll ans = (R / d) - (L - 1) / d;
	cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long N,M,tmp,sum=0;
	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>tmp;
		sum+=tmp;
	}
	N=N-sum;
	if(N<0)
		cout<<"-1"<<endl;
	else
		cout<<N<<endl;
	
	return 0;
}

Measured memory_bytes: 3656
def div(h, w):
  rep = float("inf")
  for i in range(1, h):
    a = i*w
    d = (h-i)//2
    b = d*w
    c = (h-i-d)*w
    rep = min(rep, max(a, b, c) - min(a, b, c))
    d = w//2
    b = (h-i)*d
    c = (h-i)*(w-d)
    rep = min(rep, max(a, b, c) - min(a, b, c))
  return rep

h, w = map(int, input().split())
print(min(div(h, w), div(w, h)))

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


int main() {
  int A, B, C, K;
  cin >> A >> B >>C >> K;
  bool AC = false;
  for(int i = 0; i < K; i++){
    if(A >= B) B *= 2;
    else  C *= 2;
    if(A < B && B < C){
      AC = true;
    }
  }
  if(AC) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
p = [0]*100001
p[0] = 1
p[1] = 1
p[2] = 2
ans = 1
flag = 0
for i in range(3,100001):
	p[i] = p[i-1] + p[i-2]


n,m = map(int,input().split())
l = [0]*(m+2)
l[m+1] = n
for i in range(m):
	l[i+1] = int(input())

l1 = [0]*(m+1)
for i in range(m+1):
	l1[i] = l[i+1] - l[i]

# print(l1)

if m == 0:
	print(p[n] % 1000000007)
	flag = 1
else:
	for i in range(m+1):
		if i == 0 or i == m:
			ans = ans * p[l1[i]-1]
		else:
			if l1[i] == 1:
				print(0)
				flag = 1
				break
			else:
				if l1[i] == 0:
					ans = ans
				else:
					ans = ans * p[l1[i]-2]

if flag != 1:
	print(ans % 1000000007) 


Measured memory_bytes: 464836
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int parent[200005], ranks[200005];

void initset(int n)
{
	for (int i = 0; i <= n; i++)
	{
		parent[i] = i;
		ranks[i] = 0;
	}
}
// Return representative index
int findset(int x)
{
	// Value of representative index is itself
	if (parent[x] == x)
		return x;
	parent[x] = findset(parent[x]); // Path compression; set value/arrow to representative index
	return parent[x];
}

bool sameset(int x, int y)
{ // Same set would have same rep index
	return findset(x) == findset(y);
}

// Input: 2 nodes which may not be representatives
void mergeset(int x, int y)
{
	x = findset(x);
	y = findset(y);
	if (ranks[x] > ranks[y])
	{
		parent[y] = x;
	}
	else if (ranks[y] > ranks[x])
	{
		parent[x] = y;
	}
	else
	{
		parent[x] = y;
		ranks[y]++;
	}
}

int N, M, K, L;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M;
	initset(N + M + 5); // 5 is buffer
	for (int i = 0; i < N; i++)
	{
		cin >> K;
		for (int j = 0; j < K; j++)
		{
			cin >> L;
			// 1-indexing for people; N+L is for language number, "N"-indexing
			mergeset(i + 1, N + L);
		}
	}

	for (int i = 1; i <= N; i++)
	{
		if (!sameset(i, 1))
		{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

S = input()

f = True
l = len(S)
if l%2 != 0:
    print("No")
    exit()

for i in range(l):

    if (i%2 == 0 and S[i] == "h") or (i%2 == 1 and S[i] == "i"):
        f = True
    else:
        f = False
        break
if f:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){


	int n;
	cin >> n;
	vector<string> s[10];

	s[0].push_back("a");
	rep(i,n-1){
		for(auto t:s[i]){
			char maxi = 'a';
			for(auto c:t)chmax(maxi,c);
			for(char c = 'a';c <= maxi+1;c++){
				string r = t;
				r.push_back(c);
				s[i+1].push_back(r);
			}
		}
	}
	for(auto t:s[n-1])cout << t << endl;

	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://panasonic2020.contest.atcoder.jp/tasks/panasonic2020_d

Measured memory_bytes: 8152
import sys
input = sys.stdin.readline
H, W, A, B = map(int, input().split())
res = [[0] * W for _ in range(H)]
for i in range(B):
  for j in range(A): res[i][j] = 1
for i in range(B, H):
  for j in range(A, W): res[i][j] = 1
for r in res: print("".join(list(map(str, r))))

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

const string YES = "Yes";
const string NO = "No";

auto solve(long long A, long long B, long long C) {
    return ((A <= C) && (C <= B)) ? YES : NO;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  auto result = solve(A, B, C);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n,c; cin >> n >> c;
    ll t_max = 1e5 + 10;
    vvl vec(c,vl(t_max,0));
    rep(i,n){
        ll s,t; cin >> s >> t;
        ll ct; cin >> ct;
        s--;t--;ct--;
        vec[ct][s]++;
        vec[ct][t+1]--;
    }
    rep(i,c)rep(j,t_max-1){
        vec[i][j+1] += vec[i][j]; 
    }
    ll res = 0;
    rep(j,t_max){
        ll temp = 0;
        rep(i,c){
            if(vec[i][j])temp++;
        }
        res = max(res, temp);
    }
    cout << res << endl;
}

Measured memory_bytes: 24576
#include<stdio.h>
int main(void){
	int page,a[50];
	int i,cnt;
	int right;


	while(1){
		scanf("%d",&page);
		if(page==0){
			return 0;
		}
		for(i=0;i<50;i++){
			a[i]=0;
			cnt=0;
		}
		for(i=0;i<page;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<page;i++){
			if(a[i]+1==a[i+1]){
				right=a[i+1];
				cnt++;
			}else{
				if(cnt==0){
					if(i==page-1){
						printf("%d",a[i]);
					}else{
						printf("%d ",a[i]);
					}
				}else{
					if(i==page-1){
						printf("%d-%d",right-cnt,right);
						right=0;
						cnt=0;
					}else{
						printf("%d-%d ",right-cnt,right);
						right=0;
						cnt=0;
					}
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
n=int(input())
s=input()
ans=0
r=[]
b=[]
g=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  if s[i]=='B':
    b.append(i)
  if s[i]=='G':
    g.append(i)
ans=len(r)*len(b)*len(g)
for i in range(n-2):
  for j in range(i+1,n-1):
    if 2*j-i<n and s[2*j-i]!=s[i] and s[i]!=s[j] and s[j]!=s[2*j-i]:
      ans+=-1
print(ans)

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

vector<int> offsets = {0, 1, 0, -1, 0};

vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

int min_steps = INT_MAX;

void solve(){
    int n, m, k; cin >> n >> m >> k;
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;


    vector<string> grid;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            string cur; cin >> cur;
            grid.push_back(cur);
        }
    }
    x1--;
    y1--;
    x2--;
    y2--;

    using P = pair<int,pair<int,int>>;
    queue<P> q;
    q.push(P(0, {x1, y1}));

    vector<vector<int>> dist(n, vector<int>(m, INT_MAX));
    dist[x1][x2] = 0;

    while(!q.empty()){
        P temp = q.front(); q.pop();
        int cost = temp.first;
        int x = temp.second.first; int y = temp.second.second;
        for(int i = 0; i < 4; i++){
            for(int j = 1; j <= k; j++){
                int ny = y + dy[i] * j;
                int nx = x + dx[i] * j;

                // Check borders
                if(nx < 0 || ny < 0 || nx >= n || ny >= m)
                    continue;
                    
                int ncost = cost + 1;
                if(grid[nx][ny] == '@') break;

                if(dist[nx][ny] > ncost){
                    dist[nx][ny] = ncost;
                    q.push(P(ncost, {nx, ny}));
                } else if(dist[nx][ny] == ncost){
                    continue;
                } else {
                    break;
                }
            }
        }
    }

    if(dist[x2][y2] == INT_MAX){
        cout << -1 << endl;
    } else {
        cout << dist[x2][y2] << endl;
    }
    
}

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

    solve();
    
    return 0;
}



Measured memory_bytes: 43360
#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
int main()
{
	int a,b,k;
	cin >> a >> b >> k;
	if(b-a+1<=k)
	{
		for(int i = a;i<=b;i++)cout<<i<<endl;
	}else{
		set<int>s;
		for(int i = a;i<a+k;i++)
		{
			s.insert(i);
		}
		
		for(int j = b;j>b-k;j--)
		{
			s.insert(j);
		}
		
		for(auto & x : s)
		{
			cout << x << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
using namespace std;
int cnt;
int a,b,c;
void solve(){
    for(int i=a;i<=b;i++)
    {
        if(i>c)return ;
        if(c%i==0)cnt++;
    }
}
int main()
{
    cnt=0;
    cin>>a>>b;
    //solve();
    cout<<a/b<<' '<<a%b<<' ';printf("%.5f",(double)a/b);cout<<endl;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int a,li[10];

int main(){
	REP(i,0,3) cin >> a,li[a]++;
	
	cout << (li[5]==2&&li[7]==1?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int ans = s.size();

    for(char c = 'a'; c <= 'z'; c++) {
        int cnt = 0;
        int tmp = 0;

        rep(j, s.size()) {

            if(s[j] == c) {
                tmp = max(tmp, cnt);
                cnt = 0;
            }
            else {
                cnt++;
            }
        }

        tmp = max(tmp, cnt);
        ans = min(ans, tmp);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;


int main(int argc, char const* argv[])
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    LL ans = 0;
    LL now;
    for (int r = 0; r < 3000 + 10; r++) {
        for (int g = 0; g < 3000 + 10; g++) {
            now = N - R * r - G * g;
            if (now >= 0 && now % B == 0) {
                ans += 1;
            }
            if (now < 0) {
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace csharptest
{
    class Program
    {
        static void trace(int []A,int N)
        {
            for (int i = 0; i < N; i++)
            {
                if (i > 0)
                    Console.Write(" ");
                Console.Write(A[i]);
            }
            Console.WriteLine();
        }
        static void insertionSort(int[] A, int N)
        {
            int j, i, v;
            for (i = 1; i < N; i++)
            {
                v = A[i];
                j = i - 1;
                while (j >= 0 && A[j] > v)
                {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = v;
                trace(A, N);
            }
        }
        static void Main(string[] args)
        {
            int N, i;
            int[] A = new int[100];
            N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            for (i = 0; i < N; i++)
            {
                A[i] = int.Parse(str[i]);
            }
            trace(A, N);
            insertionSort(A, N);
        }
    }
}

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

using namespace std;

int N;
const int mod = 1e9 + 7;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int fac[2000009], inv[2000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}

int dp[109][109][2];
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N), N --;
Prec (N + 1);
/*dp[1][1][1] = 1;
for (int i=1; i<N; i++)
    for (int j=1; j<=i; j++)
        for (int t=0; t<2; t++)
            for (int t2=0; t2<2; t2++)
                if (t2 | t)
                    adto (dp[i + 1][j + t2][t2], dp[i][j][t]);*/
/*for (int i=1; i<=25; i++, printf ("\n"))
    for (int j=0; j<=i; j++)
        printf ("%8d ", comb (i, j));*/
int ans = fac[N];
for (int j=1; j<=N; j++)
{
    int currVal = 0;
    if (j - 1 >= N - j)
        currVal = comb (j - 1, N - j);
    //printf ("(%d, %d) ", dp[N][j][1], currVal);
    int curr = subtract (comb (N, j), currVal);
    curr = mul (curr, fac[j]);
    adto (ans, mul (curr, fac[N - j]));
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 10368
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=50+10;

int n;
int a[maxn],pos[maxn];
int flag;

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  for(int i=1;i<=n;i++) pos[a[i]]=i;
  int kq=0;
  for(int i=1;i<=n;i++)
    if (pos[i]!=i) kq++;
  if (kq<=2) printf("YES");
  else printf("NO");
}

// 2 1 4 5 3


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, K;
  cin >> N >> K;

  if (K == 1) {
    cout << 0 << endl;
    return;
  }

  vector<ll> A(N);
  rep (i, N) cin >> A[i];

  vector<ll> acc(N+1);
  acc[0] = 0;
  rep (i, N) acc[i+1] = acc[i] + A[i];

  unordered_map<ll, vector<pair<ll, ll>>> mp;

  rep (i, N+1) {
    ll tmp = acc[i];
    tmp -= i;
    tmp += N * K;
    tmp %= K;
    mp[tmp].push_back(make_pair(i, acc[i]));
  }

  ll ans = 0;

  for (ll i = 0; i < N+1; i++) {
    ll tmp = acc[i];
    tmp -= i;
    tmp += N * K;
    tmp %= K;
    pair<ll, ll> q = make_pair(i, acc[i]);
    auto it = lower_bound(mp[tmp].begin(), mp[tmp].end(), q);
    ll index = it - mp[tmp].begin();

    if (index == 0) continue;

    ll ok = index;
    ll ng = 0;

    if ((mp[tmp][index].second - mp[tmp][0].second) % K == (mp[tmp][index].first - mp[tmp][0].first)) {
      ans += index;
      continue;
    }

    while (ng + 1 < ok) {
      ll mid = (ok + ng) / 2;
      if ((mp[tmp][index].second - mp[tmp][mid].second) % K == (mp[tmp][index].first - mp[tmp][mid].first)) {
        ok = mid;
      } else {
        ng = mid;
      }
    }

    ans += index - ok;
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 21064
#include<iostream>
#include<stdlib.h>

using namespace std;
const int MAX_N = 1024;

int kk[MAX_N*MAX_N + 1];

int n, m, Max;
int a[1024];


int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int solve(void) {


	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(Max < a[i] + a[j] && i != j && a[i] + a[j] <= m)
			Max = a[i] + a[j];

	qsort(kk, n * n, sizeof(int), compare_int);

	if(Max != 0) {
		cout << Max << endl;
	} else {
		cout << "NONE" << endl;
	}

}

int main(void) {
	while(1) {
	Max = 0;
	cin >> n >> m;
	if(n == 0 && m == 0)
		break;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
 
	solve();
	}	
}


Measured memory_bytes: 10148
N, K = map(int, input().split())
mod = 10**9+7

factorial = [1]
for i in range(1, N+1):
    factorial.append((factorial[i-1]*i)%mod)

p_list1 = [1]
for i in range(1, K+1):
    p_list1.append((p_list1[i-1]*(N-K+2-i))%mod)
    
p_list2 = [1]
for i in range(1, K+1):
    p_list2.append((p_list2[i-1]*(K-i))%mod)
    
for i in range(1, K+1):
    print ((p_list1[i]*pow(factorial[i],10**9+5,mod)*p_list2[i-1]*pow(factorial[i-1],10**9+5,mod))%mod)

Measured memory_bytes: 3444