akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] bit = new int [M];
		for(int i = 0; i < M; i++) {
			int k = sc.nextInt();
			for(int j = 0; j < k; j++) {
				int s = sc.nextInt();
				// 電球に対して繋がっているスイッチのフラグを立てる
				// 1を左にs-1ビット = スイッチの位置をbitの位置に置き換える
				// ORを取ることで接続されているスイッチの位置のみフラグを立てることができる
				bit[i] |= 1 << (s - 1);
			}
		}
		int[] p = new int[M];
		for(int i = 0; i < M; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();

		//--test
		// System.out.println("----------");
		// for(int i = 0; i < M; i++) {
		// 	System.out.print(p[i] + ":" + Integer.toBinaryString(bit[i]));
		// 	System.out.println("");
		// }
		// System.out.println("----------");
		//--test

		int ans = 0;
		// スイッチの数の^2までのループ
		// ^2の理由：スイッチの数分bitに置き換えているから
		// 例)スイッチの数が5であれば2^5=16まで
		for(int i = 0; i < Math.pow(2, N); i++) {
			boolean ok = true;
			// 電球の数分のループ
			// スイッチiをONにしたときに電球すべての条件に該当するか判定する
			// (電球が点灯するp[j]と一致する場合、OK)
			for(int j = 0; j < M; j++) {
				// スイッチのONの数を取得
				int bitCnt = Integer.bitCount(bit[j] & i);
				// スイッチのONの数を2で割った余りが電球の点灯条件に一致しない場合
				// NGのパターンとなる
				if(bitCnt % 2 != p[j]) {
					// System.out.println("[NG]swith on > "+(i)+":"+
					// Integer.toBinaryString(bit[j])+"&"+(i)+"="+
					// Integer.toBinaryString(bit[j]&i)+" "+
					// "bitCnt="+Integer.bitCount(bit[j])+
					// " >> "+bitCnt+
					// " p[j]="+p[j]
					// );
					ok = false;
					break;
				}
				// System.out.println("[OK]swith on > "+(i)+":"+
				// Integer.toBinaryString(bit[j])+"&"+(i)+"="+
				// Integer.toBinaryString(bit[j]&i)+" "+
				// "bitCnt="+Integer.bitCount(bit[j])+
				// " >> "+bitCnt+
				// " p[j]="+p[j]
				// );
			}
			if(ok) { 
				ans++;
				// System.out.println(" >> anser count");
			}
		}
		System.out.println(ans);
	}
}


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

int main() {
  int A , N  , x;
  cin >> N >> A;
  x = N % 500 ;
    
    if ( x <= A ) {
      cout << "Yes"  << endl;
    }
  else{
    cout << "No" << endl;
  }
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << "\n"; }
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;

int main() {
	int N, K; cin >> N >> K;
	ll ans = K;
	rep(i, N - 1) ans *= K - 1;
	cout << ans << endl;	
}

Measured memory_bytes: 256
S=input()
n=len(S)
nn=n-1

def num2bin(x, y):
  return format(x, '0'+str(y)+'b')

def f(a):
  out=0
  a=a+'+'
  l=len(a)
  i=0
  while i<l-1:
    j=i+1
    while j<l and a[j]!='+':
      j+=1
      
    out+=int(a[i:j])
    i=j
    
  return out
      

out=0
temp=pow(2, nn)
for i in range(temp):
  p=num2bin(i, nn)
  a=''
  for j in range(nn):
    a=a+S[j]
    if p[j]=='1':
      a=a+'+'
      
  a=a+S[-1]
  
  out+=f(a)
  
print(out)

Measured memory_bytes: 41964
from collections import deque

n,m = map(int, input().split())
g = [[] for _ in range(n+1)]
reached = list(range(1,n+1))
misi = [0] * (n+1)

#q = []

def bfs(x):
	q = deque()
	q.append(x)
	while(len(q) != 0):
		now = q.popleft()
#		print(now)
		for k in g[now]:
			if(misi[k] == 0):
#				print(now,"->",k)
				misi[k] = now
				#reached.remove(k)
				q.append(k)

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

misi[1] = 1
reached.remove(1)
bfs(1)

#print("---")
#print(reached)
if(True):
	print("Yes")
	for i in range(2,n+1):
		#print(i,":misi",misi[i])
		print(misi[i])
else:
	print("no")

Measured memory_bytes: 94764
h, w, k = map(int, input().split())
s = [input() for i in range(h)]

ans = 0
for i in range(2 ** (h)):
    for j in range(2 ** (w)):
        bag = 0
        sharp = 0
        
        for l in range(h):
            for m in range(w):
                
                if s[l][m] == "#":
                    sharp +=1
                if ((i >> l)&1) or ((j>>m)&1):
                    if s[l][m] == "#":
                        bag += 1
                        
        if sharp - bag == k:
            ans += 1
                
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
#define N (int)1e6+1

int main()
{
	ios
	int n;
	cin>>n;
	ld p[n+1]={0};
	for(int i=1;i<=n;i++)
		cin>>p[i];
	ld dp[n+1][n+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		if(i>1)
			dp[i][0]=dp[i-1][0]*(1-p[i]);
		else
			dp[i][0]=(1-p[i]);
		for(int j=1;j<=i;j++)
		{
			if(i==1)dp[i][j]=p[i];
			else
			{
				dp[i][j]=dp[i-1][j-1]*(p[i])+dp[i-1][j]*(1-p[i]);
			}
		}
	}
	ld ans=0;
	for(int i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	cout<<setprecision(12)<<ans<<nl;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n;
int a[maxn];
int sum;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum^=a[i];
	if(sum==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans;
    if(n <= k) {
        ans = min(n, k - n);
    }
    else{
        n %= k;
        ans = min(n,k - n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int  INF=100000000;
int main(){
  int a,b;
  cin>>a>>b;
  int sum=a+b;
  if(sum>=10)cout<<"error"<<endl;
  else cout<<sum<<endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, k;
    cin>>n>>k;
    vector<ll> h(n);
    for(ll i=0;i<n;++i){
        cin>>h[i];
    }
    sort(h.begin(), h.end());
    ll ans = INF;
    for(ll i=0;i<n-k+1;++i){
        ans = min(ans, h[i+k-1] - h[i]);
        //cout<<h[k+i-1]<<' '<<h[i]<<endl;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
constexpr double EPS = (1e-9L);
double dot(const Point& p1, const Point& p2) { return (conj(p1) * p2).real(); }
double cross(const Point& p1, const Point& p2) { return (conj(p1) * p2).imag(); }
constexpr bool eq(double a) { return abs(a) < EPS; }
Point project(Segment s, Point p) {
	Vector base = s.fi - s.se;
	double r = dot(p - s.fi, base) / norm(base);
	return s.fi + base * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point a = p2 - p1, b = p3 - p1;
	if (cross(a, b) > EPS) return 1;
	if (cross(a, b) < -EPS) return -1;
	if (dot(a, b) < -EPS) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool intersect(Point &p1, Point &p2, Point &p3, Point &p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment &s1, Segment &s2) {
	return intersect(s1.fi, s1.se, s2.fi, s2.se);
}
double getDistance(Point &a, Point &b) { return abs(a - b); }
double getDistanceLP(Line &l, Point &p) {
	return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi));
}
double getDistanceSP(Segment &s, Point &p) {
	if(dot(s.se - s.fi, p - s.fi) < 0.0) return abs(p - s.fi);
	if(dot(s.fi - s.se, p - s.se) < 0.0) return abs(p - s.se);
	return getDistanceLP(s, p);
}
double getDistance(Segment s1, Segment s2) {
	if(intersect(s1, s2)) return 0.0;
	return min(min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se)),
				min(getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se)));
}
int main() {
	cout << setprecision(10) << fixed;
	int q; cin >> q;
	Segment s1, s2;
	double x1, y1, x2, y2, x3, y3, x4, y4;
	rep(i, 0, q) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		s1 = mp(Point(x1, y1), Point(x2, y2));
		s2 = mp(Point(x3, y3), Point(x4, y4));
		P(getDistance(s1, s2));
	}
	return 0;
}

Measured memory_bytes: 3364
/* be name Khoda */
#include <bits/stdc++.h>
using namespace std;

const int N = 100 * 1001, M = 105;
long long n, W, dp[N][M], w[N], v[N];

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

Measured memory_bytes: 82304
void main(){
	int n = _scan();
	string[] st = readln().chomp().split();
	char[] ans;
	foreach(i; 0..n){
		ans ~= st[0][i];
		ans ~= st[1][i];
	}
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2660
from fractions import gcd

input = raw_input

k = int(input())
out = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        g1 = gcd(a, b)
        for c in range(1, k+1):
            g2 = gcd(g1, c)
            out += g2

print(out)


Measured memory_bytes: 81324
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int sum = 0;
        int[] val = new int[n];
        for (int i = 0; i < n; i++) {
            val[i] = scan.nextInt();
            sum += val[i];
        }
        int output = Integer.MAX_VALUE;
        int currSum = 0;
        for (int i = 0; i < n; i++) {
            currSum += val[i];
            output = Math.min(output, Math.abs(currSum - (sum - currSum)));
        }
        System.out.println(output);
    }

//    public static void main(String[] args) {
//        Scanner scan = new Scanner(System.in);
//        int n = scan.nextInt();
//        int sum = 0;
//        int[] val = new int[n];
//        for (int i = 0; i < n; i++) {
//            val[i] = scan.nextInt();
//            sum += val[i];
//        }
//        int output = Integer.MAX_VALUE;
//        boolean[][] dp = new boolean[n + 1][sum + 1];
//        dp[0][0] = true;
//        for (int i = 1; i <= n; i++) {
//            for (int j = 0; j <= sum; j++) {
//                dp[i][j] = dp[i - 1][j];
//                if (j - val[i - 1] >= 0) {
//                    dp[i][j] |= dp[i - 1][j - val[i - 1]];
//                }
//                if (dp[i][j]) {
//                    output = Math.min(output, Math.abs(j - (sum - j)));
//                }
//            }
//        }
//        System.out.println(output);
//    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

bool comp(const pair<string, int> &a, const pair<string, int> &b) {
  if(a.first.length() < b.first.length()) return true;
  if(a.first.length() > b.first.length()) return false;
  if(a.first < b.first) return true;
  return false;
}

int main(void) {
  int n, i;
  vector< pair<string, int> > v;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    string s;
    int m;
    cin >> s >> m;
    vector< pair<string, int> >::iterator it;
    for(it = v.begin(); it != v.end(); ++it) {
      if(s == (*it).first){
        (*it).second += m;
        break;
      }
    }
    if(it == v.end()) {
      pair<string, int> p = make_pair(s, m);
      v.push_back(p);
    }
  }
  sort(v.begin(), v.end(), comp);
  vector< pair<string, int> >::iterator it;
  for(it = v.begin(); it != v.end(); ++it) {
    cout << (*it).first << " " << (*it).second << "\n";
  }
  return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main() {
	int N; cin >> N; 
	int A[100010] = {}; 
	for(int i = 0; i < N; i++) cin >> A[i]; 
	multiset<int> S;
	S.insert(-1145141919); S.insert(1145141919); 
	S.insert(A[0]); 
	for(int i = 1; i < N; i++){
		auto it = S.lower_bound(A[i]); 
		it--; 
		if(*it == -1145141919) S.insert(A[i]); 
		else{
			it = S.erase(it); S.insert(A[i]); 
		}
	}
	cout << (int) S.size() - 2 << endl; 
}

Measured memory_bytes: 5376
import sys

s = input()

first_half = int(s[0:2])
second_half = int(s[2:4])

if 1 <= first_half and first_half <= 12 :
  if second_half == 0 or 13 <= second_half:
    print("MMYY")
  else:
    print("AMBIGUOUS")
else:
  if second_half == 0 or 13 <= second_half:
    print("NA")
  else:
    print("YYMM")

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

int n, m;
ll x[1010], y[1010], z[1010];

ll solve(int d1, int d2, int d3) {
	vector<ll> v;
	// printf("%d %d %d\n", d1, d2, d3);
	rep(i, n) v.push_back(x[i] * d1 + y[i] * d2 + z[i] * d3);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	ll ret = 0;
	rep(i, m) ret += v[i];
	return ret;
}

int main(int argc, char const *argv[])
{
	cin >> n >> m;
	rep(i, n) cin >> x[i] >> y[i] >> z[i];

	ll ans = 0;
	for (int mask = 0; mask < (1 << 3); ++mask) {
		vector<int> k(3);
		rep(i, 3) {
			if (mask & (1 << i)) k[i] = 1;
			else k[i] = -1;
		}
		ans = max(ans, solve(k[0], k[1], k[2]));
	}
	printf("%lld\n", ans);

	return 0;
}

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

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    a[i] = i + 1;
  }

  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    
    vector<int> next = a;
    if (k == 0) {
      for (int j = 0; j < 2 * n; j++) {
        if (j & 1) next[j] = a[n + j / 2];
        else next[j] = a[j / 2];
      }
    } else {
      for (int j = 0; j < k; j++) {
        next[j + 2 * n - k] = a[j];
      }
      for (int j = k; j < 2 * n; j++) {
        next[j - k] = a[j];
      }
    }
    a = next;
  }

  for (int i = 0; i < 2 * n; i++) {
    cout << a[i] << endl;
  }

  return 0;
}


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

int dir[4]{-1, 1, 0, 0};

int main() {
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> grid(h);
    for (int i = 0; i < h; ++i) {
        cin >> grid[i];
    }

    vector<vector<int>> dp(h, vector<int>(w, 1e9));
    dp[ch][cw] = 0;
    deque<pair<int, int>> dq;
    dq.emplace_front(ch, cw);

    while(dq.size()) {
        auto p = dq.front();
        dq.pop_front();
        int r = p.first, c = p.second;

        for (int i = 0; i < 4; ++i) {
            int nr = r + dir[i], nc = c + dir[3-i];
            if(nr < 0 || nc < 0 || h <= nr || w <= nc) continue;
            if(grid[nr][nc] == '#') continue;
            if(dp[nr][nc] > dp[r][c]) {
                dp[nr][nc] = dp[r][c];
                dq.emplace_front(nr, nc);
            }
        }

        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                int nr = r + i - 2, nc = c + j - 2;
                if(nr < 0 || nc < 0 || h <= nr || w <= nc) continue;
                if(grid[nr][nc] == '#') continue;
                if(dp[nr][nc] > dp[r][c] + 1) {
                    dp[nr][nc] = dp[r][c] + 1;
                    dq.emplace_back(nr, nc);
                }
            }
        }
    }

    cout << (dp[dh][dw] == 1e9 ? -1 : dp[dh][dw]) << endl;
}


Measured memory_bytes: 9476
import java.util.*;
public class Main {
	public static void main(String[] args){
	 Scanner sc= new Scanner (System.in);
	int a[];
	 a  = new int[10];
	 	for(int b=0;b<10;b++){
	 		a[b]=sc.nextInt();
	 	}

	 
	 Arrays.sort (a);
	System.out.println(a[9]);
	System.out.println(a[8]);
	System.out.println(a[7]);
	
	}

}

Measured memory_bytes: 17184
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;
const int N = 5e5 + 10;
const int MOD = 1e9;

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if(a >  b)
		printf("%d\n",a - 1);
	else
		printf("%d\n", a);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1000000007
#define pb push_back
#define ll long long int
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	int i;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	bool dp[k+1];
	for(i=0;i<=k;i++)
	{
		dp[i] = false;
		for(int j = 0;j<n;j++)
		{
			if(a[j]>i)
				break;
			if(dp[i-a[j]]==false)
			{
				dp[i] = true;
				break;
			}
		}
	}
	if(dp[k]==false)
		cout<<"Second";
	else
		cout<<"First";
	return 0;

}


Measured memory_bytes: 3724
#include <stdio.h>
#define NIL -1
#define MAX 30

struct Node {
    int parent, left, right;
};
typedef struct Node t_node;
t_node T[MAX];
int D[MAX];
int H[MAX];
int N;

void setDepth(int id, int depth)
{
    D[id] = depth;
    if (T[id].left != NIL) {
        setDepth(T[id].left, depth + 1);        
    }
    if (T[id].right != NIL) {
        setDepth(T[id].right, depth + 1);
    }
}

int setHeight(int id)
{
    int h1 = 0, h2 = 0;
    if (T[id].left != NIL) {
        h1 = setHeight(T[id].left) + 1;
    }
    if (T[id].right != NIL) {
        h2 = setHeight(T[id].right) + 1;
    }    
    return H[id] = h1 > h2 ? h1 : h2;
}

int getParent(int id)
{
    return T[id].parent;
}

int getSibling(int id)
{
    int i;
    for (i = 0; i < N; i++) {
        if (id != i && D[id] == D[i] && T[id].parent == T[i].parent) {
            break;
        }
    }
    return i != N ? i : NIL;
}

int getDegree(int id)
{
    int i, d = 0;
    for (i = 0; i < N; i++) {
        if (T[i].parent == id) {
            d++;
        }
    }
    return d;
}

void printTree()
{
    int root;
    int id;
    for (id = 0; id < N; id++) {
        if (T[id].parent == NIL) root = id;
    }
    
    setDepth(root, 0);
    setHeight(root);

    int p, s, d;
    for (id = 0; id < N; id++) {
        p = getParent(id);
        s = getSibling(id);
        d = getDegree(id);
        printf("node %d: ", id);
        printf("parent = %d, ", p);
        printf("sibling = %d, ", s);
        printf("degree = %d, ", d);
        printf("depth = %d, ", D[id]);
        printf("height = %d, ", H[id]);
        if (p == NIL) {
            puts("root"); 
            continue;
        }
        switch (d) {
            case 0: puts("leaf"); break;
            default : puts("internal node"); break;
        }
    }
}

int main()
{
    int i, j;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }    
    int id;
    for (i = 0; i < N; i++) {
        scanf("%d", &id);
        scanf("%d %d", &T[id].left, &T[id].right);
        T[T[id].left].parent = id;
        T[T[id].right].parent = id;
    }
 
    printTree();
    
    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int k[100005];
int a[100005];
int main(){
  int m,n,b,c=200005,w=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(c>=a[i]){
      c=a[i];
      w++;
    }
  }
  cout<<w<<"\n";
  return(0);
}

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

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint gcd(lint a,lint b){
    if(a<b){
        lint tmp=a;
        a=b;
        b=tmp;
    }
    if(a%b==0) return b;
    return gcd(a%b,b);
}

int main(){
    int N;
    cin >> N;
    lint T[100];
    lint ans=1;
    for(int i=0;i<N;i++){
        cin >> T[i];
        ans*=T[i]/gcd(ans,T[i]);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
BIG_NUM = 2000000000

while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print() #データセットの区切り



Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	int N; cin >> N;
	cout << N*N*N << endl;
}


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

ans = 0
lastHeight = H[N - 1]
count = 0
for i in range(N - 1):
    if H[N - i - 2] >= H[N - i - 1]:
        count += 1
        ans = max(ans, count)
    else:
        count = 0

print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N; cin >> N;
	REP(t, N) {
		vector<int> v(3); cin >> v;
		sort(ALL(v));
		if (v[0] * v[0] + v[1] * v[1] == v[2] * v[2]) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {

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

    for (int i = 1;; i++) {
      int tmp = scan.nextInt();
      if (tmp == 0) {
        break;
      }
      System.out.println("Case " + i + ": " + tmp);
    }

  }
}



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

int main() {
  string S;
  cin >> S;

  if (S[S.size() - 1] == 's')
    cout << S << "es" << endl;
  else
    cout << S << "s" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

class BipartiteMatching {
    public:
    BipartiteMatching(int n, int m);
    ~BipartiteMatching();
    void add_edge(int left, int right);
    int bipartite_matching();
    int get_matching(int left);
    
    private:
    int n;
    int m;
    int *level;
    int *que;
    bool *used;
    int *match;
    vector <vector <int> > graph;
    void bfs();
    bool dfs(int from);
};

BipartiteMatching::BipartiteMatching(int n, int m) : n(n), m(m), graph(n + m) {
    level = (int *)malloc(sizeof(int) * n);
    que = (int *)malloc(sizeof(int) * n);
    used = (bool *)malloc(sizeof(bool) * n);
    match = (int *)malloc(sizeof(int) * (n + m));
}

BipartiteMatching::~BipartiteMatching() {
    free(level);
    free(que);
    free(used);
    free(match);
}

void BipartiteMatching::add_edge(int left, int right) {
    graph[left].push_back(n + right);
}

int BipartiteMatching::bipartite_matching() {
    int matching = 0;
    for (int i = 0; i < n + m; i++) match[i] = -1;
    while (1) {
        int current = 0;
        bfs();
        for (int i = 0; i < n; i++) used[i] = false;
        for (int i = 0; i < n; i++) {
            if (match[i] < 0 && dfs(i)) current++;
        }
        if (current == 0) return matching;
        matching += current;
    }
}

int BipartiteMatching::get_matching(int left) {
    return match[left] - n;
}

void BipartiteMatching::bfs() {
    int qs = 0, qt = 0;
    for (int i = 0; i < n; i++) level[i] = -1;
    for (int i = 0; i < n; i++) {
        if (match[i] < 0) {
            level[i] = 0;
            que[qt++] = i;
        }
    }
    
    while (qs < qt) {
        int now = que[qs++];
        for (int i = 0; i < graph[now].size(); i++) {
            int to = graph[now][i], next = match[to];
            if (next >= 0 && level[next] < 0) {
                level[next] = level[now] + 1;
                que[qt++] = next;
            }
        }
    }
}

bool BipartiteMatching::dfs(int from) {
    used[from] = true;
    for (int i = 0; i < graph[from].size(); i++) {
        int to = graph[from][i], next = match[to];
        if (next < 0 || (!used[next] && level[from] < level[next] && dfs(next))) {
            match[from] = to;
            match[to] = from;
            return true;
        }
    }
    return false;
}

int a[100];
int b[100];
int c[100];
int d[100];

int main() {
    int n, i, j;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]);
    for (i = 0; i < n; i++) scanf("%d %d", &c[i], &d[i]);
    
    BipartiteMatching bm(n, n);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (a[i] < c[j] && b[i] < d[j]) bm.add_edge(i, j);
        }
    }
    
    printf("%d\n", bm.bipartite_matching());
    
    return 0;
}


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

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

  sort(A.begin(),A.end());

  cout << abs(A[0]-A[A.size()-1]) << endl;

 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  ll a, b, x;
  cin >> a >> b >> x;

  b = (a == 0) ? b / x + 1 : b / x;
  a = (a == 0) ? 0 : (a - 1) / x;
  cout << b - a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int S[1001];
int solve(int n){
  int cnt = 0;
  for(int i=2;i<=n;++i){
    for(int j=1;j<i;++j) if(S[i]-S[j-1]==n) ++cnt;
  }
  return cnt;
}
int main(){
  int n;
  for(int i=1;i<=1000;++i) S[i]=S[i-1]+i;
  while(cin>>n,n){
    cout << solve(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
n,k = map(int,input().split()) 
 #複数文字の入力
ans = 0

for i in range(1,n+1):
  j=0 
  #カウンター設置
  while i<k:
    i*=2
    j+=1
  ans+=1/2**j
print("{:.12}".format(ans/n))


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

namespace ConsoleApp15
{
    class Class19
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<string, int> Table = new Dictionary<string, int>();
            for (int i = 0; i < N; i++)
            {
                var r = Console.ReadLine();
                if (Table.ContainsKey(r))
                    Table[r]++;
                else
                    Table[r] = 1;
            }

            int max = Table.Values.Max();
            
            var ans = Table.Where(x => x.Value == max).OrderBy(x => x.Key,StringComparer.OrdinalIgnoreCase);

            foreach (KeyValuePair<string,int> s in ans)
            {
                Console.WriteLine(s.Key);
            }
        }
    }
}


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

int calc(int n) {
	n *= 1.05;
	if (n % 1000)n = (n / 1000 + 1) * 1000;
	return n;
}
int main() {
	int n; cin >> n;
	int a = 100000;
	rep(i, n) {
		a = calc(a);
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 1160
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a,b = cin()
    if a==1:
      a=14
    if b==1:
      b=14
    if a>b:
      print("Alice")
    elif a<b:
      print("Bob")
    else:
      print("Draw")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*(n)
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
N, M, K = map(int, input().split())
U = UnionFind(N)
ng = [0]*N
for i in range(M):
    a, b = map(int, input().split())
    U.union(a-1, b-1)
    ng[a-1] += 1
    ng[b-1] += 1
for i in range(K):
    c, d = map(int, input().split())
    if U.same(c-1, d-1): 
        ng[c-1] += 1
        ng[d-1] += 1
li = []
for i in range(N):
    li.append(U.size(i)-ng[i]-1)
print(*li)

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
const int INF = 0x3f3f3f3f;
struct Store {
    ll price;
    ll count;
    bool operator<(const Store &rhs) const {
        return price < rhs.price;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<Store> stores(n);
    for (int i = 0; i < n; ++i) {
        cin >> stores[i].price >> stores[i].count;
    }
    sort(stores.begin(), stores.end());
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (m <= 0) break;
        if (m <= stores[i].count) {
            ans += stores[i].price * m;
            m = 0;
        } else {
            ans += stores[i].price * stores[i].count;
            m -= stores[i].count;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
n,a,b=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]

dif=[x[ind+1]-x[ind] for ind in range(len(x)-1)]
c=0
for i in dif:
    if(i*a > b):
        c+=b
    else:
        c+=i*a
print(c)

Measured memory_bytes: 14224
#include<iostream>
#include<queue>
using namespace std;
int h,w,d[800][800],k,sx,sy,ans=1e9;
queue<pair<int,int> >P;
string s[800];
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
main()
{
	cin>>h>>w>>k;
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
		for(int j=0;j<w;j++)
		{
			d[i][j]=-1;
			if(s[i][j]=='S')sx=i,sy=j;
		}
	}
	P.push(make_pair(sx,sy));
	d[sx][sy]=k;
	while(!P.empty())
	{
		int x=P.front().first,y=P.front().second;P.pop();
		ans=min(ans,min(min(x,y),min(h-x-1,w-y-1)));
		if(x==0||y==0||x==h-1||y==w-1)ans=0;
		else for(int r=0;r<4;r++)
		{
			int tx=x+dx[r],ty=y+dy[r];
			if(s[tx][ty]!='#'&&d[tx][ty]<d[x][y]-1)
			{
				d[tx][ty]=d[x][y]-1;
				P.push(make_pair(tx,ty));
			}
		}
	}
	cout<<(ans+k-1)/k+1<<endl;
}

Measured memory_bytes: 3584
/* vo00_09.cpp */

#include <iostream>
using namespace std;

const int N = 1000000;
int prime[N];

void init();

int main()
{
	init();

	int n;
	while (cin >> n) {
		
		cout << prime[n] << '\n';

	}

	return 0;
}

void init()
{
	for (int i = 0; i < N; ++i) { prime[i] = 1; }

	prime[0] = prime[1] = 0;

	int count = 0;
	for (int i = 2; i < N; ++i) {
		if (prime[i]) {
			for (int j = i * 2; j < N; j += i) { prime[j] = 0; }
			count++;
		}
		
		prime[i] = count;
	}
}

Measured memory_bytes: 5064
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include <cmath>
#include<string.h>
#include <stdio.h>
#include <unordered_map>
#include <queue>
#include<climits>
#include <iomanip>



using namespace std;
#define ll long long
#define clr(x) memset(x, 0, sizeof(x))
#define tcase ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define GCJ ll t;cin>>t;for(ll H=1;H<=t;H++){cout<<"CASE #"<<H<<": ";solve();}
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define endl "\n"
//comment out the above line when coding probs which require flushing the output

vector<vector<int>>adj, parent;
vector<int>top;
bool vis[100010]={0};

void dfs(int node)
{
    vis[node]=true;
    
    for(int i=0;i<adj[node].size();i++)
    {
        if(!vis[adj[node][i]])
        {
            dfs(adj[node][i]);
        }
    }
    top.push_back(node);
}

void solve()
{
    adj.clear();
    parent.clear();
    top.clear();
    clr(vis);


    
    int n, m;
    cin>>n>>m;
    adj.resize(n+1);
    parent.resize(n+1);
    
    for(int i=0;i<m;i++)
    {
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        parent[b].push_back(a);
    }
    
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    
    
    
    int ans[n+1];
    clr(ans);
    
    
    reverse(all(top));
    
    for(int j=0;j<top.size();j++)
    {
        int node=top[j];
        
        int temp=-1;
        for(int i=0;i<parent[node].size();i++)
        {
            temp=max(temp, ans[parent[node][i]]);
        }
        ans[node]=temp+1;
    }
    
    

    cout<<*max_element(ans, ans+n+1)<<endl;
}


int main()
{
    
    
    fast;
    //tcase
    // {
    solve();
    // }
    
}






Measured memory_bytes: 17228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
  int n, d, ans = 0;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n)
  {
    rep(j, d)
    {
      cin >> x[i][j];
    }
  }
  rep(i, n)
  {
    rep(j, i)
    {
      int sq = 0;
      rep(k, d)
      {
        int s = x[i][k] - x[j][k];
        sq += s * s;
      }
      int t = sqrt(sq);
      if (t * t == sq)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a[1000010];
int b[1000010];
int main()
{
    int n; 
    cin>>n;
    for(int i=0;i<n;i++)
	{
        cin>>a[i];
        b[a[i]]++;
    }
    int x=0;
    int res=0;
    if(n==1) cout<<1<<endl;
    else
	{
        for(int i=1;i<1000010;i++)
		{
            x=b[i]+b[i-1]+b[i+1];
            if(x>res) res=x;
        }
        cout<<res<<endl;
	}
	system ("pause");
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int n = S.size();

  ll ans = 0;
  
  for(int tmp = 0; tmp < (1 << n-1); tmp++){
    ll t = S[0] - '0';
    for (int i=0; i<n-1;i++) {
      if (tmp & (1<<i)) {
        ans += t;
        t = S[i+1] - '0';
      }
      else {
        t = 10*t + S[i+1]-'0';
      }
    
    }
    ans += t;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    int m,n; cin>>n>>m;
    vector<string> a(n);
    vector<string> b(m);
    rep(i,0,n) cin>>a[i];
    rep(i,0,m) cin>>b[i];
    bool ans=false;
    for(int i=0; i+m<=n; i++){
        for(int j=0; j+m<=n; j++){
            bool ok=true;
            rep(k,0,m){
                rep(l,0,m){
                    if(a[i+k][j+l]!=b[k][l]){
                        ok=false; break;
                    }
                }
                if(!ok) break;
            }
            if(ok) ans=true;
        }
        if(ans) break;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  string s,t;
  cin>>s>>t;
  int ans=0;
  rep(i,len(s)){
    if(s[i]!=t[i])ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3832
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    F.sort(reverse=True)
    A.sort()
    right=10**12
    left=-1
    while right-left>1:#区間(left,right]に解Xがある
        x=(right+left)//2
        k_sum=0
        for i in range(n):
            k_sum+=max(0,A[i]-x//F[i])
            if k_sum>k:
                left=x
                break
        else:
            right=x
    print(right)
    

if __name__=='__main__':
    main()

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

public class Main {
    public static void main(String[] args) {
        FastScanner s = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long cnt01 = 0, cnt10 = 0;

        String str = s.next();
        for (int i = 0; i < str.length(); i++) {
            if (i%2==0) {
                if (str.charAt(i)=='0') {
                    cnt10++;
                } else {
                    cnt01++;
                }
            } else {
                if (str.charAt(i)=='1') {
                    cnt10++;
                } else {
                    cnt01++;
                }
            }
        }
        out.println(Math.min(cnt01, cnt10));

        out.close();
    }

    static class FastScanner {
		
		BufferedReader br; StringTokenizer st;
		FastScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			st = new StringTokenizer("");
		}
		String next() {
			while(!st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) {}
			}
			return st.nextToken();
		}
		
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() {return Long.parseLong(next()); }
		
	}
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string a,b,c;

  cin>>a>>b>>c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        int red = 0;
        for (int i = 0; i < s.length(); ++i) {
            if (s.charAt(i) == 'R') {
                ++red;
            }
        }
        int blue = s.length() - red;
        if (red > blue) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 23636
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;

int main(){

	double q;
	while(~scanf("%lf",&q)){
		if(q==-1) break;
		double x=q/2;
		for(;;){
			x = x - (pow(x,3.0)-q)/(3*x*x);
			if(abs(pow(x,3.0)-q) < 0.00001*q) break;
		}

		printf("%.6f\n",x);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  int n; cin>>n;
  ll a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];

  int an=0; ll fu=0;
  ll c[n];
  for(int i=0;i<n;i++) {
    c[i]=a[i]-b[i];
    if (c[i] < 0) an++,fu+=-c[i];
  }
  sort(c,c+n,greater<ll>());
  for(int i=0;i<=n && fu>0;i++) {
    if (i==n || c[i]<0) {
      cout<<-1<<endl;
      return 0;
    }
    fu -= c[i];
    an++;
  }
  cout<<an<<endl;
}

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

using namespace std;

const int maxn = 3001, mod = 2019;
int n, temp = 1, ans = 0, sum = 0;
string ch;
int m[maxn];

signed main()
{
    cin>>ch;
    m[0] = 1;
    for(int i = ch.size() - 1; i >= 0; i --) {
        sum += (ch[i] - '0') * temp;
        sum %= mod;
        ans += m[sum];
        m[sum] ++;
        temp %= mod;
        temp *= 10;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3708
#include<cstdio>
using namespace std;
int n,m,s;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n;++i){
        for(int j=0;j<=n;++j){
            int k=m-i-j;
            if(k>=0&&k<=n){
                ++s;
            }
        }
    }
    printf("%d\n",s);
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef long double LD;


int main()
{
  LL N;
  cin >> N;
  LL M;
  cin >> M;

  vector<set<LL>> Switch(M);
  for (LL m = 0; m < M; ++m) {
    LL K;
    cin >> K;
    for (LL k = 0; k < K; ++k) {
      LL s;
      cin >> s;
      Switch[m].insert(s - 1);
    }
  }

  vector<int> P(M);
  for (LL m = 0; m < M; ++m) {
    cin >> P[m];
  }
  
  LL counter = 0;
  for (LL bit = 0; bit < (1 << N); ++bit) {
    vector<int> ON_NUM(M, 0);
    vector<LL> S(N);
    for (LL i = 0; i < N; ++i) {
      if (bit & (1 << i)) { // i が bit に入るかどうか
        S[i] = 1;
        for (LL m = 0; m < M; ++m) {
          if (Switch[m].find(i) != Switch[m].end()) {
            // もし、m番目の電球がi番目のスイッチに接続されていたら
            ON_NUM[m]++;
          }
        }
      }
      else {
        S[i] = 0;
      }
    }

    bool all_ON = true;
    for (LL m = 0; m < M; ++m) {
      if ((ON_NUM[m] % 2) != P[m]) {
        all_ON = false;
        break;
      }
    }
    if (all_ON) {
      counter++;
    }
  }


  cout << counter;
  return 0;
}





Measured memory_bytes: 256