akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
#define maxx 110000
typedef long long ll;
int a[100010];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    int ans =1;
    int high = a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]>=high)
        {
            ans++;
            high=a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const ulong MOD9 = 1000000007;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        if (n < 2)
        {
            Console.WriteLine(0);
            return;
        }

        var white = new int[n];
        var black = new int[n];

        white[0] = s[0] == '.' ? 0 : 1;
        black[n - 1] = s[n - 1] == '.' ? 1 : 0;

        for (int i = 1; i < white.Length; ++i)
        {
            var p = white[i - 1];
            if (s[i] != '.')
                ++p;
            white[i] = p;
        }
        for (int i = n - 2; i >= 0; --i)
        {
            var p = black[i + 1];
            if (s[i] == '.')
                ++p;
            black[i] = p;
        }

        var result = Math.Min(black[0], white[white.Length - 1]);
        for (int i = 1; i < black.Length; ++i)
        {
            var r = white[i - 1] + black[i];
            if (result > r)
                result = r;
        }

        Console.WriteLine(result);
    }
}


Measured memory_bytes: 15328
#include <iostream>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  map< string, vector<int> > dict;
  while( 1 ) {
    string word;
    int page;
    if( !( cin >> word ) ){ break; }
    cin >> page;
    if( dict.find( word ) == dict.end() ) {
      pair< string, vector<int> > p;
      p.first = word;
      p.second.push_back( page );
      dict.insert( p );
    } else {
      dict[ word ].push_back( page );
    }
  }

  for(
      map< string, vector<int> >::iterator it = dict.begin();
      it != dict.end();
      it++
  ) {
    cout << it->first << endl;
    sort( it->second.begin(), it->second.end() );
    int len = it->second.size();
    for( int i = 0; i < len; i++ ) {
      cout << it->second[ i ] << flush;
      if( i != len - 1 ) { 
        cout << " " << flush;
      }
    }
    cout << endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll H, W, N;
  cin >> H >> W >> N;

  const vector<ll> dy = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
  const vector<ll> dx = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
  map<pair<ll, ll>, ll> mp;
  for (ll i = 0; i < N; i++)
  {
    ll a, b;
    cin >> a >> b;
    for (ll j = 0; j < dy.size(); j++)
    {
      ll ny = a + dy.at(j);
      ll nx = b + dx.at(j);

      if (2 <= ny && ny <= H - 1 && 2 <= nx && nx <= W - 1)
        mp[make_pair(ny, nx)]++;
    }
  }

  vector<ll> ans(10, 0);
  for (auto m : mp)
  {
    ans.at(m.second)++;
  }
  ans.at(0) = (H - 2) * (W - 2) - accumulate(ans.begin(), ans.end(), 0LL);

  for (ll i = 0; i < 10; i++)
  {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 56448
#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define fr first
#define se second
#define fi(i,s,e,inc) for(auto i=s; i<e; i+=inc)
#define fie(i,s,e,inc) for(auto i=s; i<=e; i+=inc)
#define fd(i,s,e,dec) for(auto i=s; i>e; i-=dec)
#define fde(i,s,e,dec) for(auto i=s; i>=e; i-=dec)
#define umap tr1::unordered_map
#define nl cout<<"\n";
#define vt vector
#define pb push_back
#define pr(x) cout<<x;
#define ps(x) cout<<x<<" ";
#define sp cout<<" ";
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define rev reverse
#define tc ll t; cin>>t; while(t--)
#define pq priority_queue
ll n,w;
ll wt[101],val[101];
ll dp[101][100001];
ll solve(ll n,ll w){
    if(n==0 or w==0) return 0;

    if(dp[n][w]!=-1) return dp[n][w];

    if(wt[n-1]>w)
        return solve(n-1,w);

    else
        return dp[n][w] = max(val[n-1]+solve(n-1,w-wt[n-1]),solve(n-1,w));
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>w;
    fi(i,0,n,1) cin>>wt[i]>>val[i];
    memset(dp,-1,sizeof(dp));
    pr(solve(n,w)) nl
    return 0;
}


Measured memory_bytes: 79232
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n, r, l,ans=0;
	cin >> n;
	REP(i, n) {
		cin >> l >> r;
		ans += ((r - l) + 1);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	private void execute() {
		Scanner sc = new Scanner(System.in);
		final int[] I_753 = { 3, 5, 7 };
		final int N = sc.nextInt();
		int cnt = 0;
		if (N < 100) {
			System.out.println(cnt);
			return;
		}

		ArrayList<Integer> list = new ArrayList<>();
		int keta = Integer.toString(N).length();
		list.add(3);
		list.add(5);
		list.add(7);
		int time = 10;
		for (int i = 1; i < keta; i++) {
			ArrayList<Integer> l = new ArrayList<>();
			for (int n : list) {
				for (int e : I_753) {
					l.add(n + e * time);
				}
			}
			list.addAll(l);
			time *= 10;
		}
		for (int n:list) {
			if (n<=N && is753Number(n)) {
				cnt ++;
			}
		}
		System.out.println(cnt);
	}

	private boolean is753Number(int x) {
		boolean three = false;
		boolean five = false;
		boolean seven = false;
		while (x > 0) {
			int mod = x % 10;
			switch (mod) {
			case 3:
				three = true;
				break;
			case 5:
				five = true;
				break;
			case 7:
				seven = true;
				break;
			default:
				return false;
			}
			x /= 10;
		}
		return three && five && seven;
	}
}


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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m, t;
int a[N];
int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> t;
        a[t] = -1;
    }
    a[0] = 1;
    if (a[1] != -1) a[1] = 1;
    for (int i = 2; i <= n; ++i) {
        if (a[i] == -1) continue;
        if (a[i - 1] != -1) {
            a[i] = a[i - 1];
        }
        if (a[i - 2] != -1) {
            a[i] = (a[i] + a[i - 2]) % mod;
        }
    }
    cout << a[n] << endl;
    return 0;
}


Measured memory_bytes: 4028
use proconio::input;
#[allow(unused_mut)]
fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize
    };
    let res = if !(a == b && b == c) && (a == b || b == c || c == a) {
        "Yes"
    } else {
        "No"
    };
    println!("{}", res);
}


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

int main() {
    string S;
    cin >> S;
    int N = S.length();
    bool judge = true;
    if (S[0] != 'A') judge = false;
    int C = 0, big = 0;
    for (int i = 2; i < N-1; i++) {
        if (S[i] == 'C') C++;
    }
    for (int i = 1; i < N; i++) {
        if ('A' <= S[i] && S[i] <= 'Z') big++;
    }
    if (C != big || C != 1) judge = false;
    
    cout << ((judge) ? "AC" : "WA") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int S;
  cin >> S;
  int h, m, s;
  h = S / 3600;
  S -= h * 3600;
  m = S / 60;
  s = S - m * 60;
  cout << h << ':' << m << ':' << s << endl;
}


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

int main(){
    int k , s;
    cin >> k >> s;
    int ans = 0;
    for(int i = 0; i <= k; ++i){
        for(int j = 0; j <= k; ++j){
            int z = s - i - j;
            if(z <= k && z >= 0) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>
#include <queue>
#include <numeric>
//#include <bits/stdc++.h>

using namespace std;
const int INF = 1 << 30;

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    char x[n][m];
    for(int i = 0 ; i < n ;++i )
        for(int j = 0 ; j < m ;++j)
                cin>>x[i][j];
    int h[n];
    fill(h,h+n,1);
    int l[m];
    fill(l,l+m,1);
    for(int i = 0; i < n ;++i)
    {
        for(int j = 0 ; j < m ;++j)
            if(x[i][j]=='#')
                h[i]=0;
    }
    for(int j = 0 ; j < m ;++j)
        for (int i = 0; i < n; ++i)
        {
            if(x[i][j]=='#')
                l[j]=0;
        }
    for(int i = 0 ; i < n ;++i)
    {
        int flag=0;
        for(int j = 0 ;j<m;++j)
        {
            if(!h[i]&&!l[j])
            {    
                flag=1;
                cout<<x[i][j];
            }
        }
        if(flag)
            cout<<endl;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<math.h>
#include<set>
#include<map>
#include<string.h>
#include<stack>
#define n 200000
#define loop(a, b) for(int i = a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
bool visit[n + 50];
int arr[n + 50], a, b, c, d, e;
string str1, str2;
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
	V[a].push_back(temp);
}


//////////////////////////////////////////


void solve()
{
	cin >> a;
	for(int i=2; ; i++)
	{
		int temp = sqrt(i) + 1;
		int yes = true;
		for(int j=2; j<temp; j++)
		{
			if(i % j == 0)
			{
				yes = false;
				break;
			}
		}
		if(i % 5 != 1) yes = false;
		if(!yes) continue;
		cout << i << " ";
		a --;
		if(!a) break;
	}
}
int main()
{
	int times = 1;
//	cin << times;
	loop(1, times)
	{
		solve();
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define ll long long
using namespace std;
int main(){
  int n;
  
cin>>n;
  vector<ll>a(n);
  vector<ll>sum(n);
  for(int i=0;i<n;i++){
  cin>>a[i];
    
  sum[i]=(i==0?a[i]:sum[i-1]+a[i]);
  }
   ll max=1111111111111;
  for(int i=0;i<n;i++){
  max=min(max,abs(sum[i]-(sum[n-1]-sum[i])));
  }
  cout<<max<<endl;
return 0;  
}



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


def solve(X: int):
    for x in range(X, 200003):
        if is_prime(x):
            print(x)
            break
    return


def is_prime(n: int):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    for p in range(3, math.floor(math.sqrt(n) + 1), 2):
        if n % p == 0:
            return False
    return True


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)


if __name__ == "__main__":
    main()


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

int main(){
  int n;
  int k,c;
  int sum;

  while(1){
    cin >> k;
    if(!k)break;

    sum = 0;
    n = k*(k-1)/2;
    for(int i=0;i<n;i++){
      cin >> c;
      sum += c;
    }

    cout << sum/(k-1) << endl;
  }
  return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string n;
  cin >> n;
  string m = n;
  reverse(all(m));
  cout << (n == m ? "Yes" : "No") << endl;

  return 0;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> c(h);
    rep(i,h){
        cin >> c[i];
        cout << c[i] << endl;
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n  = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] d = new int[n];
		
		double d1 = 0;
		double d2 = 0;
		double d3 = 0;
		double di = 0;
		
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++) {
			y[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++) {
			d[i] = Math.abs(x[i]-y[i]);
			d1 += d[i];
			d2 += d[i]*d[i];
			d3 += d[i]*d[i]*d[i];
			di = Math.max(di, d[i]);
		}
		
		System.out.println(String.format("%f", d1));
		System.out.println(String.format("%f", Math.pow(d2, 0.5)));
		System.out.println(String.format("%f", Math.pow(d3, 1.0/3.0)));
		System.out.println(String.format("%f", di));
	}
}


Measured memory_bytes: 26824
n = int(input())
a = list(map(int,input().split()))
x = list(set(a))
x.sort()
if len(x) >= 4:
  print("No")
  exit()
if len(x) == 3:
  if x[0]^x[1] == x[2] and 3*a.count(x[0]) == 3*a.count(x[1]) == 3*a.count(x[2]) == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 2:
  if x[0] == 0 and (2*a.count(x[0]) == 2*a.count(x[1]) == n or 6*a.count(x[0]) == 3*a.count(x[1]) == 2*n):
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 1:
  if x[0] == 0:
    print("Yes")
  else:
    print("No")

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    int ans = 1;
    for (int i = 2; i * i <= x; i++)
    {
        int res = i;
        while (res * i <= x)
        {
            res *= i;
        }
        ans = max(ans, res);
    }
    cout << ans << '\n';
    return (0);
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,k;
str s,ans;
int main(){
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i==(k-1)){
            char c;
            c = s[i];
            int x;
            x = int(c);
            if(x>=65 && x<=90){x+=32;}

            ans += char(x);
        }
        else{
            ans += s[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)

  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1

def Same(x, y, par):
  return Find(x, par) == Find(y, par)

def Size(x, par):
  return -par[Find(x, par)]

n, m, k = map(int, input().split())

par = [-1]* n
rank = [0]*n

cnt1 = [0]*n
cnt2 = [0]*n
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    Unite(a, b, par, rank)
    cnt1[a] += 1
    cnt1[b] += 1
for j in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    if Same(c, d, par):
        cnt2[c] += 1
        cnt2[d] += 1

#print(par)
#print(cnt1)
#print(cnt2)
anss = [0]*n
for i in range(n):
    ans = Size(i, par) -1 - cnt1[i] - cnt2[i]
    #print(max(ans, 0))
    anss[i] = max(ans, 0)
print(*anss)


Measured memory_bytes: 84312
from collections import defaultdict


def factorize(N):
    P = 2
    PRIME = defaultdict(int)
    while P ** 2 <= N:
        if N % P == 0:
            N //= P
            PRIME[P] += 1
        else:
            P += 1
    if N > 1:
        PRIME[N] += 1
    return PRIME


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

prime = factorize(p)
ans = 1
for j in prime:
    if prime[j] >= n:
        ans *= j ** (prime[j] // n)
print(ans)


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

if m % 2 ==0:
    for i in range(m//2):
        print(1+i, m-i)
        print(m+1+i, 2*m+1-i)
else:
    for i in range((m//2)+1):
        print(m+1+i, 2*m+1-i)
    for i in range(m//2):
        print(1+i, m-i)

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

const int N = 1e5 + 105;
int steps;
ll dp[N];
ll h[N];
int n;


ll solve(int idx) {
    if (idx >= n)
        return 1e9;
    if (idx == n - 1)
        return 0;
    if (dp[idx] != -1)
        return dp[idx];
    ll res = 1e9;
    for (int i = 1; i <= steps; i++)
        res = min(res, solve(idx + i) + abs(h[idx] - h[idx + i]));
    return dp[idx] = res;
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> steps;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0);
    return 0;
}


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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

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

    vll v1(n),v2(m);
    forn(i,n){
        cin>>v1[i];
        if(i)v1[i]+=v1[i-1];
    } 
    forn(i,m){
        cin>>v2[i];
        if(i)v2[i]+=v2[i-1];
    }

    ll max1=0;
    forn(i,n){ 
        ll temp=k-v1[i];
        if(temp<0)break;
        auto it=upper_bound(all(v2),temp);
        ll ans;
        if(it==v2.end()){
            ans=m;
        }else{
            ans=it-v2.begin();
        }

        ans+=(i+1);
        max1=max(max1,ans);
    }

    ll ans3;
    auto it1=upper_bound(all(v2),k);
    if(it1==v2.end()){
        ans3=m;
    }else{
        ans3=it1-v2.begin();
    }

    max1=max(max1,ans3);

    cout<<max1<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 6360
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a>b){
            System.out.println("a > b");
        }else if(a<b){
            System.out.println("a < b");
        }else if(a==b){
            System.out.println("a == b");
        }
        sc.close();
    }
    
}


Measured memory_bytes: 26204
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int x = sc.nextInt();
        int y = sc.nextInt();
        int sum = 0;
        if (x >= y) {
            sum += x;
            x--;
        } else {
            sum += y;
            y--;
        }
        if (x >= y) {
            sum += x;
            x--;
        } else {
            sum += y;
            y--;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	

	int x = 10*a[1] + a[2];

	if (x % 4== 0)
	{
		cout << "YES" << endl;
	}else
	{
		cout << "NO" << endl;

	}

	return 0;
}

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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  char c;
  cin >> c;
  cout << (isupper(c) ? 'A' : 'a');
}

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

  // int t;
  // cin >> t;
  // while (t--) {
    solve();
  // }

  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct rangefreq{
	int n;
	vector<vector<int> >dat;
	rangefreq(const vector<int>&v={})
	{
		n=1;
		while(n<v.size())n<<=1;
		dat.assign(2*n-1,{});
		for(int i=0;i<v.size();i++)dat[i+n-1].push_back(v[i]);
		for(int i=n-2;i>=0;i--)
		{
			dat[i].resize(dat[i*2+1].size()+dat[i*2+2].size());
			merge(dat[i*2+1].begin(),dat[i*2+1].end(),
				dat[i*2+2].begin(),dat[i*2+2].end(),
				dat[i].begin()
			);
		}
	}
	int query(int a,int b,int x,int k=0,int l=0,int r=-1)//[a,b) count(*<x)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return 0;
		else if(a<=l&&r<=b)return lower_bound(dat[k].begin(),dat[k].end(),x)-dat[k].begin();
		else return query(a,b,x,k*2+1,l,(l+r)/2)+query(a,b,x,k*2+2,(l+r)/2,r);
	}
};
int n,m;
main()
{
	cin>>n>>m;
	vector<string>L,R;
	for(int i=0;i<n;i++)
	{
		string t;cin>>t;
		L.push_back(t);
		reverse(t.begin(),t.end());
		R.push_back(t);
	}
	sort(L.begin(),L.end());
	sort(R.begin(),R.end());
	vector<int>id;
	for(int i=0;i<n;i++)
	{
		string t=L[i];
		reverse(t.begin(),t.end());
		id.push_back(lower_bound(R.begin(),R.end(),t)-R.begin());
	}
	rangefreq P(id);
	for(int i=0;i<m;i++)
	{
		string s,t;cin>>s>>t;reverse(t.begin(),t.end());
		int xl,xr,yl,yr;
		xl=lower_bound(L.begin(),L.end(),s)-L.begin();
		xr=upper_bound(L.begin(),L.end(),s+'~')-L.begin();
		yl=lower_bound(R.begin(),R.end(),t)-R.begin();
		yr=upper_bound(R.begin(),R.end(),t+'~')-R.begin();
		cout<<P.query(xl,xr,yr)-P.query(xl,xr,yl)<<endl;
	}
}



Measured memory_bytes: 36828
#include <iostream>
#include <cstdio>
using namespace std;
 
int p[110], q[110], cnt;
long long N;
     
void solve(long long n){
    if(n<1)	return;
   	if(!(n&1)){
   		q[++q[0]]=cnt++;
   		solve(n-1);
   	}else{
   		p[++p[0]]=cnt++;
   		solve(n>>1);
 	}
}
    
int main(){
  	scanf("%lld", &N);
  	solve(N);
  	printf("%d\n", cnt+100);
  	for(int i=1; i<=q[0]; i++)	printf("%d ", cnt-q[i]);
  	for(int i=p[0]; i; i--)		printf("%d ", cnt-p[i]);
   	for(int i=1; i<=100; i++)	printf("%d ", i);
 	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[105],cnt,mn=1e9;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=-100;i<=100;i++)
	{
		cnt=0;
		for(int j=1;j<=n;j++)
		{
			cnt+=(a[j]-i)*(a[j]-i);
		}
		mn=min(mn,cnt);
	}
	printf("%d\n",mn);
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll n,a,b,c;
vector<char> ans(0);
ll cu=0;
vstr s(100005);
bool ch(string ss){
  if(ss=="AB"){
    if(a==0&&b==0){
      return false;
    }
    if(a==b&&cu!=n-1&&s[cu+1]!="AB"){
      if(s[cu+1]=="AC"){
        b--;a++;
      ans.pb('A');
      }
      else{
        b++;a--;
      ans.pb('B');
      }
    }
    else if(a<=b){
      b--;a++;
      ans.pb('A');
    }
    else{
      b++;a--;
      ans.pb('B');
    }
  }
  else if(ss=="AC"){
    if(a==0&&c==0){
      return false;
    }
    if(a==c&&cu!=n-1&&s[cu+1]!="AC"){
      if(s[cu+1]=="AB"){
        c--;a++;
      ans.pb('A');
      }
      else{
        c++;a--;
      ans.pb('C');
      }
    }
    else if(a<=c){
      c--;a++;
      ans.pb('A');
    }
    else{
      c++;a--;
      ans.pb('C');
    }
  }
  else{
      if(c==0&&b==0){
        return false;
      }
      if(c==b&&cu!=n-1&&s[cu+1]!="BC"){
        if(s[cu+1]=="AB"){
          b++;c--;
       ans.pb('B');
        }
        else{
          b--;c++;
        ans.pb('C');
        }
      }
      else if(c<=b){
        b--;c++;
        ans.pb('C');
      }
      else{
        b++;c--;
       ans.pb('B');
      }
    }
  return true;
}
int main(){
  cin>>n>>a>>b>>c;
  rep(i,n) cin>>s[i];
  rep(i,n){
    if(!ch(s[i])){
      COUT("No");
      return 0;
    }
    cu++;
  }
  COUT("Yes");
  rep(i,sz(ans))COUT(ans[i]);
}


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

typedef pair<int,int> P;
char data[55][55] = {};
int done[55][55];
int R,C,sy=1,sx=1,gy,gx,ans=0,kuro=0;

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


void bfs(){
  queue<P> que;

  for(int i=1; i<=R; i++){ for(int j=1; j<=C; j++){ done[i][j]=99999; } }
  que.push(P(sy,sx));
  done[sy][sx] = 0;								//start set
  
  while(que.size()){
    P p = que.front(); que.pop();
    if (p.first == gy && p.second == gx) { break; }					  	// goal?   
    for(int i=0; i<4; i++){
      int new_y=p.first+dy[i], new_x=p.second+dx[i];
      if (new_y < 0 || R < new_y || new_x < 0 || C < new_x) { continue; }	// out of area??
      if (data[new_y][new_x] == '#') { continue; }					// wall?
      if (done[new_y][new_x]!=99999){continue;}		//seen?
      que.push(P(new_y,new_x));  
      done[new_y][new_x] = done[p.first][p.second]+1;
  	}
  }
}

int main() {
  cin >> R >> C;
  for(int i=1; i<=R; i++){ for(int j=1; j<=C; j++){ cin >> data[i][j]; 
                                                   if(data[i][j] == '#'){kuro++;}
                                                  } }
  gy = R; gx = C;
  bfs();
  if(done[gy][gx]!=99999){
    cout << R*C - kuro - done[gy][gx] - 1 << endl; 
  } else {
    cout << "-1" << endl; 
  }
  return 0;
}  


Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int check(const vector<tuple<int, int, int> >& data, int Cx, int Cy){
    int H = 0;
    {
        int h,x,y;
        tie(h,x,y) = data[0];
        H = h + abs(x-Cx) + abs(y-Cy);
    }
    for(int i=1;i<data.size();++i){
        int h,x,y;
        tie(h,x,y) = data[i];
        int temp = h + abs(x-Cx) + abs(y-Cy);
        if(h == 0){
            if(H > temp){
                return 0;
            }
        }
        else{
            if(H != temp){
                return 0;
            }
        }
    }

    return H;
}

int main(void){
    int N; cin >> N;
    vector<tuple<int, int, int> > data;
    for(int i=0;i<N;++i){
        int x,y,h; cin >> x >> y >> h;
        data.emplace_back(h,x,y);
    }
    sort(data.begin(), data.end(), greater<tuple<int, int, int> >());
    for(int cx=0;cx<=100;++cx){
        for(int cy=0;cy<=100;++cy){
            int H = check(data, cx, cy);
            if(H != 0){
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
}

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

const int mxN = 3010, mod = 1e9 + 7;
int N;
string s;
ll dp[mxN][mxN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> s;
	dp[1][1] = 1;
	for (int i = 2; i <= N; i++) {
		ll pref[i];
		pref[0] = dp[i - 1][0];
		for (int j = 1; j < i; j++) {
			pref[j] = (pref[j - 1] + dp[i - 1][j]) % mod;
		}
		for (int j = 1; j <= i; j++) {
			int l, r;
			if (s[i - 2] == '<') {
				l = 1, r = j - 1;
			} else {
				l = j, r = i - 1;
			}
			dp[i][j] = (pref[r] - pref[l - 1] + mod) % mod;
		}
	}
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans = (ans + dp[N][i]) % mod;
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 49856
//ヘッダファイル
#include<stdio.h>
#include<math.h>

//マクロ定義
#define DIM2 2
#define X 0
#define Y 1

//プロトタイプ宣言
double func_calAB(double num1, double num2);
double func_calC(double num1, double num2, double num3, double num4);
double func_calX(double a1, double a2, double b1, double b2, double c1, double c2);
double func_calY(double a1, double a2, double b1, double b2, double c1, double c2);
double func_calR(double p1[], double result[]);

main()
{
	int n = 0, i = 0; //繰り返し回数制御変数
	double p1[DIM2] = {0, 0}, p2[DIM2] = {0, 0}, p3[DIM2] = {0, 0}; //変数の宣言と初期化
	double a1 = 0, a2 = 0, b1 = 0, b2 = 0, c1 = 0, c2 = 0;
	double r  = 0, result[DIM2] = {0, 0};
	scanf("%d", &n); //繰り返し回数の入力
	
	for(i = 0; i < n; i++)
	{
		//座標の入力を取得
		scanf("%lf %lf %lf %lf %lf %lf", &p1[X], &p1[Y], &p2[X], &p2[Y], &p3[X], &p3[Y]);
		
		a1 = func_calAB(p2[X], p1[X]);
		b1 = func_calAB(p2[Y], p1[Y]);
		c1 = func_calC(p1[X], p2[X], p1[Y], p2[Y]);
		
		a2 = func_calAB(p3[X], p1[X]);
		b2 = func_calAB(p3[Y], p1[Y]);
		c2 = func_calC(p1[X], p3[X], p1[Y], p3[Y]);
		
		result[X] = func_calX(a1, a2, b1, b2, c1, c2);
		result[Y] = func_calY(a1, a2, b1, b2, c1, c2);
		
		r = func_calR(result, p1);
		
		printf("%.3lf %.3lf %.3lf\n", result[X], result[Y], r);
		r = 0, result[X] = 0, result[Y] = 0;
	}
	return 0;
}
double func_calAB(double num1, double num2)
{
	double result = 0;
	result = 2 * (num1 - num2);
	return result;
}
double func_calC(double num1, double num2, double num3, double num4)
{
	double result = 0;
	result = pow(num1, 2) - pow(num2, 2) + pow(num3, 2) - pow(num4, 2);
	return result;
}
double func_calX(double a1, double a2, double b1, double b2, double c1, double c2)
{
	double result = 0;
	result = ((b1 * c2) - (b2 * c1)) / ((a1 * b2) - (a2 * b1));
	return result;
}
double func_calY(double a1, double a2, double b1, double b2, double c1, double c2)
{
	double result = 0;
	result = ((c1 * a2) - (c2 * a1)) / ((a1 * b2) - (a2 * b1));
	return result;
}
double func_calR(double p1[], double result[])
{
	double r = 0;
	r = sqrt(pow(p1[X] - result[X], 2) + pow(p1[Y] - result[Y], 2));
	return r;
}

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

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        final int K = sc.nextInt();
        
        final int[] p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i] = sc.nextInt();
        }
        
        int answer = Arrays.stream(p).sorted().limit(K).sum();
        
        System.out.println(answer);
    }
}


Measured memory_bytes: 39320
import java.util.Scanner;
public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n==0) break; 
            double sum=0.0;
            double x=0.0;
            double a,m,y;
            int[] s = new int[n];
            for(int i=0;i<n;i++){
                s[i] = sc.nextInt();
                sum += s[i];
            }
            m = sum/n;
            for(int i=0;i<n;i++){
                x += Math.pow(s[i]-m,2);
            }
            y = x/n;
            a = Math.sqrt(y);
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 31152
#include <iostream>
#include <cstdio>

using namespace std;

int k, s;
int cnt;

int main()
{
    scanf("%d%d", &k, &s);
    for(int i = 0; i <= k; i++)
    {
        for(int j = 0; j <= k; j++)
        {
            if(s >= i + j && s <= k + i + j)cnt++;
        }
//        cnt += max(min(s-i, k) - max(s - k - i, 0) + 1, 0);
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
struct C{
  char s[11];
};
pair<C,int> a[100000];
struct pi{
  bool operator()(const pair<C,int>& p,const pair<C,int>& q){
    return strcmp(p.first.s,q.first.s)<0;
  }
  bool operator()(const pair<int,int>& p,const pair<int,int>& q){
    if(0){
    }else if(p.second>q.second){
      return 1;
    }else if(p.second<q.second){
      return 0;
    }else{
      return strcmp(a[p.first].first.s,a[q.first].first.s)<0;
    }
  }
  bool operator()(const pair<C,int>& p,const char q[]){
    return strcmp(p.first.s,q)<0;
  }
};
int main(){
  int i;
  int n,m,k,l;
  while(scanf("%d%d%d%d",&n,&m,&k,&l),n||m||k||l){
    for(i=0;i<n;++i)
      scanf("%s%d",a[i].first.s,&(a[i].second));
    sort(a,a+n,pi());
    pair<int,int> b[100000];
    for(i=0;i<n;++i)
      b[i]=make_pair(i,a[i].second);
    sort(b,b+n,pi());
    int c[100000],d[100000];
    for(i=0;i<n;++i)
      d[i]=i;
    for(i=0;i<m;++i){
      char s[11];
      scanf("%s",s);
      int p=lower_bound(a,a+n,s,pi())-a;
      c[i]=lower_bound(b,b+n,make_pair(p,a[p].second),pi())-b;
      d[c[i]]=-1;
    }
    sort(c,c+m);
    remove(d,d+n,-1);
    int mn=lower_bound(c,c+m,k)-c,mx=min(k,m)+1;
    for(;mx-mn>1;){
      int sm=0;
      for(i=0;i<(mn+mx)/2&&sm<=l;++i){
	if(0){
	}else if(b[c[i]].second>b[d[k-(mn+mx)/2]].second){
	}else if(b[c[i]].second<b[d[k-(mn+mx)/2]].second){
	  if(strcmp(a[b[c[i]].first].first.s,a[b[d[k-(mn+mx)/2]].first].first.s)<0){
	    sm+=b[d[k-(mn+mx)/2]].second-b[c[i]].second;
	  }else{
	    sm+=b[d[k-(mn+mx)/2]].second-b[c[i]].second+1;
	  }
	}else{
	  if(c[i]>d[k-(mn+mx)/2]){
	    ++sm;
	  }
	}
      }
      if(sm>l)
	mx=(mn+mx)/2;
      else
	mn=(mn+mx)/2;
    }
    printf("%d\n",mn);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector<int> p(N), q(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> q[i];
  }

  vector<int> l(N);
  for (int i = 0; i < N; i++) {
    l[i] = i + 1;
  }

  map<vector<int>, int> m;
  do {
    m[l] = m.size();
  } while(next_permutation(l.begin(), l.end()));

  cout << abs(m[p] - m[q]) << endl;
  return 0;
}

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

using namespace std;

int main()
{
  string w;
  bool a = true;
  cin >> w;
  sort(w.begin(), w.end());

  if (w.size() % 2 == 0)
  {
    for (int i = 0; i < w.size() / 2; i += 2)
    {
      if (w[i] == w[i + 1])
      {
        continue;
      }
      else
      {
        a = false;
      }
    }
  }
  else
  {
    a = false;
  }

  if (a)
    printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 256
def main ():
  N = int(input())
  A = list(map(int,input(). split ()))
  
  if 0 in A:
    print(0)
    return
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
main ()


Measured memory_bytes: 21664
#include<iostream>
#include<math.h>
#include <iomanip>
using namespace std;

int main(){
    long double ay,ax,by,bx,res;
    long int a,b,h,m;

    cin >> a >> b >> h >> m;

    ay = a * cos( ( ( 2 * h * M_PI ) / 12 ) + ( ( 2 * m * M_PI ) / ( 12 * 60 ) ) );
    ax = a * sin( ( ( 2 * h * M_PI ) / 12 ) + ( ( 2 * m * M_PI ) / ( 12 * 60 ) ) );
    by = b * cos( ( 2 * m * M_PI ) / 60 );
    bx = b * sin( ( 2 * m * M_PI ) / 60 );

    res = sqrt( ( ax - bx ) * ( ax - bx ) + ( ay - by ) * ( ay - by ) );

    cout << fixed << setprecision(20) << res << "\n";

    return 0;
}

Measured memory_bytes: 4116
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,L;
string line[105];


int main(){

	scanf("%d %d",&N,&L);

	for(int i = 0; i < N; i++){

		cin >> line[i];
	}
	sort(line,line+N);

	for(int i = 0; i < N; i++){

		printf("%s",line[i].c_str());
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>

#include <cmath>
#include <string>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

long long arr[405];
long long pref[405];
long long dp[405][405];

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

	int n;
	cin >> n;

	pref[0] = 0;
	for (int i = 1; i < n+1; i++) {
		cin >> arr[i];
		pref[i] = pref[i-1] + arr[i];
		dp[i][i] = 0;
	}

	for (int k = 1; k < n; k++) {
		for (int i = 1; i < n + 1 - k; i++) {
			int j = i + k;
			dp[i][j] = 1e18;
			for (int m = i; m < j; m++) {
				dp[i][j] = min(dp[i][j], dp[i][m] + dp[m+1][j]);
			}
			dp[i][j] += pref[j] - pref[i-1];
		}
	}

	cout << dp[1][n] << endl;

	return 0;
}


Measured memory_bytes: 1536
import numpy as np
n = int(input())
F = np.array([])
for i in range(n):
  F = np.append(F,np.array(list(map(int,input().split()))))
F = F.reshape([n,10])
p = [list(map(int,input().split())) for _ in range(n)]

ans = -10**9
for i in range(1,2**10):
  s = 0
  J = np.array([])
  for j in range(10):
    J = np.append(J,(i >> j) & 1)
  s = 0
  for j in range(n):
    s += p[j][int(np.dot(F[j],J))]
  ans = max(ans,s)
print(ans)

Measured memory_bytes: 21048
# ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ans, A, cnt = [""] * M, [], 1
    for i in range(M):
        p, y = map(int, input().split())
        A += [(p, y, i)]
    A.sort()

    ans[A[0][2]] = "{:06}{:06}".format(A[0][0], cnt)
    for i in range(1, M):
        if A[i - 1][0] == A[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[A[i][2]] = "{:06}{:06}".format(A[i][0], cnt)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

using namespace std;

const int N = 4e5 + 100;
const int offset = 2e5;

struct SegmentTree {
    int IT[N << 2];
    int n;

    void Up(int u, int val) {
        // cerr << "Up " << u << ' ' << val << '\n';
        Up(1, 0, n, u, val);
    }

    int LastSmaller(int x) {
        return LastSmaller(1, 0, n, x);
    }
    
    void Up(int k, int l, int r, int u, int v) {
        if (l == r) {
            IT[k] = v;
            return;
        }
        int m = (l + r) >> 1;
        if (u <= m) Up(k << 1, l, m, u, v);
        else Up(k << 1 | 1, m + 1, r, u, v);
        IT[k] = min(IT[k << 1], IT[k << 1 | 1]);
    }

    int LastSmaller(int k, int l, int r, int x) {
        if (IT[k] >= x) return -1;
        if (l == r) return l;
        int m = (l + r) >> 1;
        if (IT[k << 1 | 1] < x) return LastSmaller(k << 1 | 1, m + 1, r, x);
        return LastSmaller(k << 1, l, m, x);
    }
}IT;

vector<int> e[N];
long long f[N];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    string st;
    cin >> st;
    int n = st.size();
    st = '~' + st;
    int sum = 0;
    int cur = 0;
    IT.n = n;
    for (int i = 0; i < N * 4; ++i) IT.IT[i] = 1e9;
    e[0 + offset].push_back(0);
    IT.Up(0, 0);
    string s;
    for (int i = 1; i <= n; ++i) {
        if (st[i] == '(') {
            s += st[i];
            ++cur;
            f[cur] = f[cur - 1];
            ++sum;
            e[sum + offset].push_back(cur);
            IT.Up(cur, sum);
        } else if (st[i] == ')') {
            s += st[i];
            ++cur;
            f[cur] = f[cur - 1];
            --sum;
            int p = IT.LastSmaller(sum);
            // cerr << sum << ' ' << cur << ' ' << p << '\n';
            f[cur] += e[sum + offset].end() - lower_bound(e[sum + offset].begin(), e[sum + offset].end(), p);
            e[sum + offset].push_back(cur);
            IT.Up(cur, sum);
        } else {
            // -
            e[sum + offset].pop_back();
            if (s.back() == ')') ++sum;
            else --sum;
            s.pop_back();
            f[cur] = 0;
            IT.Up(cur, 1e9);
            --cur;
        }
        // cerr << IT.IT[1] << ' ' << s << ' ';
        cout << f[cur] << '\n';
    }
}


Measured memory_bytes: 26856
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = list(sys.stdin.buffer.readline().decode().rstrip())
T = list(sys.stdin.buffer.readline().decode().rstrip())

S = np.array(S, dtype=str)
T = np.array(T, dtype=str)


ok=False
for _ in range(len(S)):
    S = np.roll(S, 1)
    ok |= np.all(S == T)
if ok:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 13436
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int p[100010], n, k;
ll d[2][100010];
ll s[100010];

void solve(){
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;i++)scanf("%d", p+i);
	for(int i=1;i<=n;i++)d[0][i] = d[0][i-1] + max(0, p[i]);
	for(int i=n;i;i--)d[1][i] = d[1][i+1] + max(0, p[i]);
	for(int i=1;i<=n;i++)s[i] = s[i-1] + p[i];
	ll ans = 0;
	for(int i=1;i+k-1<=n;i++){
		ans = max(ans, d[0][i-1] + d[1][i+k] + max(0LL, s[i+k-1] - s[i-1]));
	}
	printf("%lld", ans);
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

int main() {
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    //printf("%d %d %d %d %d\n", A, B, C, X, Y);
    int mi = 1 << 30;
    int res = 0;
    if (A + B > 2 * C && X > 0 && Y > 0) {
        int R = min(X,Y);
        res = C * 2 * R;
        X -= R;
        Y -= R;
    }
    if (A < 2 * C) {
        res += A * X;
    } else {
        res += (2 * C) * X;
    }
    if (B < 2 * C) {
        res += B * Y;
    } else {
        res += (2 * C) * Y;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
s=input()
s=s[:-1]
def Evenstring(str):
    if len(str)%2==0 and str[:len(str)//2]==str[len(str)//2:]:
        return True
    else:
        return False

while True:
    if Evenstring(s)==True:
        print(len(s))
        break
    else:
        s=s[:-1]
        #末尾の一文字を削除

Measured memory_bytes: 3060