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

using namespace std;

#define MAX_N 200000

typedef long long lint;

struct elem
{
    int a, b;
};

elem v[MAX_N + 1];

int main()
{
    lint rez = 0;

    int n;
    cin >> n;
/*
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
*/

    int i;
    int mn = 2000000000;
    int cate = 0;
    lint rez2 = 0;
    int ok = 0;
    for(i = 1; i <= n; i ++)
    {
        cin >> v[i].a >> v[i].b;
        if(v[i].a > v[i].b)
            ok = 1;
    }

    if(ok == 1)
    {
        for(i = 1; i <= n; i ++)
        {
            rez += v[i].a;

            if(v[i].a > v[i].b)
                mn = min(mn, v[i].b);
        }

        rez -= mn;
    }

    else
    {

    }

    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define Yes(a) if(a)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define plaese return
constexpr auto AC = 0;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int wa = 0,ac=0;
	vector<string> str(m);
	vector<int> a(m),t(n,0);
	rep(i, m)cin >> a[i] >> str[i];
	rep(i, m) {
		if (str[i] == "WA"&&t[a[i]-1]!=-1)t[a[i] - 1]++;
		if (str[i] == "AC" && t[a[i] - 1] != -1)wa += t[a[i] - 1],t[a[i]-1]=-1,ac++;
	}
	cout << ac<<" "<<wa<< endl;
	plaese AC;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n';
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
// typedef pair<int, int> i_i;
// typedef pair<ll, int> ll_i;
// typedef pair<double, int> d_i;
// typedef pair<ll, ll> ll_ll;
// typedef pair<double, double> d_d;
// struct edge {
//     int u, v;
//     ll w;
// };
//
// #define all(x) (x).begin(), (x).end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &ai : a) {
        cin >> ai;
    }
    int m = *max_element(ALL(a));
    double mid = m / 2.0;
    int k = INF;
    for (auto &ai : a) {
        if (ai == m)
            continue;
        k = (abs(mid - ai) < abs(mid - k) ? ai : k);
    }
    cout << m << " " << k;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
//int dx[] = {1, 0};
//int dy[] = {0, 1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    int h,w;
    cin >> h >> w;
    vector<vector<int>> dp(h+10,vector<int>(h+10, inf));
    string s[h];
    rep(i,h) cin >> s[i];
    if(s[0][0] == '.') dp[0][0] = 0;
    else dp[0][0] = 1;
    rep(i,h){
        int dx[] = {1, 0};
        int dy[] = {0, 1};
        rep(j,w){
            rep(k,2){
                int ni = i + dx[k], nj = j + dy[k];
                if(ni >= h || nj >= w) continue;
                if(s[ni][nj] == '#' && s[i][j] == '.') chmin(dp[ni][nj], dp[i][j] + 1);
                else chmin(dp[ni][nj], dp[i][j]);
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (C >= A && C <= B)cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

#define si(v) v.size()
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (n); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

using ll = long long;
using ld = long double;
using namespace std;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << max(a * b, c * d) << endl;
  
  return (0);
}

Measured memory_bytes: 3648
from math import sqrt
import sys
sys.setrecursionlimit(10**6)
def f(b, n):
	if n < b:
		return n
	else:
		return f(b, n // b) + n % b

n = int(input())
s = int(input())

if n < s:
	print(-1)
elif n == s:
	print(n+1)
else:
	divs = []
	for i in range(1, int(sqrt(n-s))+1):
		if (n-s)%i == 0:
			divs.append(i)
			if i != (n-s)//i:
				divs.append((n-s)//i)
	divs.sort()
	for d in divs:
		if f(d+1, n) == s:
			print(d+1)
			break
	else:
		print(-1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define MAX 100002
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<long long int> JINJA(A+2);
	vector<long long int> TERA(B+2);
	
	for(int i=1; i<=A; i++) cin >> JINJA[i];
	for(int i=1; i<=B; i++) cin >> TERA[i];
	JINJA[0]   = LLONG_MIN / 4;
	TERA[0]    = LLONG_MIN / 4;
	JINJA[A+1] = LLONG_MAX / 4;
	TERA[B+1]  = LLONG_MAX / 4;
	
	for(int i=0; i<Q; i++){
		long long int x, ans[6], a, b, c, d;
		cin >> x;
		auto j = lower_bound(JINJA.begin(), JINJA.end(), x);
		auto t = lower_bound(TERA .begin(), TERA .end(), x);
		
		a = x - *(j-1);
		b = x - *(t-1);
		c = *j - x;
		d = *t - x;
		
		ans[0] = max(a, b);
		ans[1] = a * 2 + d;
		ans[2] = a + d * 2;
		ans[3] = b * 2 + c;
		ans[4] = b + c * 2;
		ans[5] = max(c, d);
      
		cout << *min_element(ans, ans+6) << "\n";
	}
	cout << flush;
	return 0;
}

Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n;

vector<int> a;

void input() {
  cin >> n;

  a.resize(n);
  for (auto&& i : a) {
    cin >> i;
  }
}

void solve() {
  for (auto&& i : a) {

    if (i % 2 == 0) {
      bool good = i % 3 == 0 || i % 5 == 0;

      if (!good) {
        cout << "DENIED\n";

        return;
      }
    }
  }

  cout << "APPROVED\n";
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    uint64_t X, Y;
    std::cin >> X >> Y;

    long double n = log2((long double)Y/X) + 1;

    std::cout << (uint64_t)n << std::endl;

    return 0;
}


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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
template <class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif




void solve()
{
    string s,t;
    cin>>s>>t;
    map<char,vector<long long>> items;

    for(int i=0;i<s.size();i++){
        items[s[i]].push_back(i);
    }

    long long cycle=0;

    long long last=-1;

    for(auto c:t){

        if(items.count(c)==0){
            cout<<-1<<endl;
            return;
        }

        auto indexes=items.find(c);

        auto up=upper_bound(indexes->second.begin(),indexes->second.end(),last);

        if(up!=indexes->second.end()){
            last=*up;
        }
        else{
            cycle++;
            last=indexes->second.front();
        }
    }

    long long res=0;

    res=cycle*(long long)s.size();

    res+=last+1;
    cout<<res<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  int sm = 0;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    sm += d[i];
  }
  int64_t ans = 0;
  for (int i = 0; i < n; i++) {
    sm -= d[i];
    ans += d[i] * sm;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <cmath>

using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> squares(h);
    for (int i = 0; i < h; ++i){
        cin >> squares[i];
    }

    int output = 0;
    for(int cols_flag=0; cols_flag < pow(2, h); ++cols_flag){
        for(int rows_flag=0; rows_flag < pow(2, w); ++rows_flag){
            int black = 0;
            for(int i=0; i<h; ++i){
                for(int j=0; j<w; ++j){
                    if(cols_flag & (1 << i) && rows_flag & (1 << j)){
                        if(squares[i][j] == '#'){
                            ++black;
                        }
                    }
                }
            }
            if(black == k){
                ++output;
            }
        }
    }
    cout << output << "\n";
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
int dy[4] = {-1,0,0,1};
int dx[4] = {0,1,-1,0};


int main(){

  int n;
  cin >> n;
  bool is = false;
  rep(i,25){
    if(i*4 > n)break;
    if((n-i*4)%7 == 0)is = true;
  }
  is ? cout << "Yes" << endl : cout << "No" << endl;





  

  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  long a[n];
  for(int i=0; i<n; ++i) cin >> a[i];
  
  long dif = 0;
  int j = 0;
  int k = n-1;
  
  do{
    if(dif <= 0){
      dif += a[j];
      j++;
    }else{
      dif -= a[k];
      k--;
    }
  }while(j <= k);
  
  
  printf("%d\n", abs(dif));

}

Measured memory_bytes: 1792
import fractions
N = int(input())
A = list(map(int, input().split()))

pairwise = True
setwise = False

M = 10**6+1

count = [0 for _ in range(M)]

for a in A:
    count[a] += 1

max_count = 0
for j in range(2,M):
    max_count = max(max_count,sum(count[j::j]))

if max_count == N:
    print('not coprime')
elif max_count >= 2:
    print('setwise coprime')
else:
    print('pairwise coprime')




Measured memory_bytes: 225632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{	
	ll n;
	cin >> n;
	vector<ll> x(n);
	for (int i = 0; i < n; i++) cin >> x[i];
	sort(x.begin(), x.end());

	ll ans = INT_MAX;
	for (int i = x[0]; i <= x[n - 1]; i++) {
		ll sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (i - x[j]) * (i - x[j]);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String S= sc.next();
        byte[] ascii;
        int countA=0;
        int countC=0;
        int Omoji=0;
        try{
            ascii =S.getBytes("US-ASCII");
        }catch(Exception e){
            e.printStackTrace();
            return;
        }
        int a=ascii[0];
        int c = ascii[2];
        if(a==65)countA++;
        for(int i=0;i<ascii.length;i++){
            int b=ascii[i];
            if(b>=65&&b<=90)Omoji++;
            if(b==67&&i<=ascii.length-2&&i!=1)countC++;
        }
        if(countA==1&&countC==1&&Omoji==2)System.out.println("AC");
        else System.out.println("WA");
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    vector<int> r(n);
    for(int i = 0;i < n;i++)cin >> l.at(i) >> r.at(i);
    int ans = 0;
    for(int i = 0;i < n;i++)ans += (r.at(i) - l.at(i) + 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
W, H , x, y = map(int, input().split())

'''
2 4 1 2
'''
if W % 2 == 0 and H % 2 == 0:
    if W / 2 == x and H / 2 == y:
        print(W * H / 2,1)
        exit(0)
print(W * H / 2,0)

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

int main(){
  long N,K;
  long sum=0;
  cin >> N >> K;
  vector<pair<long,long>> a;
  for(long i=0;i<N;i++){
    long b,c;
    cin >> b >> c;
    a.push_back(make_pair(b,c));
  }
  sort(a.begin(),a.end());
  for(pair<long,long>t:a){
    long x,y;
    tie(x,y) = t;
    if(sum+y<K)
    	sum += y;
    else{
    	cout << x << endl;
        break;
    }
  }
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define cinn(a) for(auto &_k:(a)) cin >> _k
#define coutt(a) for(auto &_k:(a)) cout << _k << ' '
inline int cint() { int temp; cin>>temp; return temp; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k,a=0; cin >> n >> k;
    int h[n];
    for(auto &q:h){
        cin >> q;
        a+=(q>=k);
    }
    cout << a;

}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

class Dice{
private:
  int front,back,right,left,top,bottom;
public:
  Dice(int f, int bk, int r, int l, int t, int bt){
    front = f; back = bk;
    right = r; left = l;
    top = t; bottom = bt;
  }
  void turnR(){
    int tmp = top;
    top = left; left = bottom;
    bottom = right; right = tmp;
  }
  void turnL(){
    int tmp = top;
    top = right; right = bottom;
    bottom = left; left = tmp;
  }
  void turnF(){
    int tmp = top;
    top = back; back = bottom;
    bottom = front; front = tmp;
  }
  void turnBk(){
    int tmp = top;
    top = front; front = bottom;
    bottom = back; back = tmp;
  }
  int getF(){ return front;}
  int getBk(){ return back;}
  int getR(){ return right;}
  int getL(){ return left;}
  int getT(){ return top;}
  int getBt(){ return bottom;}  
};
//------------------------------------------------------

int main(void){
  Dice *d;
  int t,f,r,l,bk,bt;
  char op[110];
  
  cin >> t >> f >> r >> l >> bk >> bt;
  d = new Dice(f,bk,r,l,t,bt);
  cin >> op;
  for (char *p=op; *p; p++){
    //cout << d->getT() << " ";
    switch(*p){
      case 'E': d->turnR(); break;
      case 'W': d->turnL(); break;
      case 'S': d->turnF(); break;
      case 'N': d->turnBk(); break;
    }
  }
  cout << d->getT() << endl;
  return 0;
}



Measured memory_bytes: 3112
open Batteries
let explode s = List.init (String.length s) (String.get s)
let s = explode (read_line ())
let k = read_int ()
let rec ans lst n = 
  match lst with
   [] -> print_endline "1"
  | first :: rest when first = '1' && n = (k-1) -> print_endline "1" 
  | first :: rest -> if first = '1' then ans rest (n+1) else print_char first

let _ = ans s 0


Measured memory_bytes: 1024
"use strict";
function Main(input) {
  input = input.split("\n");
  let tmp = input[1].split(" ");

  tmp.sort(function (a, b) {
    return parseInt(a) < parseInt(b) ? 1 : -1;
  });

  let result = 0;
  for (const n in tmp) {
    if (n % 2 == 0) {
      result = result + parseInt(tmp[n]);
    } else {
      result = result - parseInt(tmp[n]);
    }
  }
  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 7500
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template<typename T> class UpdateInterval
{
public:
using ptt = pair<T,T>;
    // 1の区間をsetで保持
    set<ptt> st;
    UpdateInterval(){};
    // [l,r) を k ({0,1})に更新
    void update(ptt a,int k){
        T l = a.first;
        T r = a.second + 1;
        T lb = l, rb = r;
        while(1){
            auto it = st.lower_bound(ptt(l, numeric_limits<T>::min()));
            if(it == st.end()){
                break;
            }
            ptt p = *it;
            if(p.first > r){
                break;
            }
            st.erase(it);
            if(p.second > r){
                rb = max(rb, p.second);
                if(!k) st.insert(ptt(r,p.second));
                break;
            }
        }
        auto it = st.lower_bound(ptt(l, numeric_limits<T>::min()));
        if(it != st.begin()){
            --it;
            ptt p = *it;
            if(p.second >= l){
                st.erase(it);
                if(!k) st.insert(ptt(p.first,l));
                lb = min(lb, p.first);
            }
            if(p.second > r){
                if(!k) st.insert(ptt(r,p.second));
                rb = max(rb, p.second);
            }
        }
        if(k) st.insert(ptt(lb,rb));
    }
};
int main(){
    ll n, x, d;
    cin >> n >> x >> d;
    if(d == 0){
        if(x == 0){
            cout << 1 << endl;
        }else{
            cout << n + 1 << endl;
        }
        return 0;
    }
    map<ll,UpdateInterval<ll>>mp;
    for(ll i = 0; i <= n; i++){
        auto p = minmax(x * i / d + (i - 1) * i / 2, x * i / d + ((n - 1) * n / 2 - (n - i - 1) * (n - i) / 2));
        show(p);
        mp[x * i % d].update(p, 1);
    }
    ll ans = 0;
    for(auto x: mp){
        for(auto y : x.second.st)ans += y.second - y.first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 28416
from collections import deque, defaultdict
n, x, y = map(int, input().split())
inf = 10**10
dp = [[inf]*n for _ in range(n)]
dic = defaultdict(int)


    

for i in range(n):
    l=1
    dp[i][i] = 0
    if i==0 and x==1:
        queue = deque([1, y-1])
        dp[i][1]=1
        dp[i][y-1]=1
        dic[1]+=2
    elif i==0:
        queue = deque([1])
        dp[i][1]=1
        dic[1]+=1
    elif i==n-1 and y==n:
        queue = deque([n-2, x-1])
        dp[i][n-2]=1
        dp[i][x-1]=1
        dic[1]+=2
    elif i==n-1:
        queue = deque([n-2])
        dp[i][n-2]=1
        dic[1]+=1
    elif i==x-1:
        queue = deque([i-1, i+1, y-1])
        dp[i][i+1]=1
        dp[i][i-1]=1
        dp[i][y-1]=1
        dic[1]+=3
    elif i==y-1:
        queue = deque([i-1, i+1, x-1])
        dp[i][i+1]=1
        dp[i][i-1]=1
        dp[i][x-1]=1
        dic[1]+=3
    else:
        queue = deque([i-1, i+1])
        dp[i][i-1]=1
        dp[i][i+1]=1
        dic[1]+=2
    while queue:
        
        t = queue.popleft()
        #dic[]+=1
        if t == x-1 and dp[i][y-1]==inf:
            queue.append(y-1)
            dp[i][y-1]=dp[i][t]+1
            dic[dp[i][t]+1]+=1
        if t == y-1 and dp[i][x-1]==inf:
            queue.append(x-1)
            dp[i][x-1]=dp[i][t]+1
            dic[dp[i][t]+1]+=1
        if not t==0:
            if dp[i][t-1]==inf:
                queue.append(t-1)
                dp[i][t-1]=dp[i][t]+1
                dic[dp[i][t]+1]+=1
        if not t==n-1:
            if dp[i][t+1]==inf:
                queue.append(t+1)
                dp[i][t+1]=dp[i][t]+1
                dic[dp[i][t]+1]+=1

for i in range(1, n):
    print(dic[i]//2)

Measured memory_bytes: 87772
#include <bits/stdc++.h>
          using namespace std;
          #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
          #define M_PI 3.14159265358979323846
          #define data data_
          #define ff first
          #define ss second

          int main()
          {
          // clock_t begin = clock();
          // #ifndef ONLINE_JUDGE
          // freopen("input.txt", "r", stdin);
          // freopen("output.txt", "w", stdout);
          // #endif
          tani_nachi_ke  

          long long n,k;
          cin >> n >> k;
          long long a[n],b[n];
          for(int i = 0; i < n; i++)
               cin >> a[i];
          for(int i = 0; i < n; i++)
               cin >> b[i];
          sort(a,a+n);
          sort(b,b+n,greater<long long>());
          // for(int i = 0; i < n; i++)
          // {
          //     cout << a[i] << " " << b[i] << endl;
          // }

         
         long long l = 0, r = 1e16;
         int t = 0;
         while( l < r)
         {
               t++;
               if(t==100)
                    break;
               long long mid = (l + r)/2;
               long long cur = 0;
               for(int i = 0; i < n; i++)
               {
                    if(a[i]*b[i] > mid)
                    {
                         cur += (a[i]*b[i] + b[i] - 1 - mid)/b[i];
                    }
               }
               // cout << l << " " << r << " " << cur << endl;
               if(cur <= k)
                    r = mid;
               else
                    l = mid+1;
         }
         cout << r << endl;




          // #ifndef ONLINE_JUDGE 
          // clock_t end = clock();
          // cout<<endl<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
          // #endif 
          // return 0;
          }

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

int mozi[30];

using namespace std;

int main(void)
{
    string s;

    cin>>s;

    for(int i = 0;i < s.size();i++)
    {
	mozi[s[i]-'a']++;
    }

    for(int i = 0;i < 30;i++)
    {
	if(mozi[i] % 2 == 1)
	{
	    cout<<"No"<<endl;

	    return 0;
	}
    }

    cout<<"Yes"<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,a,b,c,d,e,p=0;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	while(1){
		if(b<=0&&c<=0)break;
		b=b-d;
		c=c-e;
		a-=1;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 1808
n=int(input())
red=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1],reverse=True)
blue=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for bx,by in blue:
    for rx,ry in red:
        if rx<bx and ry<by:
            ans+=1
            red.remove([rx,ry])
            break
print(ans)


Measured memory_bytes: 80340
n,c,k,*t=map(int,open(0).read().split())
t.sort()
s=t[0]#start
ss=0#start
#end=t[i]
p=0
for i in range(n):
    if t[i]-s>k or i-ss+1>c:
        p+=1
        s=t[i]
        ss=i
print(p+1)

Measured memory_bytes: 14052
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: u64 = iterator.next().unwrap().parse().unwrap();
    let a: u64 = iterator.next().unwrap().parse().unwrap();
    let b: u64 = iterator.next().unwrap().parse().unwrap();

    if a == 0 {
        return "0".to_string();
    }

    let ans: u64 = a * (n / (a + b)) + min(a, n % (a + b));

    return ans.to_string();
}


Measured memory_bytes: 4352
#define q(x,y)(f[x]*h[y]%m*h[(x)-(y)]%m)
const z=1<<18,m=1000000007;long long H,W,A,B,i=1,f[1<<18],g[1<<18],h[1<<18],r;
main(){
for(f[0]=1;i<z;i++)f[i]=f[i-1]*i%m;
for(g[1]=1,i=2;i<z;i++)g[i]=g[m%i]*(m-m/i)%m;
for(h[0]=i=1;i<z;i++)h[i]=h[i-1]*g[i]%m;
for(scanf("%d%d%d%d",&H,&W,&A,&B),i=0;i<W-B;i++)r=(r+q(A+i-1,i)*q(W-i+H-A-2,H-A-1))%m;
i=!printf("%d\n",r);
}

Measured memory_bytes: 6272
#include<stdio.h>

typedef struct{
  char mark;
  int number;
} card;


int main(){

  int num,i,j,min,flag,check=0;
  card CA_1[36],CA_2[36],tmp;
  scanf("%d",&num);

  for(i=0;i<num;i++){
    scanf(" %c%d",&CA_1[i].mark,&CA_1[i].number);
  }

  for(i=0;i<num;i++)CA_2[i]=CA_1[i];

  /*bubble sort*/
  flag=1;
  while(flag){
    flag=0;
    for(j=num-1;j>=1;j--){

      if(CA_1[j].number <CA_1[j-1].number){
        tmp=CA_1[j];
        CA_1[j]=CA_1[j-1];
        CA_1[j-1]=tmp;
        flag=1;
      }
    }
  }


  /*bubble print*/
  for(i=0;i<num-1;i++){printf("%c%d ",CA_1[i].mark,CA_1[i].number);}
  printf("%c%d\n",CA_1[i].mark,CA_1[i].number);
  puts("Stable");

  /*selection sort*/

  for(i=0;i<num-1;i++){

    min=i;
    for(j=i;j<num;j++){
      if(CA_2[j].number < CA_2[min].number){
        min = j;
      }
    }
    if(CA_2[i].number != CA_2[min].number){
      tmp = CA_2[i];
      CA_2[i]=CA_2[min];
      CA_2[min]=tmp;
    }
  }
  /*selection print*/
    for(i=0;i<num-1;i++){printf("%c%d ",CA_2[i].mark,CA_2[i].number);}
    printf("%c%d\n",CA_2[i].mark,CA_2[i].number);


    for(i=0;i<num;i++){
      if(CA_1[i].number == CA_2[i].number && CA_1[i].mark != CA_2[i].mark){
        check=1;
      }
    }
      if(check==1)puts("Not stable");
      else puts("Stable");


      return 0;
  }

Measured memory_bytes: 608
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	cout << endl;
	
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    REP(i, n){
        scanf("%d", &a[i]);
    }
    const int N = 100000000;
    vector<bool> is_prime(N + 1, true);
    for(int i=4; i<=N; i+=2){
        is_prime[i] = false;
    }
    for (int p = 3; p <= N; p+=2) {
        if (!is_prime[p]){
            continue;
        }
        for (int k = p * 2; k <= N; k += p){
            is_prime[k] = false;
        }
    }
    int ans = 0;
    REP(i, n){
        if(is_prime[a[i]]){
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 14924
#include<iostream>
using namespace std;
#define MAX 100

int main()
{
	char a, b, c, d;

	cin >> a >> b >> c >> d;

	if (a == b)
	{
		if (b == c)
		{
			cout << "Yes";
		}
		else
		{
			cout << "No";
		}
	}
	else if (b == c)
	{
		if (c == d)
		{
			cout << "Yes";
		}
		else
		{
			cout << "No";
		}
	}
	else
	{
		cout << "No";
	}
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a > 0 && b > 0){
        c -= b;
        a -= d;
    }
    if(c <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
    string S, T;
    cin >> S >> T;

    int count = 0;
    size_t size = S.length();
    for(int i = 0; i < size; i++){
        if(S[i] != T[i]){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int a=(2*d)+1;
    if(n%a==0) printf("%d\n",n/a);
    else printf("%d\n",(n/a)+1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
int dp[105][105][2],a[105][105];
char book[105][105];
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int n,m;
	cin>>n>>m;
	rep(i,1,n) {
		cin>>book[i];
		rep(j,1,m) {
			if(book[i][j-1]=='.') a[i][j]=0;
			else a[i][j]=1;
		}
	}
	if(a[1][1]) {
		dp[1][1][0]=inf;
		dp[1][1][1]=1;
	}
	else {
		dp[1][1][0]=0;
		dp[1][1][1]=inf;
	}
	rep(i,1,n) {
		rep(j,1,m){
			if(i==1&&j==1) continue;
			int num=inf;
			if(a[i][j]) {
				dp[i][j][0]=inf;
				if(i>1) {
					num=min(num,min(dp[i-1][j][0]+1,dp[i-1][j][1]));
				}
				if(j>1) {
					num=min(num,min(dp[i][j-1][0]+1,dp[i][j-1][1]));
				} 
				dp[i][j][1]=num;
			}
			else {
				dp[i][j][1]=inf;
				if(i>1) {
					num=min(num,min(dp[i-1][j][0],dp[i-1][j][1]));
				}
				if(j>1) {
					num=min(num,min(dp[i][j-1][0],dp[i][j-1][1]));
				} 
				dp[i][j][0]=num;
			}
		}
	}
	cout<<min(dp[n][m][0],dp[n][m][1])<<'\n';
    return 0;
}


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

public class Main 
{
	static int dif(int a, int b)
	{
		int ma = Math.max(a, b);
		int mi = Math.min(a, b);
		return Math.min(b-a, 24 - (b-a));
	}
	static int uncertains;
	static int[] uncertain;
	static boolean[] certain;
	
	static int testcase(int cs)
	{
//		System.out.println("Start case " + Integer.toString(cs,2));
		boolean[] occ = new boolean[24];
		occ[0] = true;
		
		for(int i = 0; i < 24; i++)
			if(certain[i])occ[i]=true;
		
		for(int i = 0; i < uncertains; i++)
		{
			int pos = 0;
			if((mask[i] & cs) > 0)
			{ //inverse
				pos = 24-uncertain[i];
//				System.out.println("Inverse " + i + " into " + pos);
			}
			else
			{ //no-inverse
				pos = uncertain[i];
			}
			
			if(occ[pos])
			{
				return 0;
			}
			else
			{
				occ[pos] = true;
			}
		}
		
		//measure min dis
		int lead = 0;
		int min = 99999999;
		for(int i = 1; i < 24; i++)
		{
			if(occ[i])
			{
//				System.out.println("Occ " + i + ", lead " + lead);
				min = Math.min(min, i-lead);
				
				lead = i;
			}
		}
		if(lead!=0)
		{
			min = Math.min(min, 24-lead);
		}
//		System.out.println("case " + Integer.toString(cs,2) + ": " + min + "\n");
		
		return min;
	}
	
	static int[] mask = new int[12];
	
	public static void main(String[] args) 
	{
		int ms = 1;
		for(int k = 0; k < 12; k++)
		{
			mask[k] = ms;
			ms*=2;
		}
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		boolean[] occ = new boolean[24];
		occ[0] = true;
		
		
		int[] a = new int[n];
		int[] b = new int[n];
		
		int[] pos = new int[n];
		int close = 999;
		
		int[] grouphas = new int[12];
		grouphas[0]=1;
		
		certain = new boolean[24];
		
		for(int i = 0; i < n; i++)
		{
			int c = sc.nextInt();
			if(c==0)
			{
				System.out.println(0);
				return;
			}
			a[i] = c;
			b[i] = 24-c;
			close = Math.min(close, c);
			if(c==12)c-=12;
			grouphas[c]++;
			if(grouphas[c]>=3)
			{
				System.out.println(0);
				return;
			}
			else if(grouphas[c]==2)
			{
				//both possibilities must be occupied
				certain[a[i]]=true;
				certain[b[i]]=true;
			}
		}
		if(n>=24 || close <= 0)
		{
			System.out.println(0);
			return;
		}
		
		int unccount = 0;
		for(int i = 0; i < 12; i++)
			if(grouphas[i] == 1)
				unccount++;
		
		uncertain = new int[unccount];
		uncertains = 0;
		
		for(int i = 1; i < 12; i++)
		{ //tak is def. 0
			if(grouphas[i] == 1)
			{
				uncertain[uncertains] = i;
				uncertains++;
			}
		}
		
		int cases = 1;
		for(int i = 0; i < uncertains; i++)
			cases *= 2;
		
		int maxs = 0;
//		System.out.println(Arrays.toString(uncertain));
//		System.out.println("Cases " + cases);
		for(int c = 0; c < cases; c++)
		{
			maxs = Math.max(maxs, testcase(c));
		}
		System.out.println(maxs);
	}

}


Measured memory_bytes: 23380
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<iostream>
#include<vector>
using namespace std;

int main(void){
	std::vector<int> x(5);
	
	for(int i=0; i<5; i++)cin>>x[i];
	
	int cnt=1;
	for(auto tmp: x){
		if(tmp==0){
			cout<<cnt<<'\n';
			break;
		}
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 3592
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = map(int, input().split())
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1

    ans = 0

    def dfs(seq):
        nonlocal ans
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            ans = max(ans, score)
            return

        score = 0
        start = seq[-1] if seq else 1
        for n in range(start, M + 1):
            seq.append(n)
            dfs(seq)
            seq.pop()

    dfs([])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9288
#include<stdio.h>

#define N 100000

typedef struct{
  char c;
  int n;
  int r;
}Card;

void quickSort(Card[],int,int);
int partition(Card[],int,int);
int isStable(Card[]);

int n;

int main(){
  int i;
  Card A[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %c %d",&A[i].c,&A[i].n);
    A[i].r=i;
  }

  quickSort(A,0,n-1);  

  if(isStable(A)) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].n);
  }

  return 0;
}

void quickSort(Card A[],int p,int r){
  int q;
  if(p<r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
  return;
}

int partition(Card A[], int p, int r){
  int x,i,j;
  Card tmp;

  x=A[r].n;

  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].n<=x){
      i = i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }

  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}

int isStable(Card A[]){
  int i;

  for(i=0;i<n;i++){
    if( A[i].n == A[i+1].n && A[i].r > A[i+1].r ) return 0;
  }
  
  return 1;
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int max_n = 1e6;
ll a[max_n];
int main(){
  ll n; cin >> n;
  map<ll,ll> ma;
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
    ma[a[i]]++;
  }
  if(ma.count(0)){
    if(n%2==0 || ma[0] != 1){
      cout << 0 << endl;
      return 0;
    }
    ma.erase(0);
  }
  ll ans = 1;
  for(auto ite=begin(ma) ; ite != end(ma) ; ite++){
    if(ite -> second %2 != 0){
      cout << 0 << endl;
      return 0;
    }
    ans *= ite -> second % mod;
    ans %= mod;
  }
  cout << ans%mod << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.HashMap;
import java.util.Scanner;

// https://atcoder.jp/contests/abc163/tasks/abc163_c
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 1; i < n; i++) {
			int str = sc.nextInt();
			if (map.containsKey(str)) {
				map.put(str, map.get(str)+1);
			} else {
				map.put(str, 1);
			}
		}
		sc.close();


		for(int i=1;i<=n;i++) {
			if(map.get(i)==null) {
				System.out.println(0);
			}else {
				System.out.println(map.get(i));
			}

		}
	}
}


Measured memory_bytes: 68324
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
import math
F = sys.stdin
N = int(F.readline())
sqN = int(math.sqrt(N))
ans = 0

for i in range(1, sqN+1):
    if N % i == 0:
        A = int(i - 1)
        B = int((N / i) - 1)
        if ans == 0 or A + B < ans:
            ans = A + B

print(ans)


Measured memory_bytes: 5384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int a[210000];
int go[210000];
int ans;
int main() {
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	go[0]=0;
	ans=0;
	for(int i=1;i<n;i++) {
		if(a[i]>a[i-1]) go[i]=go[i-1]+1;
		else go[i]=0;
		if(go[i]>=k-1) {
			ans=1;
		}
	}
	set<int> ss;
	for(int i=0;i<k;i++) ss.insert(a[i]);
	if(go[k-1]!=k-1) ans++;
	for(int i=k;i<n;i++) {
		ss.insert(a[i]);
		if(*ss.begin()!=a[i-k] || *ss.rbegin()!=a[i]) {
			if(go[i]<k-1) ans++;
		}
		ss.erase(a[i-k]);
	}
	cout<<ans<<endl;
	return 0;
}


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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a) cerr << #a << " => " <<"("<<a.fs<<", "<<a.sc<<") " << en;
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debpa(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int n; cin >> n;
	int sum = 0;
	for (int i = 1; i < n; i++) {
		sum += ((n - 1) / i);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3684
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    k = int(input())
    a, b = map(int, input().split())

    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            break
    else:
        print("NG")


if __name__ == '__main__':
    resolve()


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

int main()
{
    int N, W;
    cin >> N >> W;
    vector<long> w(N);
    vector<long> v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    vector<vector<long>> dp(N + 1, vector<long>(100001));
    for (int i = 0; i < N; i++) {
        for (int sw = 0; sw <= 100000; sw++) {
            if (sw - w[i] >= 0) {
                dp[i + 1][sw] = max(dp[i + 1][sw], dp[i][sw - w[i]] + v[i]);
            }
            dp[i + 1][sw] = max(dp[i + 1][sw], dp[i][sw]);
        }        
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include "bits/stdc++.h"

using namespace std;

bool isEven(string s) {
    int n = s.size() / 2;
    for (int i = 0; i < n; ++i) {
        if (s[i] != s[n + i]) {
            return false;
        }
    }
    return true;
}

void Main() {
    string S;
    cin >> S;
    int N = S.size();
    for (int i = 1; i < N; ++i) {
        if ((N - 1 - i) % 2 == 1) {
            continue;
        }
        string s = S.substr(0, N - 1 - i);
        if (isEven(s)) {
            cout << s.size() << endl;
            return;
        }
    }
    cout << "" << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    vector<vector<int>> E(n);
    vector<vector<long long>> S(n);
    for (int i=0; i<m; i++)
    {
        int u, v;
        long long s;
        cin>>u>>v>>s;
        u--, v--;
        E[u].push_back(v);
        S[u].push_back(s);
        E[v].push_back(u);
        S[v].push_back(s);
    }

    vector<long long> V(n);
    vector<bool> X(n);
    vector<bool> F(n);
    int cv = -1;
    long long ca, cb;

    function<void(int,int,long long,bool)> BT = [&](int c, int p, long long v, bool x)
    {
        if (F[c] && X[c] != x)
        {
            cv = c;
            ca = V[c];
            cb = v;
        }
        if (F[c])
            return;
        F[c] = true;
        V[c] = v;
        X[c] = x;
        for (int i=0; i<(int)E[c].size(); i++)
        if (E[c][i] != p)
            BT(E[c][i], c, S[c][i]-v, !x);
    };
    BT(0, -1, 0LL, false);
    if (cv != -1)
    {
        if ((ca-cb)%2 != 0)
        {
            cout<<0<<endl;
            return 0;
        }

        F = vector<bool>(n);
        BT(cv, -1, (ca+cb)/2, false);
    }

    bool ok = true;
    bool bi = true;

    for (int i=0; i<n; i++)
    {
        for (int j=0; j<(int)E[i].size(); j++)
        {
            if (V[i]+V[E[i][j]] != S[i][j])
                ok = false;
            if (X[i] == X[E[i][j]])
                bi = false;
        }
    }

    if (!ok)
    {
        cout<<0<<endl;
        return 0;
    }
    if (!bi)
    {
        if (*min_element(V.begin(), V.end()) > 0)
            cout<<1<<endl;
        else
            cout<<0<<endl;
        return 0;
    }

    long long mn0 = 1000000000000000000LL;
    long long mn1 = 1000000000000000000LL;

    for (int i=0; i<n; i++)
    {
        if (X[i])
            mn0 = min(mn0, V[i]);
        else
            mn1 = min(mn1, V[i]);
    }

    long long ans = max(mn0+mn1-1, 0LL);
    cout<<ans<<endl;
}


Measured memory_bytes: 22912