akhauriyash/Code-Regression huggingface dataset:
import java.lang.StringBuilder
import kotlin.math.min
import kotlin.system.exitProcess

fun readInt(): Int {
    var digit = System.`in`.read()
    while(digit <= 32) {
        digit = System.`in`.read()
    }

    val negative = digit == '-'.toInt()
    if (negative) {
        digit = System.`in`.read()
    }
    var res = 0
    while (digit in '0'.toInt()..'9'.toInt()) {
        res *= 10
        res += digit - '0'.toInt()
        digit = System.`in`.read()
    }
    return if (negative) -res else res
}

fun main() {
    val t = readLine()!!.toInt()

    for(testNumber in 1..t) {
        val (n, a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
        val cost = HashMap<Long, Long>()

        val ops = arrayOf(Pair(2, a), Pair(3, b), Pair(5, c))

        fun getCost(x : Long) : Long {
            if(x == 0L) return 0L
            if(cost.containsKey(x)) return cost[x]!!

            var res = if(x <= 2000000000) x * d else -1L
            for((q, cst) in ops) {
                val r = x % q
                var curr = r * d + cst + getCost(x / q)
                if(x / q + 1 < x) {
                    curr = min(curr, (q - r) * d + cst + getCost(x / q + 1))
                }
                if(res == -1L || res > curr) res = curr
            }

            cost[x] = res
            return res
        }

        println(getCost(n))
    }
}

Measured memory_bytes: 66076
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int N, A;
    cin >> N >> A;
    if ((N % 500) <= A)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let mut depth;
    for i in 0..d {
        if i < 3 {
            depth = 3;
        } else {
            depth = 2;
        }
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    for j in 0..26 {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL H,W,N;
  cin >> H >> W >> N;

  cout << min((N - 1) / W + 1, (N - 1) / H + 1) << endl;
}


Measured memory_bytes: 256
n = int(input())
left=[]
right=[]
for i in range(n):
    s = input()
    l = len(s)
    a=0
    b=0
    a1=0
    b1=0
    for j in range(l):
        if s[j]==')':
            a1+=1
        else:
            a1-=1
        a=max(a1,a)
    for j in range(l):
        if s[l-1-j]=='(':
            b1+=1
        else:
            b1-=1
        b = max(b1,b)
    if a>b:
        right.append((a,b))
    else:
        left.append((a,b))
right.sort(key = lambda x:x[1],reverse=True)
left.sort(key = lambda x:x[0])
all = left+right

if all[0][0]>0:
    print('No')
    exit()
st = all[0][1]
for i in range(1,n):
    st-=all[i][0]
    if st<0:
        print('No')
        exit()
    st+=all[i][1]
if st>0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 174940
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
ll powmod(ll x, ll y, ll mod)
{
    ll ans = 1;
    while (y > 0)
    {
        if (y & 1)
        {
            ans *= x;
            ans %= mod;
        }
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    vii a(n);
    vll b(n);
    vll c(n);
    //b:aiより左側にあってaiよりstrictに大きいものの数
    rep(i,n){
        cin >> a[i];
    }
    ll d = powmod(2ll, mod - 2, mod);
    rep(i,n){
        rep(j,i){
            if (a[j]>a[i])
                {b[i]++;
                    c[i]++;
                }
        }
        repf(j,i,n){
            if (a[j]>a[i])
                c[i]++;
        }
        ans += k * b[i] % mod;
        ans %= mod;
        ll res = (k - 1) * k % mod;
        res *= c[i];
        res %= mod;
        res *= d;
        res %= mod;
        ans = (ans + res) % mod;
    }
    cout << ans << ENDL;
}

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

using namespace std;

struct item {
  int p;
  int y;
  int idx;
  int rank;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<item> vec(m);
  for (int i = 0; i < m; ++i) {
    int p, y;
    cin >> p >> y;
    vec[i] = {p, y, i, 1};
  }

  sort(vec.begin(), vec.end(), [](auto &lhs, auto &rhs) {
    return lhs.p != rhs.p ? lhs.p < rhs.p : lhs.y < rhs.y;
  });

  for (int i = 1; i < m; ++i)
    if (vec[i - 1].p == vec[i].p)
      vec[i].rank = vec[i - 1].rank + 1;

  sort(vec.begin(), vec.end(),
       [](auto &lhs, auto &rhs) { return lhs.idx < rhs.idx; });

  for (auto &v : vec) {
    cout << setfill('0') << right << setw(6) << v.p;
    cout << setfill('0') << right << setw(6) << v.rank << endl;
  }

}


Measured memory_bytes: 4784
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u)
{
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].p == NIL) cout << "root, ";
	else if (T[u].l == NIL) cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";

	for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r)
	{
		if (i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

void rec(int u, int p)
{
	D[u] = p;
	if (T[u].r != NIL) rec(T[u].r, p);
	if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main()
{
	int i, j, d, v, c, l, r;
	cin >> n;
	for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

	for (i = 0; i < n; i++) {
		cin >> v >> d;
		for (j = 0; j < d; j++) {
			cin >> c;
			if (j == 0) T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}

	for (i = 0; i < n; i++)
	{
		if (T[i].p == NIL) r = i;
	}

	rec(r, 0);

	for (i = 0; i < n; i++)
	{
		print(i);
	}
	return 0;
}


Measured memory_bytes: 7764
#include <iostream>
using namespace std;
int main(void){
    int n;
    
    cin >> n;
    
    int array[n];
    
    for(int i=0; i<n; i++)
        cin >> array[i];
        
    for(int i=n-1; i >= 0; i--){
        cout << array[i];
        if(i != 0)
            cout << " ";
    }
    
    cout << endl;
    return 0;
}



Measured memory_bytes: 3096
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      k: usize,
      _xy: [(i64, i64); n],
   }
   let mut xy = _xy;
   xy.sort();
   let mut ans = 4e18 as i64;
   for i in 0..n - 1 {
      for j in i + k - 1..n {
         let w = xy[j].0 - xy[i].0;
         let mut ys = vec![];
         for l in i..j + 1 {
            ys.push(xy[l].1);
         }
         let p = j - i + 1;
         ys.sort();
         for l in 0..p - k + 1 {
            let h = ys[l + k - 1] - ys[l];
            ans = std::cmp::min(ans, w * h);
         }
      }
   }
   println!("{}", ans);
}

/// Equivalent to std::lowerbound and std::upperbound in c++
pub trait BinarySearch<T> {
   fn lower_bound(&self, x: &T) -> usize;
   fn upper_bound(&self, x: &T) -> usize;
}
#[allow(dead_code)]
impl<T: Ord> BinarySearch<T> for [T] {
   fn lower_bound(&self, x: &T) -> usize {
      let mut low = 0;
      let mut high = self.len();
      while low != high {
         let mid = (low + high) / 2;
         match self[mid].cmp(x) {
            std::cmp::Ordering::Less => {
               low = mid + 1;
            }
            std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => {
               high = mid;
            }
         }
      }
      low
   }
   fn upper_bound(&self, x: &T) -> usize {
      let mut low = 0;
      let mut high = self.len();
      while low != high {
         let mid = (low + high) / 2;
         match self[mid].cmp(x) {
            std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {
               low = mid + 1;
            }
            std::cmp::Ordering::Greater => {
               high = mid;
            }
         }
      }
      low
   }
}


Measured memory_bytes: 4352
#pragma GCC optimize("O2")
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int gcd(int a, int b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
using namespace std;
const int maxn = 5000*100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
int n , k , a[maxn] , b[maxn] , c[maxn] , g  ;
bool check()
{
	for(int i = 1 ; i <= n ;  i++ )
	{
		if(a[i] != n) return false ; 
	}
	return true ; 
 } 
int main()
{
	migmig ;
 	cin>>n>>k ; 
 	for(int i = 1 ; i <= n ; i ++ )
 	{
 		cin>>a[i] ; 
 		if(a[i] > 0 ) g = 1 ; 
	 }
	
	 for(int j = 1 ; j <= k ; j ++ )
	 {
	 	memset(b , 0 , sizeof b) ; 
	 	memset(c , 0 , sizeof c) ; 
	 	for(int i = 1 ; i <= n ; i ++ )
	 	{
	 		b[i] += 1 ; 
	 		b[i+a[i]+1] -= 1 ; 
	 		//cout<<b[i]<< " " ; 
		 }
		 //cout<<endl; 
		 for(int i = 1 ; i <= n ; i ++ )
		 {
		 	c[i] += 1 ; 
		 	c[max(i-a[i]-1 , 0)] -= 1 ; 
		 }
		int cnt = 0 ; 
		 for(int i = 1 ; i <= n ; i ++ )
		 {
		 	cnt+=b[i] ; 
		 	a[i] = cnt ; 
		 }
		 cnt = 0 ; 
		for(int i = n ; i >=  1 ; i -- )
		{
			cnt+=c[i] ; 
			a[i] -- ; 
			a[i] += cnt ; 
		}
		if(check()) break ; 
	 }
	 for(int i = 1;  i<= n ; i ++ )
	 {
	 	cout<<a[i] <<  ' ' ; 
	 }
	 

}
//////
////////
///////////




Measured memory_bytes: 8324
# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
S = sum(A)%mod
ans = 0
for k in range(N-1):
  S -= A[k]
  S %= mod
  ans += S*A[k]
  ans %= mod
print(ans)

Measured memory_bytes: 94188
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll x,y;
   cin>>x>>y;
   ll a,b,c;
   cin>>a>>b>>c;
   
   ll arr[a], arr1[b], arr2[c];
   rep(a)
        cin>>arr[i];
   rep(b)
        cin>>arr1[i];
   rep(c)
        cin>>arr2[i];
   
   sort(arr,arr+a,greater<ll>());
   sort(arr1,arr1+b,greater<ll>());
   sort(arr2,arr2+c,greater<ll>());
   multiset<ll> ms;
   ll rem = max(0ll,x-c);
   ll ans = 0;
   ll sum = 0;
   rep(min(x,c))
        sum+=arr2[i], ms.insert(arr2[i]);
   rep(rem)
        sum+=arr[i];
   ll ptr = rem;        
   if(x>=c)  
        rem = c;
   else rem = x;        
   vector<ll> v1;
   rep(b)
        v1.pb(arr1[i]);
   for(ll i=rem;i<c;i++)
        v1.pb(arr2[i]);
   
   sort(v1.begin(),v1.end(), greater<ll>());
   multiset<ll> ms1;
   ll sum1 = 0;
   rep(y)
        sum1+=v1[i], ms1.insert(v1[i]);
   ans = sum+sum1;    
   for(ll i = ptr;i<a;i++)
   {
       if(ms.size()>0)
       {
           auto temp = *ms.begin();
           ms.erase(ms.begin());
           sum+=arr[i]-temp;
           if(*ms1.begin()<temp)
           {
               sum1-=(*ms1.begin());
               ms1.erase(ms1.begin());
               sum1+=temp;
               ms1.insert(temp);
           }
           ans = max(ans, sum1+sum);
       }
   }
   cout<<ans;
               
   return 0;        
}  
   

Measured memory_bytes: 11892
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    ll n,m;cin>>n>>m;
    if(n==1&&m==1){cout<<1<<endl;return 0;}
    if(n==1){cout<<m-2<<endl;return 0;}
    if(m==1){cout<<n-2<<endl;return 0;}
    cout<<n*m-2*n-2*m+4<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
      unsigned long N, M, h, w, score;
      
      scanf("%lu %lu", &N, &M);

      h = N > 1? N-2: 0;
      w = M > 1? M-2: 0;
      score=0;
      score += h * w;

      if (N == 1)
            score += w;
      if (M == 1)
            score += h;
      if (N ==1 && M == 1)
            score += 1; 
      cout << score << endl;
      return 0;
}
      


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
int b[N];
struct node
{
	int k,sum;	
}a[N];
int cmp(node x,node y)
{
	return x.sum<y.sum;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].sum);
		a[i].k=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n/2;i++)
		b[a[i].k]=a[n/2+1].sum;
	for(int i=n/2+1;i<=n;i++)
		b[a[i].k]=a[n/2].sum;
	for(int i=1;i<=n;i++)
		cout<<b[i]<<endl;
}

Measured memory_bytes: 4480
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n,m;
  while((n = getInt()) + (m = getInt())){
    vector<bool> inf(n, false);
    vector<pair<int,pair<int,int> > > data(m);

    inf[0] = true;

    REP(i,m){
      data[i].f   = getInt();
      data[i].s.f = getInt() - 1;
      data[i].s.s = getInt() - 1;
    }

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

    REP(i,m){
      int s = data[i].s.f;
      int d = data[i].s.s;

      if(inf[s]) inf[d] = true;
    }

    int ans = 0;
    REP(i,n) if(inf[i]) ++ans;

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 1116
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		System.out.println(factorial(n));
	}
	
	static long factorial(int n) {
		long fact = 1L;
		
		for(int i = n; i > 0; i--) {
			fact*=i;
		}
		
		return fact;
	}
}

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

ll n, w;
ll we[105];
ll va[105];
ll mem[105][100005];

ll dp(ll n, ll w)
{
    if (w == 0 || n == 0)
        return 0;
    if (mem[n][w] != -1)
        return mem[n][w];
    if (we[n] <= w)
        return mem[n][w] = max(va[n] + dp(n - 1, w - we[n]), dp(n - 1, w));
    else
    {
        return mem[n][w] = dp(n - 1, w);
    }
}

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

    for (ll i = 1; i <= n; i++)
    {
        cin >> we[i] >> va[i];
    }

    memset(mem, -1, sizeof(mem));

    cout << dp(n, w) << endl;

    return 0;
}

Measured memory_bytes: 85608
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll dp[1111][1<<12]={};

int main(void) {
  ll N, M;
  cin >> N >> M;
  ll w[1111], v[1111];
  ll i, j;
  
  for(i=0; i<M; i++) {
    ll L;
    cin >> w[i] >> L;
    ll t=0;
    for(j=0; j<L; j++) {
      ll c;
      cin >> c;
      c--;
      t+=1<<c;
    }
    v[i]=t;
  }
  
  
  
  for(i=0; i<=M; i++) {
    for(ll S=0; S<1<<N; S++) {
      dp[i][S]=INF;
    }
  }
  dp[0][0]=0;
  
  
  for(i=0; i<M; i++) {
    for(ll S=0; S<1<<N; S++) {
      chmin(dp[i+1][S|v[i]], dp[i][S]+w[i]);
      chmin(dp[i+1][S], dp[i][S]);
    }
  }
  
  if(dp[M][(1<<N)-1]==INF)
    pt(-1);
  else
    pt(dp[M][(1<<N)-1]);
  
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
static auto faster_iostream = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }();
typedef long long ll; typedef long double db;
const int N = 1e6 + 5, M = 1e9 + 7;

// #pragma GCC optimize ("trapv")

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a / b + (a % b >= 1));
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] split = sc.nextLine().split(" ");
		
		int A = Integer.parseInt(split[0]);
		int B = Integer.parseInt(split[1]);
		int C = Integer.parseInt(split[2]);
		
		int count = 0;
		
		for(int i = A; i <= B; i+=A) {
			if(count < C) count++;
		}
		
		System.out.println(count);
		
		sc.close();
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001
#define INF         INT_MAX

int32_t main(){

	
	int n,k;
	cin>>n>>k;

	if(n<=k){
		cout<<"unsafe"<<endl;
	}
	else
		cout<<"safe"<<endl;


	return 0;
}

Measured memory_bytes: 3620
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
a=0
for co,i in enumerate(A):
    if co==0 :
        a+=B[i-1]
    if co>=1 :
        if A[co-1]+1==A[co]:
            a+=B[i-1]
            a+=C[A[co-1]-1]
        else:
            a+=B[i-1]
print(a)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

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

    return 0;
}



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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
  ll n, a, b ;
  scanf("%lld", &n) ;
  int sqrt_n = sqrt(n+5) ;

  for(int i = 1 ;i<= sqrt_n;i++){
    if(n%i == 0){
      a = i ;
      b = n/i ;
    }
  }
  ll count = 0 ;
  if(a>b) {
    while(a){
      a/=10 ;
      count++ ;
    }
  }
  else {
    while(b){
      b/=10 ;
      count++ ;
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

using P = pair<s64, s64>;

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

    s64 n, d, a;
    cin >> n >> d >> a;
    vector< P > xh(n);
    rep (i, n)
    {
        cin >> xh[i].first >> xh[i].second;
    }
    sort(xh.begin(), xh.end());

    s64 ans = 0;
    s64 sum = 0;
    queue<P> q;
    rep (i, n)
    {
        int x = xh[i].first;
        int h = xh[i].second;
        while (!q.empty() && q.front().first < x)
        {
            sum -= q.front().second;
            q.pop();
        }
        h -= sum;
        if (h > 0)
        {
            ans += CEIL(h, a);
            s64 damage = CEIL(h, a) * a;
            sum += damage;
            q.push(P{x + 2 * d, damage});
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 4992
function main(input){
    let nums = input.split('\n');
    let length = nums.length;
    for(let i=0;i<length;i++){
        if(parseInt(nums[i])===0) break;
        console.log("Case "+(i+1)+": "+nums[i]);
    }

}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 22764
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}

int main(void) {
	int a, d, x;
	cin >> a >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = x * a - d;
		cout << x << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
vector<vector<int> > g;
vector<ll> c;
vector<ll> sub;
int n;
pair<ll,ll> dfs(int id,int pre){
    ll mi = 0;
    ll sm = 0;
    map<int,ll> mp;
    for(auto x:g[id]){
        if(x!=pre){
            auto y = dfs(x,id);
            chmin(mi,y.first);
            sm += y.second;
            sub[id] += sub[x];
        }
    }
    sub[id]++;
    sm += -mi;
    ll cc = -mi;
    c[id] -= (ll)cc*(ll)g[id].size();
    if(pre!=-1){
        c[pre] += cc;
    }
    for(auto x:g[id]){
        if(x!=pre){
            c[x] += cc;
        }
    }
    for(auto x:g[id]){
        if(x!=pre){
            if(c[x]>0){
                sm += c[x]*sub[x];
                c[id] += c[x];
                c[x] = 0;
            }
        }
    }
    if(c[id]>0){
        sm += sub[id]*c[id];
        c[pre] += c[id];
        c[id] = 0;
    }
    return MP(c[id],sm);
}

int main(){

    cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    sub.resize(n);
    g.resize(n);
    c.resize(n);
    rep(i,n-1){
        int s,t;
        cin >> s >> t;
        s--;t--;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n)c[i] = a[i]-b[i];
    auto x = dfs(0,-1);
    cout << x.second << endl;
    return 0;
}


Measured memory_bytes: 23664
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
string q;
signed main()
{       

	int a;
	sc(a);
	int ans = 0;
	ans += (a / 500) * 1000;
	ans += (a % 500) / 5 * 5;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i] >> w[i];
  }
  const int MAX = 100001;
  int limit = min(512, n);
  vector<vector<int>> dp(limit, vector<int>(MAX));
  for (int j = 0; j < MAX; j++) {
    dp[0][j] = (j >= w[0] ? v[0] : 0);
  }
  for (int i = 1; i < limit; i++) {
    int p = (i - 1) / 2;
    for (int j = 0; j < MAX; j++) {
      dp[i][j] = dp[p][j];
      if (j >= w[i]) {
        dp[i][j] = max(dp[i][j], dp[p][j - w[i]] + v[i]);
      }
    }
  }
  int tt;
  cin >> tt;
  while (tt--) {
    int ver, L;
    cin >> ver >> L;
    --ver;
    vector<int> ids;
    while (ver >= limit) {
      ids.push_back(ver);
      ver = (ver - 1) / 2;
    }
    int sz = (int) ids.size();
    int ans = 0;
    for (int t = 0; t < (1 << sz); t++) {
      int sv = 0;
      int sw = 0;
      for (int i = 0; i < sz; i++) {
        if (t & (1 << i)) {
          sv += v[ids[i]];
          sw += w[ids[i]];
        }
      }
      if (sw <= L) {
        ans = max(ans, dp[ver][L - sw] + sv);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 206448
#include <stdio.h>

int main() {

    int k, s;
    scanf("%d %d", &k, &s);

    int cnt = 0;
    for (int x = 0; x <= k; x++) {

        if (x > s) {
            break;
        }
        for (int y = 0; y <= k; y++) {

            int z = s - x - y;
            //printf("%d %d %d\n", x, y, z);
            if (z < 0) {
                break;
            }
            if (z <= k) {
                cnt++;
            }

        }
    }

    printf("%d", cnt);



    return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <vector>
using namespace std;
#define MAX 100001

int N,M;

vector<pair<int,int>> adj[MAX];
int visited[MAX];
int d[MAX];
bool wrong = 0;

void dfs(int s) {
    visited[s] = 1;
    
    for (auto u: adj[s]) {
        // d[u.first] = d[s] + u.second;
        // cout << s << ":" << "d:" << u.first << ":" << d[u.first] << endl;
        if (visited[u.first] == 1) {
            if ((d[u.first] - d[s] - u.second) != 0) {
                wrong = 1;
                return;
            }
        }
        else {
            d[u.first] = d[s] + u.second;
            dfs(u.first);
        }
    }
}

int main(void){
    // Your code here!
    cin >> N >> M;
    for (int i = 1; i <= M; i++){
        int l,r,d;
        cin >> l >> r >> d;
        adj[l].push_back({r,d});
        adj[r].push_back({l,-d});
    }
    
    for (int i = 1; i <= N; i++){
        if (visited[i] == 1) continue;
        dfs(i);
    }
    
    
    if (wrong == 1) cout << "No" << endl;
    else cout << "Yes" << endl;
    
}


Measured memory_bytes: 11392
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

void main() {
    struct Query { long p, q; }

    auto tmp = readln.split.to!(long[]);
    const N = tmp[0], M = tmp[1], Q = tmp[2];
    auto count = new long[][](N+1,N+1);
    foreach (i; 0..M) {
        tmp = readln.split.to!(long[]);
        const L = tmp[0], R = tmp[1];
        count[L][R]++;
    }

    auto queryList = new Query[Q];
    foreach (i; 0..Q) {
        tmp = readln.split.to!(long[]);
        const p = tmp[0], q = tmp[1];
        queryList[i] = Query(p,q);
    }
    // p <= L && R <= qの数を求める
    // ある電車の情報を(L,R)として二次元平面にプロットすると、
    // (p,q)に対して右下にある電車の個数を数える問題になる
    /*
       (0,N) --- (p,N) --- (L,N) --- (N,N)
         |         |         |         |
       (0,q) --- (p,q) --- (L,q) --- (N,q)
         |         |         |         |
       (0,R) --- (p,R) --- (L,R) --- (N,R)
         |         |         |         |
       (0,0) --- (p,0) --- (L,0) --- (N,0)
    */
    // これは、原点から(x,y)までにある電車の個数をf(x,y)としたとき
    // f(N,q) - f(p-1,q)で表される
    foreach (i; 0..N+1) {
        foreach (j; 0..N) {
            count[i][j+1] += count[i][j];
        }
    }
    foreach (i; 0..N) {
        foreach (j; 0..N+1) {
            count[i+1][j] += count[i][j];
        }
    }
    foreach (query; queryList) {
        with (query) {
            writeln(count[N][q] - count[p-1][q]);
        }
    }
}



Measured memory_bytes: 5500
// AGC005A - STring
package main

import (
	"bufio"
	"fmt"
	"os"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func main() {
	runeS := []rune(readLine())
	var temp, ans int
	for _, c := range runeS {
		if "S" == string(c) {
			temp++
		} else {
			if temp == 0 {
				ans += 2
			} else {
				temp--
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
using namespace std;
long long a,b,c,d,n,t1,t2,t3;
int main()
{
	cin>>a>>b>>c>>d>>n;
	if(a*2<b) t1=a*2;
	else t1=b;
	if(t1*2<c) t2=t1*2;
	else t2=c;
	if(n%2==0)
		if(t2*2<d) t3=t2*2;
			else t3=d;
	if(n%2==0)	cout<<n/2*t3;
	if(n==1)
	{
		cout<<t2;
		return 0;
	}
	if(n%2==1)
		if(t2*2<d) t3=t2*2;
			else t3=d;
	if(n%2!=0) cout<<min(n/2*t3+t2,n*t2);
}

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

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */


int main(){
    char c; cin >> c;
    c = c+1;
    cout << c << endl;
    
}


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

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

    int x;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x > k - x) {
            ans += k - x;
        } else {
            ans += x;
        }
    }

    cout << ans * 2 << endl;

    return 0;
}


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

int main() {

    int n, a; cin >> n;
    set<int> set;

    for (int i = 0; i < n; i++) {
        cin >> a;
        if (set.count(a) == 0)
            set.emplace(a);
        else {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 9600
from sys import stdin
import sys
import math


N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
ans = [0 for i in range(M+1)]
temp = [10000000000000000000 for i in range(M+1)]
B = [0 for i in range(M+1)]
for i in range(N):
    for k in range(1, M+1):
        B[k] += A[i][k]
for i in range(1, len(B)):
    if B[i] < X:
        print(-1)
        sys.exit()
for i in range(1, 2**N):
    ans = [0 for i in range(M+1)]
    bit = list(format(i, 'b'))
    if len(bit) < N:
        for i in range(N-len(bit)):
            bit.insert(0, '0')
    for i, v in enumerate(bit):
        if v == '1':
            for j in range(M+1):
                ans[j] += A[i][j]
    # print(ans)
    for p in range(1, M+1):
        if ans[p] < X:
            break
        if p == M:
            if ans[0] < temp[0]:
                for j in range(M+1):
                    temp[j] = ans[j]
print(temp[0])


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

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  rep(i, n) {
    cout << s.at(i) << t.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 3636
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
import Data.Array.IArray
import Data.Array.ST

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

inf = 1000000000
wf n es = runSTUArray $ do
  dt <- newArray ((1,1),(n,n)) inf-- :: ST s (STArray (Int,Int) Int)
  forM_ es $ \[a,b,c] -> do
    writeArray dt (a,b) c
    writeArray dt (b,a) c
  forM_ [1..n] $ \k ->
    forM_ [1..n] $ \i ->
      forM_ [1..n] $ \j -> do
        a <- readArray dt (i,k)
        b <- readArray dt (k,j)
        pv <- readArray dt (i,j)
        writeArray dt (i,j) (min pv (a+b))
  return dt
solve es arr = length [() | [a,b,c] <- es, arr!(a,b) /= c]

main = do
  [n,m] <- getInts
  es <- replicateM m getInts
  let arr = wf n es
  print $ solve es arr


Measured memory_bytes: 1276
N = gets.chomp.to_i
a = []

N.times do |i|
  a << gets.chomp
end

num = a.length
b = a.uniq
 
if num==b.length 
  rule=true
  a.each_with_index do |str,i|
    if i!=0
    if str.split("")[0] != a[i-1].split("").last
      rule=false
    end
    end
  end
  if rule
    puts ("Yes")
  else
    puts ("No")
  end
else
  puts ("No")
end


Measured memory_bytes: 1916
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,M;
	scan(N>>M);
	UnionFind uf(N);
	rep(i,M){
		int X,Y,Z;
		scan(X>>Y>>Z);
		X--; Y--;
		uf.unite(X,Y);
	}
	int ans=0;
	rep(i,N){
		if(uf.root(i)==i) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 1024
digits_num, count = map(int, input().split())
ans = 'X' * digits_num

if count == 0 and digits_num == 1:
    ans = '0'
    
for i in range(count):
    target, num = map(int, input().split())
    
    if target == 1 and num == 0 and digits_num != 1:
        ans = '-1'
        break
    elif ans[target - 1] == 'X':
        ans = ans[:target - 1] + str(num) + ans[target:]
    elif ans[target - 1] == str(num):
        pass
    else:
        ans = '-1'
        break

if ans[0] == 'X':
    ans = '1' + ans[1:]

if 'X' in ans:
    ans = ans.replace('X', '0')
 
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  long long int r,temp,x,y;
  while(scanf("%lld",&x)!=EOF){
    scanf("%lld",&y);
    if(x<y){
      temp=x;
      x=y;
      y=temp;
    }
    long long int a=x;
    long long int b=y;
    while(y!=0){
      r=x%y;
      x=y;
      y=r;
    }
    long long int gcd=x;
    long long int lcm=a*b/gcd;
    printf("%lld %lld\n",x,lcm);
  }
  return(0);
}

Measured memory_bytes: 596
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
 
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::string A, std::string B, std::string C){
  int count = 0;
  REP(i, N) {
    if (A[i] == B[i] && B[i] == C[i]) {
      
    } else if (A[i] == B[i]) {
      count += 1;
    } else if (B[i] == C[i]) {
      count += 1;
    } else if (C[i] == A[i]) {
      count += 1;
    } else {
      count += 2;
    }
  }
  std::cout << count << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string A;
    std::cin >> A;
    std::string B;
    std::cin >> B;
    std::string C;
    std::cin >> C;
    solve(N, A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,N;cin>>K>>N;
  int d = 0;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    if(i>0){
      d=max(d,a[i]-a[i-1]);
    }
  }
  d=max(d,K+a[0]-a[N-1]);
  cout<<K-d<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
					
public class my
{	
	public static void Main()
	{
		string s;
		
		while( null != ( s = Console.ReadLine()) ) {
			var E = my.GetDoubleArray(',', s);
			
			Vector A,B,C,D;
			
			A.X = E[0];
			A.Y = E[1];
			B.X = E[2];
			B.Y = E[3];
			C.X = E[4];
			C.Y = E[5];
			D.X = E[6];
			D.Y = E[7];
			
			bool isConvex = false;
			
			// Convex ---> P is in triangle
			isConvex |= my.IsInTriangle(A,B,C,D);
			isConvex |= my.IsInTriangle(D,A,B,C);
			isConvex |= my.IsInTriangle(C,D,A,B);
			isConvex |= my.IsInTriangle(B,C,D,A);
			
			Console.WriteLine(!isConvex? "YES":"NO");
		}
	}
	
	private static bool IsInTriangle(Vector A, Vector B, Vector C, Vector P)
	{
		Vector AP = my.SubVecter(A, P);
		Vector BP = my.SubVecter(B, P);
		Vector CP = my.SubVecter(C, P);
		
		Vector AB = my.SubVecter(A, B);
		Vector BC = my.SubVecter(B, C);
		Vector CA = my.SubVecter(C, A);
		
		//Cross Product(only z)
		var c1 = AB.X * BP.Y - AB.Y * BP.X;
		var c2 = BC.X * CP.Y - BC.Y * CP.X;
		var c3 = CA.X * AP.Y - CA.Y * AP.X;
		
		return (c1 > 0 && c2 > 0 && c3 > 0 || c1 < 0 && c2 < 0 && c3 < 0);
	}
	
	private static void Swap(int[] A, int i, int j)
	{
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}

	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static int[] GetIntArray(int n, string t)
	{
		var A = new int[n];
		var s = t.Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}

	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(char c, string s)
	{
		return Array.ConvertAll(s.Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(string s)
	{
		return Array.ConvertAll(s.Split(' '), int.Parse);
	}
	
	private static double[] GetDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
	}
	private static double[] GetDoubleArray(char c, string s)
	{
		return Array.ConvertAll(s.Split(c), double.Parse);
	}
	
	public static string Reverse(string s)
	{
		var c = s.ToCharArray();
		Array.Reverse(c);
		
		return new String(c);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}

	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteVector(Vector v)
	{
		Console.WriteLine("{0:f8} {1:f8}", v.X, v.Y);
	}
	
	private static Vector SubVecter(Vector A, Vector B)
	{
		Vector ret;
		
		ret.X = A.X -B.X;
		ret.Y = A.Y- B.Y;
		
		return ret;
	}
}

public struct Vector
{
	public double X,Y;
}

Measured memory_bytes: 9152
#include<iostream>
 using namespace std ;
 int main()
{
 int A,B,m,n,c;
 cin>>A>>B;
 c=A+B;
 m=A*B;
 n=A-B;
 if (n>m && n>c)
 {cout << n;}
 else if (m>n && m>c)
 {cout<< m ;}
else 
{cout << c; }
}

Measured memory_bytes: 3632