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


int main(){
  int N, M;
  cin >> N >> M;
  vector<set<int>> E(N);
  for(int ii=0; ii<M; ii++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].insert(b);
    E[b].insert(a);
  }
  vector<int> ans(N, -1);
  queue<int> Q;
  Q.push(0);
  ans[0] = 0;
  while(Q.size()){
    int pos = Q.front();
    Q.pop();
    for(auto& next : E[pos]){
      if(ans[next]!=-1) continue;
      Q.push(next);
      ans[next] = pos;
    }
  }

  cout << "Yes" << endl;
  for(int ii=1; ii<N; ii++){
    cout << ans[ii]+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 27356
//Om Sree Sai Ram
#include "bits/stdc++.h"
using namespace std;

template <typename T> void max_self(T& a,T b)
{
  a = max(a,b);
}

vector<int> dp;
vector<int> vis;

int main() 
{
// #ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
// #endif
int n;
cin>>n;
//dp[i] referse to probability of getting i number of heads
vector<double> dp(n+1);
dp[0] = 1;
for(int i=0;i<n;i++)
{
  double prob;
  cin>>prob;
  //dp[i] = dp[i]*(1-prob); 
  for(int c=i+1;c>=0;c--)
  {
    dp[c] = (c==0?0:dp[c-1])*prob + dp[c]*(1-prob);
  }
}
double ans=0;
for(int i=n/2+1;i<=n;i++)
{
 ans+=dp[i];
}
cout.precision(9);
cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
a_s = list(map(int, input().split()))
mn = (100-(-100))**2*n
for i in range(-100, 101):
  t = []
  for a in a_s:
    t.append((a-i)**2)
  if sum(t) < mn:
    mn = sum(t)
print(mn)

Measured memory_bytes: 3060
N,M = map(int, input().split())
if N==1 and M==1:
  result = 0
if 0<=N and N<=1 and 2<=M:
  result = M*(M-1)//2
if 2<=N and 0<=M and M<=1:
  result = N*(N-1)//2
if 2<=N and 2<=M:
  result = (N*(N-1)+M*(M-1))//2
  
print(result)

Measured memory_bytes: 9132
<?php
$cards = array();

foreach (array('S', 'H', 'C', 'D') as $mark) {
    $cards[$mark] = array_reduce(range(1, 13), function ($carry, $item) { $carry[$item] = false; return $carry; }, array());
}

fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s %d", $s, $x);

    $cards[$s][$x] = true;
}

foreach ($cards as $m => $nums) {
    foreach ($nums as $i => $found) {
        if ($found) continue;

        echo "$m $i\n";
    }
}

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

#include<stdio.h>

int main(){
  int a, b;
  cin >> a >> b;
  cout << a / b << " ";
  cout << a % b << " ";
  double f = 1.0 * a / b;
  printf("%.5f\n",  f);
  return 0;
}

Measured memory_bytes: 1240
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

count :: Int -> Int -> Int
count 1 1 = 1
count 1 m = m - 2
count n 1 = n - 2
count n m = (n - 2) * (m - 2)

main :: IO ()
main = do
    [n,m] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    print $ count n m


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
int H, N;
vector<pair<int, int>> v;
map<int, int> m;
int solve(int H) {
    if (H <= 0) return 0;
    if (m.find(H) != m.end()) return m[H];
    int res = INT_MAX;
    for (auto x: v) {
        res = min(res, solve(H - x.first) + x.second);
    }
    return m[H] = res;
}
int main () {
    cin >> H >> N;
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        v.push_back(make_pair(A, B));
    }
    cout << solve(H) << endl;
}

Measured memory_bytes: 1664
from fractions import gcd

a,b,c,d=map(int,input().split( ))

def prime_cd(n,c,d):
    c_div=n//c
    d_div=n//d
    lcm=c*d//gcd(c,d)
    cd_div=n//lcm
    return n-c_div-d_div+cd_div

print(prime_cd(b,c,d)-prime_cd(a-1,c,d))


Measured memory_bytes: 66156
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 1e6+3;

Int h, w;
char f[2001][2001];
 
Int tate[2001][2001];
//Int t_sz[2001][2001];
Int yoko[2001][2001];
//Int y_sz[2001][2001];
/* 
Int root(Int i, Int x) {
    if ()
}
 */

int main() {
    cin >> h >> w;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cin >> f[i][j];
        }
    }
    for (Int i = 0; i < h; i++) {
        Int cnt = 1;
        for (Int j = 0; j < w; j++) {
            if (f[i][j] == '.') {
                yoko[i][j] = cnt;
                cnt++;
            }
            else {
                cnt = 1;
            }
        }
    }
    for (Int i = 0; i < h; i++) {
        Int ma = -1;
        for (Int j = w - 1; j >= 0; j--) {
            if (yoko[i][j] > 0) {
                yoko[i][j] = max(yoko[i][j], ma);
                ma = yoko[i][j];
            }
            else {
                ma = -1;
            }
        }
    }
    for (Int i = 0; i < w; i++) {
        Int cnt = 1;
        for (Int j = 0; j < h; j++) {
            if (f[j][i] == '.') {
                tate[j][i] = cnt;
                cnt++;
            }
            else {
                cnt = 1;
            }
        }
    }
    for (Int i = 0; i < w; i++) {
        Int ma = -1;
        for (Int j = h - 1; j >= 0; j--) {
            if (tate[j][i] > 0) {
                tate[j][i] = max(tate[j][i], ma);
                ma = tate[j][i];
            }
            else {
                ma = -1;
            }
        }
    }
    Int res = 0;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            res = max(res, tate[i][j] + yoko[i][j]);
        }
    }
    dump(res - 1);
    /* for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cin >> f[i][j];
            t_sz[i][j] = y_sz[i][j] = 1;
        }
    }
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            yoko[i][j] = j;
        }
    }
    for (Int i = 0; i < w; i++) {
        for (Int j = 0; j < h; j++) {
            tate[j][i] = j;
        }
    }
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w - 1; j++) {
            if (f[i][j] == '.' && f[i][j + 1] == '.') {
                unite(i, j, j + 1);
            }
        }
    } */
    return 0;
}

Measured memory_bytes: 66688
s = ""

def format_input(filename = None):
	global s
	if filename == None:
		s = list(map(str, input().split())).pop()

def get_answer():
	length = len(s)
	answer = "x" * length
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
int main() {
  int n;
  cin >>n;
  vector<int>a(n);
  int count=0;
  long long sum=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a[i]=abs(x);
    if(x<0)count++;
    sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  if(count%2==0){
    cout<<sum<<endl;
  }else{
    sum-=a[n-1]*2;
    cout<<sum<<endl;
  }
  return 0;
}

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

int main() {
  int n,k;
  vector<int>l(n);
  cin>>n>>k;
  int ans=1;
  int now=0;
  for(int i=0;i<n;i++){
    cin>>l.at(i);
    now+=l.at(i);
    if(now<=k){
      ans++;
    }
  }
  cout <<ans;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
int n = 100, m = 100, c[105][105], f = 0, A, B;
int main()
{
	A = read(), B = read(); printf("%d %d\n",n,m); A--, B--;
	for(rint i = 1, j; i <= n; i++) for(j = 1; j <= m; c[i][j] = i<=n/2, j++);
	for(rint i = 1, x = 1, y = 1; i <= A; i++)
		c[x][y] = 0, (y+=2)>m?x += 2,y = 1:0;
	for(rint i = 1, x = n, y = m; i <= B; i++)
		c[x][y] = 1, (y-=2)<1?x -= 2,y = m:0;
	for(rint i = 1, j; i <= n; putchar('\n'), i++) for(j = 1; j <= m; printf("%c",c[i][j]?'#':'.'), j++); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0; i<n; i++)
#define out(x) cout<<(x)<<"\n"
 
int main(){
  int a,b,c,A;
  cin>>a>>b>>c;
  if(a==b && b==c){
    A=1;
    }
  else if(a==b || b==c || c==a){
    A=2;
  }
  else{
    A=3;
  }
out(A);
}

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

int main(){
        string str;

        cin >> str;
        int badFlg=0;
        int len = str.length();
        for(int i=0;i<len-1;i++){
                if(str[i] == str[i+1])
                        badFlg=1;
        }
        if(badFlg == 1){
                cout << "Bad";

        }else{
                cout << "Good";
        }

        return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int sum = 0;

    for(int i=0; i<N; i++){
        int l, r;
        int num = 0;
        cin >> l >> r;
        num = (r - l) +1;
        sum += num;
    }
    cout << sum << endl;
}


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

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

    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>() );

    int a=0;
    int b=0;

    for(int i=0; i<N; i++)
    {
        if( 0 == (i%2) ) a += A[i];
        else             b += A[i];
    }

    cout << a-b << endl;
  }

Measured memory_bytes: 256
import collections

N = int(input())
S = [input() for i in range(N)]

# print(S)

count = collections.Counter(S)

# print(count)

max_value = max(count.values())

max_k_list = []

for k, v in sorted(count.items(), key=lambda x: x[1], reverse=True):
    if v == max_value:
        max_k_list.append(k)
    else:
        break

max_k_list.sort()

for i in max_k_list:
    print(i)


Measured memory_bytes: 45084
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;

struct edge { int dst, silver, time; };

int main() {
    int n, m, S; cin >> n >> m >> S;
    S = min(S, 2450);
    vector<edge> adj[n];
    for (int i = 0; i < m; i++) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--; v--;
        adj[u].push_back({v, -a, b});
        adj[v].push_back({u, -a, b});
    }
    for (int i = 0; i < n; i++) {
        int c, d; cin >> c >> d;
        adj[i].push_back({i, c, d});
    }

    priority_queue<pair<long long, pair<int, int> > > pq;
    long long time[n][2451];
    for (int i = 0; i < n; i++) fill(time[i], time[i]+2451, 1LL<<60);
    pq.push({0, {0, S}});
    time[0][S] = 0;
    while (!pq.empty()) {
        long long t = -pq.top().first;
        int u = pq.top().second.first, s = pq.top().second.second;
        pq.pop();
        if (t > time[u][s]) continue;
        for (auto e : adj[u]) {
            long long t1 = t + e.time;
            int u1 = e.dst, s1 = min(s + e.silver, 2450);
            if (0 <= s1 && time[u1][s1] > t1) {
                time[u1][s1] = t1;
                pq.push({-t1, {u1, s1}});
            }
        }
    }
    for (int u = 1; u < n; u++)
        cout << *min_element(time[u], time[u] + 2451) << endl;
}


Measured memory_bytes: 6264
#include <iostream>

using namespace std;

int main(){
  
 	int n;
  cin >> n;
  n = 25 - n;
  
  cout << "Christmas";
  
  for(int i = 0 ; i < n ;i++){
   	cout << " Eve";
  }
  
  cout << endl;
  
  return 0;
  
}


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

int n;

struct Node
{
  int key;
  Node *parent, *left, *right;
};

// rootの初期化はしなくていいの? <- ともに値が0になっている
Node *root, *NIL;

void insert(int key)
{
  // zの親を格納する
  Node *y = NIL;
  Node *x = root;

  // zの生成
  Node *z = (Node *)malloc(sizeof(Node));
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL)
  {
    y = x;
    if (key < x->key)
    {
      x = x->left;
    }
    else
    {
      x = x->right;
    }
  }

  // yにはzの親が格納されている
  z->parent = y;

  if (y == NIL)
  {
    root = z;
  }
  else if (key < y->key)
  {
    y->left = z;
  }
  else
  {
    y->right = z;
  }
}

Node *find(int key)
{
  Node *x = root;
  while (x != NIL)
  {
    if (key == x->key)
    {
      return x;
    }
    else if (key < x->key)
    {
      x = x->left;
    }
    else
    {
      x = x->right;
    }
  }
  return NIL;
}

void inorder(Node *u)
{
  // ベースケース
  if (u == NIL)
  {
    return;
  }
  // 再帰ステップ
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u)
{
  // ベースケース
  if (u == NIL)
  {
    return;
  }
  // 再帰ステップ
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string com;
    cin >> com;
    if (com.at(0) == 'i')
    {
      // 挿入
      int key;
      cin >> key;
      insert(key);
    }
    else if (com.at(0) == 'p')
    {
      // 出力
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if (com.at(0) == 'f')
    {
      // 探索
      int key;
      cin >> key;
      if (find(key) != NIL)
      {
        printf("yes\n");
      }
      else
      {
        printf("no\n");
      }
    }
  }
}


Measured memory_bytes: 21932
//ITP1_8_A_19140837_Ojima_Yukiya.cpp
//提出日 2020/6/17 wednesday
//プログラミング基礎演習2 CS 第６回課題 ITP1_8_A
//学修番号 19140837　小島優希也

#include <iostream>
using namespace std;

int main(void) {
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++) {
        if ('a' <= s.at(i) && s.at(i) <= 'z') {
            cout << (char)((int)s.at(i) - 32);
        }
        else if ('A' <= s.at(i) && s.at(i) <= 'Z') {
            cout << (char)((int)s.at(i) + 32);
        }
        else {
            cout << s.at(i);
        }
    }
    cout << endl;
    return 0;

}


Measured memory_bytes: 3180
#include <iostream>

using namespace std;

int main()
{
    int P;
    int Q;
    int R;
    cin >> P >> Q >> R;

    if(P+Q<=Q+R)
    {
        if (P+Q<=P+R)
        {
            cout << P+Q;/* code */
        }else
        {
            cout << P+R;/* code */
        }    
    }else
    {
        if (Q+R<=P+R)
        {
            cout << Q+R;/* code */
        }else
        {
            cout << P+R;/* code */
        }
        /* code */
    }
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (a + b) * (a + b - 1) / 2 - a * b <<'\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int N,a[110],max=0,min=1000000000;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	for(int i=0;i<N;i++){
		if(a[i]>max){
			max=a[i];
		}
	}
	for(int i=0;i<N;i++){
		if(a[i]<min){
			min=a[i];
		}
	}
	cout<<max-min<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>
#include <stack>
#include <stdlib.h>
#include <sstream>
using namespace std;
string a;
int A, b, c, d;
stack<int> s;
int main()
{
	while(cin >> a)
	{
		if(a=="+")
		{
			b=s.top();
			s.pop();
			c=s.top();
			s.pop();
			s.push(c+b);
		}
		else if(a=="-")
		{
			b=s.top();
			s.pop();
			c=s.top();
			s.pop();
			s.push(c-b);
		}
		else if(a=="*")
		{
			b=s.top();
			s.pop();
			c=s.top();
			s.pop();
			s.push(c*b);
		}
		else
		{
			stringstream ss;
		    ss << a;
		    ss >> A;
		    ss.clear();
    		ss.str("");
    		s.push(A);
		}
	}
	cout << s.top() << endl;
	return 0;
}

Measured memory_bytes: 1236
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N
S[0] = 0
 
for i in range(1, N):
    value = math.inf
    for step in range(1, K + 1):
        if i - step < 0:
            break
        value = min(value, S[i - step] + abs(h[i] - h[i - step]))
    S[i] = value
print(S[N - 1])

Measured memory_bytes: 84908
#include <stdio.h>
#define Max 100

int main() {
    int A[Max][Max] = {};
    int n,u,k,v;
    int i,j;

    scanf("%d",&n);

    for (i = 0; i < n; ++i) {
        scanf("%d %d",&u,&k);
        u--;
        for (j = 0; j < k; ++j) {
            scanf("%d",&v);
            --v;
            A[u][v] =1;
        }
    }

    for (i = 0; i < n; ++i) {
        for (j = 0; j < n-1; ++j) {
            printf("%d ",A[i][j]);
        }
        printf("%d\n",A[i][n-1]);
    }
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int f[100010], h[100010];
int n, k;

inline void work() {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    for (int i = 2; i <= n; ++i) {
        f[i] = INT_MAX;
        for (int j = i - 1, jm = max(i - k, 1); j >= jm; --j) {
            f[i] = min(f[i], f[j] + abs(h[i] - h[j]));
        }
    }
    cout << f[n] << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

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

void factorize( int x, vector<int> &factors ){
    int d, q;
    while ( x >= 4 && x % 2 == 0 ) {
	factors.push_back(2);
	x /= 2;
    }
    d = 3; q = x / d;
    while ( q >= d ){
	if ( x % d == 0 ) {
	    factors.push_back(d);
	    x = q;
	} else {
	    d += 2;
	}
	q = x / d;
    }
    factors.push_back(x);
}

int key(int n){
    vector<int> factors;
    factorize(n, factors);
    vector<int>::iterator it = unique(factors.begin(), factors.end());
    factors.erase(it, factors.end());

    int sum = 0;
    for ( int i = 0; i < factors.size()-1; i++ ) sum += factors[i];

    return factors.back() - sum;
}

int main(void){
    int a, b;

    while(1){
	cin >> a >> b;
	if ( a == 0 && b == 0 ) break;
	if ( key(a) > key(b) ) cout << "a" << endl;
	else cout << "b" << endl;
    }


    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long x = Math.abs(sc.nextLong());
		long k = sc.nextLong();
		long d = sc.nextLong();
		sc.close();

		if (x / d > k) {
			print(x - d * k);
			return;
		}
		long min = x % d;
		boolean minIsEven = (x / d) % 2 == 0;
		boolean isEven = k % 2 == 0;
		if (minIsEven == isEven) {
			print(min);
			return;
		}
		print(d - min);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 35700
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int r,c,k;
ll v[3000][3000];
ll dp[3][3000][3000];
ll mx[3][3000][3000];
int main(){
	ios::sync_with_stdio(0);
	memset(v,0,sizeof(v));
	cin>>r>>c>>k;
	rep(i,k){
		int x,y,z;
		cin>>x>>y>>z;
		x--,y--;
		v[x][y]=z;
	}
	rep(i,r){
		rep(j,c){
			if(j)
			rep(k,3)
			mx[k][i][j]=mx[k][i][j-1];
			if(v[i][j]>mx[0][i][j]){
				mx[2][i][j]=mx[1][i][j];
				mx[1][i][j]=mx[0][i][j];
				mx[0][i][j]=v[i][j];
			}else{
				if(v[i][j]>mx[1][i][j]){
					mx[2][i][j]=mx[1][i][j];
					mx[1][i][j]=v[i][j];
					
				}else
				if(v[i][j]>mx[2][i][j])
				mx[2][i][j]=v[i][j];
			}
		}
	}
	rep(i,r)
	rep(j,c){
		dp[0][i][j]=v[i][j];
		if(i)
		dp[0][i][j]+=max(dp[0][i-1][j],max(dp[1][i-1][j],dp[2][i-1][j]));
		if(j){
			dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1]);
		}
		if(j)
		dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v[i][j]);
		if(j)
		dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v[i][j]);
	}
	cout<<max(dp[2][r-1][c-1],max(dp[1][r-1][c-1],dp[0][r-1][c-1]));
	re 0;
}

Measured memory_bytes: 495804
eval'N,X,M='+`tr ' ' ,`
s,*v=0
(v[X]=$.+=1
$*[X]=s
s+=X
v[X=X*X%M]&&(b=$.+1-v[X]
s+=N/b*(s-$*[X])
N%=b))until 0>N-=1
p s

Measured memory_bytes: 34596
main = do
    [s, t] <- words <$> getLine
    [a, b] <- map read . words <$> getLine :: IO [Int]
    u <- getLine
    if u == s
        then putStrLn $ show (a - 1) ++ " " ++ show b
        else putStrLn $ show a ++ " " ++ show (b - 1)


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

vector<ll> v[11];

bool dis(ll d, ll i, ll j)
{

    ll x = 0;
    for(ll ii = 0; ii < d; ii++)
    {

        x += (v[i][ii]-v[j][ii])*(v[i][ii]-v[j][ii]);
    }
    ll jj = sqrt(x);
    if(jj*jj==x) return true;
    else return false;
}

int main()
{


    ll n, d;
    cin >> n >> d;
    for(ll i = 0; i< n+1; i++) v[i].clear();
    for(ll i = 0; i < n; i++)
    {

        for(ll j  =0; j < d; j++)
        {

            ll x;
            cin >> x;
            v[i].pb(x);
        }
    }
    ll ans = 0;
    for(ll i = 0; i < n; i++)
    {

        for(ll j = i+1; j < n; j++)
        {

            bool tf = dis(d, i, j);
            if(tf) ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
S = list(input())
S = [char if char != '?' else None for char in S]
T = list(input())

# print(S)
# print(T)
# Tを部分文字列として含み、尚且つその中でもっとも辞書順で小さいものを選ぶ。
# 1<=S<=50なので、Sを全列挙することはできない(24**50)
# Sのうち、どこをTの部分文字列にするかを考えると、50文字あったとしても問題ないのでは？

texts = []
for i in range(len(S) + 1 - len(T)):
    # j = i + len(T)
    # print(S[i:j])

    is_fullfilled = True
    text = []
    for j, char in enumerate(T):
        if S[i + j] == char:
            text.append(char)
        elif S[i + j] is None:
            text.append(char)
        else:
            is_fullfilled = False
            break
    if is_fullfilled:

        text = ''.join(text)
        left = ''
        for char in S[:i]:
            if char is None:
                left += 'a'
            else:
                left += char
        right = ''
        for char in S[i + len(T):]:
            if char is None:
                right += 'a'
            else:
                right += char

        texts.append(left + text + right)
texts = sorted(texts)
if len(texts) == 0:
    print('UNRESTORABLE')
else:
    print(texts[0])


Measured memory_bytes: 9072
import java.util.*;

public class Main {    
    
    public static void main(String[] args){
       
       Scanner sc = new Scanner(System.in);       
                       
       long a = sc.nextLong();
       long b = sc.nextLong();
       long x = sc.nextLong();
       
       System.out.println(f(b,x) - f(a-1,x));       
              
    }  

    static long f(long a,long x){
        if(a == -1){
           return 0;
        }else{
           return (long)(a/x + 1);
        }
    }
    
}
        

Measured memory_bytes: 23764
# solution
import math
import io

data=int(input())
qwe = (list(map(int,input().split())))
score1=score2=0
cnt1=cnt2=0
for i ,num in enumerate(qwe):
	score1+=num
	if score1<=0 and i%2==0:
		cnt1+=1-score1
		score1=1
	elif score1>=0 and i%2!=0:
		cnt1+=1+score1
		score1=-1
		
	score2+=num
	if score2<=0 and i%2!=0:
		cnt2+=1-score2
		score2=1
	elif score2>=0 and i%2==0:
		cnt2+=1+score2
		score2=-1
print(min(cnt1,cnt2))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	string s , t;
	cin >> s >> t;
	int count = 0;
	for(int i = 0 ; i < (int) s.size() ; i++){
		if(s[i] != t[i])
			count++;
		}
	cout<<count;
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3812
#include<iostream>
using namespace std;
int main(){
  int m,a[10],b[10],g,n;
  
  while(cin >> m,m!=0){
    for(int i=1;i<=m;i++){
      cin >> a[i] >> b[i];
    }
    
    int sum,dp[10][1010]={};
    for(int i=1;i<=m;i++){
      sum = 0;
      dp[i-1][0] = 1;
      for(int j=1;j<=1000;j++){
	dp[i][j] = dp[i-1][j];
      }
      for(int j=0;j<b[i];j++){
	sum += a[i];
	for(int k=sum;k<=1000;k++){
	  dp[i][k] += dp[i-1][k-sum];
	}
      }
    }
    
    cin >> g;
    for(int i=0;i<g;i++){
      cin >> n;
      cout << dp[m][n] << endl;
    }
  }
  
  return(0);
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    rep(i,1,10){
        if(n%i==0&&n/i<=9){
            cout << "Yes"<<"\n";
            return 0;
        }
    }
    cout <<"No" <<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<cmath>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}
int digits(int n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int main() {
	int m = 2;
	string s;
	cin >> s;
	int ssize = s.size();
	int tmp = -1;
	vector<int>ans(ssize);
	rep(i, s.size()) {
		if (i < s.size() - 1) {
			if (s[i] == 'R' && s[i + 1] == 'L') {
				int dif = i - tmp;
				//cout << dif << endl;
				if (dif % 2 == 0) {
					ans[i] += dif / 2;
					ans[i + 1] += dif / 2;
				}
				else {
					ans[i] += dif / 2 + 1;
					ans[i + 1] += dif / 2;
				}
				tmp = i;
			}
			else if (s[i] == 'L' && s[i + 1] == 'R') {
				int dif = i - tmp;
				if (dif % 2 == 0) {
					ans[tmp] += dif / 2;
					ans[tmp + 1] += dif / 2;
				}
				else {
					ans[tmp] += dif / 2;
					ans[tmp + 1] += dif / 2 + 1;
				}
				tmp = i;
			}
		}
		else if (i == ssize - 1) {
			int dif = i - tmp;
			if (dif % 2 == 0) {
				ans[tmp] += dif / 2;
				ans[tmp+ 1] += dif / 2;
			}
			else {
				ans[tmp] += dif / 2;
				ans[tmp + 1] += dif / 2 + 1;
			}
			tmp = i;
		}
	}
	rep(i, ssize) {
		cout << ans[i]<<" ";
	}
	cout << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define mod 1000000007

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,N,l,r,ans=0;
  cin>>N;
  vector<ll> a(N),index(N);
  rep(i,N){
    cin>>a[i];
    index[a[i]-1]=i;
  }
  set<ll> se,mse;
  se.insert(-1);se.insert(N);
  mse.insert(1);mse.insert(0-N);
  rep(i,N){
    r=*se.upper_bound(index[i])-index[i];
    se.insert(index[i]);
    /* for(r=1;i+r<N;r++){
      if(a[i]>a[i+r])break;
    }*/
    l=*mse.upper_bound(0-index[i])+index[i];
    mse.insert(0-index[i]);
    /* *for(l=1;index[i]-l>=0;l++){
      if(i+1>a[index[i]-l])break;
    }*/
    ans+=(i+1)*l*r;
    //cout<<i+1<<l<<r<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 22144
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<bool>>knows(N, vector<bool>(N));
		for (int i = 0; i < N; ++i) {

			int M; cin >> M;
			for (int j = 0; j < M; ++j) {
				int p; cin >> p;
				p--;
				knows[i][p] = true;
			}
		}
		int M; cin >> M;
		vector<int>leaks;
		for (int i = 0; i < M; ++i) {
			int k; cin >> k;
			k--;
			leaks.push_back(k);
		}
		int ans = -1;
		for (int i = 0; i < N; ++i) {
			bool ok = true;
			for (int j= 0; j < M; ++j) {
				if (!knows[i][leaks[j]])ok = false;
				
			}
			if (ok) {
				if (ans == -1) {

					ans = i + 1;
				}
				else {
					ans = -1;
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3160
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include <iomanip>
using namespace std;


int main()
{
    double n,sum=0;
    cin>>n;
    vector<double>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    
    for(int i=0;i<n;i++){
        sum+=1/a[i];
    }
    
    cout<<setprecision(12)<<1/sum<<endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int x_max = x;
  REP(i,n){
    int xi;
    cin >> xi;
    x_max = max(x_max,xi);
  }
  int y_min = y;
  REP(i,m){
    int yi;
    cin >> yi;
    y_min = min(y_min,yi);
  }
  if(x_max<y_min){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  return 0;
}


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

int main(){
	int a,ss,sd,kei = 0,res = 0;
	cin >> a >> ss >> sd;
	kei = a + ss + sd;
	while((ss > 0) &&  (sd > 0)){
		ss = ss -1;
		sd = sd -1;
		res = res +2;
	}
	if(sd == 0){
		res = res + ss;
		ss = ss -ss;
	}
	while((sd > 0) && (a >0)){
		sd = sd -1;
		a = a -1;
		res = res + 1;
	}
	if(sd > 0){
		sd = sd -1;
		res = res +1;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int W,H, x,y,r;
  cin >> W >> H >> x >> y >> r;
  bool flg = true;
  if(x + r > W) flg = false;
  if(y + r > H) flg = false;
  if(x + r < 0) flg = false;
  if(y + r < 0) flg = false;
  if(x < 0) flg = false;
  if(y < 0) flg = false;
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int N;
  int a,b,c;
  cin >> N;
  a = N/1000;
  N = N%1000;
  b = N/100;
  N = N%100;
  c = N/10;
  N = N%10;
  if(a == b){
     if(b == c){
    	cout << "Yes" << endl;
     }
 	 else{
    	cout << "No" << endl;
     }
   }
   else if(b == c){
     if(c == N){
     	cout << "Yes" << endl;
     }
     else{
        cout << "No" << endl;
     }
  }
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, s[100], k[100];

int main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> s[i];
		}
		int num = 0;
		bool f = 1;
		while (f){
			int co[100] = {};
			REP(i, n){
				k[i] = s[i];
				co[s[i]]++;
			}
			REP(i, n){
				s[i] = co[s[i]];
			}
			REP(i, n){
				if (s[i] != k[i])break;
				if (i == n - 1){
					f = 0; num--;
				}
			}
			num++;
		}
		cout << num << endl;
		REP(i, n){
			i == n - 1 ? cout << s[i] << endl : cout << s[i] << " ";
		}
	}
}

Measured memory_bytes: 1160
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = scan.nextLong();
    long c = scan.nextLong();
    long d = scan.nextLong();
    double size = (double) a*b/2;
    if ((c*2 == a)&&(d*2 == b)){
      System.out.println(size +" "+ 1);
    }
    else{
      System.out.println(size +" "+ 0);
    }
  }
}


Measured memory_bytes: 38772
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
 	ll n,flag=1;cin>>n;
 	ll h[n];rep(i,0,n) cin>>h[i];
 	
 	rep(i,1,n)
 	{
 	  if(h[i-1]<=h[i])
	   {
	   	if(h[i]-1>=h[i-1])
	   	h[i]-=1;
			} 	
	}
	
	for(ll i=1;i<n;i++)
	{
		if(h[i]<h[i-1])
		{
			cout<<"No";
			return 0;
		}
		}	
	 
	cout<<"Yes";
	
	
	
	
 return 0;
}

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

int H, W;
int A[90][90], B[90][90];
bool dp[90][90][14000];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(i, H) rep(j, W) cin >> B[i][j];
    rep(i, H) rep(j, W) rep(k, 14000) dp[i][j][k] = false;
    dp[0][0][7000+A[0][0]-B[0][0]] = true;
    dp[0][0][7000+B[0][0]-A[0][0]] = true;
    
    rep(i, H) rep(j, W) rep(k, 14000) {
        if (!dp[i][j][k]) continue;
        if (i+1<H) {
            int c = A[i+1][j]-B[i+1][j];
            if (k+c<14000) dp[i+1][j][k+c] |= dp[i][j][k];
            if (k-c>=0) dp[i+1][j][k-c] |= dp[i][j][k];
        }
        if (j+1<W) {
            int c = A[i][j+1]-B[i][j+1];
            if (k+c<14000) dp[i][j+1][k+c] |= dp[i][j][k];
            if (k-c>=0) dp[i][j+1][k-c] |= dp[i][j][k];
        }
    }
    
    int ans = 1000000;
    rep(i, 14000) if (dp[H-1][W-1][i]) ans = min(ans, abs(i-7000));
    cout << ans << endl;
}

Measured memory_bytes: 100608
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn main() {
    let n: u64 = input();
    let mut words: Vec<Vec<char>> = Vec::new();
    words.push(input_char_vec());
    let mut prev: Vec<char> = words[0].to_vec();
    for _ in 1..n {
        let w = input_char_vec();
        if words.contains(&w) || prev[prev.len() - 1] != w[0] {
            // println!("{:?}", w);
            println!("No");
            return;
        }
        prev = w.to_vec();
        words.push(w);
    }
    println!("Yes");
}


Measured memory_bytes: 2140
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// main
func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt64()
	b := nextInt64()
	k := nextInt64()
	c := a - k
	if c >= 0 {
		fmt.Println(c, b)
		return
	}
	d := b + c
	if d >= 0 {
		fmt.Println(0, d)
	} else {
		fmt.Println(0, 0)
	}

}


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

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

    vector<int> d(n);
    for(int i = 0; i < n; i++){
        cin >> d.at(i);
    }

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

    int mochi = -1;
    int cnt = 0;

    for(int i = 0; i < n; i++){
        if(mochi < d.at(i)){
            mochi = d.at(i);
            cnt++;
        }
        else{
            continue;
        }
    }
    printf("%d\n",cnt);
    return 0; 
}

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

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

    lint n = a+b+c;
    using P = pair<lint, lint>;
    vector<P> all(n);
    for(lint i=0; i<n; i++) {
        lint num;
        cin >> num;
        if(i < a) {
            all[i] = P(num, 0);
        } else if(i < a+b) {
            all[i] = P(num, 1);
        } else if(i < a+b+c) {
            all[i] = P(num, 2);
        }
    }

    sort(all.rbegin(), all.rend());
    lint counter = 0;
    const lint goal = x+y;
    lint ans = 0;
    for(lint i=0; i<n; i++) {
        if(all[i].second == 0 && x > 0) {
            x--;
            counter++;
            ans += all[i].first;
        }

        if(all[i].second == 1 && y > 0) {
            y--;
            counter++;
            ans += all[i].first;
        }

        if(all[i].second == 2) {
            counter++;
            ans += all[i].first;
        }

        if(counter == goal) {
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4992
#include <iostream>
#include <set>
#include <stdio.h>
using namespace std;

int main()
{
    set<int> S;
    int query, command, num, L, R;
    
    set<int>::iterator itr, itrL, itrR;
    scanf("%d", &query);

    for (int i = 0; i < query; i++)
    {
        scanf("%d", &command);
        switch (command) {
        case 0:
            scanf("%d", &num);
            S.insert(num);

            printf("%d\n", S.size());
            break;
        case 1:
            scanf("%d", &num);
            itr = S.find(num);
            if (itr == S.end())
            {
                printf("%d\n", 0);
            }
            else
            {
                printf("%d\n", 1);
            }
            break;
        case 2:
            
            scanf("%d", &num);
            S.erase(num);
            break;
        case 3:
            scanf("%d %d", &L, &R);
            itrL = S.lower_bound(L);
            itrR = S.upper_bound(R);
            for (itr = itrL; itr != itrR; itr++)
            {
                printf("%d\n", *itr);
            }
            break;
        default:
            break;
        }
    }


    return 0;
}



Measured memory_bytes: 12496
m = int(input())
d,c = [0]*m , [0]*m
wa = 0
for i in range(m):
    d[i],c[i] = map(int,input().split())
    wa += (d[i]*c[i])
ans = sum(c) - 1
wa -= 1
    
print(ans+wa//9)

Measured memory_bytes: 47448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

template<typename T>
class BIT {
private:
	int n;
	vector<T> d;
public:
	BIT(int n = 0): n(n), d(n + 1) {}
	void add(int i, T x = 1) {
		for (i; i <= n; i += i & -i) {
			d[i] += x;
		}
	}
	T sum(int i) {
		T res = 0;
		for (i; i; i -= i & -i) {
			res += d[i];
		}
		return res;
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, q;
	cin >> n >> q;
	BIT<lint> bit(n);
	rep(i, q) {
		int now;
		cin >> now;
		if (now == 0) {
			int x;
			lint y;
			cin >> x >> y;
			bit.add(x, y);
		}
		else {
			int x, y;
			cin >> x >> y;
			cout << bit.sum(y) - bit.sum(x - 1) << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3528
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
#define sz(x) int(x.size())
// clang-format on

char s[MAX_N + 1], t[MAX_N + 1];

int main(void)
{
  string s, t;
  cin >> s >> t;

  int n = sz(s), m = sz(t);
  vector<vector<int>> is(26);
  REP(i, n) is[s[i] - 'a'].push_back(i);
  REP(i, n) is[s[i] - 'a'].push_back(i + n);

  ll ans = 0;
  int p = 0;
  REP(i, m)
  {
    int c = t[i] - 'a';
    if (sz(is[c]) == 0) {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;

int s[60]={0};
int main()
{
	int n,m,a,b;
	scanf ("%d%d",&n,&m);
	for (int i=0;i<m;i++)
	{
		scanf ("%d%d",&a,&b);
		s[a]+=1;
		s[b]+=1;
		
	}

	for (int i=1;i<=n;i++)
	{
		printf ("%d\n",s[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define end getchar();getchar();return 0
int inf = 1000000000;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt = 1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
void prime_factor(int n) {
	int cnt = 1;
	map<int, int>res;
	int m = n;
	for (int i = 2; i <= n; i++) {
		if (prime(i)) {
			while (m%i == 0) {
				++res[i];
				m /= i;
			}
		}
	}
	cout << n << ":" << endl;
	for (int i = 2; i <= n; i++) {
		if (res[i]) {
			cout << i << " " << res[i] << endl;
		}
	}
	cout << endl;
}
/*Library End!*/
int n, m;
string s, t;
signed main() {
	cin >> n >> m >> s >> t;
	int siz = lcm(n, m);
	for (int i = 0; i < siz; i += lcm(siz / n, siz / m)) {
		if (i % (siz / n) == 0 && i % (siz / m) == 0) {
			if (s[i / (siz / n)] != t[i / (siz / m)]) {
				cout << -1 << endl;
				end;
			}
		}
	}
	cout << siz << endl;
	end;
}


Measured memory_bytes: 512
a,b,m = gets.split.map(&:to_i)

fridge = gets.split.map(&:to_i)
micro = gets.split.map(&:to_i)
minf = fridge.sort[0]
minm = micro.sort[0]
sum = minf + minm
sum2 = 0
sumar = []
for j in 0..m-1 do
  discount = gets.split.map(&:to_i)
  sum2 = fridge[discount[0]-1] + micro[discount[1]-1] - discount[2]
  sumar << sum2
end
minar =sumar.sort[0]
if minar <= sum
  p minar
else
  p sum
end

Measured memory_bytes: 22420
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	-1000 <= a, 1000 <= b;
	if (a<b){
		printf("a < b\n");
	}
	else if (a>b){
		printf("a > b\n");
	}
	else
		printf("a == b\n");
	return 0;

}

Measured memory_bytes: 2616