akhauriyash/Code-Regression huggingface dataset:
from collections import deque
class DoublyLinkedKist:
    DLlist = deque()

    def command(self, cmd):
        if cmd[0] == 'insert':
            self.DLlist.appendleft(cmd[1])
        elif cmd[0] == 'delete':
            if cmd[1] in self.DLlist:
                self.DLlist.remove(cmd[1])
        elif cmd[0] == 'deleteFirst':
            self.DLlist.popleft()
        elif cmd[0] == 'deleteLast':
            self.DLlist.pop()

if __name__ == '__main__':
    DL = DoublyLinkedKist()
    for i in range(int(input())):
        DL.command(input().split())
    print(*DL.DLlist)

Measured memory_bytes: 72016
#include<iostream>
#include <string>
#include<algorithm>

using namespace std;
int main() {
	string a, b;
	int c=0;
	cin >> a >> b;
	for (int i = 0; i < min(a.size(), b.size());i++) {
		if (a[i] < b[i]) {
			c = 1;
			break;
		}
		else if (a[i] > b[i]) {
			c = 2;
			break;
		}
	}
	if (a.size() < b.size()) {
		c = 1;
	}
	if (a.size() > b.size()) {
		c = 2;
	}
	if (c == 1) {
		cout << "LESS" << endl;
	}
	else if (c == 2) {
		cout << "GREATER" << endl;
	}
	else if (c == 0) {
		cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = 1;
        int n = in.nextInt();
        int m = in.nextInt();
        int a[] = new int[n];
        int x = 0,cnt=0,sum=0;
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
            sum+=a[i];
        }
        
        x = (int)Math.ceil(sum/(1.0*4*m));
        for(int i=0;i<n;i++){
            if(a[i]>=x) cnt++;
        }
        System.out.println(cnt>=m?"Yes":"No");
    }
}

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

int main(){
 long long int a,b,x,i,j;
  while(cin>>x) {
  for(i=-200;i<=200;i++){
      a = i*i*i*i*i;
      int f=0;
     for(j=-200;j<=200;j++){
      b=j*j*j*j*j;
      //cout<<"a: "<<i<<'-'<<a<<" b: "<<j<<'-'<<b<<endl;
       if(a-b == x){
        cout<<i<<' '<<j<<endl;
        f=1;
        break;
       }
       if(a+b == x) {
        cout<<i<<' '<<-1*j<<endl;
        f=1;
        break;
       }
       if(-1*a + b == x){
        cout<<-1*i<<' '<<-1*j<<endl;
        f=1;
        break;
       }
    }
    if(f==1) break;
   }
  }
   return 0;
}


Measured memory_bytes: 3608
using System;

namespace Range
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }


        }
    }
}

Measured memory_bytes: 8844
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(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 = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e9;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}

ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
void solve() {
	int N, K; cin >> N >> K;
	COMinit();
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	VSORT(A);
	REP(i, N)A[i] = (A[i] + MOD) % MOD;
	ll ans = 0;
	FORR(i,N, K-1) {
		ans = add(ans, mult(A[i], COM(i, K-1)));
	}
	REP(i, N - K+1) {
		ans = sub(ans, mult(A[i], COM(N - i-1, K-1)));
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

int main(){
  int N;
  cin >> N;
  vector<int> C(N-1,0);
  vector<int> S(N-1,0);
  vector<int> F(N-1,0);
  for(int i=0;i<N-1;i++){
    cin >> C[i] >> S[i] >> F[i];
  }
  for(int i=0;i<N;i++){
    int time = 0;
    for(int j=i;j<N-1;j++){
      //j to j+1
      // n s.t. t <= F[i]*n
      if(time%F[j]>0){
        int n = time/F[j] +1;
        time = F[j] * n;
      }
      time = max(time,S[j]);
      time += C[j];
    }
    cout << time << endl;
  }
}

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

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

long long N, A, B, C, D;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A >> B >> C >> D;
		if (A < B) cout << "No" << endl;
		else if (B > D) cout << "No" << endl;
		else if (B <= C) cout << "Yes" << endl;
		else {
			long long S = gcd(B, D);
			long long T = ((B / S) - 1) * S + A % S;
			if (T > C) cout << "No" << endl;
			else cout << "Yes" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append((b, -c))

# Bellman Ford
dist = [float('inf') for i in range(n)]
dist[0] = 0
prev = [-1 for i in range(n)]
negative_cycle = False
for k in range(n*2):
    for i in range(n):
        for dst, cst in g[i]:
            src = i
            if dist[dst] > dist[src] + cst:
                dist[dst] = dist[src] + cst
                prev[dst] = src
                if k >= n-1 and dst == n-1:
                    dist[dst] = -float('inf')
                    negative_cycle = True

if negative_cycle:
    print('inf')
else:
    print(-dist[n-1])


Measured memory_bytes: 3444
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N, C, K;
    cin >> N >> C >> K;

    vector<ll> T(N);
    rep(i, N) cin >> T[i];

    sort(ALL(T));

    vector<ll> lims(N);
    rep(i, N) { lims[i] = T[i] + K; }

    // repv(lims) cout << *it << " ";
    // cout << endl;

    ll idx = 0, ans = 0;
    for (ll i = 0; i < N;) {
        ans++;
        idx = i;
        while (i < N && lims[i] <= lims[idx] + K && i - idx < C) {
            i++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4680
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>

using ll = long long;
using monster = std::pair<ll, ll>;

/*
貪欲法で解く：つまり爆風の左端にモンスターがいるように攻撃
1. 左端の決定
2. 攻撃対象となるモンスターを決定
3. 体力を引く
ただし高速化のために累積和的な考え方をする

半径Dの攻撃 -> [L, L + 2D]まで攻撃
*/

int main(){
    ll N, D, A;
    scanf("%lld %lld %lld%*c", &N, &D, &A);
    std::vector<monster> monsters(N);
    for(int i = 0; i < N; i++){
        std::cin >> monsters[i].first >> monsters[i].second;
    }

    // 座標の小さい順にsort
    std::sort(monsters.begin(), monsters.end());

    ll ans = 0; // 爆弾の使用回数の総和
    ll DD = 2 * D; // 長さ
    ll total = 0; // 今与えているダメージの総和
    std::queue<monster> Q; // あとから足し算するときに使用
    for(int i = 0; i < N; i++){
        ll x = monsters[i].first;
        ll life = monsters[i].second;

        // ダメージを間違って与えてしまった部分の修正
        while(Q.size() > 0 && Q.front().first < x){
            total -= Q.front().second;
            Q.pop();
        }

        life -= total; // これまで今の左端の敵へのダメージが計算される
        if(life > 0){
            ll num = (life + A - 1) / A; // 今の左端の敵を倒すのに必要な爆弾の個数 A - 1を倒してギリギリ次の倍数を持たない所まで増やす
            ans += num;
            ll damage = num * A;
            total += damage;
            Q.emplace(x + DD, damage); // 与えすぎた分を追加
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
#define R register
#define MN 5005
#define P 1000000007
typedef long long ll;
char s[MN];int n,f[MN][MN],len;
inline void rw(int &x,int y){if ((x+=y)>=P) x-=P;}
inline int mul(int x,int y){return (ll)x*y%P;}
inline int pw(int x,int k){
	R int res=1;
	for (; k; k>>=1,x=mul(x,x)) 
		if (k&1) res=mul(res,x);
	return res;
}
int main(){
	scanf("%d%s",&n,s+1);
	len=strlen(s+1);f[0][0]=1;
	for (R int i=1; i<=n; ++i)
		for (R int j=0; j<=n; ++j){
			rw(f[i][j],f[i-1][j+1]);if (!j) rw(f[i][j],f[i-1][j]);
			if (j) rw(f[i][j],f[i-1][j-1]),rw(f[i][j],f[i-1][j-1]);
		}
	printf("%d\n",mul(f[n][len],pw(pw(2,len),P-2)));
}

Measured memory_bytes: 97920
#include<stdio.h>
#include<string.h>

int main(void){
	char str[1001];
	int ans;
	char* p;

	gets(str);
	while(strcmp(str, "0") != 0){
		ans = 0;
		p = str;
		while(*p != '\0'){
			ans += (int)*p - 0x30;
			p++;
		}
		printf("%d\n", ans);
		gets(str);
	}

	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s, t;
  cin >> s >> t;
  int x, y;
  cin >> x >> y;
  string ans, dir = "UDLR";
  int n = x - s;
  int m = y - t;
  for (int i = 0; i < n; i++) {
	ans += dir[3];
  }
  for (int i = 0; i < m; i++) {
	ans += dir[0];
  }
  for (int i = 0; i < n; i++) {
	ans += dir[2];
  }
  for (int i = 0; i < m; i++) {
	ans += dir[1];
  }
  ans += dir[1];
  for (int i = 0; i < n + 1; i++) {
	ans += dir[3];
  }
  for (int i = 0; i < m + 1; i++) {
	ans += dir[0];
  }
  ans += dir[2];
  ans += dir[0];
  for (int i = 0; i < n + 1; i++) {
	ans += dir[2];
  }
  for (int i = 0; i < m + 1; i++) {
	ans += dir[1];
  }
  ans += dir[3];
  cout << ans << endl;
  return 0;
}



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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

struct BIT{
	vector<int> val;
	BIT(int n) {val = vector<int>(n+10, 0);}
	BIT() {BIT(1);}
	void update(int v, int k) {for(v+=5; v<SZ(val); v+=v&-v) val[v] += k;}
	void update(int a, int b, int k) {update(b+1, -k); update(a, k);}
	int getSum(int v) {int res = 0; for(v+=5; v>0; v-=v&-v) res += val[v]; return res;}
	int getSum(int a, int b) {return getSum(b) - getSum(a-1);}
};

BIT bit;

const int MAX_N = 3e5 + 100, MAX_M = 1e5 + 100;

int N, M;
pi Nr[MAX_N];

int main() {
	cin >> N >> M;
	bit = BIT(M);
	for(int i=0; i<N; i++) scanf("%d%d", &Nr[i].one, &Nr[i].two);
	sort(Nr, Nr+N, [&](pi &x, pi &y) {return x.two - x.one < y.two - y.one;});
	for(int d=1, ix=0; d<=M; d++) {
		while(ix < N && Nr[ix].two - Nr[ix].one + 1 < d) bit.update(Nr[ix].one, Nr[ix].two, 1), ix++;
		int ans = 0;
		for(int i=0; i<=M; i+=d) ans += bit.getSum(0, i);
		printf("%d\n", N-ix + ans);
	}
	return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

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

        int[] a = new int[n + 1];
        int count = 0 ;
        for (int i = 1 ; i < n + 1 ; i++) {
            if (s.substring(i - 1, i).equals("#")) {
                count++;
            }
            a[i] = count;
        }

        int min = 12345567;
        for (int i = 0 ; i < n + 1 ; i++) {
            int b = n - i - (a[n] - a[i]);
            int w = a[i];
            min = Math.min(min, b + w);
        }

        System.out.println(min);
    }

}


Measured memory_bytes: 38420
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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! {
        s: String
    }
    let keyence = "keyence";
    let mut flg = s.starts_with(keyence) || s.ends_with(keyence);
    for i in 1..keyence.len() {
        let slice_b = &keyence[..i];
        let slice_a = &keyence[i..];
        if s.starts_with(slice_b) && s.ends_with(slice_a) {
            flg = true;
        }
    }
    println!("{}", if flg {"YES"} else {"NO"});
}


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

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

  int cnt = 0;

  for (int i = 100; i >= 1; i--) {
    if (a % i == 0 && b % i == 0) cnt++;

    if (cnt == k) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

int N, Nr[2][MAX_N];
int Max[2][MAX_N];
int main() {
	cin >> N;
	for(int i=0; i<N; i++) {
		int x; scanf("%d", &x);
		Nr[i%2][x]++;
	}
	int V=100000;
	for(int i=1; i<=V; i++) {
		Max[0][i] = max(Max[0][i-1], Nr[1][i]);
		Max[1][V+1-i] = max(Max[1][V+1-i+1], Nr[1][V+1-i]);
	}
	int ans = INF;
	for(int i=1; i<=V; i++) {
		ans = min(ans, (N/2 - Nr[0][i]) + (N/2 - max(Max[0][i-1], Max[1][i+1])));
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5244
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	long long n, m;
	cin >> n >> m;
	long long ans = 1;
	for (long long i = 1; i * i <= m; i++) {
		if (m % i == 0) {
			if (m / n >= i)ans = max(ans, i);
			if (m / n >= m / i)ans = max(ans, m / i);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int d[201][201];
signed main() {
    REP(i,201) {
        d[i][i]=0;
        REP(j,201) {
            d[i][j]=INF;
        }
    }
    int n,m,R;
    cin>>n>>m>>R;
    vector<int> r(R);
    cin>>r;
    REP(i,m) {
        int a,b,c;
        cin>>a>>b>>c;
        d[a-1][b-1]=d[b-1][a-1]=c;
    }

    REP(i,n) {
        REP(j,n) {
            REP(k,n) {
                chmin(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }

    sort(ALL(r));
    int ans=INF;
    do {
        int tmp=0;
        REP(i,R-1) {
            tmp+=d[r[i+1]-1][r[i]-1];
        }
        chmin(ans,tmp);
    } while(next_permutation(ALL(r)));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
n,w,temp = int(input()),[],[]
for i in range(n):
    w.append(input())
    if w[-1] in temp:
        print("No")
        exit()
    else:
        temp.append(w[-1])
    if i>0 and w[i-1][-1] != w[i][0]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3060
solve2 result  (i1:i2:[]) = result
solve2 result (i1:i2:i3:rest)  =
    solve2 (result + if ((i1 < i2) == (i3 < i2)) then 0 else 1) (i2:i3:rest) 

solve :: [Int] -> Int
solve (n:p)  = solve2 0 p
    
main = interact $ show.solve.map read.words


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>

#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    ll N, M; cin >> N >> M;
    vector<pll> p(N);
    rep (i, N) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    
    ll res = 0;
    for(int i = 0; i < N &&  M > 0; i++) {
            res += p[i].first * min(M, p[i].second);
            M -= min(M, p[i].second);
    }
    cout << res << endl;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
    #define hell        1000000007
    #define rn          return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();
            
        }
        return 0;
    }
    const int N = 1e3 + 5, K = 12;
    void solve(){
        int a,b;
        cin>>a>>b;
        cout<<a*b<<endl;
    }   


Measured memory_bytes: 3612
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[i + 1], a[r] = a[r], a[i + 1]
    return i + 1


n = int(input())
*s, = map(int, input().split())

c = partition(s, 0, n - 1)
for i in range(n):
    s[i] = f"[{s[i]}]" if i == c else s[i]
print(" ".join([str(v) for v in s]))


Measured memory_bytes: 16404
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
 
ll mymod(ll a, ll b)
{
	return (a%b + b)%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
struct edge
{
	ll src;
	ll to;
	ll val;
	ll index;
};
struct node
{
	vll adj;
	ll parent;
	ll time;
	ll ex_time;
	ll indegree;
};

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
	cin>>n;
	if(n==2)
	{
		cout<<"1\n";
		exit(0);
	}
	vll factors;
	vll factors2;
	REP(i,2,sqrt(n))
	{
		if(n%i==0)
		{
			factors.pb(i);
			factors.pb(n/i);
		}
	}
	if((ll)(sqrt(n)) * (ll)(sqrt(n)) == n)
	{
		factors.pb(sqrt(n));
	}
	REP(i,2,sqrt(n-1))
	{
		if((n-1)%i==0)
		{
			factors.pb(i);
			factors.pb((n-1)/i);
		}
	}
	if((ll)(sqrt(n-1)) * (ll)(sqrt(n-1)) == n-1)
	{
		factors2.pb(sqrt(n-1));
	}
	ll ans=2;
	ans+=factors2.size();
	for(auto x: factors)
	{
		ll temp=n;
		while(temp%x==0)
		{
			temp/=x;
		}
		if(temp%x==1)
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
char Str[100005];

int main(){
    int N , k , i , Ans , Count = 0;
    scanf( "%d%d" , &N , &k );
    scanf( "%s" , Str );

    for( i = 1 ; i < N ; ++i ){
        if( Str[i] != Str[i - 1] ) ++Count;
    }

    if( Count == 0 ){
        printf( "%d\n" , N - 1 );
        return 0;
    }

    Ans = N - ( Count + 1 );
    int Temp = ( Count - 1 );

    if( (Temp % 2) == 0 ){
        Temp /= 2;
        Ans += 2 * min( Temp , k );
        k -= min( Temp , k );
        if( k >= 1 ) ++Ans;
    }
    else{
        Temp /= 2;
        if( k >= Temp + 1 ) Ans = N - 1;
        else Ans += 2 * min( Temp , k );
    }

    printf( "%d\n" , Ans );
    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def trisection(l,r,f,convex=True,discrete=True):
    eps=2 if(discrete) else 10**-12
    while(r-l>eps):
        d=(r-l)//3 if(discrete) else (r-l)/3
        h1=l+d; h2=r-d
        if((f(h1)>=f(h2))^convex): r=h2
        else: l=h1
    if(discrete):
        if(convex): return min([(f(l),l),(f(l+1),l+1),(f(r),r)])[1]
        else: return max([(f(l),l),(f(l+1),l+1),(f(r),r)])[1]
    else:
        if(convex): return min([(f(l),l),(f(r),r)])[1]
        else: return max([(f(l),l),(f(r),r)])[1]

def resolve():
    for _ in range(int(input())):
        a,b=map(int,input().split())
        l=0; r=a+b
        while(r-l>1):
            h=(l+r)//2
            f=lambda x:(x+(x>=a))*(h-x+1+(h-x+1>=b))
            x=trisection(1,h,f,convex=False,discrete=True)
            if(f(x)<a*b): l=h
            else: r=h
        print(l)
resolve()

Measured memory_bytes: 49244
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const ll INF = 1001001001;
const double pi = acos(-1);

ll ans1 = 0;

int main()
{
    ll d;
    cin >> d;
    vector<ll> c(26);
    for (ll i = 0; i < 26; i++)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    for (ll i = 0; i < d; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            cin >> s[i][j];
        }
    }
    vector<ll> t(d);
    for (ll i = 0; i < d; i++)
    {
        cin >> t[i];
    }

    vector<ll> last(d, 0);
    ll ans = 0;
    for (ll i = 0; i < d; i++)
    {
        ll day = t[i] - 1;
        last[day] = i + 1;
        ll sad = 0;
        ll score = s[i][day];
        for (int j = 0; j < 26; j++)
        {
            sad += c[j] * (i + 1 - last[j]);
        }
        ans += score - sad;
        cout << ans << endl;
        last[day] = i + 1;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  string a,b,c;
  cin >> a >> b >> c;
  ll ans=0;
  rep(i,n){
    if(a[i]==b[i]){
      if(b[i]==c[i]) continue;
      else ans++;
    }
    else if(b[i]==c[i]){
      ans++;      
    }
    else if(a[i]==c[i]){
      ans++;
    }
    else ans+=2;
  }
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int main()
{
  int R,G,B,N;
  cin >> R >> G >> B >> N;

  int ans = 0;  //(r,g,b)の組の数
  REP(r,0,N+1) {
    REP(g,0,N+1) {
      // 合計でちょうどN個
      if (R * r + G * g <= N &&
          (N - (R * r + G * g)) % B == 0) {
        ++ans;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	f = 1
	h1,s1,h2,s2 = l
	while(h1 > 0 and h2 > 0):
		h2 -= s1
		if(h2 <= 0):
			break
		h1 -= s2
	if(h1 <= 0):
		f = 0
	if(f):
		return 'Yes'
	else:
		return 'No'

l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)



Measured memory_bytes: 76412
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n){
    cin >> d[i];
  }
  boost::sort(d);
  int m;
  m = d[n/2]-d[n/2-1];
  cout << m << endl;

  return 0;
}


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

int main()
{
  int day,J,M,Jday,Mday,asobuz;

  cin >> day;
  cin >> J;
  cin >> M;
  cin >> Jday;
  cin >> Mday;

  int a = 0;
  while(J > 0){
    J -= Jday;

    a++;
  }

  int b = 0;
  while(M > 0){
    M -= Mday;
    b++;
  }
 
  if(a > b){
    asobuz = a;
  }
  else{ 
    asobuz = b;  
  }

  day -= asobuz; 
  cout << day << endl;

}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val n = readInteger()
//    val lList = readIntegerList().sorted().mapIndexed { index, i -> Pair(i, index) }
    val lList = readIntegerList().sorted()

    var ans = 0L
    for (i in lList.indices) {
        for (j in (i + 1) until lList.size) {
            val a = lList[i]
            val b = lList[j]
            val cCount = Math.max(0, lowerBound(lList, a + b) - j - 1)
            ans += cCount
        }
    }

    println(ans)
}

fun <T : Comparable<T>>lowerBound(list: List<T>, target: T): Int {
    var left = -1
    var right = list.size
    while (right - left > 1) {
        val mid = (right + left) / 2
        if (target <= list[mid])  {
            right = mid
        } else {
            left = mid
        }
    }

    return right
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 50432
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
       
        int finAns=0;
 
        end: {
            while(true) {
                int a = stdin.nextInt();
                String op = stdin.next();
                int b = stdin.nextInt();
 
                switch (op) {
                    case "+": 
                    finAns = a + b;
                    break;
                   
                    case "-": 
                    finAns = a - b; 
                    break;
                   
                    case "*": finAns = a * b; 
                    break;
                   
                    case "/": finAns = a / b; 
                    break;
                   
                    case "?": 
                    break end;
                }
 
                System.out.println(finAns);
            }
        }
    }
}

Measured memory_bytes: 26140
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<cctype>
#include<time.h>
#include<cstdlib>
#include<iomanip>
using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define INF2 1000000000000000000
#define int long long
int mod = 1000000007;
int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}


int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    string S;
    cin >> N >> P;
    cin >> S;
    if(P == 2 || P == 5) {
        int ans = 0;
        rep(i, N) {
            int num = S[i] - '0';
            if(num % P == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    mod = P;
    int ans = 0;
    map<int, int> mp;
    int sum = 0;
    rep(i, N) {
        int num = power(10, i) * (S[N - i - 1] - '0') % P;
        sum = (sum + num) % P;
        mp[sum]++;
    }
    sum = 0;
    int num = 0;
    rep(i, N) {
        //cerr << i << " " << sum << " ";
        int k = power(10, i) * (S[N - i - 1] - '0') % P;
        ans += mp[(P - sum) % P];
        sum = (sum - (k) + P*10) % P;
        //sum = (sum * 10) % P;
        num = (num + k) % P;
        mp[num]--;
        //cerr << ans << endl;
    }
    cout << ans << endl;


    return 0;
}
// 3000, 3500,3540, 3543
//       500, 540,   543
//            40,     43
//                     3

Measured memory_bytes: 4116
#!/usr/bin/env ruby
k = gets.chomp.to_i
a, b = gets.chomp.split(' ').map(&:to_i)

ans = false
a.upto(b) do |i|
  if i % k == 0
    ans = true
    break
  end
end

puts ans ? 'OK' : 'NG'


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

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

const int NMAX = 52;
const int LMAX = 62;
const ll MOD = 1e9+7;

int adj[NMAX][NMAX];

ll dp[NMAX][NMAX][LMAX];
ll dp2[NMAX][NMAX][2];
int N;
ll K;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> K;
	for(int i=0;i<N;++i) {
		for(int j=0;j<N;++j) {
			cin >> adj[i][j];
			if(adj[i][j]) {
				dp[i][j][0] = 1;
			}
		}
	}
	for(int l=0;l<LMAX-1;++l) {
		for(int i=0;i<N;++i) {
			for(int j=0;j<N;++j) {
				for(int k=0;k<N;++k) {
					dp[i][j][l+1] = (dp[i][j][l+1]+dp[i][k][l]*dp[k][j][l])%MOD;
				}
				//cerr << "  dp[" << i << "][" << j << "][" << l+1 << "] = " << dp[i][j][l+1] << endl;
			}
		}
	}
	int c = 0;
	int n = 1;
		
	for(int i=0;i<N;++i)
		dp2[i][i][c] = 1;

	for(int l=0;l<LMAX;++l) {
		if(!((1LL<<l)&K)) continue;
		//cerr << " . " << l << endl;
		for(int i=0;i<N;++i) {
			for(int j=0;j<N;++j) {
				for(int k=0;k<N;++k) {
					dp2[i][j][n] = (dp2[i][j][n]+dp2[i][k][c]*dp[k][j][l])%MOD;
					//nxt[i][j] = (nxt[i][j]+cur[i][k]*dp[k][j][l])%MOD;
				}
				//cerr << ".dp2[" << i << "][" << j << "] = " << dp2[i][j][n] << endl;
			}
		}
		swap(c, n);
		for(int i=0;i<N;++i) {
			for(int j=0;j<N;++j) {
				dp2[i][j][n] = 0;
				////cerr << ".dp2[" << i << "][" << j << "] = " << dp2[i][j][c] << endl;
			}
		}
	}
	ll ans = 0;
	for(int i=0;i<N;++i) {
		for(int j=0;j<N;++j) {
			ans = (ans+dp2[i][j][c])%MOD;
			//cerr << " !dp[" << i << "][" << j << "] = " << dp2[i][j][c] << endl;
		}
	}

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


Measured memory_bytes: 1536
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 2000000005
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

int n,m,k;
int x[100000],y[100000],z[100000];
VPi v[200001];
int a[200001];
bool ok=1;
bool bfs(int x)
{
	int mn0=INF,mn1=INF;
	queue<int> q;
	q.push(x);
	a[x]=0;
	while(!q.empty())
	{
		int y=q.front();
		if(y<n)mn0=min(mn0,a[y]);
		else mn1=min(mn1,a[y]);
		q.pop();
		for(auto p:v[y])
		{
			if(a[p.X]==-INF)
			{
				q.push(p.X);
				a[p.X]=p.Y-a[y];
			}
			else if(a[p.X]+a[y]!=p.Y)return 0;
		}
	}
	return 1LL*mn0+1LL*mn1>=0;
}
int main(){
	fill(a,a+200001,-INF);
	scanf("%d%d%d",&n,&m,&k);
	fup(i,0,k-1,1)
	{
		scanf("%d%d%d",x+i,y+i,z+i);
		x[i]--,y[i]--;
		v[x[i]].pb(mp(y[i]+n,z[i]));
		v[y[i]+n].pb(mp(x[i],z[i]));
	}
	fup(i,0,n+m-1,1)if(a[i]==-INF && !bfs(i))return !printf("No");
	puts("Yes");
}

Measured memory_bytes: 13184
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(int arg_loc,int arg_value){
		loc = arg_loc;
		value = arg_value;
	}
	int loc,value;
};

int A,D;

int calc(int loc){
	return A + (loc-1)*D;
}

int main(){

	int N;
	scanf("%d",&N);

	scanf("%d %d",&A,&D);

	int Q;
	scanf("%d",&Q);

	int x,y,z;

	vector<Info> V;

	bool Y_FLG,Z_FLG;
	int Y_pos,Z_pos,tmp;

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %d",&x,&y,&z);

		Y_FLG = false;
		Z_FLG = false;

		for(int i = 0; i < V.size(); i++){
			if(V[i].loc == y){
				Y_FLG = true;
				Y_pos = i;
			}else if(V[i].loc == z){
				Z_FLG = true;
				Z_pos = i;
			}
		}

		if(x == 0){

			if(Y_FLG == false && Z_FLG == false){

				V.push_back(Info(z,calc(y)));
				V.push_back(Info(y,calc(z)));

			}else if(Y_FLG == true && Z_FLG == false){

				tmp = V[Y_pos].value;
				V[Y_pos].value = calc(z);
				V.push_back(Info(z,tmp));

			}else if(Y_FLG == false && Z_FLG == true){

				tmp = V[Z_pos].value;
				V[Z_pos].value = calc(y);
				V.push_back(Info(y,tmp));

			}else{ //Y_FLG == true && Z_FLG == true
				swap(V[Y_pos].value,V[Z_pos].value);
			}
		}else{

			if(Y_FLG == false && Z_FLG == false){

				V.push_back(Info(y,calc(z)));

			}else if(Y_FLG == true && Z_FLG == false){

				V[Y_pos].value = calc(z);

			}else if(Y_FLG == false && Z_FLG == true){

				tmp = V[Z_pos].value;
				V.push_back(Info(y,tmp));

			}else{ //Y_FLG == true && Z_FLG == true
				V[Y_pos].value = V[Z_pos].value;
			}
		}
	}

	int K;
	scanf("%d",&K);

	bool FLG = false;

	for(int i = 0; i < V.size(); i++){
		if(V[i].loc == K){
			printf("%d\n",V[i].value);
			FLG = true;
		}
	}

	if(!FLG){
		printf("%d\n",calc(K));
	}

	return 0;
}

Measured memory_bytes: 3232
#include <stdio.h>


int main(void){
  int a,b;
  int ans;

  scanf("%d",&a );
  scanf("%d",&b );

  if(a<=9&&b<=9){
    ans=a*b;
  }else{
    ans= -1;
  }

  printf("%d\n",ans );
  return 0;
}


Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
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")
}
 
//main function
fn main() {
    let string: String = read();
    let cvec: Vec<char> = string.chars().collect();
    if cvec[2]==cvec[3]&&cvec[4]==cvec[5]{
	println!("Yes");
    }else{
	println!("No");
    }
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
    {
        cout << "error" << endl;
    }
    else
    {
        cout << a + b << endl;
    }
}

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

int main(){
	int N, K;
	cin >> N >> K;
	int R, S, P;
	cin >> R >> S >> P;
	string T;
	cin >> T;
	
	int64_t ans_point = 0;
	for(int i = 0; i < K; ++i){
		int length = N / K;
		if(i < N % K) length++;
		vector<vector<int64_t>> dp(length+1, vector<int64_t>(3, 0));
		for(int j = 0; j < length; ++j){
			for(int k = 0; k < 3; ++k){
				char enemy_hand = T.at(j * K + i);
				int64_t point = ('s' == enemy_hand && 0 == k) ? R :
								('p' == enemy_hand && 1 == k) ? S :
								('r' == enemy_hand && 2 == k) ? P : 0;
				dp[j+1][k] = max(dp[j][(k+1)%3] + point, dp[j][(k+2)%3] + point);
			}
		}
		int64_t max_point = max(dp[length][0], dp[length][1]);
		max_point = max(dp[length][2], max_point);
		ans_point += max_point;
	}
	cout << ans_point << endl;
	return 0;
}


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

int main(){

    ll a, b;
    cin >> a >> b;

    if ((a + b)%2 == 0){
        cout << (a + b)/2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    int ureshisa=0;
    cin>>n;
    while(n>=500){
        n-=500;
        ureshisa+=1000;
    }
    while(n>=5){
        n-=5;
        ureshisa+=5;
    }
    cout<<ureshisa;
}


Measured memory_bytes: 256