akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string S, T;
    cin >> S >> T;

    int ans = 1000;
    for (int offset = 0; offset+T.length() <= S.length(); ++offset) {
        int diff = 0;
        rep(i, T.length()) {
            if (T[i] != S[offset+i]) ++diff;
        }
        ans = min(ans, diff);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include <stdlib.h>
int compar(const int*,const int*);

int main(void){
  int N,M,X,Y,i,war_state=0,k,MaxX,MinY;
  scanf("%d %d %d %d",&N,&M,&X,&Y);
  int Xary[N];
  int Yary[M];
  for(i=0;i<N;i++){
    scanf("%d",&Xary[i]);
  }
  for(i=0;i<M;i++){
    scanf("%d",&Yary[i]);
  }

    qsort(Xary,sizeof(Xary)/sizeof(Xary[0]),sizeof(int),(int (*)(const void *, const void *))compar);
    qsort(Yary,sizeof(Yary)/sizeof(Yary[0]),sizeof(int),(int (*)(const void *, const void *))compar);
MaxX = Xary[N-1];
MinY = Yary[0];
if(MaxX<X)MaxX = X;
if(MinY>Y)MinY = Y;

if((MaxX<MinY)&&(MaxX!=MinY)){
  for(i=0;i<N;i++){
    if(Xary[i] == X){
      war_state = 1;
      break;
    }
    for(k=0;k<N;k++){
      if(i == k)continue;
      if(Xary[i] == Xary[k]){
        war_state = 1;
        break;
      }
    }
  }

  for(i=0;i<M;i++){
    if(Yary[i] == Y){
      war_state = 1;
      break;
    }
    for(k=0;k<M;k++){
      if(i == k)continue;
      if(Yary[i]==Yary[k]){
        war_state = 1;
        break;
      }
    }
  }
}else{
  war_state = 1;
}
//printf("%d %d\n",MaxX,MinY );
  if(war_state == 0){
    printf("No War");
  }else{
    printf("War" );
  }
  return 0;
}

int compar(const int *val1, const int *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s,t,a;
    cin>>s>>t>>a;
    if (s.back()==t[0]&&t.back()==a[0])
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int i=1;
    vector<pair<int, int>> res;
    for(; i<N-1; i++){
        if(A.at(i) > 0) break;
        res.emplace_back(A.back(), A.at(i));
        A.back() -= A.at(i);
    }
    for(; i<N-1; i++){
        res.emplace_back(A.front(), A.at(i));
        A.front() -= A.at(i);
    }
    res.emplace_back(A.back(), A.front());

    cout << (res.back().first - res.back().second) << endl;
    for(auto v : res){
        cout << v.first << " " << v.second << endl;
    }

    return 0;
}

Measured memory_bytes: 3188
#!/usr/bin/ruby
#encoding: utf-8

n = gets.to_i
h = gets.split.map(&:to_i)

dp = Array.new(n,1e9.to_i)

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

(0..n-3).each do |i|
  a = dp[i+1] + (h[i+2]-h[i+1]).abs
  b = dp[i] + (h[i+2]-h[i]).abs
  dp[i+2] = [a,b].min
end

puts dp[n-1]

Measured memory_bytes: 11396
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == "END OF INPUT") break;
            string[] s2 = s.Split(' ');
            foreach (var x in s2)
                Console.Write(x.Length);
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 15900
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);	
	int n;
	cin>>n;
	vector<long long> all_n(n);
	long long sum = 0;
	for(int i = 0 ; i < n ; i++)
	{
		cin>>all_n[i];
		sum += all_n[i];
	}
	
	
	long long pre_sum = 0;
	long long aft_sum = 0;
	vector<long long> abs_n;
	for(int i = 0 ; i < n-1 ; i++)
	{
		pre_sum += all_n[i];
		aft_sum = sum - pre_sum;
		abs_n.push_back(abs(pre_sum-aft_sum));
	}
	
	sort(abs_n.begin(), abs_n.end());
	cout<<abs_n[0];
    return 0;
}

Measured memory_bytes: 3956
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: i32 = 1000000007;

fn is_prime(x: usize) -> bool {
  if x == 1 {
    return false;
  }
  let mut i = 2;
  while i * i <= x {
    if x % i == 0 {
      return false;
    }
    i += 1;
  }
  true
}

#[fastout]
fn main() {
  input! {
    q: usize,
    lines: [(usize, usize); q],
  }
  let mut st = SegmentTree::new(100001, |a, b| a + b, 0);
  for i in (1..=100000).step_by(2) {
    if is_prime(i) && is_prime((i + 1) / 2) {
      st.set(i, 1);
    }
  }
  st.build();
  for (l, r) in lines {
    println!("{}", st.query(l, r + 1));
  }
}

struct SegmentTree<T> {
  v: Vec<T>,
  f: fn(T, T) -> T,
  e: T,
  n: usize,
}

impl<T: Copy> SegmentTree<T> {
  fn new(size: usize, f: fn(T, T) -> T, e: T) -> Self {
    let mut n = 1;
    while n < size {
      n <<= 1;
    }
    let v: Vec<T> = vec![e; n * 2];
    SegmentTree { v, f, e, n }
  }
  fn set(&mut self, k: usize, x: T) {
    self.v[k + self.n] = x;
  }
  fn build(&mut self) {
    for i in (1..self.n).rev() {
      self.v[i] = (self.f)(self.v[i * 2 + 0], self.v[i * 2 + 1]);
    }
  }
  fn query(&self, a: usize, b: usize) -> T {
    let mut l = self.e;
    let mut r = self.e;
    let mut a = a + self.n;
    let mut b = b + self.n;
    while a < b {
      if a & 1 == 1 {
        l = (self.f)(l, self.v[a]);
        a += 1;
      }
      if b & 1 == 1 {
        b -= 1;
        r = (self.f)(self.v[b], r);
      }
      a >>= 1;
      b >>= 1;
    }
    (self.f)(l, r)
  }
  fn update(&mut self, k: usize, x: T) {
    self.v[k + self.n] = x;
    let mut k = k + self.n;
    while (k >> 1) > 0 {
      k >>= 1;
      self.v[k] = (self.f)(self.v[k * 2 + 0], self.v[k * 2 + 1]);
    }
  }
  fn reset(&mut self, k: usize) {
    self.update(k, self.e);
  }
}


Measured memory_bytes: 5528
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
#define MOD 998244353ll
using namespace __gnu_pbds;
using namespace std;

int dp[3010][3010];

signed main()
{
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for(int i=a;i<=c;i++){
		for(int j=b;j<=d;j++){
			if(i==a&&j==b){
				dp[i][j]=1ll;
			}
			else if(i==a){
				dp[i][j]=(dp[i][j-1]*i)%MOD;
			}
			else if(j==b){
				dp[i][j]=(dp[i-1][j]*j)%MOD; 
			}
			else{
				dp[i][j]=(dp[i][j-1]*i)%MOD+(dp[i-1][j]*j)%MOD-(dp[i-1][j-1]*(i-1)*(j-1))%MOD;
				dp[i][j]%=MOD;
				if(dp[i][j]<0ll) dp[i][j]+=MOD;
			}
		}
	}
	cout<<dp[c][d]<<endl;
	return 0;
} 

Measured memory_bytes: 74016
#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define m 1000000007

ll modpow(ll a, ll n, ll mod);
 
int main(){
  ll x,y,s,t,n;
  cin >> x >> y;
  if((2*x-y)%3 != 0 || (2*y-x)%3 != 0 || (2*x-y) < 0 || (2*y-x) < 0){
    printf("0\n");
    return 0;
  }else{
    s = (2*y-x)/3;
    t = min((2*x-y)/3,s);
  }
  n = (x+y)/3;
  ll ans = 1;
  for(int i = n-t+1; i <= n; i++){
    ans = ans*i%1000000007;
    // printf("%lld\n", ans);
  }
  for(int i = 1; i <= t; i++){
    ans = ans*modpow(i,1000000005,1000000007)%1000000007;
    // printf("%lld %d\n", ans,i);
  }
  printf("%lld\n", ans);
  return 0;
}
 
ll modpow(ll a, ll n, ll mod){
  ll res = 1;
  while(n > 0){
    if(n & 1) res = res*a%mod;
    a = a*a%mod;
    n >>= 1;
  }
  return res;
}

Measured memory_bytes: 256
//13, 04, 2019, 09:35:28 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

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

    int a, b;

    cin >> a >> b;

    cout << max({a + max(a - 1, b), b + max(a, b - 1)}) << endl;

    
    return 0;
}

Measured memory_bytes: 256
# D - Dice in Line
from itertools import accumulate


def main():
    N, K, *P = map(int, open(0).read().split())
    # cumsum[i] = cumulative sum of expected values in [0, i]
    cumsum = tuple(accumulate([0] + [(i + 1) / 2 for i in P]))
    ans = max(right - left for left, right in zip(cumsum, cumsum[K:]))
    print(ans)


if __name__ == "__main__":
    main()


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

#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  // int64_t a, ans;
  // mp::cpp_dec_float_50 b;
  // cin >> a >> b;

  // b *= a;
  // ans = (int64_t)b;

  int64_t a;
  double b;
  cin >> a >> b;
  a = (a * (int)round(b * 100)) / 100;

  cout << a << '\n';

  return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define ing long long
#define MAX (1LL<<31)-1
signed main(){
  int n,q;
  cin>>n>>q;
  int bucket[1010];
  int data[100010];
  int sq=1000;
  for(int i=0;i<1010;i++)bucket[i]=MAX;
  for(int i=0;i<100010;i++)data[i]=MAX;
  for(int cnt=0;cnt<q;cnt++){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      int ans=MAX,i=x;
      for(;i<=y;i++){
	if(i%sq==0)break;
	ans=min(ans,data[i]);
      }
      for(;i+sq-1<=y;i+=sq){
	ans=min(ans,bucket[i/sq]);
      }
      for(;i<=y;i++){
	ans=min(ans,data[i]);
      }
      cout<<ans<<endl;
    }else{
      data[x]=y;
      bucket[x/sq]=MAX;
      for(int i=0;i<sq;i++){
	bucket[x/sq]=min(bucket[x/sq],data[(x/sq)*sq+i]);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3512
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in();
	auto v = VVI(bool, 100, n, false);
	REP(i, n) {
		ll h = in();
		REP(j, h) {
			v[j][i] = true;
		}
	}
	ll ans = 0;
	REP(i, 100) {
		bool pri = false;
		REP(j, n) {
			if (!pri&&v[i][j])++ans;
			pri = v[i][j];
		}
	}
	cout << ans << endl;
}

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

using namespace std;

int get_cost(vector<int> &nums, int target) {
	int cost = 0;
	for (int num : nums) {
		cost += (num - target) * (num - target);
	}
	return cost;
}
int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> nums(n);
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	int result = 10000000;
	for (int i = -100; i <= 100; i++) {
		result = min(result, get_cost(nums, i));
	}
	cout << result << '\n';
	return 0;
}

Measured memory_bytes: 256
s = input()

if len(s) % 2 == 1:
  print('No')
else:
  ans = "Yes"
  for i in range(len(s)):
    if i % 2 == 0 and s[i] != 'h':
      ans = "No"
      break
    if i % 2 == 1 and s[i] != 'i':
      ans = "No"
      break

  print(ans)

Measured memory_bytes: 9020
def main():
    n, a, b = map(int, input().split())
    count = n // (a + b)
    amari = n % (a + b)

    if amari - a < 0:
        print(count*a + amari)
    else:
        print((count + 1) * a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        String[] l = sc.nextLine().split(" ");

        int n = Integer.parseInt(s1[0]);
        int x = Integer.parseInt(s1[1]);

        int result=1;
        int sum=0;
        for (int i = 0; i < n;i++) {
        	sum=sum+Integer.parseInt(l[i]);
        	if (sum <= x) {
        		result++;
        	} else {
        		break;
        	}
        }

        System.out.println(result);
    }



}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        G.at(A - 1).push_back(B - 1);
        G.at(B - 1).push_back(A - 1);
    }
    vector<int> dist(N, -1), ans(N);
    queue<int> que;
    dist.at(0) = 0;
    ans.at(0) = 0;
    que.push(0);
    while (!que.empty()) {
        int V = que.front();
        que.pop();
        for (int i = 0; i < G.at(V).size(); i++) {
            if (dist.at(G.at(V).at(i)) != -1) {
                continue;
            }
            dist.at(G.at(V).at(i)) = dist.at(V) + 1;
            ans.at(G.at(V).at(i)) = V;
            que.push(G.at(V).at(i));
        }
    }
    for (int i = 0; i < N; i++) {
        if (dist.at(i) == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << ans.at(i) + 1 << endl;
    }
}

Measured memory_bytes: 10744
using System;
using System.Linq;
class program{
  static void Main(){
    int n = int.Parse(Console.ReadLine());
    int[] a = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int[] table = new int[100001];
    long ans = 0;
    for(int i = 0;i<n;i++){
      table[a[i]]++;
      ans += a[i];
    }
    n = int.Parse(Console.ReadLine());
    for(int i = 0;i<n;i++){
      int[] bc = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      ans += (bc[1]-bc[0])*table[bc[0]];
      table[bc[1]] += table[bc[0]];
      table[bc[0]] = 0;
      Console.WriteLine(ans);
    }
  }
}

Measured memory_bytes: 47004
n = int(input())
S = [str(_) for _ in range(1,14)]
H = [str(_) for _ in range(1,14)]
C = [str(_) for _ in range(1,14)]
D = [str(_) for _ in range(1,14)]
for _ in range(n):
    a,b = input().split()
    if a=="S":
        S.remove(b)
    elif a=="H":
        H.remove(b)
    elif a=="C":
        C.remove(b)
    else:
        D.remove(b)
for s in S:
    print("S "+s)
for h in H:
    print("H "+h)
for c in C:
    print("C "+c)
for d in D:
    print("D "+d)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;

	int n;
	cin >> n;
	string s;
	cin >> s;
	int i = 0, j = n - 1, count = 0;
	while (i < j) {
		if (s[i] == 'W' && s[j] == 'R') {
			swap(s[i], s[j]);
			count++;
			i++, j--;
		}
		if (s[i] == 'R')
			i++;
		if (s[j] == 'W')
			j--;
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 3736
#include<stdio.h>

int main(){
	
	int k;
	k>=1 && k<=100;
	int x;
	x>=1 && x<=100000;
	scanf("%d %d",&k,&x);
	
	if(k * 500>=x){
		printf("Yes");
	}
	else if(k * 500<x){
		printf("No");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
using namespace std;


int main() {
    int h, n;
    cin >> h >> n;
    int x;
    int sum = 0;
    for(int i=0; i<n; i++) {
        cin >> x;
        sum = sum + x;
    }   
    if(sum >= h) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
// ABC053 B - A to Z String
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char *S;
    S = malloc(sizeof(char) * 200001);
    scanf("%s", S);

    int start = -1;
    int i = 0;
    while (S[i] != '\0') {
        if (S[i] == 'A') {
            if (start == -1) {
            start = i;
            }
        }
        i++;
    }
    int end = i + 1;
    while (i > start) {
        if (S[i] == 'Z') {
            end = i;
            break;
        }
        i--;
    }
    
    printf("%d\n", end - start + 1);

    return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, M; cin >> N >> M;
  string A[N]; rep(i, N) cin >> A[i];
  string B[M]; rep(i, M) cin >> B[i];

  string result = "No";
  rep(i, N-M+1) rep(j, N-M+1) {
    bool tmp = true;
    rep(x, M) rep(y, M) if (A[i+x][j+y]!=B[x][y]) tmp = false;
    if (tmp) { result = "Yes"; break; }
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {

  ll n,m;cin>>n>>m;

  if(n>m)swap(n,m);

  if(n<2){
    if(m!=1)out(n*m-2)
    else out(1);
  }
  else out((n-2)*(m-2));

  return 0;
}


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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int n, m, x;
  cin >> n >> m >> x;
  
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i=0; i<n; i++) {
    cin >> c[i];
    for(int j=0; j<m; j++) {
      cin >> a[i][j];
    }
  }

  int min = 1200001;
  for(int i=0; i<(1<<n); i++) {
    bitset<12> b_i(i);
    vector<int> all(m);
    int cost = 0;
    for(int j=0; j<n; j++) {
      if(b_i.test(j) == 1) {
        cost += c[j];
        for(int k=0; k<m; k++) {
          all[k] += a[j][k];
        }
      }
    }
    bool ok = true;
    for(int j=0; j<m; j++) {
      if(all[j] < x) {
        ok = false;
        break;
      }
    }
    if(ok && cost < min) {
      min = cost;
    }
  }

  if(min == 1200001) {
    cout << -1 << endl;
  }
  else {
    cout << min << endl;
  }
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
const ll INF = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int nax=105;
//const int nax1 = 105;

int main()
{
	FASTIO;
	int n;
	int ans=0;
	cin >> n;
	vector<vector<int>> arr(n,vector<int>(3));
	vector<vector<int>> dp(2,vector<int>(3));
	
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin >> arr[i][j];
		}
	}
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
				dp[i%2][j] = max(arr[i-1][j]+dp[(i+1)%2][(j+1)%3], arr[i-1][j]+ dp[(i+1)%2][(j+2)%3]);
				ans = max(ans, dp[i%2][j]);
				//cout << dp[i%2][j] << " ";
		}
		//cout << "\n";
	}
	
	cout << ans << "\n";
	

	return 0;
}


Measured memory_bytes: 5760
/*
 *  Author : Jun_SH
 *  Solution for ABC 145 C
 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;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 f*x;
}
double a[10][2];
main(){
    int n;
    cin>>n;
    double ans=0;
    for(int i=0;i<n;++i){
        cin>>a[i][0]>>a[i][1];

    }
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j){
            ans+=sqrt((a[j][0]-a[i][0])*(a[j][0]-a[i][0])+(a[j][1]-a[i][1])*(a[j][1]-a[i][1]));
        }
    ans/=(double)n;
    printf("%.10lf\n",ans);
}


Measured memory_bytes: 256
//08
#include<iostream>
#include<map>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
  int cs=0;
  for(int n,w;cin>>n>>w,n|w;){
    map<int,int> m[1001];
    m[0][0]=0;
    for(int i=0;i<n;i++){
      int o;
      cin>>o;
      for(map<int,int>::iterator it=m[i].begin();it!=m[i].end();it++){
	int nb=it->first+o;
	if(!m[i+1].count(nb)||m[i+1][nb]>it->second){
	  m[i+1][nb]=it->second;
	}
	int bc=it->second+abs(w-it->first-o);
	if(!m[i+1].count(0)||m[i+1][0]>bc){
	  m[i+1][0]=bc;
	}
      }
    }
    int mc=1<<30;
    for(map<int,int>::iterator it=m[n].begin();it!=m[n].end();it++){
      mc=min(mc,it->second+max(0,it->first-w));
    }
    cout<<"Case "<<++cs<<": "<<mc<<endl;
  }
  return 0;
}

Measured memory_bytes: 24748
#include<bits/stdc++.h>
using namespace std;
string s;
string c[4] = {"maerd", "remaerd", "esare", "resare"};
int main(){
	cin>>s;
	int i=0;
	int len=s.size();
	reverse(s.begin(),s.end());
	while(i<len){
		bool flag=false;
		for(int j=0;j<4;j++){
			string tmp=s.substr(i,c[j].size());
			if(tmp==c[j]){
				i+=c[j].size();
				flag=true;
			}
		}
		if(!flag){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 512
# coding: utf-8
# Your code here!

#n = int(input())
#a = [int(i) for i in input().split()]
from fractions import gcd 



a,b,c,d = [int(i) for i in input().split()]

def res(n):#n以下
    return n - n//c - n//d + n//(c*d//gcd(c,d))

print(res(b) - res(a-1))    









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

int main() {
  int n;
  set<string> ans;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    for(int j=0; j<s.size()-1; j++) {
      string a1="",a2="",b1="",b2="";
      for(int i=0; i<s.size(); i++) {
	if(i<=j) a1+=s[i];
	else b1+=s[i];
      }
      for(int i=s.size()-1; i>=0; i--) {
	if(i>j) b2+=s[i];
	else a2+=s[i];
      }
      ans.insert(a1+b1);
      ans.insert(a1+b2);
      ans.insert(a2+b1);
      ans.insert(a2+b2);
      ans.insert(b1+a1);
      ans.insert(b1+a2);
      ans.insert(b2+a1);
      ans.insert(b2+a2);
    }
    cout << ans.size() << endl;
    ans.clear();
  }
  return 0;
}   


Measured memory_bytes: 1316
def d_ki():
    import sys
    input = sys.stdin.readline
    N, Q = [int(i) for i in input().split()]

    tree = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) for i in input().split()]
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    ans = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        ans[p - 1] += x

    # 1次元配列だったら単純に累積和を取ればいいのだが、木なので
    # DFSをしなければならない
    q = [0]
    is_visited = [False] * N
    while q:
        current = q.pop()
        is_visited[current] = True
        for child in tree[current]:
            if is_visited[child]:
                continue
            ans[child] += ans[current]
            q.append(child)
    return ' '.join(map(str, ans))

print(d_ki())

Measured memory_bytes: 121420
#include<stdio.h>
int main(void)
{
   int a,b;
   scanf("%d %d",&a, &b);

   if(a > b)
      printf("a > b\n");
   else if(a < b)
      printf("a < b\n");
   else
      printf("a == b\n");

   return 0;
}

Measured memory_bytes: 580
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int, int> P;
typedef long long ll;

vector<ll> lun;

void dfs(int d, ll  now) {
	lun.push_back(now);

	if (d == 10) return;

	for (int i = -1; i <= 1; i++) {
		int add = now % 10 + i;
		if (add >= 0 && add <= 9) dfs(d + 1, now * 10 + add);
	}
}

int main() {
	int k;
	cin >> k;
	rep(i, 9) dfs(1, i + 1);
	sort(all(lun));
	dunk(lun[k - 1]);
	return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

int dp[4001][4001];
int main()
{
	string s;
	string t;
	while (cin >> s && s != "")
	{
		memset(dp, 0, sizeof(dp));
		cin >> t;
		int ans = 0;
		for (int i = 0; i < s.size(); i++)
		{
			for (int j = 0; j < t.size(); j++)
			{
				if (s[i] == t[j])
				{
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = max(dp[i + 1][j + 1], ans);
				}
				else
				{
					dp[i + 1][j + 1] = 0;
				}
			}
		}

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

Measured memory_bytes: 63752
#include <stdio.h>

int main(void){
  int a, b, c, i, cnt = 0;
  scanf("%d %d %d", &a, &b, &c);
  for(i = a; i <= b; i++){
    if(c % i == 0)
      cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 596
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        /* int型はあふれがち */
        var N = long.Parse(ReadLine());
        var array = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var cum = CumulativeSum(array).GroupBy(x=>x);
        long sum = 0;
        foreach (var item in cum)
        {
            sum += (long)item.Count() * (item.Count() - 1) / 2;
        }
        WriteLine(sum);
    }
    public static IEnumerable<long> CumulativeSum(IEnumerable<long> array)
    {
        yield return 0;
        long tmp = 0;
        foreach (var num in array)
            yield return tmp += num;
    }
}

Measured memory_bytes: 41568
m = gets.chomp.to_i
commands = []
m.times do 
    cmd, v = gets.chomp.split(' ')
    v = v.to_i unless v.nil?
    commands.push([cmd, v])
end

def insert(tree, z)
    y = nil
    x = tree[:root]
    # p x, y, z
    until x.nil? do
        y = x
        # puts "x[:key] = #{x[:key]}"
        # puts "z[:key] = #{z[:key]}"
        if z[:key] < x[:key] then
            x = tree[x[:l]]
        else
            x = tree[x[:r]]
        end
    end
    z[:p] = y[:key] unless y.nil?
    if y.nil? then
        tree[:root] = z
        tree[z[:key]] = z
    elsif z[:key] < y[:key]
        y[:l] = z[:key]
        tree[z[:key]] = z
    else
        y[:r] = z[:key]
        tree[z[:key]] = z
    end
end

def preParse(tree, key)
    return if key == nil
    print " #{key}"
    preParse(tree, tree[key][:l])
    preParse(tree, tree[key][:r])    
end

def inParse(tree, key)
    return if key == nil
    inParse(tree, tree[key][:l])
    print " #{key}"
    inParse(tree, tree[key][:r])
end

tree = { root: nil }
commands.each do |cmd|
    if cmd[0] == "insert" then
        node = { key: cmd[1], p: nil, l: nil, r: nil }
        insert(tree, node)
    else
        # p tree
        inParse(tree, tree[:root][:key])
        puts "\n"
        preParse(tree, tree[:root][:key])
        puts "\n"
    end
end



Measured memory_bytes: 192012
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d,x;
	cin>>n>>d>>x;
	int ans=x;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		ans+=(d-1)/a+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vl l(n);
    rep(i, n) cin >> l[i];
    int ans = 0;
    rep(i, n-2) for (int j=i+1; j<n-1; j++) for(int k=j+1; k<n; k++) {
        vector<int> v(3);
        v[0] = l[i];
        v[1] = l[j];
        v[2] = l[k];
        sort(whole(v));
        if (v[0]==v[1] || v[1]==v[2]) continue;
        if (v[2]>=v[0]+v[1]) continue;
        ans++;
    }
    
    
    pr(ans);
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
int main()
{
	char str[1001], meirei[10], p[1001], c;
	int q, i, j, k, a, b;
	scanf("%s", str);
	scanf("%d", &q);
	for(i=0; i<q; i++){
		scanf("%s", meirei);
		if(strcmp(meirei, "print")==0){
			scanf("%d %d", &a, &b);
			for(j=a; j<b+1; j++){
			printf("%c", str[j]);
			}
			printf("\n");
		} else if(strcmp(meirei, "reverse")==0){
			scanf("%d %d", &a, &b);
			for(j=0; j<b-a; j++){
				for(k=b-j; k>a; k--){
					c=str[a];
					str[a]=str[k];
					str[k]=c;
				}
			}
		} else if(strcmp(meirei, "replace")==0){
			scanf("%d %d %s", &a, &b, p);
			for(j=0; j<b-a+1; j++){
				c=str[a+j];
				str[a+j]=p[j];
			}
		}
	}
	return 0;
}



Measured memory_bytes: 2048
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd(a,b,c)
print(ans)

Measured memory_bytes: 74808
// ある辺が最短経路に含まれるかどうか？？
// 
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

typedef vector<vector<ll> > Matrix;

Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

//行列の可視化
void show_matrix(Matrix matrix){
    REP(i,0,matrix.size()){
        REP(j,0,matrix.size()){
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
}

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

  d = Matrix(n, vector<ll>(n, INF));
  for (int i = 0; i < n; i++) d[i][i] = 0;
  
  vector<tuple<int,int,int>> edges;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    from--; to--;
    d[from][to] = cost;
    d[to][from] = cost;
    edges.emplace_back(make_tuple(from,to,cost));
  }
  
  warshall_floyd(n);
  
  //show_matrix(d);

  int cnt=0;
  for(auto e : edges){
    int i = get<0>(e);
    int j = get<1>(e);
    int c = get<2>(e);
    bool flag=true;
    REP(k,0,n){
      REP(l,k+1,n){
        //最短経路だったらfalseになるよん
        if(d[k][i]+c+d[j][l]==d[k][l]) flag=false;
        if(d[k][j]+c+d[i][l]==d[k][l]) flag=false;
      }
    }
    if(flag) cnt++;
  }
  P(cnt);

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
using P = pair<int,int>;

const int N = 1e+5+1;
const int INF = 1e+9+7;
int max_futures[N];
int min_pasts[N];
int a[N];

void init(int n) {
	int min_past = INF;
	for(int i = 0; i < n; i++){
		min_past = min(min_past,a[i]);
		min_pasts[i] = min_past;
	}

	int max_future = -INF;
	for(int i = n-1; i >= 0; i--){
		max_future = max(max_future,a[i]);
		max_futures[i] =max_future;
	}
}

int solve(int n) {
	set<P> s;
	int max_diff = 1;
	for(int i = 0; i < n; i++){
// 		cout << min_pasts[i] << ":" << max_futures[i] << endl;
		max_diff = max(max_futures[i] - min_pasts[i],max_diff);
	}

	for(int i = 0; i < n; i++){
		if(max_futures[i] - min_pasts[i] == max_diff)
			s.insert(P(min_pasts[i],max_futures[i]));
	}
	return s.size();
}

int main(){
	int n,t;
	cin >> n >> t;
	for(int i = 0; i < n;i++) {
		cin >> a[i];
	}
	init(n);

	cout << solve(n) << endl;
}



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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	map<char,lli> cnt;
	lli n;
	cin>>n;

	REP(i,0,n){
		char tmp;
		cin>>tmp;
		cnt[tmp]++;
	}

	lli ans = 1;
	for(auto e:cnt){
		ans *= (e.second+1);
		ans%=MOD;
	}

	ans -= 1;
	if(ans<0)ans+=MOD;

	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=100000+10;
int main()
{
    int n=0,m=0,ans=0,i;
    char a[maxn],b='0';
    scanf("%s",a);
    for(i=0;a[i]!='\0';i++)
    {
        if(a[i]==b) m++;
        else n++;
        if(i%2==0) b='1';
        else b='0';
    }
    ans=min(n,m);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int sm(int[],int);
int sm(int x[],int n){
    int t,s1=0;
    for(t=0;t<n;t++){
        s1+=x[t];
    }
    return s1;
}
int main(void){
    int i,j,s,r,c,a[101]={0},sum[101]={0};
    scanf("%d%d",&r,&c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&a[j]);
            sum[j]+=a[j];
            printf("%d ",a[j]);
        }
        s=sm(a,j);
        sum[j]+=s;
        printf("%d\n",s);
    }
    for(j=0;j<=c;j++){
        if(j!=0){printf(" ");}
        printf("%d",sum[j]);
    }
    printf("\n");
    return 0;
}


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

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

    // dp[p][q]は区間[p, q]でのX-Yの値
    ll dp[N][N] = {};
    for (int i = 1; i <= N; ++i) { // 長さ
        for (int j = 0; j <= N - i; ++j) { // 区間[j, j+i-1]を更新
            int flag = (N - i + 1) % 2; // 1なら太郎の番
            if(flag == 0) flag--;
            if(i == 1){
                dp[j][j] = a[j] * flag;
            } else{
                ll rx = dp[j][j+i-2] + a[j+i-1] * flag;
                ll lx = dp[j+1][j+i-1] + a[j] * flag;
                if(flag == 1){
                    dp[j][j+i-1] = max(rx, lx);
                } else{
                    dp[j][j+i-1] = min(rx, lx);
                }
            }
        }
    }
    cout << dp[0][N-1];
    return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n + 1), b(n);
  for (int &x : a) {
    scanf("%d", &x);
  }
  for (int &x : b) {
    scanf("%d", &x);
  }
  int64_t ans = 0;
  for (int i = 0; i < n; ++i) {
    int m = min(b[i], a[i]);
    a[i] -= m;
    b[i] -= m;
    ans += m;
    m = min(b[i], a[i + 1]);
    a[i + 1] -= m;
    b[i] -= m;
    ans += m;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1024
using System;

namespace ABC043D{
    public class Program{
        public static void Main(string[] args){
            var S = Console.ReadLine();


            for(var i = 1; i < S.Length; i++){
                if(S[i] == S[i - 1]){
                    Console.WriteLine($"{i} {i + 1}");
                    return;
                }
            }

            for(var i = 2; i < S.Length; i++) {
                if(S[i] == S[i - 2]) {
                    Console.WriteLine($"{i - 1} {i + 1}");
                    return;
                }
            }

            Console.WriteLine("-1 -1");
        }
    }
}

Measured memory_bytes: 3032
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<malloc.h>
#include<math.h>
#include<algorithm>

using namespace std;

const int maxn = 1e5+100;
int n,m,tag,f[maxn],dis[maxn];

int getfa(int x)
{
    if (f[x]==x) return x;
    int fx = getfa(f[x]);
    dis[x] += dis[f[x]];
    f[x] = fx;
    return f[x];
}

int main()
{
    scanf("%d %d",&n,&m);
    tag = 1;
    memset(dis,0,sizeof(dis));
    for (int i=1;i<=n;i++) f[i] = i;
    for (int i=0;i<m;i++)
    {
        int x,y,d;
        scanf("%d %d %d",&x,&y,&d);
        int fx = getfa(x);
        int fy = getfa(y);
        if (fx == fy)
        {
            if (dis[y] != dis[x]+d) tag = 0;
        }
        else
        {
            f[fy] = fx;
            dis[fy] = dis[x]+d-dis[y];
        }
    }
    if (tag) printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <cctype>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){
  int x,ans,i,k,a,l;
  cin >> x;
  k = x / 100;
  a = x - (100 * k);
  l = k * 5;
  if(a <= l){
    ans = 1;
  }else{
    ans = 0;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[3];
	int count = 0;
	int i;

	scanf("%d",&a[0]);
	scanf("%d",&a[1]);
	scanf("%d",&a[2]);

	for(i = a[0];i <= a[1];i++){
		if(a[2] % i == 0) count++;
	}

	printf("%d\n",count);

	return 0;
}

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

namespace ABC067_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var num = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse).ToList();
            var sum = num.Sum();
            var L = new long[n - 1];
            L[0] = num[0];
            for (var i = 1; i < n - 1; i++)
            {
                L[i] += L[i - 1] + num[i];
            }
            long min = int.MaxValue;
            for (var i = 0; i < n - 1; i++)
            {
                long c = Math.Abs(sum - 2 * L[i]);
                min = Math.Min(c, min);
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 37084
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto H = RD;
	auto W = RD;
	auto C = RDA(-1);
	auto D = RDA(-1);
	auto S = new string[](H);
	foreach (i; 0..H)
	{
		S[i] = RD!string;
	}

	BinaryHeap!(Array!(long[]), "a[0] > b[0]") heap;
	heap.insert([0, C[0], C[1]]);
	auto dist = new long[][](H, W);
	foreach (i; 0..H)
		dist[i][] = long.max;
	dist[C[0]][C[1]] = 0;
	while (!heap.empty)
	{
		auto nd = heap.front; heap.removeFront;
		auto c = nd[0];
		auto y = nd[1];
		auto x = nd[2];
		foreach (dir; [[-1, 0], [1, 0], [0, -1], [0, 1]])
		{
			auto ny = y + dir[0];
			auto nx = x + dir[1];
			if (inside(ny, 0, H) && inside(nx, 0, W))
			{
				if (S[ny][nx] == '.')
				{
					if (c < dist[ny][nx])
					{
						dist[ny][nx] = c;
						heap.insert([c, ny, nx]);
					}
				}
			}
		}
		foreach (dy; -2..3)
		{
			foreach (dx; -2..3)
			{
				auto ny = y + dy;
				auto nx = x + dx;
				if (inside(ny, 0, H) && inside(nx, 0, W))
				{
					if (S[ny][nx] == '.')
					{
						if (c+1 < dist[ny][nx])
						{
							dist[ny][nx] = c+1;
							heap.insert([c+1, ny, nx]);
						}
					}
				}
			}
		}
	}

	if (dist[D[0]][D[1]] == long.max)
	{
		writeln(-1);
	}
	else
	{
		writeln(dist[D[0]][D[1]]);
	}

	stdout.flush;
	debug readln;
}


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

P f(int x) {
  int a = x%10;
  int b;
  while (x) {
    b = x;
    x /= 10;
  }
  return P(a,b);
}

int main() {
  int n; 
  cin >> n;
  map<P,int> freq;
  for (int i=1; i<=n; ++i) {
    P p = f(i);
    freq[p]++;
  }
  ll ans = 0;
  for (int i=1; i<=n; ++i) {
    P p = f(i);
    P q(p.second, p.first);
    ans += freq[q];
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

int main(){
    int N;
    cin >> N;
    float ans = 0;
    
    for(int i = 0; i < N; ++i){
        float x; string u;
        cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        } else {
            ans += x * 380000;
        }
    }
    cout << setprecision(7) << ans << endl;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c;
cin>>a>>b>>c;
int m=a%b;
int k=2;
bool ok=false;
while(m!=(a*k)%b){
    if(c==(a*(k-1))%b){
        ok=true;
        break;
    }
    k++;
}
if(ok)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;cin>>N>>M;bool F=false;int A=-1,B=-1,C=-1;
  for (int X=0;X<=N;X++){
    for (int Y=0;Y<=N;Y++){
      if (X+Y<=N&&X*10000+Y*5000+(N-X-Y)*1000==M){
        A=X;B=Y;C=(N-X-Y);F=true;break;
      }
    }
  }
  if(!F){
    cout<<-1<<" "<<-1<<" "<<-1<<endl;return 0;
  }
  cout<<A<<" "<<B<<" "<<C<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n;
        cin>>n;
        vector<char> vec;
        while(n){
            ll x = n % 26;
            vec.pb((char)('a' + (x + 25)%26));
            if(x == 0)  n -= 26;
            n/=26;
        }
        reverse(all(vec));
        for(char u : vec) cout<<u;
    }
}


Measured memory_bytes: 3652