akhauriyash/Code-Regression huggingface dataset:
// CGL_2_D.cpp
//
#include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-10;
bool EQ(double a, double b){return fabs(a-b) < EPS;}
typedef complex<double> Point;
#define X real()
#define Y imag()

struct Segment {
  Point p1, p2;
  Segment(){};
  Segment(Point p1, Point p2) : p1(p1), p2(p2) {};
};
typedef Segment Line;
double dot(Point a, Point b){return real(conj(a) * b);}
double cross(Point a, Point b){return imag(conj(a) * b);}

Point project(Segment s, Point p) {
  double r = dot(p - s.p1, s.p2 - s.p1) / norm(s.p2 - s.p1);
  return s.p1 + (s.p2 - s.p1) * r;
}

bool isParallel(Line l1, Line l2) {
  return EQ(cross(l1.p1 - l1.p2, l2.p1 - l2.p2), 0.0);
}

const int COUNTER_CLOCKWISE = +1;
const int CLOCKWISE = -1;
const int ONLINE_BACK = +2;
const int ONLINE_FRONT = -2;
const int ON_SEGMENT = 0;
int ccw(Point a, Point b, Point c) {
  Point x = b - a;
  Point y = c - a;
  if(cross(x, y) > EPS) return COUNTER_CLOCKWISE;
  if(cross(x, y) < -EPS) return CLOCKWISE;
  if(dot(x, y) < -EPS) return ONLINE_BACK;
  if(norm(x) < norm(y)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersectSS(Segment s1, Segment s2) {
  return ccw(s1.p1, s1.p2, s2.p1) * ccw(s1.p1, s1.p2, s2.p2) <= 0 &&
    ccw(s2.p1, s2.p2, s1.p1) * ccw(s2.p1, s2.p2, s1.p2) <= 0;
}

double distancePP(Point a, Point b) {
  return abs(a - b);
}

double distanceLP(Line l, Point p) {
  return distancePP(p, project(l, p));
}

double distanceSP(Segment s, Point p) {
  if(dot(s.p2 - s.p1, p - s.p1) < -EPS) return distancePP(p, s.p1);
  if(dot(s.p1 - s.p2, p - s.p2) < -EPS) return distancePP(p, s.p2);
  return distanceLP(s, p);
}

double distanceSS(Segment s1, Segment s2) {
  if(intersectSS(s1, s2)) return 0.0;
  return min(min(distanceSP(s1, s2.p1), distanceSP(s1, s2.p2)),
             min(distanceSP(s2, s1.p1), distanceSP(s2, s1.p2)));
}

int main() {
  int q;
  cin>>q;
  int a,b,c,d,e,f,g,h;
  for(int i=0;i<q;++i){
    cin>>a>>b>>c>>d>>e>>f>>g>>h;
    Line s1(Point(a,b), Point(c,d));
    Line s2(Point(e,f), Point(g,h));
    printf("%.10f\n", distanceSS(s1,s2));
  }

  return 0;
}



Measured memory_bytes: 3292
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int A, B;
	cin >> A >> B;
	if (A <= 9 && B <= 9) cout << A * B << endl;
	else cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
K=int(input())
As=sorted(set(s))
ans=[]
for A in As:
    ans.append(A)
    if len(ans)>=K:break
    for j in range(2,K+1):
        ind=0
        for i in s:
            if i==A:
                Judge=s[ind:ind+j]
                if len(Judge)==j and (Judge not in ans):
                    ans.append(Judge)
            ind+=1
print(sorted(ans)[K-1])


Measured memory_bytes: 3060
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 1;
  char cur = S.at(0);
  for(int i = 1;i < S.size();i++){
    if(S.at(i) != cur){
      ans++;
      cur = S.at(i);
    }else{
      continue;
    }
  }
  cout << ans << endl;




  return 0;
}


Measured memory_bytes: 3708
#include <stdio.h>

int main(void) {
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  b -= a, c -= a;
  if((c <= d && c >= -d) || (b <= d && b >= -d && c - b <= d && c - b >= -d)) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int P,Q,R;
  cin >> P >> Q >> R;
  cout <<  min(P+Q,min(Q+R,P+R)) << endl;
  return 0;
}

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

int main(){
	char a[11];
	int len;
	scanf("%s",a);
	len=strlen(a);
	if(len==1||len%2!=0)
		printf("No");
	else{
	
		int i;
		int flat=0;
		for(i=0;i<len;i++){
			
			if(i==0||i%2==0)
				{
					if(a[i]!='h'){
					
						flat=1;
						break;	 }
				}
			else{
				if(a[i]!='i')
				{
					flat=1;
					break;
				}
			}
		}
		if(flat==0)
			printf("Yes");
		else
			printf("No");
	}
	
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAX_N = 200005;

int n;
ll k;
ll a[MAX_N];

bool check(ll x)
{
	if (x == 0)
		return false;
	ll cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] % x == 0)
			cnt += a[i] / x - 1LL;
		else
			cnt += a[i] / x;
	}
	return cnt <= k;
}

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

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	ll l = 0, r = 1000000005;
	while (r - l > 1)
	{
		ll mid = (l + r) / 2;
		if (check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	if (!check(l))
		l = r;
	cout << l << '\n';

	return 0;
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define inf (long long)1e10
using namespace std;

string s;
long long idx, n;

char solve();
long long parse(long long &id);
string parsestring(long long &id);
char calc(long long &id);

int main() {
  while(1) {
    cin >> s >> idx;
    if(s == "0" && idx == 0) break;
    cout << solve() << endl;
  }
  return 0;
}

char solve() {
  n = s.size();
  long long id = 0;
  while(id < n) {
    long long nowsize, nowid = id;
    nowsize = parse(id);
    if(nowsize > idx)
      return calc(nowid);
    else
      idx -= nowsize;
  }
  return '0';
}

long long parse(long long &id) {
  long long now = 0, res = 0;
  while(isdigit(s[id])) {
    now *= 10;
    now += s[id++] - '0';
  }
  if(now == 0) now = 1;
  if(s[id] >= 'A' && s[id] <= 'Z')
    return now * parsestring(id).size();
  assert(s[id] == '(');
  ++id;
  while(s[id] != ')') res = min(now * parse(id) + res, inf);
  assert(s[id] == ')');
  ++id;
  return res;
}

string parsestring(long long &id) {
  string res;
  while(id < n && s[id] >= 'A' && s[id] <= 'Z')
    res += s[id++];
  return res;
}

char calc(long long &id) {
  while(isdigit(s[id])) ++id;
  if(s[id] >= 'A' && s[id] <= 'Z') {
    string nows = parsestring(id);
    return nows[idx % nows.size()];
  }
  vector<long long> len, idv;
  long long sum = 0;
  assert(s[id] == '(');
  ++id;
  while(s[id] != ')') {
    idv.push_back(id);
    len.push_back(sum + parse(id));
    sum = len.back();
  }
  assert(s[id] == ')');
  idx %= sum;
  long long nextid =
      upper_bound(len.begin(), len.end(), idx) -
      len.begin();
  if(nextid != 0) idx -= len[nextid - 1];
  return calc(idv[nextid]);
}


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n, k; cin>>n>>k;
    cout<<n-k+1<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
ans=0
dic={}
for i in range(1,n+1):
    s=str(i)
    d=(s[0],s[-1])
    if d not in dic.keys():
        dic[d] = 1
    else:
        dic[d] += 1
 
for a in dic.keys():
    b = (a[1],a[0])
    if b in dic.keys():
        ans += dic[a]*dic[(a[1],a[0])]
 
print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
 
public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    int N = sc.nextInt();
    long[] count = new long[2];
    for (int i = 0; i < N; ++i) {
      int T = sc.nextInt();
      int A = sc.nextInt();
 
      if (i == 0) {
        count[0] = T;
        count[1] = A;
        continue;
      }
 
      long n = Math.max((count[0] + T - 1) / T, (count[1] + A - 1) / A);
      count[0] = T * n;
      count[1] = A * n;
    }
 
    out.println((count[0] + count[1]));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define int long long
#define ll long long
using namespace std;
signed main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,s.size()){
        if(s.at(i)!=t.at(i)){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;
    int c=0;
    c+=((n/500)*1000);
    n=n%500;
    c+=((n/5)*5);
    cout<<c;

    return 0;
}


Measured memory_bytes: 3648
def main():
    n = int(input())
    soma = soma_digitos(n)
    if n % soma == 0:
        print('Yes')
    else:
        print('No')
def soma_digitos(n):
    soma = 0
    while n >= 1:
        soma += n%10
        n = n//10
    return soma
main()

Measured memory_bytes: 2940
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}


*/
typedef long long ll;
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}


int main() {
    // 入力
    ll N, K;
    cin >> N >> K;
    ll A[N];
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    ll minA=A[0];
    for (int i = 0; i < N; ++i){
        if (A[i]<minA) minA = A[i];
    }
    //cout <<"min A " << minA << endl;
    
    ll count_not_min_A = 0;
    
    for (int i = 0; i < N; ++i){
        if (A[i]!=minA) ++count_not_min_A;
    }
    //cout << "not min A " << count_not_min_A << endl;
    
    float ans;
    ans = float(count_not_min_A) / (K - 1);
    if (int(ans)<ans) ans = int(ans)+1;
    cout << ans << endl;
    //cout << int(ans) << endl;
}
 


Measured memory_bytes: 1024
#include <iostream>
#include <ostream>
#include <istream>
#include <cmath>
#include <string>
#include <vector>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <vector>
#include <set>
#define pb push_back
#define ppb pop_back
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"
#define pi 3.1415926535897932
#define NMAX 100005
#define INF 1000000007
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
int K,dist[100000];
deque<int> todo;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>K;
	for(int i=0; i<K; i++)dist[i]=INF;
	dist[1]=1;
	todo.pb(1);
	while(todo.size()) {
		int x=todo.front();
		todo.pop_front();
		if(dist[(10*x)%K]>dist[x]) {
			dist[(10*x)%K]=dist[x];
			todo.push_front((10*x)%K) ;
		}
		if(dist[(x+1)%K]>dist[x]+1) {
			dist[(x+1)%K]=dist[x]+1;
			todo.push_back((x+1)%K);
		}
	}
	cout<<dist[0];
	return 0;
}



Measured memory_bytes: 896
N = int(input())
p = list(map(int, input().split()))

sorted_p = sorted(p)

# tmp = p[0]
# tmp_index = 0

# for i in range(N):
#     for j in range(N-i-1):
#         if j == 0:
#             continue
#         else:
#             if p[i] > p[i+j]:
#                 tmp = p[i]
#                 p[i] = p[i+j]
#                 p[i+j] = tmp
#
#                 count = True
#
#     # if count:
#     #     break


count = 0
for b in range(N):
    if not(p[b] == sorted_p[b]):
        t_index = p.index(sorted_p[b])

        tmp = p[b]
        p[b] = p[t_index]
        p[t_index] = tmp

        count += 1

# print(p)
# print(sorted_p)

if count < 2:
    print("YES")
else:
    print("NO")



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

using namespace std;

typedef long long ll;

int main(){
  int a, b, x;
  double z = 0.0;
  cin >> a >> b >> x;
  if (a*a*b/2.0 >= x){
    z = 2.0*x/(a*b);
    cout << setprecision(12) << atan(b/z)*(180/acos(-1)) << endl;
  }
  else{
    z = 2.0*x/(a*a)-b;
    cout << setprecision(11) << atan((b-z)/a)*(180/acos(-1)) << endl;
  }
  return 0;
}



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

MOD = 10**9 + 7

def CombMod(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p*(n-i)%MOD
        q = q*(i+1)%MOD
    return p * pow(q, MOD-2, MOD)%MOD

print((pow(2, n, MOD) - 1 - (CombMod(n, a) + CombMod(n, b)))%MOD)

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

vector<char> firstpart(vector<char> V) {
  int n,m;
  n = V.size();
  m = (n - 1)/2;
  vector<char> W(m);
  rep(i,m) {
    W.at(i) = V.at(i);
  }
  return W;
}

int main(){ 
  string S;
  cin >> S;
  
  int n,m;
  n = S.size();
  m = (n - 1)/2;
  
  vector<char> T(n),U(n),T_1(m),T_2(m),U_1(m),U_2(m);
  rep(i,n) {
    T.at(i) = S.at(i);
    U.at(i) = S.at(i);
  }
  
  reverse(U.begin(), U.end());
  
  bool answer = false;
  
  T_1 = firstpart(T);
  T_2 = T_1;
  reverse(T_2.begin(), T_2.end());
  
  U_1 = firstpart(U);
  U_2 = U_1;
  reverse(U_2.begin(), U_2.end());
  
  if (T == U && T_1 == T_2 && U_1 == U_2) answer = true;
  
  if (answer) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long money = 100;
        long count = 0;
        
        while(money < X) {
        	double doubleMoney;
        	doubleMoney = money * 1.01;
        	money = (long) doubleMoney;
        	count++;
        }
        
        System.out.println(count);

        

        
        }
	}



Measured memory_bytes: 35728
//============================================================================
// Name        : ku.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<iostream>
using namespace std;
int main(){
	int S,s,m,h;
	cin>>S;
	h=S/3600;
	S=S-h*3600;
	m=S/60;
	S=S-m*60;
	s=S;
	cout<<h<<":"<<m<<":"<<s<<endl;
	return 0;

}

Measured memory_bytes: 1168
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(long long i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int N = 50;

int main() {
    ll k;
    cin >> k;

    vector<ll> ans(N);
    rep(i, N) {
        ans[i] = k/N + N -1;
    }

    rep(i, k%N) {
        ans[i] += N;
        rep(j, N) {
            if(i != j) {
                ans[j]--;
            }
        }
    }

    cout << N << "\n";
    rep(i, N) {
        cout << ans[i] << " ";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
S = input()
if S[:N // 2] == S[N // 2:]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
 
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,q,a,b,c,cnt,i,p,r,ret;
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
   
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
   
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(L i, L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
 
main(){
    cin >> n >> k;
    for(i=0; i<n-1; i++){
        cin >> a >> b >> c;
        path[a][b]=path[b][a]=c;
    }
    dfs(0);
   
    for(i=0; i<n; i++){
        if(i && hev[par[i]]==i) continue;
        L j=i;
        do{
            pos[j]=cnt++;
            hl_par[j]=i;
        }while(j=hev[j]);
    }
    
    for(i=0; i<n; i++)
        S(pos[i],hev[i]);
    
    cin >> q;
    for(i=0; i<q; i++){
        string s;
        cin>>s>>a>>b;
        if(s[0]=='a'){
            add[a]+=b;
            S(pos[a],hev[a]);
            if(a)S(pos[a]-1,a);
        }else{
            for(ret=0;p=hl_par[a],r=hl_par[b],p-r;a=par[p])
                dep[p]<dep[r]?swap(p,r),swap(a,b),0:0,
                ret+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<ret+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }
    }
}

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

int main() {
	int a=INT_MAX,b=INT_MIN,n,T,cas=0,x;
	cin>>n;
	for(int i=0;i<n;++i) {
		cin>>x;
		a = min(a, x);
		b = max(b, x);
	}
	cout<<b-a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll f(ll x, ll y, ll z){
    return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main(){
    map<ll,ll> ret;
    ll N=ii();
    REP(x,1,N+2){
        REP(y,1,N+2){
            REP(z,1,N+2){
                ll a=f(x,y,z);
                ret[a]++;
                if(a>N){
                    break;
                }
            }
            ll aa=f(x,y,1);
            if(aa>N){
                break;
            }
        }
        ll aaa=f(x,1,1);
        if(aaa>N){
            break;
        }
    }
    REP(i,1,N+1){
        oie(ret[i]);
    }
    return 0;
}

Measured memory_bytes: 4232
#include<stdio.h>
#define STRMAX 11
int defstr(char *str1, char *str2);

int main(int argc, char **argv)
{
	char s[STRMAX];
	char t[STRMAX];
	char u[STRMAX];
	int a, b;

	scanf("%s %s", s, t);
	scanf("%d %d", &a, &b);
	scanf("%s", u);
	if (defstr(s, u))
	{
		a--;
	} else
	{
		b--;
	}

	printf("%d %d", a, b);

	return 0;
}

int defstr(char *str1, char *str2)
{
	int i;
	for (i = 0; str1[i] && str2[i]; ++i)
	{
		if (str1[i] != str2[i])
		{
			return 0;
		}
	}
	return 1;
}


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

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	string s;
	cin >> s;
	int n_passed = 0;
	int n_overseas = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == 'a') {
			if (n_passed < A + B) {
				n_passed++;
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
		} else if (s[i] == 'b') {
			if (n_passed < A + B && n_overseas < B) {
				n_overseas++;
				n_passed++;
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
		} else {	
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        
        int cy = Integer.parseInt(sc.next())-1;
        int cx = Integer.parseInt(sc.next())-1;
        int dy = Integer.parseInt(sc.next())-1;
        int dx = Integer.parseInt(sc.next())-1;
        
        boolean[][] grd = new boolean[h][w];
        
        for(int i=0; i<h; i++){
            String line = sc.next();
            for(int j=0; j<w; j++){
                char c = line.charAt(j);
                if(c=='#'){
                    grd[i][j] = true;
                }
            }
        }
        
        int[][] memo = new int[h][w];
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                memo[i][j] = (int)1e9;
            }
        }
        memo[cy][cx] = 0;
        
        ArrayDeque<Integer> q = new ArrayDeque<>();
        q.addFirst(cy*w + cx);
        while(q.size() != 0){
            int tmp = q.pollFirst();
            int y = tmp/w;
            int x = tmp%w;
            int[] d = {0,1,0,-1};
            for(int i=0; i<4; i++){
                int ny = y+d[i^1];
                int nx = x+d[i];
                if(0<=nx && nx<w && 0<=ny && ny<h){
                    if(!grd[ny][nx]){
                        if(memo[ny][nx] > memo[y][x]){
                            memo[ny][nx] = memo[y][x];
                            q.addFirst(ny*w + nx);
                        }
                    }
                }
            }
            for(int ny=Math.max(0, y-2); ny<=Math.min(h-1, y+2); ny++){
                for(int nx=Math.max(0, x-2); nx<=Math.min(w-1, x+2); nx++){
                    if(!grd[ny][nx]){
                        if(memo[ny][nx] > memo[y][x]+1){
                            memo[ny][nx] = memo[y][x]+1;
                            q.addLast(ny*w + nx);
                        }
                    }
                }
            }
        }
        
        if(memo[dy][dx] != (int)1e9){
            System.out.println(memo[dy][dx]);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 62352
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		vector<pair<int,pair<int,int> > >v;
		pair<int,pair<int,int> >p;
		long long a[20001]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>p.first>>p.second.first>>p.second.second;
			v.push_back(p);
		}
		sort(v.begin(),v.end());
		r(i,m)if(a[v[i].second.first])a[v[i].second.second]=1;
		r(i,n+1)if(a[i])s++;
		cout<<s<<endl;
	}
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        if(A > K) {
            System.out.println(K);
            return;
        }


        if(A == K) {
            System.out.println(A);
            return;
        }

        if(A + B == K) {
            System.out.println(A);
            return;
        }
        int ans = K - (A+B);
        System.out.println( A - ans );
    }
}


Measured memory_bytes: 35704
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()

typedef pair<int,int>pii;
typedef vector<int> vi;
typedef vector<vi> vii;
const int mxN=305,M=1e9+7;
//did u check when n=1?
//is mxN correct?
double dp[305][305][305],ans[mxN][mxN][mxN];
vi v(4);
int n;
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        v[x]++;
    }
    dp[v[1]][v[2]][v[3]]=1;
    for(int c=n;c>=0;c--){
        for(int b=n;b>=0;b--){
            for(int a=n;a>=0;a--){
                if(a==0 && b==0 && c==0)continue;
                if(a+b+c>n)continue;
                double waste=(double)(n-(a+b+c))/(double)n;
                double twaste=waste/(1-waste) +1;
                ans[a][b][c]+=twaste*dp[a][b][c];
                if(a!=0){
                    dp[a-1][b][c]+=dp[a][b][c]*(double)(a)/(double)(a+b+c);
                    ans[a-1][b][c]+=ans[a][b][c]*(double)(a)/(double)(a+b+c);
                }
                if(b!=0){
                    dp[a+1][b-1][c]+=dp[a][b][c]*(double)(b)/(double)(a+b+c);
                    ans[a+1][b-1][c]+=ans[a][b][c]*(double)(b)/(double)(a+b+c);
                }
                if(c!=0){
                    dp[a][b+1][c-1]+=dp[a][b][c]*(double)(c)/(double)(a+b+c);
                    ans[a][b+1][c-1]+=ans[a][b][c]*(double)(c)/(double)(a+b+c);
                }
            }
        }
    }   
    /*    for(int c=n;c>=0;c--){
        for(int b=n;b>=0;b--){
            for(int a=n;a>=0;a--){
               cout<<a<<" "<<b<<" "<<c<<" "<<dp[a][b][c]<<"\n";
            }
        }
    }*/
    cout<<fixed<<setprecision(10)<<ans[0][0][0];
}

Measured memory_bytes: 438528
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

typedef double Real;

const Real eps=1e-8;

int N;
int xs[5],ys[5];

Real getLen(Real h){
	vector<Real> vals;
	for(int i=0;i<N;i++){
		int x1=xs[i],y1=ys[i];
		int x2=xs[i+1],y2=ys[i+1];
		if(y1==y2) continue;
		if(y1>y2){
			swap(y1,y2);
			swap(x1,x2);
		}
		if(h<y1||y2<h) continue;
		Real r=(Real)(h-y1)/(y2-y1);
		Real x=x1+(Real)(x2-x1)*r;
		vals.push_back(x);
	}
	sort(vals.begin(),vals.end());
	Real res=0;
	for(int i=0;i+1<vals.size();i+=2){
		res+=vals[i+1]-vals[i];
	}
//	printf("h=%f,res=%f\n",h,res);
	return res;
}

vector<Real> hs;

Real solve(){
	Real ans=0;
	for(int i=0;i<N;i++){
		hs.push_back(ys[i]+eps);
		hs.push_back(ys[i]-eps);
	}
	sort(hs.begin(),hs.end());
	vector<int> same_y;
	for(int i=0;i<N;i++){
		if(ys[i]==ys[i+1]){
			same_y.push_back(ys[i]);
			continue;
/*			Real len1=getLen(ys[i]-eps);
			Real len2=getLen(ys[i]+eps);
//			printf("+=(%f,%f)->%f\n",len1,len2,abs(len1*len1-len2*len2));
			ans+=abs(len1*len1-len2*len2);*/
		}else{
			int x1=xs[i],y1=ys[i];
			int x2=xs[i+1],y2=ys[i+1];
			if(y1>y2){
				swap(y1,y2);
				swap(x1,x2);
			}
			Real h=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
			for(int j=0;j+1<hs.size();j++){
				Real lo=hs[j],hi=hs[j+1];
				if(lo<y1||y2<hi) continue;
				Real len1=getLen(lo);
				Real len2=getLen(hi);
				Real cur_h=h*(hi-lo)/(y2-y1);
				ans+=(len1+len2)*cur_h;
			}
		}
	}
	sort(same_y.begin(),same_y.end());
	same_y.erase(unique(same_y.begin(),same_y.end()),same_y.end());
	for(int i=0;i<same_y.size();i++){
		int y=same_y[i];
		Real len1=getLen(y-eps);
		Real len2=getLen(y+eps);
		ans+=abs(len1*len1-len2*len2);
	}
	return ans;
}

int main(){
	while(true){
		scanf("%d",&N);
		if(N==0) break;
		for(int i=0;i<N;i++) scanf("%d%d",xs+i,ys+i);
		xs[N]=xs[0],ys[N]=ys[0];
		Real ans=solve();
		printf("%f\n",ans);
	}
	return 0;
}

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

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private int w,n;
	private Integer[] ans;


	private void mainrun() {
		scan = new Scanner(System.in);

		w = Integer.parseInt(scan.nextLine());
		n = Integer.parseInt(scan.nextLine());

		ans = new Integer[w];

		for(int i = 0;i < w;i++) {
			ans[i] = i + 1;
		}

		for(int i = 0;i < n;i++) {
			looprun();
		}

		Arrays.asList(ans).forEach(System.out::println);

		scan.close();
	}

	private void looprun() {
		String[] str = scan.nextLine().split(",");

		int a = Integer.parseInt(str[0]) - 1;
		int b = Integer.parseInt(str[1]) - 1;

		int tmp = ans[a];
		ans[a] = ans[b];
		ans[b] = tmp;

	}
}


Measured memory_bytes: 32028
#include<cstdio>
//lack of practice
const long long mod = 998244353;
long long f[305][90005];
int a[305];

int main(){
	int n;
	scanf("%d",&n);
	int sum = 0;
	long long ans = 1;
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		sum += a[i];
		ans = ans*3ll%mod;
	}
	f[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= sum; j++){
			f[i][j] = f[i-1][j]*2ll%mod;
			if(j-a[i]>=0) f[i][j] = (f[i][j]+f[i-1][j-a[i]])%mod;
		}
	}
	int middle = (sum+1)/2;
	for(int i = middle; i <= sum; i++){
		ans -= (3ll*f[n][i]%mod);
		if(ans<0) ans += mod;
	}
	if(sum%2==0){
		f[0][0] = 1;
		for(int i = 1; i <= n; i++){
			for(int j = 0; j <= sum; j++){
				f[i][j] = f[i-1][j];
				if(j-a[i]>=0) f[i][j] = (f[i][j]+f[i-1][j-a[i]])%mod;
			}
		}
		//printf("%lld\n",f[n][sum/2]);
		ans += (3ll*f[n][sum/2]%mod);
		if(ans>=mod) ans -= mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 212480
#!/mnt/c/Users/moiki/bash/env/bin/python
s = int(input())

from collections import defaultdict
d = defaultdict(int)

num = 1
while True:
    # print("s: {}, num: {}, d.keys(): {} ".format(s,num, list(d.keys())))

    if s in d.keys():
        print(num)
        exit(0)
    d[s] += 1



    if s % 2 == 0:
        s //= 2 
    else:
        s = s*3 + 1

    num += 1




Measured memory_bytes: 3316
H, N = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
for i in range(len(A)):
  if H > 0:
    H -= A[len(A)-1-i]
  else:
    print("Yes")
    exit()
if H > 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 13964
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;
int H,W;
int sx,sy,gx,gy;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int visited[210][210] = {};
char F[210][210];

bool in(int x,int y){
    return 1<=x && x<=H && 1<=y && y<=W;
}

int main(){
    cin >> H >> W;
    queue<PP> Q;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> F[i][j];
            if(F[i][j]=='@'){
                sx = i; sy = j;
            }else if(F[i][j]=='%'){
                gx = i; gy = j;
            }else if(F[i][j]=='$'){
                visited[i][j] = -1;
                Q.push({{i,j},-1});
            }
        }
    }
    Q.push({{sx,sy},1});
    while(!Q.empty()){
        PP pp = Q.front(); Q.pop();
        int x = pp.first.first,y = pp.first.second;
        for(int i=0;i<4;i++){
            int nx = x+dx[i],ny = y+dy[i];
            if(!in(nx,ny) || visited[nx][ny]!=0 || F[nx][ny]=='#') continue;
            visited[nx][ny] = pp.second;
            Q.push({{nx,ny},pp.second});
        }
    }
    cout << (visited[gx][gy]==1? "Yes":"No") << endl;
}




Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
int main(){ 
  int n, m;
  cin >> n >> m; 
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<char> d(n, 'a');
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (d[s] != 'a' && d[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    d[s] = c;
  }
  string res = "";
  for (int i = 0; i < n; i++) {
    char c = d[i];
    if (c == 'a') {
      if (i == 0) {
        res += '1';
      } else res += '0';
    } else res += c;
  }
  if (n > 1 && res[0] == '0') cout << -1 << endl;
  else cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  if(c>= b-1)
  {
    cout << ((a*(b-1))/b) <<endl;
  }
  else
  {
    cout << ((a*c)/b) <<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();

    ll n,k;
    cin>>n>>k;
    ll w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][k+1]={0};
    for(int i=0;i<=k;i++)
    {
        dp[0][i]=0;
        dp[i%(n+1)][0]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(j-w[i]>=0)
            {
                dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    
    cout<<dp[n][k]<<endl;
    
}

Measured memory_bytes: 79104
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



class UnionFind{
	vector<int> par;
	vector<int> rank;
public:
	UnionFind(int n):par(n),rank(n){
		init(n);
	}
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(rank[x]<rank[y]){
			par[x]=y;
		}else{
			par[y]=x;
			if(rank[x]==rank[y])rank[x]++;
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
};



struct Edge{
	int s,t;
	int cost;
	bool operator<(const Edge &e)const{return cost<e.cost;}
};



int mst(const vector<Edge> &edges,int v,vector<int> &used){
	int res=0;
	UnionFind uf(v);
	rep(i,edges.size()){
		const Edge &e=edges[i];
		if(!uf.same(e.s,e.t)){
			uf.unite(e.s,e.t);
			res+=e.cost;
			used.push_back(i);
		}
	}
	return res;
}


int mst(const vector<Edge> &edges,int v,int unuse){
	int res=0;
	UnionFind uf(v);
	rep(i,edges.size()){
		if(i==unuse)continue;
		const Edge &e=edges[i];
		if(!uf.same(e.s,e.t)){
			uf.unite(e.s,e.t);
			res+=e.cost;
		}
	}
	rep(i,v)if(!uf.same(0,i))return -1;
	return res;
}



int main(){
	int n,m;
	vector<Edge> edges;
	vector<int> maybealter;
	cin>>n>>m;
	rep(i,m){
		Edge e;
		cin>>e.s>>e.t>>e.cost;
		e.s--;e.t--;
		edges.push_back(e);
	}
	sort(edges.begin(),edges.end());
	int mincost=mst(edges,n,maybealter);
	int cnt=0;
	int sumcost=0;
	rep(i,n-1){
		int cost=mst(edges,n,maybealter[i]);
		if(cost==-1 || mincost!=cost){
			cnt++;
			sumcost+=edges[maybealter[i]].cost;
		}
	}
	cout<<cnt<<' '<<sumcost<<endl;
	return 0;
}

Measured memory_bytes: 2008
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int nam = sc.nextInt();
		
		String ans = "No";
		for(int i = 1; i <= 9; i++){
		    for(int j = 1; j <= 9;j++){
		        if(i * j == nam){
		            ans = "Yes";
		            break;
		        }
		    }
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
function Main(input) {
  let lines = input.split("\n");
  lines.pop();
  lines = lines[0].split(" ");
  fnum = parseInt(lines[0]);
  lnum = parseInt(lines[1]);
  multiple = parseInt(lines[2]);
  let count = 0;
  for(let i = fnum; i <= lnum; i++){
  	if(i%multiple === 0) count++;
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29644
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
    int x,y;
    while(cin>>x>>y)
    {
        printf("%d\n",x+y/2);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;
    sort(all(ab), greater<pair<ll, ll>>());
    cout << ab[0].first+ab[0].second << endl;

}

Measured memory_bytes: 4764
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if (abs((a - b) % 2) == 1)
        cout << "Borys" << endl;
    else
        cout << "Alice" << endl;

    return 0;
}

Measured memory_bytes: 768
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        long H = sc.nextLong();
        long n = 1, ans = 0;
        while (H > 0) {
            ans += n;
            n *= 2;
            H /= 2;
        }

        out.println(ans);

        out.close();
    }


    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


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

if n == 1:
    print(0)
    exit()

two = 0
pre = s[0]
cont = 1
ans = 0
for c in s[1:]:
    if c != pre:
        if c == s[0]:
            two += 1
        ans += cont - 1
        cont = 1
        pre = c
    else:
        cont += 1
ans += cont - 1

if s[0] != s[-1] and k > two:
    ans += 1
print(ans + 2 * min(k, two))

Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
    int x, y;
    while(true)
    {
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0)
        {
            break;
        }
        if (x < y)
        {
            printf("%d %d\n", x, y);
        }
        else
        {
            printf("%d %d\n", y, x);
        }

    }
    return 0;
}



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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
    if (n == 0)return 1;
    if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
    return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=0;
    ans=max(a*c,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<int> p(N+2, 0);
    for(int i=1; i<=N; i++) cin >> p[i];

    int ans = 0;

    bool flg = false;
    int cnt = 0;
    for(int i=1; i<=N+1; i++){
        if(flg == false && p[i] == i){
            flg = true;
            cnt++;
        }
        else if(flg == true && p[i] == i){
            cnt++;
        }
        else if(flg == true && p[i] != i){
            ans += (cnt-1)/2 + 1;
            cnt = 0;
            flg = false;
        }
    }

    cout << ans << endl;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int x;
    cin>>x;
    for(int i=1;i<=360;++i)
    {
        if((x*i)%360==0)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

prev_food = A[0] - 1
ans = 0
for i in range(N):
    curr_food = A[i] - 1
    ans += B[curr_food]
    if curr_food - 1 == prev_food:
        ans += C[prev_food]
    prev_food = curr_food
print(ans)

Measured memory_bytes: 3064
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
  
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll l, r, d, ans = 0;
    cin >> l >> r >> d;
    for(int i = l; i <= r; i++)
    {
        if(i%d == 0)
            ans++;
    }
    cout << ans <<'\n';
    
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3608