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

const int maxn = 1010;
long long a[maxn], b[maxn], c[maxn];

int main() {
#ifdef HOME
  freopen("input.txt", "r", stdin);
#endif
  int x, y, z, kk;
  cin >> x >> y >> z >> kk;
  for (int i = 0; i < x; ++i) scanf("%lld", &a[i]); sort(a, a + x, greater<long long>());
  for (int i = 0; i < y; ++i) scanf("%lld", &b[i]); sort(b, b + y, greater<long long>());
  for (int i = 0; i < z; ++i) scanf("%lld", &c[i]); sort(c, c + z, greater<long long>());
  int top = 0;
  vector<long long> ans;
//  cerr << "done\n";
  for (int i = 0; i < x; ++i) {
    for (int j = 0; j < y; ++j) {
      for (int k = 0; k < z; ++k)
        if ((i + 1) * (j + 1) * (k + 1) <= kk) ans.push_back(a[i] + b[j] + c[k]);
        else break;
    }
  }
  sort(ans.begin(), ans.end(), greater<long long>());               
  for (int i = 0; i < kk; ++i) cout << ans[i] << '\n';
  return 0;
}

Measured memory_bytes: 1400
h,w,m=map(int,input().split())
d_h=[0]*(h+1)
d_w=[0]*(w+1)
d=[]
for i in range(m):
  nh,nw=map(int,input().split())
  d_h[nh]+=1
  d_w[nw]+=1
  d.append([nh,nw])
  
#print(d_h)
#print(d_w)

hantei=0
ans1=max(d_h)
memoh=set()
for i in range(1,h+1):
  hantei=d_h[i]
  if ans1==hantei:
    memoh.add(i)
    
hantei=0
ans2=max(d_w)
memow=set()
for j in range(1,w+1):
  hantei=d_w[j]
  if ans2 == hantei:
    memow.add(j)
ans = ans2+ans1-1
#print(memoh,memow)
count = len(memoh)*len(memow)
for hw in d:
  if hw[0] in memoh and hw[1] in memow:
    count-=1
if count>0:
  print(ans+1)
else:
  print(ans)


Measured memory_bytes: 216400
n=int(input())
A=list(map(int,input().split()))
odd=sum(A[::2])
even=sum(A[1::2])
rtemp=10**9+1
ltemp=-1
while rtemp-ltemp>1:
    mid=(rtemp+ltemp)//2
    if odd-even-mid<=mid:
        rtemp=mid 

    else:
        ltemp=mid

ans=rtemp
D=[]
for i in range(n-1):
    D.append(ans*2)
    ans=A[i]-ans
    
D.append(ans*2)
print(*D)

Measured memory_bytes: 14624
#include <bits/stdc++.h>
using namespace std;
long long  N,A,B;
long long value[51];
bool comp(long long a,long long b)
{
    return a>b?true:false;
}

long long dp[51][51];

void init()
{
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1; i<=50; i++)
    {
        dp[i][0]=1;
        for(int j=1; j<=i; j++)
            dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
    }
}
int main(void)
{
    cin>>N>>A>>B;
    init();
    for(int i=0; i<N; i++)
    {
        cin>>value[i];
    }
    sort(value,value+N,comp);
    double sum=0.0;
    for(int i=0; i<=A-1; i++)
    {
        sum+=value[i];
    }
    long long  num=0,k=0;
    for(int i=0; i<N; i++)
    {
        if(value[i]==value[A-1])
        {
            num++;
            if(i<A)
                k++;
        }
    }
    long long ans=0;
    if(k==A)//前A个相同,可以增加个数
    {
        for(int i=A; i<=B; i++)
            ans+=dp[num][i];
    }
    else
        ans+=dp[num][k];

    printf("%.15f\n",sum/A);
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, K, S;
    cin >> N >> K >> S;

    int max = 1000000000;
    rep(i, N) {
        if (i < K) cout << S;
        else {
            if (max == S) cout << max - 1;
            else cout << max;
        }
        if (i != N - 1) cout << " ";
    }
    return 0;
}

Measured memory_bytes: 1280
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N):
	tmp = list(map(int, input().split()))
	if tmp[1] == 0:
		continue
	E[tmp[0]] = tmp[2:]

cnt = [0 for _ in range(N+1)]
q = [1]

while q:
	cp = q.pop(0)
	for np in E[cp]:
		if cnt[np] != 0:
			continue
		
		cnt[np] = cnt[cp] + 1
		q.append(np)

for ind, cost in enumerate(cnt):
	if ind == 0:
		continue
	if ind == 1:
		print(ind, 0)
	else:
		if cost == 0:
			print(ind, -1)
		else:
			print(ind, cost)


Measured memory_bytes: 5628
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
  int N,P;
  string S;
  cin >> N >> P >> S;
  vector<long long> cnt(P,0);
  long long a=1,b=0;
  long long ans = 0;
  int inv = 1;
  int i,j;
  if(P == 2 || P == 5) {
    for(i=0;i<N;i++) {
      if((S[i]-'0')%P == 0)ans += i+1;
    }
  }
  else {
    for(i=0;i<P-2;i++)inv = (inv*10)%P;
    for(i=0;i<N;i++) {
      cnt[(a*(S[i]-'0')+b)%P]++;
      ans += cnt[b];
//      printf("%2d:%2lld:(%2lld,%2lld)",i,ans,a,b);
//      for(j=0;j<P;j++)printf(" %2lld",cnt[(a*j+b)%P]);
//      cout << endl;
      if(i<N-1) {
        a = (a*inv)%P;
        b = (b+P-a*(S[i+1]-'0')%P)%P;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
program beautiful_strings
  implicit none
  character(100) :: w
  integer        :: n, i, a(26), k
  read(*,*) w
  w = adjustl(w)
  n = len_trim(w)
  a = 0
  do i = 1, n
    k = ichar(w(i:i))-96
    a(k) = a(k) + 1
  end do
  do i = 1, 26
    if (mod(a(i),2).eq.0) cycle
    write(*,'(a)') "No"
    stop
  end do
  write(*,'(a)') "Yes"
  stop
end program beautiful_strings

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline ll read()
{
	long long f=1,sum=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-')	f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*f;
}
const int MAXN=310;
char s[MAXN][MAXN];
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%s",s[i]);
	int ans=0;
	for (int a=0;a<n;a++)
	{
		int b=0,i,j;
		bool flag=false;
		for (i=0;i<n && !flag;i++)
			for (j=0;j<n && !flag;j++)
			{
				int nx=(i+a)%n,ny=(j+b)%n;
				int x=ny,y=nx;
				x=(x-a+n)%n,y=(y-b+n)%n;
				if (s[i][j]!=s[x][y])
				{
					flag=true;
					break;
				}
			}
		if (i==n && j==n)
			ans++;
	}
	cout<<ans*n;
	return 0;
}


Measured memory_bytes: 384
def find(x):
    '''
    xの根を求める
    '''
    if par[x] < 0:
        return x
    else:
        p = find(par[x])
        diff_w[x] += diff_w[par[x]]
        par[x] = p
        return p


def weight(x):
    '''
    xの根からの距離を求める
    '''
    find(x)
    return diff_w[x]


def union(x, y, w):
    '''
    w[y] = w[x] + w となるようにxとyの属する集合を併合する
    '''
    w += weight(x) - weight(y)
    x = find(x)
    y = find(y)
    
    if x == y:
        return False

    if par[x] > par[y]:
        x, y = y, x
        w = -w
    par[x] += par[y]
    par[y] = x
    diff_w[y] = w
    return True


def same(x, y):
    '''
    xとyが同じ集合に属するかを判定する
    '''
    return find(x) == find(y)


def size(x):
    '''
    xが属する集合の個数を求める
    '''
    return -par[find(x)]


def diff(x, y):
    '''
    xとyが同じ集合に属するときの w[y] - w[x] を求める
    '''
    return weight(y) - weight(x)


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

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

for _ in range(m):
    l, r, d = map(int, input().split())

    if same(l-1, r-1):
        if diff(l-1, r-1) != d:
            print('No')
            exit()
    else:
        union(l-1, r-1, d)

print('Yes')

Measured memory_bytes: 85848
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)
 
int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};
 
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;
 
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
 
// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> n >> k;
 
  vector<P> vp;
  REP(i, n) {
    int t, d;
    cin >> t >> d;
    vp.push_back(P(d, t));
  }
 
  sort(vp.begin(), vp.end(), greater<P>());
 
  vector<bool> used(n + 1, false);
  priority_queue<int, vector<int>, greater<int>> que;
 
  ll kind = 0;
  ll sum = 0, ans = 0;
  REP(i, k) {
    sum += (ll)vp[i].first;
    if(!used[vp[i].second]) {
      used[vp[i].second] = true;
      kind++;
    } else {
      que.push(vp[i].first);
    }
  }
 
  ans = max(ans, kind * kind + sum);
  int j = k;
 
  while(!que.empty()) {
    sum -= que.top(); que.pop();
    while(j < n) {
      if(!used[vp[j].second]) {
        used[vp[j].second] = true;
        kind++;
        sum += (ll)vp[j].first;
        ans = max(ans, kind * kind + sum);
        break;
      }
      j++;
    }
    if(j >= n) break;
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 1528
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<u64>();
    let n = input[0];
    let a = input[1];
    let b = input[2];

    let blue = n / (a + b) * a + std::cmp::min(a, n % (a + b));
    println!("{}", blue);
}

Measured memory_bytes: 4352
from fractions import gcd

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    A = list(mi())
    ans = A[0]
    for i in range(N-1):
        ans = gcd(ans, A[i+1])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 86296
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>



using namespace std;

int dig(long long n){
	int c = 0;
	while(n > 0){
		n/=10;
		c++;
	}
	return c;
}

int F(long long a, long long b){
	return max(dig(a), dig(b));
}

int main(){
	long long N, M = 100;
	cin >> N;
	
	for(long long i = 1; i*i <= N; i++){
		if(N%i == 0){
			long long f = F(i,N/i);
			if(f < M) M = f;
		}
	}
	cout << M << endl;
}






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

typedef long long ll;

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int fact[N], ifact[N];

int inv(int a, int m) {
    if (a == 0) return 0;
    auto k = -inv(m%a,a);
    if (k < 0) k += a;
    return (ll(m)*k+1)/a;
}

int comb(int m, int n) {
    if (n < 0 || n > m) return 0;
    return (ll) fact[m] * ifact[n] % MOD * ifact[m-n] % MOD;
}


int main() {
    fact[0] = 1; 
    for (int n = 1; n < N; n++) fact[n] = ll(n) * fact[n-1] % MOD;
    ifact[N-1] = inv(fact[N-1], MOD);
    for (int n = N-2; n >= 0; n--) ifact[n] = ll(n+1) * ifact[n+1] % MOD;

    int n,k; scanf("%d %d", &n, &k);
    vector<int> a(n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a.begin(), a.end());

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (ll) a[i] * comb(i, k-1) % MOD;
        ans -= (ll) a[i] * comb(n-i-1, k-1) % MOD;
    }
    ans %= MOD; if (ans < 0) ans += MOD;
    printf("%d\n", (int) ans);

    return 0;
}


Measured memory_bytes: 1408
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, c, d ] <- readInts
	print $ solve b c d - solve ( pred a ) c d

solve ub c d = ub - ( ub `div` c ) - ( ub `div` d ) + ( ub `div` ( lcm c d ) )

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int dp[3000 + 10][3000 + 10][2];
// dp[i][j][k]
// i品目まで食べるのかを選んで，jの時間がかかったときの美味しさの最大値
// kが0のときは最後に食べるものをまだ選んでいない
// 1のときは最後に食べるものをもう選んでいる
int main() {
    int N, T;
    cin >> N >> T;
    vector<int> A(N), B(N);
    REP(i, N) { cin >> A[i] >> B[i]; }
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= T - 1; j++) {
            for(int k = 0; k < 2; k++) {
                dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
                if(j - A[i - 1] >= 0) {
                    // Aを入れることができる
                    dp[i][j][k] =
                        max(dp[i][j][k], dp[i - 1][j - A[i - 1]][k] + B[i - 1]);
                }
                if(k == 0) {
                    //これから最後にたべるものを選ぶ
                    dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][0] + B[i - 1]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= T - 1; i++) {
        for(int j = 0; j < 2; j++) {
            ans = max(ans, dp[N][i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000000
#define MOD 1000000007

void solve() {
    ll N, W, sV = 0;
    int ans = 0;
    cin >> N >> W;
    vll w(N), v(N);
    rep(i,0,N) {
        cin >> w[i] >> v[i];
        sV += v[i];
    }
    vll dp(sV+1, INF);
    //dp[i] ~ minimum weight for max i value
    dp[0] = 0;
    rep(i,0,N) {
        //dp[v[i]] = min(dp[v[i]], w[i]);
        per(j,0,sV-v[i]+1) {
            dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
        }
    }
    rep(i,0,sV+1) {
        if (dp[i] <= W) {
            ans = max(ans, i);
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;


int main()
{
  string S1234;
  cin >> S1234;

  string S12, S34;

  S12 = S1234.substr(0,2);
  S34 = S1234.substr(2);

  int num12 = atoi(S12.c_str());
  int num34 = atoi(S34.c_str());

  if( (num12 == 0 || num12 >= 13) && (num34 != 0 && num34 <= 12) ) cout << "YYMM";
  //else if( num12 >= 13 && num34 >= 13 ) cout << "NA";
  else if( (num12 > 0 && num12 <=12) && (num34 == 0 || num34 >= 13) ) cout << "MMYY";
  else if( (num12 >= 1 && num12 <= 12) && (num34 >= 1 && num34 <= 12) ) cout << "AMBIGUOUS";
  else cout << "NA";

  return 0;
}


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

typedef complex<double> P;
P a[3];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	for(int i=0; i<3; ++i){
		double x, y;
		cin >> x >> y;
		a[i] = P(x, y);
	}
	if(abs(a[1] - a[2]) > abs(a[1] - a[0]) && abs(a[1] - a[2]) > abs(a[0] - a[2])) swap(a[0], a[1]);
	for(int i=2; i>=0; --i)
		a[i] -= a[0];
	if(abs(a[1]) < abs(a[2])) swap(a[1], a[2]);
	double theta = arg(a[1]);
	theta *= -1.0;
	a[1] *= polar(1.0, theta);
	a[2] *= polar(1.0, theta);
	if(a[2].imag() < 0) a[2] = conj(a[2]);
/*	for(int i=0; i<3; ++i)
		cout << a[i].real() << " " << a[i].imag() << "\n";
*/	double b = arg(a[2]) / 2;
	double c = arg(conj(a[1] - a[2])) / 2;
//	cout << b << " " << c << "\n";
	double l = 0.0, r = 1e3;
	while(l + 1e-12 < r){
		double m = (l + r) / 2;
		double p = m / tan(b);
		double q = a[1].real() - m / tan(c);
		if(p + 2 * m - 1e-14 <= q) l = m;
		else r = m;
	}
	cout << setprecision(12) << l << "\n";
}

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<long> vec(N);
  for(int i=0;i<N;i++)
    cin>>vec.at(i);
  sort(vec.begin(),vec.end());
  long count=0;
  if(N>K){
  	for(int i=0;i<N-K;i++)
      count+=vec.at(i);
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1792
n, d = gets.chomp.split.map(&:to_i)
a, b = n.times.map{gets.split.map(&:to_i)}.transpose

cnt = 0
for i in 0..n-1
    if (a[i])**2 + (b[i])**2 <= d**2
        cnt = cnt + 1
    end
end
puts cnt

Measured memory_bytes: 31268
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 100010, mod = 1e9 + 7;
int n, tot, head[maxn];
ll dp[maxn][2];
struct Edge {
    int to, nxt;
} edge[maxn * 2];

void add(int u, int v) {
    edge[++tot].to = v, edge[tot].nxt = head[u], head[u] = tot;
}

ll DP(int u, int msk, int fa) {
    if(~dp[u][msk]) return dp[u][msk];
    ll ret = 1;
    for(int i = head[u]; i; i = edge[i].nxt) if(edge[i].to != fa) {
        int v = edge[i].to;
        if(msk == 0) ret = ret * (DP(v, 0, u) + DP(v, 1, u)) % mod;
        else ret = ret * DP(v, 0, u) % mod;
    }
    return dp[u][msk] = ret;
}

int main()
{
    memset(dp, -1, sizeof(dp));
    read(n);
    int u, v;
    rep(i, 1, n - 1) {
        read(u), read(v);
        add(u, v), add(v, u);
    }
    DP(1, 0, 0);
    DP(1, 1, 0);
    printf("%lld\n", (dp[1][0] + dp[1][1]) % mod);
    return 0;
}

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

const int MAX = 1e6+10;
int powtwo[MAX];
bool even[MAX];

void create(){
  int two = 2;
  while(two < MAX){
    for(int i=1; i<MAX; i++){
      if(i %two == 0){
        powtwo[i]++;
      }
    }
    two *= 2;
  }
}

void make_even(int n){
  int bunshi = 0;
  int bunbo = 0;
  for(int i=0; i<=n; i++){
    bunshi += powtwo[n-i];
    bunbo += powtwo[i+1];
    if(bunshi > bunbo){
      even[i+1] = true;
    }
  }
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    vec[i] = S[i] - '0';
  }
  
  bool one = false;
  
  vector<int> next(N-1);
  for(int i=0; i<N-1; i++){
    next[i] = abs(vec[i] - vec[i+1]);
    if(next[i] == 1){
      one = true;
    }
  }
  
  create();
  make_even(N-2);
  
  if(!one){
    for(int i=0; i<N-1; i++){
      if(next[i] == 2){
        next[i] = 1;
      }
    }
  }
  
  int ans = 0;
  for(int i=0; i<N-1; i++){
    //パスカルの三角形n-2Ciをかける
    int x = 0;
    if(!even[i]){
      x = 1;
    }
    ans ^= ((next[i]%2) * x);
  }
  if(!one && ans == 1){
    cout << 2 << endl;
  }
  else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 17104
#include <stdio.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	
	if(n < 1200){
		printf("ABC");
	}
	else if(n < 2800){
		printf("ARC");
	}
	else{
		printf("AGC");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
	string s;
	cin >> s;
	for(int i =0;i!=s.size();i++){
		if(s[i]==s[i+1]){
			cout << i+1 << " " << i+2<<endl;
			return 0;
		}
		if(s[i]==s[i+2]){
			cout<< i+1 << " "<< i+3 << endl;
			return 0 ;
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  
  if (L > R)
    cout << "Left" << endl;
  else if (L == R)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
 
}

Measured memory_bytes: 256
# after YouTube editorial
n,k = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
l = 0
r = a.max
while r - l > 1
  x = (l+r)/2
  y = 0
  a.each do |e|
    y += (e+x-1)/x-1 if e > x
  end
  if y > k
    l = x
  else
    r = x
  end
end
p r


Measured memory_bytes: 29888
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int i;
    int tenbou_num, road_num;
    int* height;
    int cnt = 0;
    int* good;
    int a,b;

    scanf("%d %d", &tenbou_num, &road_num);
    height = (int*)calloc(tenbou_num, sizeof(int));
    good = (int*)calloc(tenbou_num, sizeof(int));
    
    for(i=0;i<tenbou_num;i++){
        scanf("%d", height+i);
    }

    for(i=0;i<road_num;i++){
        scanf("%d %d", &a, &b);
        if(height[a-1] <= height[b-1]) good[a-1] = 1;
        if(height[a-1] >= height[b-1]) good[b-1] = 1;
        
    }

    for(i=0;i<tenbou_num;i++){
        if(good[i] == 0)cnt++;
    }
    printf("%d", cnt);
    return 0;
}

Measured memory_bytes: 2476
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  vector<double> poRL;
  vector<double> poLR;
  rep_i(i, s.length() - 1){
    if(s[i] == 'R' && s[i + 1] == 'L'){
      poRL.push_back(i);
    }
  }
  rep_i(i, s.length() - 1){
    if(s[i] == 'L' && s[i + 1] == 'R'){
      poLR.push_back(i);
    }
  }
  vector<int> ans(s.length());
  if(poLR.empty()){
    // R
    ans[int(poRL[0])] = round((poRL[0] + 1)/2) + int(s.length() - poRL[0] - 1)/2;
    // L
    ans[int(poRL[0]+1)] = (int(poRL[0] + 1) - round((poRL[0] + 1)/2)) + (int(s.length() - poRL[0] - 1) - int(s.length() - poRL[0] - 1)/2);
    debug_vi(ans);
    cout << endl;
  }else{
    for (int i = 0; i < poRL.size(); i++){
      if(i == 0){
        // R
        ans[int(poRL[i])] = round((poRL[i] + 1)/2) + int(poLR[0] - poRL[0])/2;
        // L
        ans[int(poRL[i]+1)] = (int(poRL[i] + 1) - round((poRL[i] + 1)/2)) + (int(poLR[0] - poRL[0]) - int(poLR[0] - poRL[0])/2);
      }else if(i == poRL.size() - 1){
        // L
        ans[int(poRL[i] + 1)] = round((s.length() - (poRL[i] + 1))/2) + int(poRL[i] - poLR[i - 1])/2;
        // R
        ans[int(poRL[i])] = ((s.length() - int(poRL[i] + 1)) - round((s.length() - (poRL[i] + 1))/2)) + (int(poRL[i] - poLR[i - 1]) - int(poRL[i] - poLR[i - 1])/2);
      }else{
        // R
        // if(i == 1){
        //   cout << round((poRL[i] - poLR[i - 1])/2) << endl;
        //   cout << int(poLR[i] - poRL[i])/2 << endl;
        // }
        ans[int(poRL[i])] = round((poRL[i] - poLR[i - 1])/2) + int(poLR[i] - poRL[i])/2;
        // L
        ans[int(poRL[i] + 1)] = (int(poRL[i] - poLR[i - 1]) - round((poRL[i] - poLR[i - 1])/2)) + (int(poLR[i] - poRL[i]) - int(poLR[i] - poRL[i])/2);
      }
    }
    debug_vi(ans);
    cout << endl;
  }
}

Measured memory_bytes: 1864
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt(),s=sc.nextInt(),a=0;
		for(int x=0;x<=k;x++){
			for(int y=0;y<=k;y++){
				int z=s-x-y;
				if(z>=0&&z<=k)a++;
			}
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<queue>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7;

int main()
{
    int ans=0;
    int a[3];
    bool vis[110];
    memset(vis,0,sizeof(vis));
    for(int i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
        if(!vis[a[i]])
        {
            ans++;
            vis[a[i]]=1;
        }
    }
    printf("%d\n",ans);
    return 0;
}










Measured memory_bytes: 384
import java.io.*;
import java.util.*;
//import java.util.stream.*;;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        char ch[] = br.readLine().toCharArray();
        int array[] = new int[26];
        String s = "Yes";
        for (int i = 0; i < ch.length; i++) {
            array[ch[i] - 97]++;
        }
        for (int i = 0; i < 26; i++) {
            if (array[i] % 2 != 0 && array[i] != 0) {
                s = "No";
                break;
            }
        }
        System.out.println(s);
        bw.flush();
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

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

    double th_h = (360.0 / 12.0 * h + 30.0 / 60.0 * m) * (M_PI / 180.0);
    double th_m = (360.0 / 60.0 * m) * (M_PI / 180.0);

    double h_x = a * cos(th_h);
    double h_y = a * sin(th_h);
    double m_x = b * cos(th_m);
    double m_y = b * sin(th_m);

    double dx = h_x - m_x;
    double dy = h_y - m_y;

    double ans = sqrt(dx * dx + dy * dy);

    printf("%.20f\n", ans);
}

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

int main(){
  string s,t;
  string ans = "No";
  cin >> s >> t;
  t = t.erase(t.size()-1);
  if (s == t)
    ans = "Yes";
  cout << ans << endl;
}

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

int main() {
    int n, min = 0, profit = 0, prev = 0, save = -INT_MAX;
    cin >> n;
    while(n--){
        int d;
        cin >> d;
        if(!min) min = d;
        min = d < min ? d : min;
        profit = profit > d - min ? profit : d - min;
        
        if(prev){
            save = save > d - prev  ? save : d - prev;
        }
        prev = d;
        
    }
    cout << (!profit ? save : profit) << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {

    int n;
    int L[100];

    cin >> n;

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

    sort(L ,L + n);

    int max = L[n -1];

    int sum = 0;

    for (int i = 0; i < n - 1; i++) {
        sum+=L[i];
    }

    if ( max < sum ) {

    cout << "Yes" << endl;

    }else{

    cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

template<typename T=ll>
ll djkstra(vector<map<ll, T>> &g, ll src, ll dst, function<bool(const T&, const T&)> comp=greater<T>()){
    auto c = [&comp](pair<T, ll> l, pair<T, ll> r){ return comp(l.first, r.first); };
    priority_queue<pair<T, ll>, vector<pair<T, ll>>, decltype(c)> q(c);
    vector<T> s(g.size(), -1);
    q.push({0, src});
    while(!q.empty()){
        auto e = q.top();
        q.pop();
        ll d = e.first;
        ll n = e.second;
        if(s[n]>=0) continue;
        s[n] = d;
        if(n==dst) break;
        for(auto it=g[n].begin(); it!=g[n].end(); ++it){
            if(s[it->first]>=0 || it->second<0) continue;
            q.push({d+it->second, it->first});
        }
    }
    return s[dst];
}

int main(){
    ll n, m;
    cin >> n >> m;
    vector<map<ll, ll>> lrc(n);
    rep(i, m){
        ll l, r, c;
        cin >> l >> r >> c;
        if(lrc[l-1].find(r-1) != lrc[l-1].end()){
            lrc[l-1][r-1] = min(lrc[l-1][r-1], c);
        }
        else lrc[l-1][r-1] = c;
    }
    rep(i, n-1) lrc[i+1][i] = 0;
    
    ll a = djkstra(lrc, 0, n-1);
    cout << a << endl;
}


Measured memory_bytes: 18936
N, M = map(int, input().split())

kmax = M // N
sqrt = int(M**0.5)

k = 0
for i in range(sqrt)[::-1]:
    k1, k2 = i+1, M//(i+1)
    if M % k2 == 0 and k2 <= kmax:
        k = max(k, k2)
    elif M % k1 == 0 and k1 <= kmax:
        k = max(k, k1)

print(k)

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

int main() {
    string s;
    ll k;
    std::cin >> s;
    std::cin >> k;
    ll n = s.length();

    char now = s[0];
    ll conc = 1;
    ll res1 = 0;
    for (int i = 1; i < n; i++) {
        if(now == s[i%n]){
            conc++;
        }else{
            res1 += conc/2;
            conc = 1;
            now = s[i%n];
        }
    }

    if(conc == n){
        std::cout << n*k/2 << std::endl;
        return 0;
    }
    res1 += conc/2;

    conc = 1;
    ll res2 = 0;
    now = s[0];
    for (int i = 1; i < 2*n; i++) {
        if(now == s[i%n]){
            conc++;
        }else{
            res2 += conc/2;
            conc=1;
            now = s[i%n];
        }
    }
    res2 += conc/2;

    std::cout << res1+(res2-res1)*(k-1) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  cout << setprecision(12);

  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double p = asin(1) * 2;

  double t1 = (h * 60 + m) / 720 * (2 * p);
  double t2 = m / 60 * (2 * p);

  double x1 = a * cos(t1);
  double y1 = a * sin(t1);
  double x2 = b * cos(t2);
  double y2 = b * sin(t2);

  cout << hypot(x1 - x2, y1 - y2) << ln;

  return 0;
}

Measured memory_bytes: 4116
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define p 1000000007
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, k, f[MAXN], a[MAXN], sum[MAXN];

int main()
{
	scanf("%d%d", &n, &k);
	for(rint i=1; i<=n; ++i) scanf("%d", &a[i]);
	for(rint i=0; i<=k; ++i) sum[i]=1;
	for(rint i=1; i<=n; ++i)
	{
		for(rint j=0; j<=a[i]; ++j) f[j]=sum[j]; 
		for(rint j=a[i]+1; j<=k; ++j) f[j]=(sum[j]-sum[j-a[i]-1]+p)%p;
		sum[0]=f[0];
		for(rint j=1; j<=k; ++j) sum[j]=(sum[j-1]+f[j])%p;
	}
	printf("%d\n", f[k]);
	return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 101;
int n, x[N];

int main()
{
  fastio;
  cin >> n;
  for (int i = 1; i <= n; i++){
    cin >> x[i];
  }
  int res = INF;
  for (int p = 1; p <= 100; p++){
    int cur = 0;
    for (int i = 1; i <= n; i++){
      cur += (x[i] - p) * (x[i] - p);
    }
    res = min(res, cur);
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
typedef long long LL;
int A[20],n;
LL f(int l,int r,int x,int y){
	if(r-l<=1)return 0;
	LL p=1e18;
	for(int i=l+1;i<r;++i)
	p=std::min(p,f(l,i,x,x+y)+f(i,r,x+y,y)+(LL)(x+y)*A[i]);
	return p;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)scanf("%d",A+i);
	printf("%lld",f(0,n-1,1,1)+*A+A[n-1]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
int main()
{
	std::stack<double> s;
	double a,b;
	char c[80],d;
	while (std::cin>>c)
	{
		if (c[0]=='+')
		{
			b=s.top(),s.pop();
			a=s.top(),s.pop();
			s.push(a+b);
		}
		else if (c[0]=='-'&&c[1]==0)
		{
			b=s.top(),s.pop();
			a=s.top(),s.pop();
			s.push(a-b);
		}
		else if (c[0]=='*')
		{
			b=s.top(),s.pop();
			a=s.top(),s.pop();
			s.push(a*b);
		}
		else if (c[0]=='/')
		{
			b=s.top(),s.pop();
			a=s.top(),s.pop();
			s.push(a/b);
		}
		else	s.push(atof(c));
		if ((d=getchar()) == '\n')	printf("%.6f\n",s.top());
		if (d==-1)	break;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define N_MAX 100005

using namespace std;
typedef long long ll;

int main(){
	ll N;
  	cin >> N;
  	ll A[N];
  	ll n1;
  	ll n2;
	for(int i = 0; i < N; i++){
    	cin >> A[i];
      	if(i == 0){
        	n1 = A[i];
          	n2 = 0;
        } else {
            if(n1 >= A[i] && A[i] > n2) n2 = A[i];
            if(A[i] > n1) n1 =A[i];
        }
    }
  	for(int i = 0; i < N; i++){
    	if(A[i] == n1) cout << n2 << endl;
      	else cout << n1 << endl;
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    ll a = 1, b = 1;
    REP(i, n){
        ll x, y;
        cin >> x >> y;
        ll m = max((a + x - 1) / x, (b + y - 1) / y);
        a = x * m;
        b = y * m;
    }
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int N,K,num[5000]={0},P[5000],C[5000],pre,n=1,s,preK;
	long long int maxC,maxL,ans;
	vector<long long int> vec[5000];
	cin>>N>>K;
	for(int i=0;i<N;i++){cin>>P[i];P[i]--;}
	for(int i=0;i<N;i++)cin>>C[i];
	for(int i=0;i<N;i++){
		if(num[i]>0)continue;
		num[i]=n;
		vec[n].push_back(C[i]);
		pre=P[i];
		while(pre!=i){
			num[pre]=n;
			vec[n].push_back(C[pre]);
			pre=P[pre];
		}
		n++;
	}
	ans=C[0];
	preK=K;
	for(int i=1;i<n;i++){
		s=vec[i].size();
		if(s==0)continue;
		for(int j=0;j<s;j++)vec[i].push_back(vec[i][j]);
		for(int j=0;j<s;j++)vec[i].push_back(vec[i][j]);
		for(int j=1;j<vec[i].size();j++)vec[i][j]+=vec[i][j-1];
		K=preK;
		maxC=vec[i][s-1]*(K/s);
		K%=s;
		if(maxC<0){
			maxC=0;
			K=s-1;
		}else if(maxC>0){
			maxC-=vec[i][s-1];
			K+=s;
		}
		if(K>0){
			maxL=vec[i][0];
			s=vec[i].size();
			for(int j=0;j<s;j++){
				for(int k=j;(k<j+K)&&(k<s);k++){
					if((vec[i][k]-(j>0?vec[i][j-1]:0))>maxL){
						maxL=vec[i][k]-(j>0?vec[i][j-1]:0);
					}
				}
			}
			maxC+=maxL;
		}
		if(maxC>ans)ans=maxC;
	}
	cout<<ans;
	return 0;
}

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

int N;

int a[101];

int main(void) {

	cin >> N;

	int tmp;

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

	int ans = 1000003;

	for (int i = -100; i <= 100; i++) {
		int sum = 0;
		for (int j = 1; j <= N; j++) {
			sum += (a[j] - i)*(a[j] - i);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll x;
  cin>>x;
  cout<<x/2*((x+1)/2);

}


Measured memory_bytes: 256
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  a, b = map(int, readline().split())
  print((a-1)*(b-1))
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5248
N,M=map(int,input().split())
X=list(map(int,input().split()))
Y=[]

if N>=M:
    print(0)
else:
    X.sort()
    for i in range(M-1):
        Y.append(X[i+1]-X[i])
    Y.sort()
    if N==1:
        print(sum(Y))
    else:
        print(sum(Y[:1-N]))

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(0);
    int k; cin >> k;
    int now = 7%k;
    for (int i=1;i<=1e6;i++) {
        if (now==0) {
            cout << i << endl;
            return 0;
        }
        now = (now*10+7)%k;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3616
n,m,c=gets.chomp.split(" ").map{|a| a.to_i}
b=gets.chomp.split(" ").map{|a| a.to_i}
a=[]
n.times do
  a.push(gets.chomp.split(" ").map{|a| a.to_i})
end
count=0
0.upto(n-1) do |i|
  total=0
  0.upto(m-1) do |j|
    total+=b[j]*a[i][j]
  end
  count+=1 if total+c>0
end
puts count

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

int main() {
  int N;
  cin >> N;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) return cout << "Yes" << "\n", 0;
    }
  }
  cout << "No" << "\n";
}

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


using namespace std;

const int MOD = 1000000007;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> a(N + 1, 0);
	for(int i = 0; i < M; i++) {
		int x;
		cin >> x;
		a[x] = 1;
	}
	vector<int> ptn(N+1, 0);
	ptn[0] = 1;
	if(a[1] != 1) ptn[1] = 1;
	for(int i = 2; i <= N; i++) {
		if(a[i] == 1) continue;
		ptn[i] = ptn[i - 1] + ptn[i - 2];
		ptn[i] %= MOD;
	}

	cout << ptn[N] << endl;
}


Measured memory_bytes: 1024
import copy
from scipy.sparse.csgraph import floyd_warshall as wf

N, M = map(int, input().split())
INF = float('inf')

d = [[INF] * (N) for i in range(N)]
e_list = []
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
    e_list.append([a - 1, b - 1, c])
    
wf = wf(d)

cnt = M
for a, b, c in e_list:
    for i in range(N):
        if wf[i][a] + c == wf[i][b]:
            cnt -= 1
            break
    
print(cnt)

Measured memory_bytes: 26580
mod = 998244353
n, m, k = map(int, input().split())

class Combination:
    def __init__(self, n, mod):
        self.mod = mod

        # self.fac[i] ≡ i! (factorial:階乗)
        l = [1]
        num = 1
        for i in range(1, n+1):
            num *= i
            num %= mod
            l.append(num)
        self.fac = l.copy()

        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        num = pow(num, mod-2, mod)
        l = [1 for i in range(n+1)]
        l[n] = num
        for i in range(n-1, 0, -1):
            num *= i + 1
            num %= mod
            l[i] = num
        self.rec = l.copy()

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod

c = Combination(n - 1, mod)
ans = 0
for i in range(k+1):
    ans += c.comb(n-1, i) * pow(m-1, n-i-1, mod) * m
    ans %= mod

print(ans)

Measured memory_bytes: 95976
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j += a[i]) {
				x++;
			}
		}
		System.out.println(x);

	}

}


Measured memory_bytes: 21844
N = int(input())
MOD = 10**9 + 7
base = 1
aorb = 2

for i in range(N):
    base = (base * 10) % MOD
    aorb = (aorb * 9) % MOD
aandb = 1
for i in range(N):
    aandb = (aandb * 8) % MOD
ans = (base - (aorb - aandb)) % MOD

print(ans)

Measured memory_bytes: 63784
#include<iostream>
#include<stdio.h>
using namespace std;

bool p[1000010];
int input;

void erato(){
	fill(p, p+1000010, true);
	p[0] = p[1] = false;

	for(int i=0; i * i < 1000010; i++){
		if(!p[i]) continue;

		for(int j = i + i; j < 1000010; j += i){
			p[j] = false;
		}
	}
}

int main(){
	erato();
	int input;

	while(scanf("%d", &input) != EOF){
		int ans = 0;
		for(int i=0; i <= input; i++){
			if(p[i]) ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2184
import java.lang.*;
import java.util.*;

public class Main
{
    static Scanner sc = new Scanner(System.in);

    public static void main(String args[])
    {
        while(true){
            int m = sc.nextInt();
            if(m == 0) break;
            
            int[] v = new int[m+1];
            int[] n = new int[m+1];
            for(int i=0; i<m;i++){
                v[i] = sc.nextInt();
                n[i] = sc.nextInt();
            }
            
            int[] dp = new int[1001];
            dp[0] = 1;
            
            for(int i=0; i<m; i++){
                for(int j=1000; j>=0; j--){
                    for(int k=1; k<=n[i]; k++){
                        if(j + k*v[i] <= 1000) dp[j + k*v[i]] += dp[j];
                    }
                }
            }
            int c = sc.nextInt();
            for(int i=0; i<c; i++){
                System.out.println(dp[sc.nextInt()]);         
            }
        }
    }
    
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vvi = vector< vector<int> >;
using vi = vector<int>;
using vvb = vector< vector<bool> >;
using vb = vector<bool> ;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define ar array
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) ((long long)x.size())


const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){


}


void solve(){    
    ll n;
    cin >> n;
    ll a[n+1];
    for(ll i=1;i<n+1;i++){
        cin >> a[i];
    }
    string s;
    cin >> s;
    s = " " + s;
    vll tmp;
    for(ll i=n;i>=1;i--){

        ll x = a[i];
        for(auto it : tmp){
            x = min(x,x^it);
        }
        if(x==0)
            continue;
        if(s[i] == '0'){
            tmp.pb(x);
        }else{
            cout << 1 << endl;
            return;
        }
    }
    cout << 0 << endl;

}

int main(){
    
    IOS;
    pre();
    ll T = 1;
    cin >> T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    int maxi = 0;
    int sum = 0;
    rep(i,N)
    {
        cin >> v[i];
        sum += v[i];
        if(v[i] > maxi)
        {
            maxi = v[i];
        }
    }
    cout << (sum - maxi + (maxi / 2));
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	int n;
	cin>>n;
	cin.ignore();
	rep(i,n){
		getline(cin,s);
		int size=s.size();
		rep(j,size-6){
			string point=s.substr(j,7);
			if(point=="Hoshino"){
				point="Hoshina";
				s.replace(j,7,point);
			}
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])

if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1]))


Measured memory_bytes: 25252
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,m,a,i,j,x,y=0,mn=9999999;
    cin>>n;

    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if(a<=mn)
        {
            mn=a; y++;
        }
    }

    cout<<y<<endl;

    return 0;
}


Measured memory_bytes: 256