akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    for(int i=1;i<=INF;i++){
        if(abs(A-i) == abs(B-i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main(){
  int n,ptr=0,ans=0;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin>>v[i]; 
  sort(v.begin(),v.end());
  while(ptr<n){
    int cc=v[ptr],f=0;
    while(v[ptr]==cc){
      f++;
      ptr++;
    }
    ans+=f%2;
  }
  cout<<ans<<endl;
}

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

int getResult(const int total){
  for(int i = 1; 100 * i <= total; i++){
    if(total <= 105 * i) return 1;
  }
  return 0;  
}

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

  int result = getResult(X);
  cout << result;
  return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
using System.Numerics;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var A = GetLongs(N);
		if(A.Any(x => x == 0))
		{
			WriteLine(0);
			return;
		}
		
		var ans = new BigInteger(1);
		var limit = new BigInteger(1e18);
		for(long i = 0; i < N; i++)
		{
			ans *= new BigInteger(A[i]);
			if(ans > limit)
			{
				WriteLine(-1);
				return;
			}
		}
		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 41888
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
    int n;
    while(cin>>n,n!=0){
        int a[n];
        rep(i,n)cin>>a[i];
        sort(a,a+n);
        ll sum=0;
        rep(i,n-2)sum+=a[i+1];
        cout<<sum/(n-2)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3004
S = input()

NS = ('N' in S and 'S' in S) or ('N' not in S and 'S' not in S)
EW = ('E' in S and 'W' in S) or ('E' not in S and 'W' not in S)

if NS and EW:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
//16, 06, 2018, 09:30:28 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

typedef unsigned long long ull;

const int N = 1010;

typedef struct{
    ll x, y, z;
}Triple;

Triple t1[N], t2[N];
int n, m;

void transpor(int i, int j, int k){
    ll ca = 1, cb = 1, cc = 1;

    if(i){
        ca = -1;
    }

    if(j){
        cb = -1;
    }

    if(k){
        cc = -1;
    }

    for(int i = 0 ; i < n ; i++){
        t2[i].x = t1[i].x * ca;
        t2[i].y = t1[i].y * cb;
        t2[i].z = t1[i].z * cc;
    }
}

bool compar(Triple a, Triple b){
    return (a.x + a.y + a.z) > (b.x + b.y + b.z);
}

ll get(int m){
    ll sx = 0, sy = 0, sz = 0;

    for(int i = 0 ; i < m ; i++){
        sx += t2[i].x, sy += t2[i].y, sz += t2[i].z;
    }

    return abs(sx) + abs(sy) + abs(sz);
}

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

    for(int i = 0 ; i < n ; i++){
        cin >> t1[i].x >> t1[i].y >> t1[i].z;
    }    

    ll best = -1LL;

    for(int i = 0 ; i < 2 ; i++){
        for(int j = 0 ; j < 2 ; j++){
            for(int k = 0 ; k < 2 ; k++){
                transpor(i, j, k);

                sort(t2, t2 + n, compar);

                best = max(best, get(m));
            }
        }
    }

    cout << best << endl;

    return 0;
}

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


int main(){
	const int DIV = 1000000007;
	int N;
	cin >> N;
	vector<int> num(N);
	bool exist = true;
	for (int i = 0; i < N; ++i){
		int input;
		cin >> input;
		if (input % 2 == N % 2){ exist = false; }

		num[i] = input;
	}

	sort(num.begin(), num.end());

	for (int i = 0; i < N; i += 2){
		if (i == 0 && N % 2 == 1){
			if (num[0] != 0){
				exist = false;
				break;
			}
			i = -1;
		}
		else if (num[i] != num[i + 1]){
			exist = false;
			break;
		}
	}

	int ans = 1;
	if (exist){
		for (int i = 0; i < N / 2; ++i){
			ans *= 2;
			ans %= DIV;
		}
		cout << ans;
	}
	else{
		cout << 0;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    long[] dp = new long[1<<n];
    dp[0] = 1;
    long mod = 1000000007;
    int[,] matrix = new int[n,n];//行列
      
    for(int i = 0; i < n; i++)//それぞれの行
    {
    	int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    	for(int j = 0; j < n; j++) matrix[i,j] = nums[j];//行の全ての成分
    }

    for(int i = 1; i < (1<<n); i++)//2^n回ループ
    {
      int count = -1;
      for(int j = 0; j < n; j++)
      {
        if(((i>>j)&1) == 1) count++;
      }

      for(int j = 0; j < n; j++)
      {
        if(matrix[count,j] == 1 && ((i>>j)&1) == 1)
        {
          dp[i] += dp[i^(1<<j)];
          dp[i] %= mod;
          //Console.WriteLine(i+" "+dp[i]);
        }
      }
    }
		
		Console.WriteLine(dp[(1<<n)-1]);
	}
}

Measured memory_bytes: 27360
h, w, k = gets.chomp.split.map(&:to_i)
s = []
h.times do
  s.push gets.chomp.split(//)
end

def ume(h, w, starty, startx, s, num)
  ue = 0 # max
  shita = h - 1 # max
  migi = w - 1 # max
  hidari = 0 # max

  # 1 line hidari
  (startx-1).downto(0) do |x|
    if s[starty][x] != '.'
      hidari = x + 1
      break
    end
  end
  # 1 line migi
  (startx+1).upto(w-1) do |x|
    if s[starty][x] != '.'
      migi = x - 1
      break
    end
  end
  # ue
  (starty-1).downto(0) do |y|
    unless (hidari..migi).to_a.all?{|x| s[y][x] == '.'}
      ue = y + 1
      break
    end
  end
  # shita
  (starty+1).upto(h-1) do |y|
    unless (hidari..migi).to_a.all?{|x| s[y][x] == '.'}
      shita = y - 1
      break
    end
  end

  # fill
  (ue..shita).each do |i|
    (hidari..migi).each do |j|
      s[i][j] = num.to_s
    end
  end
  # p [num, ' ', ue, shita, hidari, migi, ' ', starty, startx]
end

num = 1
h.times do |i|
  w.times do |j|
    if s[i][j] == '#'
      ume(h, w, i, j, s, num)
      num += 1
    end
  end
end

h.times do |i|
  puts s[i].join(' ')
end

Measured memory_bytes: 16892
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum=0;
    if(a>=k){
        cout<<k<<endl;
        return 0;
    }
    if(a+b>=k){
        cout<<a<<endl;
        return 0;
    }
    cout<<a-(k-a-b)<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a))cin >> a[i]
#define ccin(i, j, a) rep(i, length(a))rep(j, length(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    intl w,h,n;
    cin >> w >> h >> n;
    intl x[n];
    intl y[n];
    intl a[n];
    rep(i,n){
        cin >> x[i] >> y[i] >> a[i];
    }
    bool f[w][h];
    rep(i,w){
        m0(f[i]);
    }
    rep(i,n){
        if(a[i] == 1){
            rep(j,x[i]){
                rep(k,h){
                    f[j][k] = true;
                }
            }
        }
        else if(a[i] == 2){
            repi(j,x[i],w){
                rep(k,h){
                    f[j][k] = true;
                }
            }
        }
        else if(a[i] == 3){
            rep(j,w){
                rep(k,y[i]){
                    f[j][k] = true;
                }
            }
        }
        else {
            rep(j,w){
                repi(k,y[i],h){
                    f[j][k] = true;
                }
            }
        }
    }
    intl cnt = 0;
    rep(i,w){
        rep(j,h){
            if(!f[i][j])cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
// C++ (GCC 9.2.1)
// 解き直し.
// https://img.atcoder.jp/abc167/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 998244353;
const int LIMIT = 202020;
LL FAC[LIMIT], INV[LIMIT], C[LIMIT];

// Fermat's little theorem から, 大きな冪乗の計算を行う.
// @param a: べき乗したい正整数.
// @param b: 指数.
// @return:  べき乗した計算結果(mod版).
LL mPow(LL a, LL b){
    LL t = 1;
    while(b){
        if(b & 1) t = (t * a) % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return t % MOD;
}

// 組み合わせ(nCk)計算用(mod版).
// ※配列FAC, INV は, 事前に計算済のものを使う.
// @param n: 対象となる要素の個数.
// @param k: 選択する要素の個数.
// @return: 組み合わせ(nCk)の計算結果(mod版).
LL combination(LL n, LL k){
    if(n < 0 || k < 0 || k > n) return 0LL;
    // k = 0 で, 256423756 (※挙動がおかしい) が 出力されたため, ロジック修正.
    if(n == k || k == 0LL) return 1LL;
    LL ret = FAC[n] * INV[k] % MOD * INV[n - k] % MOD;
    return ret;
}

int main(){
    
    // 1. 入力情報.
    int N;
    LL M, K;
    scanf("%d %lld %lld", &N, &M, &K);
    FAC[0] = 1;
    repx(i, 1, LIMIT) FAC[i] = (LL)i * FAC[i - 1] % MOD;
    rep(i, LIMIT)     INV[i] = mPow(FAC[i], MOD - 2);
    
    // ※ 解説通り.
    // 2. (M - 1) の べき乗 を 用意.
    C[0] = 1;
    rep(i, LIMIT) C[i + 1] = C[i] * (M - 1) % MOD;
    
    // 3. 公式を適用.
    LL ans = 0;
    rep(k, (int)K + 1){
        LL t = M;
        t *= combination((LL)(N - 1), (LL)k);
        t %= MOD;
        t *= C[N - 1 - k];
        t %= MOD;
        ans += t;
        ans %= MOD;
    }
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 8560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      //cout<<n*i+m*j-i*j*2<<endl;
      if(m*i+n*j-i*j*2==k){cout<<"Yes"<<endl;return 0;}
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){

    int n,l;
    cin>>n>>l;
    vector<string> v(n);
    REP(i,n){
        cin >> v[i];
    }

    sort(v.begin(),v.end());
    REP(i,n){
        cout << v[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void bubble_sort(int *data, int n)
{
    int i, j;
    
    for (i = 0; i < n - 1; i++){
        for (j = 0; j < n - i - 1; j++){
            if (data[j] < data[j + 1]){
                data[j] ^= data[j + 1];
                data[j + 1] ^= data[j];
                data[j] ^= data[j + 1];
            }
        }
    }
}

int main(void)
{
    int n, m, veg[1001];
    int i, j;
    int ans;
    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d", &veg[i]);
        }
        
        bubble_sort(veg, n);
        
        ans = 0;
        for (i = 0; i < n; i++){
            if (i % m != m - 1){
                ans += veg[i];
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int r=0;
	long long ans=0,s=0,x=0;
	rep(l,n){
		while(r<n && s+a[r]==(x^a[r])){
			s+=a[r];
			x^=a[r];
			r++;
		}
		s-=a[l];
		x^=a[l];
		ans+=r-l;
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	string s; cin >> s;
	rep(i, 8){
		int n = s[0] - '0';
		if(i & 1) n += s[1] - '0';
		else n -= s[1] - '0';
		if(i & (1 << 1)) n += s[2] - '0';
		else n -= s[2] - '0';
		if(i & (1 << 2)) n += s[3] - '0';
		else n -= s[3] - '0';
		if(n == 7){
			cout << s[0];
			if(i & (1 << 0)) cout << '+';
			else cout << '-';
			cout << s[1];
			if(i & (1 << 1)) cout << '+';
			else cout << '-';
			cout << s[2];
			if(i & (1 << 2)) cout << '+';
			else cout << '-';
			cout << s[3] << "=7" << endl;
			return 0;
		}
	}
}


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

using namespace std;

int n, k;
int a[4004][4004];
int tsum[4004][4004];

int f(int x, int y) {
	return tsum[x][y] + tsum[x + k][y + k] - tsum[x][y + k] - tsum[x + k][y];
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		int t = 0;
		if (c == 'W') y += k;
		x %= (2 * k); y %= (2 * k);
		a[x][y]++;
	}
	for (int i = 0; i < 4 * k; i++) {
		for (int j = 0; j < 4 * k; j++) {
			tsum[i + 1][j + 1] = tsum[i + 1][j] + a[i % (2 * k)][j % (2 * k)];
		}
	}
	for (int i = 0; i < 4 * k; i++) {
		for (int j = 0; j < 4 * k; j++) {
			tsum[j + 1][i + 1] += tsum[j][i + 1];
		}
	}
	int ans = 0;
	for (int i = 1; i <= 2 * k; i++) {
		for (int j = 1; j <= 2 * k; j++) {
			int sum = 0;
			sum += f(i, j);
			sum += f(i + k, j + k);
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 94464
#include<bits/stdc++.h>
using namespace std;
string s;
int k,n;
int dp[120][5][2];

int fun(int pos, int cnt, int f) {
    if (cnt > k) return 0;
    if (pos == n) {
        if (cnt == k) return 1;
        return 0;
    }
    if(dp[pos][cnt][f] != -1) return dp[pos][cnt][f];

    int res = 0, limit;
    int now = s[pos] - '0';
    if (f) limit = 9;
    else limit = now;

    for (int i = 0; i <= limit; i++) {
        int ncnt = cnt, nf = f;
        if (!f && i < now) nf = 1;
        if (i != 0) ncnt++;
        if (ncnt <= k) res += fun(pos + 1, ncnt, nf);
    }

    return dp[pos][cnt][f] = res;
}

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> s >> k;
    n = s.size();
//    k = n - k;

    memset(dp, -1, sizeof(dp));
    cout << fun(0, 0, 0) << '\n';
}


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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

string S;
int Q;

int dp[27][500010];
int nex[20][500010];
signed main(){
    cin>>S;
    fill_n(*dp,27*500010,S.size()+2);
    fill_n(*nex,20*500010,S.size()+2);
    for(int i=S.size()-1;i>=0;i--){
        int c=S[i]-'a';
        dp[c][i]=i+1;
        for(int j=c+1;j<=26;j++)dp[j][i]=dp[j-1][dp[j-1][i]];
        for(int j=0;j<26;j++){
            chmin(dp[j][i],dp[j][dp[26][i]]);
            if(j)chmin(dp[j][i],dp[j-1][dp[j-1][i]]);
        }
    }

    rep(i,S.size())nex[0][i]=dp[26][i];
    for(int i=0;i<19;i++){
        rep(j,S.size()){
            nex[i+1][j]=nex[i][nex[i][j]];
        }
    }

    scanf("%lld",&Q);
    while(Q--){
        int l,r;
        scanf("%lld%lld",&l,&r);
        l--;
        for(int i=19;i>=0;i--)if(nex[i][l]<=r)l=nex[i][l];
        if(l==r)puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 184836
#include <bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define frd(i,x,y) for(int i=x;i>=y;i--)
#define ll long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define _piii pair<pii,int>
#define fi first
#define se second
#define maxn 100100
#define base 100003
#define Bit(x,i) ((x>>i)&1)
#define Turnoff(t,k) (t^(1<<(k)))
using namespace std;
int n,m = 0;
long long ans = 0;
_piii a[100100];
piii e[200100];
typedef struct
{
    int r[200100];
    int getroot(int u)
    {
        return u==r[u]?u:r[u]=getroot(r[u]);
    }
    void _union_(int u,int v,long long w)
    {
        int ru=getroot(u),rv=getroot(v);
        if (ru==rv) return;
        ans += w;
        if (ru<rv) r[rv]=ru;
        else
            r[ru]=rv;
    }
} lewlew;

lewlew A;

void inp()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("tryhard.inp","r",stdin);
    //freopen("tryhard.out","w",stdout);
    cin>>n;
    fr(i,1,n)
    {
        cin>>a[i].fi.fi>>a[i].fi.se;
        a[i].se = i;
    }
    fr(i,1,n) A.r[i] = i;
}
bool cmp1(_piii x,_piii y)
{
    return x.fi.fi < y.fi.fi;
}
bool cmp2(_piii x,_piii y)
{
    return x.fi.se < y.fi.se;
}
void sub()
{
    sort(a+1,a+1+n,cmp1);
    fr(i,1,n-1)
    {
        e[++m].fi = a[i+1].fi.fi - a[i].fi.fi;
        e[m].se.fi = a[i].se;
        e[m].se.se = a[i+1].se;
    }
    sort(a+1,a+1+n,cmp2);
    fr(i,1,n-1)
    {
        e[++m].fi = a[i+1].fi.se - a[i].fi.se;
        e[m].se.fi = a[i].se;
        e[m].se.se = a[i+1].se;
    }
    sort(e+1,e+1+m);
    fr(i,1,m)
        A._union_(e[i].se.fi,e[i].se.se,e[i].fi);
    cout<<ans;
}
int main()
{
    inp();
    sub();
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int n,p,f[500010],c[500010],a[500010];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%1d",&c[i]);
        if(!c[i])
            p=i;
        a[i]=p;
    }
    for(int i=1;i<=n;i++){
        f[i]=f[i-1];
        if(!c[i])
            continue;
        if(!c[i-1]&&c[i-2]){
            f[i]=max(f[i],f[a[i-2]]+i-2-a[i-2]);
        	f[i]=max(f[i],f[a[i-2]+1]+i-2-a[i-2]-1);
        }
        else if(a[i]>1&&c[a[i]-1])
            f[i]=max(f[i],f[a[i]-2]+i-a[i]);
    }
    printf("%d\n",f[n]);
    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    ll N;
    cin >> N;
    if (N == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    if (N % 2 == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for (ll i = 10; i <= 1e18; i *= 5)
    {
        ans += (N / i);
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

void sub()
{
    const auto N(cin2var<size_t>());
    const auto K(cin2var<size_t>());
    const auto Q(cin2var<size_t>());
    const auto As(cin2vec<size_t>(Q));
    map<size_t, int64_t> map_player_win;
    for (size_t i = 0; i < N; ++i) {
        map_player_win[i] = K - Q;
    }
    for (const auto& a : As) {
        ++map_player_win[a - 1];
    }
    for (const auto& pw : map_player_win) {
        cout << (pw.second > 0 ? "Yes" : "No") << endl;
    }
}

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

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second
#define MP make_pair
#define PB push_back

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;


int main()
{
  string s ;
  cin >> s ;
  int cnt = 0 ;
  int n = s.size() ;
  
  int i = 0 ;
  while(i<n){
    if(i==n-1){
      cnt++ ;
      break ;
    }
    if(s.at(i)!=s.at(i+1)){
      cnt++ ;
      i++ ;
    }
    else{
      if(i==n-2){
        cnt++ ;
        break ;
      }
      else{
        cnt += 2 ;
        i += 3 ;
      }
    }
  }
  
  cout << cnt <<endl ;

  return 0 ;
}





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

int main(){
	int a, b;
	cin >> a >> b;
	if (a > b) {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
	}
	else {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
	} 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cstdlib>
#include <algorithm>
#define llint long long
#define inf 1e18
#define xmax 1000000000000

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, cost;
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint N, M, S[2], T;
vector<edge> G[1005];
vector<llint> vec;
llint dist[1005];

void dijkstra(llint S, llint x)
{
	for(int i = 1; i <= N; i++) dist[i] = inf;
	dist[S] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	
	llint v, d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			llint cost = G[v][i].cost;
			if(cost == -1) cost = x;
			if(dist[G[v][i].to] > d + cost){
				dist[G[v][i].to] = d + cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

llint calc(llint i, llint x)
{
	dijkstra(S[i], x);
	return dist[T];
}

bool check(llint i, llint x, llint a, llint b)
{
	llint f = calc(i, x);
	return a*x+b == f;
}

void make(llint i)
{
	llint x = 0, a, b;
	vec.push_back(0);
	while(x < xmax){
		llint f = calc(i, x), f2 = calc(i, x+1);
		a = f2 - f, b = f - a*x;
		llint ub = xmax+1, lb = x+1, mid;
		while(ub - lb > 1){
			mid = (ub + lb) / 2;
			if(check(i, mid, a, b)) lb = mid;
			else ub = mid;
		}
		vec.push_back(lb);
		x = lb;
	}
}

llint get(llint sx, llint tx)
{
	llint big = 0, small = 1;
	if(calc(0, sx) < calc(1, sx)) swap(big, small);
	
	llint ub = tx, lb = sx+1, mid;
	while(ub - lb > 1){
		mid = (ub + lb) / 2;
		if(calc(big, mid) > calc(small, mid)) lb = mid;
		else ub = mid;
	}
	return lb;
}

int main(void)
{
	while(1){
		cin >> N >> M >> S[0] >> S[1] >> T;
		if(!N && !M && !S[0] && !S[1] && !T) break;
		
		for(int i = 1; i <= N; i++) G[i].clear();
		llint u, v, w; string s;
		for(int i = 1; i <= M; i++){
			cin >> u >> v >> s;
			if(s == "x") w = -1;
			else w = atoi(s.c_str());
			G[u].push_back(edge(v, w));
			G[v].push_back(edge(u, w));
		}
		
		vec.clear();
		make(0), make(1);
		sort(vec.begin(), vec.end());
		vec.erase(unique(vec.begin(), vec.end()), vec.end());
		
		llint ans = inf;
		for(int i = 0; i < (int)vec.size()-1; i++){
			llint s0 = calc(0, vec[i]), s1 = calc(1, vec[i]);
			llint t0 = calc(0, vec[i+1]), t1 = calc(1, vec[i+1]);
			if((s0-s1)*(t0-t1) >= 0){
				ans = min(ans, abs(s0 - s1));
				ans = min(ans, abs(t0 - t1));
			}
			else{
				llint cx = get(vec[i], vec[i+1]);
				ans = min(ans, abs(calc(0, cx) - calc(1, cx)));
				ans = min(ans, abs(calc(0, cx+1) - calc(1, cx+1)));
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <bits/stdc++.h>
#define loop(N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int
#define plli pair<lli,lli>
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(v.size()){
        pt<T>(v[i]);
    }
}
/*********************************reused****************************/
const int N = 100009;
lli a[N];
lli b[N];
lli c[N];
int main()
{
    int n;
    cin>>n;
    loop(n){
        cin >>a[i];
    }
    loop(n){
        cin >>b[i];
    }
    loop(n){
        cin >>c[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    lli d[N];
    lli s[N];
    for(int j=0;j<n;j++){
        for(int k=(j==0?0:(n-d[j-1]));k<n;k++){
            if(b[j]>=c[k])
                continue;
            else{
                d[j]=n-k;
                break;
            }
        }
    }
    s[n-1] = d[n-1];
    for(int i=n-2;i>=0;i--){
        s[i]= s[i+1]+ d[i];
    }
    lli ans = 0;
    int lastj = 0;
    bool notFound = true;
    for(int i=0;i<n;i++){
        notFound = true;
        for(int j=lastj;j<n;j++){
            if(a[i]>=b[j]){
                continue;
            }else{
                notFound = false;
                ans+=s[j];
                lastj = j;
                break;
            }
        }
        if(notFound)
            break;
    }
    cout <<ans<<endl;
    return 0;
}



Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n,W;
long long dp[105][100100];

int main(){
    fastio;
    cin >> n >> W;
    int w[n+1];
    long long v[n+1];
    for(int i=1;i<=n;i++){cin >> w[i] >> v[i];}
    for(int i=0;i<=W;i++){dp[0][i]=0;}
    for(int i=0;i<=n;i++){dp[i][0]=0;}
    for(int i=1;i<=n;i++){
        for(int j=1;j<=W;j++){
            if(j-w[i]<0){dp[i][j] = dp[i-1][j];}
            else{dp[i][j] = max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);}
        }
    }
    cout << dp[n][W] <<"\n";
    return 0;
}


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

int main(void) {
	int N, R;
	scanf("%d %d", &N, &R);

	if (N >= 10) {
		printf("%d", R);
	} else {
		printf("%d", R + 100 * (10 - N));
	}
	return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  vector<bool> updown(N - 1);
  for(int i = 0; i < N - 1; i++){
    if(H[i] >= H[i + 1]) updown[i] = true;
    else updown[i] = false;
  }
  int count = 0;
  for(int i = 0; i < N - 1;){
    if(!updown[i]) i++;
    else{
      int count1 = 0;
      while(updown[i]){
        count1++;
        i++;
      }
      count = max(count, count1);
    }
  }
  cout << count  << endl;
}

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

signed main(){
  int x;
  cin>>x;
  x%=10;
  if (x==2 || x==4 || x==7 || x==5 || x==9)
    cout<<"hon"<<endl;
  else if (x==1|| x==0 || x==6 || x==8)
    cout<<"pon"<<endl;
  else cout<<"bon"<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 998244353
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
const int N=200010;

int main()
{
	int n;
	cin>>n;
	int res=0,t=0,x;
	int p=-mod;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x<=p)
		{
			t++;
		}
		else
		{
			res=max(res,t);
			t=0;
		}
		p=x;
	}
	res=max(res,t);
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		while(num > 0){
			BigInteger num_1 = sc.nextBigInteger();
			BigInteger num_2 = sc.nextBigInteger();
			BigInteger sum = num_1.add(num_2);
			
			if(sum.toString().length() > 80){
				System.out.println("overflow");
			}
			else {
				System.out.println(sum);
			}
			num--;
		}
	}
}

Measured memory_bytes: 18508
#include <iostream>
#include <string>

int main()
{
  std::string n;
  std::cin>>n;
  
  std::string result="pon";
  switch(n.back())
  {
    case '2':case '4':case '5':case '7':case '9':
      result="hon";
      break;
    case '3':
      result="bon";
      break;
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3620
import java.util.*;

class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int min = 1001;
      
      for(int i=0;i<N;i++){
        int c = sc.nextInt();  int t = sc.nextInt();
        if(t<=T){min = Math.min(c,min);}
      }
      if(min==1001){System.out.println("TLE");}
      else{System.out.println(min);}
    }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
 ll h,w;
 cin>>h>>w;
 
 if(h==1 or w==1)
 cout<<1;
 else if(w%2==0)
 cout<<h*(w/2);
 else
 cout<<((h+1)/2)*((w+1)/2)+(h/2)*(w/2);
 
}

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

int zettaiti(int a) {
	if (a < 0)return -a;
	return a;
}
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2) {
		for (int c = 0; c < b; c++) {
			int e, f;
			cin >> e >> f;
			f = (max(zettaiti(e), zettaiti(f)))%3;
			e = (a / 2 + 1) % 3;
			switch (e - f) {
			case -2:case 1:cout << 2 << endl; break;
			case -1:case 2:cout << 1 << endl; break;
			case 0:cout << 3 << endl; break;
			}
		}
	}
	else {
		for (int c = 0; c < b; c++) {
			int d, e;
			cin >> d >> e;
			int f, g;
			if (d > a / 2)f = a / 2;
			else f = a / 2 + 1;
			if (e > a / 2)g = a / 2;
			else g = a / 2 + 1;
			d = max(zettaiti(d - f),zettaiti(e-g));
			switch ((a / 2 - d)%3) {
			case -2:case 1:cout << 2 << endl; break;
			case -1:case 2:cout << 3 << endl; break;
			case 0:cout << 1 << endl; break;
			}
		}
	}
}

Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

char str[20];

int main()
{
    int n;
    cin>>n;
    int ac,wa,tle,re;
    ac=wa=tle=re=0;
    for(int i=0;i<n;i++)
    {
        cin>>str;
        if(str[0]=='A')
            ac++;
        else if(str[0]=='W')
            wa++;
        else if(str[0]=='T')
            tle++;
        else if(str[0]=='R')
            re++;
    }
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d",re);
    return 0;
}


Measured memory_bytes: 3708
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, B, C, D = [int(x) for x in input().split()]
    ans = -float("inf")
    if A <= 0 <= B or C <= 0 <= D:
        ans = 0

    ans = max(ans, B * D)
    ans = max(ans, B * C)
    ans = max(ans, A * D)
    ans = max(ans, A * C)

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int d = a;
	int e = a*b;
	bool flag = false;
	while(d<e){
		if(d%b==c)
		 {
		 flag = true;
		  break;
		 }
		 d = d+a;
	}
	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main() {
    int n,m;cin>>n>>m;
    map<int,int> mp;
    mp[0]=1;
    int sm=0;
    ll ans=0;
    for (int i=0;i<n;i++) {
        int a;cin>>a;
        sm=(sm+a)%m;
        ans+=mp[sm];
        mp[sm]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6424
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import sys
inf = 10**9+7
mod = 10**9+7

# 約数生成
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

n = int(input())
ans=0
for i in range(3,n+1,2):
    num = len(make_divisors(i))
    if num == 8:
        ans+=1
print(ans)

Measured memory_bytes: 38256
using System;

class AOJ {
    static void Main()
    {
        int R, n;
        int min_R = (int)2e5, ans = (int)-1e9;

        n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++) {
            R = int.Parse(Console.ReadLine());

            if (i == 0)
                min_R = R;
            else {
                ans = Math.Max(ans, R-min_R);
                min_R = Math.Min(min_R, R);
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 9236
N = int(input())
H = list(map(int, input().split()))

j = []
ans = 1
count = 1

for i in range(N-1):
    if H[i] - H[i+1] >= 0:
        j.append(True)
    else:
        j.append(False)

if any(j) != True:
    print(0)
    exit()

for i in range(len(j)-1):
    if j[i] == j[i+1] == True:
        count += 1
        if count > ans:
            ans = count
    else:
        count = 1

print(ans)

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

int main()
{
  int a, ans = 0;
  for(int i = 1; i<=5; i++)
  {
    cin>>a;
    if(a == 0) ans = i;
  }
  cout<<ans<<"\n";
  return 0;
}
 

Measured memory_bytes: 3608
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define MAXN ((int)3e6+5)
#define MOD ((int)1e9 + 7) 
#define ll long long
#define _ << " " <<
#define TRACE(x) cerr << #x << " = " << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"

int n,m,t,k;
int d[25][25];
int dp[25][MAXN];

void add(int&a,int b)
{
	a += b;
	if(a > MOD)
		a -= MOD;
}

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

	cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			cin >> d[i][j];

	for (int i = 0; i < n; ++i)
		if(d[0][i])
			dp[0][(1<<i)] = 1;

	for (int j = 1; j < n; ++j)
	{
		for (int mask = 1; mask < (1<<n); ++mask)
			if(dp[j-1][mask])
			{
				// cout << j _ mask << endl;
				for (int k = 0; k < n; ++k)
				{
					// cout << "k=" _ k _ (mask&(1<<k)) << " " << d[j][k] << endl;
					if(((mask & (1<<k)) == 0) && d[j][k])		
					{
						// cout << "lel" _ j _ mask _ k << endl;
						add(dp[j][mask|(1<<k)] ,dp[j-1][mask]);
					}
				}
			}
	}

	// for (int i = 0; i < (1<<n); ++i)
	// 	cout << i << " ";
	// cout << endl;
	// for (int i = 0; i < n; ++i)
	// {
	// 	for (int j = 0; j < (1<<n); ++j)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	cout << dp[n-1][(1<<n) - 1] << endl;
	return 0;
}


Measured memory_bytes: 188672
fun main(args: Array<String>) {

    val bb = IntArray(4)

    for (i in 0 until 3) {
        val (a, b) = readLine()!!.split(" ").map{it.toInt()}
        bb[a-1] += 1
        bb[b-1] += 1
    }

    if(bb.count({it==3}) >= 1) print("NO") else print("YES")
}

Measured memory_bytes: 37608
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[3001][3001];
ll maxScore(vector<int> money)
{
   int n = money.size();
   int totalTurns = n;
   bool turn = (totalTurns%2==0)?0:1;
   for(int i = 0; i < n ; i++)
   {
       dp[i][i] = turn?money[i]:0;
   }
   turn = !turn;
   int sz = 1;
   while(sz < n)
   {
       for(int i = 0; i + sz < n ;i++)
       {
           ll scoreOne = dp[i+1][i+sz];
           ll scoreTwo = dp[i][i+sz-1];
           if(turn)
           {
              dp[i][i+sz] = max(money[i] + scoreOne, money[i+sz] + scoreTwo);
           }
           else dp[i][i+sz] = min(scoreOne, scoreTwo);
       }
       turn = !turn;
       sz++;
   }
   return dp[0][n-1];
}

int main()
{
   ll n,x;
   cin>>n;
   vector<int> v(n); ll sum =0;
   for(int i=0;i<n;i++)
   {
       cin>>v[i]; sum += v[i];
       //v.push_back(x);
   }
   cout<<2*maxScore(v) - sum;
    return 0;
}



Measured memory_bytes: 70016
n = int(input())
A = list(map(int,input().split()))

def g(A,l,m,r):
  global c
  L,R = A[l:m]+[1e11],A[m:r]+[1e11]
  i = j = 0
  for k in range(l,r):
    if L[i] < R[j]:
      A[k] = L[i]
      i += 1
      c += j
    else:
      A[k] = R[j]
      j += 1

def s(A,l,r):
  if l + 1 < r:
    m = (l+r)//2
    s(A,l,m)
    s(A,m,r)
    g(A,l,m,r)

c = 0

s(A,0,n)
print(c)



Measured memory_bytes: 27480
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N, K;
        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                N = line[0];
                K = line[1];
            }

            long ret = 0;

            long C = N / K;
            ret += C * C * C;

            if (K % 2 == 0)
            {
                // 余りがK/2の個数
                long C2 = (N + K / 2) / K;
                ret += C2 * C2 * C2;
            }
                
            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(1000000)
n,m,q = map(int,input().split())
t=[]
def dfs(l):
  if len(l) == n:
    return [l]

  if len(l) == 0:
    t=1
  else:
    t=l[-1]
  res=[]
  for i in range(t, m+1):
    temp=l+[i]
    for j in dfs(temp):
      res.append(j)
  return res

for i in range(q):
  t.append(list(map(int, input().split())))

ans=0
l=dfs([])
for i in l:
  temp=0
  for a,b,c,d in t:
    if i[b-1]-i[a-1] == c:
      temp+=d
  ans=max(ans,temp)
print(ans)
  


Measured memory_bytes: 23480
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100100];
long long res;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int minu=0;
	for(int i=1;i<=n;i++){
		if(a[i]<0)
			minu++;
		a[i]=abs(a[i]);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(minu%2==1&&i==1)
			res-=a[i];
		else
			res+=a[i];
	}
	cout<<res<<endl;
	return 0;
}


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

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	vector<int>b(n), c(n+1);
	for (int i = 0; i < n; i++)cin >> b[i];
	for (int i = 1; i <n; i++)cin >> c[i];
	int ans = 0;
	for (int i = 0; i < n; i++)ans += b[i];
	for (int i = 0; i < n - 1; i++) {
		if (a[i + 1] == a[i] + 1)ans += c[a[i]];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i,n) scanf("%d",&v[i]);
  vi v1(100001,0);
  vi v2(100001,0);
  for (int i = 0; i < n;i += 2) v1[v[i]]++;
  for (int i = 1; i < n;i += 2) v2[v[i]]++;
  int v1max=1;
  int v1maxnum=0;
  int v1max2num=0;
  int v1singlemax=0;
  rep(i,100001){
    if(v1[i]>v1maxnum){
      v1max=i;
	    v1max2num = v1maxnum;
      v1maxnum=v1[i];
      v1singlemax=0;
    }
    else if(v1[i]==v1maxnum) v1singlemax=1;
    else if(v1[i]>v1max2num) v1max2num=v1[i];
  }

  int v2max=1;
  int v2maxnum=0;
  int v2max2num=0;
  int v2singlemax=0;
  rep(i,100001){
    if(v2[i]>v2maxnum){
      v2max=i;
      v2max2num=v2maxnum;
      v2maxnum=v2[i];
      v2singlemax=0;
    }
    else if(v2[i]==v2maxnum) v2singlemax=1;
    else if(v2[i]>v2max2num) v2max2num=v2[i];
  }

  if(v1max!=v2max) cout << (n-v1maxnum-v2maxnum);
  else{
    if(v1singlemax==1 || v2singlemax==1) cout<<(n-v1maxnum-v2maxnum);
    else cout << min(n-v1maxnum-v2max2num,n-v2maxnum-v1max2num);
  }

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n,ans = 0;
  string s,ss,sss;
  cin>>a;
  cout<<(ll)ceil((double)a/2.0)<<endl;
  return 0;
}


Measured memory_bytes: 256
//解説AC

#include <bits/stdc++.h>

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int N,M;
vector<vector<bool>> G(50,vector<bool>(50,false));
vector<int> A(50),B(50);
vector<bool>visited(50);

void dfs(int v){
    visited[v]=true;
    rep(v2,N){
        if(G[v][v2]==false)continue;//繋がっていないなら
        if(visited[v2]==true)continue;//訪問済みなら
        dfs(v2);
    }
}


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

    rep(i,M){
        cin>>A[i]>>B[i];
        A[i]--,B[i]--;
        G[A[i]][B[i]]=G[B[i]][A[i]]=true;
    }
    int ANS=0;
    for(int i=0;i<M;i++){
        G[A[i]][B[i]]=G[B[i]][A[i]]=false;//取り除く

        rep(j,N)visited[j]=false;//初期化

        dfs(0);//visitedの更新

        bool bridge=false;
        rep(j,N)if(visited[j]==false)bridge=true;//一つでもtrueにされていなかったらそれは非連結にされたと言うことなので
        if(bridge)ANS++;

        G[A[i]][B[i]]=G[B[i]][A[i]]=true;//元に戻す
    }

    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256