akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define M (1000000007LL)

/***************************************
    繰り返し二乗法
    (a**n%m)
***************************************/
long powm( long a, long n, long m )
{
    long long ret = 1;
    for( ; n>0; n>>=1, a=(long long)a*a%m ) {
        if( n % 2 == 1 ) {
            ret = ret * a % m;
        }
    }

    return( ret );
}

/***************************************
    aからbまでの掛け算を計算
    ((a(a+1)(a+2)…(b))%m)
***************************************/
long multiplem( long a, long b, long m )
{
    int i;
    long long ret = 1;

    if( a > b ) {
        i = a;
        a = b;
        b = i;
    }

    for( i=a; i<=b; i++ ) {
        ret = (ret * i) %m;
    }

    return( ret );
}

/***************************************
    組み合わせ計算(nCa%m)
***************************************/
long combinationm( long n, long a, long m )
{
    int i;
    long long ret;

    if( n-a < a ) a = n-a;

    if( a == 0 ) return( 1 );

    // 分母を計算
    ret = multiplem( n, n-a+1, m );

    // 1/(a!)を計算して嬰かける
    for( i=1; i<=a; i++ ) {
        ret = (ret * powm( i, m-2, m ) ) % m;
    }

    return( ret );
}

/***************************************
    main
***************************************/
int main( int argc, char *argv[] )
{
    int n, a, b;
    long long ret;

    if( scanf( "%d%d%d", &n, &a, &b ) != 3 ) {
        puts( "Input error." );
        exit( 0 );
    }

    ret = powm( 2, n, M ) - 1;
    ret -= combinationm( n, a, M );
    ret -= combinationm( n, b, M );

    while( ret < 0 ) ret+= M;

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


Measured memory_bytes: 128
import java.util.*;
import java.util.regex.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 入力
        int n = sc.nextInt();
        int dt, dx, dy, dif;
        // 初期値
        boolean can = true;
        int t = 0;
        int x = 0;
        int y = 0;

        for (int i = 0; i < n; i++) {
            // 入力値
            dt = sc.nextInt();
            dx = sc.nextInt();
            dy = sc.nextInt();
            dif = Math.abs(dx - x) + Math.abs(dy - y) - dt + t;
            if (dif > 0 || (dif % 2 != 0)) {
                can = false;
            }
            t = dt;
            x = dx;
            y = dy;
        }

        // 出力
        if (can) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 87336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_168_Therefore
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            var pon = new List<long>();
            pon.Add(0);
            pon.Add(1);
            pon.Add(6);
            pon.Add(8);
            long answer = n % 10;         

            if (answer == 3)
            {
                string result = "bon";
                Console.WriteLine(result);
            }
            else if(pon.Contains(answer))
            {
                string result = "pon";
                Console.WriteLine(result);
            }
            else
            {
                string result = "hon";
                Console.WriteLine(result);
            }

            Console.Out.Flush();
        }
    }
}


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

using namespace std;

int main(){

  string N;
  int a=0,b=0,t;

  while(cin>>N){

    if(N=="#"){
      break;
    }


  for(int i=0;i<N.size();i++){


      if(N[i]=='q'||N[i]=='w'||N[i]=='e'||N[i]=='r'||N[i]=='t'||N[i]=='a'||N[i]=='s'||N[i]=='d'||N[i]=='f'||N[i]=='g'||N[i]=='z'||N[i]=='x'||N[i]=='c'||N[i]=='v'||N[i]=='b'){
      if(N[i+1]=='y'||N[i+1]=='u'||N[i+1]=='i'||N[i+1]=='o'||N[i+1]=='p'||N[i+1]=='h'||N[i+1]=='j'||N[i+1]=='k'||N[i+1]=='l'||N[i+1]=='n'||N[i+1]=='m'){
      b=b+1;
    }
    }else if(N[i]=='y'||N[i]=='u'||N[i]=='i'||N[i]=='o'||N[i]=='p'||N[i]=='h'||N[i]=='j'||N[i]=='k'||N[i]=='l'||N[i]=='n'||N[i]=='m'){
     if(N[i+1]=='q'||N[i+1]=='w'||N[i+1]=='e'||N[i+1]=='r'||N[i+1]=='t'||N[i+1]=='a'||N[i+1]=='s'||N[i+1]=='d'||N[i+1]=='f'||N[i+1]=='g'||N[i+1]=='z'||N[i+1]=='x'||N[i+1]=='c'||N[i+1]=='v'||N[i+1]=='b'){
       b=b+1;
    }
    }
  }
  cout<<b<<endl;

  b=0;

  }

  return 0;
}

Measured memory_bytes: 3184
N = int(input())
C=[]
S=[]
F=[]
for i in range(N-1):
  a,b,c = map(int,input().split())
  C.append(a)
  S.append(b)
  F.append(c)
for i in range(N-1):
  T = 0
  for j in range(i,N-1):
    if T < S[j]:
      T = S[j]
    elif T%F[j]==0:
      T = T
    else:
      T = T+F[j] - T%F[j]
    T = T + C[j]
  print(T)
print(0)


Measured memory_bytes: 43756
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<cstring>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define FOREACH(t,p,tit) for(t::iterator tit=p.begin();tit!=p.end();++tit)
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef set<int> pp;
string ss;

pp solve(int f,int l)
{

	pp ans;
	//ans.clear();
	bool ope=false;
/*	for(int i=f;i<l;i++)
	{
		if(
				ss[i]=='+'||
				ss[i]=='-'||
				ss[i]=='*'||
				ss[i]=='/')ope = true;
	}*/

	//int ofs = 0;
	int bo =0;
	for(int i=f;i<l;i++)
	{
	
		if(ss[i]=='(') bo++;
		if(ss[i]==')') bo--;

		if((ss[i]=='+'||ss[i]=='-'||ss[i]=='*'||ss[i]=='/')&&(bo==0))
		{
			ope = true;
		
			pp ansl = solve(f,i-1);
			pp ansr = solve(i+1,l);
			FOREACH(pp,ansl,iit)FOREACH(pp,ansr,jit)
			{
				if(ss[i]=='+') ans.insert((*iit)+(*jit));
				if(ss[i]=='-') ans.insert((*iit)-(*jit));
				if(ss[i]=='*') ans.insert((*iit)*(*jit));
				if(ss[i]=='/')if((*jit)!=0)	ans.insert((*iit)/(*jit));
			}
		}
	}
	if(!ope)
	{
		if(ss[f]=='('&& ss[l]==')'  ){return solve(f+1,l-1);}


		string s = ss.substr(f,(l-f+1));
		//cout << s << endl;
		int t = atoi(s.c_str() );
		ans.insert(t);
		//foreach(pp,ans)cout << *it << endl;
		//cout << atoi( (ss.substr(f,l+1)).c_str()) << endl ;
		//cout <<ss.substr(f,(l-f+1))<<endl;
		return ans;

	}
	return ans;
}

int main()
{
	while(cin >> ss &&(ss!="#"))
	{
		pp anss = solve(0,ss.size()-1);
		//foreach(pp,anss)cout << *it << endl;
		cout << anss.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 964
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let mut h: i64 = read();
    let mut count = 0_u32;

    // 2で割っていく
    loop {
        if h == 1 { break; }

        h /= 2;
        count += 1;
    }

    let mut attacks: u64 = 0;
    for i in 0..(count + 1) as usize {
        attacks += 2_u64.pow(i as u32);
    }
    println!("{}", attacks);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const long long INF = 1LL << 60;

int main() {
  int H, W; cin>>H>>W;
  vector<vector<int>> G(H, vector<int>(W));
  vector<int> tate(H);
  vector<int> yoko(W);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char C; cin>>C;
      if(C=='.') G[i][j]=0;
      if(C=='#'){
        G[i][j]=1;
        tate[i]=1;
        yoko[j]=1;
      } //#
    } //j
  } //i
  int K=0;
  for(int j=W-1; j>=0; j--){
    if(yoko[j]==1){
      K=j; //右端
      break;
  }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(tate[i]==1 && yoko[j]==1){
        if(G[i][j]==0) cout<<".";
        if(G[i][j]==1) cout<<"#";
        if(j==K) cout<<endl;
        }
    } //j
  } //i
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i, j, k, x[10], tmp;

	for(i = 0; i < 10; i++) scanf("%d", &x[i]);

	for(i = 0; i < 10; i++){
		for(j = 9; j > i; j--){
			if(x[j - 1] < x[j]){
				tmp = x[j];
				x[j] = x[j - 1];
				x[j - 1] = tmp;
			}
		}
	}

	k = 0;

	/*for(i = 1; i <= 10; i++){
		if(k >= 2){
			break;
		}else if(x[i] != x[i - 1]){
			printf("%d\n", x[i]);
		}
	}*/

	for(i = 0, k = 0; i < 10; i++){
		if(k >= 3){
			break;
		}else{
			printf("%d\n", x[i]);
			k++;
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define pb push_back
//#define int long long
#define mod 1000000007
#define fi first
#define se second
#define ll long long
#define scan() ll n; cin>>n ; ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(ll i=x;i<y;i++)
using namespace std;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<ll,ll> pll ;
int main()
{
	fast;
	ll k;
	cin>>k;
	ll sum=0;
	for(ll a=1;a<=k;a++)
	{
		for(ll b=1;b<=k;b++)
		{
			for(ll c=1;c<=k;c++)
			{
				if(a==1||b==1||c==1)
					sum+=1;
				else
					sum+=__gcd(a,__gcd(b,c));
			}
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3652
import fractions
a, b, c, d = map(int, input().split())
e = c * d // fractions.gcd(c, d)
f = b // c - (a - 1) // c
g = b // d - (a - 1) // d
h = b // e - (a - 1) // e
print(b - a + 1 - f - g + h)


Measured memory_bytes: 5432
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll N,A[30],B[30],C[30],M=0;
    cin >> N;
    rep(i,N){
      cin >> A[i];
    }
    rep(i,N){
      cin >> B[i];
    }
    rep(i,N-1){
      cin >> C[i];
    }
    rep(i,N){
      M+=B[A[i]-1];
      if(i>0){
        if(A[i]==A[i-1]+1){
          M+=C[A[i]-2];
        }
      }
    }
    cout << M << endl;
}

Measured memory_bytes: 888
#include <iostream>

int main() {
	char stringnya1[3], stringnya2[3];
	int jumlah{};
	std::cin >> stringnya1 >> stringnya2;
	for (int i {0}; i < 3; i++) {
		if (stringnya1[i] == stringnya2[i]) {
			jumlah++;
		}
	}
	std::cout << jumlah;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
  int n; cin>>n;  
  int A[n],B[n];
  for(int i=0;i<n;i++){cin>>A[i];}
 sort(A,A+n);
 for(int i=0;i<n;i++){B[i]=A[n-1-i];}
 int ans=0;
 ans+=B[0];
 if(n%2==0)
 {
     for(int i=1;i<n/2;i++){ans+=2*B[i];}
 }
 else
 {
   for(int i=1;i<n/2;i++){ans+=2*B[i];}  
   ans+=B[n/2];
 }  
   
   cout<<ans; 
}


Measured memory_bytes: 6692
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
u=a.sort.chunk_while{|a,b|a==b}.select{|ar|ar.size>=2}
#[[1,1],[2,2]]
if u.size<2
  puts 0
elsif u[-1].size>=4
  puts u[-1][0]**2
else
  puts u[-1][0]*u[-2][0]
end


Measured memory_bytes: 12656
#include<bits/stdc++.h>
using namespace std;
int good[100001];
int main(){
	int n,m;
	cin>>n>>m;
	int h[n+1];
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		if(h[a]>h[b]){
			good[b]=2;
			if(good[a]==0){
				good[a]=1;
			}
		}
		else if(h[a]<h[b]){
			good[a]=2;
			if(good[b]==0){
				good[b]=1;
			}
		}
		else{
			good[a]=2;
			good[b]=2;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(good[i]==1 || good[i]==0)
			cnt++;
	}
	cout<<cnt;
	return 0;
} 

Measured memory_bytes: 4412
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, k;
    cin >> n >> k;

    cout << n - k + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

  int a[1000010] = {0} , max = 0 , b;
  for(int i = 0;i < n;i ++){
    scanf("%d",&b);
    a[b] ++;
    if(max < b){
      max = b;
    }
  }

  int temp , count;
  for(int i = 1;i <= max;i ++){
    if(a[i] > 0){
      temp = i;
      count = 2;
      while(temp * count <= max){
        a[temp*count] = 0;
        count ++;
      }
      if(a[i] > 1){
        a[i] = 0;
      }
    }
  }
  int ans = 0;
  for(int i = 1;i <= max;i ++){
    if(a[i] != 0){
      ans ++;
    }
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 5644
#include <iostream>

using namespace std;

int main() {
    int x,y,min;

    cin >> x >> y;

    if(x > y){
        min = x % y;
        for(min;min > 0;min--){
            if((x % y) % min == 0 && y % min == 0){
                cout << min << endl;
                break;
            }
        }
    }
    else if(x == y){
        cout << x <<endl;
    }
    else {
        min = y % x;
        for(min;min > 0;min--){
            if((y % x) % min == 0 && x % min == 0){
                cout << min << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 100000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	k, _ := strconv.Atoi(Scanner())
	fmt.Println(smaller(n%k, k-n%k))
}

func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n>>k;

	f(i,0,n-1) cin>>ara[i];

	f(i,0,n-1){
        count+=(min((ara[i]*2),((k-ara[i])*2)));
	}
	cout<<count<<endl;
}


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

int main(void){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  map<string, int> mp;
  for(string str : s) {
    if(mp.count(str)) mp[str]++;
    else mp[str] = 1;
  }
  int max_str = 0;
  for(string str : s) max_str = max(max_str, mp[str]);
  set<string> st;
  for(string str : s) {
    if(mp[str] == max_str) st.insert(str);
  }
  for(string s : st) cout << s << endl;
  return 0;
}

Measured memory_bytes: 40636
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut A: i64 = read();
    let mut B: i64 = read();
    let mut C: i64 = read();
    let mut X:i64 = read();
    let mut counter = 0;
    for a in 0..(A+1) {
        for b in 0..B+1 {
            for c in 0..C+1 {
                if 500*a + 100*b + 50*c == X {
                    counter += 1;
                }
            }
        }
    }

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

Measured memory_bytes: 4352
#include <iostream>
#include<vector>
#include<cmath>

using namespace std;
int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d)
      cout << "Yes\n";
    else{
      if(abs(a-b)<=d && abs(b-c)<=d)
        cout << "Yes\n";
      else
        cout << "No\n";
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())
#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

char S[200000+1];
char T[200000+1];

int
main()
{
  scanf("%s", S);
  scanf("%s", T);

  int ans = 0;
  REP(i, strlen(S)) {
    if (S[i] != T[i]) ans++;
  }

  printf("%d\n", ans);

  return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N;
int A[100100];

const std::string YESNO[2] = {"No", "Yes"};

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

    std::cin >> N;

    int n4 = 0, n2 = 0, n1 = 0;
    for(int i=0;i<N;++i){
        std::cin >> A[i];

        if(A[i] % 4 == 0){
            n4++;
        }else if(A[i] % 2 == 0){
            n2++;
        }else{
            n1++;
        }
    }

    int rest = N - n2;
    std::cout << YESNO[(n2 > 0 && n4 >= (rest + 1) / 2) || (n2 == 0 && n4 >= rest / 2)] << std::endl;
}


Measured memory_bytes: 640
abc = sorted(list(map(int,input().split())))
pari = [t%2 for t in abc]

ans = 0
for n in [0,1]:
    if pari.count(n) == 2:
        idx = []
        for i in range(3):
            if pari[i] == n: idx.append(i)
        abc[idx[0]] += 1
        abc[idx[1]] += 1
        ans += 1
for i in [0,1]: ans += (abc[2]-abc[i])//2
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#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 reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    cout << n * (n + 1) / 2 << endl;

return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
int min_val, max_val;
int main()
{
    cin >> N;
    A.resize(N);
    min_val = INF;
    max_val = -INF;
    for (auto &val : A)
    {
        cin >> val;
        min_val = min(min_val, val);
        max_val = max(max_val, val);
    }
    vector<pii> result;
    if (abs(min_val) <= abs(max_val))
    {
        int max_idx = -1;
        for (int i = 0; i < N; i++)
        {
            if (max_val == A[i])
            {
                max_idx = i;
                break;
            }
        }

        for (int i = 0; i < N; i++)
        {
            result.emplace_back(mp(max_idx, i));
            result.emplace_back(mp(max_idx, i));
            max_idx = i;
        }
    }
    else
    {
        int min_idx = -1;
        for (int i = 0; i < N; i++)
        {
            if (min_val == A[i])
            {
                min_idx = i;
                break;
            }
        }
        for (int i = N - 1; i >= 0; i--)
        {
            result.emplace_back(mp(min_idx, i));
            result.emplace_back(mp(min_idx, i));
            min_idx = i;
        }
    }
    cout << result.size() << endl;
    for (auto &val : result)
    {
        cout << val.first + 1 << " " << val.second + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
        int x,y,z,t=0;
        cin>>x>>y>>z;
        x-=(2*z);
        while(x>=y){
            x-=(y+z);
            t++;
        }
        cout<<t;
   return 0;
   }

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

int main()
{
ll r , c , n ;
cin >> r >> c >> n ;
map<ll,ll> m;
rep(i,n){
  ll x , y , xx , yy ;
  cin >> x >> y >> xx >> yy ;
  if((x==0||x==r||y==0||y==c)&&(xx==0||xx==r||yy==0||yy==c)){
  if(y==0)m[x]=i;
  else if(x==r)m[r+y]=i;
  else if(y==c)m[r+c+r-x]=i;
  else if(x==0)m[2*r+c+c-y]=i;
  if(yy==0)m[xx]=i;
  else if(xx==r)m[r+yy]=i;
  else if(yy==c)m[r+c+r-xx]=i;
  else if(xx==0)m[2*r+c+c-yy]=i;
  }
}
vector<ll> v;
vector<bool> see(n);
auto itr=m.begin();
rep(i,m.size()){
  if(see[itr->second]==0){
    see[itr->second]=1;
    v.push_back(itr->second);
  }
  else{
    if(v.back()!=itr->second){
      cout << "NO" << endl;
      return 0;
    }
    v.pop_back();
  }
  itr++;
}
cout << "YES" << endl;
return 0;
}

Measured memory_bytes: 13436
#include<stdio.h>
#define H 500001

void maxHeapify(int);
int a,i,A[H];
int main()
{
  scanf("%d",&a);
  for(i=1;i<=a;i++){
    scanf("%d",&A[i]);
  }
  for(i=a/2;i>0;i--) maxHeapify(i);
  for(i=1;i<=a;i++)printf(" %d",A[i]);
    printf("\n");
    return 0;
}

void maxHeapify(int x){
  int largest, l,r, t;
    l=2*x;
    r=2*x+1;
    if(l<=a && A[l]>A[x])largest=l;
    else largest=x;
    if(r<=a&&A[r]>A[largest])largest=r;
    if(largest!=x){
        t=A[x];
        A[x]=A[largest];
        A[largest]=t;
        maxHeapify(largest);
    }
}



Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long N, A, B, K;

int main() {
    COMinit();
    while (cin >> N >> A >> B >> K) {
        long long res = 0;
        for (long long a = 0; a <= N; ++a) {
            long long rem = K - a * A;
            if (rem % B != 0) continue;
            long long b = rem / B;
            if (b > N) continue;
            long long tmp  = COM(N, a) * COM(N, b) % MOD;
            res += tmp;
            res %= MOD;
        }
        cout << res << endl;
    }
}






























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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n, m;
    cin >> n >> m;
    vector<int> h(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    vector<int> h1(n + 1);
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        h1[a] = max(h1[a], h[b]);
        h1[b] = max(h1[b], h[a]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        // DBG(h1[i]);
        // DBG(h[i]);
        if (h1[i] < h[i])
            ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
	string w;cin >> w;
	vector<int> cnt(26,0);
	for(char ch:w){
		cnt[ch-'a']++;
	}
	rep(i,26){
		if(cnt[i]%2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

} 
 

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, m; cin >> n >> m;
	vector<long long> x(m); rep(i, 0, m - 1)cin >> x[i];
	sort(all(x));
	vector<long long> dis(m - 1); rep(i, 1, m - 1)dis[i - 1] = x[i] - x[i - 1];
	sort(all(dis), greater<long long>());
	long long res = x.back() - x[0];
	rep(i, 0, min(n - 2, m - 2))res -= dis[i];
	cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int h1, m1, h2, m2, l;
	cin >> h1 >> m1 >> h2 >> m2 >> l;
	cout << (h2 - h1) * 60 + m2 - m1 - l << '\n';
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
typedef long int li;
#define df 0
int main(){
  int n,q;
  string str;
  cin >> n >> str >> q;
  vector<int>query(q);
  for(int i=0;i<q;i++){
    cin >> query.at(i);
  }

    li s=0;
    vector<li> d(n,0);
    for(int i=0;i<n;i++){
      // d();
      if(str.at(i)=='D')s++;
      d.at(i)=s;
    }
    if(df){
      for(int k=0;k<n;k++) printf("%d",d.at(k)%10);
      printf(":d\n");
    }
    s=0;
    vector<li> m(n,0);
    for(int i=0;i<n;i++){
      // d();
      if(str.at(i)=='M')s++;
      m.at(i)=s;
    }
    if(df){
      for(int k=0;k<n;k++) printf("%d",m.at(k)%10);
      printf(":m\n");
    }
    s=0;
    vector<li> dm(n,0);
    for(int i=0;i<n;i++){
      // dm();
      if(str.at(i)=='M')s+=d.at(i);
      dm.at(i)=s;
    }
    if(df){
      for(int k=0;k<n;k++) printf("%d",dm.at(k));
      printf(":dm\n");
    }

  for(int j=0;j<q;j++){
    s=0;
    for(int i=0;i<n;i++){
      if(str.at(i)=='C'){
	s+=dm.at(i);
	int q=query.at(j);
	if(i>=q){
	  s-=dm.at(i-q);
	  s-=d.at(i-q)*(m.at(i)-m.at(i-q));
	}
      }
    }
    cout << s << "\n";
  }

}

Measured memory_bytes: 24836
#include <stdio.h>
int main(void) {
	int s[100000], n, q, t, i, j, num = 0;
	int half;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", s+i);
	}
	scanf("%d", &q);
	half = n / 2;
	for (j = 0; j < q; j++) {
		scanf("%d", &t);
		if (t < s[half]) {
			for (i = 0; i < half; i++) {
				if (t == s[i]) {
					num++;
					break;
				}
			}
		} else {
			for (i = half; i < n; i++) {
				if (t == s[i]) {
					num++;
					break;
				}
			}
		}
	}
	printf("%d\n", num);
	return 0;
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int n,cnt=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		if(i&1&&a[i]&1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int Left_plate = A+B;
  int Right_plate = C+D;
  if (Left_plate > Right_plate){
   cout << "Left" << endl;
  }
  else if (Left_plate < Right_plate){
   cout << "Right" << endl; 
  }
  else {
   cout << "Balanced" << endl; 
  }
}

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

int main(){
  int N,M,X;
  cin>>N>>M>>X;
  
  vector<vector<int>> v(N,vector<int>(M+1));
  
  for (int i=0;i<N;++i){
    for (int j=0;j<M+1;++j){
      cin >> v.at(i).at(j);
    }
  }//数値入れ完了
  
  vector<int> S(0);//C任意個の合計を後に追加
  
  //全探索開始
  for (int k=0;k<(1<<N);++k){
    
    vector<int> T(M+1);//一個の探索で、各要素の合計をここに入れる。
    for (int l = 0;l<N;++l){
      if ((k>>l)&1){
        for(int m=0;m<M+1;++m){
          T.at(m)+=v.at(l).at(m);
        }
      }
    }//１の行の要素を全て足し合わせた
    
    int a=0;
    for (int b=0;b<M;++b){
      if (T.at(b+1)<X){
        a++;
      }
    }
    if (a==0){
      S.push_back(T.at(0));
    }//Sにｃの和を追加
  }
  
  if (S.size()==0){
    cout << "-1"<<endl;
  }
  else{
    sort(S.begin(),S.end());
    cout << S.at(0);
  }
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>

using namespace std;

typedef long long int ll;
int main(){
	int N,W,i,j,mx_val=0;
	cin>>N>>W;
	vector<int> wt(N);
	vector<int> val(N);
	for(i=0;i<N;i++){
		cin>>wt[i];
		cin>>val[i];
		mx_val+=val[i];
	}
	vector<vector<int>> dp(N+1,vector<int>(mx_val+1,0));
	for(j=1;j<=mx_val;j++)
		dp[0][j]= W+1;
	for(i=1;i<=N;i++){
		for(j=mx_val;j>=1;j--){
			if(val[i-1]>j){
				dp[i][j]=min(dp[i-1][j],wt[i-1]);
			}
			else{
				dp[i][j]=min(dp[i-1][j],wt[i-1]+dp[i-1][j-val[i-1]]);
			}
		}
	}
	for(j=mx_val;j>=0;j--){
		if(dp[N][j]<=W){
			cout<<j<<endl;
			break;
		}

	}

	return 0;
		
}

Measured memory_bytes: 42632
/*
#include<iostream>
#include<stack>
using namespace std;

struct time_check {
    int find_time, end_time;
};

int main() {
    int G[101][101] = {0};
    time_check t[101];

    for (int i = 1; i <= 100; i++) t[i].end_time = 0;

    stack<int> S;
    int n, u, v, k, elapsed=1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }
    S.push(1);
    t[1].find_time = 1;
    while (! S.empty()) {
        elapsed++;
        u = S.top();
        for (int i = 1; i <= n + 1; i++) {
            if (G[u][i] == 1 && t[i].end_time == 0) {
                t[i].find_time = elapsed;
                G[u][i] = 0;
                S.push(i);
                break;
            }
            if (i == n + 1) {
                t[u].end_time = elapsed;
                S.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << t[i].find_time << " " << t[i].end_time << endl;
    }

    return 0;
}
このコードはWrong Answerです...
理由は以下のコードのl.111のとこのように未訪問の頂点を始点としてdfsしてないから
*/

#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BRACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

// uに隣接するvを番号順に取得
int next(int u) {
    for (int v = nt[u]; v < n; v++) {
        nt[u] = v + 1;
        if (M[u][v]) return v;
    }
    return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r) {
    for (int i = 0; i < n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while (! S.empty()) {
        int u = S.top();
        int v = next(u);
        if (v != -1) {
            if (color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BRACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    // 初期化
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    // 未訪問のuを始点として深さ優先探索
    for (int u = 0; u < n; u++) {
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

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

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
int main()
{
	int a,b;cin>>a>>b;
	cout<<max(0,a-2*b);
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define ll long long
using namespace std;

const int N=100005;

int n,m,k,tot;
ll l,sg;
int ch[N][2];
char s[N];

ll lowbit(ll x){
	return x&-x;
}

void dfs(int k,int d){
	if (!ch[k][0]&&!ch[k][1]) return;
	if (ch[k][0]) dfs(ch[k][0],d+1);
	if (ch[k][1]) dfs(ch[k][1],d+1);
	if (!ch[k][0]||!ch[k][1]) sg^=lowbit(l-1ll*d);
}

int main(){
	int i,j;
	scanf("%d%lld",&n,&l);
	for (i=1;i<=n;i++){
		scanf("%s",s+1); m=strlen(s+1);
		k=0;
		for (j=1;j<=m;j++){
			if (!ch[k][s[j]-'0']) ch[k][s[j]-'0']=++tot;
			k=ch[k][s[j]-'0'];
		}
	}
	dfs(0,0);
	if (sg) printf("Alice\n");
	else printf("Bob\n");
	return 0;
}

Measured memory_bytes: 4224
use::std::cmp;

const INF: i64 = 1e18 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n:usize = sc.read();
    let m: usize = sc.read();
    let l: i64 = sc.read();
    let mut dist = vec![vec![INF; n]; n];
    for i in 0..n {
        dist[i][i] = 0;
    }
    for _ in 0..m{
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        let c = sc.read();
        dist[a][b] = c;
        dist[b][a] = c;
    }

    for u in 0..n{
        for v in 0..n{
            for w in 0..n{
                dist[v][w] = cmp::min(dist[v][w], dist[v][u] + dist[u][w]);
            }
        }
    }

    
    let mut ans = vec![vec![n; n]; n];
    for i in 0..n {
        ans[i][i] = 0;
    }
    for u in 0..n{
        for v in 0..n{
            if u == v{
                ans[u][v] = 0;
                continue;
            }
            if dist[u][v] <= l{
                ans[u][v] = 1;
            }
        }
    }
    
    for u in 0..n{
        for v in 0..n{
            for w in 0..n{
                ans[v][w] = cmp::min(ans[v][w], ans[v][u] + ans[u][w]);
            }
        }
    }

    // for u in 0..n{
    //     for v in 0..n{
    //         println!("{}", ans[u][v]);
    //     }
    // }


    let q: usize = sc.read();
    for _ in 0..q{
        let s:usize = sc.read();
        let t:usize = sc.read();
        if ans[s-1][t-1] == n{
            println!("-1");
        }else{
            println!("{}", ans[s-1][t-1]-1);
        }
    }
    
    
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	string keys; cin >> keys;
	keys = keys.substr(1);
	keys += ".";
	vector<string> key;
	string tmp;
	for(char c : keys) {
		if(c == '.') {
			key.push_back(tmp);
			tmp = "";
		} else {
			tmp += c;
		}
	}
	// for(string s : key) cerr << s << endl;
	int indent = -1;
	int idx = 0;
	string ans;
	while(getline(cin, tmp)) {
		if(idx >= (int)key.size()) continue;
		try {
			int ide = 0;
			for(char c : tmp) {
				if(c == ' ') {
					ide++;
				} else {
					if(ide <= indent) {
						throw "INDENT FALSE";
					}
					break;
				}
			}
			string tag;
			for(int i = ide; i < (int)tmp.size(); ++i) {
				if(tmp[i] == ':') break;
				tag += tmp[i];
			}
			if(key[idx] == tag and tag != "") {
				indent = ide;
				idx++;
			}
		}
		catch(const char* s) {
			// fprintf(stderr, "%s\n", s);
			continue;
		}
		if(idx == (int)key.size()) {
			bool flg = 0;
			for(int i = 0; i < (int)tmp.size(); ++i) {
				if(flg) {
					ans += tmp[i];
				}
				if(tmp[i] == ':') {
					i++;
					flg = 1;
				}
			}
			if(ans != "") {
				cout << "string \"" << ans << "\"" << endl;
			} else {
				cout << "object" << endl;
				ans = "!";
			}
			idx++;
		}
	}
	if(ans == "") {
		cout << "no such property" << endl;
	}
	return 0;
}


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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    int N, K, S;
    cin >> N >> K >> S;
    int F = 1e9;
    if (F == S) F = 1;
    Fr(i, 0, N)
        cout << (i < K ? S : F) << " \n"[i==N-1];

}


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

using namespace std;

typedef long long ll;

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll m = 999999999999;
    for (int i = 0; i <= X; i++) {
        if (i* A > m) { break; }
        ll k = (X - i) * 2;
        ll j;
        if (B < 2 * C) {
            // buy B
            j = max(ll(0), Y - (X - i));
        } else {
            k = max(k, Y*2);
        }
        ll cost = i * A + j * B + k * C;
        m = min(m, cost);
    }

    cout << m << endl;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int[] diff = new int[n];
        for (int i = 0; i < n - 1; i++) {
            diff[i] = a[i + 1] - a[i];
        }
        diff[n - 1] = a[0] + (k - a[n - 1]);

        int sum = Arrays.stream(diff).sum();
        int max = Arrays.stream(diff).max().getAsInt();
        int result = sum - max;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 60680
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const int MOD = 998244353;
template <class T> void chadd(T& x, T y) { x = (x + y) % MOD; }
struct SegTree {
    int N;
    vector<int> A;
    SegTree(int n) {
        N = 1; while (N < n) N *= 2;
        A.resize(2 * N);
    }
    void set(int idx, int val) {
        idx += N;
        A[idx] = val;
        idx /= 2;
        while (idx > 0) {
            A[idx] = max(A[2*idx+0], A[2*idx+1]);
            idx /= 2;
        }
    }
    int maxrange(int L, int R) {
        L += N, R += N;
        int ans = 0;
        while (L < R) {
            if (L & 1) ans = max(ans, A[L++]);
            if (R & 1) ans = max(ans, A[--R]);
            L /= 2, R /= 2;
        }
        return ans;
    }
    int get(int idx) {
        return A[idx + N];
    }
};
int main() {
    int N; cin >> N;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) {
        int x, d; cin >> x >> d; A[i] = make_pair(x, d);
    }
    sort(begin(A), end(A));
    SegTree st(N);
    for (int i = N - 1; i >= 0; i--) {
        int t = A[i].first + A[i].second;
        int k = lower_bound(begin(A), end(A), make_pair(t, 0)) - begin(A);
        st.set(i, k);
        st.set(i, st.maxrange(i, k));
    }
    vector<int> dp(N + 1);
    dp[N] = 1;
    for (int i = N - 1; i >= 0; i--) {
        chadd(dp[i], dp[i + 1]);
        chadd(dp[i], dp[st.get(i)]);
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<vector>
using namespace std;
long  a,b,c,r=0;

int main(){
    cin>>a>>b>>c;
    a+=b;
    r+=b;
    while(c>1 && a>0){
        c--;
        a--;
        r++;
        //cout<<r<<endl;

    }

    if(c>0)r++;
    cout<<r;
}



Measured memory_bytes: 256