akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;


int main(){

    string s,t;
    cin >> s>>t;

    int ans=t.size();
    for(int i=0;i<=s.size()-t.size();i++){
        int cnt=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j]!=t[j])cnt++;
        }
        ans=min(ans,cnt);
    }

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

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

int main(int argc, char const *argv[])
{
	int N, K;
	cin >> N >> K;
	if(K == 1) {
		cout << 0 << endl;
	} else {
		cout << (N - K) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define sq(a) (a)*(a)
#define ms(a,v)	memset(a,v,sizeof a)
#define ALL(x)	(x).begin(), (x).end()
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;

char f(char a,char b){
	if (a>b)	swap(a,b);
	if (a=='G' && b=='R')	return 'B';
	if (a=='B' && b=='G')	return 'R';
	if (a=='B' && b=='R')	return 'G';
	return '@';
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;	cin>>n;
  string s;	cin>>s;
  vector<int> r,g,b;
  rep(i,0,n){
	if (s[i]=='R')	r.pb(i);
	if (s[i]=='G')	g.pb(i);
	if (s[i]=='B')	b.pb(i);
  }
  ll res=0;
  rep(i,0,n){
	rep(j,i+1,n-1){
		if (s[i]==s[j])	continue;
		char t=f(s[i],s[j]);
		int x=j-i;
		int num=0;
		if (t=='R'){
			num=int(r.size())-(upper_bound(ALL(r),j)-r.begin());
			if (j+x<n&&s[j+x]=='R')	num--;
		}
		if (t=='G'){
			num=int(g.size())-(upper_bound(ALL(g),j)-g.begin());
			if (j+x<n&&s[j+x]=='G')	num--;
		}
		if (t=='B'){
			num=int(b.size())-(upper_bound(ALL(b),j)-b.begin());
			if (j+x<n&&s[j+x]=='B')	num--;
		}
		res+=num;
	}
  }
  cout<<res<<"\n";
    return 0;
}


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

const int maxn = 1e5;
int n, dp[3][maxn+2];

int main()
{
    cin>>n>>dp[0][1]>>dp[1][1]>>dp[2][1];
    for(int i=2; i<=n; i++)
    {
        cin>>dp[0][i]>>dp[1][i]>>dp[2][i];
        dp[0][i]=dp[0][i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=dp[1][i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=dp[2][i]+max(dp[0][i-1],dp[1][i-1]);
    }
    cout<<max(dp[0][n],max(dp[1][n],dp[2][n]));
    return 0;
}


Measured memory_bytes: 1408
n,k = map(int, input().split())
s = input()
slis = [s[i] for i in range(n)]

ans = ""

if slis[k-1] == "A":
    slis[k-1] = "a"
elif slis[k-1] == "B":
    slis[k-1] = "b"
elif slis[k-1] == "C":
    slis[k-1] = "c"

for i in range(n):
    ans += slis[i]

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<limits.h>
using namespace std;

#define INF (2147483647)

int n,q;
int com;
int pos,num;
int b,e;

int tree[555555];

void init();
int find(int x, int y, int now, int left, int right);
void update(int i, int x);

int main(){

  scanf(" %d %d",&n,&q);

  init();

  for(int i=0;i<q;i++){
    scanf(" %d",&com);

    if(com){
      scanf(" %d %d",&b,&e);
      printf("%d\n",find(b, e, 0, 0, n-1));
    } else {
      scanf(" %d %d",&pos,&num);
      update(pos, num);
    }
  }
}

void init(){
  int m = n;
  n = 1;

  while(m > n)n = (n << 1);

  fill(tree, tree + n * 2, INF);
  return;
}

void update(int i, int x){
  i = i + n - 1;
  tree[i] = x;

  while(i > 0){
    i = (i - 1) / 2;
    tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
  }
}

int find(int x, int y, int now, int left, int right){
  if(right < x || y < left)return INF;

  if(x <= left && right <= y)return tree[now];

  int find_left = find(x, y, now * 2 + 1, left, (left + right) / 2);
  int find_right = find(x, y, now * 2 + 2, (left + right) / 2 + 1, right);

  return min(find_left, find_right);
}

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

using namespace std;
int main() {
    int st = 0;
    int flag = 0;

    string s;
    cin >> s;
    while (1) {
        if (s.size() == st) {
            flag = 1;
            break;
        }
        else if ((s.size()- st) < 5) {
            break;
        }
        else if (s.substr(st, 5) == "dream") {
            //dreamer と判定
            if (((s.substr((st + 5), 2) == "er") && (s.substr((st + 5), 5)) != "erase")) {
                st += 7;
            }
            //dream　と判定
            else if((s.substr((st+5),2)!="er")||(s.substr((st+5),5)=="erase") ){
                st += 5;
            }
        }
        else if (s.substr(st, 5) == "erase") {
            //eraser と判定
            if (s.substr((st + 5), 1) == "r") {
                st += 6;
            }
            //erase と判定
            else if(s.substr(st+5,1)!="r") {
                st += 5;
            }
        }
        else {
            break;
        }
    }

    if (flag == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3732
#include<stdio.h>

int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    if (a < b){
        printf("a < b\n");
    }
   else if (a > b){
        printf("a > b\n");
    }
    else if (a = b){
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int D;
  cin >> D;
  int c[26];
  int las[26];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    las[i] = 0;
  }
  int s[D][26];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  int choose[D];
  for (int i = 0; i < D; i++) cin >> choose[i];
  int ans = 0;
  for (int i = 1; i <= D; i++) {
    int score = 0;
    score += s[i-1][choose[i-1] - 1];
    for (int j = 0; j < 26; j++) {
      if (choose[i-1] - 1 != j) {
        score -= c[j] * (i - las[j]);
      }
    }
    las[choose[i-1] - 1] = i;
    ans += score;
  }

  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int d,q;
    cin >> d >> q;
    ans -= s[d-1][choose[d-1]-1];
    ans += s[d-1][q-1];
    int p = choose[d-1];
    int nextp = D+1;
    int prevp = 0;
    int nextq = D+1;
    int prevq = 0;
    for (int i = d; i < D; i++) {
      if (choose[i] == p) {
        nextp = i+1;
        break;
      }
    }
    for (int i = d; i < D; i++) {
      if (choose[i] == q) {
        nextq = i+1;
        break;
      }
    }
    for (int i = d-2; i >= 0; i--) {
      if (choose[i] == p) {
        prevp = i+1;
        break;
      }
    }
    for (int i = d-2; i >= 0; i--) {
      if (choose[i] == q) {
        prevq = i+1;
        break;
      }
    }
    ans -= (d - prevp) * (nextp - d) * (c[p-1]);
    ans += (d - prevq) * (nextq - d) * (c[q-1]);
    cout << ans << endl;
    choose[d-1] = q;
  }
  return 0;
}

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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int replace = 1000;
  int lenT = t.size();
  int lenS = s.size();
  for(int j=0; j<lenS-lenT+1; j++){
    int count=0;
    for(int i=0; i<t.size(); i++){
      if(t.at(i)!=s.at(j+i)) count++;
    }
    replace = min(count,replace);
  }
  cout << replace << endl;
  return 0;
}

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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

signed main() {
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);

    rep (i, N) {
        cin >> H[i];
    }

    sort(H.begin(), H.end());
    if (K >= N) {
        cout << 0 << endl;
        return 0;
    }
    ll a = 0;
    rep (i, (N-K)) {
        a+= H[i];
    }

    cout << a << endl;

}



Measured memory_bytes: 4732
#include <iostream>
using namespace std;
int a[1005][1005],b[1000],ans[2][1000][1000];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			cin >> c;
			if(c=='#')
				a[i][j]=1,b[i]=1;
		}
	}
	int now=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			ans[now][i][j]=1;
		now^=1;
		for(int j=1;j<=m;j++)
			ans[now][i][j]=a[i][j];
	}
	for(int i=1;i<=n;i++)
		ans[1][i][1]=ans[0][i][m]=1,ans[1][i][m]=ans[0][i][1]=0;
	for(int i=0;i<=1;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=m;k++)
			{
				if(ans[i][j][k])
					cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		if(!i)
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 10880
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#pragma warning(disable:4996)

using namespace std;


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

	string s;
	cin >> s;

	if (s.find("7") == string::npos) cout << "No\n";
	else cout << "Yes\n";

	return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import math
import copy


# 引数が一つだけのやつ
# n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

H = target_1[0]
W = target_1[1]
K = target_1[2]

# 引数が複数あるやつ（そうじゃないの）
# target = [int(x) for x in input().split()]

# number = int(input())
# 複数行を受け取って処理するやつ
target = [list(input()) for i in range(H)]

# 関数
def count_sharp(target):
    return sum([x.count("#") for x in target])


def bin_code(value, keta):
    return list(("{:0" + str(keta) + "b}").format(value))


# 初期
result = 0

for i in range(2 ** H):
    for j in range(2 ** W):
        bin_i = bin_code(i, H)
        bin_j = bin_code(j, W)
        tmp = copy.deepcopy(target)
        # 色塗り
        for idx_i, ik in enumerate(bin_i):
            if ik == "1":
                tmp[idx_i] = [0] * W
            for idx_j, jk in enumerate(bin_j):
                if jk == "1":
                    tmp[idx_i][idx_j] = 0

        # カウント
        if count_sharp(tmp) == K:
            result += 1
            # print(tmp)


# 出力
print(result)


Measured memory_bytes: 9388
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for _ in range(n)]
li=[0,1,2,3]
it = list(itertools.product(li,repeat=n))
it = [i for i in it if 0 in i and 1 in i and 2 in i]
INF=100000007
ans=INF
for i in it:
    tmp=-30
    l_tmp=[0,0,0,0]
    for j in range(n):
        l_tmp[i[j]]+=l[j]
        if i[j]!=3:tmp+=10
    tmp=tmp+abs(l_tmp[0]-a)+abs(l_tmp[1]-b)+abs(l_tmp[2]-c)
    if tmp<ans:ans=tmp
print(ans)

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using ll = long long;
#define szof(x) (int)(x).size()
using namespace std;
inline ll sign(ll x) {
    if (x >= 0)
        return 1;
    return -1;
}
ll k, x, y;
vector<pair<ll, ll>> steps;

void up() {
    ll L = abs(x) + abs(y);
    ll a = (L / k) * k;
    ll d1 = (L - a) / 2;
    ll d2 = k - d1;
    if (abs(x) >= abs(y)) {
        x -= sign(x) * d1;
        y += sign(y) * d2;
    } else {
        x += sign(x) * d2;
        y -= sign(y) * d1;
    }
    steps.push_back({ x, y });
}

void down() {
    ll L = abs(x) + abs(y);
    ll a = (L / k) * k;
    ll d1 = (a - L + k) / 2;
    ll d2 = k - d1;
    if (abs(x) >= abs(y)) {
        x -= sign(x) * d2;
        y += sign(y) * d1;
    } else {
        y -= sign(y) * d2;
        x += sign(x) * d1;
    }
    steps.push_back({ x, y });
}

int main() {
    scanf("%lld%lld%lld", &k, &x, &y);

    steps.push_back({ x, y });
    if ((abs(x) + abs(y)) % k != 0) {
        if ((x ^ y) & ~k & 1LL) {
            printf("-1\n");
            return 0;
        }
        if (abs(x) + abs(y) < k) {
            if ((k & 1LL) && ((x ^ y) & 1LL)) {
                ll dx = abs(x);
                ll dy = k - dx;
                x -= sign(x) * dx;
                y += sign(y) * dy;
                steps.push_back({ x, y });
            }
        }
        ll L = abs(x) + abs(y);
        ll a = (L / k) * k;
        if ((~(a ^ L ^ k) & 1LL) && L >= k) {
            down();
        } else {
            up();
        }
    }

    while (x != 0 || y != 0) {
        ll dx = min(k, abs(x));
        ll dy = min(k - dx, abs(y));
        x -= sign(x) * dx;
        y -= sign(y) * dy;
        if (x != 0 || y != 0) steps.push_back({ x, y });
    }
    reverse(steps.begin(), steps.end());
    printf("%d\n", szof(steps));
    for (ll i = 0; i < szof(steps); ++i) {
        printf("%lld %lld\n", steps[i].first, steps[i].second);
    }
}

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

int N, K, multiply;

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

  cin >> N >> K;

  multiply = K;
  for (int i = 0; i < N - 1; i++) {
    multiply *= K - 1;
  }
  cout << multiply << endl;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = l[0], W = l[1];

            for (var i = 0; i < H; i++)
            {
                var tmp = Console.ReadLine();
                Console.WriteLine(tmp);
                Console.WriteLine(tmp);
            }
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long s=0;
    for(i=1;i<=n;i++)
    {
        if((i%3)&&(i%5))
            s+=i;
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;

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

        int[] a = new int[3];
        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[2] - a[0]);
    }
}


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

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

  double x;
  string u;
  double c = 0;

  for(int i=0;i<n;++i)
  {
    cin >> x >> u;
    if (u == "JPY") c += x;
    else  c += x*380000;
  }

  cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(t) (t).begin(),(t).end()
typedef long long ll;

int main() {
	int S=0;
	string Ans;
	string N; cin >> N;
	REP(i,N.size()){
		S = S + ((int)(N.at(i))-'0');
	}
	Ans= (S%9==0)? "Yes":"No" ;
	cout << Ans << '\n';
	return 0;
}


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


int main() {
    int N; cin >> N;
    vector<string> V(N);
    for(int i=0;i<N;i++){
        cin >> V.at(i);
    }
    sort(V.begin(),V.end());
    vector<string> ans={};
    
    int cnt=0;
    int cntM=0;
    string now=V.at(0);
    for(int i=0;i<N;i++){
        if(now==V.at(i)){
            cnt++;
            if(cnt==cntM){
                ans.push_back(now);
            }
            if(cnt>cntM){
                ans={now};
                cntM=cnt;
            }
        }
        else{
            cnt=1;
            now=V.at(i);
            if(cntM==1){
                ans.push_back(now);
            }
        }
    }
    for(string i:ans){
        cout << i << endl;
    }
}

Measured memory_bytes: 15988
#include <iostream>

int main() {
	int a[4], b[4], hit, blow;
	while (std::cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		hit = blow = 0;
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (a[i] == b[j]) {
					if (i == j) {
						++hit;
					} else {
						++blow;
					}
				}
			}
		}
		std::cout << hit << ' ' << blow << '\n';
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 100000
int n,p,cntL,cntR,pos;
char s[MAXN+5];
int ans[MAXN+5];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	s[n+1]='R';
	for(int i=1;i<=n+1;i++)
	if(s[i]=='R'){
		if(!p){
			p=1;
			ans[pos-1]+=(cntL+1)/2+cntR/2;
			ans[pos]+=(cntR+1)/2+cntL/2;
			cntL=cntR=0;
		}
		cntL++;
	}else{
		if(p)pos=i;
		p=0;
		cntR++;
	}
	for(int i=1;i<=n;i++)
	printf("%d ",ans[i]);
}

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

const int N = 3e3 + 5;
const int INF = 0x3f3f3f3f;

int dp[N][N];
string a, b, ans;

int dpf(int i, int j) {
  if(!i or !j) return dp[i][j] = 0;
  if(dp[i][j] != -INF) return dp[i][j];
  if(a[i-1] == b[j-1]) return dp[i][j] = 1 + dpf(i-1, j-1);
  return dp[i][j] = max(dpf(i-1, j), dpf(i, j-1));
}

void rec(int i, int j) {
  if(!i or !j) return;
  if(a[i-1] == b[j-1]) ans += a[i-1], rec(i-1, j-1);
  else {
    if(dp[i-1][j] == dp[i][j]) rec(i-1, j);
    else if(dp[i][j-1] == dp[i][j]) rec(i, j-1);
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> a;
  cin >> b;
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++) dp[i][j] = -INF;
  dpf(a.size(), b.size());
  rec(a.size(), b.size());
  reverse(ans.begin(), ans.end());
  cout << ans << "\n";
}


Measured memory_bytes: 35968
# A, B = list(map(int, input().split()))
# S = list(map(input().split())

"""
import itertools
s = []
for i in range(N):
    s.append(int(input()))


for i in range(n):
    x,y = [int(j) for j in input().split()]
    dataX.append(x)
    dataY.append(y)

二次元配列
for i in range(n):
    d.append([int(j) for j in input().split()])

integer_set = [list(map(int, input().split())) for _ in range(q)]


c = [[j for j in input()] for i in range(h)]

sp.sort(key=lambda x:(x[1], -x[2]))

コレクションのvalue値を取る時
for v in a.values():
        if v%2!=0:
            even = False

二次元配列
road = [[0]*n]*n　こうやって書くと全部更新されるから
road = [[0]*n for i in range(n)]って書くといい

一番回数の多いもの取得
l = collections.Counter(s)
a = l.most_common()[0][0]

forの逆
for i in reversed(range(0, n)):

順列重複あり
ans = list(itertools.product(l, repeat=n))

l_sorted = sorted(l, key=lambda x: x[1], reverse=True)

a_count = collections.Counter(a)
a_list = list(a_count.items())

"""
from fractions import gcd
from functools import reduce
# from collections import deque
# from math import factorial
# import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
# x = int(input())
n, m, q = list(map(int, input().split()))
# a, b = list(map(int, input().split()))

a = []
b = []
c = []
d = []
abcd = []
for i in range(q):
    x, y, z, k = [int(j) for j in input().split()]
    abcd.append([x, y, z, k])

s = [0]*n
ans = 0


def dfs(s, num, i):
    if i == n:
        global ans
        total = 0
        for j in range(q):
            if s[abcd[j][1]-1]-s[abcd[j][0]-1] == abcd[j][2]:
                total += abcd[j][3]
        ans = max(ans, total)
        return
    else:
        for j in range(num, m+1):
            s[i] = j
            dfs(s, j, i+1)


dfs(s, 1, 0)
print(ans)


Measured memory_bytes: 10368
#!/usr/bin/env ruby

# MOD = (10 ** 9) + 7
str = gets.chomp

hash = {}
hash[str[0]] = 1
hash[str[1]] = (hash[str[1]] || 0) + 1
hash[str[2]] = (hash[str[2]] || 0) + 1
hash[str[3]] = (hash[str[3]] || 0) + 1

flag = true
hash.keys.each do |key|
  flag = false if hash[key] !=2
end

puts flag ? 'Yes' : 'No'

Measured memory_bytes: 1788
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef unsigned  uint;
typedef unsigned long long int ull;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=1000000007;
const uint mod=998244353;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
	uint v;
	mint(ll vv=0){s(vv%mod+mod);}
	mint& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	mint operator-()const{return mint()-*this;}
	mint& operator+=(const mint&rhs){return s(v+rhs.v);}
	mint&operator-=(const mint&rhs){return s(v+mod-rhs.v);}
	mint&operator*=(const mint&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	mint&operator/=(const mint&rhs){return *this*=rhs.inv();}
	mint operator+(const mint&rhs)const{return mint(*this)+=rhs;}
	mint operator-(const mint&rhs)const{return mint(*this)-=rhs;}
	mint operator*(const mint&rhs)const{return mint(*this)*=rhs;}
	mint operator/(const mint&rhs)const{return mint(*this)/=rhs;}
	mint pow(int n)const{
		mint res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	mint inv()const{return pow(mod-2);}
	/*mint inv()const{
		int x,y;
		int g=extgcd(v,mod,x,y);
		assert(g==1);
		if(x<0)x+=mod;
		return mint(x);
	}*/
	friend ostream& operator<<(ostream&os,const mint&m){
		return os<<m.v;
	}
	bool operator<(const mint&r)const{return v<r.v;}
	bool operator==(const mint&r)const{return v==r.v;}
};
const ll MAX = 10000001;//設定して

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
mint modpow(mint a, ll n) {
    mint res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a ;
        n >>= 1;
    }
    return res;
}
// 二項係数計算
mint 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];
}

int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
 COMinit();
  mint ans=0;
 ans=modpow(3,n);
 mint now=2;
 for(int i=0;i<n/2;i++){
     ans-=(COM(n,i)*now);
     now*=2;
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 117504
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, ans, t, l;
  string s, mcxi = "mcxi";
  cin >> n;
  for (int i = 0; i < n; ++i) {
    ans = 0;
    for (int k = 0; k < 2; ++k) {
      cin >> s;
      l = s.size();
      t = 1;
      for (int j = 0; j < l; ++j) {
	if (s[j] == 'm') {
	  t *= 1000;
	  ans += t;
	  t = 1;
	} else if (s[j] == 'c') {
	  t *= 100;
	  ans += t;
	  t = 1;	
	} else if (s[j] == 'x') {
	  t *= 10;
	  ans += t;
	  t = 1;	
	} else if (s[j] == 'i') {
	  ans += t;
	  t = 1;
	} else {
	  t *= s[j] - '0';
	}
      }
    }
    s = "";
    t = 10000;
    for (int i = 0; i < 4; ++i) {
      t /= 10;
      if (ans/t == 1) s += mcxi[i];
      else if (ans/t) {
	s += ans/t + '0';
	s += mcxi[i];
      }
      ans %= t;
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
int main(){
    double a,b, c, d, e, f, x,y;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        y=(a*f-c*d)/(a*e-d*b);
        x=(c-b*y)/a;
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N = 1e3+2;
string a[N];
ll vis[N][N], dist[N][N];
const ll fx[]={-2, -2, -1, -1,0,  1,  1,  2,  2};  // Knights Move
const ll fy[]={-1,  1, -2,  2, 0,-2,  2, -1,  1}; // Knights Move
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
void bfs(ll x, ll y, ll n, ll m)
{
	memset(vis, 0, sizeof(vis));
	set<pair<ll,pll> > q;
	q.insert({0,{x, y}});
	vis[x][y]=1;
	dist[x][y]=0;
	while(!q.empty())
	{
		pair<ll,pll>top=*q.begin();
		ll x=top.second.first;
		ll y=top.second.second;
		ll wt=top.first;
		q.erase(q.begin());
		for(ll dir=0;dir<4;dir++)
		{
			ll nx=x+dx[dir];
			ll ny=y+dy[dir];
			if(nx<0 || ny<0 || nx>=n || ny>=m || a[nx][ny]=='#')
					continue;
			if(!vis[nx][ny])
			{
				dist[nx][ny]=wt;
				vis[nx][ny]=1;
				q.insert({wt,{nx, ny}});
			}
			else
			{
				if(dist[nx][ny]>dist[x][y])
				{
					pair<ll,pll>old={dist[nx][ny],{nx,ny}};
					if(q.find(old)!=q.end())
						q.erase(q.find(old));
					dist[nx][ny]=dist[x][y];
					q.insert({wt,{nx,ny}});
				}
			}
		}
		for(ll i=0;i<9;i++)
		{
			for(ll j=0;j<9;j++)
			{
				ll nx=x+fx[i];
				ll ny=y+fy[j];
				if(nx<0 || ny<0 || nx>=n || ny>=m || a[nx][ny]=='#')
					continue;
				if(!vis[nx][ny])
				{
					dist[nx][ny]=wt+1;
					vis[nx][ny]=1;
					q.insert({wt+1,{nx, ny}});
				}
				else
				{
					if(dist[nx][ny]>dist[x][y]+1)
					{
						pair<ll,pll>old={dist[nx][ny],{nx,ny}};
						if(q.find(old)!=q.end())
							q.erase(q.find(old));
						dist[nx][ny]=wt+1;
						q.insert({wt+1,{nx,ny}});
					}
				}

			}
		}
	}
}

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll h,w;
 	cin>>h>>w;
 	pll src,tar;
 	cin>>src.first>>src.second;
 	cin>>tar.first>>tar.second;
 	for(ll i=0;i<h;i++)
 	{
 		cin>>a[i];
 	}
 	bfs(src.first-1,src.second-1,h,w);
 	if(vis[tar.first-1][tar.second-1])
 	cout<<dist[tar.first-1][tar.second-1]<<endl;
 	else
 		cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 20592
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s[100010],ab = "AB",bc = "BC",ac = "AC";
vector<char> v;
int main(){
    int i,n,a,b,c;
    cin >> n >> a >> b >> c;
    for(i=0;i<n;i++){
        cin >> s[i];
    }
    s[n] = ab;
    if(a + b + c!=2){
        for(i=0;i<n;i++){
            if(s[i]==ab){
                if(a<b){
                    v.push_back('A');
                    a++; b--;
                }else{
                    v.push_back('B');
                    a--; b++;
                }
            }
            if(s[i]==bc){
                if(b<c){
                    v.push_back('B');
                    b++; c--;
                }else{
                    v.push_back('C');
                    b--; c++;
                }
            }
            if(s[i]==ac){
                if(a<c){
                    v.push_back('A');
                    a++; c--;
                }else{
                    v.push_back('C');
                    a--; c++;
                }
            }
            if(a<0 || b<0 || c<0){
                cout << "No" << endl;
                return 0;
            }
        }
    }else{
        for(i=0;i<n;i++){
            if(s[i]==ab){
                if(a<b){
                    v.push_back('A');
                    a++; b--;
                }else if(a>b){
                    v.push_back('B');
                    a--; b++;
                }else{
                    if(s[i + 1]==ac){
                        v.push_back('A');
                        a++; b--;
                    }else{
                        v.push_back('B');
                        b++; a--;
                    }
                }
            }
            if(s[i]==bc){
                if(b<c){
                    v.push_back('B');
                    b++; c--;
                }else if(b>c){
                    v.push_back('C');
                    b--; c++;
                }else{
                    if(s[i + 1]==ab){
                        v.push_back('B');
                        b++; c--;
                    }else{
                        v.push_back('C');
                        b--; c++;
                    }
                }
            }
            if(s[i]==ac){
                if(a<c){
                    v.push_back('A');
                    a++; c--;
                }else if(a>c){
                    v.push_back('C');
                    a--; c++;
                }else{
                    if(s[i + 1]==ab){
                        v.push_back('A');
                        a++; c--;
                    }else{
                        v.push_back('C');
                        a--; c++;
                    }
                }
            }
            if(a<0 || b<0 || c<0){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    for(i=0;i<n;i++){
        cout << v[i] << endl;
    }
}

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 5e3 + 3;

vector< int > V[N]; 
int M[N][N],AT[N],dpT[N],t,dp[N],A[N];

int g(int i, int s){
    if(s < 0) return mod;
    if(i == t+1) return 0;
    int &r = M[i][s];
    if(r != -1) return r;
    return r = min( g(i+1,s-AT[i]) + dpT[i] , g(i+1,s-dpT[i]) + AT[i] );    
}

void f(int x){
    
    for(int i=0; i<V[x].size(); i++)
        f(V[x][i]);

    t = 0;
    for(int i=0; i<V[x].size(); i++){
        dpT[++t] = dp[ V[x][i] ];
        AT[t] = A[ V[x][i] ];
    }

    for(int j, i=0; i<=t; i++)
        for(j=0; j<=A[x]; j++)
            M[i][j] = -1;
            
    dp[x] = g(1,A[x]);
}

int n,i,x;
signed main(){
    cin >> n;
    for(i=2;i<=n;i++){
        cin >> x;
        V[x].pb(i);
    }
    for(i=1;i<=n;i++)
        cin >> A[i];
    
    f(1);
    puts(dp[1] < mod ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        count++;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N, X = s_inpl()
x = inpl()

x_diff = [ abs(X - xi) for xi in x]

# a, bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

# リストnumbers最大公約数
def gcdlist(numbers):
    a = numbers[0]
    for i in range(len(numbers)):
        a = gcd(a, numbers[i])
    return a

print(gcdlist(x_diff))

Measured memory_bytes: 23120
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))

my_dict = dict()

current_sum = sum(a)

for item in a:
    if item in my_dict:
        my_dict[item] += 1
    else:
        my_dict[item] = 1

for item in bc:
    b, c = item
    if c in my_dict:
        if b in my_dict:
            cnt = my_dict.pop(b)
            my_dict[c] += cnt
            current_sum += (c - b) * cnt
    else:
        if b in my_dict:
            my_dict[c] = my_dict.pop(b)
            current_sum += (c - b) * my_dict[c]
    print(current_sum)


Measured memory_bytes: 32416
n=int(input())
array=[]
for i in range (1,n+1):
    j=i
    count=0
    while(j%2==0):
        j=j/2
        count+=1
    array.append(count)
max=array[0]
for i in  range(n):
    if array[i]>=max:
        max=array[i]
        j=i
print(j+1)                


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;

struct Edge{
    int to,a,b;
    Edge(ll to,ll a,ll b): to(to),a(a),b(b) {}
};

struct Data{
    int v,s;
    ll x; //時間
    Data(int v,int s,ll x):v(v),s(s),x(x) {}
    bool operator<(const Data& a) const {
        return x > a.x;
    }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S+5];


int main(){
    int n,m,s;
    cin >> n >> m >> s;
    for(int i=0;i<m;i++){
        int v,u,a,b;
        cin >> v >> u >> a >> b;
        v--; u--;
        g[v].emplace_back(u,a,b);
        g[u].emplace_back(v,a,b);
    }
    vector<int> c(n),d(n);
    rep(i,n) cin >> c[i] >> d[i];
    rep(i,n)rep(j,MAX_S+5) dp[i][j] = LINF;
    s = min(MAX_S,s);

    priority_queue<Data> q;

    auto push = [&](int v,int s,ll x){
        if(s<0) return;
        if(dp[v][s] <= x) return;
        dp[v][s] = x;
        q.emplace(v,s,x);
    };
    push(0,s,0);
    while(!q.empty()){
        Data hoge = q.top(); q.pop();
        int v = hoge.v, s = hoge.s;
        ll x = hoge.x;
        if(dp[v][s] != x) continue;
        {
            int ns = min(s+c[v],MAX_S);
            push(v,ns,x+d[v]);
        }
        for(Edge e : g[v]){
            push(e.to, s-e.a, x+e.b);
        }
    }

    for(int i=1;i<n;i++){
        ll ans = LINF;
        rep(j,MAX_S+5){
            ans = min(ans,dp[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6216
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a / b << ' ' << a % b << ' ';
	printf("%f\n", static_cast<double>(a) / static_cast<double>(b) );
	return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int X, ans=0;
	cin>>X;
	ans=(X/500)*1000;
	X%=500;
	cout<<ans+(X/5)*5<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <unistd.h>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int n;cin>>n;
    vector<int> v1,v2;
    set<pair<int,int>> s;
    for(int i=0;i<n;i++)
    {
        int x,y;cin>>x>>y;
        if(s.find({x,y})==s.end())
        {
            s.insert({x,y});
            v1.push_back(x+y);
            v2.push_back(x-y);
        }
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int a1=*v1.rbegin()-v1[0];
    int a2=*v2.rbegin()-v2[0];
    cout<<max(a1,a2);
}

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

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 18804
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> S;
int H,W;
void up(int x,int y){
	if (x==0){
		return;
	}
	if (S[x-1][y]=='.' || S[x-1][y]=='*'){
		return;
	}
	if (S[x-1][y]=='#'){
		S[x-1][y]='*';
	}
}
void down(int x,int y){
	if (x==H-1){
		return;
	}
	if (S[x+1][y]=='.' || S[x+1][y]=='*'){
		return;
	}
	if (S[x+1][y]=='#'){
		S[x+1][y]='*';
	}
}
void left(int x,int y){
	if (y==0){
		return;
	}
	if (S[x][y-1]=='.' || S[x][y-1]=='*'){
		return;
	}
	if (S[x][y-1]=='#'){
		S[x][y-1]='*';
	}
}
void right(int x,int y){
	if (y==W-1){
		return;
	}
	if (S[x][y+1]=='.' || S[x][y+1]=='*'){
		return;
	}
	if (S[x][y+1]=='#'){
		S[x][y+1]='*';
	}
}
bool Check()
{
	for (int i=0;i<H;i++){
		for (int j=0;j<W;j++){
			if (S[i][j]=='#'){
				return false;
			}
		}
	}
	return true;
}

void deal(int x,int y)
{
	if (S[x][y]=='.'){
		return;
	}
	up(x,y);
	down(x,y);
	left(x,y);
	right(x,y);
}
int main(int argc, char* argv[])
{	

	cin>>H>>W;
	int i,j;
	string s;
	for (i=0;i<H;i++){
		cin>>s;
		S.push_back(s);
	}
	for (i=0;i<H;i++){
		for (j=0;j<W;j++){
			deal(i,j);
		}
	}
	bool bOK=Check();
	if (bOK){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.TreeSet;

public class Main {

	int N, K, size;
	int[] a,segment;
	long[] b;

	public void init(int _size) {
		size = 1;

		while (size < _size)size <<= 1;

		segment = new int[2 * size];
		for (int i = 0; i < 2 * size - 1; i++) {
			segment[i] = 0;
		}
	}

	public void update(int i, int a) {
		i += size - 1;
		segment[i] += a;

		while (i > 0) {
			i = (i - 1) >> 1;
			segment[i] += a;
		}
	}

	public int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return 0;

		if (a <= l && r <= b)return segment[k];

		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

			return vl + vr;
		}
	}

	public void solve() {
		N = nextInt();
		K = nextInt();

		a = new int[N];
		for(int i = 0;i < N;i++){
			a[i] = nextInt() - K;
		}

		b = new long[N+1];
		b[0] = a[0];
		for(int i = 0;i < N;i++){
			b[i+1] += b[i] + a[i];
		}

		TreeSet<Long> set = new TreeSet<>();
		for(int i = 0;i <= N;i++){
			set.add(b[i]);
		}

		long[] c = new long[N+1];
		int p = 0;
		for(long i : set){
			c[p++] = i;
		}

		c = Arrays.copyOf(c, p);

		init(N+1);
		long ans = 0;
		for (int i = 0; i <= N; i++) {
			int x = Arrays.binarySearch(c, b[i]);
			ans += query(0, x+1, 0, 0, size);
			update(x, 1);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 47148
#include <stdio.h>
#define ll long long

int main(){
	ll a,b,c;
	scanf("%lld%lld%lld",&c,&a,&b);
	if(c==1)printf("%d",a==b);
	else if(a>b)puts("0");
	else printf("%lld",(b-a)*(c-2)+1);
}


Measured memory_bytes: 128
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		int n = int.Parse(Console.ReadLine());
		var h = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int highest = 0;
		int counter = 0;
		
		for(int i=0;i!=n-1;i++){
			
			if(h[i]>=h[i+1]){
				counter++;
			}else{
				if(counter>highest){
					highest = counter;
				}
				counter = 0;
			}
			
		}
		
		if(counter>highest){highest = counter;}
		Console.WriteLine(highest);
		
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    ll x;
    cin >> x;
    int i = 0;
    ll sum = 100;
    while (sum < x)
    {
        i++;
        sum = sum + sum * 0.01;
    }

    OP(i);
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int a = 1, b = 2, c = 0, n = sc.nextInt();
		while (2*a<=n) {
			a*=b; c++;
		}
		System.out.println((int)Math.pow(2,c));
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

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

  ll h[100010];
  for (int i = 0; i < n; i++) { cin >> h[i]; }

  ll dp[100010];
  for (int i = 0; i <= n; i++) dp[i] = INFL;

  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }

  cout << dp[n - 1] << endl;
}


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

int main()
{
	int N, X;
	cin >> N >> X;
	int count = 1;
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		X -= a;
		if (X >= 0)
			count++;
	}
	cout << count << '\n';
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char s1[110],s2[110];

int main()
{
    scanf("%s",s1);
    scanf("%s",s2);
    int len=strlen(s1);
    if(len!=strlen(s2))
    {
        printf("No\n");
        return 0;
    }
    for(int i=0; i<len; i++)
    {
        int j;
        for(j=0; j<len; j++)
            if(s1[j]!=s2[(i+j)%len]) break;
        if(j==len)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

//入力
int n;

int main() {

	cin >> n;

	cout << 800 * n - n / 15 *200 << endl;

	return 0;
}


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

from heapq import heappush, heappop
def dijkstra(g,start):
    dist = [1e18]*(len(g)) #startからの最短距離
    dist[start] = 0
    q = [(0,start)] #(そこまでの距離、点)
    pending = len(g)-1 #未確定の点の個数
    while q and pending:
        c,v = heappop(q)
        if dist[v] < c: continue
        pending -= 1
        for to, cost in g[v]:
            if dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(q, (dist[to], to))
    return dist

v,e,r = [int(i) for i in input().split()]

g = [[] for _ in range(v)]
for _ in range(e):
    a,b,c = [int(i) for i in input().split()]
    g[a].append((b, c))

for i in dijkstra(g,r):
    if i == 1e18: print("INF")
    else: print(i)



Measured memory_bytes: 89304
c = [list(map(int, input().split())) for _ in range(3)]
adif1 = c[0][1] - c[0][0]
adif2 = c[0][2] - c[0][1]
bdif1 = c[1][0] - c[0][0]
bdif2 = c[2][0] - c[1][0]
for row in range(1,3):
    if c[row][1] - c[row][0] != adif1 or c[row][2] - c[row][1] != adif2:
        print('No')
        exit()
    if c[1][row] - c[0][row] != bdif1 or c[2][row] - c[1][row] != bdif2:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, m = LI()
    if n == m:
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()

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

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

    vector <int> l(m);
    vector <int> r(m);

    for (int i=0;i<m;i++){
        cin >> l.at(i) >> r.at(i);
    }

    int up = r.at(0);
    int down = l.at(0);
    for (int i=1;i<m;i++) {
        up = min(up,r.at(i));
        down = max(down,l.at(i));
    }
    if (up>=down) {
        cout << up - down + 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N=1e5+1;
const int INF=1e9+7;

int32_t main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
 int n,k; cin>>n>>k; int H[n];
 for(int i=0;i<n;i++){cin>>H[i];}
 int dp[n];
 dp[0]=0;

 for(int i=1;i<n;i++)
 {
     dp[i]=INF;
     for(int x=i-1;(x>=0 && x>=i-k);x--)
     dp[i]=min(dp[i],(dp[x]+abs(H[i]-H[x])));
 }
 cout<<dp[n-1];
}

Measured memory_bytes: 5188
def counting_sort(array)
	max = array.max
	counter = Array.new(max + 1, 0) # max番目まで必要

	# array内の各値の出現回数を記録
	array.each_index { |i| counter[array[i]] += 1 }
	# array[i]以下の要素数を各値ごとに計算
	1.upto(max) { |i| counter[i] = counter[i] + counter[i - 1] }

	result = []
	array.reverse_each do |value|
		index = (counter[value] -= 1)
		result[index] = value
	end
	result
end

n = STDIN.gets.to_i
array = STDIN.gets.split[0...n].map(&:to_i)
puts counting_sort(array).join(" ")

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

int main()
{
	long long a,b;
	cin>>a>>b;
	if(a<b)
	swap(a,b);
	long long g=__gcd(a,b),ans=0,fu=g;
	for(int i=2; i<=sqrt(g); i++)
	{
		if(g%i)
			continue;
		ans++;
		while(g%i==0)
			g/=i;
	}
	if(g>1) 
		ans++;
	cout<<ans+1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;
  cin>>N;
  int j=0,k=1;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a!=k)
      j++;
    else
      k++;
  }
  if(N==j)
    cout<<-1<<endl;
  else
    cout<<j<<endl;
}

Measured memory_bytes: 3580