akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
// #define input(X) getline(cin,X)
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
ll n,m,l;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

vi primes;
bool prime[70000];

void hurui(){
  clr(prime,false);

  rep(i,2,55555){
    if(!prime[i]){
      if(i % 5 == 1)primes.pb(i);

      for(int j = 2;j*i <= 55555;j++)prime[j*i] = true;
    }
  }
}

int main(){
  cin >> n;
  hurui();
  rep(i,0,n){
    cout << primes[i];
    if(i == n-1)break;
    cout << " ";
  }
  puts("");
  return 0;
}

Measured memory_bytes: 384
function main()
	N,K=map(x->parse(Int,x),split(readline()))
	s=map(x->parse(Int,x),split(readline()))
	a=zeros(Int,N+1)
	b=zeros(Int,N+1)
	a[2]=s[1]
	b[2]=max(s[1],0)
	for i=2:N
		a[i+1]=s[i]+a[i]
		b[i+1]=max(s[i],0)+b[i]
	end
	ans=0
	for i=0:N-K
		sum=a[i+K+1]-a[i+1]
		if sum<0
			sum=0
		end
		sum+=b[i+1]-b[1]
		sum+=b[N+1]-b[i+K+1]
		ans=max(ans,sum)
	end
	println(ans)
end
main()

Measured memory_bytes: 154760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K,X,Y; cin>>N>>K>>X>>Y;
    int a = K*X; int b = (N-K)*Y;
    if(N<K) a = N*X, b = 0;
    int ans = a + b;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define Max 1001
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
    int d;
    cin>>d;
    if((d/10)%111==0 || (d - d/1000*1000)%111 == 0)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
N, x = map(int, input().split())
a  = list(map(int, input().split()))

b = a[:]

if b[0] > x:
    b[0] = x

for i in range(N-1):
    if b[i] + b[i+1] > x:
        b[i+1] = x - b[i]
ans = 0
for i in range(N):
    ans += a[i] - b[i]

print(ans)


Measured memory_bytes: 14068
import sys
import itertools
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    d = list(map(int,input().split()))
    ans = 0
    for i in itertools.combinations(d, 2):
        ans += i[0] * i[1]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int a,b; cin>>a>>b;
    cout<<max(0LL,a-2*b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int X;
  cin >> X;
  int n,ans;
  ans = 1;
  for(int i=2;i*i<=X;i++){
    n=i*i;
    while(n<=X){
      ans = max(ans,n);
      n *= i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define INT_MIN ( ( int ) 1 )
#define INT_MAX ( ( int ) 1000000000 )

typedef enum
{
	kSuccess,
	kError
}Result;

Result checkNumRange( int num, int min, int max );
int calctateGcd( int x, int y );

int main( void )
{
	int x;
	int y;

	scanf( "%d %d", &x, &y );

	if( ( checkNumRange( x, INT_MIN, INT_MAX ) == kError ) || ( checkNumRange( y, INT_MIN, INT_MAX ) == kError ) )
	{
		return -1;
	}

	printf( "%d\n", calctateGcd( x, y ) );

	return 0;
}

Result checkNumRange( int num, int min, int max )
{
	return ( ( num >= min ) && ( num <= max ) ) ? kSuccess : kError;
}

int calctateGcd( int x, int y )
{
	int work;

	if( x < y )
	{
		work = x;
		x = y;
		y = work;
	}

	while( y > 0 )
	{
		work = x % y;
		x = y;
		y = work;
	}

	return x;
}



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

int main()
{
    int n, i, count=0;
    cin>>n;
    char s[51];
    cin>>s;

    for(i=0; i<n;i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2] =='C'){
            count ++;
        }
    }
    printf("%d\n", count);
}


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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" <<endl;
  }
  else if (s == "Cloudy") {
    cout << "Rainy" <<endl;
  }
  else {
    cout << "Sunny" <<endl;
  }
}


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

typedef long long ll; 
typedef vector<int> veci;

int main()
{ 
    string s;
    int k;
    cin>>s>>k;
    vector<string>v;
    
    forx(i,0,s.size()){
      string t;
      for(int j=i;j<i+k&&j<s.size();j++){
        t+=s[j];
        v.push_back(t);
      }
      }
      
      sort(v.begin(),v.end());
      v.erase(unique(v.begin(),v.end()),v.end());
      cout<<v[k-1]<<endl;
   
return 0;
}


Measured memory_bytes: 1660
#include<stdio.h>
int main ( )
{
	long long int N,result;
	
	scanf("%lld",&N);
	
		if(N%2==0)
		{
		 result=N;
		}
		else
                {
                  result=N*2;

         }
	
	printf("%lld\n",result);
	return 0;
	
}
	
	

Measured memory_bytes: 1720
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

# def input(): return sys.stdin.readline().strip()
# def INT(): return int(input())
# def MAP(): return map(int, input().split())
# def LIST(): return list(map(int, input().split()))
# def ZIP(n): return zip(*(MAP() for _ in range(n)))


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

# a = list(map(int, input().split()))  # n個の文字列がリストに格納される

def sum_num(l,r): 
    result = (l+r) * (r-l+1)/2
    return result

N, K = map(int, input().split())

ans=0
for s in range(K,N+2):
    L = sum_num(0,s-1)
    R = sum_num(N-s+1,N)
    ans += R - L + 1

print(int(ans%(10**9+7)))


Measured memory_bytes: 9132
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>

using namespace std;
using namespace std::chrono;

vector<int> numbers;
int a;
int b;
int diff;
int ans;
int larger = 0;

int main() {
  cin >> a;
  cin >> b;
  diff = b-a;
  for (int i=1; i<=diff; i++) {
      larger += i;
  }
  ans = larger-b;
  
  cout << ans;
  return 0;
}

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

mod = 10**9+7

A = [a+1 for a in A]
C = [0]*(n+1)
C[0] = 3
ans = 1
for a in A:
    if C[a-1] < C[a]:
        print(0)
        exit()
    else:
        ans *= C[a-1]-C[a]
        ans %= mod
        C[a] += 1
print(ans)

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

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

using namespace std;
using lint=long long;

int main(){
	int n; cin>>n;
	vector<lint> a(n),b(n);
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>b[i];

	vector<lint> b2[30];
	rep(i,30){
		b2[i]=b;
		rep(j,n) b2[i][j]&=(1<<(i+1))-1;
		sort(b2[i].begin(),b2[i].end());
	}

	int ans=0;
	rep(i,30){
		lint cnt=0;
		rep(j,n){
			lint a2=a[j]&((1LL<<(i+1))-1);
			cnt+=lower_bound(b2[i].begin(),b2[i].end(),(1LL<<(i+1))-a2)
				-lower_bound(b2[i].begin(),b2[i].end(),(1LL<<i)-a2);
			cnt+=lower_bound(b2[i].begin(),b2[i].end(),(1LL<<(i+2))-a2)
				-lower_bound(b2[i].begin(),b2[i].end(),(1LL<<(i+1))+(1LL<<i)-a2);
		}
		if(cnt%2==1) ans|=1<<i;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 52352
#!/usr/bin/env python3
import sys
from collections import defaultdict
MOD = 1000000007  # type: int


class Combination(object):

    def __init__(self, N, mod=MOD):
        fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N+1):
            fac[i] = fac[i-1]*i % mod
            inv[i] = -inv[mod % i]*(mod//i) % mod
            finv[i] = finv[i-1]*inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        b = (self.finv[k]*self.finv[n-k] % self.MOD)
        return (self.fac[n] * b) % self.MOD


def solve(N: int, a: "List[int]", b: "List[int]"):
    # グラフの構築
    E = [[] for _ in range(N)]
    for aa, bb in zip(a, b):
        E[aa-1].append(bb-1)
        E[bb-1].append(aa-1)

    # 組み合わせの初期化
    cmb = Combination(N)

    # BFSの入り順を構成する
    front, back = -1, 1
    downward = [0]*N
    parent = [-1]*N
    for _ in range(N-1):
        front += 1
        v = downward[front]
        for u in E[v]:
            if u == parent[v]:
                continue
            parent[u] = v
            downward[back] = u
            back += 1
    # print(downward)

    # 節点vを根とした部分木の塗り方dp[v]
    dp = [1]*N
    # 節点vを根とした部分木のサイズsize[v]+1
    size = [0]*N

    # 木DP
    # 葉から根へ向かう探索
    for v in reversed(downward):
        for u in E[v]:
            if u == parent[v]:
                continue
            size[v] += size[u]+1
            dp[v] *= cmb.finv[size[u]+1]
            dp[v] %= MOD
            dp[v] *= dp[u]
            dp[v] %= MOD
        dp[v] *= cmb.fac[size[v]]
        dp[v] %= MOD

    # 全方位木DP
    # 根から葉へ向かう探索
    for v in downward:
        for u in E[v]:
            if u == parent[v]:
                continue
            dp[u] = dp[v]
            dp[u] *= (size[u]+1)*cmb.inv[N-(size[u]+1)]
            dp[u] %= MOD

    for v in dp:
        print(v)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 110120
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        while (s.contains("0B")||s.contains("1B")) {
            s = s.replaceAll("0B", "");
            s = s.replaceAll("1B", "");
        }
        s=s.replaceAll("B","");
        System.out.println(s);
}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
bool dp[10000];
char s[500005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
	cin >> n >> m;
	if(m > 2 * n){
		ans += n;		
		m -= 2 * n;
		n = 0; 
	}else{
		ans += m/2;
		m = m%2;
	}
	ans += m/4;
	p(ans);
 
 
	return 0;
}

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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int count = 0;

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

    return 0;
}

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

int main() {
    string o;
    string e;
    cin >> o >> e;
    int so = o.size();
    int se = e.size();

    rep(i, se) cout << o[i] << e[i];
    so==se ? cout << endl :
                cout << o[so-1] << endl;;
    
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 16 20:34:20 2019

@author: Yamazaki Kenichi
"""

N = int(input())
S = input()
mod = 10**9+7

abc = [chr(i) for i in range(97, 97+26)]
a = [0 for i in range(26)]
for i in range(26):
    a[i] = S.count(abc[i])

ans = 1 + a[0]
for i in range(1,26):
    ans += ans * a[i]
ans -= 1
print(ans%mod)   

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

int n;

int main() {
    cin >> n;
    int arr[n];
    for (int i=0; i<n;i++){
        cin >> arr[i];
    }
    int total;
    const size_t size = sizeof(arr) / sizeof(arr[0]);
    total = accumulate(arr, arr + size, 0);
    int left_sum = 0;
    int right_sum;
    int min_diff = 100000;
    for (int j=0; j<n; j++){
        left_sum += arr[j];
        right_sum = total - left_sum;
        min_diff = min(min_diff, abs(right_sum - left_sum));
    }
    cout << min_diff;

}

Measured memory_bytes: 3596
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
R = []
for i in range(N):
    for j in range(i+1,N):
        r = 0
        for d in range(D):
            r += (X[i][d] - X[j][d]) ** 2
        for n in range(1,300):
            if r == n ** 2:
                cnt += 1
        R.append(r)

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int main(){
  int N;
  cin >> N;
  int T[111111],A[111111];
  for(int i = 0;i < N;i++)cin >> T[i];
  for(int i = 0;i < N;i++)cin >> A[i];
  int64 g = 1;
  for(int i = 1;i < N - 1;i++){
    if(T[i] > T[i - 1]){
      if(T[i] <= A[i])continue;
      else{T[N - 1] = A[0] + 1;break;}
    }
    if(A[i] > A[i + 1]){
      if(A[i] <= T[i])continue;
      else{T[N - 1] = A[0] + 1;break;}
    }
    if(T[i] < T[i - 1]){T[N - 1] = A[0] + 1;break;}
    if(A[i] < A[i + 1]){T[N - 1] = A[0] + 1;break;}
    g = (g * min(T[i],A[i])) % 1000000007;
  }
  if(T[N - 1] == A[0])cout << g << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 1152
N=int(input())
s=[]
for i in range(N):
	s.append(input())
count=0

target = "AB"
for i in range(N):
	index = -1
	while True:
		index = s[i].find(target, index + 1)
		if index == -1:
			break
		count += 1


# これだけだと1文中に2文以上あるときに検出できない
# for i in range(N):
# 	index = s[i].find("AB")
# 	if index != -1:
# 		count += 1
a=0
b=0
ba=0


for i in range(N):
	if s[i][-1]=="A" and s[i][0]=="B":
		ba+=1
	elif s[i][-1] == "A" and s[i][0] != "B":
		a+=1
	elif s[i][-1] != "A" and s[i][0] == "B":
		b+=1
# print("a",a)
# print(b)
# print(ba)
"""
one=min(a,b)
two=0
if ba>0:
	two=ba-1

	if abs(a-b)>0:
		two=ba-1+1
print(one+two+count)
"""

if ba==0:
	count+=min(a,b)
else:
	if a==0 and b==0:
		count += (ba - 1)
	elif a == 0 or b == 0:
		count += ba
	else:
		count +=(ba + min(a,b))
		# min(a, b) : -A,B-同士が結合する数
		# B-AはB-A同士で結合する 数：ba-1
		# 結合したB-Aの最初はB，最後はAになっているので，
		# そのどちらかに-A,B-が結合したものがくっつくき，また結合が1つできる 数：ba-1+1 = ba
# if a >= 1 and b >= 1:
# 	count += ba + min(a, b)
# elif a >= 1 or b >= 1:
# 	count += ba
# else:
# 	count += max(0, ba - 1)

print(count)


Measured memory_bytes: 3700
#!/usr/bin/perl
#= CPAN mocules =====================================================#
require 5.8.8;			# Perl 5.8.8以降
use strict;				# strictモード
use warnings;			# 警告有効
use utf8;				# UTF8モード ON

#= Global values ====================================================#
#= Local routines ===================================================#
sub main(){
	my $input = <>;
	chomp $input;

	my @dat;
	my @ad;
	my $pos = 0;
	my $i = 1;
	while (1){
		$pos += $i;
		if ($pos >= $input){
			printf("%d\n", $i);
			last;
		}
		$i++;
	}
	return 0;
}

#----- 実行 -----#
exit( main() );




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

string o,e;

int main(){
  cin >> o >> e;

  string ans="";
  for(int i=0;i<o.length()+e.length();i++){
    if(i%2==0)ans+=o[i/2];
    else ans+=e[(i-1)/2];
  }

  cout << ans << endl;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  vector<int> q = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  ll n;
  cin >> n;
  cout << q[n-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N],B[N];
    for (int i=0;i<N;i++){
    cin >> A[i];
    B[i] = A[i];
    }
    sort(B,B+N,greater<int>());
    for(int i=0;i<N;i++){
      if (A[i] != B[0])cout << B[0] << endl;
      else cout << B[1] << endl;
    }
}


Measured memory_bytes: 3200
def main():
    N, M, C = map(int, input().split())
    B = [int(x) for x in input().split()]
    A = [[int(a) for a in input().split()] for i in range(N)]

    results = 0

    for a_line in A:
        tmp = 0
        for a, b in zip(a_line, B):
            tmp += a*b
        tmp += C
        if tmp > 0:
            results += 1

    print(results)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#!/usr/bin/env python3
import math
n = int(input())
def is_prime(n):
    for i in range(2,math.ceil(n**1/2)+1):
        if n % i == 0:
            return False
    return True    
i = n
while True:
    if is_prime(i): break
    i += 1
print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string ans = "";
    REP(i,0,tx-sx) ans += 'R';
    REP(i,0,ty-sy) ans += 'U';
    REP(i,0,tx-sx) ans += 'L';
    REP(i,0,ty-sy) ans += 'D';

    ans += 'D';
    REP(i,0,tx-sx+1) ans += 'R';
    REP(i,0,ty-sy+1) ans += 'U';
    ans += 'L';
    ans += 'U';
    REP(i,0,tx-sx+1) ans += 'L';
    REP(i,0,ty-sy+1) ans += 'D';
    ans += 'R';

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

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

ans=0
count=0
for i in range(1,n+1):
    if i%2 == 1:
        for j in range(1,i+1):
            if i%j == 0:
                count += 1
        if count == 8:
            ans += 1
        count = 0

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> a(n), sum(n+1);
  rep(i,n){
    cin >> a[i];
    sum[i] += a[i];
    sum[i+1] += sum[i];
    sum[i+1] %= MOD;
  }
  ll ans = 0;
  rep(i,n-1){
    ans += sum[i]*a[i+1];
    ans %= MOD;
  }
  cout << ans;
  cout << "\n";
  return 0;
}


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

public class Hello
{
    public static void Main()
    {
        var a = Console.ReadLine().Trim();
        var st = new Stack<int>();
        for (int i = 0; i < a.Length; i++)
            if (st.Count() == 0) st.Push(a[i] == 'S' ? 0 : 1);
            else
            {
                if (a[i] == 'S') st.Push(0);
                else if (a[i] == 'T' && st.Peek() == 1) st.Push(1);
                else st.Pop();
            }
        Console.WriteLine(st.Count());
    }
}


Measured memory_bytes: 12896
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
int main()
{
	int n,m,a;
	cin>>n;
	int ans=0;
	rep3(i,1,n+1)
	{
		cin>>a;
		if(a%2==1&&i%2==1) ans++;
	}
	cout<<ans;
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

struct UnionFind{
    vector<int32> par;
    int32 size;
    UnionFind(int32 n){
        REP(i,n)par.pb(i);
        size = n;
    }
    int32 root(int32 x){
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    void unite(int32 a, int32 b){
        a = root(a);
        b = root(b);
        if(a == b)return;
        par[a] = b;
        size--;
    }
    bool same(int32 a, int32 b){
        return root(a) == root(b);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    UnionFind uf = UnionFind(n);
    REP(i,m){
        int32 x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        uf.unite(x,y);
    }
    ANS(uf.size);
    return 0;
}

Measured memory_bytes: 1400
N, K = map(int,input().split())
S = input()
t = S[K-1:K]
if t == 'A':
  print(S[:K-1] + 'a' + S[K:])
elif t == 'B':
  print(S[:K-1] + 'b' + S[K:])
else:
  print(S[:K-1] + 'c' + S[K:])

Measured memory_bytes: 3060
fun main() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val hs = readLine()!!.split(' ').map { it.toInt() }
    val ans = BooleanArray(n) { true }
    repeat(m) {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() - 1 }

        when {
            hs[a] > hs[b] -> {
                ans[b] = false
            }
            hs[a] < hs[b] -> {
                ans[a] = false
            }
            else -> {
                ans[a] = false
                ans[b] = false
            }
        }
    }
    println(ans.count { it })
}


Measured memory_bytes: 62312
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	cin >> s;

	string ans="No";
	char c1=' ',c2=' ';
	int counta=0,countb=0;
	for(int i=0; i<4; i++){
		char c;
		c=s[i];
		if(counta==0){
			c1=c;
			counta++;
		}else{
			if(c==c1){
				counta++;
			}else{
				if(countb==0){
					c2=c;
					countb++;
				}else if(c==c2){
					countb++;
				}
			}
		}
	}
	if(counta==2 && countb==2){
		ans="Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

// ABC 47-C
// http://abc047.contest.atcoder.jp/tasks/arc063_a

public class Main {
	
	static int MOD = 1000000007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c = in.next().toCharArray();
		int answer = 0;
		
		char cc = c[0];
		for (int i = 1; i < c.length; i++) {
			if (cc != c[i]) {
				answer++;
				cc = c[i];
			}
		}
		
		System.out.println(answer);
	}
}

Measured memory_bytes: 25700
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

const double PI = acos(-1);

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    H *= 5.0;
    H += 5.0 * (M / 60.0);
    double a = min(abs(H - M), 60.0 - abs(H - M));
    double deg = a * 6.0 * (PI / 180.0);
    double res = sqrt(A * A + B * B - 2.0 * A * B * cos(deg));
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 4212
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 100005;
long long s = 0;
int cnt[N];
int n, a[N];
int q;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	up(i,1,n) {
		cin >> a[i];
		cnt[a[i]]++;
		s += a[i];
	}
	cin >> q;
	while (q--){
		int u, v;
		cin >> u >> v;
		s -= 1LL*(u-v)*cnt[u];
		cnt[v] += cnt[u];
		cnt[u] = 0;
		cout << s << '\n';
	}

}

Measured memory_bytes: 4392
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


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


ll A[200010];
ll B[200010];
int main() {
	ll N;
	ll sum = 0;
	cin >> N;
	REP(i, N) {
		cin >> A[i];

		B[i] = A[i] - (i + 1);
		sum += B[i];
	}
	SORT(B, N);
	int cnt = B[N / 2];
	ll ans = 0, ans2 = 0, ans3 = 0;
	if (cnt < 0) {
		int c = abs(cnt);
		REP(i, N) {
			ans += abs(B[i] + c);
			ans2 += abs(B[i] + c + 1);
			ans3 += abs(B[i] + c - 1);
		}
		ans = min(min(ans, ans2), ans3);
	}
	else if (cnt > 0) {
		REP(i, N) {
			ans += abs(B[i] - cnt);
			ans2 += abs(B[i] - cnt + 1);
			ans3 += abs(B[i] - cnt - 1);
		}
		ans = min(min(ans, ans2), ans3);
	}
	else {
		REP(i, N) {
			ans += abs(B[i]);
			ans2 += abs(B[i] + 1);
			ans3 += abs(B[i] - 1);
		}
		ans = min(min(ans, ans2), ans3);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
H,W = map(int,input().split())
A = []
for i in range(H):
  A.append(input())
#print(A)

INF = 10000
S = [[INF for _ in range(W)] for _ in range(H)]
for i in range(H):
  flag = False
  for j in range(W):
    if A[i][j] == '#':
      flag  = True
      d = 0
      S[i][j] = 0
    if flag and A[i][j] == '.':
      d += 1
      S[i][j] = min(d,S[i][j])
  flag = False
  for j in range(W-1,-1,-1):
    if A[i][j] == '#':
      flag  = True
      d = 0
      S[i][j] = 0
    if flag and A[i][j] == '.':
      d += 1
      S[i][j] = min(d,S[i][j])
for j in range(W):
  flag = False
  for i in range(H):
    if S[i][j] < INF:
      flag = True
    if flag and i > 0 and A[i][j] == '.':
      S[i][j] = min(S[i][j],S[i-1][j]+1)
  flag = False
  for i in range(H-1,-1,-1):
    if S[i][j] < INF:
      flag = True
    if flag and i < H-1 and A[i][j] == '.':
      S[i][j] = min(S[i][j],S[i+1][j]+1)
#print(S)

ans = 0
for s in S:
  ans = max(ans,max(s))
print(ans)

Measured memory_bytes: 59100
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int func(int n) {
    int res = 0;
    while(n) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

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

    if (n % func(n)) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << setprecision(16) << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; print(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;



int main() {
	int N;
	cin >> N;
	
	vector<double> V(N);

	REP(i, N) {
		cin >> V[i];
	}

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

	double ans = V[0];
	REP(i, N-1) {
		ans = (ans + V[i+1]) / 2;
	}

	print(ans);
}


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

struct segment_tree {
	segment_tree() {}
	segment_tree(int _n) {
		n = _n;
		N = 1; while(N - 1 <= n) N <<= 1;
		a = vector<int>(N << 1, 0);
	}

	void M(int i, int x) {
		a[i |= N] = x;
		for (i >>= 1; i; i >>= 1) a[i] = max(a[i << 1], a[(i << 1) | 1]);
		return;
	}

	int Q(int i) {
		int x = 0;
		for (int s = (i | N) - 1, t = (n | N) + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
			if(~s & 1) x = max(x, a[s ^ 1]);
			if(t & 1) x = max(x, a[t ^ 1]);
		}
		return x;
	}
	private :
	vector<int> a;
	int n, N;
};

int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n), s(n, 0);
	vector<bool> h(n);
	for (int mx = 0, i = 0; i < n; ++i) cin >> a[i], h[i] = (a[i] > mx), mx = max(mx, a[i]);
	for (int i = n - 1; i; --i) s[i - 1] = s[i] + h[i];

	array<segment_tree, 2> seg = {segment_tree(n), segment_tree(n)};
	for (int i = n - 1; ~i; --i) {
		array<int, 2> g = {seg[0].Q(a[i]), seg[1].Q(a[i])};
		if(h[i]) {
			seg[0].M(a[i], g[0] + 2);
			if(g[1] & 1) seg[1].M(a[i], g[1] + 2);
		}
		else {
			seg[1].M(a[i], g[0] + 1);
			if(g[1] & 1) seg[0].M(a[i], g[1] + 1);
		}
	}

	int max0(0), max1(0), cnt0(0), cnt1(0);
	string ans("");
	for (int x, i = 0; i < n; ++i) {
		x = a[i];
		seg[0].M(x, 0); seg[1].M(x, 0);

		auto check = [&](int max0, int cnt0, int max1, int cnt1) {
			static array<int, 2> g;
			g = {seg[0].Q(max0), seg[1].Q(max0)};
			if(cnt0 + cnt1 + s[i] & 1) {
				if(g[1] & 1) {
					if(cnt0 + 1 <= cnt1 + s[i] && cnt0 + g[1] >= cnt1 + s[i]) return true;
				}
			}
			else {
				if(cnt0 <= cnt1 + s[i] && cnt0 + g[0] >= cnt1 + s[i]) return true;
			}
			g = {seg[0].Q(max1), seg[1].Q(max1)};
			if(cnt0 + cnt1 + s[i] & 1) {
				if(g[1] & 1) {
					if(cnt1 + 1 <= cnt0 + s[i] && cnt1 + g[1] >= cnt0 + s[i]) return true;
				}
			}
			else {
				if(cnt1 <= cnt0 + s[i] && cnt1 + g[0] >= cnt0 + s[i]) return true;
			}
			return false;
		};

		if(check(max(max0, x), cnt0 + (x > max0), max1, cnt1)) { ans += "0"; max0 = max(max0, x); cnt0 += (x == max0); }
		else { ans += "1"; max1 = max(max1, x); cnt1 += (x == max1); }
	}
	if(cnt0 == cnt1) cout << ans << endl;
	else cout << "-1\n";
	return 0;
}

Measured memory_bytes: 9368
#include<iostream>
#include<cmath>

using namespace std;

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

   // チェック
   int a = (int)((1 + sqrt(1 + 8 * n))/2);
   if (a * (a-1)  != n * 2){
      cout << "No" << endl;
      return 0;
   }else{
      cout << "Yes" << endl;
   }

   // 出力
   cout << a << endl;
   int x = 1;
   int* num = new int[a];
   for(int i=0;i<a;i++){
      num[i] = x;
      // 数
      cout << a-1 << " ";
      for(int j=0;j<i;j++){
         cout << num[j] << " ";
         num[j]++;
      }
      for(int j=i;j<a-1;j++){
         cout << x << " ";
         x++;
      }
      cout << endl;
   }
}

Measured memory_bytes: 1408
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

ans = [["_" for _ in range(3)] for _ in range(3)]
bingo = False

for i in b:
  for j in range(3):
    for k in range(3):
      if i == A[j][k]:
        ans[j][k] = "〇"
        
for i in range(3):        
  if ans[i][0] == ans[i][1] == ans[i][2] == "〇":
    bingo = True
  if ans[0][i] == ans[1][i] == ans[2][i] == "〇":
    bingo = True

if ans[0][0] == ans[1][1] == ans[2][2] == "〇":
  bingo = True
if ans[0][2] == ans[1][1] == ans[2][0] == "〇":
  bingo = True
  
if bingo:
  print("Yes")
else:
  print("No")
  


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

template<typename T>
vector<vector<vector<T>>>
Make3DVector(int d1, int d2, int d3, T default_value) {
  return vector<vector<vector<T>>>(
      d1, vector<vector<T>>(d2, vector<T>(d3, default_value)));
}

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

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

  auto dp = Make3DVector<int64>(n + 1, n + 1, 50 * n + 1, 0LL);
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k <= i; k++) {
      for (int s = 0; s <= 50 * k; s++) {
        if (dp[i][k][s] > 0) {
          dp[i + 1][k + 1][s + xs[i]] += dp[i][k][s];
          dp[i + 1][k][s] += dp[i][k][s];
        }
      }
    }
  }

  int64 ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[n][i][a * i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 52224
#include <iostream>
#include <vector>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m));
	vector<vector<int>> b(m, vector<int>(1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int j = 0; j < m; j++) {
		cin >> b[j][0];
	}

	for (int i = 0; i < n; i++) {
		int c = 0;
		for (int j = 0; j < m; j++) {
			c += a[i][j] * b[j][0];
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 3132
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, W, D;
    while (cin>>N>>W>>D, N|W|D) {
        vector<vector<int>> st;
        st.push_back({W, D});
        for(int i=0; i<N; i++){
            int index, length;
            cin >> index >> length; index--;
            auto v = st[index];
            for(int j=index; j<i; j++)
                st[j] = st[j+1];
            
            int j = 0;
            while(1){
                if(length < v[j]){
                    vector<int> x(2), y(2);
                    x[j] = min(length, v[j]-length);
                    y[j] = max(length, v[j]-length);
                    x[j^1] = y[j^1] = v[j^1];
                    st.pop_back();
                    st.push_back(x);
                    st.push_back(y);
                    break;
                }
                length -= v[j];
                j ^= 1;
            }
        }
        vector<int> v;
        for(int i=0; i<=N; i++)
            v.push_back(st[i][0]*st[i][1]);
        sort(v.begin(), v.end());
        for(int i=0; i<=N; i++)
            cout << v[i] << (i==N ? "\n" : " ");
    }
    
    
    return 0;
}

Measured memory_bytes: 1248
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[-1])


Measured memory_bytes: 20440
#include<stdio.h>
#define MAX 100005
#define NIL -1

/*
p: parent
l: left-child
r: right sibling
*/
struct Node{ int p, l, r,d;};
struct Node T[MAX]; 
int depth[MAX];




void print(int u){
 /*
  */
 printf("node %d: parent = %d, depth = %d, ",u,T[u].p,T[u].d);
 if(T[u].p==-1){
 	printf("root, [");
 }else if(T[u].l==NIL){
 	printf("leaf, [");
 }else{
 	printf("internal node, [");
 }
 int p=T[u].l;

 while(p!=NIL){
      if(p==T[u].l)printf("%d",p);
      else printf(", %d",p);
     p=T[p].r;
 }
  printf("]\n");
}

void calc_depth(int deep,int p){
	T[p].d=deep;
	if(T[p].l==NIL)return;
	for(p=T[p].l;p!=NIL;p=T[p].r){
		calc_depth(deep+1,p);
	}
} 

int main(){
 int i, j, d, v, c, l,n;

 scanf("%d", &n);

 for ( i = 0; i < n; i++ ) {
   T[i].p = T[i].l = T[i].r = NIL;
 }

  for ( i = 0; i < n; i++ ){
   scanf("%d %d", &v, &d);
    int old=0;
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
	T[c].p=v;
 	if(j==0){
		T[v].l=c;
	}else{
		T[old].r=c;
	}
	old=c;
   }
 }
   int p;
  for(int i=0;i<n;i++)if(T[i].p==-1)p=i;
  calc_depth(0,p); 
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 2608
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,c[5][105]={},dp[5][105]={};
  cin >> n;
  for(int i=1; i<=2; i++) {
    for(int j=1; j<=n; j++) {
      cin >> c[i][j];
    }
  }
  for(int i=1; i<=2; i++) {
    for(int j=1; j<=n; j++) {
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])+c[i][j];
    }
  }
  cout << dp[2][n] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long n = sc.nextLong();
			long r = sc.nextLong();

			if (n < 10) {
				r = r + (10 - n) * 100;
			}

			// 出力(整数)
			System.out.println(r);
		}
	}

	/**
	 * 最小公倍数
	 */
	static long lcm(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return c / b;
	}

	/**
	 * 最大公約数
	 */
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}

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

bool solve() {
    ll N;
    string S;
    cin >> N >> S;
    if ( S.size() % 2 != 0 ) return false;
    for ( int i = 0; i < N/2; i++ ) {
        if ( S[i] != S[N/2+i] ) return false;
    }
    return true;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const long long INF = 2e9;
const int MaxSize = 500005;
int L[MaxSize/2+2], R[MaxSize/2+2];
int num[MaxSize];
int cnt;
void Merge(int A[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++)L[i] = A[left+i];
	for (int i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1] = R[n2] = INF;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j])A[k]=L[i++];
		else A[k]=R[j++];
	}
}
void Merge_sort(int A[], int left, int right) {
	if (left + 1 < right) {
		int mid = (right + left) / 2;
		Merge_sort(A, left, mid);
		Merge_sort(A, mid, right);
		Merge(A, left, mid, right);
	}
}
int main() {
	int n = 0;
	scanf("%d", &n);
	cnt = 0;
	for (int i = 0; i < n; i++) { 
		scanf("%d", & num[i]);
	}
	Merge_sort(num, 0, n);
	for (int i = 0; i < n ; i++) {
		if (i)printf(" ");
		 printf("%d",num[i]);
	}
	printf("\n%d\n", cnt);
	return 0;
}

Measured memory_bytes: 7004
//
//  main.cpp
//  ListOfHeights
//
//  Created by James Hosken on 28/09/2014.
//  Copyright (c) 2014 James Hosken. All rights reserved.
//

#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[])
{
    
    string input_line;
    
    int *heights;
    heights = new int[0];
    int lineNum = 0;
    
    
    while(cin)
    {
        getline(cin, input_line);
        lineNum++;
        
        //Chunk of array expansion code
        int line = atoi(input_line.c_str());
        int* temp = new int[lineNum];
        copy(heights, heights + lineNum-1, temp);
        delete [] heights;
        temp[lineNum-1] = line;
        heights = temp;
        
    }
    

    sort(heights, heights + lineNum);
    
    for(int i = lineNum-1; i >= lineNum-3; i--)
    {
        cout << heights[i] << endl;
    }

    
}

Measured memory_bytes: 1212
#include<stdio.h>

int main(){
    int a,b,d,r;
    double a2,b2,f;
    scanf("%d %d",&a,&b);
    d = a/b;
    r = a%b;
    f = (double)a / (double)b;
    
    printf("%d %d %lf",d,r,f);
    return 0;
}



Measured memory_bytes: 2744
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  char ch = getchar();
  puts(ch == 'a' || ch == 'i' || ch == 'u' || ch == 'e' || ch == 'o' ? "vowel" : "consonant");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(c) (c).begin(),(c).end()

int main() {

	int n, pos=0; string s;
	cin >> n >> s;
	char pat = 'A';
	n = 0;

	std::string target = "ABC";
   	while ((pos = s.find(target, pos )) != std::string::npos) {
          ++n;
          pos += target.length();
   }
   std::cout << n << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n,m;
vector<lli> a;
vector<vector<pair<lli,lli> > > b;
vector<vector<lli> > dp;
lli ans = 0;
int main(){
    cin >> n >> m;
    a = vector<lli> (n+1);
    for(lli i = 1;i < n;i++) cin >> a[i];
    b = vector<vector<pair<lli,lli> > > (m,vector<pair<lli,lli> >(n));
    for(lli i = 0;i < n;i++) for(lli j = 0;j < m;j++) cin >> b[j][i].first,b[j][i].second = i;
    dp = vector<vector<lli> > (n+1,vector<lli> (n+1));
    for(lli i = 0;i < m;i++){
        sort(b[i].rbegin(),b[i].rend());
        set<lli> s;
        s.insert(-1);s.insert(n);
        for(lli j = 0;j < n;j++){
            auto from = s.lower_bound(b[i][j].second);
            auto to = from;
            from--;
            dp[b[i][j].second+1][*to] += b[i][j].first;
            dp[*from+1][*to] -= b[i][j].first;
            dp[*from+1][b[i][j].second] += b[i][j].first;
            dp[b[i][j].second+1][b[i][j].second] -= b[i][j].first;
            s.insert(b[i][j].second);
        }
    }
    /* === imos === */
    for(lli i = 0;i < n;i++) for(lli j = 0;j < n;j++) dp[i+1][j] += dp[i][j];
    for(lli i = 0;i < n;i++) for(lli j = 0;j < n;j++) dp[i][j+1] += dp[i][j];
    /* --- imos --- */
    for(lli i = 0;i < n;i++) a[i+1] += a[i];
    for(lli i = 0;i < n;i++) for(lli j = i;j < n;j++) ans = max(ans,dp[i][j] - a[j] + a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 211712
N=int(input())
chk = (2*N)**(1/2)
k = chk//1
if N  != k*(k+1)//2:
    print("No")
else:
    print("Yes")
    k = int(k)
    print(k+1)
    ans_list = [[0 for i in range(k)] for j in range(k+1)]
    W1 = 0
    H1 = 0
    W2 = 0
    H2 = 1
    for i in range(N):
        ans_list[H1][W1] = i+1
        ans_list[H2][W2] = i+1
        if H1 == W1 :
            H1 = 0
            W1 =W1+1
            H2 = W1+1
            W2 = 0
        else:
            H1 += 1
            W2 += 1
    for i in range(k+1):
        print(str(k)+" "+" ".join(str(n) for n in ans_list[i]))

Measured memory_bytes: 12148
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; // 998'244'353LL
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

string T;

signed main(){
    cin >> T;
    rep(i, T.size()){
        if(T[i] == '?') cout << "D";
        else cout << T[i];
    }
    cout << endl;
}


Measured memory_bytes: 3744