akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF  = 1<<30;


struct item {
  int v, w;
  item (int v = 0, int w = 0) : v(v), w(w) {}
  bool operator<(const item &r) const { return w < r.w; }
  void operator+=(const item &r) { w += r.w, v += r.v; }
};


vector<item> enum_powerset(const vector<item> &is) {
  vector<item> a(1);
  for (auto &i : is) {
    auto b = a;
    for (auto &e : b) e += i;
    vector<item> c;
    merge(all(a), all(b), back_inserter(c));
    swap(a, c);
  }
  return a;
}


int solve(const vector<item> &is, int W) {
  int n = sz(is);
  auto a = enum_powerset({is.begin(), is.begin() + n/2});
  auto b = enum_powerset({is.begin() + n/2, is.end()});
  reverse(all(a));
 
  int ans = 0;
  int vbmax = -INF;
  auto itr = b.begin();
  for (auto &[va, wa] : a) {
    while (itr != b.end() && wa + itr->w <= W) {
      chmax(vbmax, itr->v);
      ++itr;
    }
    chmax(ans, va + vbmax);
  }
  return ans;
}


int main() {
  int n; cin >> n;
  vector<item> is(n);
  for (auto &[v, w] : is) cin >> v >> w;

  int q; cin >> q;
  rep(_, q) {
    int v, l; cin >> v >> l;
    vector<item> qi;
    while (v) {
      qi.push_back(is[v-1]);
      v /= 2;
    }
    cout << solve(qi, l) << '\n';
  }

  return 0;
}


Measured memory_bytes: 5308
// 二重ループ(内側はただの足し算)ですべての場合を尽くす
#include<iostream>
using namespace std;
int main() {
  int n,w[110],s1,s2,sum=0,ans=1000000;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> w[i];
    sum += w[i];
  }
  for(int i=0;i<n;i++){
    // ループ回す前に変数のリセット
    s1=0;
    s2=0;
    for(int j=0;j<=i;j++) s1 += w[j];
    s2 = sum-s1;
    if(s1>=s2){
      if(ans>=s1-s2) ans = s1-s2;
    }else{
      if(ans>=s2-s1) ans = s2-s1;
    }
  }
  cout << ans;
  return 0;
}
  

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
  public static void main(String argv[]) {
    int n, x, a = 1000, m;
    Scanner sc = new Scanner(System.in);
    n = Integer.parseInt(sc.next());
    x = Integer.parseInt(sc.next());
    
    for (int i = 0;i < n;i++) {
      m = Integer.parseInt(sc.next());
      x -= m;
      a = Math.min(a, m);
    }
    
    System.out.println(n + x/a);
  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

int64 gcd(int64 a, int64 b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int64 modinv(int64 a, int64 m) {
    int64 b = m, u = 1, v = 0;
    while (b) {
        int64 t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    int64 N, K;
    cin >> N >> K;

    if (K == 0) {
        cout << N * N << endl;
        exit(0);
    }

    int64 ans = 0;
    reps(1, j, N+1) {
        if (j <= K) continue;
        int64 t = N / j;
        ans += (j - K) * t;
        if (N % j >= K) ans += N % j - K + 1;
    }

    cout << ans << endl;
}


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

using namespace std;

using ll = long long;

ll gcd(ll a, ll b) {
  while (b) {
    ll c = b;
    b = a % b;
    a = c;
  }
  return a;
}

ll lcm(ll a, ll b) {
  if (!a || !b) return 0;
  return a * b / gcd(a, b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = b - a + 1;
  ans -= b / c - (a - 1) / c;
  ans -= b / d - (a - 1) / d;
  ans += b / lcm(c, d) - (a - 1) / lcm(c, d);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#include<stdlib.h>
//大きい順にソート
int c[105][3];
void merge(int i,int j,int s[][3]){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        c[d][2]=s[b][2];
        b++;
      }
      else if(j<b){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        c[d][2]=s[a][2];
        a++;
      }
      else if(s[a][2]>s[b][2]){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        c[d][2]=s[a][2];
        a++;
      }
      else{
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        c[d][2]=s[b][2];
        b++;
      }
    }
    for(d=i;d<=j;d++){
      s[d][0]=c[d][0];
      s[d][1]=c[d][1];
      s[d][2]=c[d][2];
    }
  }
}

int main(){
  int n,i,j,k;
  scanf("%d",&n);
  int mass[102][102];
  int condition[n+1][3];
  for(i=0;i<n;i++)
    scanf("%d%d%d",&condition[i][0],&condition[i][1],&condition[i][2]);
  merge(0,n-1,condition);
  for(i=0;i<=100;i++)
    for(j=0;j<=100;j++)
      mass[i][j]=condition[0][2]+abs(condition[0][0]-i)+abs(condition[0][1]-j);
  for(i=1;i<n;i++)
    for(j=0;j<=100;j++)
      for(k=0;k<=100;k++){
        if(condition[i][2]==0 && mass[j][k]>abs(condition[i][0]-j)+abs(condition[i][1]-k))
          mass[j][k]=0;
        else if(condition[i][2]!=0 && mass[j][k]!=condition[i][2]+abs(condition[i][0]-j)+abs(condition[i][1]-k))
          mass[j][k]=0;
      }
  int x,y,h=0;
  for(i=0;i<=100;i++)
    for(j=0;j<=100;j++)
      if(h<mass[i][j]){
        x=i;
        y=j;
        h=mass[i][j];
      }
  printf("%d %d %d\n",x,y,h);
  return 0;
}


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

int main(){
	string a, b;
	vector<int> ans;
	int n, num, ai, bi, c=0;
	bool flag;

	cin >> n;
	
	for(int i=0 ; i<n ; i++){
		cin >> a >> b;
		flag = false;
		
		for(int j=0 ; j<100 ; j++){
			num = 0;
			ai = a.size()-j-1;
			bi = b.size()-j-1;
			if( ai<0 && bi<0 && c==0) break;
			
			if(ai>=0)num += a[ ai ] - 48;
			if(bi>=0)num += b[ bi ] - 48;
			ans.push_back( (num+c)%10 );
			if(num+c >= 10) c = 1;
			else c = 0;
		}
		if(ans.size()>80){
			flag = true;
		}
		if(flag){
			printf("overflow");
		}else{
			for(int j=ans.size()-1 ; j>=0 ; --j){
				printf("%d", ans[j]);
			}
		}
		printf("\n");
		ans.clear();
	}
	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 3 * 1e5 + 5;
const ll mod = 1e6 + 3;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    double l;
    cin >> l;
    double ans = l / 3.0; 
    cout << fixed << setprecision(9) << ans * ans * ans << '\n';
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int x,y;
    scanf("%d %d", &x, &y);
    if( x%y == 0 ) x = -1;
    printf("%d\n", x);

    return 0;
}



Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <bitset>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

#define MOD 1000000007

int main() {

#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, d;
	cin >> n >> d;

	vector<int> dd(n);
	cin >> dd;

	vector<int> minima(n + 1);
	minima.back() = 1;
	for (int i = n - 1; i >= 0; i--)
	{
		minima[i] = minima[i + 1] + dd[i];
		if (abs(minima[i + 1] - dd[i]) >= minima[i + 1])
			minima[i] = minima[i + 1];
	}

	vector<bool> resp(n, false);
	for (int i = 0; i < n; i++)
	{
		if (d != 0)
			resp[i] = (d >= minima[i + 1]);
		d = min(d, abs(d - dd[i]));
	}


	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int pos;
		cin >> pos; pos--;
		cout << (resp[pos] ? "YES" : "NO");
		cout << "\n";
	}


	return 0;
}


Measured memory_bytes: 5888
#include <iostream>

using namespace std;

int main(){
  int W, H, x, y;
  cin >> W >> H >> x >> y;

  //(x, y)と長方形の中心を通る直線により，
  //長方形は2分割されるため，最適は W*H/2
  cout << ((double)W*(double)H)/2 << " ";

  //(x, y)が長方形の中心にいれば分割は無限にある
  if(x == (double)W/2 && y == (double)H/2)
    cout << "1" << endl;
  //そうでなければ(x, y)と中心を結ぶ直線のみ
  else
    cout << "0" << endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;

namespace aoj
{
    class Program
    {
        static void Main()
        {
            var w = int.Parse(Console.ReadLine());
            var e = new int[w];
            for (var i = 0; i < w; i++)
            {
                e[i] = i;
            }

            var n = int.Parse(Console.ReadLine());
            var arr = new string[n];
            for (var i = 0; i < n; i++)
            {
                arr[i] = Console.ReadLine();
                var _ = arr[i].Split(',');
                var t = new int[]
                {
                    int.Parse(_[0])-1,
                    int.Parse(_[1])-1
                };
                var tmp = e[t[0]];
                e[t[0]] = e[t[1]];
                e[t[1]] = tmp;
            }
            for (var i = 0; i < w; i++)
            {
                Console.WriteLine(e[i]+1);
            }
        }
    }
}

Measured memory_bytes: 9076
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        while(flag){
            int[] juge = new int[2];
            juge[0] = Integer.parseInt(sc.next());
            juge[1] = Integer.parseInt(sc.next());
            Arrays.sort(juge);
            if(juge[0] == 0 && juge[1] == 0){
                flag = false;
            }else{
                System.out.println(juge[0] + " " + juge[1]);                
            }
        }
    }
}


Measured memory_bytes: 35868
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std ;

int main()
{
	int n ,p ,miny = 1000000 ;
	double an ,s ,num[ 1000 ] ;
	cin >> n ;
	for( int i = 0 ; i < n ; i++ )
		cin >> num[ i ] ;

	sort( num ,num + n ) ;

	an = ( num[ n - 1 ] + num[ n - 2 ] ) / ( num[ 1 ] - num[ 0 ] ) ;
	for( int i = n - 1 ; i > 0 ; i-- )
	{
		if( num[ i ] - num[ i - 1 ] <= miny )
		{
			miny = num[ i ] - num[ i - 1 ] ;
			p = i ;
		}
	}
	if( p == n - 1 )
		s = ( num[ n - 3 ] + num[ n - 4 ] ) / ( num[ p ] - num[ p - 1 ] ) ;
	else
		s = ( num[ n - 1 ] + num[ n - 2 ] ) / ( num[ p ] - num[ p - 1 ] ) ;
	printf( "%.6f\n" ,max( an ,s ) ) ;
	return 0 ;
}

Measured memory_bytes: 3356
#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=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
ll gcd(ll a,ll b){
    if(b==0) return a;
    else return gcd(b,a%b);
}

constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};

string s;
int N;
int M;
int H;
int W;
int K;
int A;
int B;
int C;

int main(){
    cin >> s;
    int n=s.size();
    rep(i,n){
        for(int j=i+1;j<n;j++)
        {
            if(s[i]=='C' and s[j]=='F'){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}


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

using namespace std;
 
 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define fill(a,b) memset(a, b, sizeof(a))
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long int
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define L(x) ('a'<=x && x<='z')
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  200*1000 + 1;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
const double epsilon = 1e-9; 
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,unordered_set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

int binpow(int a,int b) {
    a=a%mod;
   
    int res = 1;
while (b > 0) {
        if (b & 1)res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
}
return (res+mod)%mod;
}



 int32_t main(){
    IOS;
 
   int t;
   //cin>>t;
     t=1;
   while(t--){

    string s;
    cin>>s;
    if(s[s.length()-1]=='s'){

       fr(i,0,s.length()){
          if(i==s.length()-1){
             cout<<"ses";
            
          }
         else cout<<s[i];

       }

       cout<<endl;
       

    
    }else{
       cout<<s+"s"<<endl;
       }
    
   }

 }

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

int main () {
    cin >> N;
    vector<int> a(N);
    float sum;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
	int ave;
    ave = round(sum/N);

    int ans = 0;
    for (int i = 0; i < N; i++){
        ans += (ave-a[i])*(ave-a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>

using namespace std;

class Vector{
public:
	double x,y;

	Vector(){}
	Vector( double dx, double dy ){
		x = dx;
		y = dy;
	}
	Vector operator-( const Vector& hoge ){
		return Vector( x - hoge.x, y - hoge.y );
	}

	Vector operator-( const Vector& hoge ) const{
		return Vector( x - hoge.x, y - hoge.y );
	}
};

double crossConduct( const Vector& lhs, const Vector& rhs )
{
	return lhs.x * rhs.y - lhs.y * rhs.x;
}

double line( const Vector& a, const Vector& b, const Vector& p )
{
	Vector hoge = b - a;
	Vector piyo = p - a;

	return crossConduct( hoge, piyo );
}

int main(int argc, char const* argv[])
{
	Vector A,B,C,D;
	char comma;

	while( cin >> A.x >> comma >> A.y >> comma >> B.x >> comma >> B.y >> comma >> C.x >> comma >> C.y >> comma >> D.x >> comma >> D.y ){
		double a,b,c,d;
		a = line( A, B, C );
		b = line( B, C, D );
		c = line( C, D, A );
		d = line( D, A, B );
		if( ( a > 0 && b > 0 && c > 0 && d > 0 ) || ( a < 0 && b < 0 && c < 0 && d < 0 ) ) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;


}

Measured memory_bytes: 0
#include<iostream>
#include<queue>

using namespace std;

int main() {
	int w, h;
	while(1){
		cin >> w >> h;
		if (w == 0)break;
		int** kabe = new int* [2 * h - 1];
		for (int i = 0;i < 2 * h - 1;i++) {
			kabe[i] = new int[w - 1 + i%2];
			for (int j = 0;j < w - 1 +i%2;j++) {
				cin >> kabe[i][j];
			}
		}
		int** dist = new int*[h];
		for (int i = 0;i < h;i++) {
			dist[i] = new int[w];
			for (int j = 0;j < w;j++) {
				dist[i][j] = -1;
			}
		}
		queue<pair<int, pair<int, int> > > q;
		q.push(make_pair(0, make_pair(0, 0)));
		dist[0][0] = 0;
		while (!q.empty()) {
			pair<int, pair<int, int> > p = q.front();
			q.pop();
			int y = p.second.first;
			int x = p.second.second;
			if (y > 0) {
				if (dist[y-1][x] == -1 && kabe[2*y-1][x]==0){
					q.push(make_pair(p.first + 1, make_pair(y - 1, x)));
					dist[y - 1][x] = p.first + 1;
				}
			}
			if (y < h-1) {
				if (dist[y + 1][x] == -1 && kabe[2 * y + 1][x] == 0) {
					q.push(make_pair(p.first + 1, make_pair(y + 1, x)));
					dist[y + 1][x] = p.first + 1;
				}
			}
			if (x > 0) {
				if (dist[y][x-1] == -1 && kabe[2 * y][x - 1] == 0) {
					q.push(make_pair(p.first + 1, make_pair(y , x-1)));
					dist[y][x-1] = p.first + 1;
				}
			}
			if (x <w-1) {
				if (dist[y][x+1] == -1 && kabe[2 * y][x] == 0) {
					q.push(make_pair(p.first + 1, make_pair(y, x+1)));
					dist[y][x + 1] = p.first + 1;
				}
			}

		}
		cout << dist[h - 1][w - 1] + 1 << endl;
	}
	
	
}


Measured memory_bytes: 4092
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vector<tuple<string,int,int>> a(n); REP(i,n){string c; int s; cin >> c >> s; a[i]=make_tuple(c,-s,i+1);} SORT(a);
    REP(i,n) out(get<2>(a[i]));

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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






template<unsigned long long m> class comb_perm{
private:
    int n;
    std::vector<long long> fact, fact_inv;
public:
    comb_perm(): n(0), fact(1), fact_inv(1){
        fact[0] = fact_inv[0] = 1;
    }
    comb_perm(int N): n(N), fact(N+1), fact_inv(N+1){
        fact[0] = fact[1] = fact_inv[0] = fact_inv[1] = 1;
        for(int i(2); i <= n; ++i) fact[i] = fact[i - 1] * i % m;
        for(int i(2); i <= n; ++i) fact_inv[i] = inv(fact[i]);
    }
 
    void resize(int N){
        fact.resize(N+1);
        fact_inv.resize(N+1);
        if(!n && N){
            fact[1] = fact_inv[1] = 1;
        }
        for(int i(std::max(2, n+1)); i <= N; ++i) fact[i] = fact[i - 1] * i % m;
        for(int i(std::max(2, n+1)); i <= N; ++i) fact_inv[i] = inv(fact[i], m);
        n = N;
    }
 
    long long power(long long a, unsigned long long b){
        long long ret(1);
        while(b){
            if(b & 1) ret = (ret * a) % m;
            a = (a * a) % m;
            b /= 2;
            if(ret < 0) ret += m;
            if(a < 0) a += m;
        }
        return ret;
    }
 
    long long inv(long long a){ // GCD(a, m) = 1
        return power(a, m-2);
    }
 
    long long permutation(int n, int r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        long long ret(fact[n]);
        ret = ret * fact_inv[n - r] % m;
        return ret;
    }
 
    long long combination(int n, int r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        long long ret(permutation(n, r));
        return ret * fact_inv[r] % m;
    }
 
    long long factorial(int a){
        return fact[a];
    }
 
    long long inv_factorial(int a){
        return fact_inv[a];
    }
};

int main(){
    int N; std::cin >> N;
    comb_perm<MOD> cp;
    long long ans(cp.power(10, N) - 2 * cp.power(9, N) + cp.power(8, N));
    ans %= MOD;
    if(ans < 0) ans += MOD;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr            first
#define sc            second
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
using namespace std;
ll xp[100005]={0};
int main()
{
    ll n,m,cnt=0,x,y;
    cin>>n>>m;
    ll a[100005];
    dom(i,n)
    {
        cin>>a[i];
    }
    com(i,m)
    {
        cin>>x>>y;
        if(a[x]==a[y])
        {
            xp[x]=1;
            xp[y]=1;
        }
        else if(a[x]<a[y])
        {
            xp[x]=1;
        }
        else
        {
            xp[y]=1;
        }
    }
    dom(i,n)
    {
        if(xp[i]==0)
        {
            //cout << a[i] << endl;
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 5204
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<18)
ll x[N],n,k;
ll cs[N];
int main(){
    cin>>n>>k;
    cs[0]=0;
    lol(i,n){
	cin>>x[i];
	cs[i+1]=cs[i]+x[i];
    }
    ll ans=(ll)mod*(ll)mod;
    ll sum=0;
    for(int i=1;i<=n;i++){
	ll cur=k*(i+n),p=4;
	for(int j=n-1;j>=0;j-=i){
	    int l=max(0,j-i+1);
	    cur+=p*(cs[j+1]-cs[l]);
	    if(cur>(ll)mod*(ll)mod)break;
	    if(p==4)p++;
	    else p+=2;
	}
	sum+=x[n-i];
	ans=min(ans,cur+sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
#include<ctype.h>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
char c[107];
int main(){
	int n=read(),Max=0,h=0;scanf("%s",c); 
    for(int i=0;i<n;++i)h+=2*(c[i]=='I')-1,Max=max(Max,h);
    printf("%d",Max);
    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
WL = [0]*(N+1)
AL = [0]*(N+1)
WLsum = 0
for _ in range(M):
    xx = input().split()
    p = int(xx[0])
    if xx[1]=='AC':
        if AL[p] == 0:
            AL[p] = 1
            WLsum += WL[p]
    else:
        WL[p] += 1

print(str(AL.count(1)) + ' ' + str(WLsum))

Measured memory_bytes: 4596
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn digit(n: u64) -> u32 {
    if n == 0 {
        return 1;
    }
    for i in 0..20u32 {
        if n < 10u64.pow(i) {
            return i as u32;
        }
    }
    20u32
}

fn main() {
    let n: u64 = input();
    if digit(n) == 1 {
        println!("{}", n);
        return;
    }
    let n_mid = (n - n / 10u64.pow(digit(n) - 1) * 10u64.pow(digit(n) - 1) - n % 10) / 10 ;
    // println!("{}", n_mid);

    let mut sum = 0;
    for i in 1..(n+1) {
        // println!("i = {}", i);
        let mut count = 0;
        let head = i / 10u64.pow(digit(i) - 1);
        let tail = i % 10;

        if tail == 0 {            
            continue;
        }

        // 一桁
        if head == tail {
            count += 1;
        }

        // 二桁以上
        for j in 1..7u32 {
            let max = (tail + 1) * 10u64.pow(j) - 10 + head;
            let min = tail * 10u64.pow(j) + head;            
            // println!("{} - {}", min, max);
            if max <= n {
                count += 10u64.pow(j - 1);
            } else if min > n {
                break;
            } else {
                // 最後の一桁で場合分け
                if head > n % 10 {
                    count += n_mid;
                } else {
                    count += n_mid + 1;
                }
            }
        }
        // println!("{}", count);
        sum += count;
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int x, a, b;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        x = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        solve();
    }

    void solve() {
        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n+1];
      for(int i = 1;i <= n;i++)a[i]=sc.nextInt();
      int cnt = 0;
      boolean[] friend = new boolean[n+1];
      Arrays.fill(friend,true);
      for(int i = 1;i <= n;i++){
      	if(a[a[i]]==i&&friend[i]==true&&friend[a[i]]==true){
        	cnt++;
            friend[i]=false;
            friend[a[i]]=false;
        }
      }
      System.out.println(cnt);
    }
}


Measured memory_bytes: 50420
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int n, cnt = 0;
inline void merge(vi &v, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	vi L(n1 + 1), R(n2 + 1);
	rep(i, 0, n1) {
		L[i] = v[left + i];
	}
	rep(i, 0, n2) {
		R[i] = v[mid + i];
	}
	L[n1] = R[n2] = 1e9;
	int i = 0, j = 0;
	rep(k, left, right) {
		++cnt;
		if(L[i] <= R[j]) {
			v[k] = L[i];
			++i;
		} else {
			v[k] = R[j];
			++j;
		}
	}
}
inline void mergeSort(vi &v, int left, int right) {
	if(left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(v, left, mid);
		mergeSort(v, mid, right);
		merge(v, left, mid, right);
	}
}
int main() {
	cin >> n;
	vi v(n); rep(i, 0, n) cin >> v[i];
	mergeSort(v, 0, n);
	rep(i, 0, n) cout << v[i] << (i + 1 == n ? "\n" : " ");
	P(cnt);
	return 0;
}

Measured memory_bytes: 6732
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAirplane solver = new AAirplane();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAirplane {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            out.println(Math.min(a + b, Math.min(a + c, b + c)));
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

        public void close() {
        }

    }
}



Measured memory_bytes: 22996
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int N, Z, W;
	vector<int> a;

	cin >> N >> Z >> W;

	for (int i = 0; i < N; i++) {
		int ai;
		cin >> ai;
		a.push_back(ai);
	}

	if (N == 1)
		cout << abs(a[0] - W) << endl;
	else
		cout << max(abs(a[N-2] - a[N-1]), abs(a[N-1] - W)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//cin.ignore();	// better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
//cout << (A + B == C ? "YES" : "NO") << endl;
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){
   	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);}


int main(void)
{
  fast();
  int n;
  cin>>n;
  int mini = INT_MAX;
  int maxi = INT_MIN;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    mini = min(mini,a[i]);
    maxi = max(maxi,a[i]);
  }
  int ans=INT_MAX;
  for(int i=mini;i<=maxi;i++)
  {
      int x = 0;
    for(int j=0;j<n;j++)
    {
        x = x+((a[j]-i)*(a[j]-i));
    }
    ans = min(ans,x);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

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

	string s; cin >> s;
	char prev = '#';
	int ans = 0;
	for (char ch: s) {
		if (ch == prev) prev = '*';
		else {
			ans++;
			if (prev != '*') prev = ch;
			else prev = '#';
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
   
int main()
{
	int size;
	char a[101],b[101];
	cin >> a >> b;
	size = sizeof a;
	char *c = new char[size*2+1];
	strcpy(c,a);
	strcat(c,a);
	if(strstr(c,b))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;		
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int x[MAX_N],y[MAX_N],w[MAX_N];
int n;
map<P,int> mp;

int search(int u,int v)
{
    int lt = mp[P(u-1,v+1)] + mp[P(u-1,v)] + mp[P(u,v+1)] + mp[P(u,v)];
    int rt = mp[P(u+1,v+1)] + mp[P(u+1,v)] + mp[P(u,v+1)] + mp[P(u,v)];
    int lb = mp[P(u-1,v)] + mp[P(u-1,v-1)] + mp[P(u,v-1)] + mp[P(u,v)];
    int rb = mp[P(u+1,v-1)] + mp[P(u+1,v)] + mp[P(u,v-1)] + mp[P(u,v)];
    int mx = max(max(lt,rt),max(lb,rb));
    return mx;
}

int main()
{
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d%d",&x[i],&y[i],&w[i]);
        mp[P(x[i],y[i])] = w[i];
	}
    int mx = 0;
    rep(i,n){
        mx = max(mx,search(x[i],y[i]));
    }
    cout << mx << " / 1\n";
	return 0;
}

Measured memory_bytes: 60648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1e9+7;
/*
【解法】
A = [1, 2, ..., n] と固定する（求める場合の数は、固定した場合の数の mPn 倍）。B を長さ n の数列とする

ある集合 S \subset {1, ..., n} の上で値が一致する（そのほかにも一致する値のある可能性がある）ような B の場合の数は g(S) = (m-|S|)P(n-|S|) 通り
（まだ決まっていない n-|S| 箇所の値を、使っていない m-|S| 個の値から重複しないように決める）

ある集合 S \subset {1, ..., n} の上でちょうど値が一致する（ S に属さない点 i ではA[i] != B[i] となる）ような
B の場合の数を f(S) 通りとすると、g(S) = \sum_{S\subset T} f(T) となる。

F(S) = f({1, ..., n} \setminus S), G(S) = g({1, ..., n} \setminus S) とおくと、
G(S) = \sum_{T\subset S} F(S) なので、包除原理から F(S) = \sum_{T\subset S} (-1)^|S\setminus T| G(T) が成り立つ。

求めるのは f(\emptyset)
= F({1, ..., n})
= \sum_{T\subset {1, ..., n}} (-1)^|{1, ..., n}\setminus T| G(T)
= \sum_{T\subset {1, ..., n}} (-1)^|{1, ..., n}\setminus T| g({1, ..., n} \setminus T)
= \sum_{T\subset {1, ..., n}} (-1)^|T| g(T)
（ T -> T\setminus {1, ..., n} で置換）
ここで g は size の関数なので g(T) = g(|T|) とおくと、 k 元集合の選び方が nCk 通りなので 
= \sum_{k=0}^n (-1)^k nCk g(k)
= \sum_{k=0}^n (-1)^k n! / (n-k)! / k! * (m-k)! / (m-n)!
となる。

これを高速に計算する。 k == 0 のとき m! / (m-n)! で、

    n! (m-k)!             n! (m-(k-1))!          n-k+1
---------------- == ------------------------ * ---------
(n-k)! k! (m-n)!    (n-(k-1))! (k-1)! (m-n)!   (m-k+1) k

なので、 k がふえるたびに (n-k+1) / (m-k+1) / k 倍すればよい
*/
ll inv_table[500001] = {};
void make_inv_table(int n){
    inv_table[1] = 1;
    for (int i=2; i<=n; ++i){
        // (MOD / i) * i + MOD % i = 0 なので
        // (MOD / i) * i = - (MOD % i)
        // - (MOD / i) * (MOD % i)^(-1) = i^(-1)
        inv_table[i] = inv_table[MOD%i] * (MOD - MOD / i) % MOD;
    }
}

ll npr(ll n, ll r){
    ll ans = 1;
    for(ll i=n-r+1; i<=n; ++i)ans = (ans * i) % MOD;
    return ans;
}

int main()
{
    ll n, m;
    scanf("%lld%lld", &n, &m);

    const ll mpn = npr(m, n);
    ll tmp = mpn;
    ll sum = tmp;
    const ll sign[2] = {1, MOD-1};
    make_inv_table(m);
    for(int k=1; k<=n; ++k){
        tmp = ((tmp * inv_table[m-k+1]) % MOD * (inv_table[k] * (n-k+1) % MOD)) % MOD;
        sum = (sum + sign[k%2] * tmp) % MOD;
    }
    printf("%lld\n", (sum * mpn) % MOD);
    return 0;
}


Measured memory_bytes: 7620
#include<stdio.h>

int linearSearch(int *, int, int);

int main(){
  int i,n,q,S[10000+1],key,cnt=0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&key);
    if(linearSearch(S, n, key)) cnt++;
  }

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

  return 0;
}

int linearSearch(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}



Measured memory_bytes: 2052
n, q = map(int, input().split())
s = input()
t = [0]*(n + 1)

for i in range(n):
    if s[i: i + 2] == "AC":
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])


Measured memory_bytes: 6188
r=input().split()
N=int(r[0])
M=int(r[1])
data=[[int(s) for s in input().split()] for i in range(M)]
left=[]
right=[]
for i in range(M):
    left.append(data[i][0])
    right.append(data[i][1])
if min(right)-max(left)+1<=0:
    print(0)
else:
    print(min(right)-max(left)+1)

Measured memory_bytes: 27128
const chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const data = Buffer.concat(chunks).toString("utf8");
  const variables = data
    .trim()
    .split(" ")
    .map((s) => parseInt(s, 10));
  console.log(solve(variables));
});

function solve(variables) {
  for (let i = 0; i < variables.length; i++) {
    if (variables[i] === 0) return i + 1;
  }
  return variables.length;
}


Measured memory_bytes: 29868
import sys

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

x = int(input())
## 上界を決める
if x == 1:
    print("1 0")
    sys.exit()

y = (x-1)//5
A = 0
C = 0

while y>C:
    A += 1
    C = (A**4) + (2*(A**3)) + (2*(A**2)) + A

## 割り切れたら終わり
if (A+1)**5-A**5 == x:
    print(str(A+1)+" "+str(A))
    sys.exit()


## 約数を列挙
divs = make_divisors(x)
divs = divs[1:]
for i in divs:
    for j in range(A):
        a = j+1
        b = a-i
        if a**5-b**5 == x:
            print(str(a)+" "+str(b))
            sys.exit()
            


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

const int MAXN = 1e5 + 5;
bool prime[MAXN];

void erathostenes()
{
	memset(prime, 1, sizeof(prime));
	for (int p = 2; p * p <= MAXN; ++p) {
		if (prime[p]) {
			for (int i = p * p; i <= MAXN; i += p)
				prime[i] = 0;
		}
	}
}

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

	int x;
	cin >> x;
	while (!prime[x])
		x++;
	cout << x << '\n';
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N;
		cin >> N;
		if (!N)break;
		vector<int>as(N);
		for (int i = 0; i < N; ++i) {
			cin >> as[i];
		}
		int sum = 0;
		for (int i = 0; i < N; ++i) {
			sum += count_if(as.begin() + i + 1, as.end(), [=](const int n) {return n < as[i]; });
		}
		cout << sum << endl;
	}
	return 0;
}

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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;
using ll = long long;
vector<int>v;
vector<int> dp;
int f(int n){
	if(n<=1) return 0;
	if(dp[n]!=-1) return dp[n];
	return dp[n] = min(abs(v[n-1]-v[n])+f(n-1), abs(v[n]-v[n-2])+f(n-2));
}

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

    int n;
    cin>>n;
    v.resize(n+1);
    dp.resize(n+1,-1);
    for(int i=1; i<=n; i++) {
    	cin>>v[i];
    }
	if(n>=2) dp[2]=abs(v[2]-v[1]);
    int ans = INT_MAX;
    ans = min(ans,f(n));

    cout<<ans;
  
    return 0;
}


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

int main()
{
  int n, x ;
  
  while(1){
  cin >> n >> x ;
  if(n==0 && x==0) break;
  
   int o=0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	for(int k=j+1;k<=n;k++){
	  if(i+j+k==x) o++;
	}
  }
}
  cout << o << "\n" ;

}
}




Measured memory_bytes: 3096
import java.math.BigInteger;
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();
			
			BigInteger a = BigInteger.valueOf(A);
			BigInteger b = BigInteger.valueOf(B);
			BigInteger c = BigInteger.valueOf(C);
			
			BigInteger left = a.multiply(b).multiply(BigInteger.valueOf(4)); 
			BigInteger right = c.subtract(a).subtract(b);
			
			if(right.compareTo(BigInteger.ZERO)==-1) {
				System.out.println("No");
				return;
			}
			
			right = right.multiply(right);
			
			
			
			if(left.compareTo(right)==-1) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
	    }
				
	}
	


Measured memory_bytes: 35912
//============================================================================
// Name        : abc131_d.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : Hello World in C++, Ansi-style
//============================================================================

/*
 D - Megalomania

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点: 400 点

 問題文

 AtCoder王国の王立問題工房でABC管理官の座に就いたキザハシ君は、浮かれるあまり仕事を引き受けすぎてしまいました。
 現在の時刻は 0 です。キザハシ君は 1 から N までの番号が振られた N 件の仕事を持っています。
 キザハシ君が仕事 i を終えるには A_i 単位時間かかります。また、仕事 i の〆切は時刻 B_i であり、
 これまでに仕事を終わらせる必要があります。時刻 B_i ちょうどに仕事 i を終わらせてもかまいません。
 キザハシ君は 2 件以上の仕事を同時にすることはできませんが、ある仕事を終わらせた直後に別の仕事を始めることはできます。
 キザハシ君はすべての仕事を〆切までに終わらせることができるでしょうか。可能ならば 'Yes'、不可能ならば 'No' を出力してください。

 制約

 ・入力はすべて整数
 ・1 <= N <= 2 × 10^5
 ・1 <= A_i, B_i <= 10^9 (1 <= i <= N)

 */

#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define rep(i, m, n) for (int i = m; i < n; ++i)

/**
 * エントリポイント．
 * @return 0.
 */
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<pair<int, int>> tasks;
	int a, b;
	rep(i, 0, n)
	{
		cin >> a >> b;
		// 締め切り，所要時間
		tasks.emplace_back(b, a);
	}
	sort(tasks.begin(), tasks.end());

	int time_elapsed = 0;
	bool isyes = true;

	for (pair<int, int> task : tasks) {
		time_elapsed += task.second; // 所要時間を足す
		if (time_elapsed > task.first) { // 締め切りを超過していた場合
			isyes = false;
			break;
		}
	}

	cout << (isyes ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 2420
N = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

ans = num2alpha(N)

print(ans.lower())


Measured memory_bytes: 9088