akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        long A = Reader.Long(), B = Reader.Long();
        if (A == B) { Console.WriteLine(1); return; }
        int at = Enu.Range(0, 60).Last(i => (A >> i & 1) != (B >> i & 1));
        long X = 1L << at;
        A &= (X << 1) - 1;
        B &= (X << 1) - 1;
        long Bmax = X + (1L << Enu.Range(1, at).LastOrDefault(i => (B >> i - 1 & 1) == 1));
        long[] L = new long[3], R = new long[3];
        L[0] = A; R[0] = X;
        L[1] = X; R[1] = Bmax;
        L[2] = X + A; R[2] = X << 1;
        Console.WriteLine(SumLen(L, R));
    }

    long SumLen(long[] L, long[] R)
    {
        var P = new long[L.Length * 2];
        for (int i = 0; i < L.Length; i++)
        {
            P[i * 2] = L[i] << 1;
            P[i * 2 + 1] = R[i] << 1 | 1;
        }
        Array.Sort(P);
        long sum = 0, prev = P[0] >> 1, balance = 0;
        foreach (var p in P)
        {
            long x = p >> 1;
            if (balance > 0) sum += x - prev;
            balance -= ((p & 1) << 1) - 1;
            prev = x;
        }
        return sum;
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
int main(void){
    int a,b;
    printf("");scanf("%d %d",&a,&b);
    
    if(a < b){
        puts("a < b");
    }else if(a > b){
        puts("a > b");
    }else{
        puts("a == b");
    }
    return 0;
}


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

using namespace std;

class Solution {
public:
	void solve() {
		int h1, m1, h2, m2, k;
		cin >> h1 >> m1 >> h2 >> m2 >> k;
		int t1 = h1 * 60 + m1;
		int t2 = h2 * 60 + m2;
		cout << t2 - t1 - k << "\n";

		return;
	};
};

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

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

using namespace std;
using ll = long long;

int main() {
    int H, W;
    cin >> H >> W;
    string grid = string(W + 2, 'X');

    string s;
    for (int i = 0; i < H; ++i) {
        cin >> s;
        grid += 'X' + s + 'X';
    }
    grid += string(W + 2, 'X');

    vector<int> empty;
    for (int i = 0; i < grid.length(); ++i) {
        if (grid[i] == '.')
            empty.push_back(i);
    }

    int move[] = {-1, 1, W + 1, W + 2, W + 3, -(W + 1), -(W + 2), -(W + 3)};
    for (int x : empty) {
        int cnt = 0;
        for (int dx : move) {
            int y = x + dx;
            if(grid[y] == '#')
                ++cnt;
        }
        grid[x] = cnt + '0';
    }
    
    for(int i = 0; i < H; ++i)
    {
        int s = W + 3 + (W + 2) * i;
        cout << grid.substr(s, W) << endl;
    }
}


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


int main(){

  vector<bool> prime(60000, true);
  prime[0] = false;
  prime[1] = false;
  for(int i=2; i<60000; i++){
    if( !prime[i] ) continue;
    for(int j=i*2; j<60000; j+=i){
      prime[j] = false;
    }
  }

  int n;
  while(cin >> n){
    int tmp = 2;
    for(int i=n-1; i>=0; i--){
      if( prime[i] ){
        tmp = i;
        break;
      }
    }
    for(int i=n+1; i<60000; i++){
      if( prime[i] ){
        cout << tmp << " " << i << endl;
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	
    int a,b,c,d;
    cin >> a >> b >> c>>d;
    cout<< min(a,b)+min(c,d) << endl;
    return 0;

  }    

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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}



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

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

    if(b % a == 0){
        cout << a + b << endl;
    }
    else{
        cout << b - a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int UF[214514],UF2[214514];
void UFinit(int n){
    for(int i=0;i<=n;i++){
        UF[i]=i;
    }
}
int UFroot(int k){
    if(UF[k]==k){
        return k;
    }else{
        UF[k]=UFroot(UF[k]);
        return UF[k];
    }
}
int UFsame(int P,int Q){
    if(UFroot(P)==UFroot(Q)){
        return true;
    }else{
        return false;
    }
}
void UFunite(int P,int Q){
    int p=UFroot(P);
    int q=UFroot(Q);
    if(p==q)return;
    if(p>q)swap(p,q);
    UF[q]=p;
}


signed main(){
    int N,K,L;
    int p[114514],q[114514],r[114514],s[114514];
    cin >> N >> K >> L;
    map<pair<int,int>,int> MP;
    REP(i,K){
        cin >> p[i] >> q[i];
        p[i]--;q[i]--;
    }
    REP(i,L){
        cin >> r[i] >> s[i];
        r[i]--;s[i]--;
    }
    UFinit(200000);
    REP(i,L){
        UFunite(r[i],s[i]);
    }
    REP(i,N){
        UF[i]=UFroot(i);
    }
    REP(i,200001){
        UF2[i]=UF[i];
    }
    UFinit(200000);
    REP(i,K){
        UFunite(p[i],q[i]);
    }
    REP(i,N){
        UF[i]=UFroot(i);
    }
    REP(i,N){
        MP[make_pair(UF[i],UF2[i])]++;
    }
    //REP(i,N){cout << UF[i] << " ";}cout << endl;
    //REP(i,N){cout << UF2[i] << " ";}cout << endl;
    REP(i,N){
        if(i!=0)cout << " ";
        cout << MP[make_pair(UF[i],UF2[i])];
    }cout << Endl;
    
    return 0;
}   


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

#define ll long long

ll a[3001][3001], dp[3001][3001][4];

int main()
{
    ll i, j, n, m, k, x, y, v, p, ans;

    cin >> n >> m >> k;

    memset(a, 0, sizeof(a));
    for(i=0; i<k; i+=1)
    {
        cin >> x >> y >> v;
        a[x][y]=v;
    }

    memset(dp, 0, sizeof(dp));
    for(i=1; i<=n; i+=1)
    {
        for(j=1; j<=m; j+=1)
        {
            // 0
            for(p=0; p<4; p+=1)
                dp[i][j][0]=max(dp[i][j][0], dp[i-1][j][p]);
            dp[i][j][0]=max(dp[i][j][0], dp[i][j-1][0]);

            // 1
            if(a[i][j]!=0)
            {
                for(p=0; p<4; p+=1)
                    dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][p]+a[i][j]);

                dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][0]+a[i][j]);
            }
            dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][1]);

            // 2
            if(a[i][j]!=0 && dp[i][j-1][1]!=0)
                dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][1]+a[i][j]);

            dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][2]);

            // 3
            if(a[i][j]!=0 && dp[i][j-1][2]!=0)
                dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][2]+a[i][j]);

            dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][3]);
        }
    }

    ans=0;
    for(i=0; i<4; i+=1)
        ans=max(ans, dp[n][m][i]);

    cout << ans << endl;
}

Measured memory_bytes: 355416
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

ll aa[205][205];
long  arr[10];

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    map<long, long> xx;

    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
        xx[a[i]-1]++;
        xx[a[i]]++;
        xx[a[i]+1]++;
    }

    long max=0;
    auto it = xx.begin();
    for(; it!=xx.end(); ++it) {
        if( it->second > max) {
            max=it->second;
        }
    }

    printf("%ld\n", max);

    return 0;
}


Measured memory_bytes: 6912
# N,M = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
S = [s for s in str(input())] # ['1', '2', '5']

sum =0
for bit in range(1 << len(S) -1):
    l = []
    tmpS = [s for s in S]
    for i in range(len(S) -1):
        if(bit & (1 << i)):
            l.append(i)
    for i in l:
        tmpS[i] += "+"
    sum+=eval("".join(tmpS))

print(sum)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nk = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var hei = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var dp = new int[nk[0]];
        dp[0] = 0;
        for(var i = 1; i < nk[0]; i++)
        {
            var min = int.MaxValue;
            for (var j = 1; j <= nk[1]; j++)
            {
                if (i - j < 0) break;
                min = Min(min, dp[i - j] + Abs(hei[i] - hei[i - j]));
            }
            dp[i] = min;
        }
        WriteLine(dp[nk[0] - 1]);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
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(){
    ll n, k;
    cin >> n >> k;
    if(k % 2 == 0) {
        ll c1 = n * 2 / k - n / k;
        ll c2 = n / k;
        cout << c1 * c1 * c1 + c2 * c2 * c2 << endl;
    }
    else {
        ll c = n / k;
        cout << c * c * c << endl;
    }
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
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)

const int kMaxN = 100;

int n;
int ans = 0;

set<int> s;

int main() {
  cin >> n;
  REP(i, n) {
    int t;
    cin >> t;
    s.insert(t);
  }

  ans = s.size();

  cout << ans << endl;
  return 0;
}


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

int main(void) {
  long A, B, tmp, r, x;
  cin >> A >> B;
  
  x = A * B;
  
  if(A<B){
    tmp = A;
    A = B;
    B = tmp;
  }
  
  r = A % B;
  while(r != 0){
    A = B;
    B = r;
    r = A % B;
  }
  
  cout << x / B << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair 
#define pii pair<int,int>
int main()
{ // int a[3]={0};
  int n,i,t=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  
  sort(a,a+n);
  int j,k;
  for(i=0;i<n-2;i++)
      for(j=i+1;j<n-1;j++)
           for(k=j+1;k<n;k++)
           {
           if(a[i]!=a[j]&&a[j]!=a[k])
           {
             if((a[i]+a[j])>a[k])
               t++;
           }
           
           }
 
  
  cout<<t;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=200020,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn];
vector<PII> v;
bool add(int x,int upr){
//	printf("add(%d,%d)\n",x,upr); 
	if(!x) return false;
	if(!v.empty()) assert(x>=v.back().first);
	if(!v.empty() && x==v.back().first){
		v.back().second++;
		if(v.back().second>upr){
			v.pop_back();
			return add(x-1,upr);
		}
	}
	else v.PB(MP(x,2));
	return true;
}
bool check(int upr){
	v.clear();
	FOR(i,1,n) if(a[i]<=a[i-1]){
		while(!v.empty() && v.back().first>a[i]) v.pop_back();
		if(!add(a[i],upr)) return false;
	}
	return true;
}
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	bool flag=true;
	FOR(i,1,n-1) flag&=a[i]<a[i+1];
	if(flag) return puts("1"),0; 
	int l=2,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <stack>
#include <queue>

using namespace std;
const int maxn = 1005;
const int inf = 1e6;

typedef pair<int, int> P;
char data[maxn][maxn];
int dist[maxn][maxn];
int sx, sy, w, h, n, sum;
P fac[15];

void initialize()
{
    for(int i=0; i<h; ++i)
    {
        for(int j=0; j<w; ++j)
        {
            dist[i][j] = inf;
        }
    }
}

void bfs(P s, P g)
{
    int a[4] = {-1, 0, 1, 0}, b[4] = {0, -1, 0, 1};
    queue<P> que;
    que.push(s);

    while(!que.empty())
    {
        P cur = que.front();
        que.pop();

        if(cur==g)  return;

        int x = cur.first, y = cur.second;
        for(int i=0; i<4; ++i)
        {
            int nx = x + a[i], ny = y + b[i];
            if(nx>=0 && nx<h && ny>=0 && ny<w && data[nx][ny]!='X' && dist[nx][ny]==inf)
            {
                que.push(P(nx, ny));
                dist[nx][ny] = min(dist[nx][ny], dist[x][y]+1);
            }
        }
    }
}

int main()
{
    //while(scanf("%d%d", &w, &h)!= EOF && w && h){
    scanf("%d%d%d", &h, &w, &n);
    for(int i=0; i<h; ++i)
        scanf("%s", &data[i]);

    for(int i=0; i<h; ++i)
    {
        for(int j=0; j<w; ++j)
        {
            if(data[i][j]=='S')
            {
                fac[0] = P(i,j);
            }
            else if(data[i][j]>='1' && data[i][j]<='9')
                fac[data[i][j]-'0'] = P(i,j);
        }
    }
    sum = 0;
    for(int i=1; i<=n; ++i)
    {
        int x = fac[i-1].first, y = fac[i-1].second;
        initialize();
        dist[x][y] = 0;
        bfs(fac[i-1], fac[i]);
        //data[x][y] = '.';
        sum += dist[fac[i].first][fac[i].second];
        //cout << sum << endl;
    }
    printf("%d\n", sum);

    //}
    return 0;
}



Measured memory_bytes: 8104
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;
#define ll long long

int main() {
    string s;
    cin >> s;

    int d[4] = { 0 };
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'N') { ++d[0]; }
        if (s[i] == 'W') { ++d[1]; }
        if (s[i] == 'S') { ++d[2]; }
        if (s[i] == 'E') { ++d[3]; }
    }

    bool can = true;
    if (d[0] > 0) {
        if (d[2] == 0) { can = false; }
    }
    if (d[2] > 0) {
        if (d[0] == 0) { can = false; }
    }
    if (d[1] > 0) {
        if (d[3] == 0) { can = false; }
    }
    if (d[3] > 0) {
        if (d[1] == 0) { can = false; }
    }

    if (can) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }

    return 0;
}

Measured memory_bytes: 256
# Atcoder Problem Solving
# Sum Equals Xor
L = input()
ans = 0
mod = 10**9+7
L = L[::-1]
N = len(L)
dp = [0 for i in range(N+10)]

if L[0] == "0":
    dp[0] = 1
else:
    dp[0] = 3
for i in range(1, N):
    if L[i] == "1":
        dp[i] = 2*dp[i-1]+pow(3, i, mod)
        dp[i] %= mod
    else:
        dp[i] = dp[i-1]
print(dp[N-1] % mod)


Measured memory_bytes: 45424
#include <iostream>
using namespace std;
const long long M = 1e9 + 7;
int main()
{
    long long ans = 1;
    int n;
    int count_c[26] = {};
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        count_c[s[i] - 'a']++;
    }
    for(int i = 0; i < 26; i++){
        ans = (ans * (count_c[i] + 1) % M) % M;
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(string, S, N);
    set<string> A;
    FOR(s, S)
    {
        A.insert(s);
    }
    OUT(A.size());
}

Measured memory_bytes: 25168
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
 long long int n;
  cin >> n;
  vector<long long int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
 long long int count=0;
  for(int i=0;i<n;i++){
    if(vec.at(i)<0){
      count++;
      vec.at(i)=vec.at(i)*-1;
    }
  }
  sort(vec.begin(), vec.end());
 long long int ans=0;
  for(int i=0;i<n;i++){
    ans+=vec.at(i);
  }
  if(count%2==0){
    cout << ans << endl;
  }
  else{
    cout << ans-vec.at(0)*2 << endl;
  }
}

Measured memory_bytes: 1024
abk=list(map(int,input().split()))

if abk[2]<=abk[0]:
    print(abk[0]-abk[2],abk[1])
elif abk[2]<=abk[0]+abk[1]:
    print(0,abk[0]+abk[1]-abk[2])
else:
    print(0,0)


Measured memory_bytes: 3060
/*
 * FileName:     max_heap_fix
 * CreatedDate:  2020-08-19 23:12:45 +0900
 * LastModified: 2020-08-19 23:23:26 +0900
 */

#include <stdio.h>
#include <stdlib.h>


void maxheapify(int *a, int index, int H){
    int key = index;
    if(2*index<=H && a[2*index]>a[index]){
        key = 2*index;
    }
    if(2*index+1<=H && a[2*index+1]>a[key]){
        key = 2*index+1;
    }
    if(key != index){
        int tmp = a[key];
        a[key] = a[index];
        a[index] = tmp;
        maxheapify(a, key, H);
    }
}


void build_heap(int *a, int H){
    for(int i=H/2; i>0; i--){
        maxheapify(a, i, H);
    }
}


int main(void){
    int H;scanf("%d", &H);
    int *a = malloc((H+1)*sizeof(int));
    for(int i=1; i<H+1; i++) scanf("%d", a+i);
    build_heap(a, H);
    for(int i=1; i<H+1; i++){
        printf(" %d", a[i]);
    }
    printf("\n");
    free(a);
    return 0;
}



Measured memory_bytes: 3312
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll n;
    cin >> n;

    cout << (n * (n - 1) / 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


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

typedef map< long long, int > pf;
pf prime_factor(long long n) {
  pf ret;
  long long i = 2;
  while (1) {
    if (i*i > n) break;
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
    i+=i%2?2:1;
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

pf lcm_pf (vector<pf>& a) {
    pf ret;
    ret[1] = 0;
    for (auto el: a) {
        for (auto el2:el) {
            chmax(ret[el2.first],el2.second);
        }
    }
    return ret;
}

ll num_pf (pf a) {
    ll ret = 1;
    for (auto el: a) {
        rep(i,0,el.second) {
            ret *= el.first;
        }
        ret %= MOD;
    }
    return ret;
}

int main(void) {
    ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i,0,N) cin>>A[i];

    vector<pf> Apr(N);
    rep(i,0,N) Apr[i] = prime_factor(A[i]);

    pf lcm = lcm_pf(Apr);

    ll ans = 0;
    ll lcm_n = num_pf(lcm);
    rep(i,0,N) {
        ans += lcm_n * modinv(A[i],MOD);
        ans %= MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;

   return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n,m,temp;
int match[10] = {100000,2,5,5,4,5,6,3,7,6};
int a[10];
int dp[10001][10];

// a>b の判定
// 1. 桁数
// 2. 大きい数字の個数
bool comp(int a[10], int b[10]) {
    if (a[0] == b[0]) {
        for (int i=9;i>0;i--) {
            if (a[i] == b[i]) continue;
            else return a[i] > b[i];
        }
    }
    return a[0] > b[0];
}

signed main() {
    for (int i=0;i<10;i++) a[i] = INF;
    cin >> n >> m;
    for (int i=0;i<m;i++) {
        cin >> temp;
        a[temp] = match[temp];
    }
    
    for (int i=9;i>0;i--) {
        if (a[i] != INF) {
            if (dp[a[i]][0] == 0) {
                dp[a[i]][0] = 1;
                dp[a[i]][i] = 1;
            }
        }
    }

    for (int i=1;i<=n;i++) {
        for (int j=0;j<10;j++) {
            if (i-a[j] >= 0 && dp[i-a[j]][0] != 0) {
                int c[10];
                for (int k=0;k<10;k++) c[k] = dp[i-a[j]][k];
                c[0]++; c[j]++;

                // 大きくなる場合更新
                if (comp(c,dp[i])) {
                    for (int k=0;k<10;k++) {
                        dp[i][k] = c[k];
                    }
                }
            }
        }
    }
    // for (int i=0;i<10;i++) cout << i << " " << dp[n][i] << endl;

    for (int i=9;i>0;i--) {
        while(dp[n][i]>0) {
            cout << i;
            dp[n][i]--;
        }
    }
    cout << endl;
}

// dp[n] = ちょうどn本使って作れる数のバケット
// dp[n][k] = n本使ったときのkの個数
// dp[n][0] = 桁数
// 操作: a[j]本使ってjを作る
// より大きくなる場合にdp[n] = dp[n-a[j]] ← j とする
// n-a[j]>=0, dp[n-a[j]] != 0 (配列の中，ちょうどn本なのであまりがないようにする)
// 初期条件: 使える数jについて，そのコストa[j]でのその個数dp[a[j]][j]と桁数をdp[a[j]][0] を1にする
// 比較の実装: 数字の個数→数字が大きい順に数字の個数


Measured memory_bytes: 1024
def main():
    ls = list(input())
    cnt = 0
    ans = 0
    for i in range(len(ls)):
        if ls[i]=="g":
            if cnt>=1:
                ans +=1
                cnt -=1
            else:
                cnt +=1
        else:
            if cnt>=1:
                cnt -=1
            else:
                cnt +=1
                ans -=1
    print(ans)
                
if __name__ == "__main__":
    main()

Measured memory_bytes: 49392
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
 
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if (a+b+c >= 22)
    {
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0;i < h;i++)
    {
        cin >> s[i];
        s[i] = "#" + s[i] + "#";
    }
    for(int i = 0;i < w + 2;i++)
        cout << "#";
    cout << '\n';
    for(int i = 0;i < h;i++)
    {
        cout << s[i] << '\n';
    }
    for(int i = 0;i < w + 2;i++)
        cout << "#";
    cout << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int conpar(const int *val1, const int *val2);
int n,a[100],i,alice,bob;
int m = sizeof(a)/sizeof(a[0]);
int main(void){
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),conpar);
    for(i = 0;i < n;i++){
        if(i%2 == 0||i == 0){
      alice += a[i];
        }else{
            bob += a[i];
        }
    }
    printf("%d",alice-bob);

    return EXIT_SUCCESS;
}
int conpar(const int *vall,const int *val2){
    if (*vall < *val2){
        return 1;
    }else if( *vall ==*val2){
        return 0;
    }else{
        return -1;
    }
}

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


def solve(N: int, a: "List[int]"):
    all_a = a[0]
    for ai in a[1:]:
        all_a = all_a ^ ai
    ans = []
    for ai in a:
        ans.append(all_a^ai)
    print(*ans)
    
    return


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

if __name__ == '__main__':
    main()


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, c, ans = 0;
	cin >> n >> m >> c;
	vector <int> b(m);
	for (int i=0; i<m; i++) {
		cin >> b[i];
	}
	for (int q=1; q<=n; q++) {
		int res = c;
		for (int i=1; i<=m; i++) {
			int x; cin >> x;
			res += x*b[i-1];
		}
		ans += res>0;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 892
N,Y = map(int,input().split())


for i in range(0,N+1):
  for j in range(0,N-i+1):
    k = N-i-j
    total = 10000*i + 5000*j + 1000*k
    if total == Y:
      print(i,j,k)
      exit()

print(-1,-1,-1)

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        long h = in.nl(), w = in.nl();
        int n = in.ni();
        int[] dx = new int[]{0,0,1,1,1,0,-1,-1,-1};
        int[] dy = new int[]{0,1,1,0,-1,-1,-1,0,1};
        HashMap<Point, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = in.ni(), b = in.ni();
            for (int j = 0; j < 9; j++) {
                if(a+dx[j]<=1||a+dx[j]>=h||b+dy[j]<=1||b+dy[j]>=w) continue;
                Point p = new Point(a+dx[j], b+dy[j]);
                map.put(p, map.containsKey(p)?map.get(p)+1:1);
            }
        }
        long[] ans = new long[10];
        for(Point p: map.keySet()) ans[map.get(p)]++;
        ans[0] = (h-2)*(w-2)-map.size();
        for(long l: ans) out.println(l);
    }
    public static class Point{
        int x, y;
        public Point(int x, int y){
            this.x = x; this.y = y;
        }
        @Override
        public boolean equals(Object o){
            return ((Point)o).x==x&&((Point)o).y==y;
        }
        @Override
        public int hashCode(){
            long res = 114514;
            res *= x;
            res %= mod;
            res *= y;
            res %= mod;
            return (int)res;
        }
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 119180
#include <stdio.h>
#include <vector>
#include <algorithm>

#define lli long long int
#define pb push_back

using namespace std;

int main() {
	lli n, k, a, pref[1010], ans = 0, mo, dua = 1099511627776;
	vector<lli> v[3];
	scanf("%lld %lld", &n, &k);
	pref[0] = 0;
	for (lli i = 1; i <= n; i++) {
		scanf("%lld", &pref[i]);
		pref[i] += pref[i - 1];
	}
	for (lli i = 1; i <= n; i++)
		for (lli j = i; j <= n; j++) {
			a = pref[j] - pref[i - 1];
			v[0].pb(a);
		}
	mo = 0;
	for (lli i = 40; i >= 0; i--) {
		v[1 - mo].clear();
		for (lli j = 0; j < (lli) v[mo].size(); j++) {
			a = v[mo][j];
			if (a & dua)
				v[1 - mo].pb(a);
		}
		if ((lli) v[1 - mo].size() >= k) {
			ans += dua;
			mo = 1 - mo;
		}
		dua /= 2;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6128
#include<bits/stdc++.h>
#define IL inline
#define _ 6005
#define ll long long
using namespace std ;

IL int gi(){
	int data=0,fu=1; char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')fu=-1,ch=getchar();
	while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();return data*fu;
}

int n,X,Fac[_],IFac[_],Ans;
#define mod 998244353
IL int Pow(int ts,int js){int al=1;while(js){if(js&1)al=1ll*al*ts%mod;ts=1ll*ts*ts%mod;js>>=1;}return al; }

IL int Comb(int N,int M){if(M>N||N<0||M<0)return 0; return 1ll*Fac[N]*IFac[M]%mod*IFac[N-M]%mod; }
IL int S(int a,int b){if(a<b||a<0||b<0)return 0; return Comb(b,a-b); }
IL int Calc(int K){
	int ret=0;
	for(int i=0;i<=X-1;++i)ret=(ret+S(i,K))%mod;
	bool flag=false;
	for(int i=1;i<=(K-1)/2;++i){
		int s=X-1-2*i,l=K-2*i; if(l*2==s)continue; 
		ret=(ret+S(s,l))%mod;
	}
	return ret+((X&1)&&(2*K>X));
}
int main(){
	n=gi(); X=gi();
	Fac[0]=1; for(int i=1;i<=n;++i)Fac[i]=1ll*Fac[i-1]*i%mod;
	IFac[n]=Pow(Fac[n],mod-2);
	for(int i=n;i>=1;--i)IFac[i-1]=1ll*i*IFac[i]%mod; 
	for(int K=0;K<=n;++K){
		//cout<<K<<": "<<Calc(K)<<" ; "<<Comb(n,K)<<endl;
		Ans=(Ans+1ll*Comb(n,K)*Calc(K)%mod)%mod;
	}
	printf("%d\n",Ans%mod);
	return 0;
}


Measured memory_bytes: 256
q = int(input())
for i in range(q):
  a, b = list(map(int, input().split()))
  if a==b:
    ans = 2*a-2
  elif abs(a-b)==1:
    ans = 2*min(a, b)-2
  else:
    c = (a*b)**0.5
    if c%1==0:
      c = int(c)-1
    else:
      c = int(c)
    if c*(c+1)>=a*b:
      ans = 2*c-2
    else:
      ans = 2*c-1
  print(ans)


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

void trace(int A[], int N){
  int i;
  for(i=0;i<N;i++){
    if(i) cout<<" ";
    cout << A[i];
  }
  cout << endl;
}

void insertionSort(int A[], int N){
  int i,j,v;
  for(i=1;i<N;i++){
    v=A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j --;
    }
    A[j+1]=v;
    trace(A,N);
  }
}

int main() {
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++) cin>>A[i];
  trace(A,N);
  insertionSort(A,N);
}


Measured memory_bytes: 3096
#include <vector>
#include <iostream>
using namespace std;
using ll = long long;

ll MOD = 998244353LL;
ll ADD(ll x, ll y) { return (x+y)%MOD; }
ll MUL(ll x, ll y) { return (x*y)%MOD; }

vector<ll> DP;
ll A,B,R,C;
ll dp(ll r, ll c,bool cbr_allowed) {
  if(r==R && c==C) { return 1LL; }
  ll key = r*(C+1)*2 + c*2 + (cbr_allowed?1:0);
  if(DP[key] >= 0) { return DP[key]; }
  // add row top-right
  ll s1 = r<R ? dp(r+1, c,false) : 0;
  // add col top-right
  ll s2 = c<C ? dp(r, c+1,true) : 0;
  // add row top-left.
  ll s3 = r<R ? MUL(c-1, dp(r+1, c, false)) : 0;
  // add col bottom-right
  ll s4 = (c<C && cbr_allowed ? MUL(r-1, dp(r,c+1, true)) : 0);

  ll ans = ADD(s1, ADD(s2, ADD(s3, s4)));
  //cerr << " r=" << r << " c=" << c << " cbr_allowed=" << cbr_allowed << " row-top-right=" << s1 << " col-top-right=" << s2 << " row-top-left=" << s3 << " col-bottom-right=" << s4 << " ans=" << ans << endl;
  DP[key] = ans;
  return ans;
}

int main() {
  cin >> A >> B >> R >> C;
  DP = vector<ll>((R+1)*(C+1)*2, -1);
  ll ans = dp(A,B,true);
  cout << ans << endl;
}


Measured memory_bytes: 144376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    ll k;
    cin >> n >> k;
    VL a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    sort(all(a));
    sort(rall(b));
    ll ng = -1, ok = 1e18;
    while(abs(ng - ok) > 1){
        ll cnt = k;
        ll mid = (ok + ng) / 2;
        bool clear = true;
        rep(i,n){
            ll score = a[i] * b[i];
            if (mid > score) continue;
            ll diff = score - mid;
            cnt -= ceil((double)diff / b[i]);
            if (cnt < 0){
                clear = false;
                break;
            }
        }
        if (clear) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 6404
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define maxx 100005
#define inf 1000000009
#define edge pair<ll,ll>
using namespace std;
 

 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦

int main()
{
	ll n,k;
	cin>>n>>k;
	ll h[n];
	for(ll i=0;i<n;i++) cin>>h[i];
	ll i;
	ll dp[n];
	for(i=0;i<n;i++)
	{
			dp[i]=inf;
	}
	dp[0]=0;
	ll j;
	for(i=0;i<n;i++)
	{
		for(j=1;j<=k && i+j<n;j++)
		{
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));	
		}	
	}	
	cout<<dp[n-1]<<endl;
}

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

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
#define PI 3.14159265
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    char a; cin >> a;
    if (a <= 91) {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
    return 0;
}


Measured memory_bytes: 3560
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define gc (c=getchar())
char readc()
{
	char c;
	while(gc<'-');
	return c;
}
int read()
{
    char c;
    while(gc<'-');
    if(c=='-')
    {
        int x=gc-'0';
        while(gc>='0')x=x*10+c-'0';
        return -x;
    }
    int x=c-'0';
    while(gc>='0')x=x*10+c-'0';
    return x;
}
#undef gc

const int N=1000+5,M=2000+5,D=1e9+7;
ll mi(ll x,int y)
{
	ll ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
struct edge
{
	int x,y,w;
	bool in;
};
bool operator <(const edge &a,const edge &b)
{
	return a.w<b.w;
}
edge l[M];
int fa[N],sz[N];
int tfa[N],tw[N];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int qiu(int x,int y)
{
	int ans=0;
	while(x!=y)
	if(sz[y]>=sz[x])
	{
		chmax(ans,tw[x]);x=tfa[x];
	}
	else
	{
		chmax(ans,tw[y]);y=tfa[y];
	}
	return ans;
}

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	int n=read(),m=read();
	ll X;
	cin>>X;
	rep(i,1,m)l[i]=(edge){read(),read(),read()};
	sort(l+1,l+m+1);
	rep(i,1,n){fa[i]=i;sz[i]=1;}
	ll sum=0;
	rep(i,1,m)
	{
		int x=find(l[i].x),y=find(l[i].y);
		if(x==y)continue;
		if(sz[x]>sz[y])swap(x,y);
		fa[x]=y;sz[y]+=sz[x];
		tfa[x]=y;tw[x]=l[i].w;
		l[i].in=1;
		sum+=l[i].w;
	}
	ll ans=0;
	if(sum==X)ans=(mi(2,n-1)-2)*mi(2,m-(n-1))%D;
	int cnt1=0,cnt0=0;
	rep(i,1,m)
	if(!l[i].in)
	{
		int w0=qiu(l[i].x,l[i].y);
		ll ns=sum-w0+l[i].w;
		if(ns>X)++cnt1; else
		if(ns==X)++cnt0; 
	}
	(ans+=2*(mi(2,cnt0)-1)%D*mi(2,cnt1))%=D;
	cout<<ans;
}



Measured memory_bytes: 256
def washall_floyd(graph):
    num_v = len(graph)
    for k in range(num_v):
        for i in range(num_v):
            for j in range(num_v):
                if graph[i][j] > graph[i][k] + graph[k][j]:
                    graph[i][j] = graph[i][k] + graph[k][j]
    return graph


n, m, r = map(int, input().split())
r_list = list(map(int, input().split()))
graph = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

graph = washall_floyd(graph)
result = float("inf")
import itertools
permi = itertools.permutations(r_list)
for per in permi:
    r = 0
    start = per[0] - 1
    for p in per[1:]:
        end = p - 1
        r += graph[start][end]
        start = p - 1
    result = min(r, result)
print(result)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long MOD = 1000000007;


int main(){
    string S;
    cin >> S;
    cout << S.at(0) << S.at(1) << S.at(2) << endl;
    return 0;
}

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

int main(){
	int a[3][3];
  	rep(i, 3)rep(j, 3) cin >> a[i][j];
  	int n;
  	cin >> n;
  	rep(i, n){
    	int b;
      	cin >> b;
      
      	rep(j, 3)rep(k, 3){
        	if(a[j][k] == b) a[j][k] = 0;
        }
    }
  	
  	bool ans = false;
  	rep(i, 3){
    	if(a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) ans = true;
    }
  	rep(i, 3){
    	if(a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) ans = true;
    }
	if(a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) ans = true;
  	if(a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) ans = true;

  	if(ans) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

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

#pragma warning(disable : 4996)

using namespace std;

int n, bit[262145];

vector<int> a, b;

void add(int i, int x)
{
	while (i <= n)
	{
		bit[i] += x; i += i & -i;
	}
}

int sum(int i)
{
	int ret = 0;

	while (i > 0)
	{
		ret += bit[i]; i -= i & -i;
	}
	
	return ret;
}

int sum(int l, int r)
{
	return sum(r - 1) - sum(l - 1);
}

int main()
{
	scanf("%d", &n);

	a.resize(n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	b = a; sort(b.begin(), b.end());

	long long ret = 0;

	for (int i = 0; i < n; i++)
	{
		int ptr = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); add(ptr + 1, 1);

		ret += sum(ptr + 2, n + 1);
	}

	printf("%lld\n", ret);

	return 0;
}

Measured memory_bytes: 5288
N = int(input())
A = list(map(int, input().split()))

ans = [0] * N
ans[0] = sum(A) - 2 * sum(A[1:(N - 1):2])
for i in range(1, N):
    ans[i] = 2 * A[i - 1] - ans[i - 1]

print(" ".join(map(str, ans)))


Measured memory_bytes: 19088
k = gets.to_i
a = gets.split.map &:to_i

x = 2
y = 3
a[0...-1].reverse.each{|t|
  x = ((x+t-1)/t)*t
  y = (y/t)*t
  y = ((y+t-1)/t)*t + (t-1)
}

tmp = x
a.each{|t|
  tmp -= tmp%t
}

if tmp != 2
  p -1
  exit
end

puts [x,y]*' '


Measured memory_bytes: 9348