akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int r;
    cin >> r;
    cout << fixed << setprecision(10) << 2 * M_PI * r << endl;
}

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

typedef struct node{
  vector<node *> nexts;
} node;

int count(node *e, node *bef, int length){
  int sum = 1;
  if(length > 0){
    vector<node *>::iterator it;
    for(it = e->nexts.begin(); it != e->nexts.end(); ++it){
      if((*it) != bef){
        sum += count((*it), e, length-1);
      }
    }
  }
  return sum;
}

int main(int argc, char *argv[]){
  int N, K;
  cin >> N >> K;
  int A[N-1];
  int B[N-1];
  node* e = new node[N];
  int i;
  int a, b;
  for(i=0; i<N-1; ++i){
    cin >> a >> b;
    A[i] = a-1;
    B[i] = b-1;
    e[a-1].nexts.push_back(&e[b-1]);
    e[b-1].nexts.push_back(&e[a-1]);
  }
  int ans;
  if(K%2 == 0){
    int ma = 0;
    for(i=0; i<N; ++i){
      ma = max(ma, count(&e[i], NULL, K/2));
    }
    ans = N - ma;
  }else{
    int ma = 0;
    for(i=0; i<N-1; ++i){
      ma = max( ma, count(&e[A[i]], &e[B[i]], (K-1)/2) + count(&e[B[i]], &e[A[i]], (K-1)/2) );
    }
    ans = N - ma;
  }
  cout << ans << endl;
  delete[] e;
  return 0;
}

Measured memory_bytes: 384
/*author: hyperion_1724
  date: 
*/

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	ll A[N+1]={0};
	FORI(i,0,N)
	{
		READV(x);
		A[x]=i+1;
	}
	ll ans=0;
	FORI(i,0,N+1)
	{
		if (A[i]!=i)
		{
			ans++;
		}
	}
	if(ans==0 || ans==2)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<b ;i++)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lli long long
#define pb push_back

using namespace std;

int main()
{
    fast
    int n;
    cin>>n;
    lli arr[n];
    rep(i,0, n){
        cin>>arr[i];
    }
    sort(arr, arr+n);
    int count =0;
    for(int i=0 ; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(arr[i]!=arr[j] && arr[j]!= arr[k] &&arr[i]+arr[j]>arr[k]  )
                count++;
            }
        }
    }
    cout<<count;
    

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793


int main()
{
    double a, b, h, m;
    cin >> a;
    cin >> b;
    cin >> h;
    cin >> m;

    double th = (60.0 * h - 11.0 * m) / 2.0;
    //cout << th << endl;
    th = th * PI / 180.0;
    double ans = sqrt(a*a+b*b-2.0*a*b*cos(th));

    printf("%0.13f",ans);

    return 0;
}

Measured memory_bytes: 4228
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	int A[100100];
	ll B[100100];
	cin >> A[0];
	B[0] = 1;
	if (A[0] > 1) {
		printf("-1\n");
		return 0;
	}
	int OK = 1;
	int i = 1;
	for (; i <= N; i++) {
		cin >> A[i];
		B[i] = (B[i - 1] - A[i - 1]) * 2;
		if (B[i] < A[i]) OK = 0;
		if (B[i] > 2e8) {
			i++;
			break;
		}
	}

	if (!OK) {
		printf("-1\n");
		return 0;
	}

	for (; i <= N; i++) {
		cin >> A[i];
		B[i] = (B[i - 1] - A[i - 1]) * 2;
		if (B[i] > 1e13) {
			B[i] = 1e13;
			i++;
			break;
		}
	}
	for (; i <= N; i++) {
		cin >> A[i];
		B[i] = 1e13;
	}

	ll kotae = 0;
	ll kari = 0;
	for (int i = N; i >= 0; i--) {
		kari += A[i];
		kotae += min(kari, B[i]);
	}

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

	Would you please return 0;
}

Measured memory_bytes: 4840
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;
#define omajinai ios::sync_with_stdio(false);cin.tie(nullptr);

#pragma region typedef 
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
#pragma endregion

#pragma region define
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#pragma endregion

#pragma region const
const ld PI = 3.141592653589793;
const ll INF18 = 1e18;
#pragma endregion

#pragma region function
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

ll weight[110], value[110];
ll dp[110][100100];

int main(){
omajinai;
    int n; ll w; cin >> n >> w;
    rep(i, n) cin >> weight[i] >> value[i];

    rep(i, n)for(int sum_w = 0; sum_w <= w; sum_w++){
        if(sum_w - weight[i] >= 0)
            chmax(dp[i+1][sum_w],
                dp[i][sum_w - weight[i]] + value[i]);
    
        chmax(dp[i+1][sum_w], dp[i][sum_w]);
    }

    cout << dp[n][w] << endl;

return 0;
}

Measured memory_bytes: 81836
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
     
     
public class Main {
	static int W;
	static int H;
	static int N;
	static boolean[][] fld;
	static int[] vx = new int[] {0,1,0,-1};
	static int[] vy = new int[] {1,0,-1,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		String in = sc.next();
		for(int i = 0; i < n; i++) {
			if(in.charAt(i) == '*') {
				num[i] = -1;
			}
			else {
				num[i] = in.charAt(i) - '0';
			}
		}
		int m = sc.nextInt();
		int[] c = new int[m];
		for(int i = 0; i < m; i++) {
			c[i] = sc.nextInt();
		}
		long[][] dp = new long[n+1][10];
		dp[0][0] = 1;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 10; j++) {
				if(num[i] != -1) {
					int tmp = 0;
					if((n - i) % 2 == 0) {
						tmp = num[i]*2;
						if(tmp >= 10) {
							switch(tmp) {
								case 10: tmp = 1; break;
								case 11: tmp = 2; break;
								case 12: tmp = 3; break;
								case 13: tmp = 4; break;
								case 14: tmp = 5; break;
								case 15: tmp = 6; break;
								case 16: tmp = 7; break;
								case 17: tmp = 8; break;
								case 18: tmp = 9; break;
							}
						}
					}
					else {
						tmp = num[i];
					}
					tmp += j;
					tmp %= 10;
					dp[i+1][tmp] += dp[i][j];
				}
				else {
					for(int k = 0; k < m; k++) {
						int tmp = 0;
						if((n - i) % 2 == 0) {
							tmp = c[k]*2;
							if(tmp >= 10) {
								switch(tmp) {
								case 10: tmp = 1; break;
								case 11: tmp = 2; break;
								case 12: tmp = 3; break;
								case 13: tmp = 4; break;
								case 14: tmp = 5; break;
								case 15: tmp = 6; break;
								case 16: tmp = 7; break;
								case 17: tmp = 8; break;
								case 18: tmp = 9; break;
								}
							}
						}
						else {
							tmp = c[k];
						}
						tmp += j;
						tmp %= 10;
						dp[i+1][tmp] += dp[i][j];
					}
				}
			}
		}

		System.out.println(dp[n][0]);
		
	}
	static int dfs(int now, int[] num, int[] c) {
		if(now == num.length) {
			return check(num)?1:0;
		}
		if(num[now] != -1) return dfs(now+1,num,c);
		int ret = 0;
		for(int i = 0; i < c.length; i++) {
			num[now] = c[i];
			ret += dfs(now+1,num,c);
		}
		num[now] = -1;
		return ret;
	}
	static boolean check(int[] a) {
		int sum = 0;
		for(int i = a.length-1; i >= 0; i--) {
			if((a.length - i) % 2 == 0) {
				int tmp = a[i]*2;
				if(tmp >= 10) {
					switch(tmp) {
					case 10: tmp = 1; break;
					case 11: tmp = 2; break;
					case 12: tmp = 3; break;
					case 13: tmp = 4; break;
					case 14: tmp = 5; break;
					case 15: tmp = 6; break;
					case 16: tmp = 7; break;
					case 17: tmp = 8; break;
					case 18: tmp = 9; break;
					}
				}
				sum += tmp;
			}
			else {
				sum += a[i];
			}
		}
		return sum % 10 == 0;
	}
}

Measured memory_bytes: 39660
n,m,k=map(int,input().split())
ans=0
INF=10**9+7
if n<=m:
    M=-(m-1)*m*(2*m-1)//3+m*m*(m-1)
    Ms=m*m*(m-1)//2-(m-1)*m*(2*m-1)//6
    M=M%INF
    Ms=Ms%INF
    for i in range(1,n+1):
        for j in range(i,n+1):
            if i==j:
                ans=ans+Ms
            else:
                d=j-i
                ans=ans+d*m**2+M
            ans=ans%INF
else:
    (n,m)=(m,n)
    M=-(m-1)*m*(2*m-1)//3+m*m*(m-1)
    Ms=m*m*(m-1)//2-(m-1)*m*(2*m-1)//6
    M=M%INF
    Ms=Ms%INF
    for i in range(1,n+1):
        for j in range(i,n+1):
            if i==j:
                ans=ans+Ms
            else:
                d=j-i
                ans=ans+d*m**2+M
            ans=ans%INF
import math
ans=(math.factorial(n*m-2)//(math.factorial(n*m-k)*math.factorial(k-2)))*ans
ans=ans%INF
print(ans)


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

int main() {
  string N;
  cin >> N;
  if(N[0]==N[1]&&N[1]==N[2]){
  	cout << "Yes" << endl;
  }else if(N[1]==N[2]&&N[2]==N[3]){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n;

int main()
{
	int i, j, k, l;
	cin>>n;
	for(i=1;;i++)
	{
		if(i*(i+1)/2 < n) continue;
		int now=n;
		for(j=i;j>=1;j--)
		{
			if(now >= j)
			{
				now-=j;
				printf("%d\n", j);
			}
		}
		break;
	}
	return 0;
}
//*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
main(){
	int n;
	cin >> n;
	int p[n];
	int max=0;
	int total=0;
	for(int i=0;i<n;i++){
		cin >> p[i];
		total+=p[i];
		if(p[i]>max)
			max=p[i];
	}total-=max/2;
	cout << total <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;


int main() {
    string s; cin >> s;
    sort(s.begin(),s.end());
    string ans = "yes";
    for(int i = 0;i < s.length()-1;i++){
        if(s[i] == s[i+1]){
            ans = "no";
        }
    }
    cout << ans;
}




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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

vector<ll> C;
vector<vector<ll>> A;
int N,M; ll X; 
ll MAX = 1000000000000000000;
ll min_val = MAX;

void solve(string S){
  if(S.size() < N){
    solve(S+"0");
    solve(S+"1");
    return;
  } 

  ll cost = 0;
  vector<ll> a(M,0);
  for(int i = 0; i < N; i++){
    if(S[i] == '1'){
      cost += C[i];

      for(int j = 0; j < M; j++){
        a[j] += A[i][j];
      }
    }
  }

  for(int j = 0; j < M; j++){
    if(a[j] < X) return;
  }

  min_val = min(min_val, cost);

  return;

}

int main(){
  cout << setprecision(10);
  cin >> N >> M >> X;

  C.assign(N,0);
  A.assign(N, vector<ll>(M,0));

  for(int i = 0; i < N; i++){
    cin >> C[i];
    for(int j = 0; j < M; j++){
      cin >> A[i][j];
    }
  }

  solve("");
  cout << (min_val == MAX ? -1 : min_val) << endl;
}


Measured memory_bytes: 3616
X,Y=map(int,input().split())
ans=0
if X==1:
    if Y==1:
        ans+=400000
    ans+=300000
if X==2:
    ans+=200000
if X==3:
    ans+=100000
if Y==1:
    ans+=300000
if Y==2:
    ans+=200000
if Y==3:
    ans+=100000
print(ans)


Measured memory_bytes: 3060
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

a,b,c,d = inpl()
print(max(0,(min(b,d)-max(a,c))))

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer city=Integer.valueOf(sc.nextLine().split(" ")[0]);
		int[] road=new int[city];

		while (sc.hasNextLine()) {
			Integer[] roadInfo=Arrays.asList(sc.nextLine().split(" "))
					.stream()
					.map(Integer::valueOf)
					.toArray(Integer[]::new);
			road[roadInfo[0]-1]++;
			road[roadInfo[1]-1]++;
		}
		for(Integer i:road) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 30932
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    bool flag = false;

    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            flag = true;
            break;
        }
    }

    if (flag)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;
    
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dx2[] = { -1 , -1 , -1, 0 , 0 , 1 , 1 , 1};
int dy2[] = { -1 , 0 , 1 , -1, 1 , -1, 0, 1};

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int n, k; cin >> n >> k;
	vi a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vi dp(n, inf);
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);
	for (int i = 2; i < n; i++)
	{
		for (int j = 1; j <= k; j++)

			if (i - j >= 0)
				dp[i] =  min(dp[i], abs(a[i] - a[i - j]) + dp[i - j]);

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

Measured memory_bytes: 4780
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a,b,d,r;
    double f;
    cin>>a>>b;
    r=a%b;
    d=a/b;
    f=(double)a/(double)b;
  printf("%d %d %.5f",d,r,f);
    return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(true){
    int w;
    cin>>w; if(w==-1) break;
    if(w<=10) cout<<4280-1150<<"\n";
    w-=10;
    if(w<=10 && w>0) cout<<4280-(1150+w*125)<<"\n";
    w-=10;
    if(w<=10 && w>0) cout<<4280-(1150+10*125+w*140)<<"\n";
    w-=10;
    if(w>0) cout<<4280-(1150+10*125+10*140+w*160)<<"\n";
  }
      
    

  return 0;
}



Measured memory_bytes: 3052
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
a = {"r":p, "s":r, "p":s}
b = [1]*n
score = 0
for i in range(n):
  if i>k-1 and t[i]==t[i-k]:
    b[i] = 1-b[i-k]
  score += a[t[i]] if b[i]==1 else 0
print(score)

Measured memory_bytes: 40688
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define N (1<<18)
class SegmentTree{
	public:
	vector<int> dat[2*N];
	void push(int i,int x){
		i+=N;
		while(i>0){
			dat[i].push_back(x);
			i/=2;
		}
	}
	void init(){
		rep(i,2*N)sort(all(dat[i]));
	}
	int cnt(int k,int x){
		return dat[k].size()-(lower_bound(all(dat[k]),x)-dat[k].begin());
	}
	int query(int l,int r,int x){//[l,r]
		l+=N,r+=N+1;
		int ans=0;
		for(;l<r;l>>=1,r>>=1){
			if(l&1)ans+=cnt(l,x),l++;
			if(r&1)r--,ans+=cnt(r,x);
		}
		return ans;
	}
};
SegmentTree seg[26];
int n;
string s[N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>s[i];
		reverse(all(s[i]));
	}
	sort(s,s+n);
	int cha[26];
	rep(i,26)cha[i]=0;
	rep(i,n){
		bool vis[26];
		rep(j,26)vis[j]=0;
		for(int j=s[i].size()-1;j>=0;j--){
			if(vis[s[i][j]-'a'])continue;
			vis[s[i][j]-'a']=1;
			seg[s[i][j]-'a'].push(i,j);
		}
		rep(j,26)cha[j]+=vis[j];
	}
	rep(i,26)seg[i].init();
	ll ans=0;
	rep(i,n){
		if(s[i].size()==1){
			ans+=cha[s[i][0]-'a']-1;
			continue;
		}
		string t=s[i];
		t.pop_back();
		ll l,r,mid;
		l=-1,r=n;
		while(l<r-1){
			mid=(l+r)>>1;
			if(t<=s[mid])r=mid;
			else l=mid;
		}
		ll L=r;
		t.push_back('z'+1);
		l=-1,r=n;
		while(l<r-1){
			mid=(l+r)>>1;
			if(s[mid]<t)l=mid;
			else r=mid;
		}
		ll R=l;
		t.back()=s[i].back();
		ans+=seg[t.back()-'a'].query(L,R,t.size()-1)-1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 478012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<20;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<pair<double,double>> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i].first>>S[i].second;
    }
    
    if(N%2){
        cout<<"NA"<<endl;
    }else{
        double x=(S[0].first+S[N/2].first)/2.0,y=(S[0].second+S[N/2].second)/2.0;
        
        for(int i=1;i<N/2;i++){
            double xx=(S[i].first+S[i+N/2].first)/2.0,yy=(S[i].second+S[i+N/2].second)/2.0;
            
            if(x!=xx||y!=yy){
                cout<<"NA"<<endl;
                return 0;
            }
        }
        cout<<setprecision(25)<<x<<" "<<y<<endl;
    }
}





Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する
int a[27], b[27];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if (a == b && b == c && c == a)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
h1, m1, h2, m2, k = map(int,input().split())

if m1 > m2:
    m2 += 60
    h2 -=1
    ans_m = m2 - m1
else:
    ans_m = m2 - m1

ans_h = h2 - h1
ans = 60 * ans_h + ans_m

print(ans-k)

Measured memory_bytes: 9176
x = int(input())
if x>=400 and x<=599:
    print(8)
elif x>=600 and x<=799:
    print(7)
elif x>=800 and x<=999:
    print(6)
elif x>=1000 and x<=1199:
    print(5)
elif x>=1200 and x<=1399:
    print(4)
elif x>=1400 and x<=1599:
    print(3)
elif x>=1600 and x<=1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 61952
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N >> M;
  A.resize(N);
  rep(i, 0, N - 1) { cin >> A[i]; };
}
void solve() {
  sort(A.rbegin(), A.rend());
  priority_queue<int> q;
  for (auto x : A) {
    q.push(x);
  }

  while (M) {
    int k = q.top();
    q.pop();
    k >>= 1;
    --M;
    q.push(k);
  }
  int ans = 0;
  while (q.size()) {
    ans += q.top();
    q.pop();
  };
  cout << ans << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 2168
class BellmanFord:#Union-Find
    def __init__(self, n, init_val = float('inf')):
        self.d = [init_val] * n #根にサイズを負の値で格納する。
        self.init_val = init_val

    def shortest_path(self, s, edges):
        self.d[s] = 0
        for _ in range(n):
            updated = False
            for a, b, w in edges:
                if self.d[a] != self.init_val and self.d[b] > self.d[a] + w:
                    self.d[b] = self.d[a] + w
                    updated = True
            if not updated:
                break
        if updated: #閉路の存在
            for a, b, w in edges:
                if self.d[a] != self.init_val and self.d[b] > self.d[a] + w:
                    self.d[b] = -float('inf')
    
    def get_path_length(self, i):
        return self.d[i]

n, m = map(int, input().split())

edges = []
for i in range(m):
    a, b, w = map(int, input().split())
    edges.append((a-1, b-1, -w))

bf = BellmanFord(n)
bf.shortest_path(0, edges)
ans = bf.get_path_length(n-1)
print(-ans if ans != -float('inf') else 'inf')

Measured memory_bytes: 74752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String t= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		//int k = sc.nextInt();
		//String s=sc.next();
		long count=0,flag=0;
		long count1=0,count2=0;
		int count3=0;
		int[] array = new int[100];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=1;i<=9;i++) {
			for(int j=1;j<=9;j++) {
				array[count3]=i*j;
				count3++;
			}
		}
		for(int i=0;i<100;i++) {
			if(array[i]==m) {
				count=1;
				break;
			}
			//System.out.println(array[i]);
		}

		if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}

		//System.out.println(buff);
	}
}




Measured memory_bytes: 21844
//https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_f

#include<bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;

int po(int n, int k){
    int ans = 1;
    while (k){
        if (k&1) ans = 1LL * ans * n % mod;
        n = 1LL * n * n % mod;
        k >>= 1;
    }
    return ans;
}

int h, w, t, ans;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> h >> w >> t;
    int gcd1 = __gcd(h, t), gcd2 = __gcd(w, t);
    h /= gcd1; w /= gcd2;
    ans = po(2, h) + po(2, w) - 1; if (ans >= mod) ans -= mod;
    ans += po(2, __gcd(h, w)) - 2; if (ans >= mod) ans -= mod; if (ans < 0) ans += mod;
    cout << po(po(ans, gcd1), gcd2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
using namespace std;
typedef long long ll;

ll a,b,c,d;

ll f(ll x){

    ll res= x;
    res -= x/c;
    res -= x/d;
    res += x/(c/__gcd(c,d)*d);
    return res;
}

int main(){
    cin>>a>>b>>c>>d;

    ll ans = f(b) - f(a-1);
    cout<<ans;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))
const ll     MAx   =  1000000000000000000;
int main()
{
    ll n,i,j,k,l=1ll,m;

    cin >> n;

    ll  ar[n+10];

    for(i=0; i<n; i++)
    {
        cin >> ar[i];
    }

    sort(ar,ar+n);

    for(i=0; i<n; i++)
    {
        if(ar[i] == 0)
        {
            l = 0;
            break;
        }
        ll fuk = MAx/l;

        if(ar[i]>fuk)return cout << -1<< endl,0;
      //  if((l*ar[i]) > MAx)return cout << -1<< endl,0;
        l = l*ar[i];
    }

    cout << l << endl;
}


Measured memory_bytes: 4344
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string S;
    cin >> n >> S;
    int c = 0;
    int d = 0;
    for(int i=0;i<S.size();i++){if(S[i]=='(')c++;else c--;d=min(d,c);}
	for(int i=0;i<-d;i++)cout<<"(";cout<<S;for(int i=0;i<c-d;i++)cout<<")";


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef long long ll;

int main(void){
  ll N;
  ll A[100001];
  ll i;
  ll S=0,Nsum,subsum=0,k,tmp;
  scanf("%lld",&N);
  for(i=0;i<N;i++){
    scanf("%lld",&A[i]);
    S+=(ll)A[i];
  }
  Nsum=(ll)N*(ll)(N+1)/2;
  if(S%Nsum){
    puts("NO");
    return 0;
  }
  k=S/Nsum;
  for(i=0;i<N;i++){
    tmp=A[i%N]+k-A[(i+1)%N];
    if(tmp%N || tmp<0){
      puts("NO");
      return 0;
    }
    subsum+=(ll)tmp/N;
  }
  puts(subsum==k?"YES":"NO");
  return 0;
}


Measured memory_bytes: 1024
V = int(input())
A = [list(map(int, input().split())) for _ in range(V)]

ret = 0
for i in range(V):
    for j in range(i+1, V):
        f = True
        for k in range(V):
            if i == k or j == k:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            elif A[i][j] == A[i][k] + A[k][j]:
                f = False
        if f:
            ret += A[i][j]

print(ret)


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


int main(){
  int N,ch;
  cin>>N;
  string st;
  cin>>st;
  for(int i=0;i<st.size();i++){
	  if(int(st.at(i)+N)>90)  cout<<char(st.at(i)+N-26);
	  else cout<<char(st.at(i)+N);
  }
  cout<<endl;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    string s; cin >> s;
    int N; N = s.size();
    int K; cin >> K;
    vector<int> d(N);
    rep(i, N) {
        d[i] = 26 - (s[i] - 'a');
    }
    string ns = "";
    rep(i, N) {
        if (d[i] != 26 && d[i] <= K) {
            ns += 'a';
            K -= d[i];
        } else {
            ns += s[i];
        }
    }
    ns[N-1] = ns[N-1] + (K % 26);
    cout << ns << endl;
    return 0;
}

Measured memory_bytes: 1104
/* Murad Eynizade */

#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define SIZE 300001
#define INF INT_MAX
#define F first
#define S second
#define in(a) scanf("%d",&a);
#define outn(a) printf("%d\n",&a);
#define outs(a) printf("%d ",&a);


using namespace std;

string a , b;

int lena , lenb , lcs[3001][3001];

int main()
{
    FAST_READ;
    cin>>a>>b;
    lena = a.length();
    lenb = b.length();
    for (int i = 1;i<=lena;i++) {
        for (int j = 1;j <= lenb;j++) {
            if (a[i - 1] == b[j - 1])lcs[i][j] = lcs[i - 1][j - 1] + 1;
            else lcs[i][j] = max(lcs[i - 1][j] , lcs[i][j - 1]);
        }
    }
    int i = lena , j = lenb , ans = lcs[lena][lenb];
    string res = "";
    while (i > 0 && j > 0) {
        if (a[i - 1] == b[j - 1]) {
            res += a[i - 1];
            i--;
            j--;
            ans--;
        }
        else if (lcs[i - 1][j] > lcs[i][j - 1]) i--;
        else j--;
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 35456
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = -10**9
v = [0] * 10

def culc():
    global ans
    score = 0
    if any(v) == False:
        return
    for i in range(N):
        index = 0
        for j in range(10):
            index += F[i][j] * v[j]
        score += P[i][index]
    ans = max(ans, score)
    return

def dfs(pos):
    if pos == 10:
        culc()
        return

    v[pos] = 0
    dfs(pos+1)
    v[pos] = 1
    dfs(pos+1)

    return

dfs(0)

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    string s, t;
    cin >> s >> t;

    int idx = -1;
    for (int i = 0; i + t.size() <= s.size(); ++i)
    {
        if ([&](){bool ret = true;
            rep (j, t.size())
            {
                if (s[i + j] != t[j] && s[i + j] != '?') ret = false;
            }
            return ret;
        }())
        {
            idx = i;
        }
    }

    if (idx == -1)
    {
        cout << "UNRESTORABLE\n";
        return 0;
    }

    rep (i, s.size())
    {
        if (idx <= i && i < idx + t.size()) s[i] = t[i - idx];
        else if (s[i] == '?') s[i] = 'a';
    }

    cout << s << "\n";
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


int main(){
	int n,a[2*M],b[2*M];
	int y[2*M]={},l[2*M]={},r[2*M]={};
	cin>>n;
	rep(i,0,n){
		cin>>a[i]>>b[i];
		l[a[i]]++,r[b[i]]++;
		y[a[i]]++,y[b[i]]--;
	}
	rep(i,1,2*M){
		l[i]+=l[i-1];
		r[i]+=r[i-1];
	}
	int ansx=0,ansy=0;
	rep(i,0,n){
		ansx=max(ansx,l[b[i]-1]-r[a[i]]);
	}
	int sumy=0;
	rep(i,1,2*M){
		sumy+=y[i];
		ansy=max(ansy,sumy);
	}
	cout<<ansx<<" "<<ansy<<endl;
	return 0;
}


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

using namespace std;
const int N=234567;
int a[N],dp[N],ans,n;

int main()
{
    cin >> n;
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    for (int i=1;i<=n;i++) dp[a[i]]=dp[a[i]-1]+1,ans=max(ans,dp[a[i]]);
    cout << n-ans << endl;
}


Measured memory_bytes: 1792
a=[]
for i in range(5):
  a.append(int(input()))
a.sort(key=lambda x:(x-1)%10)
b=0
for i in range(5):
  if i==0:
    b+=a[i]
  else:
    c=(a[i]-1)//10+1
    b+=c*10
print(b)

Measured memory_bytes: 2940
S=input()
flag_count=len(S)
Counter=0
for i in range(len(S)):
    for j in range(len(S)):
        if S[i]==S[j]:
            Counter+=1
    if Counter==2:
        flag_count=flag_count-1
    Counter=0
if flag_count == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

#define N 2005
struct Edge {
    ll from,to,cost;
};
vector<Edge>graph;
ll INF = (ll)1E18;
ll dist[N]; // 最短距離
// 戻り値がtrueなら負の閉路を含む
set<int> bellman_ford(ll n, ll s) { // nは頂点数、sは開始頂点
    set<int>v;
    rep(i,0,n-1)dist[i]=-INF;
    dist[s] = 0; // 開始点の距離は0
    for (ll i = 0; i < n; i++) {
        for(auto x:graph){
            ll from=x.from,to=x.to,cost=x.cost;
            if (dist[from] != -INF && dist[to] < dist[from] + cost) {
                dist[to] = dist[from] + cost;
                if (i == n-1 ){
                    v.insert(to);
                }; // n回目にも更新があるなら正の閉路が存在
            }
            
        }
    }
    return v;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<int>ed[n];
    vector<int>rev[n];
    for (ll i = 0; i < m; i++) {
        ll from, to, cost;
        cin >> from >> to >> cost;from--;to--;
        Edge e;e.from=from;e.to=to;e.cost=cost;
        ed[from].pb(to);
        rev[to].pb(from);
        graph.pb(e);
    }
    set<int>v=bellman_ford(n,0);
    if(v.size()>=1){//負の閉路があってもそこを通れるとは限れない
        bool used[n][2];memset(used,false,sizeof(used));
        used[0][0]=true;
        queue<int>q;q.push(0);
        while(!q.empty()){
            int t=q.front();q.pop();
            for(auto x:ed[t]){
                if(!used[x][0]){
                    q.push(x);used[x][0]=true;
                }
            }
        }
        q.push(n-1);
        used[n-1][1]=true;
        while(!q.empty()){
            int t=q.front();q.pop();
            for(auto x:rev[t]){
                if(!used[x][1]){
                    q.push(x);used[x][1]=true;
                }
            }
        }
        
        set<int>u;
        rep(i,0,n-1)if(used[i][0]&&used[i][1])u.insert(i);
        ll a=v.size(),b=u.size();
        for(auto x:u)v.insert(x);
        ll c=v.size();
        //cout<<a<<" "<<b<<" "<<c<<endl;
        if(a+b!=c)cout<<"inf"<<endl;
        else cout<<dist[n-1]<<endl;
        return 0;
    }
    cout<<dist[n-1]<<endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int maxi=0,N,h;
bool flag = true;

int main(){
    cin>>N;
    rep(i,N){
        cin>>h;
        if(maxi-h>=2)flag=false;
        maxi=max(maxi,h);
    }
    if(flag)out("Yes");
    else out("No");
    
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
int *p,a,x,y,i=0,k=0;
scanf("%d",&a);
p=malloc(sizeof(int)*(a+1));
while(scanf("%d",&x)==1){
    if(x==0){
        scanf("%d",&y);
        *(p+i)=y;
        i++;
    }
    if(x==1){
       scanf("%d",&y);
       printf("%d\n",*(p+y));
    }
    if(x==2){
        *(p+i-1)=0;
        i-=1;
    }
     if(k==a-1) break;
    k++;
}
free(p);
    return 0;
}


Measured memory_bytes: 2276
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double n = scanner.nextInt();
        double k = scanner.nextInt();
        double p = 0;

        for(int start = 1 ; start <= n ; start++){
            int count;
            int point = start;

            for(count = 0; point < k ; count++){
                point *= 2;
            }
            p += (1 / n) * (Math.pow(2 , -1 * count));
        }

        System.out.println(p);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define LL long long
#define N 500011
LL n,m,fac[N],inv[N],ans;
LL q_pow(LL a,LL b){
	LL res=1;
	while(b){
		if(b&1ll) res=res*a%MOD;
		b>>=1ll;
		a=a*a%MOD;
	}
	return res;
}
LL C(LL x,LL y){
	if(x<y) return 0;
	if(!y) return 1;
	return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
int main(){
	scanf("%lld%lld",&n,&m);
	inv[0]=fac[0]=inv[1]=fac[1]=1;
	for(int i=1;i<=500000;i++) fac[i]=fac[i-1]*i%MOD;
	inv[500000]=q_pow(fac[500000],MOD-2);
	for(int i=499999;i>=2;i--) inv[i]=inv[i+1]*(i+1)%MOD;
	int typ=1;
	int nn=min(n,m);
	for(int i=0;i<=nn;i++){
		ans=(ans+typ*C(n,i)*C(m,i)%MOD*q_pow(m+1,n-i)%MOD*q_pow(n+1,m-i)%MOD*fac[i]%MOD)%MOD;
		if(ans<0) ans+=MOD;
		typ=typ*-1;
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
using namespace std;

int main() {
  int a, b, c, d, ans = 0;
  cin >> a >> b >> c >> d;
  ans = max(a * b, c * d);
  cout << ans << endl;
  getchar();
}

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  int ans = 0;
  for(int i = 0;i<n;++i){
    cin >> a[i];
    for(int j = 0;j<31;++j){
      if (a[i] & (1<<j)){
        ans += j;
        break;
      }
    }
  }
  
  cout << ans <<endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
  int a[5];
  int i,t,state=0;

  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }
  while(1){
    state=0;
    for(i=0;i<4;i++){
      if(a[i]<a[i+1]){
	state=1;
	t=a[i];
	a[i]=a[i+1];
	a[i+1]=t;
      }
    }
    if(state==0)  break;
  }
  for(i=0;i<4;i++){
    printf("%d ",a[i]);
  }
  printf("%d",a[4]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  string sd,t;cin >> sd >> t;
  int id=0;
  bool storable =false;
  for(int i=0;i<sd.size()-t.size()+1;++i){
    bool t_storable =true;
    for (int j=0;j<t.size();++j){
      string tt = t.substr(j,1);
      string tsd = sd.substr(i+j,1);
      if(tsd != "?" && tsd != tt) t_storable =false;
      //cout << tsd << " " << tt << " " << t_storable << endl;
    }
    if(t_storable) {
      storable = true;
      id = i;
    }
  }
  if(storable){
    string s;
    for(int i=0;i<sd.size();++i){
      if(i>=id && i<id+t.size()){
        string tt = t.substr(i-id,1);
        s+=tt;
      } else {
        string tsd = sd.substr(i,1);
        if (tsd == "?") {
          s+= "a";
        } else {
          s+= tsd;
        }
      }
    }
    cout << s << endl;
  } else {
    std::cout << "UNRESTORABLE" << '\n';
  }
  return 0;
}


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

int main(){
  long long int n,i,kari;
  cin>>n;
  if(n==2){
    cout<<1;
    return 0;
  }
  set<long long int>st{};
  st.insert(n-1);
  for(i=2;i<=sqrt(n-1);i++){
    if((n-1)%i==0){
      st.insert(i);
      st.insert(n/i);
    }
  }
  st.insert(n);
  for(i=2;i<=sqrt(n);i++){
    if(n%i==0){
      kari=n/i;
      for(;;){
        if(kari%i==0){
          kari=kari/i;
        }else{
          if(kari%i==1){
            st.insert(i);
          }
          break;
        }
      }
    }
  }
  cout<<st.size();
}  

Measured memory_bytes: 256
h,w,K = map(int,input().split())
a = [input() for i in range(h)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        black = 0
        for k in range(h):
            for l in range(w):
                
                if (i>>k)&1 == 0 and (j>>l)&1 == 0 and a[k][l]=='#':
                    black += 1
                    
        if black == K:
            ans += 1
print(ans)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    int64_t tmp = 0, acc = 0;
    map<int64_t, int64_t> m;
    m[0] = 1;
    for(int i = 0; i < N; i++) {
        cin >> tmp;
        acc += tmp;
        if(m.count(acc) == 0) {
            m[acc] = 1;
        } else {
            m[acc] += 1;
        }
    }
    int64_t ans = 0;
    for(auto it = m.begin(); it != m.end(); it++) {
        tmp = it->second;
        ans += (tmp * (tmp - 1) ) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, a[114514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	if (n % 2) {
		if (a[0])cout << 0 << endl;
		else {
			for (int i = 1; i < n; i += 2) {
				if (a[i] != a[i + 1] || a[i] == a[i + 2]) {
					cout << 0 << endl; return 0;
				}
			}
		}
	}
	else {
		for (int i = 0; i < n; i += 2) {
			if (a[i] != a[i + 1] || a[i] == a[i + 2]) {
				cout << 0 << endl; return 0;
			}
		}
	}
	int ans = 1;
	rep(i, n / 2) {
		ans *= 2; ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024