akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

const int DAT_SIZE=(1<<18)-1;

ll datA[DAT_SIZE], datB[DAT_SIZE];

// [a,b)にxを加算する
// add(a,b,x,0,0,N);
void add(int a, int b, int x, int k, int l, int r){
  if(a<=l && r<=b) datA[k]+=x;
  else if(l<b && a<r){
    datB[k]+=(min(b,r)-max(a,l))*x;
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
}

// [a,b)の和を計算する
// sum(a,b,0,0,N)
ll sum(int a, int b, int k, int l, int r){
  if(b<=l || r<=a) return 0;
  else if(a<=l && r<=b) return (datA[k]*(r-l)+datB[k]);
  else{
    ll res=(min(b,r)-max(a,l))*datA[k];
    res+=sum(a,b,k*2+1,l,(l+r)/2);
    res+=sum(a,b,k*2+2,(l+r)/2,r);
    return res;
  }
}

int main(){
  int N,M; cin>>N>>M;
  vector<tuple<int,int,int> > V(N);
  rep(i,N){
    int l,r; cin>>l>>r;
    V[i]=make_tuple(r-l+1,l,r);
  }
  sort(V.begin(),V.end());
  cout<<N<<endl;
  int dekai=N,ind=0;
  for(int d=2;d<=M;d++){
    while(ind<N){
      if(get<0>(V[ind])>=d) break;
      int l=get<1>(V[ind]),r=get<2>(V[ind]);
      ind++,dekai--;
      add(l,r+1,1,0,0,M+1);
    }
    ll tmp=dekai;
    for(int i=d;i<=M;i+=d){
      tmp+=sum(i,i+1,0,0,M+1);
    }
    cout<<tmp<<endl;
  }
  return 0;
}


Measured memory_bytes: 7552
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int N;
LL A[100000];

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	sort(A, A+N);
	LL M = A[N-1] - A[0];
	for(int i=1; i<N-1; i++) M += abs(A[i]);
	cout << M << endl;
	LL small = A[0];
	LL big = A[N-1];
	for(int i=1; i<N-1; i++){
		if(A[i] < 0){
			cout << big << " " << A[i] << endl;
			big -= A[i];
		}
		else{
			cout << small << " " << A[i] << endl;
			small -= A[i];
		}
	}
	cout << big << " " << small << endl;
}


Measured memory_bytes: 2688
package main

import (
  "fmt"
)

func main() {
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<10; i++ {
      for j:=0; j<10; j++ {
        for k:=0; k<10; k++ {
          for l:=0; l<10; l++ {
            if (i+j+k+l == a) {
              b++
            }
          }
        }
      }
    }
  fmt.Println(b)
  }
}


Measured memory_bytes: 1112
fun main(args: Array<String>) {
    val (A, B, H, M) = readLine()!!.split(" ").map(String::toDouble)
    val h = H * 60 + M
    val a = V.deg(A, h * 360 / 720)
    val b = V.deg(B, M * 360 / 60)
    println(a.distanceTo(b))
}

data class V(val x: Double, val y: Double) {
    companion object {
        fun rad(A: Double, rad: Double) = V(A * Math.cos(rad), A * Math.sin(rad))
        fun deg(A: Double, deg: Double) = rad(A, d2r(deg))
        private fun d2r(d: Double) = d * Math.PI / 180
    }

    fun norm() = Math.sqrt(x * x + y * y)
    fun distanceTo(o: V) = Math.sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y))
}

Measured memory_bytes: 36604
#include <stdio.h>
#include <stdlib.h>
int MIN(int a,int b){return a<b?a:b;}
int main()
{
    int n;
    scanf("%d",&n);
    int h[n];
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    long long dp[100002]={0};
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=MIN(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
    }
    printf("%lld",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1280
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while (false)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main(); return 0;
}
#endif

void Main() {
  deque<char> s;
  string S; cin >> S;
  for(auto &x: S) s.push_back(x);
  int q; cin >> q;
  bool rev = false;
  for(int i = 0; i < q; i++) {
    int op; cin >> op;
    if(op == 1) {
      rev ^= true;
    } else {
      int f; cin >> f;
      f--;
      string c; cin >> c;
      if(f ^ rev) {
        s.push_back(c[0]);
      } else {
        s.push_front(c[0]);
      }
    }
  }
  if(!rev) {
    while(!s.empty()) {
      cout << s.front();
      s.pop_front();
    }
  } else {
    while(!s.empty()) {
      cout << s.back();
      s.pop_back();
    }
  }
  cout << "\n";
}

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

int main(){
    int h,w;
    cin >> h >> w;
    string s,s2;
    vector <int> al(26,0);

    int t;
    rep(i,h){
        cin >> s;
        rep(j,w){
            t=s[j];
            ++al[t-97];
        }
    }

    
    int a1=0,a2=0,a3=0;
    rep(i,26){
        if(al[i]%4==1){
            ++a1;
        }
        else if(al[i]%4==2){
            ++a2;
        }
        else if(al[i]%4==3){
            ++a3;
        }
        
    }

    int ans=0;
    if(h%2==0 and w%2==0){
        if(a1==0 and a2==0 and a3==0){
            ans=0;
        }
        else{
            ans=1;
        }
    }
    else if(h%2==1 and w%2==1){
        if((a1+a3)==1){
            a2+=a3;
            if(((h+w-2)/2)>=a2){
                ans=0;
            }
            else{
                ans=1;
            }
        }
        else{
            ans=1;
        }
    }
    else if(h%2==1){
        if(a1==0 and a3==0){
            if((w/2)>=a2){
                ans=0;
            }
            else{
                ans=1;
            }
        }
        else{
            ans=1;
        }
    }
    else{
        if(a1==0 and a3==0){
            if((h/2)>=a2){
                ans=0;
            }
            else{
                ans=1;
            }
        }
        else{
            ans=1;
        }
    }




    if(ans==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3636
N = int(input())
a = sorted(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

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

int main() {
  int64_t h,w;
  cin>>h>>w;
  if(h==1||w==1){
    cout<<"1";
  }
  else if((h*w)%2==0){
    cout<<(h*w)/2;
  }
  else if(1){
    cout<<((h*w)/2)+1;
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
l, r = -1, n
while r - l > 1:
    m = (l + r) // 2
    t = a[m]
    for i in range(n):
        if m == i:
            continue
        if t * 2 >= a[i]:
            t += a[i]
        else:
            break
    else:
        r = m
        continue
    l = m
print(n - r)

Measured memory_bytes: 14320
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin >> n;
  for(int i=0; i < n; i++){
    int rest = n - 100*i;
    if(rest >= 0 && rest <= i*5){
      cout << 1 << endl;
      return 0;
    }
    if(rest < 0){
      break;
    }
  }
  cout << 0 << endl;
  return 0;
}
  

Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int ret = 0;
	int count = 0;
	for (char c : s) {
		if (c == 'S') {
			count = 0;
		} else {
			++count; 
		}
		ret = max(ret, count);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3608
while True:
    N, M = map(int, input().split())
    if N == 0 and M == 0: break
    travel = [tuple(map(int, input().split())) for _ in range(N)]
    travel.sort(reverse=True, key=lambda x:x[1])
    for i, (d, p) in enumerate(travel):
        if M == 0: break
        travel[i] = (p, max(0, d-M))
        M = max(0, M-d)
    print(sum(d*p for d, p in travel))

Measured memory_bytes: 8080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,p;
  vector<int> prm;
  bool isP[200000];

  for( int i=0;i<200000;i++ )
    isP[i]=true;

  int ff=-1;
  for( int i=2; i<200000;i+=2 ){
    if( isP[i] ){
      prm.push_back( i );
      for( int j=i*2;j<200000;j+=i )
	isP[j] = false;
      if( i==2 ) i--;
      if( ff<0 && i>100000 )
	ff=prm.size();
      if( ff>0 && prm.size() > ff + 200 )
	break;
    }
  }

  while( cin>>n>>p && (n!=-1 && p!=-1) ){
    int a[100];
    vector<int> v;

    int index=0;
    while( prm[index]<=n ) index++;
    for( int i=0;i<100;i++ )
      a[i] = prm[index++];

    for( int i=0;i<100;i++ ){
      for( int j=i;j<100;j++ )
	v.push_back( a[i]+a[j] );
    }
    sort( v.begin(),v.end() );
    /*
    for( int i=0;i<100;i++ )
      cout << " " << v[i];
    cout << endl;
    */

    cout << v[p-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1208
#include <iostream>

int main(){
  int m, n, tree;
  bool year[7368792];
  while(true){
    std::cin >> m >> n;
    for(int i = 0; i < 7368792; i++) year[i] = false;
    tree = m;

    if(m == 0 && n == 0){
      break;
    }

    else{
      for(int j = 0; j < n; j++){
        for(int i = 2, hoge = tree; hoge < 7368791; i++){
          year[hoge] = true;
          hoge = tree * i;
        }
        while(year[tree] == true) tree++;
      }
      std::cout << tree << std::endl;
    }
  }
}


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

int main(void) {
  int N, D, a, cnt=0;
  cin >> N >> D;
  int X[N][D];
  
  for(int i=0; i<N; i++){
    for(int j=0; j<D; j++){
      cin >> X[i][j];
    }
  }
  
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      a = 0;
      for(int k=0; k<D; k++){
        a += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      
      for(int k=0; k<=a; k++){
        if(k*k == a) cnt++;
      }
    }
  }
  
  cout << cnt << endl;
  

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int count[5][4][11];
    int i, j, k;
    int n, b, f, r, v;

    for(i = 1; i <= 4; i++){
        for(j = 1; j <= 3; j++){
            for(k = 1; k <= 10; k++){
                count[i][j][k] = 0;
            }
        }
    }

    scanf("%d",&n);
    for(i = 1; i <= n; i++){
        scanf("%d %d %d %d",&b, &f, &r, &v);
        count[b][f][r] += v;
    }

    for(i = 1; i <= 4; i++){
        for(j = 1; j <= 3; j++){
            for(k = 1; k <= 10; k++){
                printf(" %d",count[i][j][k]);
            }
            printf("\n");
        }
        if(i != 4) printf("####################\n");
    }

    return 0;

}


Measured memory_bytes: 2056
#include<stdio.h>

int main(void){
  int x,i,n,k,stop=0;
  scanf("%d",&n);
  for (i = 1; i<=n ; i++){
    if (i % 3 == 0){
      printf(" %d",i);
    } else {
      for(k = i ; k > 0 ; k/=10){
        if (k % 10 == 3){
          printf(" %d",i);
          break;
        }
      }
    }
  }
  printf("\n");
  return 0;
}

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

int main(){
	int d,n;cin>>d>>n;
	int ans;
	
	if(d==0){
		ans=n;
	}
	if(d==1){
		ans=n*100;
	}
	if(d==2){
		ans=n*10000;
	}
	int a=1;
	if(n==100){
		for(int i=0;i<d;i++){
			a*=100;
		}
		ans+=a;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.math.BigDecimal;

class Main {
	public static void main (String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf);
				BigDecimal a = new BigDecimal(st.nextToken());
				BigDecimal b = new BigDecimal(st.nextToken());
				int n = Integer.parseInt(st.nextToken());

				BigDecimal d = a.divide(b,n+1,BigDecimal.ROUND_FLOOR);
				
				String s = d.toString();
				int c = 0;
				int sum = 0;
				while (s.charAt(c)!='.') c++;
				for (int i=c+1;i<=n+c;i++) {
					sum += Character.getNumericValue(s.charAt(i));
				}
				System.out.println(sum);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16996
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll r,g,b;
    cin>>r>>g>>b;
    ll k;
    cin>>k;

    // g>r and b>g
    // b>g>r

    ll req1=0;
    while(g<=r){
        g=g*2;
        req1++;
    }

    if(req1<=k){
        k=k-req1;
        ll req2=0;
        while(b<=g){
            b=b*2;
            req2++;
        }

        if(req2<=k){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }

    }
    else{
        cout<<"No"<<endl;
    }


}

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

int main(void){
    string str;
    cin >> str;
    int r = 0;
    for (int i=0; i<3; i++){
        if (str[i] == 'R') r++;
    }
    if (r == 2) cout << (str[1]=='R' ? 2 : 1) << endl;
    else cout << r << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

ll n;

struct edge{
    ll to,cost;
};
ll INF=1e15;
vector<edge> g[100010];
vector<ll> d(100010);
 
void dijkstra(ll x,vector<ll> &d,vector<bool> &vis){
    rep(i,len(d)){
        d[i]=INF;
    }
    priority_queue<P,vector<P>,greater<P>> que;
    d[x]=0;
    que.push(P(0,x));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        ll v=p.second;
        if(d[v]<p.first||vis[v]){
            continue;
        }
        vis[v]=true;
        rep(i,len(g[v])){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n-1){
      ll a,b;
      cin>>a>>b;
      g[a].push_back({b,1});
      g[b].push_back({a,1});
    }
    vector<ll> d(100010),d2(100010);
    vector<bool> vis(100010,false),vis2(100010,false);
    dijkstra(1,d,vis);
    dijkstra(n,d2,vis2);
    ll c1=0,c2=0;
    FOR(i,1,n+1){
      if(d[i]<=d2[i]){
        c1++;
      }else{
        c2++;
      }
    }
    if(c1>c2){
      cout<<"Fennec"<<endl;
    }else{
      cout<<"Snuke"<<endl;
    }
    /*
    FOR(i,1,n+1){
      cout<<d[i]<<'\n';
    }
    cout<<'\n';
    FOR(i,1,n+1){
      cout<<d2[i]<<'\n';
    }
    cout<<'\n';
    */
}

Measured memory_bytes: 10764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int N;

int main(void)
{
	cin >> N;
	ll ans = 1;
	vector<ll> A(N);

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

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

	for (int i = 0; i < N; i++)
	{
		if (A[i] == 0)
		{
			ans = 0;
			break;
		}
		if (1000000000000000000 / A[i] >= ans)
		{
			ans *= A[i];
		}
		else
		{
			ans = -1;
			break;
		}
	}

	cout << ans << endl;
}

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

class Main{
    public static void main(String[] args)throws Exception{
	int i = 0;
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	String str_N = br.readLine();
	String str_A = br.readLine();
	
	int[] A;
	A = new int[Integer.parseInt(str_N)];
	
	Scanner s = new Scanner(str_A).useDelimiter("\\s* \\s*");

	//入力時点の並びの標準出力
	while(s.hasNext()){
	    A[i] = s.nextInt();
	    System.out.print(A[i]);
	    if(i != A.length - 1) System.out.print(" ");
	    i++;
	}
	
	System.out.println("");
	
	for(int I = 1;I<A.length;I++){
	    int v = A[I];
	    int j = I - 1;
	    
	    while((j>=0) && (A[j]>v)){
		A[j+1] = A[j];
		j--;
	    }
	    A[j+1] = v;
	    for(i=0;i<A.length;i++){
		System.out.print(A[i]);
		if(i != A.length - 1) System.out.print(" ");
		}
	    System.out.println("");
	}
	s.close();
	return ;
    }
}



Measured memory_bytes: 34328
A,B,C=map(int,input().split())
lst=0
if A==5 or A==7:
    lst+=A
    if B==5 or B==7:
        lst+=B
        if C==5 or C==7:
            lst+=C
            if lst==17:
                print('YES')
            else:
                print('NO')
else:
    print('NO')

Measured memory_bytes: 9028
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    string s; cin >> s;
    vector<bool> alpha(26, true);
    REP(i, s.size()) alpha[s[i] - 'a'] = alpha[s[i] - 'a'] xor true;
    bool ans = true;
    REP(i, alpha.size()){
        if(alpha[i] == false){
            ans = false;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}

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

using namespace std;

int main()
{
	vector<string> weatherStr = {"Sunny", "Cloudy", "Rainy"};
	
	// 入力
	string S;
	cin >> S;
	
	int tomorrow = 0;
	for (int i = 0; i < weatherStr.size(); i++)
	{
		if (S == weatherStr[i])
		{
			tomorrow = i + 1;
			
			if (tomorrow > 2)
			{
				tomorrow = 0;
			}
			
			break;
		}
	}
	
	cout << weatherStr[tomorrow] << endl;
	
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

def check(p: int, h: list, ways: dict):
    for w in ways[p]:
        if h[p] <= h[w]:
            return False
    return True


def main():
    tmp = [int(i) for i in input().split()]
    n = tmp[0]
    m = tmp[1]

    ways = defaultdict(set)
    h = [0] + [int(i) for i in input().split()]
    for _ in range(m):
        tmp = [int(i) for i in input().split()]
        ways[tmp[0]].add(tmp[1])
        ways[tmp[1]].add(tmp[0])
    
    cnt = 0
    for i in range(1, n+1):
        if check(i, h, ways):
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 51944
N = gets.to_i
array = gets.split(' ').map(&:to_i)

sum = 0

(1..N-1).each do |i|
  if array[i-1] - array[i] > 0
    dai = array[i-1] - array[i]
    sum += dai
    array[i] += dai
  end
end

puts sum


Measured memory_bytes: 28052
#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;int main(){string s;int n;map<string,set<int> >z;map<string, set<int> >::iterator q;set<int>::iterator x;while(cin>>s>>n)z[s].insert(n);for(q=z.begin();q!=z.end();q++){s=q->first;cout<<s<<endl;for(x=z[s].begin();x!=z[s].end();x++){if(x!=z[s].begin())cout<<" ";cout<<*x;}cout<<endl;}return 0;}

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    if(d[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    sort(d.begin(), d.end());
    int mx = d[n-1];

    vector<ll> cnt(n, 0);
    rep(i,n) cnt[d[i]]++;

    if(2<=cnt[0] || cnt[0]==0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for(int i=1; i<=mx; i++){
        ans *= modpow(cnt[i-1],cnt[i], 998244353);
        ans %= ll(998244353);
    }

    cout << ans << endl;

}

Measured memory_bytes: 4504
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int n, a;
Int source[216000];
Int use[216000];
Int ans;
void ok(){
  cout << "Yes" << endl;
  exit(0);
}

void ng(){
  cout <<  -1 << endl;
  exit(0);
}


int main(){
  cin >> n;
  for(Int i = 0;i < n;i++){
    cin >> a;
    source[i] = i - a;
    if(source[i] < 0)ng();
    if(source[i] < source[i-1])ng();
    use[source[i]] = max(use[source[i]], a);
  }
  for(Int i = 0;i < n;i++)ans += use[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
import decimal
import math

A, B, H, M = map(int, input().split())

thetaA = 360 * (decimal.Decimal(H/12)+decimal.Decimal(M/(12*60)))
thetaB = 360 * decimal.Decimal(M/60)

AX = A*math.cos(math.radians(thetaA))
AY = A*math.sin(math.radians(thetaA))

BX = B*math.cos(math.radians(thetaB))
BY = B*math.sin(math.radians(thetaB))

print(math.sqrt((AX-BX)**2 + (AY-BY)**2))


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

int main() {
  long long a,b,c,k,ans;
  cin>>a>>b>>c>>k;
  if(a>k)ans=k;
  else if(a+b>=k)ans=a;
  else ans=2*a+b-k;
  cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	long long x,y;
	scanf("%lld%lld",&x,&y);
	long long now = x;
	long long ans = 1;
	while(now <= y){
		if(y / 2 >= now) now *= 2;
		else break;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string a, b;
cin >> a >> b;
double ab = sqrt(stoi(a + b));
if(floor(ab)==ab){
    cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
long long n,k;
long long ans;
int main()
{
    scanf("%lld%lld",&n,&k);
    ans=k;
    for(int i=2;i<=n;i++)
        ans*=(k-1);
    printf("%lld",ans);
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    exist2 = False
    not4 = 0
    count4 = 0
    for an in a:
        if an % 2 == 0:
            if an % 4 == 0:
                count4 += 1
            else:
                if not exist2:
                    exist2 = True
                    not4 += 1
        else:
            not4 += 1
    print('Yes' if count4 >= not4 - 1 else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 20032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  string x;
  cin>>x;
  int s=0, del=0;
  for(int i=0;i<x.length();i++){
    if(x[i]=='S') s++;
    else{
      if(s>0){
        del+=2; s--;
      }
    }
  }
  cout<<x.length()-del<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int a, b, C, x, y;
int main(void){
    // Your code here!
    cin >> a >> b >> C >> x >> y;
    int res = 1000000000, c = C * 2;
    int big = max(x, y), sma = min(x, y);
    for (int i = 0; i <= big; i++) {
        if (i > sma) {
            res = min(res, c * i + (x < y ? b * (y - i) : a * (x - i)));
        } else {
            res = min(c * i + a * (x - i) + b * (y - i), res);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llt long long int
using namespace std;
const int mod = 1e9 + 7;
llt power(llt a, llt b)
{
	llt res = 1;
	a = a%mod;
	if(a==0)
	{
		return 0;
	}
	while(b > 0)
	{
		if(b&1)
		{
			res = (res * a)%mod;
		}
		b = b >> 1;
		a = (a * a)%mod;
	}
	return res;
}
int main()
{
  	llt a;
  	scanf("%lld",&a);
  	llt ans = power(10, a);
  	ans-= 2ll * power(9, a);
  	ans+= 1ll* power(8,a);
  	ans%=mod;
  	if(ans < 0)
  	{
  		ans+=mod;
  	}
  	printf("%lld",ans);
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

int w, h;
int cnt;
int map[101][101];
struct Pos{ int x, y; Pos(int X, int Y){ x = X, y = Y ;} };

void dfs( int y, int x ){
	cnt++;
	std::queue<Pos> que;
	int kind = map[y][x];

	que.push( Pos( x, y ) );
	while( !que.empty() ){
		Pos p = que.front();
		que.pop();

		if( map[p.y][p.x] == -1 )continue;
		map[p.y][p.x] = -1;

		if( p.x + 1 < w && map[p.y][p.x + 1] == kind ){
			que.push(Pos(p.x + 1, p.y));
		}
		if( p.y - 1 >= 0 && map[p.y - 1][p.x] == kind ){
			que.push(Pos(p.x, p.y - 1));
		}
		if( p.x - 1 >= 0 && map[p.y][p.x - 1] == kind ){
			que.push(Pos(p.x - 1, p.y));
		}
		if( p.y + 1 < h && map[p.y + 1][p.x] == kind ){
			que.push(Pos(p.x, p.y + 1));
		}
	}

	return;
}

int main(){
	std::string str;

	while( std::cin >> h >> w, w * h != 0 ){
		cnt = 0;

		for( int i = 0; i < h; ++i ){
			std::cin >> str;
			for( int l = 0; l < w; ++l ){
				if( str[l] == '@' ){
					map[i][l] = 0;
				}else if( str[l] == '#' ){
					map[i][l] = 1;
				}else{
					map[i][l] = 2;
				}
			}
		}

		for( int i = 0; i < h; ++i ){
			for( int l = 0; l < w; ++l ){
				if( map[i][l] != -1 ){
					dfs(i, l);
				}
			}
		}

		std::cout << cnt << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

int ans, n;
string s, t;
void solve(){
    reads(s);
    reads(t);
    n = s.size();
    for(int i=0;i<n;i++){
        ans+=s[i]!=t[i];
    }
    printf("%d\n", ans);
}

int main(){
    ios_base::sync_with_stdio(0);
    int t = 1; //scanf("%d",&t);
    for(int caso=1;caso<=t;caso++){
        solve();
    }
}

Measured memory_bytes: 4068
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            char X = sl[0].charAt(0);
            char Y = sl[1].charAt(0);

            System.out.println(
                X < Y ? "<" : Y < X ? ">" : "=");
        }
    }
}


Measured memory_bytes: 22100
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[100000],b[100000],f[100000];
int main(){
	ll m,n;
	cin>>m>>n;
	ll i,j;
	for(i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(i=0;i<=m;i++){
		f[i]=i/a[0]*b[0];
		if(i%a[0])
			f[i]+=b[0];
	}
	for(i=1;i<n;i++){
		for(j=0;j<=m;j++){
			if(j-a[i]<=0)
				f[j]=min(f[j],b[i]);
			else
				f[j]=min(f[j],f[j-a[i]]+b[i]);
		}
	}
	cout<<f[m]<<endl;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 1, x; i < n; i++) {
        cin >> x;
        x--;
        a[x]++;
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << "\n";
    }
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    string s;
    cin >> s;

    if('A' <= s[0] && s[0] <= 'Z'){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

struct WeightedUnionFind {
    vector<int> par, wei;
    WeightedUnionFind (int N) : par(N, -1), wei(N, 0) {}
    int root(int x) {
        if (par[x] < 0) {
            return x;
        } else {
            int rx = root(par[x]);
            wei[x] += wei[par[x]];
            return par[x] = rx;
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int weight(int x) {
        root(x);
        return wei[x];
    }
    int diff(int x, int y) {
        return weight(y) - weight(x);
    }
    bool unite(int x, int y, int w) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return diff(x, y) == w;
        w += wei[x];
        w -= wei[y];
        if (par[rx] > par[ry]) {
            swap(rx, ry);
            w = -w;
        }
        par[rx] += par[ry];
        par[ry] = rx;
        wei[ry] = w;
        return true;
    }
};

int main() {
    int n;
    cin >> n;
    WeightedUnionFind WUF(n);
    int q;
    cin >> q;
    rep(i, q) {
        int num;
        cin >> num;
        if (num == 0) {
            int x, y, z;
            cin >> x >> y >> z;
            WUF.unite(x, y, z);
        } else {
            int x, y;
            cin >> x >> y;
            if (WUF.same(x, y)) cout << WUF.diff(x, y) << "\n";
            else cout << "?\n";
        }
    }
    return 0;
}



Measured memory_bytes: 3608
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    string s;cin>>s;
    int n = s.length();
    if(n<26){
        map<char,int> ma;
        for(int i=0;i<n;++i)ma[s[i]]++;
        char c = 'a';
        for(int i=0;i<26;++i){
            if(ma[c]==0){
                cout<<s + c<<endl;
                return 0;
            }
            c++;
        }
    }
    char c=s[25];
    map<char,int> ma;
    ma[c]++;
    for(int i=24;i>-1;--i){
        if(s[i]<c){
            char cc = c;
            for(auto itr = ma.begin();itr != ma.end();itr++){
                if(itr->first>s[i]){
                    if(cc>itr->first)cc=itr->first;
                }
            }
            cout<<s.substr(0,i)+cc<<endl;
            return 0;
        }
        ma[s[i]]++;
        if(c<s[i])c=s[i];
    }
    cout<<-1<<endl;
    return 0;
}

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

using namespace std;

#define vi vector<int>
#define vs vector<string>
#define pii pair<int,int>
#define vpi vector<pii>
#define mpi map<int,int>
#define i64 long long int
#define endl '\n'
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf INT_MAX/2
#define infll LLONG_MAX/3
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define eps 1e-8
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define dbg(i) printf("yo %d\n", i)
#define foreach(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define sqr(a) (a) * (a)
#define clr clear()
#define CASE(a) printf("Case %d: ",a)

//int dx[] = {0,1,0,-1,1,1,-1,-1};
//int dy[] = {1,0,-1,0,1,-1,-1,1};

// bit manipulations

//bool checkbit(int mask,int bit){return mask & (1<<bit);}

//int setbit(int mask,int bit){ return mask  (1<<bit) ; }

//int clearbit(int mask,int bit){return mask & ~(1<<bit);}

//int togglebit(int mask,int bit){return mask ^ (1<<bit);}


#define mxn 100005
vi v[mxn];
i64 dp[mxn][3];

i64 dfs(int node,int nodeColor,int parent) {

    if(dp[node][nodeColor] != -1)
        return dp[node][nodeColor];

    i64 ans = 1;
    For(i,v[node].sz) {
        int child = v[node][i];
        if(child == parent) continue;
        i64 tem = dfs(child,0,node);
        if(!nodeColor)
            tem += dfs(child,1,node);
        tem %= mod;
        ans *= tem;
        ans %= mod;
    }
//    cout << node << " " << nodeColor << " " << ans << endl;
    return dp[node][nodeColor] = ans;
}

int main()
{
    int n,a,b;
    sf(n);
    For(i,n-1) {
        sff(a,b);
        v[a].pb(b);
        v[b].pb(a);
    }

    mem(dp,-1);
    cout << ( dfs(1,0,1) + dfs(1,1,1) ) % mod << endl;

    return 0;
}



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

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
  cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                               \
  cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define debug_4(x1, x2, x3, x4)                                           \
  cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                       \
  cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                      \
  CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
  (__VA_ARGS__)
#else
#define debug(...)
#endif

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

void Main() {
  int n;
  cin >> n;
  map<int, int> M;
  rep(i, n) {
    int a;
    cin >> a;
    M[a]++;
  }
  for(auto itr = M.begin(); itr != M.end(); ++itr) if (itr->second != 1) {
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

void Yes(){
    cout << "Yes\n";
    exit(0);
}

void No(){
    cout << "No\n";
    exit(0);
}

const int SIZE = 1e5+100;
ll n;
ll a[SIZE],cou2[3];

int main(){
    cin >> n;
    ll cou[3];
    bool f;
    for(int i = 0; i < 3; i++)cou[i] = -1;

    for(int i = 0; i < n; i++){
        f = false;
        cin >> a[i];
        for(int j = 0; j < 3; j++){
            if(cou[j] == -1){
                cou[j] = a[i];
                cou2[j]++;
                f = true;
                break;
            }
            else{
                if(cou[j] == a[i]){
                    cou2[j]++;
                    f = true;
                    break;
                }
            }
        }
        if(!f){
            No();
        }
    }
 
    if(cou[1] == -1){
        if(cou[0] == 0) Yes();
        else
        {
            No();
        }
    }
        


    for(int i = 0; i < 3; i++){
        if(cou[i] == -1){
                if(cou[0] == 0){
                    if(cou2[0]*2 == cou2[1]){
                        Yes();
                    }
                    else{
                        No();
                    }
                }
                else if(cou[1] == 0){
                    if(cou2[1]*2 == cou2[0]){
                        Yes();
                    }
                    else{
                        No();
                    }                    
                }
                else{
                    No();
                }
            }
    }


    if(cou2[0] == cou2[1] && cou2[1] == cou2[2]){
        /* 
        for(int i = 0; i < 3; i++){
            int j,k,l;
            j = i;
            k = i+1;
            l = i+2;
            if(k >= 3)  k-= 3;
            if(l >= 3) l -= 3;
            ll tmp = (cou[j]^cou[k]);
            if(tmp != cou[l]) No();
        }
        Yes();
        */
        if((cou[0]^cou[1]) == cou[2] && (cou[2]^cou[0]) == cou[1] && (cou[1]^cou[2]) == cou[0]){
            Yes();
        }
        else{
            No();
        }
    }
    else{
        No();
    }
}

Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

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

	sort(s.begin(), s.end()); //sは昇順に
	sort(t.begin(), t.end(), greater<char>()); //tは降順に

	if (s < t) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,s1=0,s2=0;
    cin >> n;
    int arr[n];
    for (int i=0; i < n; i++) {
        cin >> arr[i];
        s2+=arr[i];
    }
    s2 -= arr[0];
    s1 += arr[0];
    int d = abs(s2-s1);
    for (int i=1; i < n-1; i++) {
        s1 += arr[i];
        s2 -= arr[i];
        d = min(d, abs(s2-s1));
    }
    cout << d << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    string n; cin >> n;
    int ans = 0;

    for(int i = 0; i < n.size(); i++) {
        ans += n[i] - '0';
    }

    if(atoi(n.c_str()) % ans) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}




Measured memory_bytes: 256
#include <cstdio>

int main(){
	int N;
	int a[5] = {0,};

	scanf("%d",&N);
	
	for(int i=0,x;i<N;i++){
		scanf("%d",&x);
		if(x%4==0)x=4;
		else if(x%2==0)x=2;
		else x=1;

		a[x]++;
	}

	if(a[1]==0){
		puts("Yes");
		return 0;
	}

	int p=1;
	a[1]--;
	while(a[1]>0||a[4]>0){
		if(p==1){
			if(a[4]==0){
				puts("No");
				return 0;
			}
			p=4;
			a[4]--;
		}else{
			if(a[1]==0){
				puts("Yes");
				return 0;
			}
			p=1;
			a[1]--;
		}
	}
	if(p==1 && a[4]==0 && a[2]>0){
		puts("No");
	}else{
		puts("Yes");
	}
	return 0;
}


Measured memory_bytes: 128
N = int(input().strip())
ar = [N*[] for _ in range(N)]
for row in range(N):
  ar[row] = input().strip()

fullestRows = []
maxCount = 0
for row in range(N):
  count = 0
  for col in range(N):
    if ar[row][col] == '#':
      count += 1
  if count > maxCount:
    maxCount = count
    fullestRows = [row]
  elif count == maxCount:
    fullestRows.append(row)

if maxCount == 0:
  print(-1)
else:
  found = False
  req = 0
  for fr in fullestRows:
    for row in range(N):
      if ar[row][fr] == '#':
        found = True
        break
    if found:
      break
  if not found:
    req += 1
  req += N - maxCount
  
  for col in range(N):
    for row in range(N):
      if ar[row][col] == '.':
        req+=1
        break
  print(req)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  int sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0]))
c = 0
ans = 0
for i in a:
    if c + i[1] < m:
        c += i[1]
        ans += i[0]*i[1]
    else:
        for j in range(i[1]):
                c += 1
                ans += i[0]
                if c >=m:
                    break
        break
print(ans)

Measured memory_bytes: 29028
#include<stdio.h>
long long bei(long long a,long long b);
int main(){
	long long a[101];
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(i=1;i<n;i++){
		a[i+1]=bei(a[i],a[i+1]);
	}printf("%lld\n",a[n]);
	return 0;
}
long long bei(long long a,long long b){
	long long i,temp;
    if(a<b){
    	temp=a;
    	a=b;
		b=temp;
    }for(i=1; ;i++){
    	if(a*i%b==0)return a*i;
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(left(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll a[n];
	for(ll i=0; i<n; i++)
		cin >> a[i];
	sort(a, a+n);
	ll ans = INF, k;
	for(ll i=n-2; i>=0; i--){
		if(ans > abs(a[i]-(a[n-1]/2))){
			k = a[i];
			ans = a[i]-(a[n-1]/2);
		}
	}
	cout << a[n-1] << " " << k;
	return 0;
}

Measured memory_bytes: 4396
def solve(g):
    for i in range(1, h+1):
        for j in range(1, w+1):
            if g[i][j] == '#' and g[i][j+1] == '.' \
                    and g[i+1][j] == '.' and g[i][j-1] == '.' \
                    and g[i-1][j] == '.':
                        return False
    return True

h, w = list(map(int, input().split()))
g = [['.']*(w+2)]
g += [['.'] + list(input()) + ['.'] for i in range(h)]
g.append(['.']*(w+2))

if solve(g):
    print('Yes')
else:
    print('No')


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

int main()
{
	int n;
	cin>>n;
	int t1=0,x1=0,y1=0,t2,x2,y2;
	for(int i=1;i<=n;i++){
		cin>>t2>>x2>>y2;
		int t=abs(t2-t1);
		int x=abs(x2+y2-x1-y1);
		if (x>t || (x-t)%2!=0){
			cout<<"No"<<endl;
			return 0;
		}
		t1=t2;x1=x2;y1=y2;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();

		int ans = 0;

		sc.nextLine();

		char C[][] = new char[6][6];
		char CWk[][] = new char[6][6];
		char CWk2[][] = new char[6][6];

		// 取り込み
		for (int i=0; i<H; i++) {
			C[i] = sc.nextLine().toCharArray();
		}
	    // Scannerクラスのインスタンスをクローズ
		sc.close();

//		System.out.println("base");
//		for (int i=0; i<6; i++) {
//			System.out.println(new String(C[i]));
//		}
//		System.out.println(" ");

		int  HCase = (int) Math.pow(2, H);
		int  WCase = (int) Math.pow(2, W);
		String HFormat = "%" + H + "s";
		String WFormat = "%" + W + "s";

		for (int HNow=0; HNow<HCase; HNow++) {

			for (int i=0; i<H; i++) {
				for (int j=0; j<W; j++) {
					CWk[i][j] = C[i][j];
				}
			}
//			System.out.println(new String("print CWk"));
//			for (int i=0; i<H; i++) {
//				System.out.println(new String(CWk[i]));
//			}

//			System.out.println("H:" + H + ", 2^H:" + HCase);
//			System.out.println("W:" + W + ", 2^W:" + WCase);

			String HBinStr = String.format(HFormat, Integer.toBinaryString(HNow)).replace(' ', '0');

			for(int i = 0; i<HBinStr.length(); i++) {
				if(HBinStr.charAt(i) == '1') {
					for (int j=0; j<W; j++) {
						CWk[i][j] = 'R';
					}
				}
			}

//			System.out.println("Do H");
//			for (int i=0; i<H; i++) {
//				System.out.println(new String(CWk[i]));
//			}

			for (int WNow=0; WNow<WCase; WNow++) {

				for (int i=0; i<H; i++) {
					for (int j=0; j<W; j++) {
						CWk2[i][j] = CWk[i][j];
					}
				}

//				System.out.println(new String("print CWk2"));
//				for (int i=0; i<H; i++) {
//					System.out.println(new String(CWk2[i]));
//				}

				String WBinStr = String.format(WFormat, Integer.toBinaryString(WNow)).replace(' ', '0');

				for(int j = 0; j<WBinStr.length(); j++) {
					if(WBinStr.charAt(j) == '1') {
						for (int i=0; i<H; i++) {
							CWk2[i][j] = 'R';
						}
					}
				}

//				System.out.println(HNow  +", " + WNow);
//				for (int i=0; i<H; i++) {
//					System.out.println(new String(CWk2[i]));
//				}
//				System.out.println(" ");

				int ast = 0;
				for (int x=0; x<H; x++) {
					for (int y=0; y<W; y++) {
						if(CWk2[x][y] == '#') {
							ast += 1;
						};
					}
				}
				if(K == ast) {
					ans += 1;
				}
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 49140