akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;


public class Main {
    
         
    static FastReader in;
    static StringBuilder out;


    public static double dist(int x1, int b, double angle){
        double x2=b*Math.cos(angle), y2=b*Math.sin(angle);
        return Math.sqrt(Math.pow((x2-x1), 2)+y2*y2);
    }
    public  static void main(String[] args) {
        
        in = new FastReader();
        int a=in.nextInt(),b=in.nextInt(),h=in.nextInt(),m=in.nextInt();
        double minAn=2*Math.PI/60;
        minAn=minAn*(m%60);
        double houAn=2*Math.PI/720;
        houAn=houAn*(((h*60)+m)%720);
        System.out.println(dist(a, b, Math.abs(houAn-minAn)));
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
 
     
    
}

Measured memory_bytes: 33224
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n, cnt = 0,sum=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	a.push_back(-1);
	rep(i,n){
		if (a[i] == a[i+1])cnt++;
		else sum += (cnt+1)%2,cnt = 0;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

int main(void){
    ll n;
    cin >> n;

    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }    
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll al = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll cr = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        ans += al * cr;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1536
n, k = map(int, input().split(" "))
snukes = [0] * n
result = 0
for i in range(0, k):
    number_temp = input()
    snakes_temp = list(map(int, input().split(" ")))
    for n in snakes_temp:
        snukes[n-1]+=1
for i in snukes:
    if i==0:
        result+=1
print(result)

Measured memory_bytes: 9200
#include<stdio.h>
#include<math.h>
int main(){
	int n;
	double avg,sum,var,varplus;
	double stdev;
	double kurung,kurungg;
	for(int a=0;a<99999;a++){
		scanf("%d",&n);
		if(n==0)break;
		int S[n];
		for(int i=0;i<n;i++){
			scanf("%d",&S[i]);
		}
		sum=0;
		for(int i=0;i<n;i++){
			sum+=S[i];
		}
		avg=sum/n;
		varplus=0;
		for(int i=0;i<n;i++){
			kurungg=S[i]-avg;
			kurung=pow(kurungg,2);
			varplus+=kurung;
		}
		for(int i=0;i<n;i++){
			var=varplus/n;
			stdev=sqrt(var);
		}
		printf("%lf\n",stdev);
	}
	return 0;
}


Measured memory_bytes: 2740
#include <iostream>
using namespace std;int M[105][100005];int A[105];int main(){ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);int n, k;cin >> n >> k;for(int i = 0; i < n; i++)cin >> A[i];for(int i = 0; i <= A[0]; i++)M[0][i] = i+1;for(int i = A[0]+1; i <= k; i++)M[0][i] = M[0][A[0]];for(int i = 1; i < n; i++){M[i][0] = 1;for(int j = 1; j <= k; j++){M[i][j] = M[i][j-1];M[i][j] += (M[i-1][j] - (j - A[i] - 1 >= 0 ? M[i-1][j - A[i] - 1] : 0)) % 1000000007;M[i][j] %= 1000000007;}}cout << (M[n-1][k] - M[n-1][k-1] + 1000000007) % 1000000007;return 0;}


Measured memory_bytes: 41216
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main()
{
	
	int a;
	char s[10];

	scanf("%d%s", &a, s);

	if (a >= 3200)
		printf("%s", s);
	else
		printf("red\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const ll inf=0x3f3f3f3f3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
int n,m;
struct aaa{int x,y;ll z;};
vector<aaa> v,pr,se,chan;
struct segtree{
    ll dat[263000],n;
    void build(int nn)
    {
        n=1;
        while(n<=nn) n<<=1;
        for(int i=0;i<2*n-1;i++) dat[i]=inf;
    }
    void update(int k,ll a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=min(dat[(k<<1)+1],dat[(k<<1)+2]);
        }
    }
    ll query(int l,int r){
        return query(l,r+1,0,0,n);
    }
    ll query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return inf;
        if(a<=l&&r<=b) return dat[k];
        return min(query(a,b,(k<<1)+1,l,(l+r)>>1),query(a,b,(k<<1)+2,(l+r)>>1,r));
    }
}seg;
bool cmp(aaa x,aaa y){
    if(x.x!=y.x) return x.x<y.x;
    return x.z<y.z;
}
ll f[100005];
int main()
{
    scanf("%d%d",&n,&m);
    seg.build(n);
    rep(i,1,m){
        int t1,t2,t3;
        scanf("%d%d%d",&t1,&t2,&t3);
        v.pb((aaa){t1,t2,t3});
    }
    sort(v.begin(),v.end(),cmp);
    f[1]=0;
    int p=-1;
    seg.update(1,0);
    rep(i,1,n){
        while(p+1<m&&v[p+1].x==i) {
            p++;
            pr.pb(v[p]);
        }
        int nmx=i;
        rap(j,0,pr.size()){
            if(pr[j].y>nmx){
                se.pb((aaa){nmx,pr[j].y,pr[j].z});
                nmx=pr[j].y;
            }
        }
        //printf("%d\n",se.size());
        if(se.size()==0) chan.pb((aaa){i+1,i,inf});
        else{
            chan.pb((aaa){i+1,i,se[0].z});
            rap(j,0,se.size()){
                if(j==se.size()-1) chan.pb((aaa){se[j].y+1,i,inf});
                else chan.pb((aaa){se[j].y+1,i,se[j+1].z});//x:time
            }
        }
        pr.clear();se.clear();
    }
    sort(chan.begin(),chan.end(),cmp);
    p=-1;
    rep(i,1,n){
        while(p+1<chan.size()&&chan[p+1].x<=i){
            p++;//printf("%d %d %lld\n",chan[p].x,chan[p].y,chan[p].z);
            seg.update(chan[p].y,chan[p].z+f[chan[p].y]);
        }
        f[i]=seg.query(1,i);
        //printf("%d:%lld\n",i,f[i]);
    }
    if(f[n]>=inf) printf("-1");
    else printf("%lld",f[n]);
    return 0;
}

Measured memory_bytes: 9716
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 
char big(char c) {
  return c + 'A' - 'a';
}

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  if (s1.back() == s2[0] && s2.back() == s3[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

int get_gcd(int, int);

int main(int argc, char *argv[])
{
    int a, b;
    cin >> a >> b;

    cout << get_gcd(a, b) << endl;

    return 0;
}

int get_gcd(int x, int y)
{
    if (x < y)
    {
        using std::swap;
        swap(x, y);
    }
    int r = 0;
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }

    return x;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using std::cin;
using std::cout;



int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  std::string S;
  cin >> S;

  const int sz = S.size();
  int res = 2e9;
  for (int i = 0; i+3 <= sz; ++i)
  {
    int x = (S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
    res = std::min(res, std::abs(x - 753));
  }
  cout << res << "\n";

  return 0;
}


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

vw = [tuple(map(int, input().split())) for _ in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if vw[i][1] <= j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-vw[i][1]] + vw[i][0])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[-1][-1])


Measured memory_bytes: 25948
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){
    int n, m;
    int s, t;
    int a, b;
    vit mas[100005];
    int vis[100005][5];
    
    memset(vis,0x3f3f3f3f,sizeof(vis));
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        mas[a].push_back(b);
    }
    cin >> s >> t;
    vis[s][0] = 0;
    queue<pii> que;
    que.push(pii(s,0));
    while(!que.empty()) {
        int of = que.front().first;
        int os = que.front().second;
        int nf = vis[of][os++] + 1;
        int ns = os%3;
        que.pop();
        for(int i = 0; i < mas[of].size(); i++) {
            if( chmin(vis[mas[of][i]][ns], nf) ) {
                que.push(pii(mas[of][i],ns));
            }
        }
    }

    if( vis[t][0] != 0x3f3f3f3f ) {
        cout << vis[t][0]/3 fin;
    }
    else{
        cout << -1 fin;
    }
                
    
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int n, m; cin >> n >> m;
    vector<int> wa(n, 0);
    vector<bool> ac(n, false);
    int ans = 0;
    int pen = 0;

    for (int i = 0; i < m; ++i) {
        int num;
        string res;
        cin >> num >> res;
        if(res=="WA"&&!ac[num-1]) wa[num-1]++;
        if(res=="AC") ac[num-1] = true;
    }
    for (int j = 0; j < n; ++j) {
        if(ac[j]) {
            ans++;
            pen += wa[j];
        }
    }

    cout << ans << ' ' << pen << endl;

    return 0;

}


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

 int main(){

 int h,r;
cin>>h>>r;
if ( h + r < 0 )cout<<"-1"<<endl;
else if (h + r > 0 )cout<<"1"<<endl;
else if ( h + r == 0 )cout<<"0"<<endl;
return 0; 
}



Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll out = 0;
    rep(i,N){
        if(i==0 || S[i] != S[i-1]) out++;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  int m,f,r;
  int i = 0;
  int j = 0;
  int a[1000][3];
  for(i = 0;i < 10000;i++){
    cin  >>  m >> f >> r;
    a[i][0] = m;
    a[i][1] = f;
    a[i][2] = r;
    if(m == -1 && f == -1 && r == -1){
      break;
    }
  }
  for(j = 0;j < i;j++){
    if(a[j][0]== -1 || a[j][1] == -1){
      cout << "F" <<endl;
    }else if(a[j][0]+a[j][1] >= 80){
      cout <<"A"<<endl;
    }else if(a[j][0]+a[j][1] >=65 && a[j][0]+a[j][1] < 80){
      cout <<"B" << endl;
    }else if(a[j][0]+a[j][1] >= 50 && a[j][0]+a[j][1] <65){
      cout <<"C"<<endl;
    }else if(a[j][0]+a[j][1] >=30 && a[j][0]+a[j][1] < 50){
      if(a[j][2] < 50){
        cout <<"D"<<endl;
      }else{
        cout <<"C"<<endl;
      }
    }else{
      cout <<"F"<<endl;
    }
  }
}

Measured memory_bytes: 3080
#include<iostream>
 
using namespace std;
 
int D[100][2];
 
int main()
{
	int n;
	cin>>n;
    //take input
    for(int  i =0; i < n; i++)
    {
    	cin>>D[i][0];
        cin>>D[i][1];
    }
    //check doublets
    for (int i = 0; i < n-2; i++)
    {
    	if (D[i][0] == D[i][1])
        {
        	if (D[i+1][0] == D[i+1][1])
            {
            	if (D[i+2][0] == D[i+2][1])
                {
                	cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
const int N = 1e5 + 7;
#define int long long
vector <int> ps1[N * 4], ps2[N * 4];
map <int, int> bp, cp;
int ps[N][4];
struct human {
	int a, b, c;
};
int x, y, z, n;
human a[N], b[N], c[N]; 
int res[N][4];

void add(int p, int x1, int x2, int v = 1, int s = 0, int e = N - 7) {
	ps1[v].push_back(ps1[v].back() + x1);
	ps2[v].push_back(ps2[v].back() + x2);
	if (e - s == 1)
		return;
	if (p < mid)
		add(p, x1, x2, v * 2, s, mid);
	else
		add(p, x1, x2, v * 2 + 1, mid, e);
}

pair <int, int> get(int need, int v = 1, int s = 0, int e = N - 7) {
	if (need == 0)
		return {0, 0};
	if (e - s == 1)
		return {ps1[v][need], ps2[v][need ]};
	if (ps1[2 * v].size() - 1 >= need)
		return get(need, v * 2, s, mid);
	pair <int, int> tmp = {ps1[v * 2].back(), ps2[v * 2].back()}, ttp;
	need -= (int)ps1[2 * v].size() - 1;
	ttp = get(need, 2 * v + 1, mid, e);
	return {ttp.first + tmp.first, ttp.second + tmp.second};
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for (int i = 0; i < 4 * N; i++)
		ps1[i].push_back(0), ps2[i].push_back(0);
	cin >> x >> y >> z;
	n = x + y + z;
	for (int i = 1; i <= n; i++)
		cin >> a[i].a >> a[i].b >> a[i].c, b[i] = c[i] = a[i];
	sort (a + 1, a + n + 1, [](human x, human y) {
		return x.a + y.b > x.b + y.a;	
	});
	sort (b + 1, b + n + 1, [](human x, human y) {
		return x.a + y.c > x.c + y.a;		
	});
	sort (c + 1, c + n + 1, [](human x, human y) {
		return x.b + y.c > x.c + y.b;		
	});
	for (int i = 1; i <= n; i++) {
		bp[b[i].a - b[i].c] = i;
		cp[c[i].b - c[i].c] = i;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 3; j++)
			ps[i][j] = ps[i - 1][j];
		ps[i][1] += a[i].a;
		ps[i][2] += a[i].b;
		ps[i][3] += a[i].c;
	}
	for (int i = 1; i <= n; i++) {
		add(bp[a[i].a - a[i].c], a[i].a, a[i].c);
		if (i >= x) {
//			cout << "res of first : " << i << " : ";
			pair <int, int> tmp = get(x);
			res[i][1] = tmp.first + ps[i][3] - tmp.second;
//			cout << tmp.first << " " << tmp.second << " " << ps[i][3] << " " << res[i][1] << endl;
		}	
	}
	for (int i = 0; i < 4 * N; i++) {
		ps1[i].clear();
		ps2[i].clear();
		ps1[i].push_back(0);
		ps2[i].push_back(0);
	}
	for (int i = n; i >= 1; i--) {
		add(cp[a[i].b - a[i].c], a[i].b, a[i].c);
		if (i <= n - y + 1) {
			pair <int, int> tmp = get(y);
			res[i][2] = tmp.first + (ps[n][3] - ps[i - 1][3]) - tmp.second; 
//			cout << "res of second : " << i << " " << tmp.first << " " << tmp.second << " " << ps[n][3] - ps[i - 1][3] << " " << res[i][2] << endl; 
		}
	}
	int ans = 0;
	for (int i = x + 1; i <= n - y + 1; i++) {
		ans = max(ans, res[i - 1][1] + res[i][2]);
//		cout << "ans can be : " << i << " " << res[i - 1][1] << " " << res[i][2] << endl;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 103648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const long double PI = 3.14159265358979323846264338327950L;

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

    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    
    long double rad = PI * 2. * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);

    long double rsq = (long double)(a * a + b * b) - (long double)(2. * a * b) * cosl(rad);

    cout << setprecision(20) << sqrtl(rsq) << endl;
    return 0;
}


Measured memory_bytes: 4132
//#define DEBUG

#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using Edge = pair<int, int>;

#ifdef DEBUG

#include <cassert>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
using namespace boost;
using Graph = adjacency_list<listS, vecS, undirectedS, no_property, property<edge_weight_t, int>>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;

void Test(size_t vertex, const vector<Edge>& edge, int K) {
    vector<int> weight(edge.size(), 1);
    Graph graph(edge.begin(), edge.end(), weight.begin(), vertex);
    vector<Vertex> parents(num_vertices(graph));
    vector<size_t> distance(num_vertices(graph));
    int cnt = 0;
    for (int from = 0; from < vertex; from++) {
        dijkstra_shortest_paths(graph, from, predecessor_map(&parents[0]).distance_map(&distance[0]));
        for (int to = from + 1; to < vertex; to++) if (distance[to] == 2) cnt++;
    }
    assert(cnt == K);
}

#endif

int main() {
    int N, K; cin >> N >> K;

    if (K > (N - 1) * (N - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }

    cout << N * (N - 1) / 2 - K << endl;

    // star
    vector<Edge> edge;
    edge.reserve(N * (N - 1) / 2);
    for (int i = 1; i < N; i++) {
        edge.push_back(make_pair(0, i));
        cout << 1 << " " << i + 1 << endl;
    }

    // extra edges
    int cnt = 0, limit = (N - 1) * (N - 2) / 2 - K;
    for (int i = 1; i < N && cnt < limit; i++) {
        for (int j = i + 1; j < N && cnt < limit; j++, cnt++) {
            edge.push_back(make_pair(i, j));
            cout << i + 1 << " " << j + 1 << endl;
        }
    }

#ifdef DEBUG
    Test(N, edge, K);
#endif
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = b - a;
        int d = c * (c + 1) / 2  - b;
        System.out.println(d);
    }

}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 1e9+7;
const int N = 2e5+205;
void solve(){
	int n; 
	cin>>n; 
	int cnt = 0;
	bool can = false;
	for(int i=0;i<n;i++){
		int x,y; 
		cin>>x>>y;
		if(x==y)cnt++;
		else cnt = 0;
		if(cnt>=3)can = true;
	}
	if(can)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s; 
	cin >> s;
	int mod = 0;
	for (char c : s) {
		mod += c - '0';
		mod %= 9;
	}
	cout << (mod == 0 ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n,x,y,z;
int dp[64][262144];
int main(){
	cin >> n >> x >> y >> z;
	const int fullmask = 1 << x+y+z+1;
	dp[0][1] = 1;
	for( int i = 0 ; i < n ; ++i )
		for( int mask = 0 ; mask < fullmask ; ++mask )
			for( int u = 1 ; u <= 10 ; ++u ){
				int vmask = (mask << u | 1) & fullmask-1;
				if( (vmask>>z&1) and (vmask>>y+z&1) and (vmask>>x+y+z&1) ) continue;
				dp[i+1][vmask] = (dp[i+1][vmask]+dp[i][mask]) % MOD;
			}
	int sub = 0; for( int mask = 0 ; mask < fullmask ; ++mask ) sub = (sub+dp[n][mask]) % MOD;
	int all = 1; for( int i = 0 ; i < n ; ++i ) all = all*10LL % MOD;
	cout << (all-sub+MOD)%MOD << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	int n, k;
	cin >> n >> k;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		int a = min(k - x, x);
		sum += a * 2;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N;
	vector<int> A, B;

	cin >> N;
    A.push_back(0);
	for (int i = 0; i < N; i++) {
		ll Ai;
		cin >> Ai;
		A.push_back(Ai);
	}
    A.push_back(0);
    for (int i = 0; i < N+1; i++) {
        B.push_back(abs(A[i]-A[i+1]));
    }
    int sum = accumulate(B.begin(), B.end(), 0);
    for (int i = 0; i < N; i++) {
        int res = sum;
        res -= B[i]+B[i+1];
        res += abs(A[i]-A[i+2]);
        cout << res << endl;
    }
	return 0;
}

Measured memory_bytes: 2168
#include "bits/stdc++.h"
using namespace std;
string Cipher(int &pos, string &S);
string String(int &pos, string &S);
char Letter(int &pos, string &S);
string Cipher(int &pos, string &S) {
	string ret = "";
	while (1) {
		ret += String(pos, S);
		if (S[pos] == ']' || pos >= S.size()) break;
	}
	return ret;
}
string String(int &pos, string &S) {
	if (S[pos] == '[') {
		pos++;
		string s = Cipher(pos, S);
		pos++;
		reverse(s.begin(), s.end());
		return s;
	}
	else {
		char ch = Letter(pos, S);
		return string(1, ch);
	}
}
char Letter(int &pos, string &S) {
	if (S[pos] == '+') {
		pos++;
		char ch = Letter(pos, S);
		if (ch == '?') return ch;
		ch -= 'A';
		(ch += 1) %= 26;
		return ch + 'A';
	}
	else if (S[pos] == '-') {
		pos++;
		char ch = Letter(pos, S);
		if (ch == '?') return ch;
		ch -= 'A';
		(ch += 25) %= 26;
		return ch + 'A';
	}
	char ch = S[pos];
	pos++;
	return ch;
}
int main() {
	string S;
	while (cin >> S, S != ".") {
		int pos = 0;
		string T = Cipher(pos, S);
		for (int i = 0; i < T.size(); i++) if (T[i] == '?') T[i] = 'A';
		cout << T << endl;
	}
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int a = in.readInt(); 
		int b = in.readInt();
		if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)
		System.out.println("Possible");
		else System.out.println("Impossible");
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

Measured memory_bytes: 23124
import java.util.*;
import java.lang.*;

public class Main {

    public static void main (String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();

        for (int p = 1; p < 2000; p++) {
            if ((int) (p * .08) == a && (int) (p * .1) == b) {
                System.out.println(p);
                return;
            }
        }
        System.out.println(-1);
    }
}

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

using ll = long long;


ll N,K;

int my_b_search(ll key,ll val,bool mode,vector<int64_t>& A){
    //mode -> true ならば昇順での二分探索 falseなら降順での二分探索
    int ok = mode ? -1 : N;
    int ng = mode ? N : -1;
    while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(val*A[mid]<=key)ok=mid;
        else ng=mid;
    }
    return ok;
}

bool f(ll key,vector<int64_t>& A){
    ll cnt=0;
    for(int i=0;i<N;i++){
        if(A[i]>=0){
            cnt+=my_b_search(key,A[i],true,A)+1;
        }else{
            cnt+=N-my_b_search(key,A[i],false,A);
        }
        if(key>=A[i]*A[i])cnt--;
    }
    return cnt>=2*K;
}


int main(){
    
    cin>>N>>K;
    vector<int64_t> A(N);

    for(int64_t& a:A){
        cin>>a;
    }

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

    int64_t ok=1e18,ng=-1e18;
    while(ok-ng!=1){
        int64_t mid=(ok+ng)/2;

        if(f(mid,A)){
            ok=mid;
        }else{
            ng=mid;
        }
    }

    cout<<ok<<endl;

}

Measured memory_bytes: 1792
using System;

namespace ABC_072_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int X = int.Parse(word[0]);
            int t = int.Parse(word[1]);
            if (X < t)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(X - t);
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
program row_to_column
  implicit none
  integer :: n, a(500,500) = 0, i, j, r, c = 0, x
  character(500) :: s
  read(*,*) n
  do i = 1, n
    read(*,*) s
    do j = 1, n
      if (s(j:j) == "#") a(i,j) = 1
    end do
  end do
  if (sum(a(1:n,1:n)) == 0) then
    write(*,'(i0)') -1
    stop
  end if
  do j = 1, n
    if (sum(a(1:n,j)) /= n) c = c+1
  end do
  r = n+1
  do i = 1, n
    x = 0
    if (sum(a(1:n,i)) == 0) x = 1
    x = x+n-sum(a(i,1:n))
    r = min(r,x)
  end do
  write(*,'(i0)') r+c
end program row_to_column

Measured memory_bytes: 1152
import queue
N,M = map(int,input().split())
adj = [[]for i in range(N+1)]
parent = [-1] * (N+1)
for m in range(M):
    a,b = map(int,input().split())
    adj[a].append(b)
    adj[b].append(a)
q = queue.Queue()
q.put((1,0)) # 自分、親
while(not q.empty()):
    x, p = q.get()
    if parent[x] != -1:
        continue
    parent[x] = p
    for next in adj[x]:
        if parent[next] == -1:
            q.put((next,x))
#print (parent)

print ('Yes')
for p in parent[2:]:
    print(p)

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

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

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

  int n;
  cin >> n;
  vector<int> ve;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ve.emplace_back(x);
  }
  sort(ve.begin(), ve.end(), greater<int>());
  int cur = 1;
  int tot = 1;
  ll sum = ve[0];
  while(tot < n - 1) {
    sum = sum + 1LL * ve[cur];
    tot++;
    if(tot == n - 1) break;
    sum = sum + 1LL * ve[cur];
    tot++;
    cur++;
  }
  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 4280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    
    int H,W;cin>>H>>W;
    vector<vector<int>> S(H,vector<int>(W)),A(H,vector<int>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>S[i][j];
        }
    }
    
    for(int j=0;j<W;j++){
        if(S[H-1][j]) A[H-1][j]=0;
        else A[H-1][j]=1;
    }
    
    for(int j=0;j<W;j++){
        for(int i=H-2;i>=0;i--){
            if(S[i][j]) A[i][j]=0;
            else A[i][j]=A[i+1][j]+1;
        }
    }
    
    int ans=0;
    
    for(int i=0;i<H;i++){
        stack<pair<int,int>> ST;
        vector<int> L(W),R(W);
        for(int j=0;j<W;j++){
            if(ST.empty()){
                L[j]=0;
                ST.push(make_pair(A[i][j],j));
            }
            else if(ST.top().first<A[i][j]){
                L[j]=ST.top().second+1;
                ST.push(make_pair(A[i][j],j));
            }else if(ST.top().first>=A[i][j]){
                while(!ST.empty()&&ST.top().first>=A[i][j]){
                    ST.pop();
                }
                if(ST.empty()) L[j]=0;
                else L[j]=ST.top().second+1;
                ST.push(make_pair(A[i][j],j));
            }
        }
        reverse(all(A[i]));
        
        while(!ST.empty()) ST.pop();
        
        for(int j=0;j<W;j++){
            if(ST.empty()){
                R[j]=0;
                ST.push(make_pair(A[i][j],j));
            }
            else if(ST.top().first<A[i][j]){
                R[j]=ST.top().second+1;
                ST.push(make_pair(A[i][j],j));
            }else if(ST.top().first>=A[i][j]){
                while(!ST.empty()&&ST.top().first>=A[i][j]){
                    ST.pop();
                }
                if(ST.empty()) R[j]=0;
                else R[j]=ST.top().second+1;
                ST.push(make_pair(A[i][j],j));
            }
            R[j]=W-R[j];
        }
        reverse(all(R));
        reverse(all(A[i]));
        
        for(int j=0;j<W;j++){
            ans=max(ans,A[i][j]*(R[j]-L[j]));
        }
        
        /*for(int j=0;j<W;j++){
            ans=max(ans,A[i][j]*(R[j]-L[j]));
            cout<<R[j];
            cout<<" ";
        }
        cout<<endl;*/
    }
    
    cout<<ans<<endl;
    
}




Measured memory_bytes: 17972
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int x=0;
  int y=0;
  for(int i=0;i<s.size()/2;i++){
    if(s[i]==s[s.size()-i-1]){
      x++;
    }
  }
  if(s.size()%4==1){
    for(int i=0;i<s.size()/2;i++){
      if(s[i]==s[s.size()/2-i-1]&&s[s.size()/2+1+i]==s[s.size()-1-i]){
        y++;
      }
    }
  }
  else{
    for(int i=0;i<s.size()/2;i++){
      if(s[i]==s[s.size()/2-1-i]&&s[s.size()/2+i+1]==s[s.size()-1-i]){
        y++;
      }
    }
  }
  //cout<<x<<y;
  if(x==s.size()/2&&y==s.size()/2){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
from itertools import permutations

n,m=map(int,input().split())
es=set()
for _ in range(m):
    u,v=map(int,input().split())
    es|={(u-1,v-1),(v-1,u-1)}

print(sum(all((u,v) in es for u,v in zip(p,p[1:]))
          for p in permutations(range(n)) if p[0]==0))


Measured memory_bytes: 3060
#include <iostream>
//#include <numeric>
//#include <vector>
	//#include<math.h>
	//#include <algorithm>
	//#include <functional>
	//#include <numeric>
	//#include<cmath>
//#include <stdio.h> 
//#include <cstdint>
	//#include <string>
	//#include <cstdlib>
	//#define pi 3.14159265359
using namespace std;


	int main() {

		string a, b;
		cin >> a >>b;

		if (a == b) {
				cout << "Yes";
		}

		else {
				cout << "No";
		}
		


		return 0;

	}

Measured memory_bytes: 256
# 2019/07/20

from heapq import heappop,heappush,heapify

n,m=map(int,input().split())
a=list(map(int,input().split()))
heapify(a)
bc=[]
for i in range(m):
    b,c=map(int,input().split())
    hq=(-c,b)
    heappush(bc,hq)



def cg(res):

    while bc:
        c,b=heappop(bc)
        c=-c
        while b and a:
            b-=1
            v=heappop(a)
            if c>v:res+=c
            else:
                res+=v
                return res
    return res
res=0
res=cg(res)
print(sum(a)+res)

Measured memory_bytes: 91416
x, y = map(int, input().split())


def f1(x, y):
    if y >= x:
        return y - x
    else:
        return 10**10


def f2(x, y):
    if -y >= x:
        return -y - x + 1
    else:
        return 10**10


def f3(x, y):
    if y >= -x:
        return y + x + 1
    else:
        return 10**10


def f4(x, y):
    if -y >= -x:
        return -y + x + 2
    else:
        return 10**10


ans = min(f1(x, y), f2(x, y), f3(x, y), f4(x, y))
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,a,maxi;
long long s;
int main()
{ cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin>>n;
  for(int i=1;i<=n;i++)
  { cin>>a;
    maxi=max(a,maxi);
    s+=maxi-a;
  }
  cout<<s<<'\n';
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

void solve()
{
	ll x,y;
	cin>>x>>y;
	for(ll i=1;i<=y;i++)
	{
		ll h=y-i;
		if(h%4==0 && i%2==0)
		{
			ll k=h/4;
			ll g=i/2;
			if((k+g)==x)
			{
				cout<<"Yes";
				return;
			}
		}
		if(h%2==0 && i%4==0)
		{
			ll k=h/2;
			ll g=i/4;
			if((k+g)==x)
			{
				cout<<"Yes";
				return;
			}
		}
	}
	cout<<"No";
}
int main()
{
	fast;
	ll t=1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int ans=0;
void aout(void){
	cout<<ans<<endl;
}
void out(int a){
	cout<<a<<endl;
}
int main(void){
	int n,i,j;
	cin>>n;
	if(n<=999){
		printf("ABC\n");
	}else{
		printf("ABD\n");
	}
	return 0;
}

Measured memory_bytes: 256
# print('input >>')
N = int(input())
Xs = list(map(int,(input().split())))

ans = 10 ** 10
for i in range(1,101):
    mps = 0
    for X in Xs:
        mps += (X - i)**2
    ans = min(ans, mps)

# print('-----output-----')
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

const int MXN = 1e6+6;
int in[MXN];
int n;
int ust[MXN];

int result = 1e9;
int go(int at_least)
  {
  VI stac;
  int sum = 0;
  FOR(i, 1, n)
    {
    if(in[i] != 0){sum += in[i]; ust[i] = in[i];}
    else
      {
      ust[i] = -1;
      sum--;
      stac.PB(i);
      }

    while(sum < at_least)
      {
      if(stac.size() == 0)return 1e9;
      ust[stac.back()] = 1;
      sum+=2;
      stac.pop_back();
      }
    }

//  debug(VI(ust+1, ust+n+1));

  sum = 0;
  int mx = 0;
  int mi = 0;
  FOR(i, 1, n)
    {
    assert(ust[i] != 0);
    sum += ust[i];
    assert(sum >= at_least);
    maxi(mx, sum);
    mini(mi, sum);
    }
  

//  debug(mi, mx);
  mini(result, mx-mi);
  return mx - mi;
  }

PII calc_seg()
  {
  int sum1 = 0;
  int sum2 = 0;
  int mi1 = 0, mi2 = 0;
  FOR(i, 1, n)
    {
    if(in[i] != 0)
      {
      sum1 += in[i];
      sum2 += in[i];
      }
    else
      {
      sum1++;
      sum2--;
      }
    mini(mi1, sum1);
    mini(mi2, sum2);
    }
  debug(mi2, mi1);
  return {mi2, mi1};
  }


int main()
  {
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  n = s.size();

  FOR(i, 1, n)in[i] = (s[i-1] == '1') ? 1 : (s[i-1] == '0' ? -1 : 0);

  auto r = calc_seg();
//  go(0);return 0;

  go(r.f);
  go(r.s);

//  FOR(i, r.f, r.s)debug(i, go(i));

  int poc = r.f;
  int kon = r.s;
  REP(i, 20)
    {
    int s1 = (poc+kon)/2;
    if(s1 % 2 == 0)s1++;
    int s2 = s1+2;

    if(go(s1) < go(s2))kon = s1-1;
    else poc = s2+1;
    }

  poc = r.f;
  kon = r.s;
  REP(i, 20)
    {
    int s1 = (poc+kon)/2;
    if(s1 % 2 != 0)s1++;
    int s2 = s1+2;

    if(go(s1) < go(s2))kon = s1-1;
    else poc = s2+1;
    }
  debug(poc, kon);
  cout << result << endl;
  }


Measured memory_bytes: 19152
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long K = Long.parseLong(sc.next());
		
		String ans = "";
		int cnt = 0;
		for(int i = 0; i < S.length(); i++) {
			if(!S.substring(i, i + 1).equals("1")) {
				ans = S.substring(i, i + 1);
				break;
			} else {
				cnt++;
				if(cnt == K) {
					ans = "1";
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;


int main(){
	int n;
	int cnt = 0;
	int cnt1 = 0;
	cin >> n ;
	int a;
	for (int i = 0;i < n;i++){
		cin >> a;
		if ( a% 4 == 0) cnt++,cnt1++;
		else if (a % 2 == 1) cnt++;
	}
	int need = cnt/2;
	if (cnt != n){
		if (cnt % 2) need++;
	}
	if (cnt1 >= need) cout << "Yes"<< endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
def main():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    
    def divisor(n):
        ass = []
        for i in range(1,int(n**0.5)+1):
            if n%i == 0:
                ass.append(i)
                if i**2 == n:
                    continue
                ass.append(n//i)
        return ass
    
    def is_prime(n):
        if n == 1:
            return True
        for i in range(2,int(n**0.5)+1):
            if n % i == 0:
                return False
        return True
    
    a,b=map(int,input().split())
    c=gcd(a,b)
    cnt=0
    d=divisor(c)
    for i in d:
        if is_prime(i):
            cnt+=1
    print(cnt)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3268
// aribon3-1-4_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


struct BIT {
    int sz;
    vector<int> tree;

    BIT(int n) {
        sz = n;
        tree.resize(n+1);
    }

    ll sum(int i){
        ll sm = 0;
        while (i > 0){
            sm += tree[i];
            i -= i & -i;
        }
        return sm;
    }

    void add(int i, int x){
        while (i <= sz){
            tree[i] += x;
            i += i & -i;
        }
    }
};



int main() {
#ifdef LOCAL
    ifstream in("../b05.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, K;
    cin >> N >> K;

    vector<ll> A(N);
    int a;
    REP(i, N) {
        cin >> a;
        A[i] = a - K;
    }

    vector<ll> cumsum(N+1, 0);
    REP(i, N){
        cumsum[i+1] += A[i] + cumsum[i];
    }

    vector<int> cumsum_zip(N+1);
    iota(ALL(cumsum_zip), 1);
    stable_sort(ALL(cumsum_zip), [&](int i, int j){
        return cumsum[i-1] < cumsum[j-1];
    });

    auto bit = BIT(N+2);
    ll ans = 0;
    REP(i, N+1){
        ans += bit.sum(cumsum_zip[i]);
        bit.add(cumsum_zip[i], 1);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 4984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
int dp[1 << 13];
map<int, int>mp;
int main() {
	int n, m;
	cin >> n >> m;
	mset(dp, 0x3f);
	mset(dp, 0x3f);
	dp[0] = 0;
	rep(i, 1, m) {
		int w, k;
		cin >> w >> k;
		int tmp = 0;
		rep(i, 1, k) {
			int c;
			cin >> c;
			tmp |= 1 << c - 1;
		}
		if (mp[tmp]) mp[tmp] = min(w, mp[tmp]);
		else mp[tmp] = w;
	}
	for (int i = 0; i < 1 << n; i++) {
		for (auto v : mp) {
			dp[i | v.first] = min(dp[i] + v.second, dp[i | v.first]);
		}
	}
	if (dp[(1 << n) - 1] == 0x3f3f3f3f) cout << -1 << '\n';
	else cout << dp[(1 << n )- 1] << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<int> C(N - 1, 0);
    vector<int> S(N - 1, 0);
    vector<int> F(N - 1, 0);
    vector<int> ans(N, 0);

    for (int i = 0; i < N - 1; i++) {
        int c, s, f;
        cin >> c >> s >> f;
        C[i] = c;
        S[i] = s;
        F[i] = f;
    }

    for (int i = 0; i < N - 1; i++) {
        int start = S[i] + C[i];
        for (int j = i + 1; j < N - 1; j++) {
            start = max(((start + F[j] - 1) / F[j] ) * F[j], S[j]) + C[j];
        }
        ans[i] = start;
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << "\n";
    }


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define min(a,b) ((a) < (b) ? (a):(b))
main(){
    int H,W;
    scanf("%d %d\n",&H,&W);
    int semi[H][W];
    int fukai[H][W];
    int i,j,k;

    for(i=0;i<H;i++){
        for(j=0;j<W;j++)
            semi[i][j]=getchar()-'0';
        getchar();
    }
    fukai[0][0]=0;

    for(i=1;i<H+W-1;i++){
        for(j=0;i-j>=0;j++){
            if(i-j>=W||j>=H)continue;
            if(i-j==0)
                fukai[j][i-j]=fukai[j-1][i-j]+semi[j][i-j];
            else if(j==0)
                fukai[j][i-j]=fukai[j][i-j-1]+semi[j][i-j];
            else
                fukai[j][i-j]=min(fukai[j-1][i-j],fukai[j][i-j-1])+semi[j][i-j];
        }
    }

    printf("%d\n",fukai[H-1][W-1]);
    return 0;
}

Measured memory_bytes: 616