akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

// 1次元累積和
template <typename T>
class CumSum1D
{
public:
    CumSum1D(){};
    ~CumSum1D(){};
    void init(vector<T>& arr) {
        m_cum = arr;
        m_N = arr.size();
        FOR(i, 1, m_N) m_cum[i] += m_cum[i - 1];
    }
    // get sum of [l, r]. 0-based.
    T getSum(int l, int r) {
        T ret = m_cum[r];
        if (l != 0) ret -= m_cum[l - 1];
        return ret;
    }
private:
    size_t m_N;
    vector<T> m_cum;
};

int main(void)
{
    cin.sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> Vs(N);
    REP(n, N) cin >> Vs[n];

    CumSum1D<ll> cum;
    cum.init(Vs);

    ll ans = 0;
    ll sum_of_all = cum.getSum(0, N - 1);

    if (K >= N) {
        ans = max(ans, sum_of_all);
    }
    
    REP(p1, N) {
        FOR(p2, p1, N) {
            int remained = p2 - p1 + 1;
            int taken = N - remained;
            if (taken > K) continue;

            ll score = sum_of_all - cum.getSum(p1, p2);

            //cout << "p1, p2 = " << p1 << "," << p2 << endl;
            //cout << "temp score = " << score << endl;

            vector<ll> gems;
            REP(p, p1) gems.pb(Vs[p]);
            FOR(p, p2 + 1, N) gems.pb(Vs[p]);
            //cout << "gems = "; for(auto e: gems) cout << e << " "; cout << endl;

            sort(ALL(gems));
            int i = 0;
            while(taken < K && i < SIZE(gems)) {
                if (gems[i] < 0) {
					score -= gems[i];
					++i;
                    ++taken;
                } else {
                    break;
                }
            }
            //cout << "final score = " << score << endl;

            ans = max(ans, score);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
    x,y,z = ints()
    print(z,x,y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
using System;
class _0036
{
    public static void Main()
    {
        string str;
        string[] keys = new string[7] { "1100000011", "1000000010000000100000001", "1111", "1000000110000001", "11000000011", "100000001100000001", "110000011" };
        while ((str = Console.ReadLine()) != null)
        {
            for (int i = 0; i < 7; i++) str += Console.ReadLine();
            for (int i = 0; i < 7; i++) if (str.Contains(keys[i])) Console.WriteLine((char)('A' + i));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 6208
#include <stdio.h>
// #include <string.h>
// #include <math.h>

int three(int);

int main() {
    int n,i,mo;
    scanf("%d",&n);
    for(i=3;i<=n;i++){
        if(i%3==0){
            printf(" %d",i);
        }else{
            mo = three(i);
            if(mo==1){
                printf(" %d",i);
            }
        }
    }
    printf("\n");
    return 0;
}

int three(int x){
    if(x%10==3){
        return 1;
    }else{
        x/=10;
        if(x>=3){
            three(x);
        }else{
            return 0;
        }
    }
}


Measured memory_bytes: 2080
# hiyakashiの指摘で修正
# 自分ではresと打ったつもりがselfと打ってた
# 前のソースでは割る数が負の時に動かない
# なぜAcceptしたんだろ

class Fixnum

	def /(o)
		res = self.fdiv(o)
		if (res < 0)
			return res.ceil
		else
			return res.floor
		end
	end

end

gets.to_i.times do
	puts eval(gets.chomp.chop)
end

Measured memory_bytes: 5648
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
ll n,k,a,b,c,d,m,num[maxn];
string str;
int main()
{
    cin >> str;
    if(str[2] == str[3] && str[4] == str[5])
        cout << "Yes" <<endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
     	int x=sc.nextInt();
  
		for(int c=x-k+1;c<=x+k-1;c++){
    	System.out.println(c);
        }
    }
}


Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);
        System.out.println( solve() );
    }

    private static long solve() {
        long ans = 0; // 念のため
        for (int i = 0; i < N; i++) {
            ans += count2(A[i]);
        }
        return ans;
    }

    private static int count2(int n) {
        int time = 0;
        while(n%2==0) {
            time++;
            n = n/2;
        }
        return time;
    }


    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 25044
#include <iostream>

using namespace std;

class Dice {
public:
	int top, face[6];
	void East() {
		top = face[0];
		face[0] = face[3];
		face[3] = face[5];
		face[5] = face[2];
		face[2] = top;
	}
	void West() {
		top = face[0];
		face[0] = face[2];
		face[2] = face[5];
		face[5] = face[3];
		face[3] = top;
	}
	void North() {
		top = face[0];
		face[0] = face[1];
		face[1] = face[5];
		face[5] = face[4];
		face[4] = top;
	}
	void South() {
		top = face[0];
		face[0] = face[4];
		face[4] = face[5];
		face[5] = face[1];
		face[1] = top;
	}
};


int main() {
	int i, j, k, l, q, x, y, w;
	Dice dice;
	for (i = 0; i < 6; i++)
		cin >> dice.face[i];
	cin >> q;
	for (w = 0; w < q; w++){
		cin >> x >> y;
		for (i = 0; i < 6; i++){
			if (i == 4) dice.North();
			else if (i == 5) {
				dice.South();
				dice.South();
			}
			else dice.East();
			for (j = 0; j < 4; j++){
				k = dice.face[1];
				dice.face[1] = dice.face[2];
				dice.face[2] = dice.face[4];
				dice.face[4] = dice.face[3];
				dice.face[3] = k;
				if (dice.face[0] == x&&dice.face[1] == y)
					cout << dice.face[2] << endl;
			}
		}
	}
}

Measured memory_bytes: 1160
K, S = gets.split.map(&:to_i)
cnt = 0
min_x = [0, S-2*K].max
max_x = [K,S].min
min_x.upto(max_x) do |i|
    max_y = [S - i, K].min
    0.upto(max_y) do |j|
        k = S - i - j
        cnt += 1 if k.between?(0, K)
    end
end
puts cnt

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

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

int main(){
  int n;
  cin >> n;
  vec<int> h(n);
  rep(i, n) cin >> h[i]; 

  int dp[n];
  rep(i, n){
    dp[i] = 0;
  }
  dp[0] = 0; 
  dp[1] = abs(h[0]-h[1]);
  
  rep(i, n-2){
    dp[i+2] += min(dp[i+1]+abs(h[i+1]-h[i+2]), dp[i]+abs(h[i]-h[i+2]));
  }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d,e,ab=0;
  cin >> a >>b >>c >> d >>e;
  if (a%10!=0){
    ab=a/10*10+10-a;
    a=a/10*10+10;
  }
  if (b%10!=0){
    ab=max(ab,b/10*10+10-b);
    b=b/10*10+10;
  }
  if (c%10!=0){
    ab=max(ab,c/10*10+10-c);
    c=c/10*10+10;
  }
  if (d%10!=0){
    ab=max(ab,d/10*10+10-d);
    d=d/10*10+10;
  }
  if (e%10!=0){
    ab=max(ab,e/10*10+10-e);
    e=e/10*10+10;
  }
  cout << a+b+c+d+e-ab <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
        int i, n, a[100], c1, c2;

        c1=0; c2=0;
        scanf("%d", &n);
        for(i=0; i<n; i++){
                scanf("%d",&a[i]);
                if(a[i]%2==0)
                        c1++;
        }
        for(i=0; i<n; i++)
                if(a[i]%2==0)
                        if(a[i]%3==0||a[i]%5==0)
                                c2++;

        if(c1==c2)
                printf("APPROVED\n");
        else
                printf("DENIED\n");

        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back

using namespace std;
ll d[1001][1001];
ll mod=1e9+7;

main(){
	int h,w;cin>>h>>w;
	
	
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char c;
			cin>>c;
			if(c=='#')d[i][j]=-1;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(d[i][j]!=-1){
			
			if(i==j&&j==1){
				d[i][j]=1;continue;
			}
			ll o=0;
			d[i][j]=(max(d[i][j-1],o)+max(d[i-1][j],o))%mod;	
			}	
		}
	}
	cout<<d[h][w]%mod;
} 

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

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

  int ans = 0, flag = 0;
  rep(i, 10) {
    rep(j, 10) {
      rep(k, 10) {
        flag = 0;
        rep(l, n) {
         if (flag == 0 && s[l]-'0' == i) flag = 1;
          else if (flag == 1 && s[l]-'0' == j) flag = 11;
          else if (flag == 11 && s[l]-'0' == k) {
            flag = 111;
            break;
          }
        }
        if (flag == 111) ++ans;
      }
    }
  }

  cout << ans << endl;
}

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

ll solve( vector<int> A ){
  ll res = 0;
  for(int i=1;i<N;i++){
    if( A[i-1] + A[i] > X ) {
      res += (A[i-1]+A[i]) - X;
      A[i] -= (A[i-1]+A[i]) - X;
      if( A[i] < 0 ) {
        A[i-1] += A[i];
        A[i] = 0;
      }
    }
  }
  return res;
}

int main(){
  cin >> N >> X;
  vector<int> A(N);
  for(int &a:A) cin >> a;

  ll res = solve(A);
  reverse( A.begin(), A.end() );
  res = min( res, solve(A) );
  cout << res << endl;
}




Measured memory_bytes: 1152
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s;
    cin >> s;
    set<char> ls;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    for (char c: alphabet) {
        ls.insert(c);
    }
    if (s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    } else {
        string ssub = s.substr(2, s.size() - 3);
        int cc = 0;
        set<char> other;
        for (char c: ssub) {
            if (c == 'C') {
                cc++;
            } else {
                other.insert(c);
            }
        }
        other.insert(s[1]);
        other.insert(s[s.size()-1]);
        if (cc != 1) {
            cout << "WA" << endl;
            return 0;
        }
        for (char c: other) {
            if (ls.find(c) == ls.end()) {
                cout << "WA" << endl;
                return 0;
            }
        }
        cout << "AC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,k;
    cin>>a>>b>>c>>k;
  if(k<=a)
    cout<<k<<endl;
  else
    if(k<=a+b)
      cout<<a<<endl;
  else 
    cout<<a-(k-(a+b))<<endl;
}


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

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

int main(){
  int n, m;
  cin >> n >> m;
  priority_queue<double> que;
  for(int i=0; i<n; i++){
    long long int a; cin >> a;
    que.push(double(a));
  }
  for(int i=0; i<m; i++){
    double b = que.top();
    que.pop();
    b /= 2.0;
    que.push(b);
  }
  long long int ans;
  while(!que.empty()){
    long long int c = int(floor(que.top()));
    que.pop();
    ans += c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>
int main(){
int H,W,a[300],b[300],i=0,N=0;
scanf("%d %d",&a[0],&b[0]);
while(a[i]!=0||b[i]!=0)
{
N++;
i++;
scanf("%d %d",&a[i],&b[i]);
}
for(i=0;i<=N-1;i++)
{
   for(H=1;H<=a[i];H++)
    {
      for(W=1;W<=b[i];W++)
      {
         printf("#");
      }
     printf("\n");
    }
printf("\n");
}
return 0;
}

      





Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
				for(int i=0; i<N; i++)
				{
					int a = sc.nextInt();
					int b = sc.nextInt();
					int c = sc.nextInt();
						if(a>b && a>c){
							if(a*a == b*b + c*c){
								System.out.println("YES");
							} else System.out.println("NO");
						} else if(b>a && b>c){
							if(b*b == a*a + c*c){
								System.out.println("YES");
							} else System.out.println("NO");
						} else if(c>a && c>b){
							if(c*c == a*a + b*b){
								System.out.println("YES");
							} else System.out.println("NO");
						} else System.out.println("NO");
				}
		}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(),(x).end()

int main(){
	int n; cin>>n;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	sort(all(v));
	int ans=0;
	rep(i,n-1){
		ans+=abs(v[i+1]-v[i]);
	}
	cout<<ans<<endl;
}

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

// int main() {
//   int N, Y;
//   cin >> N;
//   cin >> Y;
//   rep(x, N) {
//     rep(y, N - x) {
//       int z = N - x - y;
//       if (10000*x + 5000*y + 1000*z == Y ) {
//         cout << x << ' ' << y << ' '  << z << endl;
//         return 0;
//       }
//     }
//   }
//   cout << -1 << ' ' << -1 << ' '  << -1 << endl;
//   return 0;
// }

#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int N, Y;
  cin >> N >> Y;
  REP(x, N + 1) REP(y, N - x + 1) {
    int z = N - x - y;
    int v = 10000 * x + 5000 * y + 1000 * z;
    if (v == Y) {
      cout << x << " " << y << " " << z << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;

long long kill(long long h, long long n){
	if (h == 1) return n;
	return n + kill(h/2, n*2);
}


int main(){
	long long h, ans = 0;
	cin >> h;
	ans = kill(h, 1);
	cout << ans << endl;
	return 0;
}


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

ll n,m;
V a;
ll num(ll x){
    ll sum=0;
    rep(i,n){
        if(a[i]>=x){
            sum+=n;
        }else {
            sum+=n-(lower_bound(a.begin(), a.end(), x-a[i])-a.begin());
        }
    }
    return sum;
}

int main(){
    cin>>n>>m;
    a=V(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    V sum(n+1,0);
    rep(i,n){
        sum[i+1]=sum[i]+a[n-i-1];
    }
    ll lb=0,rb=a.back()*2+1;
    rep(i,100){
        ll mid=(lb+rb)/2;
        if(num(mid)>=m){
            lb=mid;
        }else {
            rb=mid;
        }
    }
    ll ans=0;
    ll p=0;
    rep(i,n){
        if(a[i]>=lb){
            ans+=a[i]*n+sum[n];
            p+=n;
        }else {
            ll st=lower_bound(a.begin(), a.end(), lb-a[i])-a.begin();
            ans+=a[i]*(n-st)+sum[n-st];
            p+=n-st;
        }
    }
    if(p>m){
        ans-=(p-m)*lb;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main (void)
{
    int count = 0;
    char s[10];
    scanf("%s", s);

    if ('R' == s[0]) {
        count++;
        for (int i = 1; i < 3; i++) {
            if ('R' == s[i]) {
              count++;
            }
            else {
                break;
            }
        }
    }
    else {
        for (int i = 1; i < 3; i++) {
            if ('R' == s[i]) {
              count++;
            }
        }
    }
    
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 1732
// Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int y;
		cin >> y;

		double g_max = 0.0;
		int b_max = 0;

		for(int i=0; i<n; i++){
			int b, r, t;
			cin >> b >> r >> t;

			double g;
			if(t==1){
				g = 1.0+(double)y*(double)r/100.0;
			}
			else{
				g = 1.0;
				for(int j=0; j<y; j++){
					g *= (1.0+(double)r/100.0);
				}
			}

			if(g>g_max){
				g_max = g;
				b_max = b;
			}
		}

		cout << b_max << '\n';
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <vector>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) {
        cin >> h[i];
    }
    vector<int> cost(n-1);

    cost[n-2] = abs(h[n - 1] - h[n - 2]);
    int step1,step2;
    for (int i = n - 3; i >= 0; i--){
        step1 = abs(h[i] - h[i+1]) + cost[i+1];
        step2 = abs(h[i] - h[i+2]) + cost[i+2];
        cost[i] = min(step1,step2);
    }

    cout << cost[0];

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int cnt = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < 3; i++)
    {
      if(s[i] == t[i])
      {
        cnt++;
      }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import deque
INF = float('inf')


def main():
    H, W, K = map(int, readline().split())
    x1, y1, x2, y2 = map(int, readline().split())
    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1
    C = read().split()

    dist = [[INF] * W for i in range(H)]
    dist[x1][y1] = 0
    d = deque([[x1, y1]])
    dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    while d:
        x, y = d.popleft()
        if (x, y) == (x2, y2):
            print(dist[x][y])
            quit()
        for dx, dy in dxy:
            xx = x
            yy = y
            for i in range(K):
                xx += dx;
                yy += dy
                if 0 <= xx < H and 0 <= yy < W and C[xx][yy] != '@':
                    if dist[xx][yy] <= dist[x][y]:
                        break
                    if dist[xx][yy] == INF:
                        d.append([xx, yy])
                    dist[xx][yy] = dist[x][y] + 1
                else:
                    break

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 36544
# -*- coding: utf-8 -*-
n, r = map(int, input().split())
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
print(len(Base_10_to_n(n, r)))

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

int main()
{
  int k;
  int a,b;
  cin>>k>>a>>b;
  int x=b/k;
  int y=x*k;
  if(y>=a&&y<=b)cout<<"OK";
  else cout<<"NG";
  return 0;
}

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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)

#define INT(n) int n;scanf("%d",&n)
#define STR(s) string s;cin>>s

int main(){
  INT(n); STR(s); STR(t);
  int ans = SZ(s) + SZ(t), b = max(n, max(SZ(s), SZ(t))), e = SZ(s) + SZ(t) + 1;
  REP(i, b, e){
    bool f = true;
    REP(j, SZ(s) + SZ(t) - i){
      if (s[i - SZ(t) + j] != t[j]){
        f = false;
        break;
      }
    }
    if (f) {ans = i; break;}
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        ww: [i32;n]
    }
    let ww = ww;
    let mut l = ww.iter().scan(0, |a,w| {
        *a += *w;
        Some(*a)
    }).collect::<Vec<_>>();
    l.insert(0,0);
    let mut r = ww.iter().rev().scan(0, |a,w| {
        *a += *w;
        Some(*a)
    }).collect::<Vec<_>>();
    r.reverse();
    r.push(0);
    let res = l.iter().zip(r).map(|(a,b)| (a-b).abs())
               .min().unwrap();
    println!("{}", res);
}


Measured memory_bytes: 4352
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

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

string foo(int arr[], int k, int n) {
    int dp[k+1] = {0};
    
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (arr[j] <= i) {
                if (dp[i - arr[j]] == 0) {
                    dp[i] = 1;
                    break;
                }
            } else {
                dp[i] = 0;
            }
        }
    }
    return dp[k] == 1 ? "First" : "Second";
}

int main()
{
    int n;
    int k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << foo(arr, k, n);
    return 0;
}




Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  
  ll max = 0;
  ll min = 1e9 +1;
  
  vector<ll> a(n);
  rep(i, 0, n) {
    cin >> a.at(i);
    if(a.at(i) > max) max = a.at(i);
    if(a.at(i) < min) min = a.at(i);
  }
  
  cout << abs(max-min) << "\n";

}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL ans = 0;
	string s, t; cin >> s >> t;
	FOR(i, 0, SZ(s)) {
		string a = s.substr(0, i);
		string b = s.substr(i, SZ(s));
		if (t == b+a) {
			ans = 1;
		}
	}


	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int m, f, r;
    while (true){
        scanf(" %d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1){
            break;
        }

        if (m == -1 || f == -1){
            printf("F\n");
        }
        else if (m + f >= 80){
            printf("A\n");
        }
        else if (m + f >= 65 && m + f < 80){
            printf("B\n");
        }
        else if (m + f >= 50 && m + f < 65){
            printf("C\n");
        }
        else if (m + f >= 30 && m + f < 50){
            if (r >= 50){
                printf("C\n");
            }
            else {
                printf("D\n");
            }
        }
        else if (m + f < 30){
            printf("F\n");
        }
    }

    return 0;
}
        

Measured memory_bytes: 1012
#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>
using namespace std;
 
#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 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 = 210000;
long long n, m;
int N;
 
int a[MAX], b[MAX];
set<pair<int,int> > black;
map<pair<int,int>, int> alt;
 
 
bool judge(int x, int y) {
    if (black.count(pair<int,int>(x, y))) return true;
    else return false;
}
 
 
int num[15];
void solve() {
    long long all = (n - 2) * (m - 2);
    memset(num, 0, sizeof(num));
    
    alt.clear();
    black.clear();
    for (int i = 0; i < N; ++i) {
        black.insert(pair<int,int>(a[i], b[i]));
        for (int j1 = -1; j1 <= 1; ++j1) {
            for (int j2 = -1; j2 <= 1; ++j2) {
                int ai = a[i] + j1, bi = b[i] + j2;
                if (ai < 1 || ai >= n-1 || bi < 1 || bi >= m-1) continue;
                alt[pair<int,int>(ai, bi)] = 0;
            }
        }
    }
    
    for (map<pair<int,int>, int>::iterator it = alt.begin(); it != alt.end(); ++it) {
        int x = it->first.first;
        int y = it->first.second;
        int tmp = 0;
        for (int j1 = -1; j1 <= 1; ++j1) {
            for (int j2 = -1; j2 <= 1; ++j2) {
                int nx = x + j1, ny = y + j2;
                if (judge(nx, ny)) ++tmp;
            }
        }
        //cout << x << ", " << y << ": " << tmp << endl;
        num[tmp]++;
    }
    
    for (int i = 1; i <= 9; ++i) all -= num[i];
    
    cout << all << endl;
    for (int i = 1; i <= 9; ++i) cout << num[i] << endl;
}
 
 
int main() {
    while (cin >> n >> m >> N) {
        for (int i = 0; i < N; ++i) {
            scanf("%d %d", &a[i], &b[i]);
            --a[i], --b[i];
        }
        solve();
    }
}

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

typedef modint998244353 mint;

const mint inv9 = mint(1) / 9;

struct S {
    mint x, pot;
};

typedef int F;

S op(S l, S r) {
    return {
        l.x * r.pot + r.x,
        l.pot * r.pot,
    };
}

S e() {
    return {0, 1};
}

S mapping(F l, S r) {
    if (l == 0) return r;
    return {
        (r.pot - 1) * inv9 * l,
        r.pot,
    };
}

F composition(F l, F r) {
    if(l == 0) 
        return r;
    else 
        return l;
}

F id() {
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;

    vector<S> init(n, S{1, 10});
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(init);

    while (q--) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        seg.apply(l, r, d);
        cout << seg.prod(0, n).x.val() << endl;
    }
}




Measured memory_bytes: 9964
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = int(input())
A = list(map(int,input().split()))
answers = [-1 for _ in range(N)]
for i in range(N):
    answers[A[i]-1] = i+1
print(" ".join(map(str,answers)))

Measured memory_bytes: 20716
#include<bits/stdc++.h>
#include <string>
#include <unordered_map>
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Zero(dp) memset(dp,0,sizeof(dp))
using namespace std;
bool check(string s)
{
    string t=s;
    reverse(all(t));
    return s==t;
}
int32_t main(){
ios
int t=1;
//cin>>t;
while(t--)
{ 
    int n;cin>>n;
    unordered_map<int,int> m;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    int ans=0;  
    for(auto i:m)
    {
        ans+=(i.second*(i.second-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<ans-(m[a[i]]*(m[a[i]]-1))/2+((m[a[i]]-1)*(m[a[i]]-2))/2<<'\n';
    }
}
}


Measured memory_bytes: 9160
#include <iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    char word;
    
    while(1){
        scanf("%c",&word);
        if(isalpha(word)){
            if (isupper(word))printf("%c",tolower(word));
            else if(islower(word))printf("%c",toupper(word));
            }else printf("%c",word);
            
        if(word=='\n')break;
        }
        return 0;
    }


Measured memory_bytes: 3096
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    string S;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    for (int i=0; i<N; i++){
        cin >> S;
        if (S == "AC"){
            ac += 1;
        }
        if (S == "WA"){
            wa += 1;
        }
        if (S == "TLE"){
            tle += 1;
        }
        if (S == "RE"){
            re += 1;
        }
    }
    cout << "AC" << " x " << ac << endl;
    cout << "WA" << " x " << wa << endl;
    cout << "TLE" << " x " << tle << endl;
    cout << "RE" << " x " << re << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool ans = false;
  for (int i = 1; i <= 9; i++) {
    if (n % i == 0 && (n/i <= 9) && (n/i >= 1)) {
      ans = true;
      break;
    }
  }

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

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = int.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        string[] s = new string[n];
        long[] t = new long[n];
        for (int i = 0; i < n; i++)
        {
            string[] tmp = Console.ReadLine().Split().ToArray();
            s[i] = tmp[0];
            t[i] = long.Parse(tmp[1]);
        }

        var x = Console.ReadLine();
        var index = Array.IndexOf(s,x);
        long ans = 0;
        for (int i = index+1; i < n; i++)
        {
            ans += t[i];
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11104
program Knapsack_1
    implicit none
    integer(4):: n,wn
    integer(8), allocatable:: w(:), v(:)
    integer(8), allocatable:: dp(:), ndp(:)
    integer(4):: i, j

    read*, n, wn
    allocate(w(n), v(n), dp(0:wn), ndp(0:wn))
    do i=1, n
        read*, w(i), v(i)
    end do

    dp(:) = 0
    ndp(:) = 0

    do i=1,n
        do j=1, wn
            if (j < w(i)) then
                ndp(j) = dp(j)
            else
                ndp(j) = max(dp(j), dp(j-w(i)) + v(i))
            end if
        end do
        dp(:) = ndp(:)
    end do

    print*, dp(wn)
end program Knapsack_1

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
typedef long long ll;
int main() {
	const int ramen = 700;
	int count = 0;

	char aaaa[3] = {};
	std::cin >> aaaa[0] >> aaaa[1] >> aaaa[2];
	if (aaaa[0] == 'o') {
		count++;
	}
	if (aaaa[1] == 'o') {
		count++;
	}
	if (aaaa[2] == 'o') {
		count++;
	}
	std::cout << ramen + (100 * count) << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int arr[3001][3001];
 
int32_t main()
{
	fast;
	string s, t;
	cin>>s>>t;
	int m=s.length();
	int n=t.length();
	for(int i=0;i<m+1;i++)
		arr[i][0]=0;
	for(int i=0;i<n+1;i++)
		arr[0][i]=0;
	for(int i=1;i<m+1;i++)
	{
		for(int j=1;j<n+1;j++)
		{
			if(s[i-1]==t[j-1])
			{
				arr[i][j]=arr[i-1][j-1]+1;
			}
			else
			{
				arr[i][j]=max(arr[i-1][j], arr[i][j-1]);
			}
		}
	}
	string s1="";
	int a=m;
	int b=n;
	while(a>0 && b>0)
	{
		if(arr[a][b]==arr[a-1][b])
			a--;
		else if(arr[a][b]==arr[a][b-1])
			b--;
		else
		{
			s1=s[a-1]+s1;
			a--;
			b--;
		}
	}
	cout<<s1<<endl;
	return 0;
}

Measured memory_bytes: 70656
a,b=map(int,input().split())
#print(a)
c=[list(input()) for i in range(a)]
#print(c[0])
d=['.'for i in range(b)]
#print(d)
e=[]
for i in range(a):
	if c[i]!=d:
		e.append(c[i])
#print(e)
#for k in range(len(e)):
f=[]
for i in zip(*e):
	f.append(list(i))
#print(f)

g=['.'for i in range(len(e))]
#print(g)
h=[]
for i in range(len(f)):
	if f[i]!=g:
		h.append(f[i])
#print(h)
j=[]
for i in zip(*h):
	j.append(list(i))
for i in range(len(j)):
	print(''.join(j[i]))


Measured memory_bytes: 3316
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int main(void){
	int A,B,C,cnt=0;
	scanf("%d%d%d",&A,&B,&C);
	while(1){
		if(A==B && B==C)break;
		ll m = max(A,max(B,C));
		if(m-A >= 2){
			A+=2;
			cnt++;
			continue;
		}
		if(m-B >= 2){
			B+=2;
			cnt++;
			continue;
		}
		if(m-C >= 2){
			C+=2;
			cnt++;
			continue;
		}
		if(m-A==1 && m-B==1){
			A++;B++;
			cnt++;
			continue;
		}
		if(m-A==1 && m-C==1){
			A++;C++;
			cnt++;
			continue;
		}
		if(m-C==1 && m-B==1){
			C++;B++;
			cnt++;
			continue;
		}
		if(m-A==1){
			A+=2;
			cnt++;
			continue;
		}
		if(m-B==1){
			B+=2;
			cnt++;
			continue;
		}
		if(m-C==1){
			C+=2;
			cnt++;
			continue;
		}
	}
	printf("%d\n",cnt);
	
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<int> dp(N);

    for (int i = 1; i < N; i++) {
        dp[i] = dp[i-1] + abs(A[i] - A[i-1]);
        if (i - 2 >= 0)
            dp[i] = min(dp[i], dp[i-2] + abs(A[i] - A[i-2]));
    }

    cout << dp[N-1] << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,M,L;
  cin >> N >> M >> L;
  vi A(M),B(M),C(M);
  vvl d(N,vl(N,1e12));
  rep(i,M) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;B[i]--;
    d[A[i]][B[i]]=C[i];
    d[B[i]][A[i]]=C[i];
  }
  int Q;
  cin >> Q;
  vi s(Q),t(Q);
  rep(i,Q) {
    cin >> s[i] >> t[i];
    s[i]--;t[i]--;
  }
  
  rep(i,N) d[i][i]=0;
  rep(k,N) {
    rep(i,N-1) {
      rep2(j,i+1,N) {
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        d[j][i]=d[i][j];
      }
    }
  }
  
  vvi count(N,vi(N,INF));
  rep(i,N) {
    rep(j,N) {
      if(d[i][j]<=L) count[i][j]=1;
    }
  }
  rep(i,N) count[i][i]=0;
  rep(k,N) {
    rep(i,N-1) {
      rep2(j,i+1,N) {
        count[i][j]=min(count[i][j],count[i][k]+count[k][j]);
        count[j][i]=count[i][j];
      }
    }
  }
  
  rep(i,Q) {
    if(count[s[i]][t[i]]!=INF) cout << count[s[i]][t[i]]-1 << endl;
    else cout << -1 << endl;
  }
}

Measured memory_bytes: 5628
#include <iostream>
#include <vector>
//#include <algorithm>
#include <set>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int bfs(const vector<vector<int>>& G, boost::dynamic_bitset<>& eb, const uint u, const uint v, const uint p) {
	//cout << "bfs " << u << " " << v << " " << p << endl; 
	if(u == v) return 0;
	
	for(uint nu=0; nu<G[u].size(); nu++) {
		if(nu == p) continue;
		if(G[u][nu] == -1) continue;
		
		int nd = bfs(G, eb, nu, v, u);
		//cout << "nd " << u << " " << v << " " << nd << endl; 
		if(nd != -1) {
			eb.set(G[u][nu]);
			return nd + 1;
		}
	}
	
	return -1;
}

int main() {
	uint N;
	cin >> N;
	
	vector<vector<int>> G(N, vector<int>(N, -1));
	
	for(uint i=0; i<N-1; i++) {
		uint a, b;
		cin >> a >> b;
		
		G[a-1][b-1] = (int)i;
		G[b-1][a-1] = (int)i;
	}
	
	uint M;
	cin >> M;
	
	vector<boost::dynamic_bitset<>> ebits(M, boost::dynamic_bitset<>(M + N - 1));
	vector<set<boost::dynamic_bitset<>>> ps(2, set<boost::dynamic_bitset<>>());
	
	for(uint i=0; i<M; i++) {
		uint u, v;
		cin >> u >> v;
		
		int dist = bfs(G, ebits[i], u-1, v-1, u-1);
		ebits[i].set(i + N - 1);
		//cout << dist << " " << ebits[i] << endl;
	}
	
	ps[0].insert(boost::dynamic_bitset<>(M + N - 1, 0));
	ull ans = 0;
	
	for(uint i=0; i<=M; i++) {
		uint cur = i % 2;
		uint nxt = (i + 1) % 2;
		
		for(auto p : ps[cur]) {
			
			uint bcnt = p.count() - i;
			ull dif = (ull)1 << (N - 1 - bcnt);
			
			ans = (i % 2) ? ans - dif : ans + dif;
			
			for(uint j=0; j<M; j++) {
				if(!p[j + N - 1]) {
					//cout << "np " << np << endl;
					ps[nxt].insert(p | ebits[j]);
				}
			}
		}
		
		ps[cur].clear();
	}
	
	cout << ans;
	
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  int x;
  x = 1;
  
  for(int i=0 ; i<N ; i++){
    string S;
    cin >> S;
    
    if( S == "P"){
      x *=1 ;
    }
    
    else if( S == "W"){
      x *=1 ;
    }
    
    else if( S == "G"){
      x *= 1;
    }
    
    else if( S == "Y"){
      x *= 0;
    }
    
    else{
      cout << "error" << endl;
      break;
    }
  }
  
  if( x == 1){
    cout << "Three" << endl;
  }

  else if( x == 0){
    cout << "Four" << endl;
  }
  
  else{
    cout << "error" << endl;
  }
}

Measured memory_bytes: 256
n, m = STDIN.gets.split.map(&:to_i)

result = m.times.inject({}) {|acc|
  num, r = STDIN.gets.split
  acc[num] ||= [false, 0]
  unless acc[num][0] 
    if r == 'AC'
      acc[num][0] = true
    else
      acc[num][1] += 1
    end
  end
  acc
}

acs = result.values.select {|n| n[0] }

puts "#{acs.length} #{acs.inject(0) {|acc, i| acc + i[1]}}"

Measured memory_bytes: 22652
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def ceil(a,b):
    return a//b + int(a%b != 0)

N = I()
A = LI()

mau = [0]*(N+1)
miu = [0]*(N+1)
miu[0] = 1
mau[0] = 1
for i in range(1,N+1):
    mau[i] = (mau[i-1]-A[i-1])*2
    miu[i] = miu[i-1]-A[i-1]

mad = [0]*(N+1)
mid = [0]*(N+1)
mad[-1] = A[-1]
mid[-1] = A[-1]
for i in range(N)[::-1]:
    mad[i] = mad[i+1]+A[i]
    mid[i] = ceil(mid[i+1],2)+A[i]


ans = 0
for i in range(N+1):
    if mad[i] < 0 or mau[i] < 0:
        print('-1')
        exit()
    if mid[i] > mau[i]:
        print('-1')
        exit()
    if miu[i] > mad[i]:
        print('-1')
        exit()
    ans += min(mad[i],mau[i])

print(ans)

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N;
    string S;
    cin >> N;

    ll tmp = N / 200;

    cout << 10 - tmp << endl;

}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > c) {
        cout << max(0, min(d - a, b - a));
    }
    else if (c > a) {
        cout << max(0, min(b - c, d - c));
    }
    else {
        cout << min(b - a, d - c);
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(m*i+n*j-2*i*j==k){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
N,K,Q=map(int,input().split())
A = []
for _ in range(Q):
    A.append(int(input()))#縦入力
Nlist = []
for i in range(N):
    Nlist.append(K-Q)
for j in range(0,Q):
    Nlist[A[j]-1] += 1
for k in range(0,N):
    if Nlist[k]>=1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 81648