akhauriyash/Code-Regression huggingface dataset:
package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var N int
	con.Scan(&N)
	con.Println(800*N - 200*(N/15))
	return nil
}


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


int main () {
    int a ;
    cin >> a ;
    string s ;
    cin >> s ;
    if(a >= 3200){
        cout << s << endl ;
    }
    else {
        cout << "red" << endl ;
    }
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  char a;
  vector<char> S;
  for(int i = 0 ; i < n ; i++){
    cin >> a;
    S.push_back(a);
  }
  int maxi = 0;
  for(int i = 0; i < n-1; i++){
    vector<char> s(0);
    for(int j = 0; j <= i ; j++){
      int flag = 0;
      for(int k = 0; k <= s.size() ; k++){
        if(s.size() == 0){
          flag = 0;
        }
        else if( S[j] == s[k]){
          flag = 1;
        }
      }
      if(!flag) s.push_back(S[j]);
    }
    int count = 0;
    for(int j = 0; j < s.size() ; j++){
      for(int k = i+1; k < n; k++){
        if(s[j] == S[k]){
          count++;
          break;
        }
      }
    }
    if(maxi < count) maxi = count;
  }
  cout << maxi << endl;
}


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

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int A, B;
	cin >> A >> B;
	cout << A*B << '\n';    

    return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    map<ll, ll> u;
    rep(i, k)
    {
        int d;
        cin >> d;
        rep(i, d)
        {
            int a = 0;
            cin >> a;
            a--;
            u[a] += 1;
        }
    }
    ll count = 0;
    rep(i, n)
    {
        if (u[i] == 0)
        {
            count += 1;
        }
    }
    cout << count;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] s = new int[n];
        int[] t = new int[m];
        int mod = 1000000007;
        for(int i=0;i<n;i++){
            s[i] = Integer.parseInt(sc.next());
        }
        for(int i=0;i<m;i++){
            t[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        long[][] dp = new long[n+1][m+1];

        for(int i=0;i<n+1;i++)dp[i][0] = 1;
        for(int i=0;i<m+1;i++)dp[0][i] = 1;

        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i]==t[j]){
                    dp[i+1][j+1] = (dp[i][j+1]+dp[i+1][j])%mod;
                }else{
                    dp[i+1][j+1] = (dp[i][j+1]+dp[i+1][j]-dp[i][j])%mod;
                    dp[i+1][j+1]+=mod;
                    dp[i+1][j+1]%=mod;
                }
            }
        }
        System.out.println(dp[n][m]);
    }
}   

Measured memory_bytes: 86336
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	


int main()
{
	fastio;
	ll n,k;
	cin>>n>>k;
	ll kr=n%k;
	cout<<min(kr,k-kr)<<endl;
	
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,x;
	cin>>n>>x;
	int l[n];
	int ans=0;
	int coor=0;
	for(int i=0;i<n;i++)
	{
		cin>>l[i];
	}
	for(int i=0;i<n+1;i++)
	{
		if(coor<=x)
		ans++;
		coor+=l[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main(){
    map<string,vector<int> >M;
    string str;
    int p;
    while(cin>>str>>p){
        M[str].push_back(p);
    }
    map<string,vector<int> >::iterator ite=M.begin();
    for(;ite!=M.end();ite++){
        sort((ite->second).begin(),(ite->second).end());
    }
    for(ite=M.begin();ite!=M.end();ite++){
        cout<<ite->first<<endl;
        bool f=false;
        for(int i=0;i<(ite->second).size();i++){
            if(f)cout<<" ";
            cout<<(ite->second)[i];
            f=true;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1240
#include <iostream>
#include <iomanip>

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;
    int A[N];
    for(auto &a : A){
        std::cin >> a;
    }
    double result = 0;
    for(auto &a : A){
        result += 1.0/a;
    }
    result = 1.0/result;

    std::cout <<std::fixed << std::setprecision(10) << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;

int f(string x){
  if(x.size()<2){
    int num = atoi(x.c_str());
    return num;
  }
  int sum=0;
  rep(i,x.size()){
    sum+=atoi((x.substr(0, i+1)).c_str());cout<<sum<<endl;
  }
  return f(x.substr(1))+x[0]+sum;
}

int main() {
  string s;cin>>s;ll sum=0;
  rep(bit,(1<<s.size()-1)){
    vector<int> v;
    v.push_back(0);
    rep(i,s.size()){
      if(bit&(1<<i))v.push_back(i+1);
    }
    v.push_back(s.size());
    for(int a=0;a<v.size()-1;a++){
      //sum+=atoi((s.substr(v[a],v[a+1]-v[a])).c_str());
      sum+=stoll((s.substr(v[a],v[a+1]-v[a])));
    }
    //sum+=atoi((s.substr(v[v.size()-1],s.size()-v[v.size()-1])).c_str());
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] a = new int[3][3];
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                a[i][j] = sc.nextInt();
        int _1 = a[0][1]+a[0][2]+a[1][2];
        int _2 = a[1][0]+a[2][0]+a[2][1];
        int _3 = a[0][0]+a[1][1]+a[2][2];
        if(_1+_2==2*_3) {
            System.out.println("Yes");
        }
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 21972
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 100000
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;

  int A[MAX_N];
  int pos1;
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 1)
      pos1 = i;
  }

  int Ans = 0;
  if (N <= K) {
    Ans = 1;
  } else {
    int lp = pos1;
    while (lp > 0) {
      Ans++;
      lp -= (K - 1);
    }
    int rp = pos1 + abs(lp);
    while (rp < (N - 1)) {
      Ans++;
      rp += (K - 1);
    }
  }
  cout << Ans << endl;
  return 0;
}

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

int x[50], y[50];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  map<pair<int,int>,int> count;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < n; b++) {
      int dx = x[a]-x[b], dy = y[a]-y[b];
      count[{dx,dy}]++;
    }
  }
  int ans = n;
  for (auto p : count) {
    if (p.first.first || p.first.second)
      ans = min(ans, n-p.second);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a, b, i, j;
	while (1) {
		cin >> a >> b;
		if (a == 0 && b == 0) { break; }
		else {
			for (i = 1;i <= b;i++) { printf("#"); }
			printf("\n");
			for (j = 2;j <= a-1;j++) {
				printf("#");
				{ for (i = 2;i <= b-1;i++) { printf("."); }
				printf("#\n");
				}
			}
			for (i = 1;i <= b;i++) { printf("#"); }
			printf("\n");
			printf("\n");
		}
	}
		return 0;
	
}


Measured memory_bytes: 3020
N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for i in range(N):
    #B[i]より小さいAのインデックスを求める
    ok = -1#B[i]より小さい
    ng = N#B[i]より大きい
    while ng-ok>1:#
        mid = (ok + ng)//2
        if A[mid]<B[i]:
            ok = mid
        else:
            ng = mid
    
    #B[i]より大きいCのインデックスを求める
    ok2 = N
    ng2 = -1
    while ok2-ng2>1:
        mid2 = (ok2+ng2)//2
        if C[mid2] > B[i]:
            ok2 = mid2
        else:
            ng2 = mid2
    
    ans += (ok+1)*(N-ok2)

print(ans)

Measured memory_bytes: 105600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N),b(N),c(N);
    for(int i=0;i<N;i++) cin >> a.at(i) >> b.at(i) >> c.at(i);

    int dp[3][N];
    dp[0][0] = a.at(0);
    dp[1][0] = b.at(0);
    dp[2][0] = c.at(0);

    for(int i=1;i<N;i++){
        dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a.at(i);
        dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + b.at(i);
        dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + c.at(i);
    }

    int ans  = max(dp[0][N-1],max(dp[1][N-1],dp[2][N-1]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5588
/* x x x x x */
//var input = "1 1 0 1 1";

function main(input){
  input = input.trim();
  var list = input.split(" ");
  for(var i=0; i<list.length; i++){
    if(list[i]==0){console.log(i+1);}
  }
}
//main(input);
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29680
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
int arr[N];
int f(int x,int y){
	int s=1;
	while(y){
		if(y%2) s*=x;
		x*=x;
		y/=2;
	}return s;
}
signed main(){
	int n;int ans=0;cin>>n;
	int cnt=0;
	if(n==1) {
		cout<<"1";return 0;
	}
	if(n==2){
		cout<<"3";return 0;
	}
	while(n!=0){
		n/=2;
		ans+=f(2,cnt);cnt++;
	}cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
tn = [None] * n
for i in range(n):
    tn[i] = (int(input()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b


result = 1
for t in tn:
    result = lcm(result, t)
2

print(result)



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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

ll prime[1000];

void fact(int n){
	for(int i=2;i<=n;i++){
		if(n%i==0){
			prime[i]++;
			n/=i;
			i--;
		}
	}
}

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

	ll ret = 1;
	FOR(i, 2, n+1) fact(i);
	FOR(i, 2, n+1) {
		ret *= (prime[i]+1);
		ret %= MOD;
	}

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int N,M;
int main(){
	// debug;
	ios;

	cin>>N>>M;
	if(N&1){
		for(int i = 1;i<=M;i++){
			cout<<i<<" "<<N-i+1<<'\n';
		}
	}else{
		int mid = N/2;
		for(int i = 1;i<=min(M,mid/2);i++){
			cout<<i<<" "<<mid-i+1<<'\n';
		}
		M -= min(M,mid/2);
		for(int i = 1;i<=M;i++){
			cout<<i+mid<<" "<<N-i<<'\n';
		}
	}

	return 0;
}


Measured memory_bytes: 3608
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, x, y = LI()
G = [[] for _ in range(n)]
ans = [0] * (n - 1)
for i in range(n - 1):
    G[i] += [i + 1]
    G[i + 1] += [i]

for j in range(n):
    q = [j]
    par = [-1] * n
    dist = [-1] * n
    dist[j] = 0
    while q:
        u = q.pop()
        for v in G[u]:
            if dist[v] == -1:
                dist[v] = dist[u] + 1
                q += [v]
    flag = [0] * n
    q2 = [x - 1, y - 1]
    dist[x - 1] = min(dist[x - 1], dist[y - 1] + 1)
    dist[y - 1] = min(dist[y - 1], dist[x - 1] + 1)
    while q2:
        a = q2.pop()
        for b in G[a]:
            if dist[a] + 1 < dist[b]:
                dist[b] = dist[a] + 1
                q2 += [b]

    for k in range(n):
        if k == j: 
            continue
        else:
            ans[dist[k] - 1] += 1


for l in ans:
    print(l // 2)





Measured memory_bytes: 54492
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,count;
  cin >> N >> X;
  vector<int> m_i(N);
  for(int i=0;i<N;i++){
      cin >> m_i.at(i);
  }
  sort(m_i.begin(), m_i.end());
  X = X - accumulate(m_i.begin(), m_i.end(), 0);
  count = N + X/m_i.at(0);
  cout <<  count << endl;
}

Measured memory_bytes: 256
//https://www.slideshare.net/hcpc_hokudai/binary-indexed-tree
//http://hos.ac/slides/20140319_bit.pdf
#include<iostream>
#include<vector>
#include<functional>
using namespace std;


//x の最も下の立っているビットは，x & -x で取り 出せる
template <class T> class BIT{
    private:
    vector<T> array;
    const int n;
    
    public:
    //constractor
    BIT(int _n) : array(_n + 1, 0), n(_n){}
    
    //sum [0,i]
    T sum(int i){
        T s = 0;
        while(i > 0){
            s += array[i];
            i -= i & -i;
        }
        return s;
    }

    //sum [i,j]
    T sum(int i, int j){
        T ret_i = sum(i -1);
        T ret_j = sum(j);
        return ret_j - ret_i;
    }

    // 1-index
    void add(int i, T x){
        while(i <= n){
            array[i] += x;
            i += i & -i;
        }
    }
};


// 問題例
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp


int main(){
    int n, q; cin >> n >> q;
    BIT<int> bit(n);
    for(int i=0; i<q; ++i){
        int c, x, y;
        cin >> c >> x >> y;

        if(c == 0){
            bit.add(x, y);
        }else{
            cout << bit.sum(x, y) << endl;
        }
    }
}


Measured memory_bytes: 3132
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
int diff(string &s1,string &s2)
{
    int cnt=0;
    for(int i=0;i<s1.size();i++)
    if(s1[i]!=s2[i]) cnt++;
    return cnt;
}
void sol(void)
{
string a,b;
cin>>a>>b;
int mi=3000;
for(int i=0;i<=a.size()-b.size();i++)
{
    string t=a.substr(i,b.size());
    mi=min(mi,diff(t,b));
}
cout<<mi;
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	string A,B,C; cin>>A>>B>>C;

	int count = 0;
	rpz(i,N){
		char a,b,c; a=A[i];b=B[i];c=C[i];
		if(a!=b && b!=c && c!=a) count += 2;
		else if(a==b && b==c) count += 0;
		else if(a==b || a==c || b==c) count += 1;
	}

	ote(count);
}


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


int main(){
  int n,m;cin>>n>>m;
  int a[n],b[n],c[m],d[m];
  rep(i,n)cin>>a[i]>>b[i];
  rep(i,m)cin>>c[i]>>d[i];
  int ans;
  rep(i,n){
    int mn=1e9;
    rep(j,m){
      int dst=abs(c[j]-a[i])+abs(d[j]-b[i]);
      if(dst<mn){
        mn=dst;
        ans=j+1;
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
/*input
5
24 11 8 3 16
*/

#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>;

const int M = 1e6+5;
int p[M];

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  rep(i, n) {
    bool ok = true;
    if (p[a[i]] == 0) {
      ans++;
      p[a[i]] = -1;
      for (int j = a[i]*2; j < M; j += a[i]) {
        p[j] = 1;
      }
    }
    else if (p[a[i]] == -1) {
      ans--;
      p[a[i]] = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7948
n, m = map(int, input().split(" "))


def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = sorted(list(set(table)))
    return table


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


s = set(divisor(n)).intersection(set(divisor(m)))

ans = 1
for ss in s:
    if len(prime_factorize(ss)) == 1:
        ans += 1

print(ans)

Measured memory_bytes: 10948
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
ll mod=1e9+7;
pair<ll,ll> dfs(int s,vector<int> graph[],vector<bool> &visited)
{
    visited[s]=1;
    pair<ll,ll> pr={1,1};
    for(int v:graph[s])
    {
        if(!visited[v])
        {
            pair<ll,ll> pr1=dfs(v,graph,visited);
            pr.first*=pr1.second;
            pr.first%=mod;
            pr.second*=(pr1.second+pr1.first);
            pr.second%=mod;
        }
    }
    return pr;
}
int main()
{
    int n;
    cin>>n;
    vector<int> graph[n+1];
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<bool> visited(n+1,false);
    pair<ll,ll> pr=dfs(1,graph,visited);
    cout<<(pr.first+pr.second)%mod;
}

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

int main(){

long long x;
cin>>x;

int five_hund = x/500;
int remain = x - (500*five_hund);
int five = remain/5;

int ans = 1000*five_hund + 5*five;
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
X, Y= map(int,input().split())

if Y < 2 *X:
    print('No')
elif Y%2 != 0:
    print('No')
else:
    if (4*X-Y)%2 == 0 and (4*X-Y) >= 0:
        print('Yes')
    else:
        print('No')   

Measured memory_bytes: 9208
N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
r = (N//min([a,b,c,d,e]))+4
if N%min([a,b,c,d,e]) != 0:
    print(r+1)
else:
    print(r)



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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	int x, y, z;
	int ans = 0;
	cin >> x >> y >> z;
	ans = x / (y + z);
	if(x % (y+z) < z) ans--;
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 200001

int cnt1[MAX];
int cnt2[MAX];

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

    int n;
    cin >> n;
    vector <int> even , odd;
    int v;
    for (int i = 0; i < n; i++) {
        cin >> v;
        if (i & 1) {
            odd.pb(v);
        }
        else {
            even.pb(v);
        }
    }
    set <int> ss;
    for (auto it : even) {
        cnt1[it]++;
        ss.insert(it);
    }
    vector <PII> vec1 , vec2;
    for (auto i : ss) {
        vec1.pb({cnt1[i] , i});
    }
    int f = ss.size();
    ss.clear();
    for (auto it : odd) {
        cnt2[it]++;
        ss.insert(it);
    }
    for (auto i : ss) {
        vec2.pb({cnt2[i] , i});
    }
    sort(allr(vec1));
    sort(allr(vec2));
    int s = ss.size();
    int m = n / 2;
    if (f == 1 && s == 1 && (vec1[0].second) == (vec2[0].second)) {
        cout << n / 2 << endl;
        return 0;
    }
    else if (f == 1) {
        v = vec1[0].second;
        for (auto it : vec2) {
            if (it.second != v) {
                cout << (m - it.first) + (m - vec1[0].first);
                return 0;
            }
        }
    }
    else if (s == 1) {
        v = (vec2[0].second);
        for (auto it : vec1) {
            if (it.first != v) {
                cout << (m - it.first) + (m - (vec2[0].first));
                return 0;
            }
        }
    }
    else {
        if ((vec1[0].second) != (vec2[0].second)) {
            cout << (m - (vec1[0].first)) + (m - (vec2[0].first)) << endl;
        }
        else {
            auto it = vec2.begin();
            it++;
            int ans1 = (m - (vec1[0].first)) + (m - vec2[1].first);
            it = vec1.begin();
            int ans2 = (m - vec1[1].first) + (m - (vec2[0].first));
            cout << min(ans1 , ans2) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4984
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int z;
  for(;cin>>z,z;)
    {
      int ans=0;
      for(int x=1;x*x*x<=z*z*z;x++)
	for(int y=1;x*x*x+y*y*y<=z*z*z;y++)
	  {
	    ans=max(ans,x*x*x+y*y*y);
	  }

      cout<<z*z*z-ans<<endl;
    }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N,K;
    cin>>N>>K;
    int ans=0;
    if(K%2==1){
        int n=N/K;
        ans=n*n*n;
    }else{
        int n=N/K;
        ans=n*n*n;
        int co=0;
        int x=K/2;
        while(true){
            int y=x*(co*2+1);
            
            if(y>N) break;
            co++;
        }
        ans+=(co*co*co);
    }
    cout << ans << endl;



}


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

typedef pair <int, int> ii;

int n, l;
vector <ii> res;

int main()
{
    scanf("%d %d", &n, &l);
    int my = (n - 1) * (n - 2) / 2;
    if (my < l) { printf("-1\n"); return 0; }
    for (int i = 2; i <= n; i++)
        res.push_back(ii(1, i));
    for (int i = 2; i <= n; i++)
        for (int j = i + 1; j <= n && my > l; j++) {
            res.push_back(ii(i, j));
            my--;
        }
    printf("%d\n", int(res.size()));
    for (int i = 0; i < res.size(); i++)
        printf("%d %d\n", res[i].first, res[i].second);
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int rc = 0;
		int lz = 0;
		for(; scanner.hasNext();)
		{
			String str = scanner.next();
			String[] s = str.split(",");
			
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			if(a*a + b*b == c*c)
			{
				rc ++;
			}
			else if(a>=c && b>=c)
			{
				lz ++;
			}
		}
		
		System.out.println(rc);
		System.out.println(lz);
	}
}

Measured memory_bytes: 26068
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

  int main() {
    debug();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
  
    float x=ceil(n/1.08);

    if(floor(x*1.08)==n){
    	cout<<x<<endl;
    }else{
    	cout<<":("<<endl;
    }

    return 0;
  }

Measured memory_bytes: 3800
#include <iostream>
 
using namespace std;
 
typedef pair<int,string> P;
 
int main(){
    int n,q;
    P p[50];
 
    cin >> n >> q;
    for(int i = 0 ; i < n ; i++){
	cin >> p[i].first >> p[i].second;
    }
 
    string ans = "kogakubu10gokan";
    int t = 0;
    for(int i = 0 ; i < n ; i++){
	if(q < p[i].first){
	    t++;
	    cout << ans << endl;
	    break;
	}
	ans = p[i].second;
    }
    if(!t) cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define mdsaqib std::ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
using namespace std;

signed main(){
    mdsaqib;
    int n,k;
    cin >> n >> k;
    vector <int> A(n),B(n);
    for(auto& a:A)cin >> a;
    for(auto& a:B)cin >> a;
    int ans=0;
    vector <int> X(n);
    for(int i=0;i<n;i++){
        vector <int> V(n,-1);
        int temp=0;
        int mx=B[A[i]-1];
        int tot=0;
        int pos=i;
        int kk=k;
        while(kk--){
            if(V[pos]>-1)break;
            //cout << pos<<" ";
            V[pos]=pos;
            pos=A[pos]-1;
            tot+=B[pos];
            mx=max(mx,tot);
            temp++;
        }
        //cout << endl;
        if(tot<=0){
            X[i]=mx;
        }
        else if(temp==k){
            X[i]=mx;
        }
        else{
            int zz=k/temp;
            kk=k-zz*temp;
            int mxx=max(mx,(zz-1)*tot+mx);
            mx=zz*tot;
            tot=0;
            pos=i;
            while(kk--){
                pos=A[pos]-1;
                tot+=B[pos];
                mxx=max(mxx,mx+tot);
            }
            X[i]=mxx;
        }
    }
    sort(all(X));
    cout << X[n-1];
    // for(int i=0;i<n;i++){
    //     cout << X[i] << " ";
    // }
}

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

//const int max_int = int(1e6 + 13);

int main() {
	//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << char(s1[0] - 'a' + 'A');
	cout << char(s2[0] - 'a' + 'A');
	cout << char(s3[0] - 'a' + 'A');
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	int A, B;
	cin >> N;
	int L = 1, R = 1;
	int S = 2;

	rep(i, 0, N)
	{
		cin >> A >> B;
		int ts = INF;
		int tl, tr;
		int l, r;
		l = (L + A - 1) / A * A;
		r = l / A * B;
		if (L <= l && R <= r)
		{
			if (chmin(ts, l + r))
			{
				tl = l, tr = r;
			}
		}
		r = (R + B - 1) / B * B;
		l = r / B * A;
		if (L <= l && R <= r)
		{
			if (chmin(ts, l + r))
			{
				tl = l, tr = r;
			}
		}
		R = tr, L = tl;
	}

	cout << L + R << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())
l = ''
r = ''
countReverse = 0
for operation in range(q):
    t = input().split()
    if int(t[0]) == 1:
        countReverse += 1
    if int(t[0]) == 2:
        if int(t[1]) == 1:
            if countReverse % 2 == 0:
                l = t[2] + l
            else:
                r = r + t[2]
        else:
            if countReverse % 2 == 0:
                r = r + t[2]
            else:
                l = t[2] + l
if countReverse % 2 == 0:
    s = l + s + r
else:
    s = s[::-1]
    l = l[::-1]
    r = r[::-1]
    s = r + s + l
print(s)

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for(int i=0; i<N; i++) if(S.substr(i, 3) == "ABC") ans++;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int a, b, q;
    cin >> a >> b >> q;
    set<ll> tera, jinja;
    for (int i = 0; i < a; i++)
    {
        ll s;
        cin >> s;
        jinja.insert(s);
    }
    for (int i = 0; i < b; i++)
    {
        ll s;
        cin >> s;
        tera.insert(s);
    }
    while (q--)
    {
        ll x;
        cin >> x;
        ll ret = 1e15;
        {
            auto itr1 = jinja.upper_bound(x);
            auto itr2 = tera.upper_bound(x);
            if (itr1 != jinja.end() && itr2 != tera.end())
                ret = min(ret, max(*itr1, *itr2) - x);
        }
        {
            auto itr1 = jinja.upper_bound(x);
            auto itr2 = tera.upper_bound(x);
            if (itr1 != jinja.begin() && itr2 != tera.begin())
            {
                itr1--;
                itr2--;
                ret = min(ret, -min(*itr1, *itr2) + x);
            }
        }
        {
            auto itr1 = jinja.upper_bound(x);
            auto itr2 = tera.upper_bound(x);
            if (itr1 != jinja.begin() && itr2 != tera.end())
            {
                itr1--;
                ret = min(ret, *itr2 - *itr1 + min(*itr2 - x, x - *itr1));
            }
        }
        {
            auto itr1 = jinja.upper_bound(x);
            auto itr2 = tera.upper_bound(x);
            if (itr1 != jinja.end() && itr2 != tera.begin())
            {
                itr2--;
                ret = min(ret, *itr1 - *itr2 + min(*itr1 - x, x - *itr2));
            }
        }
        cout << ret << endl;
    }
}


Measured memory_bytes: 10752
import Data.Maybe

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  s <- getLine
  t <- getLine
  print $ fromMaybe (-1) $ solve n m s t

solve :: Int -> Int -> String -> String -> Maybe Int
solve n m s t = if b then Just l else Nothing
  where
    l = lcm n m
    n' = l `div` n
    m' = l `div` m
    l' = lcm n' m'
    b = all (\(i,j) -> s !! i == t !! j) [(p`div`n',p`div`m') | x <- [0..(l`div`l'-1)], let p = x*l']


Measured memory_bytes: 9596
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){
  int x,y;
  tie(x,y) = frm;
  set<pii> se;
  if(x-1 >= 0)se.insert(pii(x-1,y));
  if(x+1 < n)se.insert(pii(x+1,y));
  if(y-1 >= 0)se.insert(pii(x,y-1));
  if(y+1 < m)se.insert(pii(x,y+1));
  for(auto t:se){
    int tx,ty;
    tie(tx,ty) = t;
    if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){
      table.at(tx).at(ty) = table.at(x).at(y) + 1;
      ans = max(ans,table.at(tx).at(ty));
      hukasa(s,table,ans,t,n,m);
      table.at(tx).at(ty) = -1;
    }
  }
}
void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(pii(cost.at(frm),frm));
  vector<bool> kakutei(n,false);
  while(!q.empty()){
    pii now = q.top();
    q.pop();
    int n1,n2;
    tie(n1,n2) = now;
    if(kakutei.at(n2))continue;
    kakutei.at(n2) = true;
    for(auto t:g.at(n2)){
      int tx,ty;
      tie(tx,ty) = t;
      if(cost.at(tx) > n1 + ty){
        cost.at(tx) = n1 + ty;
        q.push(pii(cost.at(tx),tx));
      }
    }
  }
}

int main(){
  int n;
  cin >> n;
  if(n == 1)cout << 0 << endl;
  else{
    long long ans = ruizyou(10,n);
    ans -= ruizyou(9,n) * 2;
    ans += ruizyou(8,n);
    ans %= MOD;
    if(ans < 0)ans += MOD;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

  ll n,ans=0;
  cin>>n;

  for(int i=1;i<=n;i++)
  {
    for(int j=2;j<=5;j++)
    {
      long long y = pow(i,j);

      if(y<=n) ans = max(ans,y);
    }
  }

  cout<<ans<<endl;

 return 0;
 }


Measured memory_bytes: 3888
#include<iostream>
#include<string>

using namespace std;

int main()
{
int n;cin>>n;
string s,t;cin>>s>>t;
int ans=n*2;
for(int i=1;i<=n;i++)
{
bool flag=true;
for(int j=i;j<=n;j++)
{
if(s[j-1]!=t[j-i+1-1])
{
flag=false;
break;
}
}
if(flag)
{
ans=n+i-1;
break;
}
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,ma,mb;
	int A[45];
	int B[45];
	int C[45];
	int dp[45][405][405];
	int INF=1000000;
	
	cin>>n>>ma>>mb;
	for(int i=0;i<n;i++)cin>>A[i]>>B[i]>>C[i];
	
	for(int i=0;i<=n;i++){
		for(int a=0;a<405;a++){
			for(int b=0;b<405;b++)
				dp[i][a][b]=INF;
		}
	}
	
	dp[0][0][0]=0;
	for(int i=0;i<=n-1;i++){
		for(int a=0;a<405;a++){
			for(int b=0;b<405;b++){
				dp[i+1][a][b]=min(dp[i+1][a][b],dp[i][a][b]);
				dp[i+1][a+A[i]][b+B[i]]
				=min(dp[i+1][a+A[i]][b+B[i]],dp[i][a][b]+C[i]);
			}
		}
	}
	int ans=INF;
	
	for(int a=1;a<405;a++){
		for(int b=1;b<405;b++){
			if(a*mb==b*ma){
				ans=min(ans,dp[n][a][b]);
				//cout<<a<<b<<" "<<ans<<endl;
				
			}
		}
	}
		
	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;
	
}


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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  if (B <= A) {
    cout << "delicious" << endl;
  } else if (B <= A + X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }

  for(int i = 0; i < n - k; ++i)
  {
    cout << (a[i] < a[i + k] ? "Yes" : "No") << endl;
  }

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3988
// include stdc++.h slows down compilation much.
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;

#define FAIL_RETURN \
do\
{\
    printf("-1\n");\
    return 0;\
} while(0);

ll solve(const string &s, int m)
{
    int res[2] = {0, 0};
    int lastChanged[2] = {-1, -1};
    int i;
    for (i = 1; i < (int)s.size(); i++)
    {
        if (s[i] == s[i - 1])
        {
            lastChanged[0] = i;
            res[0]++;
            i++;
        }
    }

    res[1] = 1;
    lastChanged[1] = 0;
    for (i = 2; i < (int)s.size(); i++)
    {
        if (s[i] == s[i - 1])
        {
            lastChanged[1] = i;
            res[1]++;
            i++;
        }
    }


    ll ans = 1e15;
    if (s[0] != s[s.size() - 1] || lastChanged[0] == s.size() - 1) // 000000
    {
        ans = min(ans, (ll)m * res[0]);
    }
    else if (lastChanged[1] != s.size() - 1) // 01111111
    {
        ans = min(ans, res[0] + (ll)(m - 1) * res[1]);
    }
    else // 01010101
    {
        ll cur = 0;
        if (m & 1)
        {
            cur = res[0];
            m--;
        }

        cur += (ll)m / 2 * (res[0] + res[1]);
        ans = min(ans, cur);
    }

    return ans;
}

int main()
{
	// USE_IOSTREAM;
	#ifndef ONLINE_JUDGE
	//freopen("1.txt", "r", stdin);
	#endif

    int m;
    string s;
    cin >> s >> m;

    ll ans = solve(s, m);
    for (int i = 0; i < s.size() / 2; i++)
    {
        int idx = s.size() - 1 - i;
        swap(s[i], s[idx]);
    }
    ll res = solve(s, m);

    ans = min(ans, res);
	
    cout << ans << endl;
	
	return 0;
}


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


int main() {
	int n, a;
	cin >> n >> a;
	int x = n % 500;

	if ((x - a) <= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))

b=[a[i] for i in range(0,n,2)]
c=[a[i] for i in range(1,n,2)]
from collections import Counter
xb=list(Counter(b).items())
xc=list(Counter(c).items())
xb=sorted(xb, key=lambda x:-x[1])
xc=sorted(xc, key=lambda x:-x[1])
ans=[]
if xb[0][0]==xc[0][0]:
    if len(xc)>1:
        ans.append(n//2-xb[0][1]-(-n//2)-xc[1][1])
    if len(xb)>1:
        ans.append(n//2-xb[1][1]-(-n//2)-xc[0][1])
    if len(xc)==1 and len(xb)==1:
        ans.append(n//2)
else:
    ans.append(n//2-xb[0][1]-(-n//2)-xc[0][1])
print(min(ans))

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

using namespace std;

int main() {
  string S;

  cin>>S;

  int flag = 0;
  for(int i=0; i<4; i++) {
    if(S[i]==S[i+1]) {
      flag = 1;
    } else {

    }
  }

  if(flag==1) {
    cout<<"Bad"<<endl;
  } else {
    cout<<"Good"<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
#define Maxn 200010
int a[Maxn],l1[Maxn],l2[Maxn];
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		l1[i]=max(l1[i-1],a[i]);
	}
	for(register int i=n;i>=1;--i)l2[i]=max(l2[i+1],a[i]);
	for(register int i=1;i<=n;++i)printf("%d\n",max(l1[i-1],l2[i+1]));
	return 0;
}

Measured memory_bytes: 3968
import scala.io.StdIn._
object Main {
  def main(args:Array[String]) {
    val S = readLine()
    val T = readLine()
    var count = 0

    for(i <- 0 until S.size) {
      if(S(i) != T(i)) count += 1
    }
    println(count)
  }
}


Measured memory_bytes: 54872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	ll n, m;
	std::cin >> n >> m;
	std::string s;
	std::string t;
	std::cin >> s >> t;

	ll l = lcm(n, m);
	

	std::map<int, char> mp;

	// sについて
	for (ll i = 0; i < n; ++i) {
		mp[i * l / n] = s[i];
	}

	bool is_exist = true;

	// tについて矛盾がないか
	for (ll i = 0; i < m; ++i) {
		if (mp[i * l / m] == 0) mp[i * l / m] = t[i];
		else {
			if (mp[i * l / m] != t[i]) {
				is_exist = false;
				break;
			}
		}
	}

	if (is_exist) std::cout << l << std::endl;
	else std::cout << -1 << std::endl;

	return 0;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ma = max (a,c);
  int ans = min (b,d);
  if(ans-ma <=0){
    cout << 0 << endl;
  }
  else{
    cout <<ans -ma << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <list>

using namespace std;

//#define EPS (1e-10)
//
//struct Point{
//    Point(double _x = 0, double _y = 0){
//        x = _x;
//        y = _y;
//    }
//    double x;
//    double y;
//
//    Point operator + (Point p){
//        return Point(x + p.x, y+ p.y);
//    }
//
//    Point operator - (Point p){
//        return Point(x - p.x, y - p.y);
//    }
//
//    Point operator * (double a){
//        return Point(a * x, a * y);
//    }
//
//    Point operator / (double a){
//        return Point(x / a, y / a);
//    }
//
//    double abs(){
//        return sqrt(norm());
//    }
//
//    double norm(){
//        return x * x + y * y;
//    }
//
//    bool operator < (const Point &p) const{
//        return x!=p.x ? x < p.x : y < p.y;
//    }
//
//    bool operator == (const Point &p) const{
//        return fabs(x - p.x) && fabs(y - p.y) < EPS;
//    }
//
//};
//
//typedef Point Vector;
//
//double dot(Vector a, Vector b){
//    return a.x * b.x + a.y * b.y;
//}

int main() {

    bool isOk = true;

    string str;
    cin>>str;

    for(int i=0;i<str.length();i++){
        char ch = str[i];
        for(int j=0;j<str.length();j++){
            if(i!=j && ch == str[j]){
                isOk =false;
            }
        }
    }

    if(isOk){
        printf("yes");
    }else{
        printf("no");
    }

    return 0;

}

Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim s As String = NextString()

        For i As Integer = 0 To s.Length - 1
            If i Mod 2 = 0 Then
                Write(s(i))
            End If
        Next
        WriteLine()
    End Sub

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920