akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	vector<vector<int>> xy(N, vector<int>(N, -1));

	int x, y;
	rep(i, N){
		cin >> A[i];
		rep(j, A[i]) {
			cin >> x >> y;
			xy[i][x-1] = y;
 		}
	}

	int ans = 0;
	for (int i = 0; i < 1 << N; ++i) {
		int truth_cnt = 0;
		bool check = true;
		vector<int> list(N, 0);

		for (int j = 0; j < N; ++j) {
			if ((i >> j) & 1) {
				list[j] = 1;
				truth_cnt += 1;
			}
		}

		for (int j = 0; j < N; ++j) {
			if (list[j] == 1) {
				for (int k = 0; k < N; ++k) {
					if (xy[j][k] != -1) {
						if (list[k] != xy[j][k]) {
							check = false;
							break;
						}
					}
				}
			}
		}
		
		if (check) {
			ans = max(ans, truth_cnt);
		}
	}

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


Measured memory_bytes: 3644
main = do
    l <- getLine
    let (a:b:[]) = map read $ words l :: [Int]
        x = area a b
        y = circumference a b
    putStrLn $ show x ++ " " ++ show y

area :: Int -> Int -> Int
area a b = a * b

circumference :: Int -> Int -> Int
circumference a b = ( a + b) * 2


Measured memory_bytes: 3572
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;

int main(){
	int d[60];
	int i;
	int j;
	int n;
	int ans=0;
	cin >> n;
	rep(i, n) cin >> d[i];
	for(i=0; i<n-1; i++){
		repx(j, n, i+1){
			ans += d[i]*d[j];
		}
	}
	cout << ans <<endl;
}


Measured memory_bytes: 256
import itertools
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
#print(ab)
N_list = [i for i in range(1, N + 1)]

Np_list = list(itertools.permutations(N_list))
ans = 0
for p in Np_list:
    #print(p)
    flag = True
    if p[0] != 1:
        continue
    for j in range(len(p) - 1):
        if p[j] < p[j+1] and [p[j], p[j + 1]] not in ab:
            flag = False
        elif p[j] > p[j + 1] and ([p[j + 1], p[j]] not in ab):
            flag = False
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 8052
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const int inf = 1 << 30;
const int maxn = 1e5;
LL ans = 0;
int main(){
	int n,num[maxn+5] = {0};
	cin >> n;
	for(int i = 1;i<=n;i++){
		cin >> num[i];
		ans += abs(num[i]-num[i-1]);
	}
	ans += abs(num[n]);
	for(int i = 1;i<=n;i++){
		LL pos = ans;
		pos -= abs(num[i]-num[i-1]);
		pos -= abs(num[i+1]-num[i]);
		pos += abs(num[i+1]-num[i-1]);
		cout << pos << endl;
	}
	return 0;
}

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

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

    int taste[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> taste[i];
        sum += taste[i];
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        res += taste[i] * (sum - taste[i]);
    }

    cout << res / 2 << endl;
}

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

int main()
{
  int n;
  bool flag = false;

  cin >> n;
  for (int i = 1; i < 10; i++)
  {
    for (int j = 1; j < 10; j++)
    {
      if (n == i * j)
        flag = true;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
S = input()

ans = 0

for i in range(1 << len(S) - 1):
    op = []
    for j in range(len(S) - 1):
        if i >> j & 1:
            op.append('+')
        else:
            op.append('')
    op.append('')
    exp = ''
    for e in zip(S, op):
        exp += ''.join(e)
    ans += eval(exp)

print(ans)


Measured memory_bytes: 3060
#include <cstdio>

int main() {
	int w, h;
	while(true) {
		scanf("%d %d", &h, &w);
		if(w == 0 & h == 0) break;
		for(int i = 1; i <= w*h; i++) {
			printf("#");
			if(i % w == 0) printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1000
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        mut s: Chars,
        mut t: Chars,
    }

    s.sort();
    t.sort();
    t.reverse();
    if s<t {
        println!("Yes");
    } else {
        println!("No");
    }

}


Measured memory_bytes: 2144
#include <iostream>

using namespace std;

int main()
{
    long long n,x,t;
    long long s=0,c=0;
    cin >> n >> x >> t;
    while(c < n)
    {
        c = c+x;
        s = s+t;
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 3588
int M[10][10];
int x,y,s,i,j;
int main(){
	while(~scanf("%d,%d,%d",&x,&y,&s)){
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				if(s==2){
					if(fmax(abs(i-x),abs(j-y))<=1)M[i][j]+=1;
				}else{
					if(abs(i-x)+abs(j-y)<=(s+1)/2)M[i][j]+=1;
				}
			}
		}
	}
	int ac=0,ans=0;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(M[i][j]==0)ac++;
			ans=fmax(ans,M[i][j]);
		}
	}
	return !printf("%d\n%d\n",ac,ans);
}

Measured memory_bytes: 0
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long ans=100000000;
    long long N;

    cin >> N ;
    vector<long long>a(N,0);

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

    for(int i=0; i<N; i++){
        long long temp=a[i];
        long long num=0;
        while(temp%2==0){
            num++;
            temp/=2;
        }
        ans=min(num, ans);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**9)

n = int(input())
tree = [[] for _i in range(n)]
for _i in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

c = deque(sorted(list(map(int, input().split())), reverse=True))
visit = [-1 for _i in range(n)]
visit[0] = c.popleft()

def solve(p):
    r = 0
    for i in tree[p]:
        if visit[i] < 0:
            visit[i] = c.popleft()
            r += visit[i]
            r += solve(i)
    return r
x = solve(0)
print(x)
print(*visit)

Measured memory_bytes: 56152
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s = 700;
  string A;
  cin >> A;
  for(int i = 0; i < 3; i++){
  	if(A[i] == 'o'){
    	s += 100;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

// use unordered_map to save memory usage
unordered_map<int, int> mp;
int get(int x) {
  int ret = mp[x];
  if (ret == 0) {
    mp.erase(x);
    ret = INT_MAX/2;
  }
  return ret;
}

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

  string s; cin >> s;
  string t = "CODEFESTIVAL2016";

  int cnt;
  rep(i, 16) {
    if (s[i] != t[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;

const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5+10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;
bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
}


void solve() {

    ll n;cin>>n;
    set<ll> s;
    for(ll i=0;i<n;i++)
    {
        ll x;cin>>x;
        s.in(x);
    }
    if(s.size()==n)
        cout<<"YES";
    else
        cout<<"NO";


}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    fio
    int t=1;
    if(imp) cin>>t;

    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }

}


Measured memory_bytes: 13032
//Lannisters Don't Act Like Fools

#include <iostream>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

int main() {
	// your code goes here
	int n,m;
  scanf("%d%d",&n,&m);
        int a[m],i,sum=0;
        for(i=0;i<m;i++)
        {
          scanf("%d",&a[i]);
          sum+=a[i];
        }
        if(sum>n)
        printf("-1\n");
        else
        {
          printf("%d\n",n-sum);
        }
        
	return 0;
}


Measured memory_bytes: 3728
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    ll a, b;
    cin >> a >> b;
    string f;
    cin >> f;
    if (f == s)
    {
        cout << a - 1 << " " << b << endl;
    }else{
        cout << a << " " << b - 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 302;
string a,b,c;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c;
	ll x=-1,y=-1,z=-1;
	ll n=0;
	while(1){
		if(n==0){
			x++;
			if(x==a.size()){
				cout<<"A"<<endl;
				return 0;
			}
			n=a[x]-'a';
		}else if(n==1){
			y++;
			if(y==b.size()){
				cout<<"B"<<endl;
				return 0;
			}
			n=b[y]-'a';
		}else{
			z++;
			if(z==c.size()){
				cout<<"C"<<endl;
				return 0;
			}
			n=c[z]-'a';
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    print(S.count('+') - S.count('-'))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8928
while True:
    rec = list(map(int,input().split(" ")))
    if rec[0] ==0 and rec[1] ==0: break
    for i in range(rec[0]):
        for j in range(rec[1]):
            if i%2 == 0:
                if j%2 ==0:
                    print("#",end="")
                else:
                    print(".",end="")
            else:
                if j%2 ==0:
                    print(".",end="")
                else:
                    print("#",end="")
        print("")
    print("")

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main(){
  ll n;
  cin>>n;
  vector<string> s(n);

  rep(i, n) cin>>s[i];

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

  ll ans = n;
  for(ll i=1; i<n; i++){
    if(s[i] == s[i-1]) ans--;
  }
  out(ans);
}


Measured memory_bytes: 9492
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#define MAX_N   101
#define MAX_wv  101
#define MAX_W   10001
using namespace std;

int n = 4;
int W = 5;
int w[MAX_wv];//   =   {2,2,1,3};
int v[MAX_wv];//   =   {4,5,2,8};
int dp[MAX_N][MAX_W];//    =   {0};



int main(){
    scanf("%d %d",&n,&W);
    for(int i = 0; i < n; i++){
        scanf("%d %d",&v[i],&w[i]);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < W+1; j++){
            if(j < w[i]){
                dp[i+1][j]  =   dp[i][j];
            }else{
                dp[i+1][j]  =   max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
        }
    }
//    for(int i = 0; i < n+1; i++){
//        for(int j = 0; j < W+1; j++){
//            printf("%2d ",dp[i][j]);
//        }
//        printf("\n");
//    }
    printf("%d\n",dp[n][W]);
    return 0;
}

Measured memory_bytes: 7040
#include <stdio.h>
int main(){
	int a[10], i, j, tmp;

	for(i = 0; i < 10; i++){
		scanf("%d",&a[i]);
	}

	for(i = 0; i < 10; i++){
		for(j = i + 1; j < 10; j++){
			if(a[i] > a[j]){
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}

	for(i = 1; i <= 3; i++){
		printf("%d\n",a[10-i]);
	}
	return 0;
}

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

using namespace std;


template
<typename TYPE,size_t SIZE>
size_t array_length(const TYPE(&)[SIZE])
{
	return SIZE;
}

int main() {
	//入力
	//vector<int> c(9, 0);
	int c[3][3];
	//cout << c[8] << endl;
	for (int i = 0; i < array_length(c); i++) {
		for (int j = 0; j < array_length(c[i]); j++) {
			cin >> c[i][j];
		}
	}

	//処理
	for (int i = 0; i < array_length(c); i++) {
		for (int j = 0; j < array_length(c); j++) {
			for (int k = 0; k < array_length(c); k++) {
				for (int l = 0; l < array_length(c); l++) {
					if (c[i][k] + c[j][l] != c[i][l] + c[j][k]) {
						cout << "No" << endl;
						return 0;
					}
				}
			}
		}
	}
	/*
	a1 + b1 = c[0][0];
	a1 + b2 = c[0][1];
	a1 + b3 = c[0][2];

	a2 + b1 = c[1][0];
	a2 + b2 = c[1][1];
	a2 + b3 = c[1][2];

	a3 + b1 = c[2][0];
	a3 + b2 = c[2][1];
	a3 + b3 = c[2][2];

	1, 5, 9 == 2, 6, 7
	2 == 3, 4, 8
	*/

	//出力
	cout << "Yes" << endl;
	return 0;
	//cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
from sys import stdin
#sys.setrecursionlimit(10**6) 

def main():
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if 6 <= a and a <= 12:
        v = b//2
    elif a <= 5:
        v = 0
    else:
        v = b
    print(v)

if __name__ == "__main__":
    main()

Measured memory_bytes: 21444
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int MAX_NUM = 100000000;
vector<bool> ps(MAX_NUM + 1, true);

int main() {
    ps[0] = ps[1] = false;
    for (int i = 4; i <= MAX_NUM; i += 2) {
        ps[i] = false;
    }
    for (int i = 3; i <= MAX_NUM; i += 2) {
        if (!ps[i]) {
            continue;
        }
        for (int j = i + i; j <= MAX_NUM; j += i) {
            ps[j] = false;
        }
    }

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        if (ps[k]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 13332
C = [[int(x) for x in input().split()],[int(x) for x in input().split()],[int(x) for x in input().split()]]
a1max = min(C[0])
for a1 in range(a1max + 1):
  b1, b2, b3 = C[0][0] - a1, C[0][1] - a1, C[0][2] - a1
  a2 = C[1][0] - b1
  a3 = C[2][0] - b1
  if C[1][1] == a2 + b2 and C[1][2] == a2 + b3 and C[2][1] == a3 + b2 and \
    C[2][2] == a3 + b3:
      print('Yes')
      break
else:
  print('No')

Measured memory_bytes: 3064
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<i64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

struct Cummulation {
    sums: Vec<i64>
}

impl Cummulation {
    fn new(target: &Vec<i64>) -> Cummulation {
        let mut cumulation_vec: Vec<i64> = Vec::new();
        cumulation_vec.push(0);
        let mut pre = 0;
        for i in target {
            let n = i + pre;
            cumulation_vec.push(n);
            pre = n;
        }
        Cummulation {sums: cumulation_vec}
    }

    fn get(&self, left: usize, right: usize) -> i64 {
        self.sums[right + 1] - self.sums[left]
    }
}

fn convination(n: u64, m: u64) -> u64 {
    let mut ret = 1;
    if n < m {
        return 0;
    }
    for i in 0..m {
        ret *= n - i;
    }
    ret / m
}

fn main() {
    let _: u64 = input();
    let a_vec = input_vec();
    let cumulation = Cummulation::new(&a_vec);

    let mut nums_map: HashMap<i64, u64> = HashMap::new();
    for c in &cumulation.sums {
        let n = nums_map.entry(*c).or_insert(0);
        *n += 1;
    }
    let mut sum = 0;
    for v in nums_map.values() {
        sum += convination(*v, 2);
    }
    println!("{}", sum);
}


Measured memory_bytes: 18180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}


int main(){
	vector<bool> a(26,false);
	string s; cin >> s;
	for(char i: s){
		a[i-'a'] = true;
	}
	rep(i,26){
		if(a[i] == false){
			cout << (char)('a'+i) << endl;
			return 0;
		}
	}
	cout << "None\n";
}


Measured memory_bytes: 3744
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

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

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n, k;
		cin >> n >> k;
		string s;
		cin >> s;
		int score = 0;
		//初期スコアをカウントする
		rep (i, n - 1) {
			if (s[i] == s[i + 1]) score++;
		}
		//ランレングス法を用いて考察し、最適な操作をしたスコアを求める
		//1回の操作で増えるスコアは最大2であることに着目する
		int ans = min(score + 2 * k, n - 1);
		cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <limits>
#include <unordered_map>

using ll = long long;
using vi =  std::vector<int>;

template<class T>
T cc(T t)
{
	return t * (t - 1) / 2;
}


int main()
{
	int N;
	std::cin >> N;
	vi A(N);
	for (int i = 0; i < N; i++)
		std::cin >> A[i];

	vi bucket(N+1, 0);
	for (int i = 0; i < N; i++) 
		bucket[A[i]]++;

	ll sum = 0;
	for (int tama : bucket)
		sum += cc<ll>(tama);

	for (int i = 0; i < N; i++)
	{
		ll ans = sum + 1 - bucket[A[i]];
		std::cout << ans << std::endl;
	}
}



Measured memory_bytes: 4096
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

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

int partition(vector<int> &A, vector<int> &I, vector<char> &S, int p, int r)
{
	int x = A[r];
	int i = p - 1;
	for(int j = p; j < r; ++j) {
		if(A[j] <= x) {
			++i;
			swap(A[i], A[j]);
			swap(S[i], S[j]);
			swap(I[i], I[j]);
		}
	}
	swap(A[i + 1], A[r]);
	swap(S[i + 1], S[r]);
	swap(I[i + 1], I[r]);
	return i + 1;
}

void QuickSort(vector<int> &A, vector<int> &I, vector<char> &S, int p, int r)
{
	if(p < r) {
		int q = partition(A, I, S, p, r);
			QuickSort(A, I, S, p, q - 1);
			QuickSort(A, I, S, q + 1, r);
	}
}

bool isStable(vector<int> &A, vector<int> &I, int n)
{
	REP(i, n - 1) {
		if(A[i] == A[i + 1] && I[i] > I[i + 1])
			return false;
	}

	return true;
}

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

	vector<int> A(n);
	vector<char> S(n);
	vector<int> I(n);
	REP(i, n) {
		cin >> S[i] >> A[i];
		I[i] = i;
	}
	QuickSort(A, I, S, 0, n - 1);

	(isStable(A, I, n))? cout << "Stable" : cout << "Not stable";
	cout << endl;

	REP(i, n) {
		cout << S[i]  << ' ' << A[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	int N;
   	cin>>N;
   	int count[N+1];
   	for(int i=1;i<=N;i++)
   		count[i]=0;
   	for(int i=0;i<N-1;i++)
   	{
   		int temp;
   		cin>>temp;
   		count[temp]++;
   	}
   	for(int i=1;i<=N;i++)
   		cout<<count[i]<<endl;
}

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

int main() {
	int n,m;
	cin >> n;
	vector<string> blue(n);

	for(int i=0; i<n; i++)
	cin >> blue.at(i);
	
	cin >> m;
	vector<string> red(m);

	for(int i=0; i<m; i++)
	cin >> red.at(i);

int r=0, b=0;
	for(int i=0; i<n; i++){
		b = 0;
		for(int j=0; j<n; j++){
			if(blue.at(i) == blue.at(j)){
				b++;
			}
		}
		for(int j=0; j<m; j++){
			if(blue.at(i) == red.at(j)){
				b--;
			}
		}
		if(b>r){
			r = b;
		}
	}

	cout << r << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    ll X;
    cin >> X;
    
    ll i = 100, ans = 0;
    while(i < X){
        i *= 1.01;
        ans++;
    }

    cout << ans << endl;
}

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

int main()
{
    int h,w;
    while(cin>>h>>w&&h||w){
        for(int i=0;i<h;i++){
            if(i==0|i==h-1){
                cout<<string(w,'#');
                cout<<endl;
            }else{
                for(int j=0;j<w;j++){
                    if(j==0|j==w-1){
                        cout<<'#';
                    }else{
                        cout<<'.';
                    }
                }
                cout<<endl;
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
#define int ll

int n, m, a[5005], b[5005][202], best[5005], hi[5005][202][16];
ll psa[5005];
ll ans;
int query(int L, int R, int Y){
	if (L==R) return b[L][Y];
	int k=0;
	while(L+(1<<k+1)<=R) ++k;
	return max(hi[L][Y][k], hi[R-(1<<k)+1][Y][k]);
}
void solve(int L, int R, int L2, int R2){
	//return;
	if (L>R) return;
	int M = (L+R)/2, p;
	ll c, hi = -(1LL<<60);
	drain(best);
	int start = max(L2, M);
	fox(l2, m){
		best[l2] = query(M, start, l2);
	}
	c = -(psa[start]-psa[M]);
	//cout << start << " " << M << " " << c << endl;
	fox(l, m){
		//cout << best[l] << ' ';
		c += best[l];
	}// cout << endl;
	for (int l = start; l<=R2; ++l){
		fox(l2, m){
			if (b[l][l2]>best[l2]){
				c += b[l][l2]-best[l2];
				best[l2] = b[l][l2];
			}
		}
		if (c>hi){
			hi=c;
			p=l;
		}
		c-=a[l];
		
	}
	//cout << M << ' ' << hi << endl;
	ans=max(ans, hi);
	if (L!=R){
		solve(L, M-1, L2, p);
		solve(M+1, R, p, R2);
	}
	
}
int32_t main() {
	scanf("%i%i", &n, &m);
	fox(l, n-1){
		scanf("%i", a+l);
		psa[l+1]=psa[l]+a[l];
	}
	fox(l, n){
		fox(l2, m){
			scanf("%i", &b[l][l2]);
		}
	}
	foxr(l, n){
		fox(l2, m){
			hi[l][l2][0]=b[l][l2];
			fox1 (k, 14){
				if (l+(1<<k)>=n) break;
				hi[l][l2][k]=max(hi[l][l2][k-1], hi[l+(1<<k-1)][l2][k-1]);
			}
		}
	}
	solve(0, n-1, 0, n-1);
	cout << ans;
	return 0;
}

Measured memory_bytes: 134656
#include <stdio.h>
 
int main(void){
	
	char a[10],b[10],c[10];
	int i,j;
	
	scanf("%s %s %s",&a,&b,&c);
	if(a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0]) 
	{
	printf("YES\n");
	} else {
	printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
package main

// Solution for https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_b

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var a, b, c, k int
	con.Scan(&a, &b, &c, &k)
	i := 0
	for a >= b {
		b = b + b
		i++
	}
	for b >= c {
		c = c + c
		i++
	}
	if i <= k {
		con.Println("Yes")
	} else {
		con.Println("No")
	}

	return nil
}


Measured memory_bytes: 1844
N = int(input())
S = [input() for i in range(N)]

# 'AB'の数を数える
cnt_ab = sum([s.count('AB') for s in S])

# L: 先頭が'B'、終わりが'A'の数を数える
cnt_b_a = sum([(s[0] == 'B') and (s[-1] == 'A') for s in S])

# M: 先頭が'B'、終わりが'A'じゃないの数を数える
cnt_b_na = sum([(s[0] == 'B') and (s[-1] != 'A') for s in S])

# N : 先頭が'B'じゃなく、終わりが'A'の数を数える
cnt_nb_a = sum([(s[0] != 'B') and (s[-1] == 'A') for s in S])

count = cnt_ab
if (cnt_b_a == 0): # MとNの数の小さい方の分だけ追加できる
    count += min(cnt_b_na, cnt_nb_a)
elif (cnt_b_na + cnt_nb_a == 0): # Lの個数 - 1個だけ追加できる
    count += (cnt_b_a - 1)
else:
    count += (cnt_b_a + min(cnt_b_na, cnt_nb_a))
print(count)

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

typedef long long int ll;
typedef vector<int> vi;            
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int>     pii;
typedef vector<bool> vb;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#ifdef LOCAL
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
    ll x, k, d; cin>>x>>k>>d;
    x = abs(x);
    ll moves1 = x/d;
    ll moves2 = x/d+1;
    if(k<=moves1)
        cout<<x-k*d<<endl;
    else if((k-moves1)%2==0)
        cout<<x-d*moves1<<endl;
    else
        cout<<d*moves2-x<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen(".inp.txt", "r", stdin);
        freopen(".out.txt", "w", stdout);
        freopen(".err.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 3660
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        int p = 0;
        int size = s.length();
        while (p <= size) {
            String s2 = s.substring(p, size) + s.substring(0,p);
            p++;
            if (s2.equals(t)) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

int main() {
  int a,b; cin>>a>>b;
  string A=to_string(a), B=to_string(b);
  string AA=A, BB=B;
  for(int i=1; i<b; i++){
    AA+=A;
  }
  for(int i=1; i<a; i++){
    BB+=B;
  }
  if(AA>BB){
    AA=BB;
  }
  cout<<AA<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int k,c,cnt=0;
	for(int i=1;i<=n;i++){
		k=i;
		c=0;
		while(k!=0){
			k=(k/10);
			c++;
		}
		if(c%2==1)cnt++;
	}
	cout<<cnt<<endl;

			
	return 0;
}

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

int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		sum += i;
	}
	cout<<sum<<endl;

return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	string a, b, c; cin >> a >> b >> c;
	cout << (a[a.size()-1] == b[0] && b[b.size()-1] == c[0] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int cont[105];
int x[30],y[30],c[105];

int main(){
  int N;
  string s;
  cin>>N>>s;
  memset(cont,0,sizeof(cont));

  for(int t=0;t<N;t++){
    c[t]=s[t]-'a';       //a~z->0~25
  }
  for(int t=0;t<N;t++){
    y[c[t]]++;
  }

   for(int t=0;t<N;t++){
     x[c[t]]++;y[c[t]]--;
     bool used[30]={};
     for(int i=0;i<=t;i++){
       if(x[c[i]]>=1&&y[c[i]]>=1&&!used[c[i]]){
         cont[t]++;
         used[c[i]]=true;
       }
     }
   }

  int max=0;
  for(int t=0;t<N;t++){
    if(max<cont[t])max=cont[t];
  }

  cout<<max<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()


void solution(){
	int n; cin >> n;
	vector<long double> p(n); for(auto &x : p) cin >> x;
	// dp[i][j] -- prob of exactly j heads in i coins
	// dp[i][j] = dp[i-1][j]*(1-p) + dp[i-1][j-1]*p
	vector<vector<long double>> dp(n+1,vector<long double>(n+1,0));
	dp[0][0] = 1.0;
	// dp[i][0] -- 0 heads in i coins
	// dp[0][i] -- i heads in 0 throws
	// basically, j <= i always
	for(int i = 1; i <= n; i++){
		dp[i][0] = (1.0-p[i-1]) * dp[i-1][0];
	}
	long double ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i; j++){
			dp[i][j] = dp[i-1][j] * (1-p[i-1]);
			dp[i][j] += dp[i-1][j-1] * p[i-1];
			if(i == n && j > n/2) ans += dp[i][j];
		}
	}
	printf("%0.18Lf\n",ans);



}	


int main(){ 
	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 144200
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long 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()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

char a[105][105];
int main(){FIN

    ll h,w; cin>>h>>w;
    set<ll> hs, ws;
    REP(i,h){
        REP(j,w){
            cin>>a[i][j];
            if (a[i][j]=='#') {hs.insert(i); ws.insert(j);}
        }
    }
    ll ct=0;
    REP(i,h){
        if (!hs.count(i)) continue;
        REP(j,w){
            if (hs.count(i) && ws.count(j)) {
                cout<<a[i][j];
                ct++;
            }
            if ((ct) % ws.size()==0) cout<<endl;
        }
    }
    return 0;

}

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

const int M=1e9+7;

long long mod(long long x){
    return ((x%M + M)%M);
}
long long add(long long a, long long b){
    return mod(mod(a)+mod(b));
}
long long mul(long long a, long long b){
    return mod(mod(a)*mod(b));
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n; cin>>n;
	ll arr[n], arr1[n];
	for(ll i=0; i<n; i++){
		cin>>arr[i];
		arr1[i]=arr[i];
	}
	
	for(ll i=n-2; i>=0; i--){
		arr[i]+=arr[i+1];
	}
	
	ll ans = 0;
	for(int i=n-2;i>=0; i--){
        ans=add(ans,mul(arr1[i],arr[i+1]));
    }
	
	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 6776
n,m=map(int,input().split())

data = []
for _ in range(m):
    lista = [int(i) for i in input().split()]
    data.append(lista)
    
listp = [int(i) for i in input().split()]

testnum = 2**n
ans = 0
for i in range(testnum):
    checklist = [0]*n
    tmpi = i
    for j in range(n):
        if tmpi>=2**(n-1-j):
            checklist[j]=1
            tmpi -= 2**(n-1-j)
    #print("clist",checklist)
    succ = True
    for j in range(m):
        sumnum = 0
        for jj in range(1,len(data[j])):
            sumnum += checklist[data[j][jj]-1]
        if sumnum%2 != listp[j]:
            succ = False
            break
    if succ==True:
        ans +=1
        
print(ans)

Measured memory_bytes: 42608
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;
const double BTC = 380000.0;

double btoj(double x) {
  return x*BTC;
} 

int main() {
  int n;
  cin >> n;
  double sum = 0;

  rep(i, n) {
    double x;
    string s;
    cin >> x >> s;

    if(s == "BTC") {
      x = btoj(x);
    }
    sum += x; 
  }
  cout << sum << endl;
  return 0;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	int h, w, n; scanf("%d%d%d", &h, &w, &n);
	int x = max(h, w);
	printf("%d\n", (n+x-1)/x);

	return 0;
}

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


int main()
{
    int n, d;
    scanf("%d%d", &n, &d);
    int x[n][d] = {};
    rep(i,n){
        rep(j,d){
            cin >> x[i][j];
        }
    }

    int cnt = 0;
    rep(i,n){
        for(int j = i+1; j < n; j++){
            int norm = 0;
            for(int k = 0; k < d; k++){
                int diff = abs(x[i][k] - x[j][k]);
                norm += diff*diff;
            }
            if(sqrt(norm) -floor(sqrt(norm))==0) cnt++;
        }
    }
    printf("%d", cnt);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {
	LL n, i, j, l;
	cin >> n >> l;
	vector<string> s(n);
	for (i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	for (i = 0; i < n; i++) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main(){
int A , B, C, K;
cin >> A >> B >> C >> K;
int ans;
if(K <= A){
    ans = K;
}else if(K <= A + B){
    ans = A;
}else{
    ans = A - (K - A - B);
}

cout << ans << endl;

}

Measured memory_bytes: 3672
abc = sorted(list(map(int, input().split())))

first = abc[2] - abc[0]
second = abc[2] - abc[1]

cnt = 0

if first % 2 == 0 and second % 2 == 0:
    cnt += first//2 + second//2

elif (first % 2 == 1 and second % 2 == 0) or (first % 2 == 0 and second % 2 == 1):
    cnt += first//2 + second//2 + 2

else:
    cnt += first//2 + second//2 + 1

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 1;
    while(ans <= n) {
        ans *= 2;
        if(ans > n) {
            ans /= 2;
            break;
        }
    };
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
S=input()
ans=0
for i in range(1,len(S)):
  S1=S[:i]
  S2=S[i:]
  cnt = set()
  for s1 in S1:
    if s1 in S2:
      cnt.add(s1)
  ans = max(ans,len(cnt))
print(ans)

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

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define sz(x) int((x).size())
#define fi first
#define se second

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))
#define mp(a,b) make_pair(a,b)

// useful bits
#define IN(i,l,r) (i >= l && i <= r);
#define relax(a,b) a = max(a,b);
#define relaxi(a,b) a = min(a,b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7)) 
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

// for rand
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// use uniform_int_distribution<int>(0, i)(rng)

int a,b,c;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
//	freopen("output.txt", "w" , stdout);
	/* freopen("in.txt" , "r" , stdin); */
	clock_t start = clock();
	#endif
	cin >> a >> b>> c;
	int t = b;
	if( a + b >= c -1 )
		t += c;
	else
		t += a+b+1;
	cout << t<< endl;
	#ifndef ONLINE_JUDGE
	/* cout << setprecision(12) << ld(clock()-start) / CLOCKS_PER_SEC << endl; */
	#endif
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String str = sc.nextLine().replace(" ", "").replace("Y", "");
    if(str.length() == n){
      System.out.println("Three");
    }else{
      System.out.println("Four");
    }
  }
}

Measured memory_bytes: 22612
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int x, y;
int A, B, C;
int a[N], b[N], c[N];

int f(int m){
	int cur = a[x] + b[y];
	cur += c[m];
	int ans = 0;
	for(int i = 0; i <= m; i++){
		int cx = x-i;
		int cy = y-(m-i);
		if(cx >= 0 && cx <= A && cy >= 0 && cy <= B)
			ans = max(ans, cur - (a[x] - a[cx] + b[y] - b[cy]));
	}
	return ans;
}
 
signed main() {
	IOS;
	cin >> x >> y >> A >> B >> C;
	for(int i = 1; i <= A; i++)
		cin >> a[i];
	for(int i = 1; i <= B; i++)
		cin >> b[i];
	for(int i = 1; i <= C; i++)
		cin >> c[i];
	sort(a+1, a+A+1, greater<int>());
	sort(b+1, b+B+1, greater<int>());
	sort(c+1, c+C+1, greater<int>());
	for(int i = 1; i <= A; i++)
		a[i] += a[i-1];
	for(int i = 1; i <= B; i++)
		b[i] += b[i-1];
	for(int i = 1; i <= C; i++)
		c[i] += c[i-1];
	int l = 0, h = min(x+y, C);
	while(l+1 < h){
		int m = (l+h) >> 1;
		if(f(m) > f(m+1))
			h = m;
		else
			l = m;
	}
	cout << max(f(l), f(h));
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,a,b,c,d,e;
  cin >> n>> a >> b >> c >>d >>e;

  ll f=a;
  f=min(f,b);
  f=min(f,c);
  f=min(f,d);
  f=min(f,e);

  ll m;
  if(n%f==0)m=n/f;
  else m=n/f+1;
  cout << 4 + m << endl;


}

Measured memory_bytes: 3584
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

bool calc(string s) {
    for (int i = 0; i < s.length - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            return true;
        }
    }
    return false;
}

void main() {
    auto s = readln.chomp;
    writeln(calc(s) ? "Yes" : "No");
}


Measured memory_bytes: 256