akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000000005LL
#define MOD 1000000007

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

ll a,b,c,x,y,d,n;

int main(){

  cin >> a>> b >> c >> x >> y;
  d = c*2;
  n= INF;

  rep(i,0,x+1){
    ll j = (ll)i;
    n = min(n, a*j+d*(x-j)+b*max(0LL,y-(x-j)));
  }

  swap(a,b);
  swap(x,y);

  rep(i,0,x+1){
    ll j = (ll)i;
    n = min(n, a*j+d*(x-j)+b*max(0LL,y-(x-j)));
  }
  cout << n << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int n, k;
    while(cin >> n >> k) {
        if(n == 0) break;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];

        vector<int> cs(n+1, 0);
        for(int i = 1; i < n+1; i++) {
            cs[i] = cs[i-1];
            cs[i] += a[i-1];
        }

        int ans = (-1) * INF;
        for(int i = 0; i < n+1-k; i++) {
            ans = max(ans, cs[i+k] - cs[i]);
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 3644
//Number 1209

#include <stdio.h>
#define MAX 300

int main(void)
{
  int n, i, j;
  int coin[18];
  int count[MAX+1] = {0};
      
  for(i=1; i<18; i++)   //square coin
    coin[i] = i*i;
  
  count[0] = 1;
  
  for(i=1; i<18; i++)
    {
      for(j=coin[i]; j<MAX+1; j++)
	{
	  count[j] += count[j-coin[i]];
	}
    }

  while(1)
    {
      scanf("%d", &n);
      if(n==0)
	break;
      
      printf("%d\n", count[n]);
    }

  return 0;
}

  

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R) >> 1)
using namespace std;
const int MAXN = 200100;
const int mod = 998244353;
typedef long long LL;
typedef pair<int, int> PII;
int n;
bool check(int m) { return 1LL * m * (m + 1) >= n + n; }
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d", &n);
	int L = 0, R = n;
	while (R - L > 1) {
		// cout << L << " " << R << endl;
		if (check(mid)) {
			R = mid;
		} else {
			L = mid;
		}
	}
	printf("%d\n", R);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class a{
    public static void Main(){
        string str = Console.ReadLine();
        int ans;
        if(str == "RRR"){
            ans = 3;
        }
        else if(str == "RRS" || str == "SRR"){
            ans = 2;
        }
        else if(str == "SSS"){
            ans = 0;
        }
        else{
            ans = 1;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 17592
#include <cstdio>
#define max(a,b)((a)>(b)?(a):(b))
int const maxn = 101;
int g[3][maxn];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&g[1][i]);
	for(int i=1;i<=n;++i) scanf("%d",&g[2][i]);
	for(int i=1;i<=2;++i) {
		for(int j=1;j<=n;++j) {
			g[i][j]+=max(g[i-1][j],g[i][j-1]);
		}
	}
	printf("%d\n",g[2][n]);
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/python3

M = 1000000007

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

c = ((6 * n - 6 * k + 12 + 3 * (n + 1) * (k + n + 1) * (n - k + 2) - (n + 1) * (n + 2) * (2 * n + 3) + k * (k - 1) * (2 * k - 1)) // 6) % M

print(c)


Measured memory_bytes: 9160
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	cout<<n*(n+1)/2;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int long long N;
  cin >> N;
  int long long cnt = 1;
  int long long sum = 0;

  while (true)
  { 
    if(cnt%3!=0 && cnt%5!=0){
      sum += cnt;
    }
    
    if(cnt==N){
      break;
    }
    cnt++;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int row=in.nextInt();
        int col=in.nextInt();
        int n[][]=new int[row][col];
        int sum[]=new int [row+1];
        int sum2[]=new int[col+1];
        int sum_R=0,sum_C=0;
        for (int i = 0; i <row; i++) {
            for (int j = 0; j < col; j++) {
                n[i][j]=in.nextInt();
                sum[i]=sum[i]+n[i][j];
         //       System.out.println("j= "+j);
                sum2[j]=sum2[j]+n[i][j];
            }
        }
       // System.out.print("Row: ");
        /*for (int i = 0; i <row; i++) {
            sum_R=sum_R+sum[i];
            System.out.print(sum[i]+" ");
        }*/
       // System.out.println("");
        //System.out.print("Col: ");
        for (int i = 0; i <col; i++) {
            sum_C=sum_C+sum2[i];
         //   System.out.print(sum2[i]+" ");
        }
        //System.out.println("");
       // System.out.println(sum_R);
       // System.out.println(sum_C);
        
        for (int i = 0; i <row; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(n[i][j]+" ");
            }
            System.out.print(sum[i]);
            System.out.println("");
        }
        for (int i = 0; i < col; i++) {
            System.out.print(sum2[i]+" ");
        }
        System.out.print(sum_C);
        System.out.println("");
    }
}


Measured memory_bytes: 42164
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
H = rl()

ans = 0
cnt = 0
prev = H[0]
for i in range(1,N):
    if H[i] <= prev:
        cnt += 1
        ans = max(cnt, ans)
    else:
        cnt = 0
    prev = H[i]
print(ans)

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

using namespace std;

int main(){
    int k;cin>>k;
    long long val=7;
    val=val%k;
    for(int i=1;i<=k;i++){
        if(val==0){
            cout << i <<endl;
            return 0;
        }
        val=(val*10+7)%k;
    }
    cout <<-1<<endl;
}


Measured memory_bytes: 3648
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
      	int K = Integer.parseInt(sc.next());
      	int X = Integer.parseInt(sc.next());
      
      	if (500 * K >= X) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
main = do
  li <- getLine
  let x = read li
  let (a,b) = compute x
  putStrLn (show a ++ " " ++ show b)

{-
a5 < x のうちは、これに足してxに達するためのマイナスなbを
a5 = x なら b = 0 でいい
a5 > x のときは、ここから引いてxに合わせるためのプラスなbを
探す
-}

frt :: Int -> [Int]
frt n5
  | n^5 == n5 = [n]
  | otherwise = []
 where n = floor ((fromIntegral n5) ** 0.2)

compute :: Int -> (Int,Int)
compute x =  head [ (a,b) | a <- [1..], b <- sub x a ]

sub :: Int -> Int -> [Int]
sub x a = let a5 = a^5 in case compare a5 x of
  EQ -> [0]
  LT -> map negate $ frt (x-a5)
  GT -> frt (a5-x)

Measured memory_bytes: 4332
N, M = [int(t) for t in input().split()]
a = [[0]*2 for i in range(M)]  # 始点と距離
for i in range(M):
    s, e = [int(t) for t in input().split()]
    a[i][0] = s - 1
    a[i][1] = e - 1

b = sorted(a, key=lambda x: x[1])

count = 1
flag = b[0][1]
for i in range(1, M):
    if b[i][0] < flag:
        continue
    elif b[i][1] > flag:
        flag = b[i][1]
        count += 1

print(count)


Measured memory_bytes: 22056
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



#define MAX_N 100000
int prime[MAX_N];//i番目の素数
bool is_prime[MAX_N + 1];
int min_factor[MAX_N + 1];//最小の素因数
int sieve(int n) {
	int p = 0;
	memset(is_prime, true, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	min_factor[0] = 0;
	min_factor[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			min_factor[i] = i;
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
				if (min_factor[j] == 0)min_factor[j] = i;
			}
		}
	}
	return p;
}



int np;
vector<pair<long long, int> > prime_factor(long long n) {
	vector<pair<long long, int> > res;
	rep(i,np) {
		if (n == 1)break;
		int num = 0;
		while (n%prime[i]==0) {
			n /= prime[i];
			num++;
		}
		if(num%3)res.push_back(make_pair(prime[i], num%3));
	}
	if (n > 1) {
		long long s = sqrt(n) + 1e-1;
		if(s*s==n && is_prime[s])res.push_back(make_pair(s, 2));
		else res.push_back(make_pair(n, 1));
	}
	return res;
}


vector<pair<long long, int>> pf[100000];



long long f(vector<pair<long long, int>> v) {
	long long res = 1;
	for (auto p : v) {
		rep(i,p.second) {
			res *= p.first;
		}
	}
	return res;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	np = sieve(2200);
	sieve(MAX_N);


	int n;
	cin >> n;
	map<long long, int> cnt;
	map<long long, long long> pa;
	rep(i,n) {
		long long s;
		cin >> s;
		auto pf = prime_factor(s);
		auto paf = pf;
		for (auto &p : paf)p.second = (3 - p.second) % 3;
		long long a = f(pf), b=f(paf);
		++cnt[a];
		pa[a] = b;
	}
	int ans = 0;
	for (auto p : cnt) {
		long long a = p.first, b = pa[a];
		int c = cnt.find(b)==cnt.end()? 0:cnt[b];
		if (a == 1) {
			ans++;
		}
		else if (p.second > c) {
			ans += p.second;
		}
		else if (p.second == c && a<b) {
			ans += p.second;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
//xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = 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 (b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  vi check(n-1);
  rep(i,n-1) check[i] = a[i+1]-a[i];
  vector<bool> increase;
  rep(i,n-1){
    if(check[i] != 0){
      increase.push_back(0 < check[i]);
    }
  }
  int ans = 1;
  for(int i = 1; i < increase.size(); i++){
    if(increase[i-1] != increase[i]){
      ans++;
      i++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 1024
ans1=[0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852]
ans2=[1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

ans=ans1+ans2
print(ans[int(input())])



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

struct edge{
    int to;
    long long cost;
};

long long dist[100005];

typedef vector<vector<edge> > Graph;
Graph graph;

void dfs(int v, int p, long long cost){
    dist[v] = cost;
    for(int i=0; i<graph[v].size(); i++){
        edge e = graph[v][i];
        if(e.to == p){
            continue;
        }
        dfs(e.to, v, cost+e.cost);
    }
}
int main(void){
    int n;
    cin >> n;
    graph = Graph(2*n);
    for(int i=0; i<n-1; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back((edge){b,c});
        graph[b].push_back((edge){a,c});
    }

    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1, 0);
    for(int i=0; i<q; i++){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 16640
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

point = []
for i in range(len(A)):
    ryori = A[i]
    point.append(B[ryori - 1])
    if i >  0 :
        if ryori - A[i - 1] == 1:
            point.append(C[ryori - 2])
    

print(sum(point))

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

int n;
int dst[100][100];

int v[100];
int c[100];
int M = 1001001001;


int dijkstra(int a){
	for(int i=0; i<100; i++){
		v[i] = M;
		c[i] = 0;
	}
	int t[100];
	t[0] = a;
	v[a] = 0;
	int ns = 0, nn = 1;
	while(nn>0){
		int mn = M;
		int mnx = 0;
		for(int i=ns; i<ns+nn; i++){
			if(v[t[i]]<mn){
				mn = v[t[i]];
				mnx = i;
			}
		}
		int tmp = t[ns];
		t[ns] = t[mnx];
		t[mnx] = tmp;
		int x = t[ns];
		ns++;
		nn--;

		c[x] = 1;
		for(int i=0; i<n; i++){
			if(dst[x][i]<M && c[i]==0){
				if(v[x]+dst[x][i] < v[i]){
					v[i] = v[x]+dst[x][i];
					t[ns+nn] = i;
					nn++;
				}
			}
		}


	}
}

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

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			dst[i][j] = M;
		}
	}

	for(int i=0; i<m; i++){
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		dst[a-1][b-1] = c;
		dst[b-1][a-1] = d;
	}
	int x1, x2, y1, y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	int ans = 0;
	dijkstra(x1-1);
	ans += v[x2-1];
	dijkstra(x2-1);
	ans += v[x1-1];
	cout << y1 - y2 - ans << endl;
	return 0;
}

Measured memory_bytes: 1248
#include<stdio.h>

int c, a, b[20];
int n, m, ans, i, j;
int now;

int main(){
	scanf("%d%d%d", &n, &m, &c);
	for(i=0; i<m; i++){
		scanf("%d", b+i);
	}
	for(j=0; j<n; j++){
		now = c;
		for(i=0; i<m; i++){
			scanf("%d", &a);
			now += a * b[i];
		}
		ans += (now > 0);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

#define MAX_SIZE 200000

int main(void) {
	char S[MAX_SIZE];
	scanf("%s", S);
	int length = strlen(S);
	int istwo = false, point = 1, answer = 1;
	while (point < length) {
		if (!istwo) {
			if (point == length - 1) {
				if (S[point] != S[point - 1]) {
					answer++;
				}
				break;
			}
			else if (S[point] == S[point - 1]) {
				istwo = true;
				point += 2;
			}
			else {
				point++;
			}
		}
		else {
			point++;
			istwo = false;
		}
		answer++;
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
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<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 mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n >> m >> l;
  ll ans = l;
  rep(i,0,n){
    ll p;
    cin >> p; 
    for(int j = 1;j <= m;j += p)ans += 1;
  }
  print(ans);
  return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<int> v(N);
  for(int i = 0; i < N; i++) cin >> v[i];

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

  double ans = v[0];
  for(int j = 0; j < (N-1); j++){
    ans = (ans + v[j+1]) / 2.;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

int main() {
    constexpr int64_t mod = 998244353;

    int n, k; cin >> n >> k;
    vec<array<int, 2>> range(k);
    for (auto &[l, r] : range) { cin >> l >> r; ++r; }

    vec<int64_t> dp(n, 0); dp[0] = 1; dp[1] = -1;
    for (int i = 0; i < n; ++i) {
        // 確定した方法の数iを復元する
        if (0 < i) dp[i] = (dp[i] + dp[i - 1]) % mod;
        // iの方法の数を区間[l,r)すべてに足す
        for (auto [l, r] : range) {
            if (i + l < n) dp[i + l] = (dp[i + l] + dp[i]) % mod;
            if (i + r < n) {
                dp[i + r] = (dp[i + r] - dp[i]) % mod;
                while (dp[i + r] < 0) dp[i + r] += mod;
            }
        }
    }

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



Measured memory_bytes: 4752
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;



 int main(){
	 LL n,x;
	 cin>>n>>x;
	 vector<LL> d(n),dd(n+1,0);
	 LL ans=2*n*x,as=(n+1)*x;
	 FOR(i,0,n){
		 cin>>d[i];
		 ans+=5*d[i];
		 dd[i+1]=d[i];
		 dd[i+1]+=dd[i];
	 }

	 FOR(t,1,n){//ゴミ捨てる回数
		 LL scr=n*x+t*x;
		 int tmp=n-t;
		 int mx=(n+t-1)/t;
		 int mn=n/t;
		 int last=n%t;
		 int range=0;
		 if(mx>=2)range=(n-last)/mn;
		 /*
		 vector<LL> num(n,1);
		 FOR(i,0,last)num[i]=mx;
		 int itr=-1;
		 FORD(i,mn+1,1){
			 itr++;
			 FOR(j,0,range){
				 num[j+last+itr*range]=i;
			 }
		 }
		 FOR(i,0,n){
			 if(num[i]==1){
				 scr+=5*d[i];
			 }else{
				 scr+=((num[i]+1)*(num[i]+1)-num[i]*num[i])*d[i];
			 }
		 }
		 //*/
		 scr=min(ans,scr+(2*mx+1)*(dd[last]));
		 FORD(i,mn+1,1){
			 if(scr==ans)break;
			 if(i==1){
				 scr=min(ans,scr+5*(dd[last+(mn-i+1)*range]-dd[last+(mn-i)*range]));

			 }else{
				 scr=min(ans,scr+(2*i+1)*(dd[last+(mn-i+1)*range]-dd[last+(mn-i)*range]));
			 }
		 }
		 ans=min(ans,scr);
		 //cerr<<t<<" scr:"<<scr<<endl;
	 }
	 cout<<ans<<endl;
   return 0;
 }


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 500;
int h, w, q[N][N];
vi a, b, c, d;
void ans(int _a, int _b, int _c, int _d){
  a.pb(_a);
  b.pb(_b);
  c.pb(_c);
  d.pb(_d);
  q[_c][_d]++;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  FOR(i, 0, h)FOR(j, 0, w) cin >> q[i][j];
  FOR(i, 0, h)FOR(j, 0, w-1) if(q[i][j]%2) ans(i, j, i, j+1);
  FOR(i, 0, h-1)if(q[i][w-1]%2) ans(i, w-1, i+1, w-1);
  cout << sz(a) << endl;
  FOR(i, 0, sz(a)) cout << a[i]+1 << " " << b[i]+1 << " " << c[i]+1 << " " << d[i]+1 << endl;
  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A+B+C >= 22){
    cout << "bust" << endl;
  } else if (A+B+C <= 21) {
    cout << "win" << endl;
  }
  
}

Measured memory_bytes: 256
// Problem : D - Leaping Tak
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()

const ll inf=0x3f3f3f3f3f3f3f3f;
const ll N = 8e5 + 5, p = 998244353;

ll st[4 * N], lazy[4 * N];
ll dp[N] = {0};
void add(ll &a, ll &b) {
	a = (a % p + b % p) % p;
}
void build(ll node, ll L, ll R) {
	if(L == R) {
		st[node] = dp[L] % p;
		return;
	}
	ll M = (L + R)>>1;
	build(2 * node, L, M);
	build(2 * node + 1, M + 1, R);
	st[node] = (st[2 * node] % p + st[2 * node + 1] % p) % p;
}
void prop(ll node, ll L, ll R) {
	st[node] = (st[node] % p +  ((R - L + 1) % p * lazy[node] % p) % p) % p;
	if(L != R) {
		add(lazy[2 * node], lazy[node]);
		add(lazy[2 * node + 1], lazy[node]);
	}
	lazy[node] = 0;
}
void update(ll node, ll L, ll R, ll l, ll r, ll val) {
	if(lazy[node]) {
		prop(node, L, R);
	}
	if(r < L || l > R)return;
	if(l <= L && r >= R) {
		st[node] = (st[node] % p +  ((R - L + 1) % p * val % p) % p) % p;
		if(L != R) {
			add(lazy[2 * node], val);
			add(lazy[2 * node + 1], val);
		}
		return;
	}
	ll M = (L + R)>>1;
	update(2 * node, L, M, l, r, val);
	update(2 * node + 1, M + 1, R, l, r, val);
	st[node] = (st[2 * node] % p + st[2 * node + 1] % p) % p;
}
ll query(ll node, ll L, ll R, ll l, ll r) {
	if(lazy[node]) {
		prop(node, L, R);
	}
	if(r < L || l > R)return 0;
	if(l <= L && r >= R) {
		return st[node];
	}
	ll M = (L + R)>>1;
	ll sum = (query(2 * node, L, M, l, r) % p + query(2 * node + 1, M + 1, R, l, r) % p) % p;
	return sum;
}
int main() {
    SPEED;
    ll n, k;
    cin>>n>>k;
    vector<pii> v(k);
    for(ll i = 0; i < k; i++) {
    	cin>>v[i].fi>>v[i].se;
    }
    sort(all(v));
    dp[1] = 1;
    build(1, 1, N - 1);
    for(ll i = 1; i <= n; i++) {
    	ll val = query(1, 1, N - 1, i, i);//dp[i]
    	for(auto it:v) {
    		update(1, 1, N - 1, i + it.fi, i + it.se, val);
    	}
    }
    cout<<query(1, 1, N - 1, n, n);
    return 0;
}

Measured memory_bytes: 28144
#include<stdio.h>
int max(int a,int b){
        if(a>b) return a;
        return b;
}
int main(void){
        int dp1[3]={0},dp2[3];
        int n;
        int a,b,c;
        int i;
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%d%d%d",&a,&b,&c);
                if(i&1){
                        dp1[0]=max(dp2[1]+a,dp2[2]+a);
                        dp1[1]=max(dp2[0]+b,dp2[2]+b);
                        dp1[2]=max(dp2[0]+c,dp2[1]+c);
                }else{
                        dp2[0]=max(dp1[1]+a,dp1[2]+a);
                        dp2[1]=max(dp1[0]+b,dp1[2]+b);
                        dp2[2]=max(dp1[0]+c,dp1[1]+c);
                }
        }
        if(n&1){
                printf("%d\n",max(max(dp2[0],dp2[1]),dp2[2]));
        }else{
                printf("%d\n",max(max(dp1[0],dp1[1]),dp1[2]));
        }
        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
void solve()
{
    ll n, m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

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

#define MAX_V 100001
#define INF 1000000000000001
typedef long long ll;

struct edge { ll to, cost; };
typedef pair<ll, ll> P; // firstは最短距離、secondは頂点の番号
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve(long long N, vector<long long> a, vector<long long> b, vector<long long> c, long long Q, long long K, vector<long long> x, vector<long long> y){
	for (int i=0; i<N-1; i++) {
		edge e1 = {a[i],c[i]};
		G[b[i]].push_back(e1);
		edge e2 = {b[i],c[i]};
		G[a[i]].push_back(e2);
	}
	dijkstra(K);
	for (int i=0; i<Q; i++) {
		cout << d[x[i]]+d[y[i]] << endl;
	}
}

int main(){	
	long long Q;
	long long N;
	long long K;
	scanf("%lld",&N);
	vector<long long> a((N-1)-1+1);
	vector<long long> c((N-1)-1+1);
	vector<long long> b((N-1)-1+1);
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
		scanf("%lld",&c[i]);
	}
	scanf("%lld",&Q);
	vector<long long> x(Q-1+1);
	vector<long long> y(Q-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= Q-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
	}
	solve(N, a, b, c, Q, K, x, y);
	return 0;
}



Measured memory_bytes: 18928
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200001;


int main(){
  int n;
  int k;
  cin>>n>>k;
  
  
  int b[maxn];
  fill(b,b+maxn,0);
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    b[tmp]++;
  }

  sort(b,b+maxn);
  int now=0;
  for(int i=0;i<maxn;i++){
    if(b[i]!=0)now++;
  }
  int d=now-k;
  int res=0;
  for(int i=0;i<maxn;i++){
    if(d<=0)break;
    if(b[i]!=0){
      res+=b[i];
      d--;
    }
  }
  cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int h1,w1,h2,w2;
    cin>>h1>>w1>>h2>>w2;
    cout<<h1*w1-h2*w1-h1*w2+h2*w2<<endl;
    return 0;
}

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


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int x = 0;
    int y = 0;
    int ans = 0;
    while ((x < X) && (y < Y) && ((A + B) > (C * 2)))
    {
        ++x;
        ++y;
        ans += C * 2;
    }
    while (x < X)
    {
        if (A > C * 2)
        {
            ++x;
            ans += C * 2;
        }
        else
        {
            ++x;
            ans += A;
        }
    }
    while (y < Y)
    {
        if (B > C * 2)
        {
            ++y;
            ans += C * 2;
        }
        else
        {
            ++y;
            ans += B;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n,k;
	cin>>n>>k;
	int tot_edges=(n-1)*(n-2)/2;
	if(k>tot_edges){
		cout<<"-1"<<endl;
		return 0;
	}
	int cnt=0;
	cout<<n-1+tot_edges-k<<endl;
	for(int i=2;i<=n;i++){
		cout<<1<<" "<<i<<endl;
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(k==tot_edges){
				return 0;
			}
			cout<<i<<" "<<j<<endl;
			tot_edges--;
		}
	}
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  string s;
  cin>>s;
  if(s[0]==s[1]){cout<<1<<" "<<2<<endl;return 0;}
  repi(i,2,s.size() ){
    if(s[i-2]==s[i-1] || s[i-1]==s[i] || s[i-2]==s[i]){
      cout<<i-1<<" "<<i+1<<endl;
      return 0;
    }
  }
  cout<<-1<<" "<<-1<<endl;
	
  return 0;
}



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

int main(void)
{
	string str_cards, str_subcards1, str_subcards2;
	int i, m, h;

	while (1) {

		// cout << "文字列を入力してください" << endl;
		cin >> str_cards;

		if (str_cards == "-") break;

		// cout << "シャッフル回数を入力してください" << endl;
		cin >> m;

		for (i = 0; i < m; i++) {
			// cout << "何文字目でシャッフル？" << endl;
			cin >> h;

			str_subcards1 = str_cards.substr(0, h);
			str_subcards2 = str_cards.substr(h);

			// cout << str_subcards1 << ", " << str_subcards2 << endl;

			str_cards = str_subcards2 + str_subcards1;
		}

		cout << str_cards << endl;

	}
}


Measured memory_bytes: 3160
let N = Int(readLine()!)!
let A = readLine()!.characters.split(" ").map{Int(String($0))!}
var S = [0]
for i in 0..<N {
  S += [S[i]+A[i]]
}
var s = [Int: Int]()
for i in S {
  s[i] = (s[i] ?? 0) + 1
}
print(s.values.reduce(0){$0+$1*($1-1)/2})

Measured memory_bytes: 29032
#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include <cmath>
using namespace std;
const long long N = 105;
long long M= 1000000007;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != ',')cout << s[i];
		else cout << endl;
	}
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define ff first
#define ss second
#define mp make_pair
void setIO() {
     ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
};


int main() {
     setIO();
     ll n,k;
     cin >> n >> k;

     vector<ll> scores;
     for(int i = 0; i < n; i++){
          ll x;
          cin >> x;
          scores.pb(x);
     }

     ll mans = 1;
     vector<string> op;
     
     for(int i = 0; i < n; i++){
          if(i < k){
               continue;
          }

          if( scores[i] > scores[i-k] )
               op.push_back("Yes");
          else
               op.push_back("No");
     }
     for(auto k: op)
          cout << k << endl;
     return 0;
}

Measured memory_bytes: 13112
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<a.length;i++){
            a[i]=sc.nextInt();
        }
        for(int j=a.length-1;j>=0;j--){
            System.out.print(a[j]);
            if(j==0)
            break;
            System.out.print(" ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 26360
#include <cstdio>

int main ()
{
  int S;
  int h, m, s;

  scanf("%d", &S);

  h = S / 3600;
  S = S % 3600;

  m = S / 60;
  s = S % 60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

Measured memory_bytes: 2696
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N;
  cin >> N;
  vll A(N);
  rep(i, N - 1) {
    cin >> A[i];
    A[i] --;
  }
  
  vll C(N);
  rep(i, N - 1) {
    C[A[i]] ++;
  }
  
  rep(i, N) {
    fin(C[i]);
  }
}

Measured memory_bytes: 6372
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];

  int ans = 0;
  REP(k, 30) {
    int T = 1 << k;
    vector<int> a(A), b(B);
    REP(i, N) {
      a[i] %= 1 << (k + 1);
      b[i] %= 1 << (k + 1);
    }

    sort(ALL(b));
    int p = 0;
    REP(i, N) {
      int i1 = lower_bound(ALL(b), T - a[i]) - b.begin();
      int i2 = lower_bound(ALL(b), 2*T - a[i]) - b.begin();
      int i3 = lower_bound(ALL(b), 3*T - a[i]) - b.begin();
      p += (i2 - i1) + (N - i3);
      p %= 2;
    }
    ans |= p << k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3432
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  bool ans=true;
  if(s.length()%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<s.length();i++){
    if(i%2==0&&s[i]!='h') ans=false;
    if(i%2==1&&s[i]!='i') ans=false;
  }
  cout<<(ans?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
/*
void disp(char **house,int w,int h){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)
			cout<<house[i][j]<<" ";
	cout<<endl;
	}
cout<<endl;
return;
}
*/

void aruku(char** house,int w,int h,int row,int col){
	if(house[col][row]=='0')return;
	house[col][row]='0';
	if(row+1<w)aruku(house,w,h,row+1,col);
	if(col+1<h)aruku(house,w,h,row,col+1);
	if(row-1>=0)aruku(house,w,h,row-1,col);
	if(col-1>=0)aruku(house,w,h,row,col-1);
return;
}

int tansaku( char** house,int w,int h){
	int row=0;int col=0;int cnt=0;
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++){
		if(house[i][j]=='1'){row=j;col=i;cnt++;
			aruku(house,w,h,row,col);
		}
	}
	return cnt;
}


int main(void){
int h=12,w=12;
	string next;
	do{
	char** house=(char**)calloc(h,sizeof(char*));
	for(int i=0;i<h;i++)house[i]=(char*)calloc(w,sizeof(char));

	for(int i=0;i<h;i++){
		string str;
		getline(cin,str);
		for(int j=0;j<w;j++){house[j][i]=str[j];}
	}
	
	//disp(house,w,h);
	int ret=tansaku(house,w,h);
	cout<<ret<<endl;
	for(int i=0;i<h;i++)free(house[i]);
	free(house);
	
	}while(getline(cin,next));
	
	return 0;
}



Measured memory_bytes: 3108
# -*- coding: utf-8 -*-
from collections import defaultdict
from itertools import permutations
def inpl(): return list(map(int, input().split()))

D = defaultdict(int)
for _ in range(3):
    x, y = inpl()
    D[(x-1, y-1)] = 1
    D[(y-1, x-1)] = 1

for X in permutations(range(4)):
    #print(X)
    for i in range(3):
        if D[(X[i], X[i+1])] == 0:
            break
    else:
        print("YES")
        break
else:
    print("NO")

Measured memory_bytes: 3316
#include <stdio.h>

int main() {
  int n, m, A[100][100], b[100], c[100], i, j;

  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &A[i][j]);
    }
  }
  for (i = 0; i < m; i++) scanf("%d", &b[i]);

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      c[i] += A[i][j] * b[j];
    }
  }

  for (i = 0; i < n; i++) {
    printf("%d\n", c[i]);
  }

  return 0;
}


Measured memory_bytes: 2100
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  string s;
  cin>>s;
  ll n=s.size();
  loop(i,n)cout<<"x";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

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

  int x = tx-sx;
  int y = ty-sy;
  rep(i,y) printf("U");
  rep(i,x) printf("R");
  rep(i,y) printf("D");
  rep(i,x) printf("L");

  printf("L");
  rep(i,y+1) printf("U"); rep(i,x+1) printf("R");
  printf("D");

  printf("R");
  rep(i,y+1) printf("D"); rep(i,x+1) printf("L");
  printf("U");
}

Measured memory_bytes: 256
import math


a, b, C = map(int, input().split())

C = math.radians(C)
S = a * b * math.sin(C) / 2
L = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))
h = b * math.sin(C)

print("{:.5f}\n{:.5f}\n{:.5f}".format(S, L, h))



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

int main() {
    int N, K;
    map<int, int> mp;
    
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N; i++){
        cin >> a[i];
        mp[a[i]] += 1;
    }
    

    int type_num = 0;
    for (auto p : mp) {
        ++type_num;
    }

    int num[type_num] = {0};
    int count = 0;
    for (auto p : mp) {
        auto value = p.second;
        num[count] += value;
        count++;
    }

    int res = 0;
    sort(num, num + count);
    for (int i = 0; i < type_num - K; i++){
        res += num[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 11136