akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

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

    int sum_min;
    sum_min = h * 60 + m;

    double k_a, k_b; // 角度
    k_a = sum_min * 0.5;
    k_b = sum_min * 6;
/**
    int i;
    for(i = k_a; i >= 360; i -= 360) {
        k_a = i;
    }
    for(i = k_b; i >= 360; i -= 360) {
        k_b = i;
    }
    **/

    double k_ab;
    if (k_a > k_b) {
        k_ab = k_a - k_b;
    }
    else {
        k_ab = k_b - k_a;
    }
    /**
    if (k_a == 0) {
        k_ab = 360 - k_b;
    }
    if (k_b == 0) {
        k_ab = 360 - k_a;
    }
    **/

    double dis, dis_tmp;
    dis_tmp = a * a + b * b - 2 * a * b * cos(k_ab / 180 * M_PI);
    dis = sqrt(dis_tmp);

    cout << fixed << setprecision(9) << dis << endl;
}


Measured memory_bytes: 4228
from collections import Counter
N, T = map(int, input().split())
A = [int(i) for i in input().split()]
m = A[0]
B = []
for a in A[1:]:
    B.append(a - m)
    m = min(m, a)
c = Counter(B)
print(c[max(c.keys())])

Measured memory_bytes: 72084
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int N;
	char S[1001];
	cin>>N;
	cin>>S;

	bool flag=0;
	while(!flag){
		int sta=0,end=0;
		int maxdow=0;
		for(int i=0;i<strlen(S);i++){
			if(S[i]=='('){
				end++;
			}
			else{
				end--;
				maxdow=max(maxdow,-1*end);
			}
		}
		string es=S,str=S;
		if(sta>end){
			str="("+es;
		}
		else if(sta<end){
			str=es+")";
		}
		else if(maxdow){
			string beg,fin;
			for(int i=0;i<maxdow;i++){
				beg+="(";
				fin+=")";
			}
			str=beg+es+fin;
		}
		else{
			flag=1;
		}
		strcpy(S,str.c_str());
	}
	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int[][] A = new int[3][3];
		for(int i=0;i<3;i++){
			String W = in.readLine();
			String[] Ws = W.split(" ");
			A[i][0] = Integer.parseInt(Ws[0]);
			A[i][1] = Integer.parseInt(Ws[1]);
			A[i][2] = Integer.parseInt(Ws[2]);
		}

		String W = in.readLine();
		int N = Integer.parseInt(W);

		for(int i=0;i<N;i++){
			W = in.readLine();
			int b = Integer.parseInt(W);

			for(int y=0;y<A.length;y++){
				for(int x=0;x<A[y].length;x++){
					if(A[x][y] == b){
						A[x][y] = -1;
					}
				}
			}
		}
		String ans ="No";
		for(int y=0;y<A.length;y++){
			boolean flg = true;
			for(int x=0;x<A[y].length;x++){
				if(A[x][y] != -1){
					flg=false;
					break;
				}
			}
			if(flg){
				ans="Yes";
			}
		}

		for(int y=0;y<A.length;y++){
			boolean flg = true;
			for(int x=0;x<A[y].length;x++){
				if(A[y][x] != -1){
					flg=false;
					break;
				}
			}
			if(flg){
				ans="Yes";
			}
		}

		if(A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1 ){
			ans="Yes";
		}

		if(A[2][0] == -1 && A[1][1] == -1 && A[0][2] == -1 ){
			ans="Yes";
		}


		System.out.println(ans);
	}


}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vii a(n,mp(0,0));
    for(ll i=0;i<n;i++)
    {
        cin>>a[i].S>>a[i].F;//deadline,duration
    }
    sort(a.begin(),a.end());
    ll t=0;
    bool fail=false;
    for(ll i=0;i<n;i++)
    {
        ll end_time=t+a[i].S;
        if(end_time>a[i].F)
        {
            fail=true;
            break;
        }
        t=end_time;
    }
    if(fail)
    {
        cout<<"No\n";
    }
    else
    {
        cout<<"Yes\n";
    }
}


Measured memory_bytes: 3328
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

x,n = map(int,input().split())
S = set(map(int,input().split()))
for i in range(100):
  if x-i not in S:
    print(x-i)
    break
  if x+i not in S:
    print(x+i)
    break

Measured memory_bytes: 65632
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p = 1e9 + 7;
const int maxn = 1e5 + 2;

void solve() {
    int Red = 0, N;
    cin >> N;
    string s; cin>>s;
    for(int i = 0; i < N; i++) {
        if(s[i] == 'R') Red++;
    }
    int W = 0;
    for(int i = 0; i < Red; i++) {
        if(s[i] == 'W') W++;
    }
    cout << W; 
}

int main() {
    fast 
    // input output
    int t = 1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3744
#include<stdio.h>
int number1[100],number2[100],number3[100];
int merge_it(int l,int m,int r)
{
    int i=0,j=0,k=0,in1=0,in2=0,index=l;
    for(i=l;i<=m;i++)number2[j++]=number1[i];
    for(;i<=r;i++)number3[k++]=number1[i];
    while(in1<j && in2<k)
    {
        if(number2[in1]>number3[in2])number1[index++]=number2[in1++];
        else number1[index++]=number3[in2++];
    }
    if(in1<j)
    {
        while(in1<j)
        {
            number1[index++]=number2[in1++];
        }
    }
    else
    {
        while(in2<k)
        {
            number1[index++]=number3[in2++];
        }
    }
    return 0;
}
int merge(int lower,int highest)
{
    int mid;
    if(lower==highest)return 0;
    else
    {
        mid=(lower+highest)/2;
        merge(lower,mid);
        merge(mid+1,highest);
        merge_it(lower,mid,highest);
    }
}
int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m)==2)
    {
        int sum=0,i;
        for(i=0;i<n;i++)scanf("%d",&number1[i]);
        merge(0,n-1);
        for(i=0;i<m;i++)sum+=number1[i];
        printf("%d\n",sum);

    }
    return 0;
}


Measured memory_bytes: 128
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int f(int a, int b) {
  return min(a - b, b);
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int>a(n);
  for(auto &e:a) cin >> e;
  int x = *max_element(rbegin(a), rend(a));
  pair<int, int> best(-1, 0);
  for(int i = 0; i < n; i++) {
    if(a[i] != x) best = max(best, make_pair(f(x, a[i]), a[i]));
  }
  cout << x << " " << best.second << endl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;
 
  for (int i = 0; i < S.size(); i++) {
    if(S.at(i)=='1'){
     cout<<'9';
    }
    else{
      cout<<'1';
    }
  }
  
    cout<<endl;
  
}






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

#define  ll         long long
#define  llu        unsigned long long
#define  mod        1000000007
#define  pi         ((2.0)*acos(0.0))
#define  pb         push_back
#define  pf         push_front
#define  eb         emplace_back
#define  mp         make_pair
#define  all(x)     (x).begin(),(x).end()
#define  X          first
#define  Y          second

/*loop*/
#define  fr(i,m,n)   for(ll i=m;i<n;++i)

/*output shortcuts*/
#define  nl         "\n"
#define  Yes        cout<<"Yes\n"
#define  yes        cout<<"yes\n"
#define  YES        cout<<"YES\n"
#define  No         cout<<"No\n"
#define  no         cout<<"no\n"
#define  NO         cout<<"NO\n"

using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s,t;
    cin>>s>>t;

    ll x=s.size();
    ll y=t.size();

    ll dp[x+1][y+1];
    char dir[x+1][y+1];

    fr(i,0,x+1)
    {
        fr(j,0,y+1)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
                continue;
            }

            if(s[i-1]==t[j-1])
            {
                dir[i][j]='S';
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);

                if(dp[i][j]==dp[i][j-1])
                    dir[i][j]='L';
                else
                    dir[i][j]='U';
            }
        }
    }
        //cout<<dp[x][y]<<nl;
        /*printing the sub-string*/
        ll a=dp[x][y];
        //cout<<a<<nl;
        string sub="";
        while(a>0)
        {
            if(dir[x][y]=='S')
            {
                sub.pb(s[x-1]);
                x--; y--; a--;
                continue;
            }
            if(dir[x][y]=='L')
            {
                y--; continue;
            }
            if(dir[x][y]=='U')
            {
                x--; continue;
            }
        }

        reverse(all(sub));

        cout<<sub<<nl;

return 0;
}


Measured memory_bytes: 82736
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

class State{
public:
  int d;
  int p;
};

int n, m;

vector<int> E[500];
int dist[500];
const int INF = 1000000000;

int solve(){
  int ans = 0;
  State u, v;
  u.p = 0;
  u.d = 0;
  dist[0] = 0;
  queue<State> Q;
  Q.push(u);
  while(!Q.empty()){
    u = Q.front(); Q.pop();
    for(int i=0;i<E[u.p].size();i++){
      if(u.d + 1 < dist[E[u.p][i]] && u.d <= 1){
	v.p = E[u.p][i];
	v.d = u.d + 1;
	dist[v.p] = v.d;
	Q.push(v);
      }
    }
  }
  for(int i=0;i<n;i++){
    if(dist[i]<=2 && dist[i] != 0){
      ans++;
    }
  }
  return ans;
}

main(){
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    for(int i=0;i<500;i++) E[i].clear();
    fill(dist, dist+500, INF);
    for(int i=0;i<m;i++){
      int a, b;
      cin >> a >> b;
      E[a-1].push_back(b-1);
      E[b-1].push_back(a-1);
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf=1000000007;
const ll maxinput=100005;
const ll mod=998244353;
#define mp make_pair
int main()
{
    int n;cin>>n;
    int activity[n][3];
    for(int i=0;i<n;i++)
        cin>>activity[i][0]>>activity[i][1]>>activity[i][2];

    int dp[n][3]; 
    //dp[i][0] is the maximum happiness he gets at the end of ith day if on ith day he is swimming 
    //dp[i][1] is the maximum happiness he gets at the end of ith day if on ith day he is catching bugs 
    //dp[i][2] is the maximum happiness he gets at the end of ith day if on ith day he is doing homework 

    dp[0][0]=activity[0][0];dp[0][1]=activity[0][1];dp[0][2]=activity[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=2;j++)
            dp[i][j]=activity[i][j]+max({(j==0)?0:dp[i-1][0],(j==1)?0:dp[i-1][1],(j==2)?0:dp[i-1][2]});
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<"\n";
}

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

int main() {
	int r, g, b, sum;
	cin >> r >> g >> b;

	r = 100 * r;
	g = 10 * g;
	sum = r + g + b;
	
	if (sum % 4 == 0) {
		cout << "YES"<< endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,d = map(int, input().split())
array = [list(map(int, input().split())) for i in range(n)]
sqarray = [i**2 for i in range(130)]
count = 0

for i in range(n-1):
    for j in range(i+1, n):
        dis = sum([(array[i][k] - array[j][k])**2 for k in range(d)])
        if dis in sqarray:
            count += 1
            
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int a,b,c,d,ans,tmp;
    string s;
 
   cin >> c >> a >> b;
  	a = c*a;
  	if(a > b){
      cout << b;
    }else{
      cout << a;
    }

}


Measured memory_bytes: 3584
# include <iostream>
# include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
int main(void) {
    fast_cin();

    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    

    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k1 = sc.nextInt();
		long[][] dp = new long[h+1][w];
		long mod=1000000007;
		dp[0][0]=1;
		for(int i=1; i<=h; i++){
			for(int j=w-1; j>=0; j--){
				for(int k=0; k<Math.pow(2,w-1); k++){
					boolean a=false;
					boolean b=false;
					boolean jud=false;
					int count=0;
					int y=k;
					while(y>0){
						if((y&1)==1){
							if(jud){
								break;
							}
							if(w-1-count==j){
								a=true;
							}else if(w-1-count==j+1){
								b=true;
							}
							jud=true;
						}else{
							jud=false;
						}
						count++;
						y>>=1;
						if(y<=0){
							jud=false;
						}
					}
					if(jud){
						continue;
					}
					if(j>0 && a){
						dp[i][j]+=dp[i-1][j-1];
					}else if(j<w-1 && b){
						dp[i][j]+=dp[i-1][j+1];
					}else{
						dp[i][j]+=dp[i-1][j];
					}
					dp[i][j]%=mod;
				}
			}
		}
		System.out.println(dp[h][k1-1]);
	}
}


Measured memory_bytes: 22612
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Exponential
	var X int
	fmt.Scanf("%d", &X)

	if X == 1 {
		fmt.Println("1")
	} else {
		var max int
		for b := 1; b < X; b++ {
			for p := 2; p < 100; p++ {
				A := int(math.Pow(float64(b), float64(p)))
				if A > X {
					break
				} else {
					if max < A {
						max = A
					}
				}
			}
		}
		fmt.Println(max)
	}
}


Measured memory_bytes: 1836
n = int(input())

p = list(map(int,input().split()))

count = 0

for i in range(1, n+1):
    if i <= n - 2:
        if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
            count += 1

print(count)

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

using namespace std;
typedef long long ll;

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

    vector<int> A;
    for (int i = 0; i < K; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int a;
            cin >> a;
            A.push_back(a);
        }
    }

    int count = 0;
    for (int i = 1; i <= N; i++)
    {
        bool flag = false;
        for (const auto &a : A)
        {
            //cout << "a " << a << endl;
            if (a == i)
            {
                flag = true;
                break;
            }
        }

        if (!flag)
            count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main () {
  long long X, K, D;
  cin >> X >> K >> D;
  if(X < 0)X *= -1;
  if(X / D <= K){
    K -= (X / D);
    X -= (X / D) * D;
    if(K % 2 == 0)cout << X << endl;
    else cout << abs(X - D) << endl;
  } else {
    X -= D * K;
    cout << X << endl;
  }
  
  return 0;
}

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

using namespace std;

//defined variable and data types and structures here
#define ll long long 
#define ull unsigned long long
#define V(a) vector<a>
#define VV(a) vector<vector(a)>
#define P(a,b) pair<a,b>
#define pb push_back
#define eb emplace_back //use instead of pb(mp(a,b))
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define Hashmap(a,b) unordered_map<a,b>


//define functions here
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define bcount(a) _builtin_popcount(a)
#define sz(a) sizeof(a)

//optimizations
#define io {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}

const int MOD=(int)1e9+7;

//dp implemetatiom of computinf nCr
ll binC(ll n, ll k) {
   ll C[k+1];
   ll j;
   rep(j,0,k+1){
       C[j]=0;
   }
   C[0] = 1;
   for (ll i = 1; i <= n; i++) {
      for (ll j = min(i, k); j > 0; j--)
         C[j] = C[j] + C[j-1];
   }
   return C[k];
} 

template <typename T>
T minn(T a, T b){
    return (a<b)?a:b;
}

template <typename T>
T maxx(T a, T b){
  return (a<b)?b:a;
}



void solve(){
   ll x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<"\n";

}
int main() {
   io;
auto start = chrono::steady_clock::now();
#ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin); 
   //freopen("output.txt", "w", stdout); 
 #endif
   ll t=1;
   //cin>>t;
   while(t--){
    solve();
   }

    return 0;
}

Measured memory_bytes: 256
def cc
    n,m = gets.chomp.split(/\s/).map{|x| x.to_i}

    py = []
    for i in 0..(n)
        py[i] = []
    end

    for i in 1..m
        pr, y = gets.chomp.split(/\s/).map{|x| x.to_i}
        py[pr].push([i-1, y])
    end

    for i in 0..(n)
        py[i] = py[i].sort {|a,b| (a[1] <=> b[1]).nonzero? || a[2] <=> b[2]}
    end
    #p py
    #p py.sort {|a,b| a[1].sort {|c,d| c[1]<=>d[1]} > b[1] }
    #p py.sort {|a,b| (a[1] <=> b[1]).nonzero? || a[2] <=> b[2]}

    cnt = 0
    for i in 0..(n)
        pz = py[i]
        pz.each_with_index do |pa,idx|
            pa.push(cnt, idx+1)
        end
        cnt += 1
    end
    py.flatten(1).sort {|a,b| a[0] <=> b[0]}.each do |pz|
        puts sprintf("%06d%06d", pz[2], pz[3])
    end

end

cc

Measured memory_bytes: 44648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int mod=int(1e9)+7;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin>>n;
    ll w;
    cin>>w;
    ll d[n+1],v[n+1];
    ll k=0;
    for(int i=0;i<n;i++){
        cin>>d[i+1];
        cin>>v[i+1];
        k+=v[i+1];
    }
    ll dp[n+1][k+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=k;j++){
            dp[i][j]=ll(1e18);
            if(j==0){
                dp[i][j]=0; 
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(v[i]<=j){
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+d[i]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    ll ans=LLONG_MIN;
    for(int i=k;i>=0;i--){
        if(dp[n][i]<=w&&(dp[n][i]!=ll(1e18))){
            ans=max(ans,(ll)i);
            break;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 82512
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void)
{	
	int h, w;
	cin >> h >> w;
	vector<vector<char>>a(h, vector<char>(w));
	vector<vector<int>>b(h, vector <int> (w,0));
	vector<vector<int>>c(h, vector <int>(w, 0));
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '#') {
				rep(k, h) {
					b[k][j]++;
				}
				rep(k, w) {
					c[i][k]++;
				}
			}
		}
	}

	rep(i, h) {
		bool println = false;
		rep(j, w) {
			if (b[i][j] >= 1 && c[i][j] >= 1) {
				cout << a[i][j];
				println = true;
				if(j==w-1)cout << "" << endl;
			}
			else if (j == w - 1 && println)cout << "" << endl;
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll N,M; cin >> N>>M;
  vi a(M);
  ll sum = 0;
  rep(i,M) {
    cin >> a[i];
    sum += a[i];
  }
  ll ans = N-sum;
  if (ans<0) ans = -1;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef pair <int, int> pii;
typedef vector <int> vii;
typedef complex <double> Point;

#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mp make_pair
#define fst first
#define snd second

long long t, n, m, u, v, q, k;
const int N = 2e5 + 500;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 61LL;
long long arr[N];

vector <int> adj[N];
vector <long long> edges[N];

int assign(int v, int p) {
  
  long long res = 2 * arr[v];
  if (adj[v].size() == 1) res = arr[v];
  for (int i = 0; i < adj[v].size(); ++i) {
    int u = adj[v][i];
    if (u == p) continue;
    int p_id = assign(u, v);
    res -= edges[u][p_id];
    edges[v][i] = edges[u][p_id];
  }
  int ret = 0;
  for (int i = 0; i < adj[v].size(); ++i) {
    int u = adj[v][i];
    if (u != p) continue;
    ret = i;
    edges[v][i] = res;
    //cout << v << " " << edges[v][i] << endl;
  }
  return ret;
}
int main() {
  csl;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> arr[i];
  
  if (n == 2) {
    if (arr[1] == arr[2]) cout << "YES\n";
    else cout << "NO\n";
    return 0;
  }
  
  for (int i = 1; i <= n - 1; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    edges[u].push_back(0);
    edges[v].push_back(0);
  }
  int root = 1;
  for (int i = 1; i <= n; ++i) {
    if (adj[i].size() >= 2) {
      root = i;
      break;
    }
  }
  assign(root, 0);
  bool valid = true;
  for (int i = 1; i <= n; ++i) {
    long long sum = 0;
    long long max_edge = 0;
    if (adj[i].size() == 1) continue;
    for (long long weight : edges[i]) {
      if (weight < 0) valid = false;
      sum += weight;
      max_edge = max(max_edge, weight);
    }
    if (i == root) {
      if (sum != 2 * arr[root]) {
        valid = false;
      }
    }
    //cout << max_edge << " " << sum << endl;
    if (sum % 2 != 0) valid = false;
    if (max_edge > sum / 2) valid = false;
  }
  
  if (valid) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}


















Measured memory_bytes: 24704
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

bool isprime(int x){
  if(x==2){ return true; }
  if(x<2 || x%2==0){ return false; }
  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}

int calc(int n, int x){
  int k=0;
  while(n/1){
    k += n/x;
    n /= x;
  }
  return k;
}

int main(){
  int n;
  cin >> n;
  ll ans=1;
  for(int i=1; i<=n; i++){
    if(isprime(i)){
      ans *= (calc(n,i)+1);
      ans %= mod;
    } 
  }
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;

    ll res = min(n % k, k - n % k);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long ans = 0;
    int N;
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        int a,b;
        cin >> a >> b;
        ans += b-a+1;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b)
    {
        printf("a > b\n");
    }
    else if(a<b)
    {
        printf("a < b\n");
    }
    else
    {
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<cstdio>
#include<cstring>
using namespace std;
int n,now;
char s[100010];
int main() {
	scanf("%s",s+1); n=strlen(s+1);
	if (s[n]=='1') {
		printf("-1\n"); return 0;
	}
	if (s[1]=='0') {
		printf("-1\n"); return 0;
	}
	for (int i=1,j=n-1;i<n;i++,j--) if (s[i]!=s[j]) {
		printf("-1\n"); return 0;
	}
	now=1;
	for (int i=2;i*2<=n;i++) {
		if (s[i]=='1') {
			printf("%d %d\n",now,i);
			for (int j=now+1;j<i;j++) printf("%d %d\n",i,j);
			now=i;
		}
	}
	for (int i=now;i<n;i++) printf("%d %d\n",i,n);
	return 0;
}

Measured memory_bytes: 1536
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


#include <stdio.h>

#include<stdio.h>

int main(void)
{
	int  i, cnt = 0;
	int  x,a[101],n;

	i_cin2(n,x);
	i_cins(n, a);
	qsort(a,n,sizeof(int),s_asort);
	
	for (i = 0; i < n; i++) {
		if (!a[i]) continue;
		cnt++;
		x -= a[i];
		if (x <= 0)break;
	}
	
	(!x) ? i_cout(cnt) : i_cout(cnt - 1);
	return 0;
}



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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<=n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define sz(v) ((int)(v).size())
#define get(a,st,en)  fl(i,st,en)       cin>>a[i]
#define pr(a,st,en)     fl(i,st,en)     cout<<a[i]<<" \n"[i==en]
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod = 1e9+7;
// credits @Benq
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/
void trial_division1(long long n) {
        ll ans = 0;
    for (long long i = 2; i * i <= n; i++) {
        if(n%i == 0)    {
                int reqd = 1, cnt = 0;
                while(n%i == 0) {
                        n /= i;
                        cnt++;
                        if(cnt == reqd) {
                                ans++;
                                reqd++;
                                cnt = 0;
                        }
                }
        }
    }
    if (n > 1)  ans++;
    cout<<ans;
}
void solve()    {
        ll n;   cin>>n;
        if(n==1)        {
                cout<<0;
                return;
        }
        trial_division1(n);
}
int main()  {
    fast;
    //test()
        solve();
}


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

int main()
{
    vector<int> v(100002, 0);
    int N;
    cin >> N;
    for (int i=0; i<N; i++)
    {
        int tmp;
        cin >> tmp;
        v[tmp]++;
        v[tmp+1]++;
        v[tmp+2]++;
    }
    int res = *max_element(v.begin(), v.end());
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main()
{
ll ans=0,n;
cin >> n;
int table[n]={};
rep(i,n) {
    cin >> table[i];
}

rep(i,n) {
    table[i]+=n-i;
}
sort(table,table+n);
ll me=table[n/2];

rep(i,n) {
    ans+=abs(table[i]-me);
}
cout << ans << endl;
return 0;
}





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

using namespace std;

int main()
{
  int N,A,B;
  cin>> N>> A>> B;

  int ret=0;
  for(int i=1;i<=N;i++)
  {
    cerr<< "::"<< i<< endl;
    int num=i;
    int sum=0;
    while(num)
    {
      sum+=num%10;
      num/=10;
      cerr<< ":"<< sum<< " "<< num<< endl;
    }
    if(A<=sum&&sum<=B)ret+=i;
  }
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll MEMO[2001][2001];

int main() {
  ll H, W;
  cin >> H >> W;
  vector<string> map(H);
  for (int i = 0; i < H; i++) {
    cin >> map[i];
  }
  for (int i = 0; i < H; i++) {
    ll left_serial_cnt = 0, right_serial_cnt = 0;
    for (int j = 0; j < W; j++) {
      MEMO[i][j] += left_serial_cnt++;
      if (map[i][j] == '#') left_serial_cnt = 0;
      MEMO[i][W - j - 1] += right_serial_cnt++;
      if (map[i][W - j - 1] == '#') right_serial_cnt = 0;
    }
  }
  for (int j = 0; j < W; j++) {
    ll up_serial_cnt = 0, down_serial_cnt = 0;
    for (int i = 0; i < H; i++) {
      MEMO[i][j] += up_serial_cnt++;
      if (map[i][j] == '#') up_serial_cnt = 0;
      MEMO[H - i - 1][j] += down_serial_cnt++;
      if (map[H - i - 1][j] == '#') down_serial_cnt = 0;
    }
  }
  ll ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (map[i][j] == '.') ans = max(ans, MEMO[i][j]);
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

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

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> sum(n);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(i == 0) sum[i] = a;
        else sum[i] = sum[i-1] + a;
    }

    map<ll, ll> mp;
    mp[0]++;
    for(int i = 0; i < n; i++) mp[sum[i]]++;
    
    ll ans = 0;
    for(auto p : mp) ans += p.second * (p.second - 1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 14336
using System;

namespace Atcoder
{
    class ABC163_B
    {
        static void Main(string[] args)
        {
            string[] str1 = Console.ReadLine().Split(' ');
            int n = int.Parse(str1[0]);
            int m = int.Parse(str1[1]);
            int[] An = new int[m];
            int sum = 0;
            string[] str2 = Console.ReadLine().Split(' ');
            for(int i = 0; i < m; i++)
            {
                An[i] = int.Parse(str2[i]);
                sum += An[i];
            }
            if(sum <= n)
            {
                Console.Write(n - sum);
            }
            else
            {
                Console.Write("-1");
            }
        }
    }
}


Measured memory_bytes: 28504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().exec();
	}

	public void exec() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(br.readLine());
		long[] fib = {1,1,1};
		int ptr = 0;
		long ans = 1;
		for(int i=2; i<=n; i++, ptr=(ptr+1)%3) {
			ans = fib[ptr] = fib[(ptr+1)%3] + fib[(ptr+2)%3];  
		}
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 24316
N = int(input())
CSF = [[int(x) for x in input().split()] for _ in range(N-1)]

time = [0]*N    
for i in range(1,N):    
    for j in range(i):
        if time[j]<CSF[i-1][1]:
            time[j] = CSF[i-1][1]+CSF[i-1][0]
        else:
            time[j] += (CSF[i-1][2]-time[j])%CSF[i-1][2] + CSF[i-1][0]
for i in range(N):
    print(time[i])


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

int main() {
    int N; string S;
    cin >> N >> S;
    long long r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') ++r;
        else if (c == 'G') ++g;
        else ++b;
    }
    long long all = r * g * b;
    long long sub = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if (S[i] == S[j]) continue;
            int k = j*2-i;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) continue;
            ++sub;
        }
    }
    cout << all - sub << endl;
}

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


int main()
{
    int x = 50000;
    int pn[50001];

    for( int i = 0; i < 50001; i++ )
        pn[i] = 0;

    //50000以下の素数を配列に格納
    for( int i = 2; i <= x; i++ )
    {
        bool judge = true;
        for( int j = 2; j <= sqrt(i); j++ )
        {
            if( i % j == 0 )
            {
                judge = false;
                break;
            }
        }
        if( judge == true )
            pn[i] = i;
    }

    //整数の入力
    int n;
    while( cin >> n )
    {
        if( n == 0 )
            break;

        int cnt = 0;

        for( int i = 2; i <= n / 2; i++ )
            if( pn[i] != 0 && pn[n-i] != 0 )
                cnt++;
        
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 123;
 
int f[N + 5][N + 5][N + 5];
 
const int inf = (int)1e9;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        f[i][j][k] = inf;
      }
    }
  }
  f[a][b][c] = 0;
  for (int i = a; i < N; ++i) {
    for (int j = b; j < N; ++j) {
      for (int k = c; k < N; ++k) {
        f[i + 1][j + 1][k] = min(f[i + 1][j + 1][k], f[i][j][k] + 1);
        f[i + 1][j][k + 1] = min(f[i + 1][j][k + 1], f[i][j][k] + 1);
        f[i][j + 1][k + 1] = min(f[i][j + 1][k + 1], f[i][j][k] + 1);
        f[i + 2][j][k] = min(f[i + 2][j][k], f[i][j][k] + 1);
        f[i][j + 2][k] = min(f[i][j + 2][k], f[i][j][k] + 1);
        f[i][j][k + 2] = min(f[i][j][k + 2], f[i][j][k] + 1);
      }
    }
  }
  int ans = inf;
  for (int i = a; i < N; ++i) {
    for (int j = b; j < N; ++j) {
      for (int k = c; k < N; ++k) {
        if (i == j && j == k) {
          ans = min(ans, f[i][j][k]);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8448
def f(a,b)
#	a,b = b,a unless a <= b
	d = b/a
	b %= a
	return (2*d-1)*a if b == 0
	2*d*a + f(b,a)
end




n,x = gets.split.map(&:to_i)
p n+f(* [x,n-x].sort)


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    int piece = 0, offset = 0;
    vector<int> x, y;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'o') {
                piece++;
                offset += n + m - i - j;
                x.push_back(i);
                y.push_back(j);
            }
        }
    }

    mcf_graph<int, int> f(piece + n * m + 2);
    const int st = piece + n * m, t = piece + n * m + 1;
    vector visited(piece, vector(n, vector(m, false)));
    for (int i = 0; i < piece; i++) {
        f.add_edge(st, i, 1, 0);
        queue<pair<int, int>> q;
        q.emplace(x[i], y[i]);
        while (not q.empty()) {
            auto t = q.front();
            q.pop();
            int k = t.first, l = t.second;
            if (visited[i][k][l] or s[k][l] == '#') continue;
            visited[i][k][l] = true;
            f.add_edge(i, piece + k * m + l, 1, 0);
            if (k + 1 < n and not visited[i][k + 1][l] and s[k + 1][l] != '#') q.emplace(k + 1, l);
            if (l + 1 < m and not visited[i][k][l + 1] and s[k][l + 1] != '#') q.emplace(k, l + 1);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] != '#') f.add_edge(piece + i * m + j, t, 1, n + m - i - j);
        }
    }

    cout << offset - f.flow(st, t).second << endl;
}


Measured memory_bytes: 7580
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();

	    int m= 1;
	    
int i=0;
           while(true) {
        	   if(Math.pow(2, i)<=N) {
        		   m=(int)Math.pow(2, i);
        		   i++;
        	   }else {
        		   break;
        	   }
           }


	   
	    System.out.print(m);

//        if (t.equals("Sunny")) {
//        	System.out.print("Cloudy");
//        }else if(t.equals("Cloudy")){
//        	System.out.print("Rainy");
//        } else {
//        	System.out.print("Sunny");
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35252
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

int n, m, nxt[N][26];
string s, t;

int32_t main(){_

   cin >> s >> t;

   n = sz(s), m = sz(t);

   for (int i = 0; i < 26; ++i)
   {
      nxt[n][i] = n;
   }

   for (int i = n-1; i >= 0; --i)
   {
      for (int j = 0; j < 26; ++j)
      {
         nxt[i][j] = nxt[i+1][j];
      }
      int x = s[i] - 'a';
      nxt[i][x] = i;
   }

   int prev = -1, ans = 0, cnt = 0;
   for (int i = 0; i < m; )
   {
      int x = t[i] - 'a';
      if(nxt[prev+1][x] >= n){
         ans += (n-1)-prev;
         prev = -1;
         cnt++;
      }
      else{
         cnt = 0;
         ans += nxt[prev+1][x] - prev;
         prev = nxt[prev+1][x];
         ++i;
      }
      if(cnt >= 100){
         cout<<-1;
         exit(0);
      }
   }

   cout<<ans;

   return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)

#define ln << endl

const int MOD = 1e9 + 7;

int main() {
    int N; cin >> N;
    string O; cin >> O;

    times(2, a) times(2, b) {
        vector<bool> S(N + 2);
        S[0] = a; S[1] = b;

        times(N, i) {
            S[i+2] = S[i] == S[i+1] == (O[i] == 'o');
        }
        if(S[0] == S[N] && S[1] == S[N+1]) {
            times(N, i) cout << (S[i+1] ? 'S' : 'W');
            cout ln;
            return 0;
        }
    }

    cout << -1 ln;

    return 0;
}


Measured memory_bytes: 512
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
using ll = long long int;

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

    ll place[n + 1];
    for(int i=1; i<=n; i++){
        ll a;
        cin >> a;
        place[a] = i;
    }

    ll ans = 0;
    set<ll> used = {0, n+1};

    for(int i=1; i<=n; i++){
        ll r, l;
        auto itr = used.lower_bound(place[i]);
        r = *itr;
        l = *(--itr);

        ans += i * (place[i] - l) * (r - place[i]);
        used.insert(place[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    int A=0;

    vector<int>x(N);
    vector<int>y(M);
    for(int i=0;i<N;i++){
        cin>>x[i];
    }
    for(int i=0;i<M;i++){
        cin>>y[i];
    }
    sort(x.begin(), x.end()); 
    reverse(x.begin(), x.end());
    sort(y.begin(), y.end()); 
    
    for(int i=x[0]+1;i<=y[0];i++){
        if(i>X&&i<=Y){
            A=1;
            break;
        }
    }
    
    if(A==1){
        cout<<"No War"<<endl;
    }
    else{
        cout<<"War"<<endl;
    }
}

Measured memory_bytes: 3556
#include <iostream>
#define LEN 2000000
using namespace std;

int N, A[LEN+1];

void maxHeapify(int i)
{
    int l, r, larget;
    l=2*i;
    r=2*i+1;
    if( l<=N&&A[l]>A[i]) larget=l;
    else larget=i;
    if( r<=N&&A[r]>A[larget]) larget =r;
    if(larget!=i){
        swap(A[i],A[larget]);
        maxHeapify(larget);
    }
}

int main()
{
    cin>>N;
    for(int i=1;i<=N;i++) cin>>A[i];
    for(int i=N/2;i>=1;i--) maxHeapify(i);
    for(int i=1;i<=N;i++) cout<< " " <<A[i];
    cout<< endl;
    return 0;
}




Measured memory_bytes: 4952
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		long ans = 0;
		for(var i=0;i<N;i++){
			for(var j=i+1;j<N;j++){
				ans += A[i]*A[j];
			}
		}
		Console.WriteLine(ans);
	}
}

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)

// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < n; ++i){
// 		res += max(0ll, a[i]-x/f[i]);
//     }
//     return res <= k;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }



int main(){
  string S;
  cin >> S;
  vector<int> a(4, 0);
  REP(i, S.size()){
    if(S.at(i) == 'N') a.at(0)++;
    if(S.at(i) == 'W') a.at(1)++;
    if(S.at(i) == 'S') a.at(2)++;
    if(S.at(i) == 'E') a.at(3)++;
  }
if(a.at(0) == 0 && a.at(2) != 0) no;
else if(a.at(1) == 0 && a.at(3) != 0) no;
else if(a.at(2) == 0 && a.at(0) != 0) no;
else if(a.at(3) == 0 && a.at(1) != 0) no;
else yes;


}

Measured memory_bytes: 256