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

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;

  bool ans = false;

  for (int i = 0; i <= k; i++)
  {
    for (int j = 0; j <= k - i ; j++)
    {
      int aa, bb, cc;
      aa = a * pow(2, i);
      bb = b * pow(2, j);
      cc = c * pow(2, k-i-j);

      if(aa < bb && bb < cc)
      {
        ans = true;
      }
    }
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 4112
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<iomanip>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define ll long long
#define ld long double
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const ll MOD = 1000000007;// 10^9+7
const ll INF = (1ll << 60);


//変数

struct P {
	ld x, y, r;

	ld dist(P oth)const {
		ld d = powl(x - oth.x, 2) + powl(y - oth.y, 2);
		d = sqrtl(d);
		d -= r + oth.r;
		return max(0.L, d);
	}
};


constexpr int MAX_N = 1002;
ld cost[MAX_N][MAX_N];
ld d[MAX_N];
bool used[MAX_N];

int N;



//サブ関数
//入力
void input()
{
	vector<P> ps(2);
	cin >> ps[0].x >> ps[0].y >> ps[1].x >> ps[1].y;
	cin >> N;
	ps.resize(N + 2);
	REP(i, N)cin >> ps[i + 2].x >> ps[i + 2].y >> ps[i + 2].r;
	REP(i, N + 2)REP(j, N + 2)cost[i][j] = ps[i].dist(ps[j]);
}

void dijkstra(int s)
{
	fill(d, d + N + 2, INF);
	fill(used, used + N + 2, false);
	d[s] = 0;

	while (true) {
		int v = -1;
		REP(u, N + 2)if (!used[u] && (v == -1 || d[u] < d[v]))v = u;
		if (v == -1)break;
		used[v] = true;

		REP(u, N + 2)d[u] = min(d[u], d[v] + cost[v][u]);
	}
}

//計算
void calc()
{
	dijkstra(0);
	cout << fixed;
	cout << setprecision(15) << d[1] << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    string buf;
    for (auto c : s){
        if (c == 'B'){
            if (buf.size() > 0) buf.pop_back();
        }else{
            buf.push_back(c);
        }
    }
    cout << buf << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>

using lli = long long int;
lli inf = 1000000007;
using namespace std;


void solve()
{
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}

int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 256
indexes = []


def dfs(Ds, s, e, v=None):
    if e - s == 1:
        if v == Ds[s]:
            indexes.append((s, e))
        return Ds[s]
    else:
        center = (s + e) // 2
        left = dfs(Ds, s, center, v=v)
        right = dfs(Ds, center, e, v=v)

        left_m = - (10 ** 9)
        li = -1
        su = 0
        for i in range(center-1, s-1, -1):
            su += Ds[i]
            if left_m != max(left_m, su):
                left_m = max(left_m, su)
                li = i

        right_m = -(10 ** 9)
        ri = -1
        su = 0
        for i in range(center, e):
            su += Ds[i]
            if right_m != max(right_m, su):
                right_m = max(right_m, su)
                ri = i

        if left_m + right_m == v:
            indexes.append((li, ri))

        m = max(left, right, left_m + right_m)
        return m


def solve(N, T, As):
    Ds = [As[i + 1] - As[i] for i in range(N - 1)]
    max_v = dfs(Ds, 0, N - 1)
    dfs(Ds, 0, N - 1, v=max_v)
    return len(indexes)


if __name__ == "__main__":
    N, T = map(int, input().split(" "))
    As = list(map(int, input().split(" ")))
    print(solve(N, T, As))


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

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

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	cout << min(n*a,b);
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

for x in range(N, -1, -1):
    for y in range(N-x, -1, -1):
        z = N - x- y
        if (10000*x)+(5000*y)+(1000*z) == Y:
            print(x, y, z)
            exit()
            
print(-1, -1, -1)

Measured memory_bytes: 3060
use std::io;

fn christmas_eve() -> u32 {
    let mut n_k = String::new();
    io::stdin().read_line(&mut n_k).unwrap();
    let n_k: Vec<usize> = n_k.trim_right()
        .split_whitespace()
        .map(|v| v.parse::<usize>().unwrap())
        .collect();
    let n = n_k[0];
    let k = n_k[1];
    let mut h = vec![0; n];
    for elm in h.iter_mut() {
        let mut hi = String::new();
        io::stdin().read_line(&mut hi).unwrap();
        *elm = hi.trim_right().parse::<u32>().unwrap();
    }
    h.sort();

    h.iter().take(h.len() - k + 1)
        .enumerate()
        .map(|(i, v)| h[i + k - 1] - v)
        .min().unwrap()
}


fn main() {
    let ans = christmas_eve();
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int calc1(int n) {
	return pow(2, int(log2(n)));
}

int calc2(int n) {
	vector<int> pow2 = {1, 2, 4, 8, 16, 32, 64, 128};
	return *prev(upper_bound(pow2.begin(), pow2.end(), n));
}


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

	// cout << calc1(n) << endl;
	cout << calc2(n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	cout << 2 * b - a << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1000000007;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n;
  string s;
  cin >> n >> s;
 
  if(n%2) {
    cout << "No" << endl;
    return 0;
  }
  
  if(s.substr(0,n/2)==s.substr(n/2,n/2)) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static int MAX = 246913;
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        boolean[] isPrime = sieve();
        int[] answers = getAnswers(isPrime);
        
        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;
            System.out.println(answers[n]);
        }
    }
    
    public static boolean[] sieve() {
        boolean[] isPrime = new boolean[MAX];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i < MAX / 2; i++) {
            if (!isPrime[i]) continue;
            for (int j = i+i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
        
        return isPrime;
    }
    
    public static int[] getAnswers(boolean[] isPrime) {
        int[] answers = new int[MAX/2+1];
        answers[1] = 1;
        for (int i = 2; i <= MAX / 2; i++) {
            int temp = answers[i-1];
            if (isPrime[i]) temp--;
            if (isPrime[(i-1)*2+1]) temp++;
            answers[i] = temp;
        }
        return answers;
    }
}




Measured memory_bytes: 28272
package main

import (
	"fmt"
)

func main() {
	var K, N int
	fmt.Scanf("%d %d", &K, &N)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	max := 0
	for i := 0; i < N; i++ {
		dist := (A[(i+1)%N] - A[i] + K) % K
		if dist > max {
			max = dist
		}
	}
	fmt.Println(K - max)
}


Measured memory_bytes: 5632
n = int(input())
data = []
zoro = []
yn = False
for i in range(n):
    data = input().split()
    if data[0] == data[1]:
        zoro += [True]
    else:
        zoro += [False]
    if i > 1 and (zoro[i] == True and zoro[i-1] == True and zoro[i-2] == True):
        yn = True
print("Yes") if yn == True else print("No")

Measured memory_bytes: 9156
#include<stdio.h>
int main(void){
	long a,b,n;
	scanf("%ld%ld%ld",&a,&b,&n);
	if(b>n){
		printf("%ld\n",a*n/b-n/b*a);
	}else{
		printf("%ld\n",a*(b-1)/b-(b-1)/b*a);
	}
	return 0;
}


Measured memory_bytes: 1700
//============================================================================
// Name        : template.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x; cin >> x >> n;
	map<int, int> mp;
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	forn(i, n) {
		int q; cin >> q;
		mp[q] = 1;
	}

	int ans = 0;
	REP(i, 0, 99) {
		if (mp.find(x - i) == mp.end()) {
			ans = x - i;
			break;
		} else if (mp.find(x + i) == mp.end()) {
			ans = i + x;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3616
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, h := readInt(), readInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		b[i] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Sort(sort.Reverse(sort.IntSlice(b)))
	d := 0
	ib := 0
	ans := 0
	for d < h {
		if ib == n || b[ib] <= a[0] {
			ans += (h - d + a[0] - 1) / a[0]
			break
		}
		d += b[ib]
		ans++
		ib++
	}
	fmt.Println(ans)
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC086_B();
        }

        static void ABC086_B()
        {
            var ab = Console.ReadLine().Split(' ');
            var x = (int)Math.Sqrt(int.Parse(ab[0] + ab[1]));
            if (x * x == int.Parse(ab[0] + ab[1]))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, s, n) for (signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const double EPS = 1e-9;

signed main() {
	int h;
	while (cin >> h && h) {
		VV board(h, V(5));
		rep(i, h) rep(j, 5) cin >> board[i][j];
		int score = 0;

		while (true) {
			int added = 0;
			VV next = board;
			rep(i, h) rep(j, 3) {
				if (board[i][j] == board[i][j + 1] && board[i][j] == board[i][j + 2]) {
					added += next[i][j] + next[i][j + 1] + next[i][j + 2];
					next[i][j] = next[i][j + 1] = next[i][j + 2] = 0;
				}
			}
			score += added;
			board = next;

			rep(j, 5) {
				int shift = 0;
				for (int i = h - 1; i >= 0; i--) {
					int tmp = board[i][j];
					board[i][j] = 0;
					board[i + shift][j] = tmp;
					shift += tmp == 0;
				}
			}

			if (added == 0) break;
		}

		cout << score << endl;
	}
}

Measured memory_bytes: 3136
def dfs(s):
    d=len(s)
    if d>10:
        return
    
    if s!='':
        if s[0]!='0':
            num.add(int(s))

    for c in '0123456789':
        if s=='':
            dfs(s+c)
        else:
            if abs(int(s[-1])-int(c))<=1:
                dfs(s+c)

k=int(input())
num=set()

dfs('')
ans=list(num)
ans.sort()
print(ans[k-1])

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

#define llu             unsigned long long int
#define ll              long long int
#define f0(i, n)        for( i = 0 ; i <  n ; i++ )
#define f1(i, n)        for( i = 1 ; i <= n ; i++ )
#define ff(i, m, n)     for( i = m ; i <= n ; i++ )
#define sp(i)           fixed << setprecision( i )
#define pb              push_back
#define pf              push_front
#define nl              cout<<"\n";

///ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75
///                    ELIN(K-5)
///ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47

int main()
{
    ll k,n,m,i;
    cin>>k>>n;
    m=n;
    vector < ll > v;
    set < ll > s;
    while(n--)
    {
        ll a;
        cin>>a;
        v.pb(a);
    }
    sort(v.begin(),v.end());
    ll c=min(v[m-1]-v[0],k-v[m-1]+v[0]);
    //cout<<"c: "<<c<<endl;
    s.insert(c);
    f1(i, m-1)
    {
        ll b=min(v[i]-v[i-1],k-v[i]+v[i-1]);
        //cout<<"b: "<<b<<endl;
        s.insert(b);
    }
    auto j=s.rbegin();
    cout<<k-*j<<endl;

    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int sum = 0;
	string S;
	cin >> S;
	REP(i, S.size()) {
		int a = S[i] - '0';
		sum += a;
	}
	if (sum % 9)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 3776
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;

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

	int n,m; cin >> n >> m;

	int idx[55][55] = { 0 };
	int count[55] = { 0 };

	int a, b;
	rep(i, m)
	{
		cin >> a >> b;
		a--; b--;
		count[a]++,count[b]++;
	}

	rep(i, n) Print(count[i]);

	return 0;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct list{
    int key;
    struct list *next,*back;
};

struct list *list;
 
struct list * search(int key){
    struct list *x = list->next;
    while(x!=list && x->key!=key) x = x->next;
    return x;
}

void init(){
    list = (struct list *)malloc(sizeof(struct list));
    list->next = list;
    list->back = list;
}

void print(){
    struct list *x = list->next;
    int i = 0;
    while(1){
       if(x == list) break;
       if(i++ > 0) printf(" ");
        printf("%d", x->key);
        x = x->next;
    }
    printf("\n");
}

void insert(int key){
    struct list *x = (struct list *)malloc(sizeof(struct list));
    x->key = key;
    x->next = list->next;
    list->next->back = x;
    list->next = x;
    x->back = list;
}

void delete(struct list *x){
    if(x == list) return;
    x->back->next = x->next;
    x->next->back = x->back;
    free(x);
}

int main(){
    int key, n, i;
    char ins[20];
    scanf("%d", &n);
    init();
 
    for(i = 0; i < n; i++){
      scanf("%s %d", ins, &key);
      if(ins[0] == 'i'){
          insert(key);
      }
      else if(ins[0] == 'd'){
          if(strlen(ins) > 6){
              if(ins[6] == 'F') delete(list->next);
              else if(ins[6] == 'L') delete(list->back);
          }else {
              delete(search(key));
          }
      }
    }
    print();
    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m,c;cin>>n>>m>>c;
  vector<int> b(m);
  for(int i=0;i<m;i++)cin>>b[i];
  int ans=0;
  for(int i=0;i<n;i++){
    int t=c;
    for(int j=0;j<m;j++){
      int a;cin>>a;
      t += a*b[j];
    }
    if(t>0)ans++;
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
 
int main() {
    int n,m,x,y,bet,set;
    bool flag = false;
    cin >> n >> m >> x >> y;
    int a[n];
    int b[m];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int j=0;j<m;j++){
        cin >> b[j];
    }



    if(n==1){
        bet = a[0];
    }else if(n==2){
        bet = max(a[0],a[1]);
    }else{
        bet = a[0];
        for(int k=1;k<n;k++){
            bet = max(bet,a[k]);
        }
    }
        
        
    if(m==1){
        set = b[0];
    }else if(m==2){
        set = min(b[0],b[1]);
    }else{
        set = b[0];
        for(int l=1;l<m;l++){
            set = min(set,b[l]);
        }
    }

    for(int m=-100;m<101;m++){
        if(x<m && m<=y){
            if(bet<m && m<=set){
                cout << "No War" << endl;
                flag = true;
                break;
            }
        }
    }
    if(flag){
        return 0;
    }else{
        cout << "War" << endl;
    }
}

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

using namespace std;

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

	int ans = 0;
	int t = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(sum - a[i]) * abs(sum - a[i]);
	}
	sum++;
	for (int i = 0; i < n; i++) {
		t += abs(sum - a[i]) * abs(sum - a[i]);
	}
	cout << (ans > t ? t : ans) << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 桁数の入力
a = int(input())
# スペース区切りの整数の入力
b = input().split()
b = list(map(int, b))
c = list(range(1, a + 1))

d = []
for i, j in zip(b, c):
    d.append(i-j)
d.sort()
e = d[a // 2]
f = 0
for i in range(a):
    f += abs(d[i]-e)

print(f)

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

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


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

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();

        int a = 0,b = 0;

        for(int i = 1;i < s.length(); i++){
            if(s.charAt(i - 1) != s.charAt(i))a++;
        }

        for(int i = s.length() - 2;i >= 0; i--){
            if(s.charAt(i + 1) != s.charAt(i))b++;
        }

        System.out.println(Math.min(a, b));


    }


}


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


int main(){

  int r,c; cin >> r >> c;
  int row[r]={},col[c]={};
  int sum;
  for(int i=0; i<r; i++){
    for(int j=0; j<c; j++){
      int t;
      cin >> t;
      row[i] += t;
      col[j] += t;
      sum += t;
      cout << t << " ";
    }
    cout << row[i] << endl;
  }
  for(int j=0; j<c; j++){
    cout << col[j] << " ";
  }
  cout << sum << endl;

}

Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int main()
{
	double in;
	while(cin>>in)
	{
		if(in<=48) cout<<"light fly"<<endl;
		else if(48<in&&in<=51) cout<<"fly"<<endl;
		else if(51<in&&in<=54) cout<<"bantam"<<endl;
		else if(54<in&&in<=57) cout<<"feather"<<endl;
		else if(57<in&&in<=60) cout<<"light"<<endl;
		else if(60<in&&in<=64) cout<<"light welter"<<endl;
		else if(64<in&&in<=69) cout<<"welter"<<endl;
		else if(69<in&&in<=75) cout<<"light middle"<<endl;
		else if(75<in&&in<=81) cout<<"middle"<<endl;
		else if(81<in&&in<=91) cout<<"light heavy"<<endl;
		else cout<<"heavy"<<endl;
	}
  return 0;
}

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

using namespace std;

typedef long long llint;

int main() {
  llint n, a, b;
  cin >> n >> a >> b;
  llint ans = a * (n / (a + b));
  ans += min(n % (a + b), a);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    bool flag = false;
    for (int i = 1; i <= b; ++i) {
        flag = a * i % b == c;
        if (flag) break;
    }

    cout << (flag ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int P[15][15];
main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int A[15];
    for(int i=1;i<=n;i++)
        A[i] = i;

    int a,b;
    for(int i=1;i<=m;i++)
    {
        scanf("%d %d",&a,&b);
        P[a][b] = 1;
        P[b][a] = 1;
    }
    long long counter = 0;
    for(int i=2;i<=n;i++)
        {
            if(!P[A[i]][A[i-1]])
                break;
            if(i == n)
                counter++;
        }
    while(next_permutation(A+2,A+n+1))
    {
        for(int i=2;i<=n;i++)
        {
            if(!P[A[i]][A[i-1]])
                break;
            if(i == n)
                counter++;
        }

    }
    printf("%lld",counter);
}


Measured memory_bytes: 128
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int A=scan.nextInt();
    int B=scan.nextInt();
    int max=A*B;
    if(max<A+B){
      max=A+B;
    }
    if(max<A-B){
      max=A-B;
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(int, A, B);
	loop(C, 3) 
		if (A*B*(C + 1) & 1) {
			out("Yes");
			return 0;
		}
	out("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MX = 100005;

int main() {
  int n;
  cin >> n;
  vector<ll> cnt(MX);
  rep(i,n) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll tot = 0;
  rep(i,MX) tot += i*cnt[i];

  int q;
  cin >> q;
  rep(i,q) {
    int b, c;
    cin >> b >> c;
    tot -= b*cnt[b];
    tot -= c*cnt[c];
    cnt[c] += cnt[b]; cnt[b] = 0;
    tot += b*cnt[b];
    tot += c*cnt[c];
    cout << tot << endl;
  }
  return 0;
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		sc.close();

		int diffx = x2 - x1;
		int diffy = y2 - y1;
		int x3 = x2 - diffy;
		int y3 = y2 + diffx;
		int x4 = x3 - diffx;
		int y4 = y3 - diffy;

		System.out.println(String.format("%d %d %d %d", x3, y3, x4, y4));
	}
}


Measured memory_bytes: 23124
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  a.push_back(0);
  int ans=0;
  rep(i,n+1){
    int d=a[i]-a[i+1];
    if(d<0)continue;
    else ans+=d;
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 256
//nani?
#include<bits/stdc++.h>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef double ld;
using namespace std;
const ll inf=1e10+6;
const ll MOD=1e9+7;
const ll mod=998244353;
// ac cmtr;
const int MX = 1e6+5;
const int LG = 25;
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}
 
//---------------------------
 
ll a[MX];

int main(){
    fastio;
    ll n,k;
    cin>>n>>k;
    f(i,0,n) cin>>a[i];
    sort(a,a+n);
    ll rep = inf;
    for(int i = 0 ; i <= n-k ; i++){
        ll aux = a[i];
        ll aux2 = a[i+k-1];
        ll ans = 0;
        if(aux <= 0 && aux2 <= 0){
            ans = max(abs(aux),abs(aux2));
        }
        else if(aux >= 0 && aux2 >= 0){
            ans = max(aux,aux2);
        }
        else{
            ans = min(2*abs(aux) + abs(aux2) ,2*abs(aux2) + abs(aux)); 
        }
        rep = min(rep , ans);
    }
    cout<<rep<<endl;
}

Measured memory_bytes: 4392
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
int main() {
#define int long long
	vector<int> a;
	REP(i, 3) {
		int b;
		cin >> b;
		a.push_back(b);
	}
	sort(a.begin(), a.end());

	cout << min(a[1] + a[2],a[1] - a[0] + a[2] - a[1]) << endl;
	return 0;
}

Measured memory_bytes: 384
from collections import deque

N, M, P = map(int, input().split())

edges = [[] for _ in range(N)]
revEdges = [[] for _ in range(N)]
E = []
for _ in range(M):
    fr, to, cost = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append(to)
    revEdges[to].append(fr)
    E.append((fr, to, -(cost - P)))

def canVisit(start, edges):
    st = deque([start])
    minDist = [10**18] * N
    minDist[start] = 0

    while st:
        now = st.popleft()
        d = minDist[now] + 1
        for to in edges[now]:
            if minDist[to] > d:
                minDist[to] = d
                st.append(to)

    return [True if minDist[to] < 10**18 else False for to in range(N)]

canForward = canVisit(0, edges)
canBack = canVisit(N - 1, revEdges)

minDist = [10**18] * N
minDist[0] = 0
for i in range(N + 1):
    for fr, to, cost in E:
        d = minDist[fr] + cost
        if minDist[to] > d:
            if i == N and canForward[fr] and canBack[to]:
                print(-1)
                exit()

            minDist[to] = d

print(max(0, -minDist[N - 1]))


Measured memory_bytes: 53608
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int a,b,c,ans;cin>>a>>b>>c;
    ans=a+b+c;
    int m=max(a,max(b,c));
    ans+=9*m;
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a[100000], b[50000], count=0;
  int i, right, left, center, n, q;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &b[i]);
  }
  for(i=0; i<q; i++){
    right = n;
    left = 0; 
    while(left<=right){
      center = (right + left)/2;
      if(a[center] == b[i]) {
	count++;
	break;
      }
      else if(a[center] < b[i])
	left = center + 1;
      else
	right = center - 1;
    }
  }
  printf("%d\n", count);
  return 0;
}

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

const int MOD = 1000000007;

int main() {

  long long N, K, res;
  cin >> N >> K;

  res = 0;
  for(long long k=K; k<=N+1; k++){
    long long start = (k * (k - 1 ))/2;
    long long end = ((2*N - k + 1)*k)/2;
    long long sum = end - start + 1;
    res = (res + sum)%MOD;
  }
  cout << res << endl;
}

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := []int{0, 1, 2, 3, 5, 7, 8, 9}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		out := make([]int, 10)
		now := 0
		for n > 0 {
			out[now] = table[n%8]
			now++
			n /= 8
		}
		tmp := make([]string, 0)
		for i := now - 1; i >= 0; i-- {
			tmp = append(tmp, strconv.Itoa(out[i]))
		}
		fmt.Println(strings.Join(tmp, ""))
	}
}



Measured memory_bytes: 5932
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int f(dchar c, string s) {
        auto cs = s.dup.array;
        int n = cast(int)s.length - 1;
        for (int i = 0; i < s.length; i++) {

            bool ok = true;
            for (int j = 0; j < n; j++) {
                cs[j] = cs[j] == c ? cs[j] : cs[j+1];
                if (cs[j] != c) ok = false;
            }
            if (ok) {
                return i + 1;
            }
            n--;
        }
        return 0;
    }

    if (s.all!(c => c== s[0])) return 0;
    return s.map!(c => f(c, s)).reduce!min;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}


Measured memory_bytes: 380
import java.util.*;
public class Main{
    public static void main(String[]args){  
    Scanner sc=new Scanner(System.in);
    char[][]C=new char[2][3];
    String N=sc.next();
    String X=sc.next();
    for(int j=0;j<3;j++){
        C[0][j]=N.charAt(j);
        C[1][j]=X.charAt(j);
    }
    char[][]D=new char[2][3];
    D[0][0]=C[1][2];
    D[0][1]=C[1][1];
    D[0][2]=C[1][0];
    D[1][0]=C[0][2];
    D[1][1]=C[0][1];
    D[1][2]=C[0][0];
    if((C[0][0]==D[0][0])&&(C[0][1]==D[0][1])&&(C[0][2]==D[0][2])){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }
    
    
    
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0;i < 3;i++){
    if(S[i] == '1'){
      count++;
    }
    }
 cout << count << endl;
  }


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
	string s;
	cin >> s;
	
	int i = s.size();

	if (s.at(i - 1) == 's') {
		cout << s << "es";
	}
	else {
		cout << s << "s";
	}
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int t[22][22];
int dp[1<<16];
int solve(int b){
  if(b == (1 << n) - 1) return 0;
  if(dp[b]) return dp[b];

  int ret = 1 << 28;
  for(int i = 0; i < n; i++){
    if(b & 1 << i) continue;
    int pt = t[i][0];
    for(int j = 0; j < n; j++){
      if(b & 1 << j){
	pt = min(pt,t[i][j+1]);
      }
    }
    ret = min(ret,solve(b | 1 << i) + pt);
  }
  return dp[b] = ret;
}
int main(void){
  while(1){
    scanf("%d",&n); if(!n) break;
    memset(dp,0,sizeof(dp));
    for(int i = 0; i < n; i++){
      for(int j = 0; j <= n; j++){
	scanf("%d",&t[i][j]);
      }
    }
    printf("%d\n",solve(0));
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n,x;
    cin>>n>>x;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll count = 0;
    rep(i,n-1)
    {
        if(a[i]+a[i+1]>x)
        {
            ll dif = a[i+1]+ a[i]- x;
            count += dif;
            if(a[i+1]-dif>=0)a[i+1]-=dif;
            else
            {
                dif -= a[i+1];
                a[i+1] = 0;
                a[i]-=dif;
            }
            
        }
    }
    cout<<count<<endl;

    return 0;
}

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

int main(){
  
  int n;
  cin >> n;
  double a[10];
  string b[10];
  for(int i=0; i<n; i++) cin >> a[i] >> b[i];

   
    double sum=0;
     for(int i=0; i<n; i++){
     	if(b[i]=="BTC") sum+=a[i]*380000.0;
       else sum+=a[i];
     }
    cout << sum << endl;
}

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

using namespace std;

typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<ll> a(n, 0), sum(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

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

    int ans = 1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] <= 2 * sum[i]) ++ans;
        else break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
const db pi = acos(-1.0);
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 1e5 + 10;
int n, m;
int x[N], y[N];
int num[N], vis[N];

int main()
{
	n = read();
	m = read();
    rep(i, 1, m)
    {
    	x[i] = read();
    	y[i] = read();
    }
    rep(i, 1, n) num[i] = 1;
    vis[1] = 1;
    rep(i, 1, m)
    {
        int s = x[i];
        int e = y[i];
        num[s] --;
        num[e] ++;
        if (vis[s]) vis[e] = 1;
        if (num[s] == 0)
        	if (vis[s])
        		vis[s] = 0;
    }
    int res = 0;
    rep(i, 1, n)
        if (vis[i])
            res ++;
    printf("%d\n", res);
}



Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int a,b,c,d; cin>>a>>b>>c>>d;
  int overlap = 0;

  if(a >= d || b <= c) {
    overlap = 0;
  } else {
    int mid_left = max(a, c);
    int mid_right = min(b, d);
    overlap = mid_right - mid_left;
  }

  cout << overlap << endl;
}


Measured memory_bytes: 256
require 'set'

n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }
abc = abc.map {|a, b, c| [a, b, -1*(c-tax)] }

# get adjuscent list
graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
abc.each do |a, b, c|
  graph[a] << b
  r_graph[b] << a
end

# build from_1 from_n
def reachable(s, g)
  q=[s]
  visited = Set.new(q)
  until q.empty?
    from = q.shift
    g[from].each do |to|
      next if visited.include?(to)
      visited.add(to)
      q.push(to)
    end
  end
  visited
end

from_1 = reachable(1, graph)
from_n = reachable(n, r_graph)
av = from_1 & from_n
edges=abc.select {|a, b, c| av.include?(a) && av.include?(b) }

#p av
#p edges

# b-f method
updated = false
INF= 10**12
dist = Array.new(n+1, INF)
dist[1]=0
n.times do
  updated = false
  edges.each do |from, to, cost|
    next if dist[from]==INF

    if dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated = true
    end

  end
  break unless updated
end

if updated
  p -1
  exit
end

# answer
p [0, -dist[n]].max




Measured memory_bytes: 3452
#include <cstdio>
#include <vector>
using namespace std;

int main(){
	int n;
	while(scanf("%d", &n), n){
		vector<int> v(n);
		for(int i = 0; i < n; ++i){
			scanf("%d", &v[i]);
		}

		int ans = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < i; ++j){
				if(v[j] > v[i]){
					++ans;
				}
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1032
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Print(lcm(a, b))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func gcd(a, b int) int {
	for i := min(a, b); i >= 1; i-- {
		if a % i == 0 && b % i == 0 {
			return i
		}
	}
	return 0
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
using namespace std;

int main()
{
/* ---------------------------------- */
	int n,tmp,sum=0;
	std::vector<int> v;

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		v.push_back(tmp);
	}
/* ---------------------------------- */

	std::sort(v.rbegin(), v.rend()); //降順

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

	if(v[0]<sum){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 384
import itertools

# N, M, Q = 3, 4, 3
# ARR = [
#     [1, 3, 3, 100],
#     [1, 2, 2, 10],
#     [2, 3, 2, 10]
# ]

# 4 6 10
# 2 4 1 86568
# 1 4 0 90629
# 2 3 0 90310
# 3 4 1 29211
# 3 4 3 78537
# 3 4 2 8580
# 1 2 1 96263
# 1 4 2 2156
# 1 2 0 94325
# 1 4 3 94328


N, M, Q = map(int, input().split())
ARR = []
for i in range(Q):
    ARR.append(list(map(int, input().split())))


def calculate(n, m, q, arr):
    result = []
    for comb in itertools.combinations_with_replacement(range(1, m + 1), n):
        result.append(mmm(list(comb), arr))

    print(max(result))


def mmm(comb, arr):
    result = 0

    for ar in arr:
        if (comb[ar[1] - 1] - comb[ar[0] - 1]) == ar[2]:
            result = result + ar[3]
    return result


calculate(N, M, Q, ARR)


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

int main() {
	int n; cin>>n;
	int arr[n];
	for(int i=0; i<n; i++) cin>>arr[i];
	int dp[n];
	
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	dp[2]=min(dp[1]+abs(arr[2]-arr[1]), abs(arr[2]-arr[0]));
	
	for(int i=3; i<n; i++){
	    int a=dp[i-2]+abs(arr[i]-arr[i-2]);
	    int b=dp[i-1]+abs(arr[i]-arr[i-1]);
	    
	    dp[i]=min(a, b);
	}
	
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
S = input()
N = len(S)
A = []
for s in range(N):
    A.append(S[s])
B = []
C = []
B = A[:(N-1)//2]
C = A[(N+3)//2-1:N]
if B == C:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9112
#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;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define ps(x,y) fixed<<setprecision(y)<<x
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
int main()
{
    boost;
    ll n,i,j,x,t,y,m;
    cin>>n>>m;
    ll ans=0;
    if(n>=2) ans+=(n*(n-1))/2;
    if(m>=2) ans+=(m*(m-1))/2;
    cout<<ans;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
dic = {n + 1:set() for n in range(N)}

for m in range(M):
    a, b = list(map(int, input().split()))
    dic[a].add(b)
    dic[b].add(a)

def check(a, b):
    Sa = dic[a] - {b}
    stack = list(Sa)
    al = {a}
    while stack != []:
        p = stack.pop()
        al.add(p)
        stack += list(dic[p] - al)
        if b in stack:
            return False
    return True

res = 0
for n in range(1,N+1):
    S = dic[n]
    if len(S) == 1:
        res += 1
        dic[S.pop()].discard(n)
        continue
    elif len(S) == 0:
        continue
    else:
        for s in S:
            if check(n, s):
                res += 1
                dic[s].discard(n)
                continue

print(res)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>

using namespace std;

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

  if(num == 1) cout << "NO" << endl;

  vector<int> number;

  int temp;
  for(int i=0; i<num; ++i){
    cin >> temp;
    number.push_back(temp);
  }

  int sum = 0;
  for(auto v:number){
    sum += v;
  }

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

Measured memory_bytes: 892