akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = acos(-1) ;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans;
	ll a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	ll as=0,bs=0;
	for(ll i=0;i<n;i++)
	{
		if(s.at(i)=='a'&& as+bs<a+b)cout<<"Yes"<<nw,as++;
		else if(s.at(i)=='b'&& as+bs<a+b && bs<b)
			cout<<"Yes"<<nw,bs++;
		else cout<<"No"<<nw;
	}

}


Measured memory_bytes: 3744
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,j,l,k;
	char a[105][105],c;
	while(~scanf("%d%d",&n,&l))
	{getchar();
	 for(i=0;i<n;i++)
	 {
	  for(j=0;j<l;j++)
	  scanf("%c",&a[i][j]);
	  getchar();
	 }
	 for(i=0;i<n-1;i++)
	 for(j=0;j<n-1-i;j++)
	 if(strcmp(a[j],a[j+1])>0)
	 for(k=0;k<l;k++)
	  {c=a[j][k];
	   a[j][k]=a[j+1][k];
	   a[j+1][k]=c;
	  }
	for(i=0;i<n;i++)
    for(j=0;j<l;j++)
    printf("%c",a[i][j]);
    printf("\n");
}
}

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

using namespace std;

#define ll long long
#define sf scanf
#define pf printf 
#define nl printf("\n")

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("in.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif

	ll n,k,res;
	sf("%lld %lld",&n,&k);
	if(n%k==0) res = 0;
	else{
		res = min((n-(k*(n/k))),(k*((n/k)+1))-n);
	}
	pf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{

	int a, b, c;
	cin >> a >> b >> c;

	if(b/a >= c){
		cout << c << endl;
	}else{
		cout << b/a << endl;
	}
	return 0;
}

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

sou = sum(A)

ritu = sou / (4*M)


kazu = 0
for i in A:
    if i >= ritu:
        kazu += 1
    else:
        continue

if kazu >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
n,l = map(int,input().split())

ans = 0
if l >= 0:
     for i in range(n-1):
          ans += l+i+1
elif l <= 0 <= l+n-1:
     for i in range(n):
          ans += l+i
else:
     for i in range(n-1):
          ans += l + i
print(ans)


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

int main(){
	int m,d;
	int mm[]={31,29,31,30,31,30,31,31,30,31,30,31};
	string s[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	while(cin>>m>>d){
		if(m==0)break;
		int dd=0;
		for(int i=0;i<m-1;i++)dd+=mm[i];
		dd+=d;
		int ans=(dd+2)%7;
		//cout<<dd<<endl;
		cout<<s[ans]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
const long NUM = 1000000007;
 
int main()
{
	int n, m;
	cin >> n >> m;
 
	vector<bool> ok(n+1, true);
	for (int i = 0; i < m; ++i)
	{
		int input;
		cin >> input;
		ok[input] = false;
	}
 
	vector<long> dp(n+1);
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j <= min(i + 2, n); ++j)
		{
			if (ok[j])
            {
              	dp[j] += dp[i];
				dp[j] %= NUM;
            }
		}
	}
 
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections       #-}

import           Control.Monad       (foldM, replicateM, unless, when)
import           Control.Monad.ST    (ST, runST)
import           Data.Foldable       (for_)
import qualified Data.Vector         as V (enumFromTo, thaw)
import           Data.Vector.Mutable (STVector)
import qualified Data.Vector.Mutable as V (read, write)

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  bridges <- replicateM m $ do
    [a, b] <- map read . words <$> getLine
    pure (a, b)
  for_ (solve n bridges) print

type Island = Int
type Bridge = (Island, Island)
type Inconvenience = Int

solve :: Int -> [Bridge] -> [Inconvenience]
solve n bridges =
  tail $ runST $ do
    uf <- toUnionFind n

    let
      f [] _ = error "first arguement will not be empty"
      f is@(inconvenience : _) (i1, i2) = do
        (s1, contain1) <- find i1 uf
        (s2, contain2) <- find i2 uf
        let bothContained = contain1 == contain2

        unless bothContained $ unite i1 i2 uf

        pure $ (inconvenience - (if bothContained then 0 else s1 * s2)) : is

    foldM f [maxInconvenience] $ reverse bridges
  where
    maxInconvenience :: Inconvenience
    maxInconvenience = n * (n - 1) `div` 2

type Size = Int
type UnionFind s a = STVector s (Size, a)

toUnionFind :: Int -> ST s (UnionFind s Int)
toUnionFind n = V.thaw $ (1,) <$> V.enumFromTo 0 n

find :: Int -> UnionFind s Int -> ST s (Size, Int)
find i uf = do
  (s, i') <- V.read uf i

  if i' == i
    then pure (s, i)
    else do
      (s', i'') <- find i' uf
      V.write uf i' (s', i'') -- path compression
      pure (s', i'')

unite :: Int -> Int -> UnionFind s Int -> ST s ()
unite i1 i2 uf = do
  (s1, representative1) <- find i1 uf
  (s2, representative2) <- find i2 uf

  when (representative1 /= representative2) $ do
    V.write uf representative1 (s1, representative2)
    V.write uf representative2 (s1 + s2, representative2)

{-
-- 素朴なリストでは TLE

type UnionFind a = [[a]]

toUnionFind :: [a] -> UnionFind a
toUnionFind = map pure

find :: Eq a => a -> UnionFind a -> (Size, [a])
find x xss =
  let
    xs = fromJust $ L.find (x `elem`) xss
  in
    (length xs, xs)

union :: Eq a => a -> a -> UnionFind a -> UnionFind a
union x1 x2 xss =
  let
    (contain1, notContain1) = partition (x1 `elem`) xss
    (contain2, notContain2) = partition (x2 `elem`) xss
    containNeither = notContain1 `intersect` notContain2
  in
    (head contain1 ++ head contain2) : containNeither
-}


Measured memory_bytes: 76284
#include <iostream>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,d;
    int ans=0;
    cin >> n >> d;
    ans = n / (d*2+1);
    if (n % (d*2+1) != 0) {
        ans++;
    }
    cout << ans << "\n";
}

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

int main(){
  int n;
  const int M=256;
  while(cin>>n,n){
    vector<int> l(n);
    for(int i=0;i<n;i++){
      cin>>l[i];
    }

    double res=1e9;
    int ress=-1;
    int resa=-1;
    int resc=-1;
    for(int s=0;s<=15;s++){
      for(int a=0;a<=15;a++){
	for(int c=0;c<=15;c++){
	  vector<int> r(n);
	  int pre=s;
	  for(int i=0;i<n;i++){
	    r[i]=(a*pre+c)%M;
	    pre=r[i];
	  }
	  vector<int> o(n);
	  for(int i=0;i<n;i++) o[i]=(l[i]+r[i])%M;

	  vector<int> x(256,0);
	  for(int i=0;i<n;i++) x[o[i]]++;
	  double h=0;
	  for(int i=0;i<256;i++){
	    if(x[i]!=0){
	      h+=(-1.0*x[i]/n*log(1.0*x[i]/n));
	    }
	  }
	  const double EPS=1e-9;
	  if(h<res-EPS){
	    res=h;
	    ress=s;
	    resa=a;
	    resc=c;
	  }
	  
	}
	


      }


    }
      cout<<ress<<" "<<resa<<" "<<resc<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3356
import java.io.IOException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		
		while (true) {
			String [] line = scanner.nextLine().split(" ");
			int m = Integer.parseInt(line[0]);
			int f = Integer.parseInt(line[1]);
			int totalTest = m + f;
			int r = Integer.parseInt(line[2]);
			if (totalTest + r == -3) {
				break;
			}
			if (totalTest < 30 ||m == -1 || f == -1) {
				System.out.println("F");
			} else {
				if (totalTest >= 80)
					System.out.println("A");
				if (totalTest < 80 && totalTest >= 65)
					System.out.println("B");
				if (totalTest < 65 && totalTest >= 50)
					System.out.println("C");
				if (totalTest >= 30 && totalTest < 50 && r >= 50)
					System.out.println("C");
				if (totalTest >= 30 && totalTest < 50 && r < 50)
					System.out.println("D");
			}
		}
	}
}

Measured memory_bytes: 26032
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
  long n,k,i,f,l;
  long sum1=0;
  long sum2=0;
  long r=0;
  cin>>n>>k;
  for(i=k;i<=n+1;++i){
    f=i*(i-1)/2;
    l=(n*2-i+1)*i/2;
    sum1=l-f+1;
    sum2=(sum2+sum1)%mod;
  }
  cout<<sum2;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int workdays = 0;
  int tmp = 0;
  for(int i=0;i<M;i++){
    cin >> tmp;
    workdays += tmp;
  }

  if(N-workdays < 0){
    cout << -1 << endl;
  }else{
    cout << N - workdays << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int main() {
  int n, h, w, x, y, sum = 0;
  std::cin >> n >> h >> w;
  for (int i = 0; i < n; i++) {
    std::cin >> x >> y;
    if (x >= h && y >= w) sum++;
  }

  std::cout << sum << std::endl;
  return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N;
	vector<llong> a,b;

	cin >> N;
	a.resize(N), b.resize(N);
	for(int i = 0; i < N; i++)
		cin >> a[i] >> b[i];

	llong ans = 0;
	for(int i = N-1; i >= 0; i--){
		a[i] += ans;
		ans += b[i] - (a[i]%b[i] ? a[i]%b[i] : b[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
char a[10][10],b[10][10];
int n,m,k;
bool check(int x,int y){
    vector<int> r,c;
    for(int i=1;i<=n;i++){
        int p=i-1;
        if((x>>p)%2==1) r.push_back(i);
    }
    for(int i=1;i<=m;i++){
        int p=i-1;
        if((y>>p)%2==1) c.push_back(i);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            b[i][j]=a[i][j];
        }
    }
    for(auto i:r){
        for(int j=1;j<=m;j++){
            b[i][j]='.';
        }
    }
    for(auto i:c){
        for(int j=1;j<=n;j++){
            b[j][i]='.';
        }
    }
    int num=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(b[i][j]=='#') num++;
        }
    }
    return num==k;
}
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
            ans+=check(i,j);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
map<pip,int>ma;
int n;
vvi in;
vvi f(int a){
	vvi w(n,vi(n));
	rep(i,n)rep(j,n){
		w[n-1-i][n-1-j]=a%2;
		a/=2;
	}
	return w;
}
int F(vvi w){
	int a=0;
	rep(i,n)rep(j,n){
		a*=2;
		a+=w[i][j];
	}
	return a;
}
vvi nex(vvi w){
	vvi ne(n,vi(n));
	rep(i,n)rep(j,n){
		int co=0;
		rep(k,8){
			int x=i+dx[k];
			int y=j+dy[k];
			if(x<0||y<0||x>=n||y>=n)continue;
			co+=w[x][y];
		}
		if(w[i][j]&&(co==2||co==3))ne[i][j]=1;
		if(w[i][j]==0&&co==3)ne[i][j]=1;
	}
	
	return ne;
}
signed main(){
	while(cin>>n,n){
		vs s(n);
		rep(i,n)cin>>s[i];
		int x,y;
		in=vvi(n,vi(n));
		rep(i,n)rep(j,n){
			if(s[i][j]-'.')in[i][j]=1;
			if(s[i][j]=='@')x=i,y=j;
		}
		ma.clear();
		ma[{F(in),{x,y}}]=1;
		queue<pip>que;
		que.push({F(in),{x,y}});
		while(!que.empty()){
			int w;pii p;
			w=que.front().first;
			p=que.front().second;
			que.pop();
			vvi fi=f(w);
			
			int cnt=ma[{w,p}];
			int co=0;
			rep(i,n)rep(j,n)if(fi[i][j])co++;
			if(co==1){
				cout<<cnt-1<<endl;
				goto end;
			}
			
			fi[p.first][p.second]=0;
			rep(k,8){
				int nx=p.first+dx[k];
				int ny=p.second+dy[k];
				if(nx<0||ny<0||nx>=n||ny>=n)continue;
				if(fi[nx][ny])continue;
				fi[nx][ny]=1;
				// show2d(fi);
				vvi ne=nex(fi);
				ne[nx][ny]=1;
				// show2d(ne);
				// cout<<endl;
				if(ma[{F(ne),{nx,ny}}]==0){
					ma[{F(ne),{nx,ny}}]=cnt+1;
					que.push({F(ne),{nx,ny}});
				}
				fi[nx][ny]=0;
			}
		}
		cout<<-1<<endl;
		end:;
	}
}









Measured memory_bytes: 5160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < q; i++) {
            ary[Integer.parseInt(sc.next()) - 1]++;
        }
        StringBuilder sb = new StringBuilder();
        for (int num : ary) {
            if (k - (q - num) > 0) {
                sb.append("Yes\n");
            } else {
                sb.append("No\n");
            }
        }
        System.out.println(sb.toString());
    }
}

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

int mincost(int n ,int k,vector<int>&height)
{
     vector<int>dp(n,INT_MAX);
     dp[0]=0;
     dp[1] = abs(height[1]-height[0]);
     for(int i =2;i<n;i++)
     {  for(int j =i-1;j>=0&&j>=i-k;j--)
          if(i>j)
          dp[i] = min(dp[i],dp[j]+abs(height[i]-height[j]));
     }
    return dp[n-1];
}
int main(){
    int n,k ;
  cin>>n>>k;
  vector<int>height(n);
  for(int i=0;i<n;i++)
  {  cin>>height[i];
  }
  cout<<mincost(n,k,height)<<endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();
		sb.append(br.readLine());
		sb.reverse();
		System.out.println(sb);
	}
}

Measured memory_bytes: 24144
#include <vector>
#include <cmath>
#include <iostream>

const unsigned MOD_UNIT = (int)1e9 + 7;

int main()
{
	int N, M;
	std::cin >> N >> M;

	std::vector<unsigned long long> a(N + 1, true);
	for (int i = 0; i < M; i++) {
		int index;
		std::cin >> index;
		a[index] = false;
	}

	std::vector<unsigned long long> dp(N + 1);
	dp[0] = 1;
	dp[1] = a[1] ? 1 : 0;
	for (int i = 2; i <= N; i++) {
		if (a[i]) {
			dp[i] = (dp[i - 1] + dp[i - 2]) % MOD_UNIT;
		} else {
			dp[i] = 0;
		}
	}
	printf("%llu\n", dp[N]);
}


Measured memory_bytes: 1792
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int H = (int)Math.pow(10,6)+10;
	        int[] m = new int[H];
	        int[] p = new int[H];
	        int k=0;
	        m[1]=1;
	        for(int i=2;i<H;i++) {
	        	if(m[i]==0) {
	        		m[i]=1;
	        		p[k]=i;
	        		k++;
	        		for(int j=i+i;j<H;j=j+i) {
	        			m[j]=i;
	        		}
	        	}
	        }
	        
	        long N = sc.nextLong();
	        int[] a = new int[H];
	        for(int i=0;i<k;i++) {
	        	if(N%p[i]==0) {
	        		while(N%p[i]==0) {
	        			a[i]++;
	        			N=N/p[i];
	        		}
	        	}
	        }
	        long ans=0;
	        if(N!=1)ans++;
	        for(int i=0;i<k;i++) {
	        	int cnt=0;
	        	for(int j=1;a[i]>=j;j++) {
	        		a[i]=a[i]-j;
	        		cnt++;
	        	}
	        	ans=ans+cnt;
	        }
	        
	        System.out.println(ans);
	    }
	}

Measured memory_bytes: 48632
n = gets.to_i
s = gets.chomp.chars
sum = 0
arr1 = []
(n - 1).downto(2) do |i|
  next if arr1.include?(s[i])
  arr1 << s[i]
  arr2 = []
  (i - 1).downto(1) do |j|
    next if arr2.include?(s[j])
    arr2 << s[j]
    sum += s[0...j].uniq.size
  end
end
puts sum

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define endl '\n'

vector<int> zf(string s) {
    int n = (int)s.size();
    vector<int> z(n);
    int l = 0, r = 0;
    z[0] = 0;
    for (int i = 1; i < n; i++) {
        if (i <= r)
            z[i] = min(r - i + 1, z[i - l]);
        while (i + z[i] < n && s[i+z[i]] == s[z[i]]) z[i]++;
        if (i + z[i] - 1 > r) {
            l = i; r = i + z[i] - 1;
        }
    }
    return z;
}

vector<int> pf(string s) {
    int n = (int)s.size();
    vector<int> p(n);
    p[0] = 0;
    for (int i = 1; i < n; i++) {
        p[i] = p[i - 1];
        while (p[i] && s[p[i]] != s[i]) {
            p[i] = p[p[i] - 1];
        }
        if (s[p[i]] == s[i]) p[i]++;
    }
    return p;
}



int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<int> x(n), y(n);
    vector<int> h(n), g(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i]; x[i]--; y[i]--;
        h[x[i]] = i;
        g[y[i]] = i;
    }
    vector<set<int>> ans;
    set<int> curr;
    int mx = n - 1, my = 0;
    int p = h[mx];
    while (true) {
        while (true) {
            // cout << p << ", ";
            curr.insert(p);
            int np = -1;
            if (y[p] > my) {
                for (int yy = my; yy <= y[p]; yy++) {
                    curr.insert(g[yy]);
                    if (x[g[yy]] < mx) {
                        if (np == -1) {
                            np = g[yy];
                        }
                        else {
                            if (x[np] > x[g[yy]]) {
                                np = g[yy];
                            }
                        }
                    }
                }
            }
            else {
                if (x[p] < mx) {
                    for (int xx = mx; xx >= x[p]; xx--) {
                        curr.insert(h[xx]);
                        if (y[h[xx]] > my) {
                            if (np == -1) {
                                np = h[xx];
                            }
                            else {
                                if (y[np] < y[h[xx]]) {
                                    np = h[xx];
                                }
                            }
                        }
                    }
                }
            }
            my = max(my, y[p]);
            mx = min(mx, x[p]);
            if (np == -1) {
                break;
            }
            p = np;
        }
        // cout << endl;
        ans.push_back(curr);
        curr.clear();
        mx--;
        my++;
        if (mx == -1) break;
        p = h[mx];
    }
    vector<int> nans(n);
    for (auto el : ans) {
        for (auto e : el) nans[e]=el.size();// cout << e << " ";
        // cout << endl;
    }
    for (auto el : nans) cout << el << endl;

    return 0;
}


Measured memory_bytes: 29772
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];
    int q;
    cin>>q;

    rep(i, q) {
        int c, b, e;
        cin>>c>>b>>e;
        if (c == 0) cout<<*min_element(as.begin() + b, as.begin() + e)<<endl;
        else cout<<*max_element(as.begin() + b, as.begin() + e)<<endl;
    }
}


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

int main(){
  int start;
  string str;
   cin >> str;
  start=str[0]-'0';
  int i;
  int check=0;
  for(i=1;i<str.size();i++){
    if('9' !=str[i]){
      check=1;
    }
  }
  cout << start+9*(str.size()-1)-check;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ans = __gcd(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,c;
	int i;
	int num;
	scanf("%d",&num);

	for(i=0;i<num;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b){
			printf("YES\n");
		}

		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <map>

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  cin >> N >> K;
  map<ll, ll> ab;
  for (ll i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    auto itr = ab.find(a);
    if (itr != ab.end()) {
      ab[a] += b;
    } else {
      ab[a] = b;
    }
  }
  for (auto itr = ab.begin(); itr != ab.end(); ++itr) {
    if (K <= itr->second) {
      cout << itr->first;
      break;
    } else {
      K = K - itr->second;
    }
  }

  return 0;
}

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

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

	vector<int> w(n);
	for (int i = 0; i < n; i++) { cin >> w[i + 1]; }
	
	int ans = 2147483647;

	for (int t = 1; t < n; t++) {
	
		int s1 = 0;
		for (int j = 1; j <= t; j++) { s1 += w[j]; }

		int s2 = 0;
		for (int j = t + 1; j <= n; j++) { s2 += w[j]; }
		
		ans = min(ans, abs(s1 - s2));
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n, k;
    std::cin >> n >> k;

    std::map<ll, ll> map;
    for (ll i = 0; i < n; i++) {
        ll a, b; std::cin >> a >> b;
        map[a] += b;
    }

    ll cnt = 0;
    for (auto i : map)
        if ((cnt += i.second) >= k) {
            std::cout << i.first << '\n';
            return;
        }
}


Measured memory_bytes: 7576
import sys

N, M = map(int, input().split())
p = []

for _ in range(N):
    A, B = map(int, input().split())
    p.append((A, B))

p.sort(key=lambda x:x[0])

money = 0
now = 0

for p_ in p:
    price = p_[0]
    amount = p_[1]
    if now + amount < M:
        now += amount
        money += price * amount
    else:
        money += price * (M-now)
        print(money)
        sys.exit()

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

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] S = new int[N];
		int[] T = new int[N];
		for (int i = 0; i < N; ++i) {
			S[i] = Integer.parseInt(sc.next());
			T[i] = Integer.parseInt(sc.next());
		}
		int[] P = new int[M + 2];
		for (int i = 0; i < M; ++i) {
			P[i + 1] = Integer.parseInt(sc.next());
		}
		P[M + 1] = 1000000001;
		Arrays.sort(P);
		int[][] tbl = new int[M + 2][2];
		for (int i = 1; i <= M + 1; ++i) {
			tbl[i][1 - i % 2] = tbl[i - 1][1 - i % 2] + P[i] - P[i - 1];
			tbl[i][i % 2] = tbl[i - 1][i % 2];
		}
		long sum = 0;
		for (int i = 0; i < N; ++i) {
			int[] len = new int[2];
			int posFar = -Arrays.binarySearch(P, Math.max(S[i], T[i])) - 2;
			len[0] = tbl[posFar][0];
			len[1] = tbl[posFar][1];
			int posNear = -Arrays.binarySearch(P, Math.min(S[i], T[i])) - 2;
			len[0] -= tbl[posNear][0];
			len[1] -= tbl[posNear][1];
			int add = 0;
			if (S[i] < T[i]) {
				add = len[posNear % 2];
				add -= S[i] - P[posNear];
				if (posFar % 2 == posNear % 2) add += T[i] - P[posFar];
			} else {
				add = len[posFar % 2];
				add += S[i] - P[posFar];
				if (posFar % 2 == posNear % 2) add -= T[i] - P[posNear];
			}
			sum += add;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 75048
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    p2 = [(i + 1) / 2 for i in p]
    l = []
    for i in range(N - (K - 1)):
        if i == 0:
            s = 0
            for j in range(K):
                s += p2[j]
            l.append(s)
        else:
            l.append(l[-1] - p2[i - 1] + p2[i + (K - 1)])
    print(max(l))
    # m = -1
    # for i in range(N - (K - 1)):
    #     s = 0
    #     for j in range(K):
    #         s += p2[i + j]
    #     m = max(m, s)
    # print(m)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35308
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

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

	vector<int> froms;
	int fromg[200000] = { 0 };

	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		if (a == 1) {
			froms.push_back(b - 1);
		}
		else if (b == n) {
			fromg[a - 1] = 1;
		}
	}

	rep(i, 0, froms.size()) {
		if (fromg[froms[i]] == 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	

	cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,K;
    cin>>N>>K;
    vl A(N);
    rep(i,N) cin>>A[i];
    vl visit(N,-1);
    vl road;
    ll to=0;
    ll roop;
    ll nroop;
    rep(i,200001){
        if(visit[to]!=-1){
            roop=i-visit[to];
            nroop=visit[to];
            break;
        }
        road.pb(to+1);
        visit[to]=i;
        to=A[to]-1;
    }
    if(K<nroop){
        cout<<road[K]<<endl;
    }else{
        K-=nroop;
        K%=roop;
        cout<<road[K+nroop]<<endl;
    }
}


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

const int64_t MOD=1e9+7;

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}


int main(){

  string S;
  cin>>S;
  reverse(S.begin(),S.end());

  int N=S.size();
  vector<int> modinv={1,4,3,12,9,10};
  vector<int> mod={1,10,9,12,3,4};

  //dp[i][j]はS[i-1]までの'?'を0から9にしたときに出来得る j mod 13なる数の総数
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(13));


    if(S[0]=='?'){
      for(int j=0;j<10;++j) dp[1][j]=1;
    }
    else{
      int a=ctoi(S[0]);
      dp[1][a]=1;
    }

  for(int i=1;i<N;++i){
    for(int j=0;j<13;++j){
      if(S[i]=='?'){
          for(int k=0;k<13;++k){
            int a=((modinv[i%6]*(j-k))%13+13)%13;
            if(a<10){
              dp[i+1][j] += dp[i][k];
              dp[i+1][j] %= MOD;
            }
          }
        }
      else{
        int b=ctoi(S[i]);
        int k=((j-mod[i%6]*b)%13+13)%13;
        dp[i+1][j] = dp[i][k];
        dp[i+1][j] %= MOD;
        }
      }
  }

  cout<<dp[N][5]<<endl;
}


Measured memory_bytes: 13696
#include <boost/algorithm/string/join.hpp>
#include <boost/format.hpp>
#include <sstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

using namespace std;
using namespace boost;

typedef int64_t INT;

int table[]{ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

struct Route
{
    int sy, sx;
    int gy, gx;
};

void chMax(string &a, const string &b)
{
    if(a == "-") {}
    else if(a.size() > b.size()) return;
    else if(a.size() == b.size() && a > b) return;
    a = b;
}
void Resolve(istream &is, ostream &os) {
    INT H, W;
    is >> H >> W;
    vector<Route> routes;

    int pw = -1;
    for(int h = 0; h < H;h++)
    {
        int ow=-1;
        for(int w = 0; w < W;w++)
        {
            int count;
            is >> count;
            if(w==pw){
                count++;
                routes.push_back(Route{h-1, w, h, w});
                pw = -1;
            }

            if(ow == -1 && count%2==1) ow = w;
            else if(ow != -1 && count%2==1) {
                routes.push_back(Route{h, ow, h, w});
                ow = -1;
            }
        }
        pw = ow;
    }
    stringstream oos;
    int count = 0;
    for (const auto route: routes) {
        for(int x = route.sx; x < route.gx; x++){
            count++;
            oos << route.sy+1 << " " << x+1 << " " << route.sy+1 << " " << x+2 << '\n';
        }
        for(int y = route.sy; y < route.gy; y++){
            count++;
            oos << y+1 << " " << route.sx+1 << " " << y+2 << " " << route.sx+1 << '\n';
        }
    }
    os << count << '\n';
    os << oos.str();
}

#if !TEST
int main() { cin.tie(0); ios::sync_with_stdio(false); Resolve(cin, cout); cout.flush(); return 0;}
#endif

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0)
{
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 1e5 + 10;

int n;

int test(string s, char c)
{
  int cnt = 0;
  int op = c - '0';
  for(const auto &x : s)
  { 
    if(x - '0' != op)
      cnt++;
    op ^= 1;
  }
  return cnt;
}

int main()
{
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  cout << min(test(s, '0'), test(s, '1')) << endl;
  return 0;
}

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

typedef long long ll;

int main(){
    ll X, K, D, ans=0;
    cin>>X>>K>>D;
    X=abs(X);
    ll to_zero;
    to_zero = X/D;
    if(to_zero>=K){
        cout<<abs(X-D*K)<<endl;
        return 0;
    }
    K -= to_zero;
    if(K%2==0){
        cout<<abs(X-D*to_zero)<<endl;
    }else{
        cout<<abs(X-D*to_zero-D)<<endl;        
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=1<<20,mo=924844033;
int i,j,n,k[maxn],re,ne[maxn],g[maxn],num;
int s[maxn],a[maxn],f[maxn],len,t;
int ji[maxn],ni[maxn],ans[maxn],b[maxn],w[maxn];
void add(int x,int y){
	ne[++num]=k[x],k[x]=num,g[num]=y;
}
void dfs(int x,int y){
	int i;
	s[x]=1;
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (go!=y)dfs(go,x),s[x]+=s[go];
	}
}
int qs(int x,int y){
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if (y&1) s=(ll)s*x%mo;
	return s;
}
void mod(int &x){
	x-=(x>=mo)?mo:0;
}
void dft(int *a,bool sig){
	int i,j,k,m=1,half,ws,o;
	fo(i,0,len-1) g[f[i]]=a[i];
	for(;m<len;){
		half=m,m<<=1,ws=sig?w[len/m]:w[len-len/m];
		for(i=0;i<len;i+=m){
			for(j=i,o=1;j<i+half;j++,o=(ll)o*ws%mo){
				int u=g[j],v=(ll)g[j+half]*o%mo;
				mod(g[j]+=v),mod(g[j+half]=u+mo-v);
			}
		}
	}
	if (sig){
		fo(i,0,len-1) a[i]=g[i];
	}else fo(i,0,len-1) a[i]=(ll)g[i]*re%mo;
}
int main(){
	n=read();
	fo(i,1,n-1) {
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
	ji[0]=1;
	fo(i,1,n) ji[i]=(ll)ji[i-1]*i%mo;
	ni[n]=qs(ji[n],mo-2);
	fd(i,n,1) ni[i-1]=(ll)ni[i]*i%mo;
	dfs(1,0);
	a[n]=n;
	fo(i,2,n) a[s[i]]--,a[n-s[i]]--;
	fo(i,1,n) a[i]=a[i]<0?a[i]+mo:a[i];
	b[0]=1;
	fo(i,1,n) a[i]=(ll)a[i]*ji[i]%mo,b[i]=ni[i];
	fo(i,1,n>>1) swap(a[i],a[n-i+1]);
	len=1;
	for(;len<=n*2;len<<=1,t++);
	w[0]=1,w[1]=qs(5,(mo-1)/len);
	fo(i,2,len) w[i]=(ll)w[i-1]*w[1]%mo;
	re=qs(len,mo-2);
	fo(i,0,len-1){
		int x=i,y=t-1;
		for(;x;x>>=1,y--) f[i]+=(x&1)<<y;
	}
	dft(a,1),dft(b,1);
	fo(i,0,len-1) a[i]=(ll)a[i]*b[i]%mo;
	dft(a,0);
	fo(i,1,n) ans[i]=a[i];
	fo(i,1,n>>1) swap(ans[i],ans[n-i+1]);
	fo(i,1,n) printf("%d\n",(ll)ans[i]*ni[i]%mo);
}

Measured memory_bytes: 42880
from itertools import product

h, w, n = list(map(int, input().split()))
idxs = {}
ans = [0]*10
for i in range(n):
    a, b = list(map(int, input().split()))
    for a_, b_ in product(range(a-1, a+2), range(b-1, b+2)):
        if a_ <= 1 or b_ <= 1 or a_ >= h or b_ >= w:
            continue

        # print(a_, b_)
        if (a_, b_) not in idxs.keys():
            idxs[(a_, b_)] = 1
        else:
            idxs[(a_, b_)] += 1
        
for keys, item in idxs.items():
    ans[item] += 1
ans[0] = (h-2)*(w-2)-sum(ans[1:])

for a in ans:
    print(a)


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

using namespace std;

#define INF (1ll << 62)
#define eb emplace_back
#define ii pair<int,int>
#define OK (cerr <<"OK"<< endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
const int MOD = 1e9 + 7;

signed main () {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;

  cin >> s;

  int q;
  cin >> q;

  list<char> l;
  for(char c: s)
    l.eb(c);

  bool rev = false;

  while(q--) {

    int t;

    cin >> t;

    if(t == 1)
      rev = !rev;
    else {
      int a; 
      char b;
      cin >> a >> b;
      if(a == 1) {
        if(rev)
          l.eb(b);
        else
          l.push_front(b);
      } else {
        if(rev)
          l.push_front(b);
        else
          l.eb(b);
      }
    }
  }

  if(rev) {
    for(auto it = l.rbegin(); it != l.rend(); it++)
      cout << *it;
    cout << endl;
  } else {
    for(char c: l)
      cout << c;
    cout << endl;
  }

}

Measured memory_bytes: 10064
n,m=map(int,input().split())
cnt=[1]*n
yn=[0]*n
yn[0]=1
for i in range(m):
    x,y=map(int,input().split())
    cnt[x-1]-=1
    cnt[y-1]+=1
    if x==1:
        if cnt[0]==0:
            yn[0]=0
        yn[y-1]=1
        for j in range(i+1,m):
            x,y=map(int,input().split())
            if yn[x-1]==1:
                yn[y-1]=1
            if cnt[x-1]==1:
                yn[x-1]=0
            cnt[x-1]-=1
            cnt[y-1]+=1
        break
print(yn.count(1))


Measured memory_bytes: 10504
import math

a, b, x = map(int, input().split())

if (a ** 2) * b <= 2 * x:
    t = (2 * b * (a ** 2) - 2 * x) / a ** 3
    res = math.degrees(math.atan(t))
else:
    t = 2 * x / (a * b ** 2)
    res = 90 - math.degrees(math.atan(t))

print(res)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>

int main(){
  int n;
  std::cin >> n;

  double a[n];
  for(int i = 0; i < n; i++) scanf("%lf", &a[i]);

  double den = 1;
  double mol = 0;
  
  for(int i = 0; i < n; i++) den = den*a[i];

  for(int i = 0; i < n; i++){
    mol += den/a[i];
  }

  double ans = den/mol;
  printf("%lf\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	string s; cin >> s;
	ll r=0, g=0, b=0;
	rep(i,n){
		if(s[i]=='R') r++;
		else if(s[i]=='G') g++;
		else b++;
	}
	ll ans = r*g*b;
	for(ll j=1; 2*j<=n; j++){
		for(ll i=0; i<n-2*j; i++){
			if(s.at(i)!=s.at(i+j) && s.at(i+j)!=s.at(2*j+i) && s.at(i)!=s.at(2*j+i)) ans--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 文字の入力
		String S = sc.next();
		String T = sc.next();

		int len = S.length();//文字の桁数
		String tmp = S; 	
		String wk = null ;
		if(tmp.equals(T)){
    		System.out.println("Yes");
    		sc.close();
    		return;
		}
		
		//文字数分繰り返す
		for(int i = 0;i < len;i++)
		{
			String wk2 = "";
			String[] strArray = tmp.split("");
			for(int j = 0;j < len;j++){
				if(j==0){
					wk = strArray[0]; 
				}else{
					wk2 = wk2 + strArray[j];
//					wk2.concat(strArray[j]);
//					strArray[j-1] = strArray[j];
					if(len - 1 == j){
						wk2 = wk2 + wk;
//						wk2.concat(wk);
//						strArray[j] = wk;
					}
				}
			}
//			tmp = strArray.toString();
			tmp = wk2;
			
			if(tmp.equals(T)){
	    		System.out.println("Yes");
	    		sc.close();
	    		return;
			}
		}

        	
   		System.out.println("No");
   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 26196
from collections import deque
import sys
sys.setrecursionlimit(10**9 + 7)


def dfs1(pos, par, e=1):
    """dfsを用いて前計算する"""
    for child in tree[pos]:
        if child == par:
            continue
        tmp = st_val[child]
        e *= (1 + tmp)
        e %= MOD
    st_val[pos] = e
    return st_val[pos]


def dfs2(pos, par, e=1):
    """全方位木DP"""
    for child in tree[pos]:
        if child == par:
            ind = compress[par][pos]
            tmp = ruiseki_l[par][ind] * ruiseki_r[par][len(tree[par]) - ind - 1]
        else:
            tmp = st_val[child]
        e *= (1 + tmp)
        e %= MOD
        ind = compress[pos][child]
        re_subtree_val[pos][ind] = 1 + tmp

    for i in range(len(tree[pos])):
        ruiseki_l[pos][i + 1] = ruiseki_l[pos][i] * re_subtree_val[pos][i]
        ruiseki_l[pos][i + 1] %= MOD
    for i in range(len(tree[pos])):
        ruiseki_r[pos][i + 1] = ruiseki_r[pos][i] * re_subtree_val[pos][-i-1]
        ruiseki_r[pos][i + 1] %= MOD
    ans[pos] = e



def topological_sort(root, par=-1):
    q = deque([(root, par)])
    res = [(root, par)]
    while q:
        pos, par = q.pop()
        for child in tree[pos]:
            if child == par:
                continue
            else:
                q.append((child, pos))
                res.append((child, pos))
    return res


n, m = map(int, input().split())
MOD = m
info = [list(map(int, input().split())) for i in range(n-1)]
tree = [[] for i in range(n)]
for i in range(n-1):
    a, b = info[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

# 木上のdfsの行きがけ順
preorder_list = topological_sort(0, par=-1)

# subtreeから値を集める
st_val = [0] * n
for pos, par in reversed(preorder_list):
    dfs1(pos, par)

# rerootによって、subtreeから値を集める。
re_subtree_val = [[1] * len(tree[i]) for i in range(n)]

# 左右それぞれの累積
ruiseki_l = [[1] * (len(tree[i]) + 1) for i in range(n)]
ruiseki_r = [[1] * (len(tree[i]) + 1) for i in range(n)]

compress = [{v: j for j, v in enumerate(tree[i])} for i in range(n)]
ans = [0]*n
for pos, par in preorder_list:
    dfs2(pos, par)

for i in range(n):
    print(ans[i] % MOD)



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool graph[10][10] = {false}; //隣接行列
bool visited[10] = {false};
int n, m;

int dfs(int bv, int depth)
{
    int res = 0;

    if (depth == n - 1)
    {
        // cout << "res" << ':' << bv << endl;
        return 1;
    }

    for (int v = 0; v < n; v++)
    {
        if (bv == v)
        {
            continue;
        }
        if (graph[bv][v] && graph[v][bv] && !visited[v])
        {
            visited[v] = true;
            // cout << "run:" << v << endl;
            res += dfs(v, depth + 1);
            visited[v] = false;
        }
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;
    }
    visited[0] = true;
    cout << dfs(0, 0) << endl;
}

Measured memory_bytes: 256
w, h, n = map(int, input().split())

left = 0
right = w
down = 0
up = h

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        down = max(down, y)
    elif a == 4:
        up = min(up, y)

if left >= right or down >= up:
    ans = 0
else:
    ans = (right - left) * (up - down)
print(ans)

Measured memory_bytes: 3064
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for height in range(h):
        for width in range(w):
            if (height + width) % 2 == 0:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print() #データセットの区切り


Measured memory_bytes: 7000
#include <iostream>

using namespace std;

int main() {
        int N, K;
        int cnt = 0;

        cin >> N >> K;

        int h[N];

        for (int i = 0; i < N; i++) {
                cin >> h[i];
                if (h[i] >= K) {
                        cnt += 1;
                }
        }
        cout << cnt << endl;

        return 0;
}
                                                                                                                                                                                                          

Measured memory_bytes: 640
# N! 通りの総和は期待値で考えたほうがわかりやすくなることが多そう

import sys
from functools import lru_cache
sys.setrecursionlimit(500000)

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

def main():
    modinv = make_modinv_list(200)

    @lru_cache(maxsize=None)
    def solve(idx, X):
        # 降順ソートした S の idx 個目以降を使ったときの操作後の X の期待値
        if idx == N:
            return X
        # idx 個目を idx 個目以降で最初に使うかで場合分け
        res = 0
        # 最初に使う場合（確率 (1/(N-idx))）
        res += modinv[N-idx] * solve(idx+1, X % S[idx]) % mod
        # 最初に使わない場合（確率 ((N-idx-1)/(N-idx))）
        res += (N-idx-1) * modinv[N-idx] * solve(idx+1, X) % mod
        return res % mod

    mod = 10**9+7
    N, X = map(int, input().split())
    S = sorted(map(int, input().split()), reverse=True)
    ans = solve(0, X)
    for i in range(2, N+1):
        ans = ans * i % mod
    print(ans)

main()


Measured memory_bytes: 188408