akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[100];
  int n;cin >> n;
  for(int j=0;j<n;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  
  bool ff = true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
	d[l].roll('R');
	for(int j=0;j<4;j++){
	  d[l].roll('N');
	  if(same(d[k],d[l])) f=true;
	}
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      if(f) ff=false;
    }
  }
  
  cout << (ff?"Yes":"No") << endl;
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    int N,Q; cin>>N>>Q;
    string s; cin>>s;
    s='-'+s+'+';
    vector<char> t(Q),d(Q);
    rep(i,Q){
        cin>>t.at(i)>>d.at(i);
    }
    int L=-1,R=N;
    while(R-L>1){
        int M=L+(R-L)/2,tmp=M;
        char place=s.at(tmp+1);
        rep(i,Q){
            if(t.at(i)==place){
                if(d.at(i)=='R'){
                    tmp++;
                    place=s.at(tmp+1);
                }else{
                    tmp--;
                    place=s.at(tmp+1);
                }
            }
        }
        if(tmp==-1){
            L=M;
        }else{
            R=M;
        }
    }
    int ans1=L;
    L=-1; R=N;
    while(R-L>1){
        int M=L+(R-L)/2,tmp=M;
        char place=s.at(tmp+1);
        rep(i,Q){
            if(t.at(i)==place){
                if(d.at(i)=='R'){
                    tmp++;
                    place=s.at(tmp+1);
                }else{
                    tmp--;
                    place=s.at(tmp+1);
                }
            }
        }
        if(tmp==N){
            R=M;
        }else{
            L=M;
        }
    }
    int ans2=L;
    cout<<ans2-ans1<<endl;
}

Measured memory_bytes: 896
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  numS = scanner.nextInt();//要素数
		int arrayS[] = new int[numS];
		
		for(int i = 0; i < numS; i ++ ){
			arrayS[i] = scanner.nextInt();
		}
		int  numT = scanner.nextInt();//要素数
		int arrayT[] = new int[numT];
		
		for(int i = 0; i < numT; i ++ ){
			arrayT[i] = scanner.nextInt();
		}
		
		LinearSearch(numS,arrayS,numT,arrayT);
		
		scanner.close();
	}
	
	public static void LinearSearch(int numS,int[] arrayS,int numT, int[] arrayT){ 
		int count = 0;
		int match = 0;
		int i;
		
		for(i = 0; i < numT; i ++ ){
			count = 0;
			while( count < numS ){
				if(arrayT[i] == arrayS[count]){
					match ++;
					break;
				}
				count ++;
			}
		}
		
		System.out.println(match);	
	}
}


Measured memory_bytes: 68000
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = 1123456789012;
LL N, K;
std::vector<LL>H, nums;
std::vector<std::vector<std::vector<LL>>>memo;

LL dp(LL i, LL j, LL k)
{
	if (j < 0) return inf;
	if (i == N) return 0;
	if (memo[i][j][k] != -1) return memo[i][j][k];
	LL res1 = dp(i + 1, j, H[i]) + std::max(nums[H[i] - 1] - (k == 0 ? 0 : nums[k - 1]), 0LL);
	LL res2 = dp(i + 1, j - 1, k);
	return memo[i][j][k] = std::min(res1, res2);
}

int main()
{
	in >> N >> K;
	H.resize(N);
	rep(i, N) in >> H[i];

	nums = H;
	std::sort(nums.begin(), nums.end());
	nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
	std::map<LL, LL>index;
	rep(i, nums.size()) index[nums[i]] = i + 1;
	rep(i, N) H[i] = index[H[i]];

	memo.resize(N, std::vector<std::vector<LL>>(K + 1, std::vector<LL>(N + 1, -1)));
	out << dp(0, K, 0) << std::endl;
}


Measured memory_bytes: 216192
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,m;
	int sum=0;
	cin>>n>>m; 
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+1,a+1+n,cmp);
	if(a[m]*4*m<sum)
	puts("No");
	else
	puts("Yes");
  return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

mod = 10**9+7

A = sorted(A)

bikkuri = [1]
for i in range(1,N+1):
    bikkuri.append((bikkuri[-1]*i)%mod)
bikkuri2 = [1]
for i in range(1,N+1):
    bikkuri2.append(pow(bikkuri[i],mod-2,mod))
    
def comb(n,r):
    if n<r:
        return 0
    else:
        return (bikkuri[n]*bikkuri2[n-r]*bikkuri2[r])%mod
    
ans = 0
for i in range(N):
    ans += A[i]*(comb(i,K-1)-comb(N-i-1,K-1))
    ans %= mod
print(ans)

Measured memory_bytes: 65704
program name
    implicit none
    integer(4):: n,k,i
    real(8),allocatable:: p(:),ans(:)
    real(8):: tot

    read*, n,k
    allocate(p(n), ans(n-k+1))
    read*, p(:)

    tot = sum(p(1:k))
    ans(1) = dble(tot+k)/dble(2)

    do i=2,n-k+1
        tot = tot - p(i-1) + p(i+k-1)
        ans(i) = dble(tot+k)/dble(2)
    end do

    print*, maxval(ans)
end program name

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
	return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int> &vec)
{
	for (auto &e : vec)
	{
		cout << e << " ";
	}
	cout << endl;
}

int func(long long A, long long B)
{
	// cout << fixed << setprecision(8);
	vector<int> v{1, 2, 3};
	v.erase(remove(v.begin(), v.end(), A), v.end());
	v.erase(remove(v.begin(), v.end(), B), v.end());
	cout << v[0] << endl;

	return 0;
}

int main()
{
	long long A;
	scanf("%lld", &A);
	long long B;
	scanf("%lld", &B);

	func(A, B);

	return 0;
}


Measured memory_bytes: 256
import math
a, b, c = map(int, input().split())
PI = 3.1415926535897932384
c = math.radians(c)
print('{:.5f}'.format(a * b * math.sin(c) / 2))
A = a - b * math.cos(c)
B = b * math.sin(c)
print('{:.5f}'.format(math.sqrt(A * A + B * B) + a + b))
print('{:.5f}'.format(B))



Measured memory_bytes: 5708
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> t(n);
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> t[i];
        sum += t[i];
    }
    int m; cin >> m;
    for(int i = 0; i < m; i++)
    {
        int p, x; cin >> p >> x;
        p--;
        cout << sum - t[p] + x << endl;
    }
    return 0;
}



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

using namespace std;

typedef long long int ll;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll d[n][n];
    int i,j;
    for(i=0,j=0;i<n;i++,j++)
        d[i][j]=a[i];
        for(int k=1;k<n;k++){
            for(i=0,j=k;j<n;i++,j++){
                d[i][j]=max(a[i]-d[i+1][j], a[j]-d[i][j-1]);
            }
        }
    cout<<d[0][n-1]<<endl;
}

Measured memory_bytes: 69888
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int N;

struct ST {
  ll v;
  int i;
};
bool operator<(const ST& a, const ST& b){
  return a.v < b.v;
}

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

  vector<ST> v;
  rep(i,N){
    ll x;
    cin >> x;
    v.push_back((ST){x,i});
  }
  sort(ALLOF(v));

  int ret = 0;
  rep(i,v.size()){
    if(i%2 != (v[i].i)%2) ret++;
  }

  cout << ret/2 << endl;
  
  
  return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#define N 2000
int A[N+1];
int main(void){
    int n,a,q,key,sum=0;
    int i,j;

    A[0]=1;
    scanf("%d",&n);
    for(i=0;i<n;i++){
	scanf("%d",&a);
	sum+=a;
	for(j=sum-a;j>=0;j--){
	    if(A[j]) A[j+a]=1;
	}
    }

    scanf("%d",&q);
    for(i=0;i<q;i++){
	scanf("%d",&key);
	if(A[key]) printf("yes\n");
	else printf("no\n");
    }

    return 0;
}

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

int main(){
  string s; cin >>s;
  ll ans = 0;
  int cnt = 0;
  int n = s.size();
  rep(i,n){
    if(s[i]=='B') cnt++;
    else ans += cnt;
  }
  cout << ans << endl;
  return 0; 
}

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

namespace AtcoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            var argNK = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();

            long N = argNK[0];
            long K = argNK[1];

            var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();

            

            for(long i = K; i < N; i++)
            {
                if(A[i] > A[i - K])
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }
    }
}


Measured memory_bytes: 47024
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi A(n);
  for(auto &a:A){
    cin>>a;
  }
  sort(ALL(A));
  ll ans = llINF;
  for(int i=0;i<=n-k;i++){
    ans = min(ans,A[i+k-1]-A[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main (void){
  char s[101];
  scanf("%s", s);
  int r = 0;
  int i;
  int n = strlen(s);
  for(i=0; i<n; i++){
    if (s[i] != s[n-1-i]){
      r++;
    }
  }
  printf("%d\n", r/2);
}


Measured memory_bytes: 128
n=int(input())
s=input()
if n%2==1:
  print('No')
else:
  s1=''
  s2=''
  for i in range(n):
    if i<n//2:
      s1+=s[i]
    else:
      s2+=s[i]
  if s1==s2:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3060
import collections
s = input()
sl = collections.Counter(s)
ans = len(s)
s_af = s
for c in sl.keys():
    s_af = s
    cnt = 0
    while s_af.count(c) != len(s_af):
        s_bf = s_af
        cnt +=1
        for i in range(len(s_bf)-1):
            if s_bf[i] ==c or s_bf[i+1]==c:
                if i ==0:
                    s_af = c
                else:
                    s_af += c
            else:
                if i == 0:
                    s_af = s_bf[i]
                else:
                    s_af += s_bf[i]
    ans = min(ans,cnt)

    
print(ans)


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

int main() {
  ll ans = 0,n,k,mod = 1e9+7;
  cin >> n >> k;
  for(ll i = k;i <= n+1;i++){
    ll sum = i*n-i*(i-1)+1;
    sum %= mod;
    ans += sum;
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(){
int a,b,c,max;

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

if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
printf("YES");
else
printf("NO");
}

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

int main(){
	int h,n;	cin>>h>>n;
	int sum=0;
	for(int i=0;i<n;i++){
		int a;	cin>>a;
		sum+=a;
	}
	if(h<=sum)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K;
  cin >> N >> K;

  vector<int> t(N), d(N);
  REP(i, N){
    cin >> t[i] >> d[i];
    t[i]--;
  }
  

  priority_queue<int> q;
  priority_queue<int, vector<int>, greater<int>> eat;
  vector<pair<int, int>> MAX(N, {-INF, -1});
  vector<bool> used(N, false);

  int ret = 0;
  REP(i, N){
    if(MAX[t[i]].first < d[i]){
      if(MAX[t[i]].second != -1) used[MAX[t[i]].second] = false;
      if(MAX[t[i]].first != -INF) ret -= MAX[t[i]].first;
      ret += d[i];
      MAX[t[i]] = {d[i], i};
      used[MAX[t[i]].second] = true;
    }
  }

  int cnt = 0;
  REP(i, N){
    if(used[i]){
      cnt++;
      eat.push(d[i]);
    }else q.push(d[i]);
  }

  while((int)eat.size() > K){
    cnt--;
    ret -= eat.top(); eat.pop();
  }
  REP(i, K-eat.size()){
    ret += q.top(); q.pop();
  }

  int ans = ret+cnt*cnt;
  while(!eat.empty() && !q.empty()){
    cnt--;
    ret -= eat.top(); eat.pop();
    ret += q.top();   q.pop();

    chmax(ans, ret+cnt*cnt);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);

    set<string> st;
    rep(i, n) st.insert(s.at(i));

    cout << int(st.size()) << endl;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll n, k, sum = 0 ;
    cin >> n >> k ;
    ll arr[n + 5] ;
    for (int i = 0; i < n; i++) {
        cin >> arr[i] ;
    }
    sort(arr, arr + n) ;
    for (int i = 0; i < k; i++) {
        sum += arr[i] ;
    }
    cout << sum ;

    return 0 ;
}


Measured memory_bytes: 3604
#include<iostream>
#include <cfenv>
#include <vector>   
#include <cmath>
using namespace std;
int V[20],C[20];
int main()
{
  int N;
  cin >> N;
  for(int i=0;i<N;++i)
    cin >>V[i];
  for(int i=0;i<N;++i)
    cin >> C[i];
  
  int sum=0;
  for(int i=0;i<N;++i)
  {
   	int a = V[i] - C[i];
    if(a>0)
      sum+=a;
  }
  cout << sum << endl;
  return 0;
}

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

int main(){    
  int i;
  cin >> i;
  if(i == 25) cout << "Christmas" << endl;
  else if(i == 24) cout << "Christmas Eve" << endl;
  else if(i == 23) cout << "Christmas Eve Eve" << endl;
  else if(i == 22) cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#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>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = -1;
    int j = 1;
    int last = -1;
    for (int i = 0; i < N; i++)
    {
        if (A[i] == j)
        {
            ans = i + 1 - j;
            j++;
            last = i;
            continue;
        }
        if (i == N - 1 && j > 1)
        {
            ans += (i - last);
        }
        
    }
    
    cout << ans << endl;

  return 0;
}


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

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int fnGcdGet(int nNumA, int nNumB)
{
  int nDividend = max(nNumA, nNumB);
  int nDivisor  = min(nNumA, nNumB);

  while (nDividend % nDivisor != 0)
  {
    int nRemain = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nRemain;
  }
  return nDivisor;
}

int fnMaxGcd(const vector<int>& cnrvnNum)
{
  vector<int> vnLeftGcd(cnrvnNum.size());
  vector<int> vnRigtGcd(cnrvnNum.size());
  vector<int> vnRemnGcd(cnrvnNum.size());

  vnLeftGcd[0] = cnrvnNum[0];
  
  for (int i = 1; i < cnrvnNum.size(); i++)
    vnLeftGcd[i] = fnGcdGet(vnLeftGcd[i - 1], cnrvnNum[i]);
  
  vnRigtGcd[cnrvnNum.size() - 1] = cnrvnNum[cnrvnNum.size() - 1];

  for (int i = cnrvnNum.size() - 2; i >= 0; i--)
    vnRigtGcd[i] = fnGcdGet(vnRigtGcd[i + 1], cnrvnNum[i]);

  for (int i = 0; i < cnrvnNum.size(); i++)
    if (i == 0)
      vnRemnGcd[i] = vnRigtGcd[i + 1];
    else if (i == cnrvnNum.size() - 1)
      vnRemnGcd[i] = vnLeftGcd[i - 1];
    else
      vnRemnGcd[i] = fnGcdGet(vnLeftGcd[i - 1], vnRigtGcd[i + 1]);
  
  auto it = max_element(begin(vnRemnGcd), end(vnRemnGcd));
  return *it;
}
 
int main()
{
  vector<int> vnNum;

  fnInput(vnNum);
  cout << fnMaxGcd(vnNum) << endl;

  return 0;
}

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

int gcd(int x, int y){
	if(y == 0){
		return x;
	}
	return gcd(y, x%y);
}

int main(){
	while(true){
		int a,b;
		cin >> a >> b;
		if(cin.eof()){
			break;
		}
		int GCD = gcd(a, b);
		cout << GCD << ' '<< a / GCD * b << endl;
	}
	return 0;
}


Measured memory_bytes: 1160
#include <stdio.h>
#define K_MAX 1000
int n,k,tiles[K_MAX][2];
int min(int x,int y){return(x<y)?x:y;}
void solve(void){
	int i = 0;
	int ans;
	while(i<k){
		ans=min(tiles[i][0],tiles[i][1])%3;
		if(!ans)ans=3;
		printf("%d\n",ans);
		i++;
	}
	return;
}
int main(void){
	int i=0;
	scanf("%d%d",&n,&k);
	while(i<k){
		scanf("%d%d",&tiles[i][0],&tiles[i][1]);
		if(tiles[i][0]>=n/2){
			tiles[i][0]=n-tiles[i][0]+1;
		}
		if(tiles[i][1]>=n/2){
			tiles[i][1]=n-tiles[i][1]+1;
		}
		i++;
	}
	solve();
	return 0;
}

Measured memory_bytes: 604
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

q = list(range(1, 10))
q = deque(q)

for _ in range(K):
	x = q.popleft()
	r = x%10
	if r > 0:
		q.append(10*x+(r-1))
	q.append(10*x+r)
	if r < 9:
		q.append(10*x+(r+1))
print(x)


Measured memory_bytes: 14164
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


x = int(input())
k = 0
while k*(k+1)//2 < x:
    k += 1
ans = k
print(ans)

Measured memory_bytes: 63064
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll bi[3][3];
    bool bb[3][3];
    ll n;
    rep(i,3){
        rep(j,3){
            cin>>bi[i][j];
            bb[i][j]=false;
        }
    }
    cin>>n;
    vector<ll> b(n);
    rep(i,n) cin>>b[i];
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(b[i]==bi[j][k]){
                    bb[j][k]=true;
                }
            }
        }
    }
    bool ans = false;
    if(bb[0][0]==true && bb[0][1]==true && bb[0][2]==true) ans = true;
    else if(bb[1][0]==true && bb[1][1]==true && bb[1][2]==true) ans = true;
    else if(bb[2][0]==true && bb[2][1]==true && bb[2][2]==true) ans = true;
    else if(bb[0][0]==true && bb[1][0]==true && bb[2][0]==true) ans = true;
    else if(bb[0][1]==true && bb[1][1]==true && bb[2][1]==true) ans = true;
    else if(bb[0][2]==true && bb[1][2]==true && bb[2][2]==true) ans = true;
    else if(bb[0][0]==true && bb[1][1]==true && bb[2][2]==true) ans = true;
    else if(bb[0][2]==true && bb[1][1]==true && bb[0][2]==true) ans = true;
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

const int LIM = 60000;

map<string, int> tone;

void init(){
    tone["C"]  = 0;
    tone["C#"] = 1;
    tone["D"]  = 2;
    tone["D#"] = 3;
    tone["E"]  = 4;
    tone["F"]  = 5;
    tone["F#"] = 6;
    tone["G"]  = 7;
    tone["G#"] = 8;
    tone["A"]  = 9;
    tone["A#"] = 10;
    tone["B"]  = 11;
}

int st[LIM+1], me[LIM+1];
int S, N, M;

bool dfs(int pos, int num){
    if(pos == N) return num == M;
    if(num >= M || pos >= N) return 0;
    if(me[num] == st[pos]) return dfs(pos+1, num+1);
    if(me[num] == (st[pos] + 1) % 12) return dfs(pos+2, num+1);
    if(pos > 0 && me[num] == (st[pos] + 11) % 12) return dfs(pos-1, num+1);
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    init();
    cin >> S;
    for(;S--;){
        cin >> N >> M;
        string str;
        for(int x = 0; x < N; x++){
            cin >> str;
            st[x] = tone[str];
        }
        for(int x = 0; x < M; x++){
            cin >> str;
            me[x] = tone[str];
        }
        reverse(st, st+N);
        reverse(me, me+M);
        bool res = false;
        res = dfs(0, 0) || dfs(1, 0);
        if(res){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n,k;
ll a[200005];

ll tot_cuts(ll len){
    ll tot=0;
    for (int i = 0; i < n; ++i)
    {
        if((a[i]%len)==0){
            tot = tot+(a[i]/len)-1;
        }
        else{
            ll x=a[i]/len;
            tot+=x;
        }
    }
    return tot;
}

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    cin>>n>>k;
    ll max1=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        max1=max(max1, a[i]);
    }

    ll start=1;
    ll end=max1;
    while(start<end){
        ll mid=(start+end)/2;
        if(tot_cuts(mid)<=k){
            end=mid;
        }
        else{
            start=mid+1;
        }
    }
    cout<<start;

    return 0;
}

Measured memory_bytes: 5108
#include<stdio.h>

int main(void)


{


 int a,b,d,r;


 double f=0;


 scanf("%d",&a);


 scanf("%d",&b);


 d=a/b;


 r=a%b;


 f=(double)a/(double)b;


 printf("%d %d %lf\n",d,r,f);


 return 0;


}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

ll modPow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n-1, p)) % p;
  ll t = modPow(a, n/2, p);
  return (t * t) % p;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
  
  ll n;
  cin >> n;
  ll k = n;
  string s;
  cin >> s;
  n += s.size();

  vector<ll> fact(n+1); //階乗
  vector<ll> fact_inv(n+1); //階乗の逆元
  fact[0] = 1;
  for (int i = 0; i < n; i++) fact[i+1] = (fact[i] * (i+1)) % MOD;
  fact_inv[n] = modPow(fact[n], MOD-2, MOD);
  for (int i = n-1; i >= 0; i--) fact_inv[i] = (fact_inv[i+1] * (i+1)) % MOD;

  auto comb = [&](ll n0, ll r) { //MODで
    return (((fact[n0] * fact_inv[n0-r]) % MOD) * fact_inv[r]) % MOD;
  };

  vector<ll> pows(n+1);
  pows[0] = 1;
  for (int i = 1; i <= n; i++) {
    pows[i] = (pows[i-1]*25) % MOD;
  }

  ll ans = modPow(26, n, MOD);
  for (int i = 0; i < n-k; i++) {
    //cout << ans << endl;
    ans -= comb(n, i) * pows[n-i];
    ans = (ans + MOD * MOD) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 51248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define bp  __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-14;
const int MOD = 1000000007;

int main()
{
    ARB
    int r;
    cin>>r;
    double ans=2*3.14*r;
    cout<<fixed<<setprecision(2)<<ans;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	bool ok = true;
	for(int i=0,x;i<n;++i){
		cin >> x;
		if(x%2 == 0 && x%3 != 0 && x%5 != 0)
			ok = false;
	}

	cout << (ok ? "APPROVED" : "DENIED") << '\n';

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

M1,D1 = inpl()
M2,D2 = inpl()

if M1 == M2:
    print(0)
else:
    print(1)


Measured memory_bytes: 4716
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define sz(A) int(A.size())
#define FIFO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(A) begin(A),end(A)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<pair<int,int>> vii;
map<ll, ll> dp;
ll A, B, C, D;
map<ll, int>vis;
ll maxi, fact;
ll dpp(ll num) {
	
	if(dp.find(num) != dp.end())return dp[num];
	if(vis.find(num) != vis.end())return maxi;
	//cout << num << " uwu\n";
	vis[num] = 1;
	if(num == 0)return 0;
	ll ans = LLONG_MAX;
	if(num < fact) {
		ans = min(ans, 1LL * num * D);
	}
	ans = min(ans, dpp(num/2) + (num%2) * D + A);
	ans = min(ans, dpp(num/2 + 1) + (2 - (num%2)) * D + A);
	ans = min(ans, dpp(num/3) + (num % 3) * D + B);
	ans = min(ans, dpp(num/3 + 1) + (3 - (num % 3)) * D + B);
	ans = min(ans, dpp(num/5) + (num % 5) * D + C);
	ans = min(ans, dpp(num/5 + 1) + (5 - (num % 5)) * D + C);
	return dp[num] = ans;
}
int main() {
	maxi = ll(1e14);
	
	int t;
	cin >> t;
	while(t--) {
		dp.clear();
		vis.clear();
		ll n;
		
		cin >> n >> A >> B >> C >> D;
		fact = ll(1e9);
		fact *= 14;
		fact /= D;
		cout << dpp(n) << "\n";
//		cout << dpp(12) << "\n";
	}
	return 0;
}


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

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

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

int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << endl;
  } else {
    cout << r + 100 * (10 - n) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define SZ size()

using namespace std;
typedef long long ll;

int in(){int a; scanf("%d", &a); return a;}
ll inll(){ll a; scanf("%lld", &a); return a;}

//--------------------------------------------------

const int MAX = 8e3 + 5;
const int INF = 0x3f3f3f3f;

string s;
int X, Y;
vector <int> xsteps, ysteps;


int memx[MAX][MAX];

bool dpx(int i, int curX) {

    if(i == xsteps.SZ) return curX == X;
    int &res = memx[i][curX];
    if(res != -1) return res;
    res = 0;
    res = dpx(i+1, curX + xsteps[i]) || dpx(i+1, curX - xsteps[i]);
    return res;
}

int memy[MAX][MAX];

bool dpy(int i, int curY) {

    if(i == ysteps.SZ) return curY == Y;
    int &res = memy[i][curY];
    if(res != -1) return res;
    res = 0;
    res = dpy(i+1, curY + ysteps[i]) || dpy(i+1, curY - ysteps[i]);
    return res;
}


int main(){

    memset(memx, -1, sizeof memx);
    memset(memy, -1, sizeof memy);

    cin >> s;
    s = s + 'T';

    X = in(), Y = in();

    int steps = 0;
    int turns = 0;
    int xstart = 0;

    for(int i=0; i<s.SZ; i++){

        if(s[i] == 'F') steps++;

        else {

            if(turns == 0) {
                xstart = steps;
            }

            else if(steps > 0) {
                if(turns % 2 == 0) xsteps.push_back(steps);
                else ysteps.push_back(steps);
            }

            turns++;
            steps = 0;
        }
    }

    if(dpx(0, xstart) && dpy(0, 0)) printf("Yes\n");
    else printf("No\n");

}



Measured memory_bytes: 500992
input_first = input()
input_second = input()

split_input_first = input_first.split()
split_input_second = input_second.split()

k = int(split_input_first[0])
n = int(split_input_first[1])

distance_list = []
for i in range(n):
    if i == n - 1:
        distance_list.append(k + int(split_input_second[0]) - int(split_input_second[n-1]))
    else:
        distance_list.append(int(split_input_second[i+1]) - int(split_input_second[i]))
distance_list = sorted(distance_list)

result = 0
for i in range(n):
    if i == n - 1:
        break
    else:
        result += distance_list[i]
print(result)

Measured memory_bytes: 21908
import std.algorithm;
import std.array;
import std.range;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;

alias FairyPos = Tuple!(int,int);

void main(){
    auto blue_num = readln.chomp.to!int;
    string[] blues;
    foreach(i; iota(0, blue_num)) {
        blues ~= readln.chomp;
    }
    auto red_num = readln.chomp.to!int;
    string[] reds;
    foreach(i; iota(0, red_num)) {
        reds ~= readln.chomp;
    }
    auto pluss = get_num_by_string(blues);
    // writeln(pluss);
    auto minus = get_num_by_string(reds);
    // writeln(minus);
    int[string] scores;
    foreach(str, num; pluss) {
        int minus_score = str in minus ? minus[str] : 0;
        scores[str] = pluss[str] - minus_score;
    }
    int max_num;
    foreach(score; scores) {
        max_num = score > max_num ? score : max_num;
    }
    max_num.writeln;
}

int[string] get_num_by_string(string[] raw){
    int[string] result;
    raw.each!((str){
        if(str in result){
            result[str]++;
        }else{
            result[str] = 1;
        }
    });
    return result;
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
long long n,m,h=0;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	cout<<min(n,m/2)+max(m-n*2,h)/4;

	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll get(ll l,ll r,ll x){
    return (r/x) - ((l-1)/x);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll lcm = c*d;
    lcm/=__gcd(c,d);
    ll num1 = get(a,b,c)+get(a,b,d)-get(a,b,lcm);
    num1=b-a+1-num1;
    cout<<num1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long int
int32_t main()
{   
	very_slow

      int k;
	  cin>>k;
	  vector<pair<int,int>>v;
	  for(int w=0;w<k;w++)
	  {  int x,y;
	    cin>>x>>y;
         v.push_back(make_pair(x,y));
	  }
	   
	   bool flag=false;
	   for(auto itr=v.begin();itr<v.end();)
	   {  int cnt=0;
		   if(itr->first==itr->second)
		   {
			   while(itr<v.end() && itr->first==itr->second)
			   {
				   cnt++;
				   itr++;
			   }
			   if(cnt>=3)
			   {
				   flag=true;
			   }
		   }
		   else
		   {
			   itr++;
		   }
	   } 
	   if(flag==true)
	   {
		   cout<<"Yes"<<endl;
	   }
	   else
	   {
		   cout<<"No"<<endl;
	   }

	return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll dp[51][51][2501];

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n, a;
	cin >> n >> a;

	vector<int> x;
	x.pb(0);
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		x.pb(t);
	}

	for(int i=1; i<=n; i++){
		dp[i-1][0][0] = 1;
		for(int k=1; k<=n; k++){
			for(int j=0; j<=2500; j++){
				if(j - x[i] >= 0){
					dp[i][k][j] = dp[i-1][k][j] + dp[i-1][k-1][j - x[i]];
				}else{
					dp[i][k][j] = dp[i-1][k][j];
				}
			}
		}
	}

	/*
	for(int i=1; i<=n; i++){
		for(int j=0; j<=50; j++){
			printf("%lld ", dp[i][j]);
		}
		puts("");
	}
	*/

	ll ans = 0;
	for(int i=1; i<=n; i++){
		ans += dp[n][i][a*i];
	}

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


Measured memory_bytes: 50048
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
    int a,b;cin>>a>>b;
    if(max(a,b)>8){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  char str[20];
  int i, n;

  scanf("%s", str);

  for (i = 0; i < 20; i++)
    if (str[i] == '\0') break;

  n = i;

  for (i = n - 1; i >= 0; i--)
    putchar(str[i]);
  putchar('\n');

  return 0;
}

Measured memory_bytes: 520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        int count = 1;
        while (true) {
            final String str = br.readLine();
            if (str.equals("0"))
                break;
            System.out.println(String.format("Case %d: %s", count, str));
            count++;
        }
    }
}

Measured memory_bytes: 55492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NMAX 3000
#define INF 1000000000

int a, b, c, d, e, f;
set<int> water, suger;
double concentration;

void solve() {
  int i, j;
  ll w, s, w_max, s_max;

  for (i = 0; i <= NMAX; i++) {
    for (j = 0; j <= NMAX; j++) {

      w = 100 * a * i + 100 * b * j;
      s = c * i + d * j;

      if (w <= f) {
        water.insert(w);
      }

      if (s <= f) {
        suger.insert(s);
      }
    }
  }

  concentration = -INF;
  w_max = 0;
  s_max = 0;

  for (auto p : water) {
    for (auto q : suger) {

      w = p;
      s = q;

      if (w == 0 && s == 0) {
        continue;
      }

      if (w + s <= f && s <= w / 100 * e) {
        if (concentration < (double)s / (double)(w + s)) {
          w_max = w;
          s_max = s;
          concentration = (double)s / (double)(w + s);
        }
      }
    }
  }

  cout << w_max + s_max << " " << s_max << "\n";

  return;
}

int main() {
  cin >> a >> b >> c >> d >> e >> f;

  solve();

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <atcoder/dsu>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, q;
    cin >> n >> q;
    atcoder::dsu d(n);
    while(q--){
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0){
            d.merge(u, v);
        }else{
            cout << d.same(u, v) << endl;
        }
    }

    return 0;
}


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

int N;
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    int ans = 1000000000000000;
    for (int i=1; i*i<=N; i++) {
        if (N%i==0) ans = min(ans, i-1+N/i-1);
    }
    cout << ans << endl;
}

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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
const ll M = 1000000007;
signed main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> D(k);
    cin>>D;
    while(1){
        ll f=1;
        for(ll d:D){
            ll a=n;
            while(a>0){
                if(a%10==d){
                    f=0;
                    break;
                }
                a/=10;
            }
            if(f==0)break;
        }
        if(f==0){
            n++;
        }else{
            cout<<n<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

int main()
{
    int x;
    int y;
    
    scanf("%2d%2d", &x, &y);
    

    if(x > 12 || x == 0){
        if(y > 12 || y == 0){
            printf("NA");
        }else{
            printf("YYMM");
        }
    }else{
        if(y > 12 || y == 0){
            printf("MMYY");
        }else{
            printf("AMBIGUOUS");
        }
        
    }

    return 0;
}

Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 3 "../../library/cumulative_sum.hpp"

template<class T>
struct CumulativeSum {
  vector<T> v;

  CumulativeSum(size_t n) : v(n+1) {};
  CumulativeSum(vector<T> v_) {
    v.resize(v_.size()+1);
    rep(i, v_.size())
      v[i+1] = v_[i];
  };

  void add(size_t i, T x) {
    v[i+1] += x;
  }

  // O(N)
  void build() {
    if (v.size() == 0) return;
    rep(i, v.size()-1)
      v[i+1] += v[i];
  }

  // O(1) sum [l, r]
  T sum(size_t l, size_t r) const {
    return l == 0 ? v[r+1] : v[r+1]-v[l];
  }

  // O(1) sum [0, r]
  T sum(size_t r) const {
    return v[r+1];
  }

  T& operator[](size_t i) {
    return v[i];
  }

  const T& operator[](size_t i) const {
    return v[i];
  }
};
#line 3 "d.cpp"

int main() {
  ll n;
  string s;
  cin >> n >> s;

  vector<CumulativeSum<ll>> cnt(3, CumulativeSum<ll>(n));
  string rgb = "RGB";
  rep(i, n) {
    rep(j, 3) {
      if (s[i] == rgb[j]) {
        cnt[j].add(i, 1);
      }
    }
  }

  rep(i, 3) {
    cnt[i].build();
  }

  auto f = [&rgb](char c) {
    rep(i, 3) {
      if (c == rgb[i]) {
        return i;
      }
    }
  };

  ll ans = 0;
  rep(i, n) {
    rep3(j, i+2, n) {
      if (s[i] == s[j]) {
        continue;
      }

      ll ind = 3 - f(s[i]) - f(s[j]);

      ll tmp = cnt[ind].sum(i+1, j-1);
      if ((j-i)%2 == 0 and s[(j+i)/2] == rgb[ind]) {
        tmp--;
      }

      ans += tmp;
    }
  }
  cout << ans << el;
}


Measured memory_bytes: 3752
N = int(input())
h = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
if N == 1:
    print(dp[1])
else:
    for i in range(2, N):
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])) 
    print(dp[-1])

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

int d[100000];
int main(){
	int k;scanf("%d",&k);
	priority_queue<P,vector<P>,greater<P>>que;
	memset(d,0x3f,sizeof(d));
	for(int i=1;i<10;i++){
		d[i%k]=min(d[i%k],i);
		que.push(P(i,i%k));
	}
	while(!que.empty()){
		P p=que.top();que.pop();
		if(d[p.second]!=p.first)continue;
		rep(i,10){
			if(d[(p.second*10+i)%k]>p.first+i){
				d[(p.second*10+i)%k]=p.first+i;
				que.push(P(d[(p.second*10+i)%k],(p.second*10+i)%k));
			}
		}
	}
	cout<<d[0]<<endl;
}


Measured memory_bytes: 2804