akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	int n, r;
	cin >> n >> r;
	if (n >= 10) {
		cout << r;
	}
	else {
		cout << 100 * (10 - n) + r;
	}
}


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

typedef long long int ll;

const ll mod = 1e9+7;
const int N = 111;
const int K = 1e5+7;

ll dp[2][K];

ll qry(int i, int j, int k)
{
  ll l = 0, r = dp[i][k];
  if(j > 0) l = dp[i][j-1];
  return (r + mod - l)%mod;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n, k;
  cin >> n >> k;
  
  int cur = 0;
  for(int i=0;i<=k;++i)
    dp[cur][i] = 1;
  for(int i=1;i<=n;++i)
  {
    int a; cin >> a;
    cur ^= 1;
    for(int j=k;j>=0;--j)
      dp[cur][j] = qry(cur ^ 1, j - a, j);
    for(int j=1;j<=k;++j)
      dp[cur][j] = (dp[cur][j-1] + dp[cur][j]) % mod;
  }
  
  if(k > 0)
    cout << (dp[cur][k] + mod - dp[cur][k-1]) % mod << endl;
  else cout << dp[cur][k] << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define rep(i,f,t) for(int i=f;i<t;i++)
using namespace std;
int solve(){
	ll n;
  	cin>>n;
  	string s;
  	while(n--){
  		char c=n%26+'a';
  		s=c+s;
  		n/=26;
	}
	cout<<s<<endl;
	return 0;
}
int main(){
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3592
from itertools import accumulate, combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))

SA = list(accumulate(A)) + [0]
B = A[:]

for l, r in combinations(range(N), 2):
    B.append(SA[r] - SA[l-1])

ans = 0
for i in range(42, -1, -1):
    ans *= 2
    B1 = [b for b in B if 2**i & b]
    if len(B1) >= K:
        ans += 1
        B = B1[:]

print(ans)


Measured memory_bytes: 59980
#include <cstdio>
#include <algorithm>

using namespace std;

#define LL long long

LL f[101][101][301];
int a[101];

int main()
{
	int n,w;
	scanf("%d%d",&n,&w);
	for(int i=1;i<=n;i++)
	{
		int v;
		scanf("%d%d",&a[i],&v);
		int ad=a[i]-a[1];
		for(int j=0;j<=i;j++)
		{
			for(int k=0;k<=300;k++)f[i][j][k]=f[i-1][j][k];
			for(int k=ad;k<=300;k++)
			{
				if(j>0)f[i][j][k]=max(f[i][j][k],f[i-1][j-1][k-ad]+v);
			}
		}
	}
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int k=0;k<=300;k++)
			{
				if((LL)j*a[1]+k<=w)ans=max(ans,f[i][j][k]);
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}

Measured memory_bytes: 22272
N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X,x)
for a in set(A):
    cnt = f(A,a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt-a
print(ans)

Measured memory_bytes: 20592
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int h1,m1,h2,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    printf("%d\n",max((h2*60+m2)-(h1*60+m1) - k, 0));
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

// factorization O(sqrt(n))
map<long long, long long> prime_factor(long long n) {
    map<long long, long long> res;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    auto dict = prime_factor(n);
    vl cum(50, 0);
    repeat(i, 1, 50) {
        cum[i] += cum[i - 1] + i;
    }
    ll ans = 0;
    foreach (e, dict) {
        ll f = e.first;
        ll s = e.second;

        repeat(i, 1, 50) {
            if (cum[i] > s) {
                ans += i - 1;
                break;
            }
        }
    }
    out(ans);

    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 1;
    if (a + b == 3) ans = 3;
    if (a + b == 4) ans = 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final int MAX = 10000;

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

		int[] cols = new int[MAX];
		int[] rows = new int[MAX];
		
		boolean[] col_checked = new boolean[MAX];
		boolean[] row_checked = new boolean[MAX];
		
		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int col_sum = 0;
			for(int i = 0; i < n; i++){
				cols[i] = sc.nextInt();
				col_sum += cols[i];
				//System.out.println(col_sum);
			}
			
			
			int row_sum = 0;
			for(int i = 0; i < n; i++){
				rows[i] = sc.nextInt();
				row_sum += rows[i];
			}
			/*
			if(col_sum != row_sum){
				System.out.println("No");
				continue;
			}
			*/
			for(int i = 0; i < n; i++){
				row_checked[i] = col_checked[i] = false;
			}
			
			int limit_col = n;
			int limit_row = n;
			
			
			while(true){
				boolean updated = false;
				/*
				System.out.println("limit_col = " + limit_col + ", limit_row =  " + limit_row);
				for(int i = 0; i < n; i++){
					System.out.print(cols[i] + " ");
				}
				System.out.println();
				for(int i = 0; i < n; i++){
					System.out.print(rows[i] + " ");
				}
				System.out.println();
				sc.next();
				*/
				for(int col = 0; col < n; col++){
					if(col_checked[col]){
						continue;
					}else if(cols[col] == 0){
						col_checked[col] = true;
						limit_row--;
						updated = true;
					}else if(cols[col] == limit_col){
						col_checked[col] = true;
						cols[col] = 0;
						limit_row--;
						updated = true;
						
						for(int row = 0; row < n; row++){
							if(!row_checked[row]){
								rows[row]--;
							}
						}
					}
				}
				/*
				System.out.println("limit_col = " + limit_col + ", limit_row =  " + limit_row);
				for(int i = 0; i < n; i++){
					System.out.print(cols[i] + " ");
				}
				System.out.println();
				for(int i = 0; i < n; i++){
					System.out.print(rows[i] + " ");
				}
				System.out.println();
				sc.next();
				*/
				for(int row = 0; row < n; row++){
					if(row_checked[row]){
						continue;
					}else if(rows[row] == 0){
						row_checked[row] = true;
						limit_col--;
						updated = true;
					}else if(rows[row] == limit_row){
						row_checked[row] = true;
						rows[row] = 0;
						limit_col--;
						updated = true;
						
						for(int col = 0; col < n; col++){
							if(!col_checked[col]){
								cols[col]--;
							}
						}
					}
				}
				
				if(!updated){
					break;
				}
			}
			
			boolean flag = true;
			for(int i = 0; i < n; i++){
				if(rows[i] != 0 || cols[i] != 0){
					flag = false;
					break;
				}
			}
			
			System.out.println(flag ? "Yes" : "No");
		}

	}

}

Measured memory_bytes: 60324
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  int n = s.size();
  if (s[0] == '0' || s[n - 1] == '1') {
    cout << -1 << endl;
    return 0;
  }
  vector<int> res;
  rep(i, n / 2) {
    if (s[i] != s[n - 2 - i]) {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] == '1') res.push_back(i + 1);
  }
  res.push_back(n);
  reverse(res.begin(), res.end());
  int m = res.size();
  vector<pair<int, int>> ans;
  int idx = n;
  rep(i, m - 1) {
    ans.push_back({i + 1, i + 2});
    FOR(j, res[i + 1] + 2, res[i] + 1) {
      ans.push_back({i + 1, idx--});
    }
  }
  rep(i, n - 1) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }





  
  return 0;
}

Measured memory_bytes: 2484
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	if (1 <= a && a <= 9) {
		if (1 <= b && b <= 9) {
			cout << a * b << endl;
			return 0;
		}
	}

	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int N[100000]={0},i,m,n,q,l,r,mid,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&q);
		N[i]=q;
	}
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		l=0;r=n;
		scanf("%d",&q);
		while(l<r)
		{
			mid=(l+r)/2;
			if (N[mid]==q) {c++;break;}
			else if (q<N[mid]) {r=mid;}
			else {l=mid+1;}
		}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 1000
#!/usr/bin/env ruby
n, k = gets.chomp.split.map(&:to_i)

a = gets.chomp.split.map(&:to_i)

town_a = [nil, a].flatten
visited_count = Array.new(n + 1, 0)
@marked_town = nil
@loop_length = 0

now = town_a[1]

counter = 1
loop do
  return puts now if counter == k

  @loop_length += 1 if @marked_town

  if now == @marked_town
    nokori = (k - counter) % @loop_length

    nokori.times do
      now = town_a[now]
    end
    puts now
    break
  end

  if @marked_town.nil?
    visited_count[now] += 1
      @marked_town = now if visited_count[now] == 2
  end
  now = town_a[now]
  counter += 1
end




Measured memory_bytes: 31968
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N,K,Q;cin>>N>>K>>Q;
    vector<int> v(100010,K-Q);
    
    int A;
    for(int i=0;i<Q;i++){
        cin>>A;
        v[A]++;
    }

    for(int i=1;i<=N;i++){
        if(v[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;

}

Measured memory_bytes: 1024
X, N = map(int, input().split())
P = set(map(int, input().split()))

sub = 10000
ans = 0
for i in range(-1000, 1001):
    y = X + i
    if y in P:
        continue
    if abs(i) < sub:
        sub = abs(i)
        ans = y
print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define N 5005
long long f[N*N];
int s[3][4],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=3;j++)
			scanf("%d",&s[i][j]);
	for(int i=1;i<=3;i++)
	{
		int tmp=s[2][i]-s[1][i];
		for(int j=s[1][i];j<=n;j++)f[j]=max(f[j-s[1][i]]+tmp,f[j]);
	}
	int mx=n+f[n];memset(f,0,sizeof(f));
	for(int i=1;i<=3;i++)
	{
		int tmp=s[1][i]-s[2][i];
		for(int j=s[2][i];j<=mx;j++)f[j]=max(f[j-s[2][i]]+tmp,f[j]);
	}
	printf("%lld\n",mx+f[mx]);
}

Measured memory_bytes: 195968
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
dic = Counter(A)
ans = 0
for k,v in dic.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)


Measured memory_bytes: 23268
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
bool is_prime(int n){
    int max=sqrt(n);
    for(int i=2;i< max;i++){
        if(n%i==0) return 0;  
    }
    return 1;
}
int main(){
    int n;
    cin>>n;
    while(1){
        if(is_prime(n)==1){
            cout<<n<<endl;
            return 0;
        }
        n++;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>

#define lm ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define case "Case " << l << ":"
#define quit return 0

using namespace std;
int main()
{
    lm
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    long long int n,c=0,m;
    cin >> n ;
    char a[100];
    while(n>26)
    {
        if(n%26==0)
        {
            a[c++]=26+96;
            n=n/26-1;
        }
        else{
        a[c++]=n%26+96;
        n/=26;
        }
    }

    a[c++]=n+96;
    for(m=c-1;m>=0;m--){
        cout << a[m];
    }
    quit;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main{

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    double n = sc.nextInt();
    double a;

    if(1<=n && n<=100){

      if(n%2==0){
        a = (n/2)/n;
      }else{
        a = ((n+1)/2)/n;
      }

      System.out.println(a);
    }
  }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int cnt = 0;
  rep(i, n) {
    int p;
    cin >> p;
    if(p == i + 1)
      cnt++;
    else {
      ans += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  ans += (cnt + 1) / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>


#define MAX 100


using namespace std;


int main()
{
    int n;
    vector< vector<int> > adj(MAX, vector<int>(MAX, -1));
    cin >> n;
    for (int i = 0; i < n; i++) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            adj[id][v] = c;
        }
    }

    vector<int> min_costs(MAX, INT_MAX);
    vector<bool> in_tree(MAX, false);
    vector<int> parent(MAX, false);

    min_costs[0] = 0;
    for (int tc = 0; tc < n; tc++) {
        int min_cost = INT_MAX;
        int closest_v = -1;
        for (int i = 0; i < n; i++) {
            if (min_cost > min_costs[i] && !in_tree[i]) {
                min_cost = min_costs[i];
                closest_v = i;
            }
        }

        in_tree[closest_v] = true;

        for (int i = 0; i < n; i++) {
            if (adj[closest_v][i] < 0)
                continue;

            int w = min_cost + adj[closest_v][i];
            if (!in_tree[i] && min_costs[i] > w) {
                min_costs[i] = w;
                parent[i] = min_cost;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << min_costs[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3180
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int a, b;
int h, m;

const double PI = 3.1415926535897932384626;


int main()
{
	scanf("%d%d%d%d", &a, &b, &h, &m);
	
	double dm = m * 6; //360 / 60;
	double dh = h * 30;	//360 / 12 + m * 
	dh = dh + m * 6.0 / 12;
	
	double d;
	if (dh >= dm) {
		double da = dh - dm;
		double db = 360 - da;
		if (da < db)
			d = da;
		else
			d = db;
	} else {
		double da = dm - dh;
		double db = 360 - da;
		if (da < db)
			d = da;
		else
			d = db;
	}
	
////	printf("%.20lf\n", d);
	double rad = d * PI / 180.0;
	double ans = a * a + b * b - 2 * a * b * cos(rad);
	ans = sqrt(ans);
	printf("%.20f\n", ans);
	
	return 0;
}


Measured memory_bytes: 2584
import java.util.*;

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

		int count_1 = 0;
		for (int i=0; i<S.length(); i++){
			if (i%2 == 0){
				if (S.charAt(i) == '0'){
					count_1 += 1;
				}
			}else if (i%2 == 1){
				if (S.charAt(i) == '1'){
					count_1 += 1;
				}
			}
		}

		int count_2 = 0;
		for (int i=0; i<S.length(); i++){
			if (i%2 == 0){
				if (S.charAt(i) == '1'){
					count_2 += 1;
				}
			}else if (i%2 == 1){
				if (S.charAt(i) == '0'){
					count_2 += 1;
				}
			}
		}

		System.out.println(Math.min(count_1, count_2));
	}
}

Measured memory_bytes: 24380
# coding: utf-8
# Your code here!

S = input()

# print(S)

# print(len(S))

if len(S) == 2:
    print(S)
elif len(S) == 3:
    s_reversed = reversed(S)
    # print(s_reversed)
    # print(S.reverse())
    print(S[::-1])
else:
    pass


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
vector<int>e[1010];
int n,m,now,tot,xu[1010],v[1010],a[202000],b[202000];
int w[1010][1010],c[1010][1010];
I D_1(int x){
	w[now][x]=v[x]=1;
	for(auto d:e[x])if(!v[d])D_1(d);
}
I D_2(int x){
	xu[x]=tot;v[x]=1;
	for(auto d:e[x])if(!v[d])D_2(d);
}
I D_3(int x){
	if(xu[x]!=tot)c[now][x]=1;v[x]=1;
	for(auto d:e[x])if(!v[d])D_3(d);
}
int main(){
	read(n);read(m);
	F(i,1,m){
		read(a[i]);read(b[i]);e[a[i]].emplace_back(b[i]);
	}
	F(i,1,n){
		now=i;C(v,0);D_1(i);
	}
//	F(i,1,n){
//		F(j,1,n)cout<<w[i][j];
//		cout<<endl;
//	}
	F(i,1,n){
		now=i;
		C(v,0);C(xu,0);tot=0;v[i]=1;
		for(auto d:e[i]){
			++tot;
			if(!v[d])D_2(d);
		}
		C(v,0);re sz=e[i].size();v[i]=1;tot=sz+1;
		FOR(j,sz-1,0){
			--tot;
			if(!v[e[i][j]])D_3(e[i][j]);
		}
	}
	F(i,1,m){
		if(w[b[i]][a[i]]^c[a[i]][b[i]])printf("diff\n");
		else printf("same\n");
	}
	return 0;
}



Measured memory_bytes: 14528
//============================================================================
// Name        : b.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
using namespace std;

int main() {
	int n,d;cin>>n>>d;
	vector<vector<int>> x(n,vector<int>(d,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>x[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<n-1;i++){
		for(int m=i+1;m<n;m++){
			int ssum=0;
			for(int j=0;j<d;j++){
				ssum+=(x[i][j]-x[m][j])*(x[i][j]-x[m][j]);
			}
			for(int k=0;k<1000;k++){
				if(k*k==ssum){
					ans++;
				}
			}
		}

	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n,m,X,Y;
    cin>>n>>m>>X>>Y;
    vector<int>x(n);
    for(int i=0;i<n;i++){
        cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    vector<int>y(m);
    for(int i=0;i<m;i++){
        cin >> y.at(i);
    }
    sort(y.begin(),y.end());
    bool war=0;
    for(int i=X+1;i<=Y;i++){
        if(i>x.at(n-1)&&i<=y.at(0)){
            war=1;
            break;
        }
    }
    if(war) cout << "No War";
    else cout << "War";
}

Measured memory_bytes: 256
s = input()
s = s[:-1 if len(s) % 2 else -2]

while True:
    ls = len(s)
    # print(f"{s[:ls // 2]:} == {s[-ls // 2:]:}")
    if s[:ls // 2] == s[-ls // 2:]:
        print(len(s))
        break
    s = s[:-2]

Measured memory_bytes: 3060
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n;
int l[210];

int main() {
    scanf("%d",&n);
    for (int i=0;i<2*n;i++) {
        scanf("%d",l+i);
    }
    sort(l,l+2*n);
    int ans=0;
    for (int i=0;i<2*n;i+=2) {
        ans+=l[i];
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(n+1):
	for j in range(n+1):
		k = n-(i+j)
		if k < 0:
			continue
		s = i*10000+j*5000+k*1000
		if s == y:
			print (i,j,k)
			exit()
print (-1,-1,-1)


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

int main(void) {
    string s, t;
    cin >> s >> t;
    
    int n = (int)(s.size() - t.size());
    int min = 1000;
    
    for (int i = 0; i <= n; i++) {
        int counter = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s.at(i+j) != t.at(j)) {
                counter++;
            }
        }
        if (counter < min) {
            min = counter;
        }
    }
    cout << min <<endl;
    return 0;
}

Measured memory_bytes: 3560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class AFavoriteSound {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(C, B / A) << endl;
  }
};


signed main() {
  AFavoriteSound solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i,  a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

ll k;

bool check(int x, vector<int>& A) {
	vector<int> v;
	rep(i, A.size()) {
		if (A[i] % x) v.push_back(A[i] % x);
	}
	sort(all(v));
	vector<int> l(v.size() + 1, 0), r(v.size()+1, 0);
	rep(i, v.size()) {
		l[i+1] = l[i] + v[i];
	}
	rrep(i, v.size()) {
		r[i] = r[i+1] + (x - v[i]);
	}
	rep(i, v.size()+1) {
		if (max(l[i], r[i]) <= k) return true;
	}
	return false;
}
void solve(long long N, long long K, std::vector<long long> A) {
	k = K;
	int s = 0;
	rep(i, N) {
		s += A[i];
	}
	vector<int> v;
	for (int i = 1; i * i <= s; i++) {
		if (s % i == 0) {
			v.push_back(i);
			if (i * i != s) {
				v.push_back(s / i);
			}
		}
	}
	int res = 0;
	for (auto x : v) {
		if (check(x, A)) {
			res = max(res, x);
		}
	}
	cout << res << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	long long K;
	scanf("%lld",&K);
	std::vector<long long> A(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, K, std::move(A));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    int a,b;
    cin >> a >> b;
    
    if(a == b)Yes;
    else No;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
int main(void)
{
	int N; cin >> N;
	string S; cin >> S;
	set<char> l, r, sum;
	rep(i, 0, N)sum.insert(S[i]);
	int num_sum = sum.size();
	int ans = 0;
	rep(i, 1, N) {
		rep(j, 0, i)l.insert(S[j]);
		rep(j, i, N)r.insert(S[j]);
		int tmp = l.size() + r.size() - num_sum;
		ans = max(ans, tmp);
		l.clear(); r.clear();
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	vll a(5);
	rep(i,5) cin >> a[i];
	sort(rall(a));
	rep(i,5) cout << a[i] << (i==4?"\n":" ");
	return 0;
}


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

int main(void)
{
  int N,L;
  char moji[110][110],stock[110];
  scanf("%d%d",&N,&L);
  
  for(int m = 0;m < N;m++)
  {
    scanf("%s",moji[m]);
  }
  
  for(int i = 0;i < N;i++)
  {
    for(int j = 0;j < N - 1;j++)
    {
      if(strcmp(moji[j],moji[j+1]) >= 0)
         {
           strcpy(stock,moji[j]);
           strcpy(moji[j],moji[j+1]);
           strcpy(moji[j+1],stock);
         }
    }
  }
  
  for(int n = 0;n < N;n++){printf("%s",moji[n]);}
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int i,j,k,n,in[200][2],ttt[200][200],a,b,c,d;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    ttt[i][i]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&in[i][0],&in[i][1]);
  }
  //printf("\n");
  
  for(i=2;i<=n;i++){
    for(j=0;j<n-i+1;j++){
      ttt[j][j+i-1]=9999999;
      for(k=j;k<j+i;k++){
	a=ttt[j][k]+ttt[k+1][j+i-1]+in[j][0]*in[k][1]*in[j+i-1][1];
	if(a<ttt[j][j+i-1]){
	  ttt[j][j+i-1]=a;
	}
      }
      //printf("%d\n",ttt[j][j+i-1]);
    }
    //printf("\n");
  }

  printf("%d\n",ttt[0][n-1]);

  return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
long long ans;
int main() {
	cin>>n;
	for(int i=1;i<=n-1;i++) {
		// cout<<"n/i = "<<n/i<<'\n';
		if(n%i==0) ans+=n/i-1;
		else ans+=n/i;
		// cout<<"ans = "<<ans<<'\n';
	}
	cout<<ans;
	return 0;
}



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


int main(){
	int h, w;
	cin >> h >> w;
	int a[500][500];
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> a[i][j];
		}
	}
	vector<pair<pair<int, int>, pair<int, int> > > ans;
	for (int i = 0; i < h; i++){
		if (i%2 == 0){
			for (int j = 0; j < w; j++){
				if (j == w-1){
					if (a[i][j]%2 && i != h-1){
						ans.push_back(make_pair(make_pair(i, j), make_pair(i+1, j)));
						a[i+1][j]++;
					}
				}else{
					if (a[i][j]%2){
						ans.push_back(make_pair(make_pair(i, j), make_pair(i, j+1)));
						a[i][j+1]++;
					}
				}
			}
		}else{
			for (int j = w-1; j >= 0; j--){
				if (j == 0){
					if (a[i][j]%2 && i != h-1){
						ans.push_back(make_pair(make_pair(i, j), make_pair(i+1, j)));
						a[i+1][j]++;
					}
				}else{
					if (a[i][j]%2){
						ans.push_back(make_pair(make_pair(i, j), make_pair(i, j-1)));
						a[i][j-1]++;
					}
				}
			}
		}
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++){
		cout << ans[i].first.first+1 << " " << ans[i].first.second+1 << " ";
		cout << ans[i].second.first+1 << " " << ans[i].second.second+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(),X.end()

int main(){
	int n;
	cin >> n;
	ll int tmp;
	ll int sum,min,max;
	max = -1000010;
	min = 9999999;
	sum = 0;
	for(int i=0;i<n;i++){
		cin >> tmp;
		if(tmp<min) min = tmp;
		if(tmp>max) max = tmp;
		sum += tmp;
	}
	cout << min <<" " << max << " " << sum << endl;

}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define out(a) debg(a);
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
// template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}




int main(){
    long long N;
    scanf("%lld",&N);
    ll cnt=0;
    for (long long a = 1; a <= 1000000; a++) {
        for (long long b = 1; b <= 1000000; b++) {
            if(a*b<N){
                cnt++;
            }else{
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3708
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions
fn init_fact(n: u64, MOD: u64) -> (Vec<u64>, Vec<u64>, Vec<u64>){
    let mut fact = vec![1; n as usize];
    let mut finv = vec![1; n as usize];
    let mut inv  = vec![1; n as usize];
    for i in 2..n as usize{
        fact[i] = (fact[i-1] * i as u64) % MOD;
        inv[i]  = MOD - inv[(MOD as usize)%i] * (MOD/(i as u64))%MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
    return (fact,finv,inv);
}

fn nCr(n: u64, r: u64, MOD: u64, fact: &Vec<u64>, finv: &Vec<u64>) -> u64{
    if n<r { return 0; }
    return fact[n as usize] * (finv[r as usize] * finv[(n-r) as usize] % MOD) % MOD;
}

// Main
fn main(){
    input!{
        H: u64,
        W: u64,
        A: u64,
        B: u64,
    }
    let modulo = 1_000_000_007;
    let f = init_fact(200_000, modulo);
    let fact = f.0;
    let finv = f.1;

    let mut ans: u64 = 0;
    for i in 0..H-A{
        ans += nCr(i+B-1,i,modulo,&fact,&finv) * nCr(H-i-1+W-B-1,W-B-1,modulo,&fact,&finv);
        ans %= modulo;
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;


int main() {
    
    ld a,b,c,d;
    cin>>a>>b>>c>>d;
    ld tyo = d/60*360;
    ld tan = (c/12 + 1.0/12*d/60)*360;
    ld doo=abs(tan-tyo);
    // fin(doo);
    ld co = cos(doo/180*MATHPI);
    // fin(co);
    ld ans=a*a+b*b-2*a*b*co;
    printf("%.9Lf\n",sqrt(ans));
}



Measured memory_bytes: 4168
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int a = 0, b = 0;
	rep(i, s.size()){
		if(s[i] == '0') a++;
		else b++;
	}
	cout << min(a, b) * 2 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

YES = "yes"  # type: str
NO = "no"  # type: str

def solve(S: str):
    s = set(S)
    ret = YES
    if len(s) != len(S):
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060