akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
 int S, h, m, s;
 cin >> S;
 h = S / 3600;
 m = (S % 3600) / 60;
 s = S - (h * 3600 + m * 60);
 cout << h << ":" << m << ":" << s << endl;
 return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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;
}

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

  int N;
  cin >> N;
  vector<int> dp(N + 1, INF);
  dp[0] = 0;
  vector<int> v(1, 1);
  int six = 6;
  while (six <= N) {
    v.push_back(six);
    six *= 6;
  };
  int nine = 9;
  while (nine <= N) {
    v.push_back(nine);
    nine *= 9;
  };
  sort(all(v));

  dump(v.size());

  rep(i,0,v.size()){
    rep(j,v[i],dp.size()){
      chmin(dp[j],dp[j-v[i]]+1);
    }
  }
  cout<<dp[N]<<endl;


  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int x;

		for(int i = 1;i<6;i++) {
			x = scan.nextInt();
			if(x == 0) {
				System.out.println(i);
				break;
			}
		}

	}
}

Measured memory_bytes: 26916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();
	bool A[701][701] = {};
	rep(i, M) {
		int a = getint(), b = getint();
		A[a][b] = true;
		A[b][a] = true;
	}

	vector<int> V;

	int dame = 0;
	int tukatta[701] = {};
	int msum = 0;

	rep1(q, N) {
		if (tukatta[q] == 0) {
			tukatta[q] = 1;
			queue<pair<int, int>> que;
			que.push(mp(q, 1));
			int n[3];
			n[1] = 1;
			n[2] = 0;

			while (que.size()) {
				auto p = que.front();
				que.pop();
				int i = p.first;
				int d = p.second ^ 3;
				rep1(j, N) {
					if (i != j && !A[i][j]) {
						if (tukatta[j] == 0) {
							tukatta[j] = d;
							que.push(mp(j, d));
							n[d]++;
						}
						else if (tukatta[j] != d) dame = 1;
					}
				}
			}
			V.pb(abs(n[1] - n[2]));
			msum += min(n[1], n[2]);
		}
	}

	if (dame) {
		co(-1);
	}
	else {
		bool dp[701] = {};
		dp[0] = true;
		for (auto p : V) {
			for (int i = 700; i >= 0; i--) {
				if (dp[i]) dp[i + p] = true;
			}
		}
		int saishou = 1e9;
		for (int i = 0; i <= 700; i++) {
			if(dp[i]) saishou = min(saishou, abs(N - msum - i - msum - i));
		}
		int X = (N + saishou) / 2;
		int Y = (N - saishou) / 2;
		int kotae = X * (X - 1) / 2 + Y * (Y - 1) / 2;
		co(kotae);
	}

	Would you please return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>

char str[105][105];

int arr[255];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0; i<n; i++){
		scanf("%s",str[i]);
	}
	memset(arr, 0, sizeof(arr));
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			arr[(int)str[i][j]]++;
		}
	}
	int k1=0,k2=0,k4=0;
	for(int i='a'; i<='z'; i++){
		k4+=arr[i]/4*4;
		k2+=arr[i]%4/2*2;
		k1+=arr[i]%4%2;
	}
	bool pass = true;
	if(n%2==1 && m%2==1){
		if(k1>1)
			pass=false;
		if(k2>n+m-2)
			pass=false;
	}else if(n%2==1){
		if(k1>0)
			pass=false;
		if(k2>m)
			pass=false;
	}else if(m%2==1){
		if(k1>0)
			pass=false;
		if(k2>n)
			pass=false;
	}else{
		if(k1>0)
			pass=false;
		if(k2>0)
			pass=false;
	}
	puts(pass?"Yes":"No");
	
	return 0;
}


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

int main (){
	int a, b, c;
	int i,j;

	cin >> a;
	for (i = 0; i < 26; i++) {
		for (j = 0; j < 15; j++) {
			if ((4 * i + j * 7) == a) {
				printf("Yes"); 
				break;
			}
		}
		if (j != 15) { break; }
	}
	if (i == 26) { printf("No"); }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (((a == b) && a != c) || ((a == c) && a != b) || ((b == c) && a != b))
	{
		printf("Yes");
	}
	else printf("No");
}

Measured memory_bytes: 128
N,W=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  w_,v_=map(int,input().split())
  for w in range(W+1):
    if w-w_>=0:
      dp[i+1][w]=max(dp[i][w],dp[i][w-w_]+v_)
    else:
      dp[i+1][w]=dp[i][w]
print(max(dp[N]))

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

int main() {
    int a[5];
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    int k;
    cin >> k;
    bool check = true;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            if (abs(a[i] - a[j]) > k) check = false;
        }
    }
    cout << (check ? "Yay!" : ":(") << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()
    val x = Array(n) { sc.nextInt() }
    var best = 1e8.toInt()
    for (p in 1..100) {
        var s = 0
        for (xi in x) {
            s += (xi - p) * (xi - p)
        }
        if(best > s) best = s
    }
    println(best)
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31392
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))

using namespace std;

int main() {
  int t;cin >> t;
  int arr[t], brr[t];
  if (t == 1) {
    cout << 0 << endl;
    return 0;
  }
  cin >> arr[0];
  cin >> arr[1];
  brr[0] = 0;
  brr[1] = fabs(arr[1] - arr[0]);
  for (int i = 2; i < t; i++) {
    cin >> arr[i];
    brr[i] = min(brr[i-1] + fabs(arr[i-1] - arr[i]),
    brr[i-2] + fabs(arr[i-2] - arr[i]));
  }
  cout << brr[t - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {

    int h = 0;
    int w = 0;
    char[][] square = null;
    String[] tmp = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      tmp = br.readLine().split("\\s");
      h = Integer.parseInt(tmp[0]);
      w = Integer.parseInt(tmp[1]);

      square = new char[h][w];
      for (int i = 0; i < h; i++) {
        square[i] = br.readLine().toCharArray();
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    boolean result = true;

    parentLoop:
    for (int i = 0; i < square.length; i++) {
      final char[] line = square[i];
      for (int j = 0; j < line.length; j++) {
        if (line[j] == '#') {
          if (0 <= i - 1 && square[i - 1][j] != '#') {
            if (i + 1 < h && square[i + 1][j] != '#') {
              if (0 <= j - 1 && square[i][j - 1] != '#') {
                if (j + 1 < w && square[i][j + 1] != '#') {
                  result = false;
                  break parentLoop;
                }
              }
            }
          }
        }
      }
    }
    if (result) {
      System.out.print("Yes");
    } else {
      System.out.print("No");
    }
  }
}

Measured memory_bytes: 23252
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

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

#define int long long
#define ar array
const int INF = 1e10;


void solve(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for(auto& e : arr) cin >> e;
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 1;i < n; i++){
		if(i==1) dp[i] = abs(arr[i] - arr[i-1]);
		else{
			dp[i] = min(dp[i],dp[i-1]+abs(arr[i]-arr[i-1]));
			dp[i] = min(dp[i],dp[i-2]+abs(arr[i]-arr[i-2]));
		}
	}
	cout << dp[n-1] << "\n";
} 

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int TC = 1;
    while(TC--)
        solve();

    return 0;
}



Measured memory_bytes: 4748
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int a[Max],d[Max];
int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n+1;i++)
        d[i]=d[i-1]+a[i-1];
    int ans=0;
    for(int i=1;i<=n+1;i++){
        //printf("%d\n",d[i]);
        if(d[i]<=x)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

//?§??????°??????????????°?????¶????????????????????°
int n,m,h,k;

//???????§???????????§????1day???????????°
int s,t,p;

typedef pair<int,int> P;
typedef pair<P,int> PP;
struct edge{
	int to,cost,time,corp;
	
	edge(int to_,int cost_,int time_,int corp_){
		to=to_; cost=cost_; time=time_; corp=corp_;
	}
	
};
vector<edge> G[100];

const int BIT=1<<8;

// i????????????????????????????????????
int pass_corps[BIT];

// pass_cost[bit] bit?????¨?????????????????????????????????
int pass_cost[BIT];

//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
int corps_cost[BIT];

// d[time][pos]
int d[25][100];

priority_queue<PP,vector<PP>,greater<PP> > q;

const int INF=1e8;

int solve(int use){
	

	for(int i=0;i<=h;i++){
		for(int j=0;j<n;j++) d[i][j]=INF;
	}
	
	d[0][s]=corps_cost[use];
	
	
	// cost,time,pos
	q.push(PP(P(corps_cost[use],0),s));
	while(!q.empty()){
		
		PP pp=q.top(); q.pop();
		
		int cost=pp.first.first,time=pp.first.second,pos=pp.second;
		
		//printf("cost %d, time %d, pos %d\n",cost,time,pos);
		
		if(pos==t){
			while(!q.empty()) q.pop();
			return cost;
		}
		if(d[time][pos]<cost) continue;
		
		for(int i=0;i<G[pos].size();i++){
			edge e=G[pos][i];
			int to=e.to,ncost=cost+e.cost,nt=time+e.time,ncorp=e.corp;
			
			//printf("to %d, ncost %d, nt %d ncorp %d\n",to,ncost,nt,ncorp);
			
			if(nt>h) continue;
			
			if(use&(1<<ncorp)) ncost=cost;
			if(ncost<d[nt][to]){
				d[nt][to]=ncost;
				q.push(PP(P(ncost,nt),to));
			}
			
		}
		
	}
	
	return INF;
	
}

int main(){
	
	while(scanf("%d %d %d %d",&n,&m,&h,&k),n){
		
		for(int i=0;i<n;i++) G[i].clear();
		for(int i=0;i<(1<<k);i++){
			pass_corps[i]=0;
			pass_cost[i]=corps_cost[i]=INF;
		}
		for(int i=0;i<m;i++){
			int a,b,c,h,r;
			scanf("%d %d %d %d %d",&a,&b,&c,&h,&r);
			a--; b--; r--;
			
			G[a].push_back(edge(b,c,h,r));
			G[b].push_back(edge(a,c,h,r));
		}
		
		scanf("%d %d %d",&s,&t,&p);
		s--; t--;
		
		int l,d,corp,corps;
		for(int i=0;i<p;i++){
			
			scanf("%d %d",&l,&d);
			
			corps=0;
			while(l--){
				scanf("%d",&corp);
				corp--;
				corps|=(1<<corp);
			}
			
			pass_corps[i]=corps;
			pass_cost[pass_corps[i]]=d;
		}
				
		//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
		corps_cost[0]=0;
		for(int i=0;i<(1<<k);i++){
			if(corps_cost[i]==INF) continue;
			for(int j=0;j<p;j++){
				corps_cost[i|pass_corps[j]]=min(corps_cost[i|pass_corps[j]],corps_cost[i]+pass_cost[pass_corps[j]]);
			}
		}
		
		int res=INF;
		for(int use=0;use<(1<<k);use++){
			if(corps_cost[use]==INF) continue;
			res=min(res,solve(use));
		}
		if(res==INF) res=-1;
		cout<<res<<endl;	
	}
}

Measured memory_bytes: 3328
#include <atcoder/math>
#include <cstdio>

using namespace std;
using namespace atcoder;


int main(){
  int t;
  scanf("%d", &t);
  
  for (int i = 0; i < t; i ++) {
    long long n, m, a, b;
    scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
    printf("%lld\n", floor_sum(n, m, a, b));
  }

  return 0;
  
}  

Measured memory_bytes: 1696
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parents=[-1]*n
  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
  def same(self,x,y):
    return self.find(x)==self.find(y)
  def members(self,x):
    root=self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]
  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]
  def group_count(self):
    return len(self.roots())
  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}
  def __str__(self):
    return '\n'.join('{}: {}'.format(r,self.members(r)) for r in self.roots())
  
n,m=map(int,input().split())
a,b=[0]*m,[0]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
res=0
for i in range(m):
  UF=UnionFind(n)
  for j in range(m):
    if j!=i:
      UF.union(a[j],b[j])
  if UF.group_count()==2:
    res+=1
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int a,b;
	cin >> a >> b;
	int c = a + b;
	(c%3 == 0 || a%3 == 0 || b%3 == 0)? cout << "Possible" << endl : cout << "Impossible" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
const int N = 1300;
int main (void)
{
	char str[N];
	while(fgets(str, 1300 , stdin))
	{
		int sum = 0;
		if(str[0] == '0')
		{
			break;
		}
		for(int i = 0 ; i < strlen(str)-1 ; i++)
		{
			sum += str[i] - '0';
		}
		printf("%d\n" , sum);
	}
	return 0;
}


Measured memory_bytes: 2088
def merge(data, left, mid, right, count):
    n1 = mid - left
    n2 = right - mid 
    L = []
    R = []
    for i in range(n1):
        L.append(data[left+i])
    for i in range(n2):
        R.append(data[mid+i])
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0 
    j = 0 
    for k in range(left, right):
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
            count += 1
        else:
            data[k] = R[j]
            j += 1
            count += 1
    return count

def merge_sort(data, left, right, count):
    if left + 1 < right:
        mid = (left + right) / 2 
        count = merge_sort(data, left, mid, count)
        count = merge_sort(data, mid, right, count)
        count = merge(data, left, mid, right, count)
    return count

def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)
    count = merge_sort(num_list, 0, len(num_list), 0)
    num_list =  map(str, num_list)
    print " ".join(num_list)
    print count

if __name__ == '__main__':
    main()

Measured memory_bytes: 70424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    
    // j-i = aj+ai
    // j-aj = i+ai, i<j
    map<int, int> mp;
    rep(j, n) ++mp[j - a[j]];
    
    ll ans = 0;
    rep(i, n) {
        --mp[i - a[i]];
        ans += mp[a[i] + i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 21076
#include <iostream>

int main() {
    int r, D, x;

    std::cin >> r >> D >> x;

    int xi = x;

    for (int i = 0; i < 10; i += 1) {
        xi = r * xi - D;
        std::cout << xi << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q,k,x,i;
  cin>>n>>k>>q;
  map<int,int> mapping;
  int a[100005];
  for(i=1;i<=n;i++) a[i]=k-q;
  for(i=0;i<q;i++){
   cin>>x;
   mapping[x]++;
}
  map<int,int>::iterator it;
  for(it=mapping.begin();it!=mapping.end();it++) a[(it->first)]+=(it->second);
  for(i=1;i<=n;i++) if(a[i]>0) cout<<"Yes\n"; else cout<<"No\n";
  //for(i=1;i<=n;i++) cout<<a[i]<<'\n';
  //for(it=mapping.begin();it!=mapping.end();it++) cout<<it->first<<" "<<it->second<<'\n';
  return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,M,P = map(int,(input().split()))
line = []
for i in range(M):
    a,b,c = map(int,(input().split()))
    line.append([a-1,b-1,-c+P])

min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする

def Bellman_Ford(S,V,E,distance):
    
    flag = 0
    for _ in range(V):
        update = False
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = min_distance[s] + d # 最短距離を上書きする
                update = True
        if not update:
            flag = 1
            break
    return min_distance,flag

def Bellman_Ford2(S,V,E,distance):
    for _ in range(V):
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = -float("inf")
                if g == N-1:
                    break
        else:
            continue
        break
    return min_distance

min_distance,flag = Bellman_Ford(1,N,M,line)

if flag == 1:
    ans = min_distance[N-1]
    print(max(-ans,0))
else:
    min_distance = Bellman_Ford2(1,N,M,line)
    ans = min_distance[N-1]
    if ans == -float("inf"):
        print(-1)
    else:
        print(max(-ans,0))

#print(min_distance)


Measured memory_bytes: 75496
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())

    alf = [chr(ord('a') + i) for i in range(26)]

    maxdigit = 1
    pre = 0

    while N - pre > 26 ** maxdigit:
        pre += 26 ** maxdigit
        maxdigit += 1


    # print(maxdigit,pre)

    N -= pre

    res = ''

    for d in range(1,maxdigit+1):
        for i in range(26):
            if N <= 26 ** (maxdigit - d) * (i + 1):
                res += alf[i]
                N -= 26 ** (maxdigit - d) * i
                break

    print(res)



main()


Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

int main(){
	ios::sync_with_stdio(0);
	long long n;
	cin >> n;
	long long ans = INF;
	for (long long i = 1; i * i <= n; ++i){
		if (n % i == 0){
			ans = min(ans, i - 1ll + n / i - 1ll);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), nc = scanner.nextInt();
			int[] s = new int[n], t = new int[n], c = new int[n];
			int maxT = IntStream.range(0, n).map(i -> {
				s[i] = scanner.nextInt();
				t[i] = scanner.nextInt();
				c[i] = scanner.nextInt() - 1;
				return t[i];
			}).max().getAsInt();
			int[][] channel = new int[nc][maxT * 2 + 2];
			IntStream.range(0, nc).forEach(i -> Arrays.fill(channel[i], 0));
			IntStream.range(0, n).forEach(i -> {
				Arrays.fill(channel[c[i]], s[i] * 2, t[i] * 2 + 1, 1);
			});
			System.out.println(IntStream.range(0, maxT * 2 + 2)
					.map(i -> IntStream.range(0, nc).map(j -> channel[j][i]).sum()).max().getAsInt());
		}
	}
}


Measured memory_bytes: 86992
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

using namespace std;

typedef long long li;
typedef unsigned long long lu;
const li infl = ~0LLU >> 2;

template <class T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <class T>
inline void Max(T &x, T y) {
  if (y > x) x = y;
}

/*

const int mod = 998244353;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

*/

// ----------------------------------------

int Solve(int k, int m) {
  int r = m % k;
  if (r == 0) {
    return m / k;
  }
  int d = m / k + 1;
  int rep = max(r / d, 1);
  m -= rep * d;
  return Solve(k, m);
}

int main(void) {
  int n;
  scanf("%d", &n);
  int xsum = 0;
  for (int i = 0; i < n; ++i) {
    int a, k;
    scanf("%d%d", &a, &k);
    xsum ^= Solve(k, a);
  }
  puts(xsum ? "Takahashi" : "Aoki");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vi a(n);
    multiset <ll> s;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        s.insert(x);
    }
    for(ll i=0;i<m;i++)
    {
        ll x=*s.rbegin();
        x/=2;
        auto ms=s.end();
        ms--;
        s.erase(ms);
        s.insert(x);
    }
    ll sum=0;
    for(ll i:s)
    {
        sum+=i;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 5760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author https://github.com/rishabhdeepsingh/competitive
 */

// Created by White Knife on 15/04/20.
// doot diddly donger cuckerino Hahahahahah

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC target("popcnt")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define sz(x)           int((x).size())
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << rang(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
template<typename T> int sgn(T val) { return (T(0) < val) - (val < T(0));}
template<typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T> T gcd(T x, T y) { return (y == T(0)) ? x : gcd(y, x % y); }
// @formatter:on


class BMixJuice {
public:

  void solveOne(istream& cin, ostream& cout) {
  
  }
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    for (auto& _a : a) cin >> _a;
    sort(all(a));
    ll ans = accumulate(a.begin(), a.begin() + k, 0);
    cout << ans << '\n';
  }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	BMixJuice solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 100005, M = 101;
int n, m;
ll dp[M][N];
const ll inf  = 1e18;
int W[M], P[M];

ll f(int i, int w){
	if(w < 0)return -inf;
	if(w == 0 || i == n)return 0;
	ll &ans = dp[i][w];
	if(ans != -1)return ans;
	ans = max(f(i+1, w), f(i+1, w-W[i])+P[i]);
	return ans;
}


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

  cin >> n >> m;

	forn(i, 0, n){
		cin >> W[i] >> P[i];
	}

	memset(dp, -1, sizeof dp);
	cout << f(0, m) << endl;


  


}





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

#define int long long

using namespace std;

 main () {
	int i, o, t, j, l, s, z;
	cin >> i >> o >> t >> j >> l >> s >> z;
	int kol = 0;
	int kol1 = 0;                        
	kol1 += i / 2 * 4;
	kol1 += j / 2 * 4;
	kol1 += l / 2 * 4;
	if (i >= 1 && l >= 1 && j >= 1) {
		kol = 6;
		i --, l --, j --;
	}
	kol += i / 2 * 4;
	kol += j / 2 * 4;
	kol += l / 2 * 4 ;
	cout << max (kol, kol1) / 2 + o;
	return 0;
}                                                        

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

using namespace std;

string reverse(const string& str){
  string ret;
  string::const_reverse_iterator it = str.rbegin();
  for(; it != str.rend(); it++) {
    ret.push_back(*it);
  }
  return ret;
}

void cut0(string& str){
  while(str[str.size() - 1] == '0' && str.size() > 1){
    str.erase(str.size() - 1);
  }
}

int main () {
  int n;
  string a, b, sum;
  
  cin >> n;
  while(n--) {
    bool overflow = false;

    cin >> a >> b;
    if (a.size () > 80 || b.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    a = reverse(a);
    b = reverse(b);
    a.resize(80, '0');
    b.resize(80, '0');
    sum.clear();
    sum.resize(80, '0');
    
    for(size_t i = 0; i < 80; i++) {
      sum[i] += a[i] - '0' + b[i] - '0';
      if(sum[i] > '9'){
        sum[i] -= 10;
        if(i < 79) {
          sum[i+1] = '1';
        }
        else {
          overflow = true;
          break;
        }
      }
    }
    if(overflow){
      cout << "overflow" << endl;
    }
    else {
      cut0(sum);
      cout << reverse(sum) << endl;
    }
  }
}

Measured memory_bytes: 1216
def comb(n,m)
  new_m = [m,n-m].min
  ret = 1
  for i in n-new_m+1..n
    ret *= i
  end
  for i in 1..new_m
    ret /= i
  end
  return ret
end

n = gets.to_i
mod = 10**9 + 7
a = n / 3
b = n % 3
ans = 0
for box in 1..a
  amari = n - 3 * box
  ans += comb(amari+box-1,amari)
  ans %= mod
end

puts ans

Measured memory_bytes: 14928
#include <stdio.h>
#include <algorithm>

using namespace std;

#define N 110000

typedef long long ll;

struct Node {
    int a, b;
    bool operator < (const Node &u) const {
        return a < u.a;
    }
};

Node a[N];

int main() {
    int n; ll k;
    while (scanf("%d%lld", &n, &k) != EOF) {
        for (int i = 0; i < n; ++i) scanf("%d%d", &a[i].a, &a[i].b);
        sort(a, a +n);
        ll sum = 0;
        for (int i = 0; i < n; ++i) {
            if (k <= sum + a[i].b) { printf("%d\n", a[i].a); break; }
            else sum += a[i].b;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  string str1;
  cin>>n;
  cin.ignore();
  for(int i=0;i<n;i++){
    getline(cin,str1);
    while(str1.find("Hoshino")!=string::npos){
      str1.replace(str1.find("Hoshino"),7,"Hoshina");
    }
    cout<<str1<<endl;
  }
  return 0;
}

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

int main(){
string s;
cin >> s;
bool ans = false;
for(int i{}; i<s.size(); i++){
	if(s[i]=='7'){
		ans = true;
		break;
	}
}

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




	return 0;
}


Measured memory_bytes: 3636
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class ANovember30 {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int a,b,c,d;cin >> a >> b >> c >> d;
        //cout << a << " " << c << endl;
        if(c == a + 1 and d == 1){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
};

int main() {
	ANovember30 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
N,Y = map(int,input().split())
def find(N,Y):
  for xi in range(N+1):
    for yi in range(N+1):
      zi = N - xi - yi
      s = xi*10000 + yi*5000 + zi*1000      
      if s == Y and (xi+yi+zi)<=N and zi>=0 :
        print("{} {} {}".format(xi,yi,zi))
        return
      if s > Y:
        break
  print("-1 -1 -1")
  
find(N,Y)

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

using namespace std;

int main() {
 long long c,x,ok=0;
 cin>>x;
 while(x>0){
     if(x%10==7) ok=1;
     x=x/10;
 }
 if(ok==0) cout<<"No";
 else      cout<<"Yes";
 return  0;
}

Measured memory_bytes: 3636
n = gets.chomp.to_i
a = []
b = []
worklist = []
nowtime = 0
n.times do |i|
  input = gets.chomp
  a[i],b[i] = input.split.collect{ |item| item.to_i}
  worklist[i] = [a[i],b[i]]
end

result = "Yes"
worklist.sort!{ |l,r| l[1] <=>r[1]}
worklist.each do |task|
  nowtime += task[0]
  if nowtime > task[1]
    result = "No"
  end
end

puts result

Measured memory_bytes: 22540
#include<stdio.h>
int main(){
  int H,W,i=0,j=0;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)break;
    for(i=0;i<H;i++){
      if(i%2==0){
	for(j=0;j<W;j++){
	  if(j%2==0){
	    printf("#");
	  }else{
	    printf(".");
	  }
	}
	   printf("\n");
      }else{
	for(j=0;j<W;j++){
	  if(j%2==0){
	    printf(".");
	  }else{
	    printf("#");
	  }
	}
	printf("\n");
      }
    } 
    printf("\n");
  }
  return 0;
}



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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
//int INF = 1e9;
const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template<class T> inline void chmax(T & a, T b) { if (a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if (a > b)  a = b; }

const int VMAX = 100100;
const int NMAX = 110;
int w[NMAX];
int v[NMAX];
int dp[NMAX][VMAX];

signed main() {
	ios::sync_with_stdio(false);
	int N, W;
	cin >> N >> W;
	rep(i, N) cin >> w[i] >> v[i];


	rep(i, NMAX) rep(j, VMAX) dp[i][j] = INF;
	dp[0][0] = 0;


	rep(i, N) {
		rep(j, VMAX) {
			if (j - v[i] >= 0)
				chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			chmin(dp[i + 1][j], dp[i][j]);
		}
	}


	int ans = 0;
	rep(i, VMAX) if (dp[N][i] <= W) ans = i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N,ans;
    vector<tuple<ll, ll, ll>> vc;
    vector<ll> A;
    vector<ll> B;
    cin >> N;
    int a,b;
    for(int i = 0;i < N;i++){
		cin >> a >> b;
	    vc.emplace_back( a + b, a, b );
    }
    
    sort( begin( vc ), end( vc ), greater<tuple<ll, ll, ll>>() );
    ans = 0;
    for(int i = 0;i < N;i++){
        if(i%2)
            ans -= get<2>( vc[ i ] );
        else
            ans += get<1>( vc[ i ] );
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
const double EPS=1e-9;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define t() ll t;cin>>t;while(t--) 

int main()
{ 
    fastio;
    ll i,n,j,k;
    cin>>n;
    vector<vector<ll>>a(n,vector<ll>(3));
    vector<vector<ll>>dp(n,vector<ll>(3,0));
    for(i=0;i<n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<n;i++)
    {
        for(j=0;j<3;j++)
            for(k=0;k<3;k++)
                if(j!=k)
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
    }
    ll ans=0;
    for(i=0;i<3;i++)
        ans=max(ans,dp[n-1][i]);
    cout<<ans;
    
       
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
long long powlr[35];
long long x[100004];
long dp[33][100004];
int main()
{
    powlr[0]=1;
    for(long i=1;i<=32;i++)powlr[i]=powlr[i-1]*2LL;
    long n;
    cin>>n;
    for(long i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    long l,q;
    cin>>l>>q;
    for(long j=1;j<n;j++)
    {
        long l1=j;long r=n;
        while(r-l1>1)
        {
            long mid=(l1+r)/2;
            if(x[mid]-x[j]<=l)l1=mid;
            else r=mid;
        }
        dp[0][j]=l1;
          if(x[n]-x[j]<=l){dp[0][j]=n;}
      //  cout<<j<<" ff "<<dp[0][j]<<" "<<x[j]<<endl;
    }
    dp[0][n]=n+1;
    long d=1;
    for(long i=2;i<=n;i=i*2LL)
    {
        for(long j=1;j<=n;j++)
        {
            if(dp[d-1][j]>n){dp[d][j]=n+1;continue;}
            dp[d][j]=dp[d-1][dp[d-1][j]];
        }
        d++;
    }
    d--;
    for(long i=1;i<=q;i++)
    {
        long a,b;
        cin>>a>>b;
        if(b<a){a=a+b;b=a-b;a=a-b;}
        long long int ans=0;
        for(long j=d;j>=0;j--)
        {
            long f=dp[j][a];
          //  cout<<f<<" "<<a<<" "<<b<<" "<<ans<<" "<<j<<endl;
            if(f<=b){a=f;ans+=powlr[j];}
        }
        if(a!=b)ans++;
        cout<<ans<<endl;

    }
}


Measured memory_bytes: 14848
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>

using namespace std;
typedef long long ll;


int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll x, k, d; cin >> x >> k >> d;
	if (x >= 0) {
		ll cnt = x / d;
		if (cnt >= k) {
			cout << x - (k * d);
		}
		else {
			k -= cnt;
			x = x - (cnt * d);
			if (k & (ll)1) {
				cout << abs(x - d) << '\n';
			}
			else {

				cout << x << '\n';
			}
		}
	}
	else {
		ll cnt = (-x) / d;
		if (cnt >= k) {
			cout << abs(x + (k * d));
		}
		else {
			k -= cnt;
			x += (cnt * d);
			if (k & (ll)1) {
				cout << abs(x + d) << '\n';
			}
			else {
				cout << abs(x) << '\n';
			}
		}

	}

}

Measured memory_bytes: 3156
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define Max 10010
using namespace std;

int unit[Max*2],n,m;

struct st{
    int from, to;
    double cost;
}edge[Max*Max];

pair<int, int> ch[Max*2];

void init(int n){
    for(int i = 0; i <= n; i++)
        unit[i] = i;
}

int cmp(st a, st b){
    return a.cost > b.cost;
}

int find(int k){
    if(unit[k] == k) return k;
    return unit[k] = find(unit[k]);
}

int isthesame(int a, int b){
    int x = find(a), y = find(b);
    if(x == y) return false;
    else
    {
        //cout<<x<<"  "<<y<<endl;
        unit[x] = y;
        return true;
    }
}

double kruskal(){
    sort(edge+1, edge + m + 1, cmp);
    init(n);
    double ans = 0;
    for(int i = 1; i <= m; i++)
    {
        if(isthesame(edge[i].from, edge[i].to))
        {
            ans += edge[i].cost;
        }
    }
    return ans;
}

int main()
{
    int a,b,x,y;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> a >> b;
        ch[i] = {a,b};
    }
    double allcost = 0;
    for(int i = 1; i <= m; i++)
    {
        cin >> x >> y;//genhao x-x1^2+y-y1^2
        double cost = sqrt((ch[x].first-ch[y].first)*(ch[x].first-ch[y].first)
                           +(ch[x].second-ch[y].second)*(ch[x].second-ch[y].second));
        allcost += cost;
        edge[i] = {x, y, cost};
       // cout << cost<<endl;
    }
    printf("%.3f\n", allcost - kruskal());
    return 0;
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define f first 
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX 1000005
#define pb push_back
int flag[1000006];
ll gcd(ll a, ll b)
{
  if(a == 0)
    return b;
  return gcd(b%a,a);
}

int main(){
  FIO;
  int n,m;
  cin >> n >> m;
  int l,r,re =INT_MAX,le = -1;
  for (int i = 0; i < m; ++i)
  {
    cin  >> l >> r;
    le = max(l,le);
    re = min(r,re);
  }
  if(re >= le)
    cout << re-le+1;
  else
    cout << "0";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 aa, bb, cc, x;
  cin >> aa >> bb >> cc >> x;
  i64 ans = 0;
  for (i64 a = aa; a >= 0; --a) {
    for (i64 b = bb; b >= 0; --b) {
      for (i64 c = cc; c >= 0; --c) {
        if (500 * a + 100 * b + 50 * c == x) ++ans;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

ll g1[305][305];
ll g2[305][305];

const ll INF = 1e18;

int main(void) {
  int n, m, l;
  scanf("%d%d%d", &n, &m, &l);
  REP(i, n) REP(j, n) {
    g1[i][j] = i == j ? 0 : INF;
  }
  REP(iEdge, m) {
    int a, b;
    ll c;
    scanf("%d%d%lld", &a, &b, &c);
    --a;
    --b;
    g1[a][b] = g1[b][a] = c;
  }
  REP(k, n) REP(i, n) REP(j, n) {
    g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]);
  }
  REP(i, n) REP(j, n) {
    if(i == j) {
      g2[i][j] = 0;
    } else if(g1[i][j] <= l) {
      g2[i][j] = 1;
    } else {
      g2[i][j] = INF;
    }
  }
  REP(k, n) REP(i, n) REP(j, n) {
    g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
  }
  
  int nQuery;
  scanf("%d", &nQuery);
  REP(iQuery, nQuery) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s;
    --t;
    printf("%lld\n", g2[s][t] >= INF ? -1 : g2[s][t]-1);
  }
  
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = max(0LL, b / c - (a - 1) / c);
    ll y = max(0LL, b / d - (a - 1) / d);
    ll t = lcm(c, d);
    ll z = max(0LL, b / t - (a - 1) / t);
    ll ans = b - a + 1 - x - y + z;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);

int main()
{
  // input_from_file;
  string s1,s2,s;cin>>s1>>s2;ll n=s1.size(),m=s2.size();
  vector<vector<ll>> dp(n+1,vector<ll> (m+1,0));
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s1[i-1]==s2[j-1])  dp[i][j]=dp[i-1][j-1]+1;
      else{
          dp[i][j]=dp[i-1][j]>dp[i][j-1] ? dp[i-1][j]:dp[i][j-1];
      }
    }
  }
  ll j=m,i=n;
  while(i>0 && j>0){
    if(s1[i-1]==s2[j-1])  {s.pb(s1[i-1]);i--;j--;}
    else{
      if(dp[i-1][j]==dp[i][j])  i--;
      else  j--;   
    }
    // cout<<"i="<<i<<" ,j="<<j<<endl;
  }
  reverse(s.begin(),s.end());
  cout<<s;
  return 0;
}

Measured memory_bytes: 70784