akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=20005;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n;
char s[maxn],t[maxn];
int as[maxn],at[maxn],cs,ct,a[maxn],b[maxn];
signed main(){
	n=read();
	scanf("%s",s+1);
	scanf("%s",t+1);
	if(s[1]=='1')as[++cs]=0;
	for(int i=1;i<n;i++)if(s[i]!=s[i+1])as[++cs]=i;
	if(s[n]=='1')as[++cs]=n;
	if(t[1]=='1')at[++ct]=0;
	for(int i=1;i<n;i++)if(t[i]!=t[i+1])at[++ct]=i;
	if(t[n]=='1')at[++ct]=n;
	for(int i=1;i<=cs;i++)a[i+ct]=as[i];
	for(int i=cs+ct+1;i<=ct+ct+cs;i++)a[i]=n;
	int ans=1e9;
	for(int i=0;i<=ct+cs;i+=2){
		for(int j=1;j<=i;j++)b[j]=0;
		for(int j=1;j<=ct;j++)b[i+j]=at[j];
		for(int j=i+ct+1;j<=cs+ct+ct;j++)b[j]=n;
		int R=0;
		for(int j=1;j<=cs+ct+ct;j++)R+=abs(a[j]-b[j]);
		ans=min(ans,R);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
  int N;
  cin>>N;
  string str;
  cin >> str;

  int count = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == 'R') {
      count++;
    }
  }
  if(count>str.size()-count)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
  int a,b,t,ans=0;
  cin>>a>>b>>t;
  while(t>=a){
   ans+=b;
   t-=a;
  }
  
  cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   int a,b;cin>>a>>b;
   cout<<(a*b%2==0?"Even":"Odd");
}



Measured memory_bytes: 256
// 問題名: Edit Distance
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp
// 所要時間: 40分(カンニングあり)
// --感想--
// 編集距離が出てくる問題は何度か解いたことがあったが、編集距離そのものを求める問題を解いたことがなかったため、
// 典型問題に触れることができて良い勉強になった。考察は考えても浮かばなかったため、
// https://qiita.com/odenmonster/items/db443d5808788a869fe9
// こちらのサイトを参考にした。

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

// 考察: s1に文字を挿入する操作をs2の対応する文字を削除する操作に置き換えてもよく、s1の文字を置換する操作は
// s1、s2の対応する文字を削除する操作に置き換えてもよい。よって3つの操作は、
// ・s1から1文字削除
// ・s2から1文字削除
// ・s1、s2から1文字削除(削除する文字の位置が対応している必要あり)
// となる。
// 後ろから2つの文字列を揃えていくことを考えると、末尾が同じ文字のときは何もする必要がなく、
// 末尾の文字が異なるときはs1、s2、あるいは両方の末尾の文字を消していくことで、動的計画法を用いて解くことができる。

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    // dp[i][j]:=s1の左からi文字の部分文字列とs2の左からj文字の部分文字列の編集距離
    int dp[1010][1010];
    // 一方が空文字列のとき、編集距離はもう一方の文字列の長さ
    for (int i = 0; i <= s1.length(); i++)
        dp[i][0] = i;
    for (int j = 0; j <= s2.length(); j++)
        dp[0][j] = j;
    for (int i = 1; i <= s1.length(); i++){
        for (int j = 1; j <= s2.length(); j++){
            if(s1[i - 1] == s2[j - 1])
                dp[i][j] = dp[i - 1][j - 1];
            else
                dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
        }
    }
    cout << dp[s1.length()][s2.length()] << endl;
}


Measured memory_bytes: 7140
import java.util.*;
import java.util.stream.IntStream;

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

        int K = sc.nextInt();
        int X = sc.nextInt();

        IntStream stones = IntStream.range(X - (K - 1), X + K);

        stones.forEach(stone -> System.out.print(stone + " "));
    }
}

Measured memory_bytes: 28884
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s;
  ll ans = 10000000000000;
  cin >> s;
  for(char c='a';c<='z';c++){
    string cp;
    cp = s;
    ll cnt = 0;
    while(true){
      bool can = true;
      string tmp;
      ll n = cp.size();
      for(int i=0;i<n;i++){
        if(cp[i]!=c){
          can = false;
          break;
        }
      }
      if(can){
        break;
      }
      cnt++;
      for(int i=0;i<n-1;i++){
        if(cp[i]==c||cp[i+1]==c){
          tmp += c;
        }else{
          tmp += cp[i];
        }
      }
      cp = tmp;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define llint long long int
#define REP(i,s,l) for(llint i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007
 
int main() {
 
    //N個の宝石 i番目Vi原価 Ci経費
    int qnt;
    cin >> qnt ;
    int genka[qnt], keihi[qnt];
    int mouke = 0;
    int sagaku;
 
 
  
    REP(i,0,qnt){ cin >> genka[i];}
    REP(i,0,qnt){ cin >> keihi[i];}
 
    REP(i,0,qnt){
        sagaku = genka[i] - keihi[i];
        if(sagaku > 0) mouke += sagaku;
    }
 
    cout << mouke << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N, M;
	string ans = "Yes";
	cin >> N >> M;
	if (N != M)
		ans = "No";
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
 
constexpr int MOD = 1000000007;
const int INF = 1 << 30;
 
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



 int main(){
 int a;
 cin>>a;
 cout<< a+a*a+a*a*a;


 }

Measured memory_bytes: 3564
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 305, mod = 998244353;
int n, k, mem[MX][MX][MX], sm1[MX][MX][MX], sm2[MX][MX][MX];
string s;
vi v;

int dp (int i, int ant, int k);

int s1 (int i, int ant, int k) {
	if (v[i - 1] + ant >= n) return 0;

	int &res = sm1[i][ant][k];
	if (res != -1) return res;

	res = dp(i, ant, k) + s1(i, ant + 1, k);
	if (res >= mod) res -= mod;

	return res;
}

int s2 (int i, int ant, int k) {
	if (ant < 0 || k < 0) return 0;

	int &res = sm2[i][ant][k];
	if (res != -1) return res;

	res = dp(i, ant, k) + s2(i, ant - 1, k - 1);
	if (res >= mod) res -= mod;

	return res;
}

int dp (int i, int ant, int k) {
	if (k < 0) return 0;
	if (i && v[i - 1] + ant >= n) return 0;
	if (i == v.size()) return ant <= k;

	int &res = mem[i][ant][k];
	if (res != -1) return res;
	res = 0;

	res = s1(i + 1, ant, k);
	res += s2(i + 1, ant - 1, k - 1);
	if (res >= mod) res -= mod;

	if (i && v[i - 1] + ant >= v[i]) {
		int nex = v[i - 1] + ant - v[i];
		res -= s2(i + 1, nex, k - (ant - nex));
		if (res < 0) res += mod;
	}

	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	memset(mem, -1, sizeof(mem));
	memset(sm1, -1, sizeof(sm1));
	memset(sm2, -1, sizeof(sm2));

	cin >> s >> k;
	n = s.size();

	forn (i, n) if (s[i] == '0') {
		v.pb(i);
	}

	cout << dp(0, 0, min(n, k)) << endl;

	return 0;
}


Measured memory_bytes: 336156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n,lim; cin >> n >> lim;
    int res=INF;
    rep(i,n){
        int c,t; cin >> c >> t;
        if(t<=lim) chmin(res,c);
    }
    if(res==INF) cout<<"TLE"<<endl;
    else cout<<res<<endl;
}

Measured memory_bytes: 3588
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] w = saori.nextHayami().split("");
		HashMap<String,Integer> str = new HashMap<>();
		int count = 0;
		boolean flg = false;
		for(int i = 0; i < w.length;i++){
			if(str.containsKey(w[i])){
				count = str.get(w[i]) + 1;
				str.put(w[i], count);
			} else {
				str.put(w[i],1);
			}
		}

		for(int num : str.values()){
			if(num % 2 != 0){
				flg = true;
			}
		}
		if(flg){
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using M = map<int, int>;
ll INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  int r;
  cin >> r;
  printf("%.10lf\n", 2 * r * pi);

  return 0;
}


Measured memory_bytes: 3760
class Dice
  attr_reader :u, :f, :r, :l, :b, :d
  def initialize(line)
    @u, @f, @r, @l, @b, @d = line.split.map(&:to_i)
  end
  def rot(direc)
    case direc
    when "E";
      @u, @l, @d, @r = @l, @d, @r, @u
    when "N";
      @u, @f, @d, @b = @f, @d, @b, @u
    when "S";
      @u, @f, @d, @b = @b, @u, @f, @d
    when "W";
      @u, @l, @d, @r = @r, @u, @l, @d
    when "Z";
      @f, @r, @b, @l = @r, @b, @l, @f
    end
  end
  def dispUp
    printf "%d\n", @u
  end
  def arr
    {:u=>u, :f =>f, :r=>r, :l=>l, :b=>b, :d=>d}
  end
  def out
    return sprintf "%d %d %d %d %d %d", u, f, r, l, b, d
  end
  def diceMatch(dice2)
    dice2.arr.each{|key, val|
      if self.u == val then
        d2 = dice2.clone
        k = sprintf "%s", key
        case k
        when "d"; d2.rot("N"); d2.rot("N");
        when "f"; d2.rot("N");
        when "b"; d2.rot("S");
        when "l"; d2.rot("E");
        when "r"; d2.rot("W");
        end
        4.times do
          if self.out == d2.out then
            return "Yes"
          end
          d2.rot("Z")
        end
      end
    }
    return "No"
  end
end

n = gets.to_i
dice = Array.new(n)
i = 0
n.times{
  dice[i] = Dice.new(gets.chomp)
  i += 1
}
for i in 0..n-1
  for j in i+1..n-1
    if dice[i].diceMatch(dice[j]) == "Yes" then
      printf "No\n"
      exit
    end
  end
end
printf "Yes\n"

Measured memory_bytes: 8968
import java.util.Scanner;

class Main{
  public static void main(String[] arg){
    Scanner scan=new Scanner(System.in);
    String in=scan.next();
    String[] input=in.split("");
    int Ans=0;
    for(int a=0; a<input.length/2; a++){
      if(!input[a].equals(input[input.length-1-a])){
        Ans++;
      }
    }
    System.out.println(Ans);
  }
}

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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<(n);i++)

int main(){
    ll sum=0;
    int N;
    cin >> N;
    vector<vector<int>> kanri(N+1,vector<int>());
    vector<int> hozon(N+1);
    for(int i=1;i<=N;i++){
        int temp;
        cin >> temp;
        hozon[i]=temp;
        kanri[temp].emplace_back(i);
    }
    for(int i=1;i<=N;i++){
        if(!(kanri[i].size()==0)){
            sum += kanri[i].size()*(kanri[i].size()-1)/2;
        }
    }
    for(int i=1;i<=N;i++){
        cout << sum-(kanri[hozon[i]].size()-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 11008
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      long[][] dp = new long[n][3];

      long[][] x = new long[n][3];
      for(int i=0;i<n;i++){
        x[i][0] = Long.parseLong(sc.next());
        x[i][1] = Long.parseLong(sc.next());
        x[i][2] = Long.parseLong(sc.next());
      }
      dp[0][0]= x[0][0];
      dp[0][1]= x[0][1];
      dp[0][2]= x[0][2];

      for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
          for(int k=0;k<3;k++){
            if(j!=k){
              dp[i][j] = Math.max(dp[i][j],dp[i-1][k]+x[i][j]);
            }
          }
        }
      }

      long ans = 0;

      ans = Math.max(dp[n-1][0],dp[n-1][1]);
      ans = Math.max(ans,dp[n-1][2]);

      System.out.println(ans);

    }
}


Measured memory_bytes: 72808
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		var a = int.Parse(Console.ReadLine());
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Array.Sort(input);

		var last = input[input.Length - 1];
		var ans = int.MaxValue;
		for (var i = 0; i <= last; i++)
		{
			ans = Math.Min(ans, Sum(i, input));
		}

		System.Console.WriteLine(ans);
	}

	public static int Sum(int middle, int[] input)
	{
		var ans = 0;
		foreach (var a in input)
		{
			ans += Math.Abs(a - middle) * Math.Abs(a - middle);
		}
		return ans;
	}
}

Measured memory_bytes: 13396
def get_depth(graph,tmp_depth,vertex_list,depth_list):
    new_vertex_list=[]
    for vertex in vertex_list:
        for j in range(len(depth_list)):
            if(graph[vertex][j]!=0 and depth_list[j]==-1):
                depth_list[j]=tmp_depth + 1
                new_vertex_list.append(j)
    if(len(new_vertex_list)!=0):
        get_depth(graph,tmp_depth+1,new_vertex_list,depth_list)


#グラフの作成
n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
    tmp_ope=list(map(int,input().split()))
    for j in range(tmp_ope[1]):
        graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1


depth_list=[-1]*n
depth_list[0]=0
vertex_list=[0]
get_depth(graph,0,vertex_list,depth_list)

for i in range(n):
    print(f"{i+1} {depth_list[i]}")


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
#define mxn 3005
using namespace std;


int n,m,cur = 1;
string s[mxn];
int comp[mxn][mxn];
bool vis[mxn][mxn];
map<pair<int,int>,int> mp;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
bool check(int i,int j){
    if(i < 0 || j < 0 || i >= n || j >= m){
        return false;
    }
    return true;
}
void dfs(int i,int j){
    vis[i][j] = 1;
    comp[i][j] = cur;
    for(int k = 0; k < 4; k++ ){
        int ni = i + dx[k];
        int nj = j + dy[k];
        if(check(ni,nj) && vis[ni][nj] == 0 && s[ni][nj] == '.'){
            dfs(ni,nj);
        }
    }
}


void solve(){
    int ch,dh,cw,dw;

    
    cin >> n >> m ;
    cin >> ch >> dh >> cw >> dw;
    ch--;dh--;cw--;dw--;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(comp[i][j] == 0 && vis[i][j] == false && s[i][j] == '.'){
                dfs(i,j);
                cur++;
            }
        }
    }
    vector<int> v[cur];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i][j] == '#')continue;
            for(int k = i - 2; k <= i + 2; k++){
                for(int m = j - 2; m <= j + 2; m++){
                    if(check(k,m) && s[k][m] == '.'){
                        if(mp[{comp[k][m],comp[i][j]}] == 0 && comp[k][m] != comp[i][j]){
                            mp[{comp[k][m],comp[i][j]}] = 1;
                            mp[{comp[i][j],comp[k][m]}] = 1;
                            v[comp[k][m]].pb(comp[i][j]);
                            v[comp[i][j]].pb(comp[k][m]);
                        }
                    }
                }
            }
        }
    }
    int source = comp[ch][dh];
    int destination = comp[cw][dw];
    // cout << source << "  " << destination << '\n' ;
    int visited[cur] = {};
    map<int,int> depth;
    queue<int> q;
    q.push(source);
    visited[source] = 1;
    depth[source] = 0;
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(auto i : v[u]){
            if(visited[i] == 0){
                visited[i] = 1;
                q.push(i);
                depth[i] = depth[u] + 1;
            }
        }
    }


    cout << (depth.find(destination) == depth.end() ? -1 : depth[destination] );
}

int main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 60724
#include<stdio.h>
#include<math.h>

int hantei(int data){
  int i = 3;
  if(data == 2){
    return 1;
  }
  if(data < 2 || data % 2 == 0){
    return 0;
  }
  while(i <= sqrt(data)){
      if(data % i == 0){
        return 0;
      }
      i = i + 2;
  }
return 1;
}

int main(void){
   int data;
   int num,i;
   int sum=0;
   while(1){
      scanf("%d",&num);
      if(num >= 1 && num <= 10000){
        break;
      }
   }

  for(i = 0 ; i < num ; i++){
     while(1){
     scanf("%d",&data);
     if(data >= 2 && data <= 100000000){
       break;
     }
     }
     sum += hantei(data);
  }
   printf("%d\n",sum);
   return 0;
}



Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <set>

using namespace std;

struct Node {
  std::vector<int> neighbor;
};

using Tree = std::vector<Node>;

std::vector<int> route(Tree& tree, int from, int dst, std::vector<bool>& visited) {
  if (from == dst)
    return {dst};
  for (int v : tree[from].neighbor) {
    if (visited[v])
      continue;
    visited[v] = true;
    std::vector<int> r = route(tree, v, dst, visited);
    if (!r.empty()) {
      r.push_back(from);
      return r;
    }
  }
  return {};
}

std::vector<int> route(Tree& tree, int from, int dst) {
  std::vector<bool> visited(tree.size(), false);
  visited[from] = true;
  return route(tree, from, dst, visited);
}

int counts(Tree& tree, int v, std::vector<bool>& visited) {
  int sum = 1;
  for (int a : tree[v].neighbor) {
    if (visited[a])
      continue;
    visited[a] = true;
    sum += counts(tree, a, visited);
  }
  return sum;
}

int counts(Tree& tree, int v, int skip) {
  std::vector<bool> visited(tree.size(), false);
  visited[v] = true;
  visited[skip] = true;
  return counts(tree, v, visited);
}

void erase(std::vector<int>& v, int num) {
  for (auto it = v.begin(); it < v.end(); it++) {
    if (*it == num) {
      v.erase(it);
      return;
    }
  }
}

int main() {
  int n;
  cin >> n;
  Tree tree(n);
  for (int i = 0; i < n - 1; i++) {
    int in, out;
    cin >> in >> out;
    tree[in - 1].neighbor.push_back(out - 1);
    tree[out - 1].neighbor.push_back(in - 1);
  }

  int black = 0;
  int white = n - 1;
  std::vector<int> r = route(tree, black, white);

  int half = r.size() / 2;
  int black_side_id = r[half];
  int white_side_id = r[half - 1];
  int black_num = counts(tree, black_side_id, white_side_id);
  int white_num = n - black_num;
  
  std::cout << (black_num > white_num ? "Fennec" : "Snuke") << std::endl;
  return 0;
}


Measured memory_bytes: 17276
import itertools
n, m, q = list(map(int, input().split()))
ary = []
point_max=0
for i in range(q):
    ary.append(list(map(int, input().split())))

l = list(range(1, m+1))
# 全パターン網羅
for v in itertools.combinations_with_replacement(l, n):
    point=0
    # 得点計算
    for j in ary:
        if v[j[1]-1]-v[j[0]-1]==j[2]:
            point+=j[3]
    if point_max < point:
        point_max = point
print(point_max)

Measured memory_bytes: 67824
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin>>N;
  vector<vector<ii> > testimonies(N);
  rep(i,N) {
    int a; cin >> a;
    vector<ii> temp(a);
    rep(j, a) {
      int x, y;
      cin >>x>>y;
      x--;
      temp[j] = ii(x,y);
    }
    testimonies[i] = temp;
  }

  int ans = 0;
  for (int i=0; i< (1<<N); i++) {
    vi isHonest(N, 1);
    [&] {
      for (int j=0; j<N; ++j) {
        if ((i>>j)&1) isHonest[j]=1;
        else isHonest[j] = 0;
      }
      for (int j=0; j<N; ++j) {
        if (!isHonest[j]) continue;
        for (int k=0; k<testimonies[j].size(); k++) {
          int x = testimonies[j][k].first;
          if (isHonest[x] != testimonies[j][k].second) return;
        }
      }
      ans = max(ans, __builtin_popcount(i));
    }();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
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; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        A[--a] = i;
    }
    for(int i = 0; i < n; i++) cout << A[i]+1 << " ";
    cout << endl;
    return 0;
}



Measured memory_bytes: 1152
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100000;
int n,m;
int cnt[N+5];
bool pos[N+5];

int main()
{
	scanf("%d %d",&n,&m);
	int a,b;
	pos[1]=1;
	for(int i=1;i<=n;i++) cnt[i]=1;
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&a,&b);
		if(pos[a]) pos[b]=1;
		if( !(--cnt[a]) ) pos[a]=0;
		cnt[b]++;
	}
	int s=0;
	for(int i=1;i<=n;i++)
		s+=pos[i];
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,q;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>q;
    if(n==1){
        rep(i,q){
            cin>>a>>b;
            Cout(min(a,b));
        }
    }
    else{
    rep(i,q){
        cin>>a>>b;
        while(1){
            if(a>b){
                a=(a+n-2)/n;
            }
            else{
                b=(b+n-2)/n;
            }
            if(a==b)break;
        }
        Cout(a);
    }
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

map<int,vi> link;
map<int,int> add;
vi ans;
vector<bool> visited;

void dfs(int v, int a) {
    // printf("v:%d a:%d\n",v,a);
    a += add[v];
    ans[v] += a;
    visited[v] = true;
    for(auto c : link[v]) {
        if(visited[c]) continue;
        dfs(c,a);
    }
}

int main() {
    int n,q; cin >> n >> q;
    rep(i,n-1) { 
        int a,b;
        cin >> a >> b;
        link[a].pb(b);
        link[b].pb(a);
    }
    //         printf("\n");
    // for(auto x:link){
    //     printf("oya:%d\n",x.first);
    //     for(auto y:x.second) {
    //         printf("ko:%d ",y);

    //     }
    //     printf("\n");
    // }
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        add[p] += x;
    }
    rep(i,n+1) {
        ans.pb(0);
        visited.pb(false);
    }
    dfs(1,0);
    FOR(i,1,n+1) {
        if(i!=1) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 53236
#include<stdio.h>

int main(){
  int n,i,j;
  int fib[45]; 
  
  scanf("%d",&n);

  fib[0]=1;
  fib[1]=1;

  
  for(i=2;i<=n;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  printf("%d\n",fib[n]);

  return 0;
}

  



Measured memory_bytes: 2104
n, k = map(int, input().split())

a = list(map(int, input().split()))

b = [0]*n
pos = 0

j = 0

while True:
	b[pos] += 1
	if b[pos]>1:
		rpos = pos
		pos = a[rpos]-1
		i = 1
		while True:
			if pos == rpos:
				break
			pos = a[pos]-1
			i += 1
		break
	
	pos = a[pos]-1
	j += 1

j = j-i

if k>j:
	kp = (k-j)%i
	pos = rpos
else:
	kp = k
	pos = 0

for _ in range(kp):
	pos = a[pos]-1

print(pos+1)

Measured memory_bytes: 32380
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(std::string AtCoder, std::string s, std::string Contest){
    cout << AtCoder[0] << s[0] << Contest[0] << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string AtCoder;
    std::cin >> AtCoder;
    std::string s;
    std::cin >> s;
    std::string Contest;
    std::cin >> Contest;
    solve(AtCoder, s, Contest);
    return 0;
}


Measured memory_bytes: 256
d = {}
d["a"]=raw_input()
d["b"]=raw_input()
d["c"]=raw_input()

def pop(x):
    if len(d[x]) == 0:
        print x.upper()
        exit()
    n = d[x][0]
    d[x] = d[x][1:]
    pop(n)

pop("a")
        

Measured memory_bytes: 2820
import java.util.*;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    Set<Integer> cnt = new HashSet<>();
    cnt.add(a);
    cnt.add(b);
    cnt.add(c);
    
    System.out.println(cnt.size());
  }
}

Measured memory_bytes: 21076
r, c = map(int, input().split())

d = [0] * (r + 1)

for i in range(r):
    d[i] = list(map(int, input().split()))
    d[i].append(0)
    for j in range(c):
        d[i][c] += d[i][j]

d[r] = [0] * (c + 1)
for i in range(c + 1):
    for j in range(r):
        d[r][i] += d[j][i]

for i in range(r + 1):
    row = ''
    for j in range(c + 1):
        row += str(d[i][j])
        if j <= c - 1:
            row += ' '
    print(row)



Measured memory_bytes: 5696
#include <stdio.h>
#include <ctype.h>

typedef long long ll;

ll H,W;
int board[100][100];
int main(){
        scanf("%lld %lld",&H,&W);
        for(int y = 0; y < H; y++){
                for(int x = 0; x < W; x++){
                        char c;
                        do{scanf("%c",&c);}while(isspace(c));
                        board[x][y]=c;
                }
        }

        for(int y = 0; y < H ; y++){
                int found = 0;
                for(int x = 0; x < W; x++){
                        if(board[x][y] == '#'){ found = 1; break;}
                }
                if(found == 0){
                        for(int x = 0; x < W; x++) board[x][y] = '*';
                }
        }
        for(int x = 0; x < W ; x++){
                int found = 0;
                for(int y = 0; y < H; y++){
                        if(board[x][y] == '#'){ found = 1; break;}
                }
                if(found == 0){
                        for(int y = 0; y < H; y++) board[x][y] = '*';
                }
        }

        for(int y = 0; y < H; y++){
                char needNewLine = 0;
                for(int x = 0; x < W; x++){
                        if(board[x][y] != '*'){
                                needNewLine = 1;
                                printf("%c",board[x][y]);
                        }
                }
                if(needNewLine) puts("");
        }
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())

def gcd(x,y):
   if x % y == 0:
       return y
   return gcd(y, x % y)

CD = (c * d) // gcd(c,d)

h_b =b - (b // c) - (b // d) + (b // CD)
h_a = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // CD

print(h_b - h_a)

Measured memory_bytes: 3060
#include <iostream>
int main(){
    int n,x,y;
    while(true){
        std::cin >> n >> x;
        if(n == 0&&x == 0)break;
        y = 0;
        for(int a = 1;a <= n;a++){
            for(int b = 1;b <= n;b++){
                for(int c = 1;c <= n;c++){
                    if(a + b + c == x){
                        y = y + 1;
                        if(a == b||a == c||b == c||a > b||a > c||b > c||a > n||b > n||c > n){
                            y = y - 1;
                        }
                    }
                }
            }
        }
        std::cout << y << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

// North, west, south, east
int dh[] = {-1, 0, 1, 0};
int dw[] = {0, -1, 0, 1};

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>>g (h, vector<char> (w));
    queue<P> q;
    Graph dist(h, vector<int> (w,1002003004));
    auto push = [&](int vh, int vw, int d){
        if(dist[vh][vw] != 1002003004) return;
        dist[vh][vw] = d;
        q.push({vh,vw});
    };

    rep(i,h){
        rep(j,w){
            cin >> g[i][j];
            if(g[i][j] == '#'){
                push(i,j,0);
            }
        }
    }

    while(!q.empty()){
        P p = q.front(); q.pop();
        int d = dist[p.first][p.second];

        rep(i,4){
            int vh = p.first + dh[i], vw = p.second + dw[i];
            if(vh <= -1 || vh >= h || vw <= -1 || vw >= w) continue;
            if(g[vh][vw] == '#') continue;
            push(vh, vw, d+1);
        }
    }

    int ans = 0;

    rep(i,h) rep(j,w) ans = max(ans,dist[i][j]);

    cout << ans << endl;
}




Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int h,w;
vst a;
ll dp[1100][1100];

int main(){cout<<fixed<<setprecision(10);
           cin>>h>>w;
           a.resize(h);
           rep(i,0,h)cin>>a[i];
           dp[0][0]=1;
           rep(i,0,h){
            rep(j,0,w){
             if(a[i][j]=='#')continue;
             if(j-1>=0)dp[i][j]=dp[i][j-1];
             if(i-1>=0)dp[i][j]+=dp[i-1][j];
              dp[i][j]%=inf;
            }
           }
           cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 14100
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <set>
const int inf=2147483647;
const int mo=924844033; 
const int N=4005;
using namespace std;
int n,m,tot;
bool lk[N];
long long f[N][N][2],jc[N],ans;
int main(){
    scanf("%d%d",&n,&m);
    jc[0]=1;
    for(int i=1;i<=n;i++) jc[i]=1ll*jc[i-1]*i%mo;
    for(int i=1;i<=m;i++)
        for(int t=2;t--;)
            for(int j=i;j<=n;j+=m){
                tot++;
                if(j!=i) lk[tot]=1;
            }
    f[0][0][0]=1;
    for(int i=0;i<n*2;i++)
        for(int j=0;j<=n;j++){
            f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%mo;
            if(lk[i+1]) f[i+1][j+1][1]=f[i][j][0];
        }
    for(int i=0,t=1;i<=n;i++,t=-t){
        f[2*n][i][0]=1ll*(f[2*n][i][0]+f[2*n][i][1])*jc[n-i]%mo;
        ans=(ans+f[2*n][i][0]*t+mo)%mo;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 249472
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int a[1001][1001][3];

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

    int h, w, K;
    cin >> h >> w >> K;
    const string joi="JOI";
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            a[i][j][joi.find(s[j])]++;
        }
    }

    rep(i, h) rrep(j, w) rep(k, 3) a[i][j][k] += a[i][j + 1][k];
    rep(j, w) rrep(i, h) rep(k, 3) a[i][j][k] += a[i + 1][j][k];
    auto getSum = [&](int r1, int c1, int r2, int c2, int k) {
        return a[r1][c1][k] - a[r2][c1][k] - a[r1][c2][k] + a[r2][c2][k];
    };

    rep(i, K) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        r1--; c1--;
        rep(k, 3) {
            cout << (k == 0 ? "" : " ") << getSum(r1, c1, r2, c2, k);
        }
        cout << endl;
    }
}

Measured memory_bytes: 26416
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,m,l; cin>>n>>m>>l;
    vector<vector<ll>> d(n,vector<ll>(n,INF));
    rep(i,n) d[i][i]=0;
    rep(i,m){
        ll a,b,c; cin>>a>>b>>c;
        a--; b--;
        d[a][b]=c; d[b][a]=c;
    }
    rep(k,n)rep(i,n)rep(j,n){
        if(d[i][j]>d[i][k]+d[k][j])
        d[i][j]=d[i][k]+d[k][j];
    }
    vector<vector<ll>> d2(n,vector<ll>(n,INF));
    rep(i,n) d[i][i]=0;
    rep(i,n)rep(j,n){
        if(d[i][j]<=l)
        d2[i][j]=1;
    }
    rep(k,n)rep(i,n)rep(j,n){
        if(d2[i][j]>d2[i][k]+d2[k][j])
        d2[i][j]=d2[i][k]+d2[k][j];
    }
    ll q; cin>>q;
    rep(i,q){
        ll s,t; cin>>s>>t;
        s--; t--;
        if(d2[s][t]!=INF) printf("%lld\n",d2[s][t]-1);
        else printf("-1\n");
    }
}

Measured memory_bytes: 1920
// ABを買うか買わないか -> 駄目
// ABだけを買って分解する -> これが想定解らしい...
package main

import "fmt"

func main() {
	var A, B, C, X, Y int
	fmt.Scan(&A, &B, &C, &X, &Y)
	ans := int(1e18)
	for i := 0; i <= int(1e5); i++ {
		x, y := 0, 0
		if i < X {
			x = X - i
		}
		if i < Y {
			y = Y - i
		}
		ans = min(ans, 2*i*C+x*A+y*B)
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 512
n=int(input())
s=[input() for _ in range(n)]
from collections import Counter
c=Counter(s)
l=c.most_common()
a=[l[0][0]]
for i in range(1,len(l)):
  if l[i][1]==l[0][1]:
    a.append(l[i][0])
  else:
    break
a.sort()
for j in range(len(a)):
  print(a[j])


Measured memory_bytes: 50296
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
int N, Q;
int main() {
	scanf("%d", &N);
	vector<int> L(N * 2);
	rep(i, 0, N * 2)scanf("%d", &L[i]);
	sort(L.begin(), L.end());
	int c = 0;
	rep(i, 0, N)c += L[i * 2];
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n, c[8][8]; map<vector<char>, int> m;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &c[i][j]);
		}
	}
	vector<char> s; for (int i = 0; i < n; i++) s.push_back((char)(i));
	priority_queue<pair<int, vector<char> > > que; que.push(make_pair(-1, s));
	int ret = 0;
	while (!que.empty()) {
		pair<int, vector<char> > state = que.top(); que.pop();
		vector<char> v = state.second;
		if (m[v] != 0) continue;
		m[v] = state.first;
		ret = -state.first - 1;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				swap(v[i], v[j]);
				que.push(make_pair(state.first - c[i][j], v));
				swap(v[i], v[j]);
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}
/*
前半の数列の候補は2nまで、後半の数列の候補はnから3nまで
*/
priority_queue<int> maxpq;
priority_queue<int,vector<int>,greater<int> > minpq;

int n;
int a[300001];

ll fsum[100001] = {0};
ll bsum[100001] = {0};

int main(){
  scanf("%d",&n);
  REP(i,3*n){
    scanf("%d",&a[i]);
  }
  REP(i,n){
    minpq.push(a[i]);
    fsum[0] += a[i];
    maxpq.push(a[3*n-1-i]);
    bsum[n] += a[3*n-1-i];
  }
  FOR(k,1,n+1){
    minpq.push(a[n+k-1]);
    fsum[k] = fsum[k-1]+a[n+k-1]-minpq.top();
    minpq.pop();
    maxpq.push(a[2*n-k]);
    bsum[n-k] = bsum[n-k+1]+a[2*n-k]-maxpq.top();
    maxpq.pop();
  }
  ll mx = fsum[0]-bsum[0];
  REP(i,n+1){
    mx = max(mx,fsum[i]-bsum[i]);
  }
  printf("%lld\n",mx);


}


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

int f(int n) {
	if (n % 2 == 0)
		return n / 2;
	else
		return 3 * n + 1;
}

int main() {
	int s;
	cin >> s;
	vector<int> a(10e6);
	a[0] = s;
	for (int i = 1; ; i++) {
		a[i] = f(a[i - 1]);
		for (int j = 0; j < i; j++) {
			if (a[i] == a[j]) {
				cout << i + 1 << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 39296
w = gets.to_i
arr = Array.new(w)
0.upto(arr.size-1) do |i|
    arr[i] = i+1
end
gets.to_i.times do
    a, b = gets.split(",").map(&:to_i)
    a -= 1; b -= 1
    arr[a], arr[b] = arr[b], arr[a]
end
puts arr

Measured memory_bytes: 8484
#include <stdio.h>

int main(void){
	
	int n[10000],i;
	
	i=0;
	n[i]=1;
	for(;n[i]!=0;){
		i++;
		scanf("%d",&n[i]);
	}
	
	for(i=1;n[i]!=0;i++){
		printf("Case %d: %d\n",i,n[i]);
	}
	return 0;
}

Measured memory_bytes: 1064
#!/usr/bin/env php
<?php
const YES = "Yes";
const NO = "No";

function getInputs() {
    while(($input = fgets(STDIN)) !== false) {
        foreach (explode(' ', $input) as $v) {
            yield $v;
        }
    }
}

$gen = getInputs();
$N = $gen->current(); $gen->next();
    $pre_x = 0;
    $pre_y = 0;
    $pre_t = 0;
    while ($gen->valid()) {
        $time = $gen->current(); $gen->next();
        $cur_x = $gen->current(); $gen->next();
        $cur_y = $gen->current(); $gen->next();
        $move_t = $time - $pre_t;
        $move_s = abs($cur_x - $pre_x) + abs($cur_y - $pre_y);
        if ($move_s > $move_t) {
            echo NO.PHP_EOL;
            return;
        }
        if (($move_s % 2) != ($move_t % 2)) {
            echo NO.PHP_EOL;
            return;
        }

        $pre_x = $cur_x;
        $pre_y = $cur_y;
        $pre_t = $time;
    }
    echo YES.PHP_EOL;


Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  int N,M;
  string A[55], B[55];
  cin>>N>>M;
  REP(i,0,N) cin>>A[i];
  REP(i,0,M) cin>>B[i];

  bool flag = false;

  REP(i,0,N){
    REP(j,0,N){
      if(N-i < M || N-j < M) continue;
      int cnt = 0;
      REP(k,0,M){
        REP(l,0,M){
          if(A[i+k][j+l] == B[k][l]) cnt++;
        }
      }
      if(cnt == M*M) flag = true;
    }
  }

  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
ll K;
int A[212345], F[212345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", A + i);
	REP(i, N) scanf("%d", F + i);
	
	sort(A, A + N);
	sort(F, F + N, greater<int>());
	
	ll l = -1, r = longINF;
	while (r - l > 1) {
		ll m = (l + r) / 2;
		ll cur = 0;
		REP(i, N) {
			ll mi = m / F[i];
			if (A[i] > mi) cur += A[i] - mi;
		}
		if (cur <= K) r = m;
		else l = m;
	}
	
	cout << r << endl;
	
	return 0;
}


Measured memory_bytes: 1792