akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
  int N, i;
  scanf("%d", &N);
  long int A[N+1], B[N];
  long int count = 0;
  for(i=0; i<N+1; i++)
    scanf("%ld", &A[i]);
  for(i=0; i<N; i++)
    scanf("%ld", &B[i]);

  for(i=0; i<N; i++){
    if(B[i] <= A[i]){
      A[i] -= B[i];
      count += B[i];
    }
    else{
      B[i] -= A[i];
      count += A[i];
      if(B[i] <= A[i+1]){
	A[i+1] -= B[i];
	count += B[i];
      }
      else{
	count += A[i+1];
	A[i+1] = 0;
      }    
    }
  }
  
  printf("%ld\n", count);


  return 0;
}


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

int N;
int S[100010];
vector<int> cmp;
int CS[100010];
bool mem[100010] = {0};
vector<int> V;
long long ans = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",&S[i]);
    for(int i = 0; i < N; i++)cmp.push_back(S[i]);
    sort(cmp.begin(),cmp.end());
    cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
    for(int i = 0; i < N; i++)S[i] = lower_bound(cmp.begin(),cmp.end(),S[i]) - cmp.begin();
    for(int i = 0; i < N; i++)CS[i] = S[i];
    sort(CS,CS + N);
    for(int i = 0; i < N; i += 2)mem[CS[i]] = true;
    for(int i = 0; i < N; i++)if(mem[S[i]])V.push_back(i);
    for(int i = 0; i < V.size(); i++)if(V[i] % 2 == 1)ans++;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1912
n,m = map(int,input().split())
dp = [0 for i in range(n+1)]
for i in range(m):
    j = int(input())
    dp[j] = -1
dp[0] = 1
dp[1] = 1 if dp[1] != -1 else 0
for i in range(2,n+1):
    if dp[i] == -1:
        dp[i] = 0
        continue
    dp[i] = dp[i-1] + dp[i-2]
print(dp[n]%1000000007)

Measured memory_bytes: 460056
import java.util.*;

public class Main{
  public static void main(String aargs[]){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    String[] ss = {"AC","WA","TLE","RE"};
    int[] cnts = {0,0,0,0};
    
    for(int i = 0; i <= n; i++){
      String r = sc.nextLine();
      for(int j = 0; j < 4; j++){
        if(r.equals(ss[j])){
          cnts[j]++;
          break;
        }
      }
    }
    
    for(int i = 0; i < 4; i++){
      System.out.println(ss[i] + " x " + cnts[i]);
    }
    
  }
}

Measured memory_bytes: 60528
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26324
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int   p[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  char  *str;
  int   target;
  int   result;

  str = (char *)malloc(sizeof(char) * 10000);
  result = scanf("%s", str);
  target = atoi(str) - 1;
  if (target >= 0 && target <= 31)
    printf("%d", p[target]);
  return (0);
}


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

int main(){
  int X,A,B;
  int h,d,e;
  scanf("%d%d%d",&X,&A,&B);
  for (int i = 0; i<=X;i++){
  h = (i%100000)/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+i%10;
  if((A<=h)&&(h<=B)) d+=i;
  }
  printf("%d",d);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cstdlib>
#include <fstream>


using namespace std;

int main(void) {
	string s;
	char c = 'A',cc;
	int count = 0;
	while(cin>>cc) {
		//char cc;
		if (c == cc) {
			count++;
			continue;
		}
		while (c != cc) {
			c++;
			if (c > 'Z')c = 'A';
			if (c == 'A') count++;
		}
	}

	cout << count << endl;
	
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	int q;
	cin >> q;
	vvi g(n);
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector<long long> add(n);
	for (int i = 0; i < q; i++)
	{
		int p; long long x;
		cin >> p >> x;
		add[p - 1] += x;
	}
	vector<long long> res(n);
	vector<bool> visited(n, false);
	visited[0] = true;
	queue<pair<int, long long>> qq;
	qq.push(make_pair(0, add[0]));
	while (!qq.empty())
	{
		auto cur = qq.front(); qq.pop();
		int u = cur.first; long long curr = cur.second;
		res[u] = curr;
		for (int i = 0; i < sz(g[u]); i++)
		{
			int v = g[u][i];
			if (!visited[v])
			{
				visited[v] = true;
				qq.push(make_pair(v, curr + add[v]));
			}
		}
	}
	for (int i = 0; i < n; i++)
		cout << res[i] << " ";
	return 0;
}

Measured memory_bytes: 20340
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    
    vector<unsigned long long int> a(3);
    int k;
    cin>>a[0]>>a[1]>>a[2]>>k;
    
    sort(a.begin(), a.end());
    
    for(int i=0; i<k; i++){
        a[2]*=2;
    }
    
    cout<<a[0]+a[1]+a[2]<<endl;
    
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    ll N;cin >> N;
    ll W;cin >> W;
    vector<vector<ll> > Obj(4,vector<ll>());
    ll w1 = 0;
    rep(i,N){
        ll w,v;
        cin >> w >> v;
        if(i==0)w1=w;
        Obj[w-w1].push_back(v);
    }
    rep(i,4){
        sort(Obj[i].begin(),Obj[i].end());
        reverse(Obj[i].begin(),Obj[i].end());
    }
    vector<vector<ll> > sum(4,vector<ll>());
    rep(i,4){
        sum[i].resize(Obj[i].size()+1);
        rep(j,Obj[i].size()){
            sum[i][j+1]=sum[i][j]+Obj[i][j];
        }
    }
    ll res = 0;
    rep(i,sum[0].size()){
        rep(j,sum[1].size()){
            rep(k,sum[2].size()){
                rep(l,sum[3].size()){
                    if(i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3)<=W){
                        res = max(res,sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]);
                    }
                }
            }   
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
int main()
{
	ll a[3],b[3],s[10];
	for(int i=0;i<2;i++) cin>>a[i];
	for(int i=0;i<2;i++) cin>>b[i];
	int t=0;
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			ll sum=a[i]*b[j];
			s[t++]=sum;
		}
	}
	sort(s,s+t);
	printf("%lld\n",s[t-1]);
} 

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define INF 1000000007
#define MOD 998244353
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

ll N, M, K;

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll cmb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main(){

	cin >> N >> M >> K;
	ll ans = 0;
	init();
	rep(i, K + 1){
		ll acc = M * cmb(N - 1, i) % MOD;
		acc *= modpow(M - 1, N - 1 - i);
		ans += acc;
		ans %= MOD;
	}
	print(ans);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





Measured memory_bytes: 15612
import math


def main(n, a, b):
    def validator(x, a, b):
        total = sum([(x // (10 ** digit)) %
                     10 for digit in range(int(math.log10(n)) + 1)])
        return total >= a and total <= b
    print(sum([x for x in range(1, n + 1) if validator(x, a, b)]))


if __name__ == "__main__":
    n, a, b = [int(x) for x in input().split()]
    main(n, a, b)


Measured memory_bytes: 9280
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let K: usize = sc.get();
    let mut cnt = vec![0; N];
    for _ in 0..K {
        let d: usize = sc.get();
        for _ in 0..d {
            let A: usize = sc.get::<usize>()-1;
            cnt[A] += 1;
        }
    }
    let mut ans = 0usize;
    for i in 0..N {
        if cnt[i] == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
/*input
46 4 40 5
*/

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ta = (a+d-1)/d;
    int ao = (c+b-1)/b;
    if (ta >= ao) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3632
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2<<endl;
	
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
	    int x = scan.nextInt();


	    //?????£????????????(int)
	    System.out.println( (int)Math.pow(x, 3) );
	    
	   

	}

}

Measured memory_bytes: 25980
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<(w*h)/2.0;
	if(x*2==w&&y*2==h)
	{
		cout<<" "<<1;
	}
	else cout<<" "<<0;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class TaskA {
 public:
  int score(char c1, char c2) {
    if (c1 == '.' && c2 == '#') return 1; else return 0;
  }


  void solveOne(istream &in, ostream &out) {
    int height;
    int width;
    in >> height >> width;
    vector<string> grid(height);
    for (int r = 0; r < height; ++r) in >> grid[r];
    vector<vector<int>> best(height, vector<int>(width, (int) 1e9));
    best[0][0] = grid[0][0] == '#' ? 1 : 0;
    for (int r = 0; r < height; ++r) {
      for (int c = 0; c < width; ++c) {
        if (r == 0 && c == 0) continue;
        if (r > 0) {
          best[r][c] = min(best[r][c], best[r - 1][c] + score(grid[r - 1][c], grid[r][c]));
        }
        if (c > 0) {
          best[r][c] = min(best[r][c], best[r][c - 1] + score(grid[r][c - 1], grid[r][c]));
        }
      }
    }
    out << best[height - 1][width - 1] << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt;
    nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskA solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 384
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
 
readIntsLines :: IO [[Int]]
readIntsLines = map (map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

calc :: [Int] -> [Int] -> [Int]
calc [pa, pb, pc] [ca, cb, cc] = [na, nb, nc]
  where na = max (pb + ca) (pc + ca)
        nb = max (pa + cb) (pc + cb)
        nc = max (pa + cc) (pb + cc)

solve :: [Int] -> [[Int]] -> [[Int]]
solve _ [] = []
solve pabc (cabc:abcs) = nabc : solve nabc abcs
  where nabc = calc pabc cabc

main :: IO ()
main = do
  n <- readLn :: IO Int
  abcs <- readIntsLines
  print . maximum . last $ solve [0,0,0] abcs

Measured memory_bytes: 61820
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Caracal vs Monster
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll h;
  scanf("%lld", &h);

  int n = 0;
  while (h > 0) h >>= 1, n++;
  //printf("%d\n", n);

  printf("%lld\n", (1LL << n) - 1);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ai = [int(i) for i in input().split()]

li = [0]*(10**6+1)

for i in range(1,n):
    if ai[i] >= 2*10**5:
        continue
    li[ai[i]-i+5*10**5] += 1

ans = 0

for i in range(1,n):
    if ai[i-1] >= 2*10**5:
        continue
    #print(i)
    ans += li[-ai[i-1]-(i-1)+5*10**5]
    if i == n:
        #print(i,i,i)
        break
    if ai[i] < 2*10**5:
        li[ai[i]-i+5*10**5] -= 1
        
print(ans)

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

int main() {
    int n, m;
    cin>>n>>m;
    vector<vector<int>> adj(n, vector<int>(0));
    
    int indegree[n];
    memset(indegree, 0 , sizeof(indegree));
    
    int x,y;
    for(int i = 0;i<m;i++){
        cin>>x>>y;
        adj[x-1].push_back(y-1);
        indegree[y-1]++;
    }
    
    // so now build a topological order and then go over it to find the max len of things;
    
    vector<int> order;
    queue<int> q;
    
    int dis[n];
    memset(dis, -1, sizeof(dis));
    
    
    for(int i = 0;i<n;i++){
        if(indegree[i]==0){ 
            q.push(i);
            dis[i] = 0;
        }
    }
    
    
    while(!q.empty()){
        int a = q.front();
        for(int i = 0;i<adj[a].size();i++){
            int b = adj[a][i];
            indegree[b]--;
            if(indegree[b] == 0)q.push(b);
        }
        order.push_back(a);
        q.pop();
    }
    
    //for(int i = 0;i<n;i++) cout<<order[i]+1<<" ";
    //Topological order is set.
    //dis[order[0]] = 0;
    //for(int i = 0;i<n;i++)cout<<"I: "<<i+1<<" "<<"dis: "<<dis[i]<<endl;
    
    for(int i = 0;i<order.size();i++){
        int a = order[i];
        for(int j = 0;j<adj[a].size();j++){
            int b = adj[a][j];
            dis[b] = max(dis[b],dis[a]+1);
        }
    }
    
    //for(int i = 0;i<n;i++)cout<<"I: "<<i+1<<" "<<"dis: "<<dis[i]<<endl;
    int result = 0;
    for(int i = 0;i<n;i++)result = max(result, dis[i]);
    
    cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 7164
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 2005;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> tree_set;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int a[3];
    for (int i = 0; i < 3; i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    if(a[0]==a[1]&&a[0]!=a[2])
        cout<<"Yes";
    else if(a[2]==a[1]&&a[0]!=a[2])
        cout<<"Yes";
    else
        cout<<"No";

    printclock;
    return 0;
}


Measured memory_bytes: 256
import sys
import math

N=int(sys.stdin.readline())

length=math.ceil(math.log((N*25)/26+1,26))

for g in range(1,length):
	N-=pow(26,g)

N-=1

s=[]
while(N>0):
	s.append(N%26)
	N//=26

for h in range(length-len(s)):
	s.append(0)

s.reverse()

ans="abcdefghijklmnopqrstuvwxyz"

for g in range(len(s)):
	print(ans[s[g]],end="")
print()

Measured memory_bytes: 61852
import math
import cmath
 
def area(x):
    theta = cmath.phase(x[1]-x[0])
    C = (x[3]-x[2])*complex(math.cos(-theta),math.sin(-theta))
    return C.imag

def parallel(P):
    x = []
    for i in range(4):
        x.append(complex(P[i*2],P[i*2+1]))
    return True if abs(area(x))<eps else False

n = int(input())
eps = 0.0000001
for _ in range(n):
    P = list(map(float,input().split()))
    print("YES" if parallel(P) else "NO")


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

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  ll a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
using System;

namespace ITP1_10_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            double a = double.Parse(str[0]);
            double b = double.Parse(str[1]);
            double C = double.Parse(str[2]);

            double S = a * b * Math.Sin(2 * Math.PI * C / 360) / 2;
            double L = a + b + Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2) - 2 * a * b * Math.Cos(2 * Math.PI * C / 360));
            double h = b * Math.Sin(2 * Math.PI * C / 360);

            Console.WriteLine("{0}", S);
            Console.WriteLine("{0}", L);
            Console.WriteLine("{0}", h);
        }
    }
}

Measured memory_bytes: 5768
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		var n = int.Parse(Console.ReadLine());
		TimeSpan ts = new TimeSpan(0, 0, n);
		Console.WriteLine(string.Format("{0}:{1}:{2}",ts.Hours, ts.Minutes, ts.Seconds) );
	}
}

Measured memory_bytes: 9228
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

s.sort()

while True:
    if sum(s) % 10 == 0:
        index = None
        for i in range(n):
            if s[i] % 10 != 0:
                index = i
                break
        if index != None:
            s.pop(index)
        else:
            break
    else:
        break
    if len(s) == 0:
        break
    
if sum(s) % 10 == 0:
    print(0)
else:
    print(sum(s))


Measured memory_bytes: 3060
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-problems/ChristmasEveEve.py
#
n = int(input())
p = list()
for i in range(n):
    pi = int(input())
    p.append(pi)

print(int(sum(p)-max(p)/2))

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

int main() {
    int N;
    int K;
    cin >> N >> K;

    double possibility = 0;
    vector<int> exp;
    for (int i = 1; i <= N; i++) {
        int num = i;
        int count = 0;
        while (num < K) {
            count++;
            num *= 2;
        }
        exp.push_back(count);
    }
    sort(exp.begin(), exp.end());
    int max = exp[exp.size() - 1];

    long long int sum = 0;
    for (int i = 0; i < exp.size(); i++) {
        sum += pow(2, max - exp[i]);
    }
    possibility = sum;
    possibility /= pow(2, max);

    possibility /= N;
    printf("%1.12f\n", possibility);
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;


const int nmax=8;
 bool graph[nmax][nmax];

 int dfs(int v,int N,bool visited[nmax]){

	bool all_visited=true;

	//すべて訪問したかチェック
	for (int i = 0; i < N; i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}

	//すべて訪問可能なルートを数える為
	if (all_visited) {

		return 1;
	}

	int ret = 0; //ルートの数

	//グラフ上でつながって
	//まだ訪れたことがない
	for (int j = 0; j < N; j++) {

		//v==0からスタート
		if (graph[v][j]==false) {
			continue;
		}

		if (visited[j]) {
			continue;
		}

		visited[j] = true;
		ret += dfs(j, N, visited);
		visited[j] = false;

	}

	return ret;
 }

 int main(void){
	 int N,M;
	 cin >> N >> M;

	 //二次元のグラフを作成
	 for(int i=0;i<M;++i){
	 int A,B;
	 cin >> A >> B;
	 graph[A-1][B-1]=graph[B-1][A-1]=true;
	}
	 
	 //訪問先配列初期化
	 bool visited[nmax];
	 for(int i=0;i<N;++i){
	 visited[i]=false;
	 }

	 visited[0]=true;
	 cout << dfs(0,N,visited) << endl;
	 return 0;
 }


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

const int INF = 1 << 24;
int ticket, V, E, start, goal;
//d[i][j]: i枚使ったんだよー
int d[11][101], used[11][101], cost[101][101];

int dijkstra(int s){
	for(int i=0;i<11;i++){
		std::fill(d[i], d[i]+101, INF);
		std::fill(used[i], used[i]+101, 0);
	}

	d[0][s] = 0;

	while(true){
		int u = -1, v;
		for(int i=0;i<=ticket;i++){
			for(int j=1;j<=V;j++){
				if(!used[i][j] && (u == -1 || d[i][j] < d[u][v])){
					u = i;
					v = j;
				}
			}
		}

		if(u == -1)break;
		used[u][v] = 1;

		for(int j=1;j<=V;j++){
			d[u][j] = std::min(d[u][j], d[u][v] + cost[v][j]);
			if(u+1 <= ticket){
				d[u+1][j] = std::min(d[u+1][j], d[u][v] + cost[v][j] / 2);
			}
		}
	}
	
}

int main(){
	while(std::cin >> ticket >> V >> E >> start >> goal, V){
		for(int i=1;i<=100;i++){
			for(int j=1;j<=100;j++){
				cost[i][j] = INF;
			}
		}
		for(int i=0;i<E;i++){
			int a, b, f;
			std::cin >> a >> b >> f;
			cost[a][b] = cost[b][a] = f;
		}
		dijkstra(start);
		int res = INF;
		for(int i=0;i<=ticket;i++){
			res = std::min(res, d[i][goal]);
		}
		std::cout << res << std::endl;
	}
}

Measured memory_bytes: 1208
import sys
import itertools
input = sys.stdin.readline
inf = 200000000
n, m, r = map(int,input().split())
rs = list(map(int,input().split()))
d = [[inf] * (n+1) for j in range(n+1)]
for i in range(n+1):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    d[a][b] = d[b][a] = c
for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            d[i][j] = d[j][i] = min(d[i][j], d[i][k] + d[k][j])
p = list(itertools.permutations(range(r)))
s = inf
for q in p:
    t = 0
    for i in range(r-1):
        t += d[rs[q[i]]][rs[q[i+1]]]
    if s > t:
        s = t
print(s)

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

using namespace std;

typedef long long ll;
const int MAX = 100005;
const int MOD = 1000000007;

#define F first
#define S second

void solve()
{
	
	return;
}
vector<vector<ll>> adj,block;
vector<ll> visit;
map<ll,ll> mp,mp2;
//map<ll,vector<ll>> mp2;

ll comp=0,ct=0;
void dfs(ll i)
{
	ct+=1;
	mp[comp]=ct;
	visit[i]=comp;
	//mp2[i]=comp;
	//mp2[comp].push_back(i);
	for(ll node:adj[i])
	{
		if(visit[node]==0)
		{
			//ct++;
			dfs(node);
		}

	}
	return;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll n,m,k;
	cin>>n>>m>>k;
	adj.assign(n,vector<ll>());
	block.assign(n,vector<ll>());
	for(int i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		a--,b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(auto i: adj)
	{
		sort(i.begin(),i.end());
	}
	visit.assign(n,0);
	
	for(int i=0;i<n;i++)
	{
		if(visit[i]==0)
		{
			comp+=1;
			ct=0;
			dfs(i);
		}
	}
	for(int i=0;i<k;i++)
	{
		ll a,b;
		cin>>a>>b;
		a--,b--;
		if(visit[a]==visit[b])
		{
			block[a].push_back(b);
			block[b].push_back(a);
		}
	}
	// for(auto i: mp2)
	// {
	// 	sort(i.S.begin(),i.S.end());
	// }
	// for(auto i: mp)
	// {
	// 	cout<<i.F<<" "<<i.S<<endl;
	// }
	for(int i=0;i<n;i++)
	{
		ll ct2=0;
		// if(adj[i].size()==0)
		// {
		// 	ct2=block[i].size();
		// }
		// else
		// {
		// 	for(ll node:block[i])
		// 	{
		// 		if(visit[i]==visit[node])
		// 		{
		// 			vector<ll>::iterator low;
		// 			//if(adj[i].size()>0)
		// 			{
		// 				low=lower_bound(adj[i].begin(),adj[i].end(),node);
		// 				if(*low!=node)
		// 					ct2++;
		// 			}
		// 		}
		// 	}
		// }
		ll x=mp[visit[i]];
		x-=(adj[i].size()+1+block[i].size());
		x=max(x,0LL);
		cout<<x<<" ";
	}
	cout<<"\n";
	return 0;
}


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

int nlist[110];

int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>nlist[i];
  }
  
  int min_cost = 1<<30;
  
  for(int i=-100;i<=100;i++){
    int temp = 0;
    for(int j=0;j<N;j++){
      temp += (i-nlist[j])*(i-nlist[j]);
    }
    min_cost = min(min_cost,temp);
  }

  cout<<min_cost<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int dis[2], r1, num1;
	int n, num, i;
	
	while(1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		r1 = 0;
		for (i = 0; i < n; i++){
			
			scanf("%d %d %d", &num, &dis[0], &dis[1]);
			
			if (dis[0] + dis[1] > r1){
				r1 = dis[0] + dis[1];
				num1 = num;
			}
		}
		printf("%d %d\n", num1, r1);
	}
	return (0);
}

Measured memory_bytes: 600
def solve():
    N = int(input())
    S = input()
    cnt = {}
    for c in S:
        cnt[c] = cnt.get(c, 0) + 1
    total_triplets = cnt.get('R', 0) * cnt.get('G', 0) * cnt.get('B', 0)
    for stride in range(1, N):
        for i in range(0, N-2*stride):
            j = i + stride
            k = j + stride
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                total_triplets -= 1
    print(total_triplets)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9208
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int C = sc.nextInt();
        int n = 0;

        for (int i = 0; i < C; i++) {
            int m = sc.nextInt();
            n += m;
        }
        if (n % (N + 1) == 0) {
            System.out.println(n / (N + 1));
        } else {
            System.out.println(n / (N + 1) + 1);
        }
    }
}



Measured memory_bytes: 26248
/*input
4
aaaa
a
aaa
aa
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    set<string> ss;
    REP(i,n){
        string s;
        cin>>s;
        ss.insert(s);
    }
    cout<<sz(ss);
}


Measured memory_bytes: 19236
#include<stdio.h>
int main(void)
{
  int price=700;
  char top[3];
  scanf("%s",top);
    if(top[0]=='o') price=price+100;
    if(top[1]=='o') price=price+100;
    if(top[2]=='o') price=price+100;
  printf("%d",price);
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x >= y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x <= y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  while (n > 0) { if (n % 10 == 2) ans++; n /= 10; }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	i64 n;
	cin >> n;
	i64 a, b;
	cin >> a >> b;
	i64 t = abs(b-a);
	i64 ans;
	if (t % 2 == 0)ans = t / 2;
	else {
		i64 x, y;
		x = a-1;
		y = n - b;
		ans = min(x,y);
		ans++;
		ans += (t - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){ 
	long long l,r,f,s,i,j;
	scanf("%lld %lld",&l,&r);
	for(i = l;i <= r;i++){
		if(i % 2019 == 0){
			printf("0");
			return 0;
		}
	}
	f = l * r % 2019;
	for(i = l;i < r;i++){
		for(j = i + 1;j <= r;j++){
			s = i * j % 2019;
			if(s < f) f = s;
			if(f==1) break;
		}
	}
	printf("%lld",f);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, k;
string s;

int32_t main(){_

   cin >> s >> k;

   n = sz(s);

   vector<pair<int, int>> v;
   for (int i = 0; i < n; )
   {
      int j = i;
      while(j < n and s[i] == s[j])
         ++j;
      v.push_back({s[i] - 'a', j - i});
      i = j;
   }

   if (sz(v) == 1){
      int s = v[0].S;
      s *= k;
      cout<<s/2;
      exit(0);
   }

   if (v[0].F != v.back().F){
      int sum = 0;
      for (int i = 0; i < sz(v); ++i)
      {
         sum += (v[i].S / 2) * k;
      }
      cout<<sum;
      exit(0);
   }

   int ans = (v[0].S) / 2 + (v.back().S / 2);
   ans += ((v.back().S + v[0].S) / 2) * (k - 1);

   for (int i = 1; i < sz(v)-1; ++i)
   {
      ans += (v[i].S / 2) * k;
   }

   cout<<ans;


   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
 
void solve(){
    
    int n;
    cin>>n;

    ll a[n+1];

    rep(i,1,n+1)cin>>a[i];

    ll dp[n+1][n+1];
    
    for(int i=1;i<=n;i++)
        if(n%2)
        dp[i][i]=a[i];
        else
        dp[i][i]=-a[i];

    for(int len=2;len<=n;len++){
        for(int i=1;i+len-1<=n;i++){
            if((n-len)%2==0)
            dp[i][i+len-1]=max(dp[i+1][i+len-1]+a[i],dp[i][i+len-2]+a[i+len-1]);
            else
            dp[i][i+len-1]=min(dp[i+1][i+len-1]-a[i],dp[i][i+len-2]-a[i+len-1]);
        }
    }

    cout<<dp[1][n];

}
 
 
 
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
   
 
    int t=1,i=1;
   // cin>>t;
    
 
    while(t--){
       // cout<<"Case #"<<i++<<": ";
        solve();
    
    }
 
    return 0;
}

Measured memory_bytes: 70400
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int func(int a, int b) {
  string aa = to_string(a);
  string bb = to_string(b);
  return max(aa.size(), bb.size());
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
     ll n ; cin >> n;
     ll ans = INF;
     ll tmp = 0;
     for(ll i=1; i*i<=n; ++i) {
       if (n%i==0) {
         tmp = func(i, n/i);
       }
       chmin(ans,tmp);
     }
     ct(ans);
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<vi> vvi;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

#define MAX 10005
int dp[MAX][MAX];

int main(void) {
    int c,n,m;
    cin >> c >> n >> m;
    rep(i,MAX)rep(j,MAX) dp[i][j] = -INF;
    dp[0][0] = 0;
    rep(i,n){
        int s,p;
        cin >> s >> p;
        rep(j,c+1)if(dp[i][j] >= 0){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if(j+s <= c){
                dp[i+1][j+s] = max(dp[i+1][j+s], dp[i][j] + p);
            }
        }
    }
    rep(i,m){
        int t = c / (i+1);
        int ans = 0;
        rep(j,t+1)ans = max(ans, dp[n][j]);
        cout << ans*(i+1) << endl;
    }
}



Measured memory_bytes: 394140
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


ll gcd(ll a, ll b)
{
    if (a < b)
	swap(a, b);
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
    int n;
    while (cin >> n, n)
    {
	int m = n*(n+1)/2;
	vector<ll> even, odd;
	rep (i, m)
	{
	    ll t;
	    cin >> t;
	    if (t & 1)
		odd.push_back(t);
	    else
		even.push_back(t);
	}
	sort(all(odd));
	sort(all(even));

	int e = sqrt((double)even[0]*even[1] / odd[0] + 0.5);

	printf("%d\n", e);
	for (int i = 0; i < even.size(); ++i)
	    printf("%d%c", (int)(even[i] / e), i + 1 == even.size() ? '\n' : ' ');
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<18)+5;
const int N2=(1<<9)+5;
const int M=1e5+5;
const int inf=INT_MAX;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
int n,v[N],w[N],d[N],dp[N2][M];
int query(int x,int l)
{
	if (l<0) return -inf;
	if (d[x]<=9) return dp[x][l];
	return max(query(x/2,l),query(x/2,l-w[x])+v[x]);
}

signed main()
{
	memset(dp,0,sizeof(dp));
	n=read();
	d[0]=0;
	for (int i=1;i<=n;i++)
	{
		v[i]=read();
		w[i]=read();
		d[i]=d[i/2]+1;
	}
	for (int now=1;now<=n&&d[now]<=9;now++)
	{
		for (int i=0;i<=(int)1e5;i++) dp[now][i]=dp[now/2][i];
		for (int i=w[now];i<=(int)1e5;i++) dp[now][i]=max(dp[now][i],dp[now/2][i-w[now]]+v[now]);
	}
	int m=read();
	while (m--)
	{
		int x=read(),l=read();
		print(query(x,l));
	}

	return 0;
}

Measured memory_bytes: 208672
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

      
n,q = map(int,input().split())
uf = UnionFind(n)

for i in range(q):
  c,x,y = map(int,input().split())
  if c == 0:
    uf.union(x,y)
  else:
    print(uf.same(x,y)+0)





Measured memory_bytes: 5792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int n;
int cnt = 0;

int main(){
 cin >> n;
  for(int i = 1; i <= n; i++){
    int p;
    cin >> p;
    if(p != i) cnt++;
  }
  if(cnt > 2) cout << "NO" <<endl;
  else cout << "YES" <<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
d = {i: 0 for i in range(n)}
for i in range(m):
    a, b = map(int, input().split())
    d[a - 1] += 1
    d[b - 1] += 1
for i in d.values():
    if i % 2 == 1:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 15084