akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let k: usize = read();
    let mut a: Vec<u32> = (0..n).map(|_| read()).collect();
    a.sort();
    print!("{}", a[..k].iter().sum::<u32>());
}

Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a,b,c,d,e,i,j;
 string s,s1;
 cin >> s >> s1;
 e=s.length();
 for(i=0;i<=s.length()-s1.length();i++)
 {
     int k=i,m=0;
     for(j=0;j<s1.length();j++)
     {
         if(s1[j]!=s[k])
         {
             m++;
         }
         k++;
     }
     e=min(e,m) ;

 }
 cout << e << endl;

}


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

using namespace std;

int main() {
  int n; cin >> n;
  vector< pair<int, int> > adj[n];
  
  for(int i = 0; i < n; i++) {
    int ix, nn; cin >> ix >> nn;
    for(int j = 0; j < nn; j++) {
      int v, c; cin >> v >> c;
      adj[ix].push_back(make_pair(c, v));
    }
  }

  int inf = 10000000;
  int ans[n];
  fill(ans, ans+n, inf);

  ans[0] = 0;
  int ix = 0, sd[n] = {1};
  while(true) {

    for(int i = 0; i < adj[ix].size(); i++) {
      int cost = ans[ix] + adj[ix][i].first;
      int k = adj[ix][i].second;

      if(cost < ans[k]) {
        ans[k] = cost;
        sd[k] = 0;
      }

    }

    sd[ix] = 1;
    ix = -1;
    for(int i = 0; i < n; i++) {
      if(sd[i] == 0 && (ix == -1 || ans[ix] > ans[i])) {
        ix = i;
      }
    }
    if(ix == -1) {
      break;
    }
  }

  for(int i = 0; i < n; i++) {
    cout << i << " " << ans[i] << endl;
  }
}

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

int main()
{
    ll i,j,k,n,q,t,a,b;
    cin>>n>>a>>b;
    t=min(abs(n-a),abs(n-b));
    if(t==abs(n-a))
        cout<<'A'<<endl;
    else
        cout<<'B'<<endl;

}




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

using namespace std;

bool check_camel(char s)
{
    if (s >= 'a' && s <= 'z')
    {
        return true;
    }
    return false;
}

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

    if (s[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }

    //Cを一文字3からs.length()-2までに含む
    int k = 0;
    int l = 0;
    for (int j = 2; j < s.length() - 1; j++)
    {
        if (s[j] != 'C')
        {
            k++;
        }
        else
        {
            l = j;
        }
    }

    if (k != s.length() - 4)
    {
        cout << "WA" << endl;
        return 0;
    }

    for (int i = 1; i < s.length(); i++)
    {
        if (l == i)
        {
            continue;
        }
        if (!check_camel(s[i]))
        {
            cout << "WA" << endl;
            return 0;
        }
    }

    cout << "AC" << endl;
    return 0;
}

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

unsigned long long h, w, ans;

int main() {
  cin>>h>>w;
  ans = ((h*w)/2);
  if(h==1|| w==1){
    cout<<1;
  }
  else{
    if((h*w)%2==0){
      cout<<ans;
    }
    else{
      cout<<ans+1;
    }
  }
}

Measured memory_bytes: 256
//ITP1_2_D:   Circle in a Rectangle
#include <iostream>
using namespace std;
int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (W<x + r || H<y + r || 0>x - r || 0>y - r)cout << "No";
	else cout << "Yes";
	cout << endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  vector<int> a(n);
  int cnt_minus = 0;
  ll sum = 0;

  REP(i,n) {
    cin >> a[i];
    if (a[i] < 0) { cnt_minus++; a[i] = -a[i]; }
    sum+=a[i];
  }

  sort(ALL(a));

  if (cnt_minus%2) sum -= a[0]*2;
  COUT(sum);
  return 0;
}

Measured memory_bytes: 3728
function Main(input) {
    input = input.trim();
    const tmp = input.split(" ");
    const s = parseInt(tmp[0],10);
    const w = parseInt(tmp[1],10);

    if(s <= w){
        console.log('unsafe');
    }else{
        console.log('safe');
    }
    
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29412
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

bool pr[1000000];

template <size_t N>
void psieve(bool (&p)[N]) {
  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!p[i])
      continue;
    for (int j = i * i; j < N; j += i)
      p[j] = false;
  }
}

int solve(int n) {
  int r = 0;
  REP (i, n+1) r += pr[i];
  return r;
}

int main() {
  ios::sync_with_stdio(false);
  psieve(pr);
  int n;
  while (cin >> n) {
    cout << solve(n) << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int n;
int a[20][20];
ll sum[1<<16];
ll dp[1<<16];
ll f(int msk)
{
    ll &ret = dp[msk];
    if (~ret) return ret;
    ret = 0;
    for (int sub = msk ; sub ; sub = (sub-1) & msk)
    {
        ret = max(ret, f(msk & (~sub)) + sum[sub]);
    }
    return ret;
}
int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            scanf("%d", &a[i][j]);
    for (int i = 0 ; i < (1<<n); ++i)
    {
        for (int j = 0 ; j < n; ++j)
            for (int k = 0; k < n; ++k)
                if ((1<<j) & i)
                    if ((1<<k) & i)
                        sum[i] += a[j][k];
        sum[i] /= 2;
    }
    printf("%lld\n", f((1<<n)-1));
    return 0;
}


Measured memory_bytes: 1280
def judge h, base, add, t
  nh = h.map{|lf| lf - t * base}
  add_count = 0
  nh.reject{|lf| lf <= 0}.each{|lf|
    add_count += (lf / add.to_f).ceil
  }
  return t >= add_count
end

lambda {
  n,a,b = *readline.split(/\s+/).map(&:to_i)
  a -= b
  h = readlines.map(&:to_i)
  hi = (h.max.to_f / b).ceil
  lo = 1
  while lo < hi
    t = (lo + hi) / 2
    if judge h, b, a, t
      hi = t
    else
      lo = t + 1
    end
  end
  puts lo
}.call



Measured memory_bytes: 43532
n,m=map(int,input().split())
ac = 0
wa = 0
ac_list = [0]*n
wa_list = [0]*n

for _ in range(m):
    p,s=input().split()
    p = int(p) - 1
    if ac_list[p] == 'AC': continue
    ac_list[p] = s
    if s == 'AC':
        ac += 1
        wa += wa_list[p]
    else:
        wa_list[p] += 1
print(ac,wa)

Measured memory_bytes: 10100
import sys
from collections import deque
from operator import itemgetter


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    h.insert(0,0)
    dp = [10 ** 9 + 7] * (N + 1)
    dp[1] = 0
    for i in range(1, N + 1):
        for k in range(1, K + 1):
            if k <= i:
                dp[i] = min(dp[i], dp[i - k] + abs(h[i - k]- h[i]))
    print(dp[-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 85520
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        int N = 0;
        int K = 0;
        try (Scanner scan = new Scanner(System.in);) {
            N = scan.nextInt();
            K = scan.nextInt();
        }

        if (K == 1) {
            System.out.println(0);
        } else {
            System.out.println(N - K);
        }

    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int sum = 0;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }

    double mean = (double)sum / (double)N ; 
    double m = 10000;

    int y;
    for(int i = -100; i <= 100; i++){
        if(m > abs(mean - i)){
            y = i;
            m = abs(mean - i);
        }
    }

    int ans = 0;
    rep(i, N){
        ans += (A[i] - y) * (A[i] - y);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())

x = abs(x)

inf = float('INF')

if x - k*d >= 0:
    ans = x - k * d

else:
    temp = x//d
    if (k-temp) % 2 == 0:
        ans = x - temp * d
    else:
        ans = x - (temp+1) * d

ans = abs(ans)

print(ans)


Measured memory_bytes: 9172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int sx = scanner.nextInt();
		int sy = scanner.nextInt();
		int tx = scanner.nextInt();
		int ty = scanner.nextInt();
		scanner.close();
//		String result = "";
//		List<String> result = new ArrayList<String>();
//		String rr = "";
		StringBuilder sb = new StringBuilder();
		// 1回目
		for(int i = 0; i < ty - sy; i++){
//			result += "U";
			sb.append("U");
		}
		for(int i = 0; i < tx - sx; i++){
//			result += "R";
			sb.append("R");
		}

		for(int i = 0; i < ty - sy; i++){
//			result += "D";
			sb.append("D");
		}
		for(int i = 0; i < tx - sx; i++){
//			result += "L";
			sb.append("L");
		}
		/// 2回目
//		result += "L";
		sb.append("L");
		for(int i = 0; i < ty - sy; i++){
//			result += "U";
			sb.append("U");
		}
//		result += "U";
		sb.append("U");
		for(int i = 0; i < tx - sx; i++){
//			result += "R";
			sb.append("R");
		}
//		result += "RDR";
		sb.append("RDR");

		for(int i = 0; i < ty - sy; i++){
//			result += "D";
			sb.append("D");
		}
//		result += "D";
		sb.append("D");
		for(int i = 0; i < tx - sx; i++){
//			result += "L";
			sb.append("L");
		}
//		result += "LU";
		sb.append("LU");

//		System.out.println(result);
		System.out.println(sb);

	}

}


Measured memory_bytes: 21972
def valid?(a, b, c)
  a <= b + c && b <= c + a + 1 && c <= a + b + 1
end
 
def calc(rear, front, west, east, north, south, limit, best)
  path = []
  while path.size < limit
    a = rear + front
    b = west + east
    c = north + south
 
    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 69
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 78
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 83
    #elsif west > 0 && valid?(b - 1, c, a)
    else
      rear, front, west, east = west - 1, east, front, rear
      y = 87
    end
     
    if best
      x = best[path.size]
      return best if x < y
      best = nil if x > y
    end
    path << y  
  end
  path
end
 
def find(target, limit)
  best = nil
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      best = calc(rear, front, west, east, north, south, limit, best)
    end
  end
  best
end
 
loop do
  target = gets.split.map!(&:to_i)
  break if target.all?(&:zero?)
  p, q = gets.split.map!(&:to_i)
  result = find(target, q)
  puts result ? result[p-1...q].pack('C*') : 'impossible'
end

Measured memory_bytes: 72800
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h == 0 && w == 0) break;
            var s = new string('#', w);
            for (int i = 0; i < h; i++) Console.WriteLine(s);
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 8792
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int a,b;
int main(){
	a=rd(),b=rd();
	rt(Max(a-b-b,0));
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 2304
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(int argc, const char * argv[]) {
    int A, B;
    cin >> A >> B;

    ll X = 10 * B;
    for (int i = 0; i < 10; i++) {
        if (8 * (X + i) / 100 == A) {
            cout << X + i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 888
def fact(n)
  return 1 if n <= 1
  n * fact(n - 1)
end

def dist(p, q)
  Math.sqrt(
    ((p[:x] - q[:x]) ** 2) + ((p[:y] - q[:y]) ** 2)
  )
end

def main(argv)
  n = gets.chomp.to_i
  
  ps = [nil] * n
  n.times{ |i| ps[i] = {:x => 0.0, :y => 0.0} }
  n.times do |i|
    (ps[i][:x], ps[i][:y]) = gets.chomp.split(' ').map(&:to_f)
  end
  
  ds = [nil] * n
  n.times{ |i| ds[i] = [0.0] * n }
  n.times do |i|
    n.times do |j|
      ds[i][j] = dist(ps[i], ps[j])
    end
  end
  
  sum = 0.0
  n.times do |i|
    ((i+1)...n).each do |j|
      sum += ds[i][j]
    end
  end
  
  puts (sum * fact(n - 1) * 2) / fact(n).to_f
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <memory.h>
int main(void){
  int n,w,h,x,y,f[500][500],i,j,k,l,s,t,sum,ans;
  while(1){
    scanf("%d",&n);
    if(!n)
      break;
    memset(f,0,sizeof(f));
    scanf("%d %d",&w,&h);
    for(i=0;i<n;i++){
      scanf("%d %d",&x,&y);
      f[x-1][y-1]=1;
    }
    ans=sum=0;
    scanf("%d %d",&s,&t);
    for(i=0;i<=w-s;i++){
      for(j=0;j<=h-t;j++){
	for(k=0;k<s;k++){
	  for(l=0;l<t;l++){
	    sum+=f[i+k][j+l];
	  }
	}
	if(ans<sum)
	  ans=sum;
	sum=0;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1584
#include<bits/stdc++.h>
using namespace std;
int gcb(int a, int b) {
    int c;
    while(b!=0) {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
int main () {
    ios_base::sync_with_stdio(false);
    int ans = 0;
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=N;j++) {
            int n = gcb(i,j);
            for(int k=1;k<=N;k++) {
                ans+=gcb(n,k);
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3656
n, m, x, y = gets.chomp.split.map(&:to_i)
x_arr = gets.chomp.split.map(&:to_i)
y_arr = gets.chomp.split.map(&:to_i)
x_max = x_arr.max
y_min = y_arr.min
if [*((x + 1)..y)].select { |i| x_max < i && i <= y_min }.empty?
  puts 'War'
else
  puts 'No War'
end

Measured memory_bytes: 1788
import numpy as np
n,k=map(int,input().split())
a = np.array(list(map(int,input().split())))
a.sort()

p = a[a>0]
m = a[a<0]
z = np.count_nonzero(a==0)

def count(x):
  cnt = 0
  if x>=0:
    cnt+=z*n
  cnt += a.searchsorted(x//p,side='right').sum()
  cnt += n*len(m) - a.searchsorted(-(-x//m),side='left').sum()
  cnt -= np.count_nonzero(a*a<=x)
  return cnt//2
l,r = -10**19,10**19
while r-l>1:
  mid = (l+r)//2
  cnt = count(mid)
  if cnt >= k:
    r = mid
  else:
    l = mid
print(r)
  

Measured memory_bytes: 32296
import java.util.*;
 
public class Main{
 
    
 
        
    
 
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] ms = new long[n+1];
        long[] hs = new long[n];
 
        for(int i=0;i<n+1;i++){
            ms[i] = sc.nextLong();
        }
        
        for(int i=0;i<n;i++){
            hs[i] = sc.nextLong();
        }
 
        long tot = 0;
        long min;
 
        for(int i = n;i>=0;i--){
            
            if(i<=n-1){
                min = Math.min(ms[i],hs[i]);
                ms[i] -= min;
                hs[i] -= min;
                tot += min;
            }
            
 
            if(i > 0){
                min = Math.min(ms[i],hs[i-1]);
                ms[i] -= min;
                hs[i-1] -= min;
                tot += min;
            }
            
        }
 
      
        System.out.println(tot);
 
 
 
        sc.close();
    }
}

Measured memory_bytes: 67424
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;

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;
}
template<class T>T modPow(T a, int b) {
	T t = 1;
	REP(i, b) {
		t *= a;
		t %= MOD;
	}
	return t;
}

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll dp[100001][13];


using namespace std;
int main()
{
	string s;
	cin >> s;
	int len = s.length();
	
	dp[0][0] = 1;
	REP(i, len) {
		bool b=false;
		if (s[i] == '?')b = true;
		REP(tar, 10) {
			if (!b && s[i]-'0' != tar)continue;
			REP(j, 13) {
				dp[i + 1][(j*10+tar)%13] += dp[i][j];
				dp[i + 1][(j * 10 + tar) % 13] %= MOD;
			}
		}
	}

	cout << dp[len][5] << endl;

	return 0;
}

Measured memory_bytes: 10624
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * (max(a) + 2)

for i in range(n):
    if a[i] != 0:
        cnt[a[i]-1] += 1
    cnt[a[i]] += 1
    cnt[a[i]+1] += 1
ans = 0
for c in cnt:
    ans = max(ans, c)

print(ans)

Measured memory_bytes: 13964
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let p: i64 = scan(tokens);
    let edges: Vec<(usize, usize, i64)> = vec(m, |_| (scan(tokens), scan(tokens), scan(tokens)));
    let mut next: Vec<Vec<usize>> = vec![Vec::new(); n + 1];
    let mut prev: Vec<Vec<usize>> = vec![Vec::new(); n + 1];
    for &(a, b, _) in &edges {
        next[a].push(b);
        prev[b].push(a);
    }
    fn dfs(i: usize, next: &Vec<Vec<usize>>, visited: &mut Vec<bool>) {
        if visited[i] {
            return;
        }
        visited[i] = true;
        for &j in &next[i] {
            dfs(j, next, visited);
        }
    }
    let mut lower_1 = vec![false; n + 1];
    let mut upper_n = vec![false; n + 1];
    dfs(1, &next, &mut lower_1);
    dfs(n, &prev, &mut upper_n);
    let mut d = vec![0; n + 1];
    d[n] = 0;
    for i in 0..n + 1 {
        if i == n {
            println!("-1");
            return;
        }
        let mut update = false;
        for &(a, b, c) in &edges {
            if lower_1[a] && upper_n[b] && d[a] + p - c < d[b] {
                d[b] = d[a] + p - c;
                update = true;
            }
        }
        if !update {
            break;
        }
    }
    d[1] = 0;
    for i in 2..n + 1 {
        d[i] = std::i64::MAX;
    }
    loop {
        let mut update = false;
        for &(a, b, c) in &edges {
            if lower_1[a] && upper_n[b] && d[a] < std::i64::MAX && d[a] + p - c < d[b] {
                d[b] = d[a] + p - c;
                update = true;
            }
        }
        if !update {
            break;
        }
    }
    println!("{}", std::cmp::max(0, -d[n]));
}


Measured memory_bytes: 4476
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for i in range(N):
    A = list(map(int,input().split()))
    p = C
    for j in range(M):p+=A[j]*B[j]
    if p>0:count+= 1
print(count) 
    







Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, M, C = mi()
B = li()

cnt = 0

for i in range(N):
    A = li()
    tmp = 0
    for j in range(M):
        tmp += A[j] * B[j]
    if tmp + C > 0:
        cnt += 1
    
print(cnt)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,K;
ll V[111];
ll i, j,k,l,ans;

ll calc(ll l,ll r){
    priority_queue<ll> pq;
    ll i, k=0,ct=0;
    fornum(i,0,l){
        ct += V[i];
        if(V[i]<0){
            pq.push(-V[i]);
        }
    }
    fornum(i,N-r,N){
        ct += V[i];
        if(V[i]<0){
            pq.push(-V[i]);
        }
    }
    k = K - l - r;
    while(k>0&&pq.size()){
        ct += pq.top();
        pq.pop();
        k--;
    }
    return ct;
}

int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &V[i]);
    }
    ans = 0;
    fornum(i,0,N+1){
        fornum(j,0,N+1){
            if(i+j>N||i+j>K)
                continue;
            ll ct = calc(i, j);
            if(ct>ans){
                ans = ct;
            }
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
using System;

namespace _0619
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] b = new int[4];
            int[] c = new int[2];
            for(int i=0;i<4; i++) { b[i] = int.Parse(Console.ReadLine()); }
            for (int i = 0; i < 2; i++) { c[i] = int.Parse(Console.ReadLine()); }

            Array.Sort(b);
            Array.Sort(c);
            Console.WriteLine(c[1] + b[3] + b[2] + b[1]);
        }
    }
}

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 2e9;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  set<string> s;
  for (int i=0; i<n; ++i) {
    string str;
    cin >> str;
    s.insert(str);
  }
  cout << s.size() << endl;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int dp[101][1001]; // i, sum

int main()
{
    int M;
    
    while(cin >> M, M)
    {
        vector<int> a(M), b(M);
        rep(i, M) cin >> a[i] >> b[i];

        memset(dp, 0, sizeof(dp));

        dp[0][0] = 1;

        rep(i, M)
        {
            rep(j, b[i] + 1)
            {
                rep(k, 1001)
                {
                    if(k + j * a[i] <= 1000) dp[i + 1][k + j * a[i]] += dp[i][k];
                }
            }
        }

        int G;
        cin >> G;

        rep(i, G)
        {
            int N;
            cin >> N;
            cout << dp[M][N] << endl; 
        }
    }

    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto&& i : v) cin >> i;

    ll ans = 0, low = 0;
    REP(i, n){
        ll a = (v[i] - 1) / (low + 1);
        chmax(low, 1LL);
        if(a <= 0){
            chmax(low, v[i]);
        }
        else{
            ans += a;
        }
        debug(low);
    }

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1e8;
int main() {
	int n;
	cin >> n;
	vector<int> r(n),c(n);
	for(int i=0; i<n; i++){
		cin >> r.at(i) >> c.at(i);
	}
	
	vector<vector<int>>dp(n,vector<int>(n,INF));
	for(int i=0; i<n; i++) dp.at(i).at(i) = 0;
	for(int w=1; w<=n-1; w++){
		for(int l=0; l+w<n; l++){
			if(w==1) dp.at(l).at(l+w) = r.at(l)*c.at(l+w)*c.at(l); 
			for(int mid=l; mid<l+w; mid++){
				chmin( dp.at(l).at(l+w), dp.at(l).at(mid) + dp.at(mid+1).at(l+w) + r.at(l)*c.at(l+w)*c.at(mid));
			}
		}
	}
	cout << dp.at(0).at(n-1) << endl;
}



Measured memory_bytes: 3156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)

ll sq(ll x){
	return x*x;
}

int main(void){
	int n,i;
	ll a[123456],ans=0ll,x;
	cin >> n >> x;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=1; i<n; i++){
		ans += max(0ll,a[i-1]+a[i]-x);
		a[i] = min(a[i],max(0ll,x-a[i-1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
int n,m,a[100005],cnt[100005];
int main(){
	cin>>n;
	int ans=0;
	for(register int i=1;i<=n;i++)cin>>m,cnt[m]++,cnt[m+1]++,cnt[m-1]++;
	for(register int i=0;i<=100000;++i)ans=max(ans,cnt[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(a<b)swap(a,b);
  if(a%b==0)return b;
  return gcd(b,a%b);
}
int main(){
  ll n;cin>>n;
  ll a[n];for(int i=0;i<n;i++)cin>>a[i];
  ll u=pow(n,0.5);
  vector<ll> v;
  ll now=a[0];
  for(int i=1;i<n;i++){
    if(i%u==0){
      v.push_back(now);
      now=a[i];
    }
    else{
      now=gcd(now,a[i]);
    }
  }
  v.push_back(now);
  //cout<<u;return 0;
  //cout<<t[0]<<t[1]<<t[2];return 0;
  ll ans=0;
  for(int i=0;i<n;i++){
    ll y=i/u;
    ll r;
    if(y==0)r=v[1];
    else r=v[0];
    for(int j=0;j<v.size();j++){
      if(j==y)continue;
      r=gcd(r,v[j]);
    }
    for(int j=y*u;j<y*u+u;j++){
      if(j==i||j>=n)continue;
      r=gcd(r,a[j]);
    }
    ans=max(r,ans);
  }
  cout<<ans<<endl;
}

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

using namespace std;

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

  int a, b, c;
  cin >> a >> b >> c;
  if (a <= c && c <= b) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 100100
#define MAX_M 100100

// ACしたかどうか
bool seen[MAX_N];

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(MAX_N);
  string s[MAX_M];
  int ac = 0;
  vector<int> wa(MAX_N, 0);
  for (int i = 0; i < M; i++) cin >> p[i] >> s[i];
  for (int i = 0; i < M; i++) {
    int P = p.at(i);
    if (seen[P]) continue;
    if (s[i] == "AC") {
      // AC済みにする
      seen[P] = true;
      ac++;
    }
    if (s[i] == "WA") wa[P] += 1;
  }

  // WAの合計
  int sum = 0;
  for (int i = 0; i < N + 1; i++) {
    if (seen[i]) sum += wa[i];
  }
  cout << ac << ' ' << sum << endl;
  return 0;
}


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

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

    vector<int> subNumVec(n, 0);

    for (int i = 1; i < n; ++i)
    {
        int input;
        cin >> input;

        ++subNumVec.at(input - 1);
    }

    for (const int &singleSubNum : subNumVec)
    {
        cout << singleSubNum << endl;
    }
}

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

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)

#define forn(n) for(int i = 0; i < n; i++)
#define fork(k, n) for(int i = k; i < n; i++)

#define pb(n) push_back(n);

typedef long long ll;
typedef double dbl;

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
	//Code here bby
  string s, t;
  cin>>s>>t;
  int res = 1e9;
  for(int idx = 0; idx < s.size() - t.size() + 1; idx++){
    int dif = 0;
    for(int chk = 0; chk < t.size(); chk++){
      if(s[chk + idx] != t[chk]){
        dif++;
      }
    }
    res = min(res, dif);
  }
  cout<<res<<endl;
}


Measured memory_bytes: 3640
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    vector <ll> v(n);
    vector <bool> p(1000005, 1);
    for (ll &x : v) cin >> x;
    sort (v.begin(), v.end());
    map <ll, ll> m;
    for (ll x : v) m[x] = 0;
    int flag = 0;
    for (ll i = 0; i < n; i++) {
        m[v[i]]++;
        if (v[i] == 1) flag = 1;
        if (m[v[i]] > 1) p[v[i]] = 0;
    }
    if (flag) {
        if (!p[1]) cout << 0;
        else cout << 1;
        return 0;
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        if (p[v[i]]) {
            ans++;
        }
        for (ll j = 2; v[i]*j < 1000005; j++) {
            p[v[i]*j] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 17428
#include<stdio.h>
int main()
{

    int A,B,c;
    scanf("%d %d",&A,&B);
    c=B*2;
    if(c<A)
    {
        printf("%d\n",A-c);
    }
    else
    {
        printf("0\n");
    }
    return 0;
}


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

#define reint register int
#define coint const int

using namespace std;

int cntNum(int num) {
    int res = 0;
    for (; num; ++res, num /= 10);
    return res;
}

int main(void) {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (reint i = 1; i <= n; ++i)
        ans += (cntNum(i) & 1);
    printf("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    set<int>s1,s2,s3;
    s1.insert(1);
    s1.insert(3);
    s1.insert(5);
    s1.insert(7);
    s1.insert(8);
    s1.insert(10);
    s1.insert(12);
    s2.insert(4);
    s2.insert(6);
    s2.insert(9);
    s2.insert(11);
    s3.insert(2);

    if((s1.count(a)&&s1.count(b))||(s2.count(a)&&s2.count(b)))cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}




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

using namespace std;

struct SortItem
{
  uint64_t a, b;
  SortItem(uint64_t a = -1, uint64_t b = -1) : a(a), b(b) {}

  bool operator<(const SortItem &item) const {
    return (b == item.b) ? a < item.a : b < item.b;
  }
};

struct VectorItem
{
  uint64_t v, i;
  VectorItem(uint64_t v = -1, uint64_t i = -1) : v(v), i(i) {}

  bool operator<(const VectorItem &item) const {
    return v < item.v;
  }
};

uint64_t count_cycles(uint64_t N, const vector<VectorItem> &A)
{
  uint64_t count = 0;
  vector<bool> checked(N, false);

  for (uint64_t n = 0; n < N; ++n) {
    if (checked[n]) { continue; }

    uint64_t start = n, index = A[n].i;
    checked[start] = true;
    while (index != start) {
      checked[index] = true;

      index = A[index].i;
      if (checked[index]) { break; }
    }

    ++count;
  }

  return count;
}

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

  vector<uint64_t> A(N), B(N);
  for (uint64_t n = 0; n < N; ++n) { cin >> A[n]; }
  for (uint64_t n = 0; n < N; ++n) { cin >> B[n]; }

  vector<SortItem> vec(N);
  for (uint64_t n = 0; n < N; ++n) { vec[n] = SortItem(A[n], B[n]); }
  sort(vec.begin(), vec.end());

  vector<VectorItem> C(N), D(N);
  for (uint64_t n = 0; n < N; ++n) { C[n].v = vec[n].a; C[n].i = n; }
  for (uint64_t n = 0; n < N; ++n) { D[n].v = vec[n].b; D[n].i = n; }
  sort(C.begin(), C.end());
  sort(D.begin(), D.end());

  bool flag = true;
  for (uint64_t n = 0; n < N; ++n) {
    flag &= C[n].v <= D[n].v;
  }

  if (count_cycles(N, C) == 1) {
    bool flag2 = false;
    for (uint64_t n = 0; n < N - 1; ++n) {
      flag2 |= D[n].v >= C[n + 1].v;
    }
    flag &= flag2;
  }

  cout << (flag ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  vector<ll> A(N);
  FOR(i,0,N){
    cin >> A[i];
  }
  vector<ll> sum(N+1,0);
  FOR(i,0,N){
    sum[i+1] = sum[i] + A[i];
  }
  ll ans = 1e18;
  FOR(i,2,N-1){
    int first = lower_bound(sum.begin(), sum.end(), (sum[i] + 1) / 2) - sum.begin();
    int first_minus = first - 1;
    int third = lower_bound(sum.begin(), sum.end(), sum[i] + (sum[N] - sum[i] + 1) / 2) - sum.begin();
    int third_minus = third - 1;
    FOR(j,first_minus,first+1){
      FOR(k,third_minus,third+1){
        ans = min(ans, max({sum[j], sum[i]-sum[j], sum[k]-sum[i], sum[N]-sum[k]})-min({sum[j], sum[i]-sum[j], sum[k]-sum[i], sum[N]-sum[k]}));
      }
    }
  }
  cout << ans << endl;
}

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

int find(int n){
	int res=0;
	rep(i,n){
		if(n%i==0) ++res;
	}
 return res;
}

int main(){
int x;
cin >> x;
while(true){
 if(find(x)==0){
 	cout << x << endl;
 	break;
 }
 ++x;
}
return 0;
}


Measured memory_bytes: 256
const Main = input => {
  const inputParsed = input.split("\n");
  const number = Number(inputParsed[0]);
  if(inputParsed[1].length > number){
    console.log(inputParsed[1].substring(0,number) + '...')
  }else{
    console.log(inputParsed[1])
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29996
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    ll n,x;
    cin>>x>>n;
    ll a[n];
    
    set<ll>s;
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    
    for(ll i=0;i<100000;i++)
    {
        if(!s.count(x-i))
        {
            cout<<x-i;
            break;
        }
        if(!s.count(x+i))
        {
            cout<<x+i;
            break;
        }
        

    }
    

    return 0;
}


Measured memory_bytes: 3636
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (1..n).map { sc.nextInt() }
    var ans = Int.MAX_VALUE
    for (i in -100..100) {
        var sum = 0
        for (x in a) sum += (i - x) * (i - x)
        ans = Math.min(ans, sum)
    }
    println(ans)
}

Measured memory_bytes: 31396
#include <bits/stdc++.h>
#define REP(i, n) for(llong i = 0;i < n;i++)
#define REPR(i, n) for(llong i = n;i >= 1;i--)
#define FOR(i, m, n) for(llong i = m;i < n;i++)
#define FORR(i, m, n) for(llog i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
llong mod = 1000000007;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};


int main(){
  int a,b;
  cin >> a >> b;
  int t = b - a+1;
  REP(i,2*a -1){
    cout <<t<<" ";t++;
  }
}


Measured memory_bytes: 256
let f s=function|[]->[(0,s)]|(n,w)::t when w=s->(n+1,w)::t|t->(0,s)::t open List;;let l=sort compare(Str.split(Str.regexp" ")(read_line()));;Printf.printf"%s %s
"(snd(hd(sort(fun a b->fst b-fst a)(fold_right f l[]))))(hd(sort(fun a b->String.length b-String.length a)l))

Measured memory_bytes: 2112
/*
ID: samarth10
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>

using namespace std;


void setIO(string name) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
}


int main() {
    //setIO();
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; i < s.length(); ++i){
        if (s[i] != t[i]){
            cnt ++;
        }
    }
    cout << cnt << "\n";
}



Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007


int main(){
	string s,t;
    cin>>s>>t;
	int n=s.size(),m=t.size();
	int i,cost=0,ans=INT_MAX,q,j;
	for(i=0;i<=n-m;i++){
		cost=0;
        q=i;
		for(j=0;j<m;j++){
			if(s[q++]!=t[j])
				cost++;
		}
		ans=min(ans,cost);
	}
	cout<<ans<<endl;
}

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

using namespace std;

typedef long double ld;

ld dp[301][301][301];

ld solve(int th, int tw, int o, int n) {
    if(dp[th][tw][o] != -1)
        return dp[th][tw][o];
    ld ans = 0;
    int total = o+tw+th;
    if(o > n || tw > n || th > n || (o+tw+th == 0))
        return 0;
    ans += (ld)n/(o+tw+th);
    if(th > 0)
        ans += ((ld)th/total)*solve(th-1, tw+1, o, n);
    if(tw > 0)
        ans += ((ld)tw/total)*solve(th, tw-1, o+1, n);
    if(o > 0)
        ans += ((ld)o/total)*solve(th, tw, o-1, n);
    dp[th][tw][o] = ans;
    return ans;
}

int main() {
    int n, o = 0, tw = 0, th = 0, tmp;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        tmp == 1 ? o++ : (tmp == 2 ? tw++ : th++);
    }
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            for(int k = 0; k <= n; k++)
                dp[i][j][k] = -1;
        }
    }
    dp[0][0][0] = 0;
    cout << fixed << setprecision(10) << solve(th, tw, o, n) << "\n";
}

Measured memory_bytes: 426496
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#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 ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())

////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	vector<int> l(n*2);
	rep(i,0,n*2)
		cin >> l[i];
	
	vsort(l);
	
	long ans = 0;
	for(int i = 0 ; i < 2 * n ; i += 2 )
		ans += min(l[i],l[i+1]);

	P(ans);
	ret 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<climits>
using namespace std;

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

	vector<long long> x(N), y(N);
	for(int i=0; i<N; i++)
		cin >> x[i] >> y[i];

	vector<long long> xx(x), yy(y);
	sort(xx.begin(), xx.end());
	sort(yy.begin(), yy.end());

	long long ret = LLONG_MAX;
	for(int lx=0; lx<N-1; lx++)
	{
		for(int rx=lx+1; rx<N; rx++)
		{
			for(int ty=0; ty<N-1; ty++)
			{
				for(int by=ty+1; by<N; by++)
				{
					int cnt = 0;
					for(int i=0; i<N; i++)
						if(	x[i]>=xx[lx] && x[i]<=xx[rx] &&
							y[i]>=yy[ty] && y[i]<=yy[by])
							cnt++;

					if(cnt < K)
						continue;

					long long w = xx[rx] - xx[lx];
					long long h = yy[by] - yy[ty];

					ret = min(ret, w*h);
				}
			}
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int x,n;
	cin>>x>>n;
	map<int,int> mp;
	for(int i=0;i<n;++i){
		int val;
		cin>>val;
		++mp[val];
	}
	int ans = INT_MAX;
	for(int i=x;;++i){
		if(!mp[i]){ans = abs(x-i);break;}
	}
	int fin = 0;
	for(int i=x;;--i){
		if(!mp[i]){if(abs(x-i)<=ans){fin=i;}else fin=x+ans;break;}
	}
	cout<<fin<<'\n';
	return 0;
}

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

#define ll long long

using namespace std;

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

int main(){
    ll a, b;
    cin >> a >> b;
    ll c, d;
    c = max(a, b);
    d = min(a, b);
    cout << lcm(a, b);
}

Measured memory_bytes: 256
k = int(input())

if k == 1:
    print(1)
    print(1)
    exit()

n = (k + 3) // 4 * 2
l = 2 * n - k
print(n)
for i in range(n):
    for j in range(n):
        if j % 2 == 0 or (i + j) % n >= n - l:
            print((i + j) % n + 1, end = ' ')
        else:
            print(n + (i + j) % n + 1, end = ' ')
    print("")
            


Measured memory_bytes: 4392
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000000

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

struct OwnEdge
{
	ll from, to, cost;
	OwnEdge() :from(-1), to(-1), cost(-1) {}
	OwnEdge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}
};

OwnEdge edges[2000];
ll tod[1000];

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

	int V, E, r;
	scanf("%d %d %d", &V, &E, &r);

	for (int i = 0; i < V; i++)
	{
		tod[i] = INF;
	}

	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);

		edges[i] = OwnEdge(s, t, d);
	}

	tod[r] = 0;

	bool ns = false;
	for (int i = 0; i < V; i++)
	{
		for (int j = 0; j < E; j++)
		{
			OwnEdge t = edges[j];
			if (tod[t.from] != INF&&tod[t.to]>(tod[t.from] + t.cost))
			{
				tod[t.to] = (tod[t.from] + t.cost);
				if (i == (V - 1))
				{
					ns = true;
				}
			}
		}
	}

	if (ns)
	{
		printf("NEGATIVE CYCLE\n");
		return 0;
	}

	for (int i = 0; i < V; i++)
	{
		printf(tod[i] ==INF ? "INF\n" : "%lld\n", tod[i]);
	}

	return 0;
}


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

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

int main() {
	int n, x,tmp,tmp2,d=-1;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (i == 0) {
			tmp2 = tmp - x;
			continue;
		}
		d = gcd(abs(tmp - x), abs(tmp2));
		tmp2 = d;
	}
	if (d == -1) {
		cout << abs(tmp - x) << endl;
	}
	else {
		cout << d << endl;
	}
}

Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll k, l, m, n;
const int M = 1e9 + 7;

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

cin >> n;

ll sum = 0, num = 0, min = M, a;
rep(i, n) {
    cin >> a;
    if(a < 0) {
        num++;
        a *= -1;
    }
    sum += a;
    if(a < min) min = a;
}

if(num % 2 == 0) {
    cout << sum << endl;
} else {
    cout << sum - 2* min << endl;
}
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  if(n%2==0) cout << n << endl;
  else cout << 2*n << endl;
  
  return 0;
}


Measured memory_bytes: 3628