akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

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

char board[10][10];
int H, W;

int main()
{
	cin >> H >> W;
	
	for (int i = 0; i < H; i++)
		cin >> board[i];

	int num = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (board[i][j] == '#')num++;
		}
	}
	if (H + W - 1 == num)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma once

#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif
/*
 * @see https://snuke.hatenablog.com/entry/2014/12/01/235807
 */
//BEGIN CUT HERE
// longest prefix suffix matching of [0, i)
vector<int> morris_pratt(const string &s){
  int n=s.size();
  vector<int> mp(n+1,-1);
  for(int i=0,j=-1;i<n;i++){
    while(~j&&s[i]!=s[j]) j=mp[j];
    mp[i+1]=++j;
  }
  return mp;
}
// smallest d s.t. s[x] == s[x + d] for all x
vector<int> minimum_period(const string &s){
  auto mp=morris_pratt(s);
  for(int i=1;i<(int)mp.size();i++) mp[i]=i-mp[i];
  return mp;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
// test minimum_period
signed ARC060_F(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string w;
  cin>>w;

  int n=w.size();
  if(w==string(n,w[0])){
    cout<<n<<endl<<1<<endl;
    return 0;
  }

  auto kmp=minimum_period(w);
  if(n%kmp[n]!=0||n==kmp[n]){
    cout<<1<<endl<<1<<endl;
    return 0;
  }

  string w_rev=w;
  reverse(w_rev.begin(),w_rev.end());
  auto kmp_rev=minimum_period(w_rev);

  int cnt=0;
  for(int i=1;i<n;i++){
    int j=n-i;
    if(i%kmp[i]==0&&i>kmp[i]) continue;
    if(j%kmp_rev[j]==0&&j>kmp_rev[j]) continue;
    cnt++;
  }
  cout<<2<<endl<<cnt<<endl;
  return 0;
}
/*
  verified on 2020/08/20
  https://atcoder.jp/contests/arc060/tasks/arc060_d
*/

signed main(){
  ARC060_F();
  return 0;
}
#endif


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    const int R = 0;
    const int G = 1;
    const int B = 2;
    vector<int> color({R, G, B});
    
    const int X = 8;
    const int Y = 9;

    string patt[2];
    cin >> patt[0] >> patt[1] ;
    
    const lli mod = 1000000007;
        
    const int N = 52 + 5;
    map<pair<int, int>, lli> dp[N];
    dp[0][make_pair(X, X)] = 1;

    for (int i = 0; i < n; ++i) {
      each (j, dp[i]) {
        const pair<int, int> p = j.first;
        if (patt[0][i] == patt[1][i]) {
          each (c, color) {
            unless (p.first == c || p.second == c) {
              // cout << i << "(|):" << p << "->" << make_pair(c, c) << endl;
              (dp[i + 1][make_pair(c, c)] += j.second) %= mod;
            }
          }
        } else {
          each (c, color) {
            each (d, color) {
              if (c == d) continue;
              unless (p.first == c || p.second == d) {
                // cout << i << "(=):" << p << "->" << make_pair(c, d) << endl;
                (dp[i + 2][make_pair(c, d)] += j.second) %= mod;
              }
            }
          }          
        }
      }
    }

    lli sum = 0;
    each (i, dp[n]) {
      (sum += i.second) %= mod;
    }
    cout << sum << endl;
  }
  
  return 0;
}


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
#define MAX_N 5001
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a[MAX_N], sum, MAX;

int main(){
	while (cin >> n&&n){
		MAX = -100000000;
		REP(i, n)cin >> a[i];
		for (int i = 0; i < n; i++){
			sum = a[i];
			MAX = max(MAX, sum);
			for (int j = i + 1; j < n; j++){
				sum += a[j];
				MAX = max(MAX, sum);
			}
		}
		cout << MAX << endl;
	}
}

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

N = int(input())
a = list(map(int,input().split()))	
b = list(map(int,input().split()))
c = list(map(int,input().split()))
total = 0

for i in range(N):
    total += b[a[i] - 1]
    if i >= 1 and a[i - 1] + 1 == a[i]:
        total += c[a[i - 1] - 1]
print(total)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**6)

K = 43


def main(input, print):
    n = int(input())
    a = list(map(int, input().split()))
    a1 = a[0]
    a2 = a[1]
    s = a1 + a2
    x = 0
    for i in range(2, n):
        x ^= a[i]

    dp = [[[-1 for _ in range(2)] for _ in range(2)] for _ in range(K)]
    dp[0][0][0] = 0
    v = 1
    for i in range(K-1):
        cx = x & 1
        cs = s & 1
        ca = a1 & 1
        for j in range(2):
            for k in range(2):
                if dp[i][j][k] == -1:
                    continue
                for na in range(2):
                    for nb in range(2):
                        ni = i + 1
                        nj = 0
                        nk = k
                        if na ^ nb != cx:
                            continue
                        ns = na + nb + j
                        if ns % 2 != cs:
                            continue
                        if ns >= 2:
                            nj = 1
                        if ca < na:
                            nk = 1
                        elif ca == na:
                            nk = k
                        else:
                            nk = 0
                        dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k] | (v*na))
        x >>= 1
        s >>= 1
        a1 >>= 1
        v <<= 1

    ans = dp[K-1][0][0]
    if ans == -1 or ans == 0:
        print(-1)
    else:
        print(a[0]-ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


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

int main() {
    int N; cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++) cin >> P.at(i);

    int minv = N + 1, res = 0;
    for (int i = 0; i < N; i++) {
        minv = min(minv, P.at(i));
        if (minv == P.at(i)) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 4060
import itertools
import copy
def row(c, i, H, W):
  for j in range(W):
    c[i][j] = 0
    
def column(c, j, H, W):
  for i in range(H):
    c[i][j] = 0

def blacks(c, H, W):
  black = 0
  for row in c:
    black += sum(row)
  return black

H, W, K = map(int, input().split())
c = []
for i in range(H):
  c.append([])
  string = input()
  for color in string:
    if color == '#':
      c[-1].append(1)
    else:
      c[-1].append(0)
height = list(itertools.product([0, 1], repeat=H))
weight = list(itertools.product([0, 1], repeat=W))
answer = 0
for tate in height:
  for yoko in weight:
    cc = copy.deepcopy(c)
    for i in range(len(tate)):
      if tate[i]:
        row(cc, i, H, W)
    for j in range(len(yoko)):
      if yoko[j]:
        column(cc, j, H, W)
    if blacks(cc, H, W) == K:
      answer += 1
print(answer)

Measured memory_bytes: 9348
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        
        int kosu=int.Parse(Console.ReadLine());
        string [] a=Console.ReadLine().Split(' ');
        string [] b=Console.ReadLine().Split(' ');
        
        int [] x=a.Select(int.Parse).ToArray();
        int [] y=b.Select(int.Parse).ToArray();
        
        double sum1=0;
        double sum2=0;
        double sum3=0;
        double max=0;
        for(int i=0;i<kosu;i++)
        {
            sum1+=Math.Abs(x[i]-y[i]);
            sum2+=Math.Pow(Math.Abs(x[i]-y[i]),2);
            sum3+=Math.Pow(Math.Abs(x[i]-y[i]),3);
            if(Math.Abs(x[i]-y[i])>max)max=Math.Abs(x[i]-y[i]);
        }
        Console.WriteLine(sum1);
        Console.WriteLine(Math.Sqrt(sum2));
        Console.WriteLine(Math.Pow(sum3,1.0/3.0));
        Console.WriteLine(max);
    }
}



Measured memory_bytes: 18392
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
S = input()
T = input()

if S == T:
    print("No")
    sys.exit()

Sx = ''.join(sorted(S))
Tx = ''.join(sorted(T, reverse=True))

L = []
L.append(Sx)
L.append(Tx)

L.sort()

if L[0] == Sx:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 77460
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int N, a[100], cnt[101];
bool f;

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> a[i];
		++cnt[a[i]];
	}
	sort(a, a + N);
	f = true;
	if (a[0] == a[1]) {
		if (cnt[a[0]] >= 3)f = false;
		if (a[N - 1] != a[0] * 2 - 1)f = false;
		for (int i = a[0] + 1; i <= a[N - 1]; ++i)
			if (cnt[i] <= 1)f = false;
	}
	else {
		if (a[N - 1] != a[0] * 2)f = false;
		for (int i = a[0] + 1; i <= a[N - 1]; ++i)
			if (cnt[i] <= 1)f = false;
	}
	if (f)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long  
#define pb push_back
#define fi first
#define se second
using namespace std;
ll mo=1e9+7;
ll i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
 while(tc--)
 {
	string s,t;
	cin>>s>>t;
	for(i=0;i<26;i++)
	{
		string k;
		k=s+char(97+i);
		if(k==t)
		{
			cout<<"Yes";
			break;
		}
	}
	if(i==26)
	cout<<"No";
	cout<<"\n";
 } 
}


Measured memory_bytes: 3652
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  int cnt[s[0].size()];
  for (int i = 0; i < s[0].size(); i++) cnt[i] = 0;
  for (int i = 0; i < s[0].size(); i++) {
    for (int j = 1; j < n; j++) {
      for (int k = 0; k < s[j].size(); k++) {
        if (s[0][i] == s[j][k]) {
          s[j][k] = 'A';
          cnt[i]++;
          break;
        }
      }
    }
  }
  string ans = "";
  for (int i = 0; i < s[0].size(); i++) {
    if (cnt[i] == n - 1) ans += s[0][i];
  }
  sort(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
char s[1010];
int n;
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	scanf("%d",&n);
	if (n==1) { printf("%s\n",s+1);return 0;}
	for (int i=1;i<=len;i++)
		if (i%n==1) putchar(s[i]);
	return 0;
}


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

int n,k,d[20];

int check(int x){
	while(x){
		for(int i=1;i<=k;i++)
			if(x%10==d[i])return 0;
		x/=10;
	}
	return 1;
}

int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		cin>>d[i];
	for(int i=n;i<=1000000;i++)
		if(check(i)){
			printf("%d",i);
			break;
		}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    string s;
    cin>>s;
    int q;
    cin>>q;
    vector<char>u(6e5+10,0);
    for (int i = 0; i < s.size(); i++)
    {
            u[3e5+1+i]=(char)s[i];
    }
    
    bool m=true;
    int l=3e5,r=3e5+1+(int)s.size();
    while(q--){
        int t;
        cin>>t;
        if(t==1){
            m=1-m;
        }
        else{
            int f;
            char v;
            cin>>f>>v;
            if(f==1){
                if(m==true){
                    u[l]=v;
                    l--;
                }
                else{
                    u[r]=v;
                    r++;
                }
            }
            if(f==2){
                if (m == false)
                {
                    u[l] = v;
                    l--;
                }
                else
                {
                    u[r] = v;
                    r++;
                }
            }
        }
    }
  //  cerr<<l<<" "<<r<<endl;
    if(m){
    for (int i = l+1; i < r; i++)
    {
            cout<<u[i];
        
    }
    cout<<endl;
    }
    else{
        for (int i = r-1; i>= l+1; i--)
        {
            cout << u[i];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1408
struct shop_t{
	int count;
	char name;
}s[5];
//M(int*a){return*1[&a]-*a;}
M(int*a,int*b){return*b-*a;}
main(){
	int a,b,i=0;
	for(;~scanf("%d%d",&a,&b);){
		s[i].count=a+b;
		s[i].name='A'+i;
		if(++i==5){
			qsort(s,5,sizeof(*s),M);
			printf("%c %d\n",s[0].name,s[0].count);
			i=0;
		}
	}
}

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

int main(void){
  int n, x, t, s;
  cin >> n >> x >> t;
  if(n%x==0){
    s=t*(n/x);
  }
  else{
    s=t*((n/x)+1);
  }
  cout << s;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int n;
  int count;
  bool isPrime;
  
  while (1) {
    cin >> n;
    if (n == 0) break;

    count = 0;
    for (int i = n + 1; i <= 2 * n; i++) {
      if (n == 1) {
        count = 1;
        break;
      }
      if (!(i % 2)) continue;
      isPrime = true;
      for (int j = 3; j <= sqrt(i); j+=2) {
        if (!(i % j)) {
          isPrime = false;
          break;
        }
      }
      if (isPrime) {
        count++;
      }
    }
    cout << count << endl;
  }
}
      



Measured memory_bytes: 3076
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

if A1>B1:
    A1,A2,B1,B2 = B1,B2,A1,A2
D1 = B1-A1
D2 = B2-A2

if D1*T1 + D2*T2 > 0:
    print(0)
    exit()
if D1*T1 + D2*T2 == 0:
    print('infinity')
    exit()

p = D1*T1
q = -D2*T2
d = q-p
k = p//d
b = int(q*k == p*(k+1))
print(1 + k*2 - b)

Measured memory_bytes: 9180
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = 0;
    for (int i=0; i<3; ++i){
        if(s[i] == '1'){
            n++;
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define pie pair<int,int>
using namespace std;

/* power modulo p */

int mpower(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
}

int32_t main(){

	int n,p;
	cin>>n>>p;
	string s;cin>>s;
	int a[n];
	for(int i=0;i<n;i++){
		a[i]=s[i]-'0';
		a[i]%=p;
	}
	if(p!=2&&p!=5){
		map<int,int> mp;
		int pre[n];
		pre[0]=(a[0]*mpower(10,n-1,p))%p;
		mp[0]++;
		mp[pre[0]%p]++;
		for(int i=1;i<n;i++){
			pre[i]=((pre[i-1]+(a[i]*mpower(10,n-i-1,p)))%p);
			mp[pre[i]%p]++;
		}
		int ans=0;
		for(auto x:mp){
			if(x.second){
				ans+=(x.second*(x.second-1))/2;
			}
		}
		cout<<ans<<endl;
	}else{

		int ans=0;
		for(int i=0;i<n;i++)
			if(a[i]%p==0)ans+=i+1;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    if(n > k) ans = x * k + y * (n - k);
    else ans = x * n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int dig_sum(int a){
	int res = 0;
	while(a){
		res += a % 10;
		a /= 10;
	}
	return res;
}


int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
	int n; cin >> n;
	int ans = IINF;
	rep(i, 1, n){
		ans = min(ans, dig_sum(i) + dig_sum(n - i));
	}
	cout << ans << "\n";
  
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,len;
char s[10005];
int main()
{
	scanf("%d\n%s",&n,s);
	if(n==0) {printf("%s",s);return 0;}
	len=strlen(s);
	for(int i=0;i<len;++i)
	{
		s[i]-='A';s[i]=(s[i]+n)%26;
		s[i]+='A';printf("%c",s[i]);
	}
	return 0;
}

Measured memory_bytes: 256
// ohainiさんの写経
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	int N;
	cin >> N;
	map<int,int> m;
	m[0]++;
	for(int i = 0; i < N; i++) {
		int t;
		cin >> t;
		m[t]++;
	}
	int ans = 100;
	vector<int> q;
	int cnt = 1;
	for(auto x:m){
		if(x.second>=3 || (x.first == 0 && x.second >= 2)|| (x.first == 12 && x.second >=2)){
			ans = 0;
			break;
		} else {
			if(x.second==2){
				q.push_back(x.first);
				q.push_back(24-x.first);
			}
			if(x.second == 1){
				if(cnt) q.push_back(x.first);
				else q.push_back(24-x.first);
				cnt = 1 - cnt;
			}
			sort(q.begin(),q.end());
			for(int i = 0; i < (int)q.size()-1; i++){
				chmin(ans,q[i+1]-q[i]);
			}
			chmin(ans,24-*(q.end()-1));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N, M = ri_()
d = [0] * N
for i in range(M):
    a, b = ri_()
    d[a - 1] += 1
    d[b - 1] += 1
for i in range(N):
    print(d[i])

Measured memory_bytes: 63340
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
	
	int f[10]={0},a;
	cin>>a;
	f[a]=1;
	cin>>a;
	f[a]=1;
	cin>>a;
	f[a]=1;
	cin>>a;
	f[a]=1;
	if(f[1]&&f[7]&&f[9]&&f[4])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	

}

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

int main()
{
  ll N, K, ans = 0;
  cin >> N >> K;
  vector<ll> a(N, 0);
  for (ll i = 0; i < N; i++)
  {
    cin >> a[i];
  }

  if (N <= K)
  {
    ans = 1;
  }
  else
  {
    ans = ceil((double)(N - 1) / (K - 1));
  }

  cout << ans << endl;
}


Measured memory_bytes: 4060
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	ll N, K;
	std::cin >> N >> K;

	vll A(N + 1);
	repeq(i, 1, N) {
		std::cin >> A[i];
	}

	ll cur = 1;
	vll dic(N + 1, -1);
	bool flg = false;
	repeq(i, 1, K) {
		if (dic[cur] < 0 || flg) {
			dic[cur] = i;
			cur = A[cur];
		}
		else if(!flg) {
			ll tmp = K - (dic[cur] - 1);
			tmp %= i - dic[cur];
			i = K - tmp ;
			flg = true;
		}
	}

	std::cout << cur << endl;
	return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


int main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	int a[m];
	for(int i=0;i<m;i++){
		cin>>a[i];
	}
	int cnt1=0,cnt2=0;
	int x1=x,x2=x;
	while(x1!=0){
		x1--;
		for(int i=0;i<m;i++){
			if(x1==a[i]){
				cnt1++;
			}
		}
	}
	while(x2!=n){
		x2++;
		for(int i=0;i<m;i++){
			if(x2==a[i]){
				cnt2++;
			}
		}
	}
	int ans=min(cnt1,cnt2);
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <queue>

using namespace std;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> freq(26);
  string line;
  getline(cin, line);
  for(int i = 0; i < n; i++)
  {
	string line;
	getline(cin, line);
	freq[line[0] - 'A']++;
  }
  priority_queue<int> q;
  for(int i = 0; i < 26; i++)
  {
	if(freq[i] > 0)
	{
	  q.push(freq[i]);
	}
  }

  int count = 0;
  while(q.size() >= k)
  {
	vector<int> vs;
	for(int i = 0; i < k; i++)
	{
	  vs.push_back(q.top());
	  q.pop();
	}
	count++;
	for(int i = 0; i < k; i++)
	{
	  vs[i]--;
	  if(vs[i] > 0)
	  {
		q.push(vs[i]);
	  }
	}
  }
  cout << count << endl;
}


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

vector<ll> ans;
vector<vector<int>> node;

// 1 <= ai < bi <= N という制約は ai が bi の親になることを保証しない
// 例
// 1-4
// 2-4
// 3-4

void score(int now, int parent=-1) {
    for (int u : node[now]) {
        if (u == parent) {
            continue;
        }
        ans[u] += ans[now];
        score(u, now);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    ans.resize(n);
    node.resize(n);

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    score(0);
    rep(i, n) {
        if (i == 0) {
            cout << ans[i];
        } else {
            cout << " " << ans[i];
        }
    }
    cout << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 24320
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

vector<int> v;
vector<vector<int>> tree;
vector<bool> visited;

void dfs(int i = 1) {
  for (int j : tree[i]) {
    if (visited[j]) continue;
    visited[j] = 1;
    v[j] += v[i];
    dfs(j);
  }
}


int main() {
  ll N, Q, a, b, p, x;
  cin >> N >> Q;

  v.resize(N+1);
  tree.resize(N+1);
  visited.resize(N+1);
  for (int i = 1; i != N; ++i) {
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  for (int i = 0; i != Q; ++i) {
    cin >> p >> x;
    v[p] += x;
  }

  visited[1] = 1;
  dfs();

  for (int i = 1; i <= N; ++i) {
    cout << (i > 1 ? " " : "") << v[i];
  }
  cout << endl;
}


Measured memory_bytes: 24332
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

struct Node {
	ll p;
	Node *prev, *next;
};

Node *nil;
int main() {
	nil = new Node();
	nil->next = nil;
	nil->prev = nil;

	ll n; cin >> n;

	rep(i, 0, n) {
		ll a; cin >> a;
		Node* node = new Node();
		node->p = a;
		if (i % 2 == 0) {
			nil->prev->next = node;
			node->prev = nil->prev;
			nil->prev = node;
			node->next = nil;
		}
		else {
			nil->next->prev = node;
			node->next = nil->next;
			nil->next = node;
			node->prev = nil;
		}
	}

	if (n % 2 == 0) {
		Node *s = nil->next;
		while (s != nil) {
			cout << s->p;
			if (s->next != nil) {
				cout << " ";
			}
			s = s->next;
		}
	}
	else {
		Node *s = nil->prev;
		while (s != nil) {
			cout << s->p;
			if (s->prev != nil) {
				cout << " ";
			}
			s = s->prev;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 8448
S = input()

T = ["dream","dreamer","erase","eraser"]
flag = True
for i in range(len(S)):
    if (flag == False) or (len(S) == 0):
        break
    if S[-5:] in T:
        S = S[:-5]
    elif S[-6:] in T:
        S = S[:-6]
    elif S[-7:] in T:
        S = S[:-7]
    else:
        print("NO")
        flag = False
if flag == True:
    print("YES")

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

int check(LL a[],LL n)
{
    LL tot_cost=0;
    LL i=1;
    LL cost[n+1];
    for(LL i=0;i<=n;i++){
        cost[i]=INT_MAX;
    }
    if(n==2)
    {
        return abs(a[n]-a[n-1]);
    }
    cost[1]=0;
    cost[2]=cost[1]+abs(a[1]-a[2]);
    cost[3]=min(cost[2]+abs(a[2]-a[3]),cost[1]+abs(a[1]-a[3]));
    i=4;
    while(i<=n)
    {
        cost[i]=min(cost[i-1]+abs(a[i]-a[i-1]),cost[i-2]+abs(a[i]-a[i-2]));
        i++;
    }
   /* for(LL i=1;i<=n;i++)
        cout<<cost[i]<<" ";
    cout<<endl;*/

    return cost[n];
}


int main()
{
    LL n;
    cin>>n;
    LL a[n+1];
    for(LL i=1;i<=n;i++)
        cin>>a[i];
    cout<<check(a,n)<<endl;

    return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		// 読み込み
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
      	if (S.substring(2,3).equals(S.substring(3,4)) && S.substring(4,5).equals(S.substring(5,6))) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <stdlib.h>
#define MAX_E 500000
#define MAX_V 100000
#define INF 1010001000

typedef struct edge{
    int from, to, cost;
}edge;

edge es[MAX_E];
int d[MAX_V];
int v, e;

int main(void)
{
    int i, j, r, fl;
    scanf("%d%d%d", &v, &e, &r);

    for (i = 0; i < v; i++) {
        d[i] = INF;
    }

    for (i = 0; i < e; i++) {
        scanf("%d %d %d", &es[i].from, &es[i].to, &es[i].cost);
    }
    d[r] = 0;
    while (1) {
        fl = 1;
        for (i = 0; i < e; i++) {
            if (d[es[i].from] != INF &&
                    d[es[i].to] > d[es[i].from] + es[i].cost) {
                d[es[i].to] = d[es[i].from] + es[i].cost;
                fl = 0;
            }
        }
        if (fl) {
            break;
        }
    }
    for (i = 0; i < v; i++) {
        if (d[i] == INF) {
            puts("INF");
        } else {
            printf("%d\n", d[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 6740
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(string, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto h = aryread();
    long cnt, left;
    while (h.sum > 0)
    {
        long iter = n, m = h[left];
        foreach (i; iota(left, n))
        {
            if(h[i] == 0)
            {
                iter = i;
                break;
            }
            m = min(h[i], m);
        }
        foreach (i; iota(iter - left))
        {
            // writeln(left + i);
            h[i + left] -= m;
        }
        left = h.left_idx();
        // h.writeln();
        cnt += m;
    }
    cnt.writeln();
}

auto left_idx(T)(T ary)
{
    long iter;
    while (iter < ary.length && ary[iter] == 0)
        iter++;
    return iter;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

using namespace std;


/// Bismilahir Rahmanir Rahim


typedef unsigned int ui;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef short int si;
typedef unsigned short int usi;
typedef pair <int, int> pii;


#define CASE false
#define TEST false
#define BUFFER true
#define TIME false
#define DEBUG true
#define _ << " " <<
#define __ << "\n"
#define ff first
#define ss second


const double pi = acos(-1);
const int inf = 2147483647;
const int _inf = -2147483648;
const int mod = 1e9+7;


void delay(int sec); // DEBUG



void solution(void)
{
    int n;

    cin >> n;
    int ara[n][3], dp[n][3];

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 3; ++j) {
            cin >> ara[i][j];
        }
    }
    dp[0][0] = ara[0][0];
    dp[0][1] = ara[0][1];
    dp[0][2] = ara[0][2];

    int thr = 3;
    for(int i = 1; i < n; ++i) {
        for(int j = 0; j < thr; ++j) {
            if (!(j ^ 0)) dp[i][j] = ara[i][j] + max(dp[i-1][1], dp[i-1][2]);
            else if (j ^ 2) dp[i][j] = ara[i][j] + max(dp[i-1][0], dp[i-1][2]);
            else dp[i][j] = ara[i][j] + max(dp[i-1][0], dp[i-1][1]);
        }
    }


    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) __;



    return ;
}

int main(int argc, char *arv[])
{
    #if BUFFER
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #endif


    unsigned short int t = 1;

    #if CASE
    int cnt = 1;
    #endif

    #if TEST
    cin >> t;
    #endif

    #if TIME
    clock_t start_time, end_time;
    double time_elapsed;
    #endif


    while(t--) {

        #if TIME
        start_time = clock();
        #endif

        #if CASE
        cout << "Case " << cnt++ << ": ";
        #endif

        solution();

        #if TIME
        end_time = clock();

        time_elapsed = (double) (end_time - start_time) / CLOCKS_PER_SEC;

        cout << "\nRuntime: " << fixed << setprecision(7) << time_elapsed << "\n";
        #endif
    }


    return 0;
}

void delay(int sec)
{
    int mili_sec = 1000 * sec;

    clock_t start_time = clock();

    while (clock() < start_time + mili_sec);

    return ;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main() {
  string n;
  cin>>n;
  for (int i=0; i<3; i++) {
    if (n[i]=='9') cout<<1;
    else cout<<9;
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)cnt++;
    }
    if(cnt==8)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

 
struct LazySegmentTree {
private:
    int n;
    vector<LL> node, lazy;
    vector<bool> lazyFlag;
 
public:
    LazySegmentTree(vector<LL> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        lazyFlag.resize(2*n-1, false);
 
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
 
    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }
 
    void update(int a, int b, LL x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }
 
    LL find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return LINF;
        if(a <= l && r <= b) return node[k];
        LL vl = find(a, b, 2*k+1, l, (l+r)/2);
        LL vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};


int main(){
    int n,q,a,b;cin >> n >> q >> a >> b;
    vector<LL> x(q);
    for (int i = 0; i < q; i++) {
        cin >> x[i];
    }
    LazySegmentTree seg1( vector<LL> (n+1,LINF) );
    LazySegmentTree seg2( vector<LL> (n+1,LINF) );
    seg1.update(a,a+1,abs(x[0]-b)-a);
    seg1.update(b,b+1,abs(x[0]-a)-b);
    seg2.update(a,a+1,abs(x[0]-b)+a);
    seg2.update(b,b+1,abs(x[0]-a)+b);
    LL sum = 0;
    for (int i = 1; i < q; i++) {
        LL t = min(seg1.find(0,x[i])+x[i],seg2.find(x[i],n+1)-x[i])-abs(x[i]-x[i-1]);
        seg1.update(x[i-1],x[i-1]+1,t-x[i-1]);
        seg2.update(x[i-1],x[i-1]+1,t+x[i-1]);
        sum += abs(x[i]-x[i-1]);
    }
    LL dp = LINF;
    for (int i = 0; i < n+1; i++) {
        dp = min(dp,seg1.find(i,i+1)+i);
    }
    cout << sum+dp << endl;
    return 0;
}



Measured memory_bytes: 19940
#include<stdio.h>

#define N 8

#define F 0

#define FN 1
void Queen(int);
void Print(void);

int Q[N][N];
int drop[2*N+1];
int dn[2*N+1];
int r[N];
int c[N];

int main(){
  int i,n;
  int q_c,q_r;
  scanf("%d", &n);

  for(i = 0; i <n; i++){
    scanf("%d%d", &q_r,&q_c);
    Q[q_r][q_c] = FN;
  }
  
  Queen(0);
  return 0;
}
void Queen(int a){
  int i;
  if(a == N){
    Print();
    return;
  }
  for(i = 0;i < N; i++){
    if(c[i] == FN || drop[a+i] == FN || dn[a-i+N-1] == FN)continue;

    r[a] = i;
    c[i] =FN;
    drop[a+i] =FN;
    dn[a-i+N-1] = FN;
    Queen(a+1);
    
    c[i] =F;
    drop[a+i] = F;
    dn[a-i+N-1] = F;
  }

}

void Print(void){
  int i,j;
  for(i = 0; i< N; i++){
    for(j = 0; j < N; j++){
      if(Q[i][j] == FN){
	if(r[i] != j) return;
      }
    }
  }
   for(i = 0; i< N; i++){
    for(j = 0; j < N; j++){
      if(r[i] == j){
	printf("Q");
      }
      else{
	printf(".");
      }
    }
    printf("\n");
   }
}

Measured memory_bytes: 572
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2

output:
3
"""

import sys
from collections import deque


def graph_bfs(source, target, parent):
    visited = [False] * vertices
    queue = deque()
    queue.append(source)
    visited[source] = True

    while queue:
        current = queue.popleft()
        for adj, cp in adj_table[current].items():
            if not visited[adj] and cp > 0:
                queue.append(adj)
                visited[adj] = True
                parent[adj] = current

    return True if visited[target] else False


def graphFordFulkerson(source, sink):
    parent = [-1] * vertices
    max_flow = 0

    while graph_bfs(source, sink, parent):
        path_flow = float('inf')

        bk_1 = sink
        while bk_1 is not source:
            path_flow = min(path_flow, adj_table[parent[bk_1]][bk_1])
            bk_1 = parent[bk_1]

        max_flow += path_flow

        bk_2 = sink
        while bk_2 is not source:
            parent_bk_2 = parent[bk_2]
            adj_table[parent_bk_2].setdefault(bk_2, 0)
            adj_table[bk_2].setdefault(parent_bk_2, 0)

            # print(bk_2, parent_bk_2, path_flow, bk_1, parent[bk_1], parent, adj_table)
            adj_table[parent_bk_2][bk_2] -= path_flow
            adj_table[bk_2][parent_bk_2] += path_flow
            bk_2 = parent[bk_2]

    return max_flow


def generate_adj_table(v_table):
    for each in v_table:
        source, target, cp = map(int, each)
        init_adj_table[source][target] = cp

    return init_adj_table


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    init_adj_table = [dict() for _ in range(vertices)]
    adj_table = generate_adj_table(v_info)
    ans = graphFordFulkerson(source=0, sink=vertices - 1)
    print(ans)

Measured memory_bytes: 8108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<char, int> p;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    string s; cin >> s;
    int n = s.length();
    set<char> c;
    REP(i,n) c.emplace(s[i]);
    if(c.size()==1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = INF;
    for(char x : c) {
        ll tmp = 0;
        string str = s;
        bool flag = true;
        while(flag) {
            string S = "";
            REP(i,str.length()-1) {
                S += (str[i]==x || str[i+1]==x ? x : str[i]);
            }
            str = S;
            REP(i,S.length()) {
                if(S[i] != x) break;
                if(i==S.length()-1) {
                    flag = false;
                }
            }
            tmp ++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import*
e=sys.stdin.readline
n=int(e())
A=[[]for _ in[0]*n]
for _ in[0]*n:
 b=list(map(int,e().split()))
 for i in range(b[1]):k=2*-~i;A[b[0]]+=[(b[k],b[k+1])]
H=[[0,0]]
d=[0]+[1e6]*n
c=[1]*n
while H:
 f=heappop(H)
 u=f[1]
 c[u]=0
 if d[u]>=f[0]:
  for s in A[u]:
   v=s[0]
   if c[v]and d[v]>d[u]+s[1]:
    d[v]=d[u]+s[1]
    heappush(H,[d[v],v])
for i in range(n):print(i,d[i])


Measured memory_bytes: 69152
#include <stdio.h>
#include <stdlib.h>

#define ll long long
#define MD 998244353
#define mod(n) ((n%MD+MD)%MD)
#define max(x, y) (x>y? x : y)
#define min(x, y) (x<y? x : y)
#define mul3(x, y, z) (mod(mod(x*y)*z))
#define ARG_MAX 3010

ll Y(ll, ll, ll, ll);
static ll memo_X[ARG_MAX][ARG_MAX];
static ll memo_Y[ARG_MAX][ARG_MAX];

ll modpow(ll x, ll y){
    ll res = 1;
    while(y>0){
        if(y&1) res = mod(res*x);
        x = mod(x*x);
        y >>= 1;
    }
    return res;
}

ll X(ll A, ll B, ll C, ll D){
    if(memo_X[C][D]!=-1) return memo_X[C][D];

    ll res;
    if(C==A) res = (D-B)*modpow(A-1, D-B-1);
    else if(D==B) res = modpow(B, C-A);
    else res = X(A, B, C-1, D)*D + Y(A, B, C-1, D)*D;

    res = mod(res);
    memo_X[C][D] = res;
    return res;
}

ll Y(ll A, ll B, ll C, ll D){
    if(memo_Y[C][D]!=-1) return memo_Y[C][D];

    ll res;
    if(D==B) res = 0;
    else if(C==A) res = modpow(A, D-B) - (D-B)*modpow(A-1, D-B-1);
    else res = X(A, B, C, D-1) + Y(A, B, C, D-1)*C;

    res = mod(res);
    memo_Y[C][D] = res;
    return res;
}


int main(){
    int A, B, C, D;
    scanf("%d%d%d%d", &A, &B, &C, &D);

    for(int i=0;i<ARG_MAX;i++){
        for(int j=0;j<ARG_MAX;j++){
            memo_X[i][j] = -1;
            memo_Y[i][j] = -1;
        }
    }
    if(C<=A && D<=B){
        printf("1\n");
        return 0;
    }    

    ll ans = mod(X(A, B, C, D) + Y(A, B, C, D));
    printf("%lld\n", ans);

    return 0;
}



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

int main()
{
    double pi = 3.14159265358979323846264338327950L;
    double A, B, H, M, ans;
    cin >> A >> B >> H >> M;
    ans = (A * A) + (B * B) - 2 * A * B * cos(abs((30 * H + 0.5 * M) - 6*M) * pi / 180.0);
    cout << fixed << setprecision(30) << sqrt(ans) << endl;
    return 0;
}


Measured memory_bytes: 4076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


    class Program
    {
        static void Main(string[] args)
        {
          int Input = int.Parse(Console.ReadLine());
          long sum = 0;
          for(int i = 1; i <= Input; i++){
              if(i % 3 != 0 && i % 5 != 0){
                  sum += i;
              }
          }
          
            Console.WriteLine(sum);
          
        }
    }



Measured memory_bytes: 17628
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    string s, t;
    cin >> s;
    for (int j = 0; j < 7; j++){
        t = s;
        t.erase(j, s.size() - 7);
        if (t == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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

void main_()
{
    ll N, M, K;
    cin >> N >> M >> K;

    for (ll i = 0; i <= N; ++i) {
        for (ll j = 0; j <= M; ++j) {
            ll black = i * M + j * N - (2 * i * j);
            if (black == K) {
                cout << "Yes\n";
                return;
            }
        }
    }

    cout << "No\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256