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

using namespace std;

#define N 300000

int n,X,Y,ans,A[N],B[N],d[N],fa[N];
bool vis[N];
vector<int> a[N],b[N];

void dfs(int u){
	for (int v:b[u])
		if (v!=fa[u]){d[v]=d[u]+1; fa[v]=u; dfs(v);}
}

void dfs2(int u,int par,int dist){
	if (vis[u]){puts("-1"); exit(0);}
	ans=max(ans,d[u]*2);
	for (int v:a[u])
		if (v!=par){
			if (dist+1<d[v]) dfs2(v,u,dist+1);
			else if (dist+1==d[v]) ans=max(ans,d[v]*2);
		}
}

int main(){
	scanf("%d%d%d",&n,&X,&Y);
	for (int i=1;i<n;++i){
		int x,y; scanf("%d%d",&x,&y);
		A[i]=x; B[i]=y;
		a[x].push_back(y); a[y].push_back(x);
	}
	for (int i=1;i<n;++i){
		int x,y; scanf("%d%d",&x,&y);
		b[x].push_back(y); b[y].push_back(x);
	}
	dfs(Y);
	for (int i=1;i<n;++i){
		int x=A[i],y=B[i];
		if (fa[x]!=y&&fa[fa[x]]!=y&&fa[x]!=fa[y]&&fa[y]!=x&&fa[fa[y]]!=x)
			vis[x]=vis[y]=1;
	}
	dfs2(X,0,0);
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 39932
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x)
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
    //#ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // #endif
    cin>>a>>b;
    if(a<=b)cout<<1<<endl;
    else if(a%b==0){
        cout<<a/b<<endl;
    }else if(a%b!=0){
     cout<<a/b+1<<endl;
    }




    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
  int n; cin>>n; string s[n]; int t[n];
  for(int i=0;i<n;i++) cin>>s[i]>>t[i];
  string ss;cin>>ss; bool smsm=false; int an=0;
  for(int i=0;i<n;i++) {
    if (smsm) an+=t[i];
    if (ss==s[i]) smsm=true;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	int a = A % 3;
	int b = B % 3;
	int ab = (A + B) % 3;

	if (a == 0 || b == 0 || ab == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	
}


Measured memory_bytes: 3632
main=getLine>>=print.s.map read.words
s[a,b,x]=g 0 90 where
 g l r|abs(l-r)<1e-11=l|f m=g m r|True=g l m where m=(l+r)/2
 f r=x<a*min(b/t)a*(b-min(a*t)b/2)where t=tan$r*pi/180

Measured memory_bytes: 508
N=int(input())
Hs = [int(i) for i in input().split()]

# dp そのマスに最後にいた際の最大移動回数
dp = [0]*N

for i in range(1,N):
    if Hs[i-1]>=Hs[i]:
        dp[i] = dp[i-1]+1
    else:
        dp[i]=0

print(max(dp))

Measured memory_bytes: 14224
#include<iostream>
#include<cstdio>
#define NIL -1
using namespace std;

struct Node{
	int parent;
	int left;
	int right;
};

struct Node T[1000];
int n;

void preParse(int u) { //先行
	if (u == NIL) {
		return;
	}
	cout << " ";
	printf("%d", u);
	preParse(T[u].left);
	preParse(T[u].right);
}

void inParse(int u) { //中間
	if (u == NIL) {
		return;
	}
	inParse(T[u].left);
	cout << " ";
	printf("%d", u);
	inParse(T[u].right);
}

void postParse(int u) { //後行
	if (u == NIL) {
		return;
	}
	postParse(T[u].left);
	postParse(T[u].right);
	cout << " ";
	printf("%d", u);
}

int main() {
	int n; //節点の数
	int id; //節点の番号
	int child; //子
	int l, r;

	cin >> n;

	for (int i = 0; i < n; i++) {
		T[i].parent = NIL;
		T[i].left = NIL;
		T[i].right = NIL;
	}

	for (int i = 0; i < n; i++) {
		cin >> id >> l >> r;
		T[id].left = l;
		T[id].right = r;
		if (T[id].left != NIL) {
			T[l].parent = id;
		}
		if (T[id].right != NIL) {
			T[r].parent = id;
		}
	}


	cout << "Preorder" << endl;
	int root = 0;
	for (int i = 0; i < n; i++) {
		if (T[i].parent == NIL) root = i;

	}
	preParse(root);

	cout << endl <<"Inorder" << endl;
	inParse(root);
	cout << endl << "Postorder" << endl;
	postParse(root);
	cout << endl;

	return 0;
}


Measured memory_bytes: 3196
#include<stdio.h>

int main(void)
{
	int a, b, c, d, sum, n, k;
	int x[6];
	
	for (int i = 1;i < 6;i++) {
		scanf("%d", &a);
		if (a == 0) {
			printf("%d", i);
		}
	}
		



	return 0;
}

Measured memory_bytes: 1676
n, k = map(int, input().split())
s = input()
g = []
a = 'A'
s = s+'B'
cnt = 1
for i in s:
  if a == i:
    cnt+=1
  else:
    a = i
    g.append(cnt)
    cnt = 1
print(n-max(1,len(g[1:])-2*k))

Measured memory_bytes: 10512
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   ll n,k,i,j,cc=0;
   cin>>n>>k;
   ll ara[n+1];
   for(i=1;i<=n;i++)cin>>ara[i];
   for(i=1;i<=k;i++){
     ll x,y;
     cin>>x>>y;
     Graph[x].pb(y);
     Graph[y].pb(x);
   }
   for(i=1;i<=n;i++){
        ll l=0;
    for(j=0;j<Graph[i].size();j++){
        ll u=Graph[i][j];
        if(ara[i]<=ara[u]){
            l=1;
            break;
        }
    }
    if(l==0)cc++;
   }
   cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 12576
n=int(input())
l = [0] * 10001
for a in range(1, 101):
    for b in range(1,101):
        for c in range(1, 101):
            o = a**2 + b**2 + c**2 + a*b + a*c + c*b
            if o <= 10000:
                l[o] += 1
for i in range(1, n+1):
    print(l[i])

Measured memory_bytes: 9132
r, g, b, n = map(int, input().split())
a1, a2, a3 = sorted([r, g, b])

r = 0
I = n//a3+1
for i in range(I):
    for j in range((n-i)//a2+1):
        t = n-i*a3-j*a2
        if t>=0 and t%a1==0:
            r += 1
print(r)

Measured memory_bytes: 2940
int main(void)
{
  int N,i;
  double M;
  double x[10];
  char u[3];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%lf",&x[i]);
    scanf("%s",&u[i]);
    if(u[i]=='J'){
      M=M+x[i];}
    else if(u[i]=='B'){
      M=M+x[i]*380000;}
  }
  printf("%f\n",M);
    
  
  return(0);
}

Measured memory_bytes: 128
#170D
def main():
    import sys
    from collections import Counter
    import random
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    #A = [random.randint(1, 10**6+1) for _ in range(2*(10**5))]
    judge = [0 for _ in range(10**6+1)]
    A.sort()
    B = Counter(A)
    for a in A:
        judge[a] =1
    for a in A:
        if judge[a] ==1:
            if B[a] >=2:
                judge[a] = 0
            for i in range(2*a, 10**6+1, a):
                judge[i] = 0
                
    print(judge.count(1))

if __name__=='__main__':
    main()

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=2e6+5;
const int mod=1e9+7;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

# define int long long

int k,n;
char s[N];
int fac[N],inv[N];
int mi25[N],mi26[N];
int ans;

int Qpow(int base,int ind){
    int res=1;
    while(ind){
        if(ind&1)res=res*base%mod;
        base=base*base%mod;
        ind>>=1;
    }
    return res;
}

int C(int n,int m){
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

signed main()
{
    read(k);
    scanf("%s",s+1);
    n=strlen(s+1);
    fac[0]=mi25[0]=mi26[0]=inv[0]=1;
    Rep(i,1,n+k)fac[i]=fac[i-1]*i%mod;
    Rep(i,1,n+k)mi25[i]=mi25[i-1]*25%mod;
    Rep(i,1,n+k)mi26[i]=mi26[i-1]*26%mod;
    Rep(i,1,n+k)inv[i]=Qpow(fac[i],mod-2);
    Rep(i,n,n+k)ans+=C(i-1,n-1)*mi25[i-n]%mod*mi26[n+k-i]%mod,ans%=mod;
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
	int N,K;
  	cin >> N >> K;
    char s[N];
    cin >> s;
  	s[K-1] = s[K-1] + 0x20;
	for (int i = 0; i < N ; i++){
		cout << s[i];
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<vector<int> > dp(m+1,vector<int>(5000,INF));
    dp[0][0]=0;
    for(int i=1;i<=m;i++){
        int cost,k;
        int w=0;
        cin>>cost>>k;
        for(int j=0;j<k;j++){
            int x;
            cin>>x;
            x--;
            w|=(1<<x);
        }
        for(int j=0;j<(1<<12);j++){
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            dp[i][j|w]=min(dp[i][j|w],min(dp[i-1][j]+cost,dp[i-1][j|w]));
        }
    }
    if(dp[m][(1<<n)-1]!=INF)
    cout<<dp[m][(1<<n)-1];
    else cout<<-1;
}


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

int main (){
    int A, B, C, D;
    cin>>A>>B>>C>>D;
    int judge=A+B-C-D;
    if(judge>0){
        cout<<"Left"<<endl;
    }
    else if(judge<0){
        cout<<"Right"<<endl;
    }
    else{
        cout<<"Balanced"<<endl;
    }
}


Measured memory_bytes: 256
b = []
b.append([int(s) for s in input().split()])
b.append([int(s) for s in input().split()])
b.append([int(s) for s in input().split()])

n = int(input())

for i in range(0, n):
    v = int(input())

    for i in range(0, 3):
        for j in range(0, 3):
            if b[i][j] == v:
                b[i][j] = 999

ans = 'No'

for i in range(0, 3):
    s = set(b[i])

    if len(s) == 1:
        ans = 'Yes'

for i in range(0, 3):
    s = set([b[0][i], b[1][i], b[2][i]])

    if len(s) == 1:
        ans = 'Yes'

c = set([b[0][0], b[1][1], b[2][2]])

if len(c) == 1:
    ans = 'Yes'

c = set([b[0][2], b[1][1], b[2][0]])

if len(c) == 1:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vvll a(n, vll(n));
    REP(i, n) REP(j, n) cin >> a[i][j];
    // vvll dp(n+1, vll(1<<n)); dp[0][0] = 1;
    // rep(i, 1, n+1) {
    //     rep(s, 0, 1<<n) {
    //         rep(j, 0, n) {
    //             if (((s>>j)&1) && a[i-1][j]==1) {
    //                 dp[i][s] = (dp[i][s] + dp[i-1][s^(1<<j)]) % MOD;
    //             }
    //         }
    //     }
    // }

    // vll dp(1<<n, 0); dp[0] = 1;
    // rep(s, 1, 1<<n) {
    //     ll i = __builtin_popcount(s);
    //     rep(j, 0, n) {
    //         if (((s>>j)&1) && a[i-1][j]==1) {
    //             dp[s] = (dp[s] + dp[s^(1<<j)]) % MOD;
    //         }
    //     }
    // }

    vvll dp(n+1, vll(1<<n)); dp[0][0] = 1;
    rep(i, 0, n) {
        REP(s, 1<<n) {
            if (dp[i][s]) REP(j, n) {
                if (((s>>j)&1)==0 && a[i][j]==1) {
                    dp[i+1][s^(1<<j)] = (dp[i+1][s^(1<<j)] + dp[i][s]) % MOD;
                }
            }
        }
    }
    cout << dp[n][(1<<n)-1] << '\n';
    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N, K;
int A[MAX_N];

vector<int> vec[MAX_N];
bool used[MAX_N];

int ans = 0;
int solve(int pos) {
    int ret = 0;
    for(int next : vec[pos]) {
        if(next == pos) {
            continue;
        }
        int tmp = solve(next);
        if(tmp >= K && pos != 0) {
            ans++;
        } else {
            ret = max(tmp, ret);
        }
    }
    return ret+1;
}

signed main()
{
    cin >> N >> K;
    REP(i,N) {
        cin >> A[i]; A[i]--;
    }

    if(A[0] != 0) {
        ans++;
        A[0] = 0;
    }

    FOR(i,1,N) {
        vec[A[i]].push_back(i);
    }

    solve(0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int N;
    int xpy=0;
    int xmy=0;
    int mxpy=0;
    int mxmy=0;
    cin>>N;
    int x,y;
    cin>>x>>y;
    xpy=x+y;
    xmy=x-y;
    mxpy=y-x;
    mxmy=-1*(x+y);
    for(int i=1;i<N;i++){
        cin>>x>>y;
        if(xpy<x+y){
            xpy=x+y;
        }
        if(xmy<x-y){
            xmy=x-y;
        }
        if(mxpy<y-x){
            mxpy=y-x;
        }
        if(mxmy<-1*(x+y)){
            mxmy=-1*(x+y);
        }
    }
    //cout<<xpy<<" "<<mxmy<<" "<<xmy<<" "<<mxpy<<endl;

    cout<<max(xpy+mxmy,xmy+mxpy)<<endl;


    return 0;
}

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  char a='1';
  for(int i=0;i<K;i++){
    if(S[i]=='1')continue;
    else{
      a=S[i];
      break;
    }
  }
  cout << a;
}



Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    M := make(map[int]bool)
    var n int
    fmt.Scanf("%d", &n)

    res := 0
    for i := 0; i < n; i++ {
        var a int
        fmt.Scanf("%d", &a)
        if M[a] {
            M[a] = false
            res--
        } else {
            M[a] = true
            res++
        }
    }

    fmt.Printf("%d\n", res)

}


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

int main(){
  int a, b;
  cin >> a >> b;
  
  int namin, nbmin, namax, nbmax;
  namin = int(a / 0.08 - 0.001) + 1;
  nbmin = int(b / 0.10 - 0.001) + 1;
  namax = int(a / 0.08 + 12.5 - 0.001) + 1;
  nbmax = int(b / 0.10 + 10.0 - 0.001) + 1;
  
  int ans;
  ans = max(namin, nbmin);
  if(ans == namin){
    if(ans >= nbmax)
      ans = -1;
  }
  else{
    if(ans >= namax)
      ans = -1;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main
{
    private static class Move
    {
        private final int node;
        private final int cost;
        private final ArrayList<Integer> visited;

        Move(int node, int cost, ArrayList<Integer> visited)
        {
            this.node = node;
            this.cost = cost;
            this.visited = visited;
        }
    }

    private static final int INF = Integer.MAX_VALUE / 2;

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int r = sc.nextInt();

        ArrayList<Integer> cities = new ArrayList<>();
        for (int i = 0; i < r; i++) {
            cities.add(sc.nextInt() - 1);
        }

        int[][] matrix = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrix[i][j] = INF;
            }
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();

            matrix[a][b] = c;
            matrix[b][a] = c;
        }

        for (int k = 0; k < n; k++) {
            for (int s = 0; s < n; s++) {
                for (int g = 0; g < n; g++) {
                    matrix[s][g] = Math.min(matrix[s][g], matrix[s][k] + matrix[k][g]);
                    matrix[g][s] = Math.min(matrix[g][s], matrix[g][k] + matrix[k][s]);
                }
            }
        }

        int minCost = Integer.MAX_VALUE;
        LinkedList<Move> queue = new LinkedList<>();
        for (int city : cities) {
            queue.add(new Move(city, 0, new ArrayList<>()));
        }
        while (!queue.isEmpty()) {
            Move move = queue.removeFirst();
            move.visited.add(move.node);
            if (move.visited.size() == r) {
                if (move.cost < minCost) {
                    minCost = move.cost;
                }
            }

            for (int i = 0; i < n; i++) {
                int nextCost = matrix[move.node][i];
                if (nextCost != INF && cities.contains(i) && !move.visited.contains(i)) {
                    queue.add(new Move(i, move.cost + nextCost, new ArrayList<>(move.visited)));
                }
            }
        }

        System.out.println(minCost);
    }
}


Measured memory_bytes: 102456
#include<bits/stdc++.h>
using namespace std;
int a[55];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)a[i]=-a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++)ans-=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", &a[i])
#define SAL(i, n, a) R(i, n) scanf("%lld", &a[i])
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int main(){
	ll A;
	int B1, B2;
	SL(A);
	int b;
	scanf("%d. %d", &B1, &B2);
	if (B1 != 0) {
		B1 *= 100;
		b = B1 + B2;
	}
	else b = B2;
	ll ans = A * b / 100;
	PL(ans);
} 

Measured memory_bytes: 3824
//左真ん中右の中で2番めに小さい
#include <stdio.h>

int main()
{
    int n, p[20+1], i, cnt = 0;

    scanf("%d", &n);
    for( i = 1; i <= n; i++ )
    {
        scanf("%d", &p[i]);
    }
    
    for( i = 2; i <= n-1; i++ )
    {
        if (p[i - 1] < p[i] && p[i] < p[i + 1])
            cnt++;
        else if (p[i - 1] > p[i] && p[i] > p[i + 1])
            cnt++;
        else 
            continue;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    vector<char> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> d[i];
    }
    double l = 0, r = INF<int>;
    double xmax = INF<ll>, xmin = -INF<ll>, ymax = INF<ll>, ymin = -INF<ll>;
    double xmax2 = INF<ll>, xmin2 = -INF<ll>, ymax2 = INF<ll>, ymin2 = -INF<ll>;
    for (int i = 0; i < 300; ++i) {
        double lb = (l*2+r)/3, ub = (l+2*r)/3;
        xmax = -INF<ll>, xmin = INF<ll>, ymax = -INF<ll>, ymin = INF<ll>;
        xmax2 = -INF<ll>, xmin2 = INF<ll>, ymax2 = -INF<ll>, ymin2 = INF<ll>;
        for (int j = 0; j < n; ++j) {
            double X1 = x[j], Y1 = y[j], X2 = x[j], Y2 = y[j];
            if(d[j] == 'R')  X1 += lb,  X2 += ub;
            if(d[j] == 'L')  X1 -= lb,  X2 -= ub;
            if(d[j] == 'U')  Y1 += lb,  Y2 += ub;
            if(d[j] == 'D')  Y1 -= lb,  Y2 -= ub;
            xmax = max(xmax, X1); xmin = min(xmin, X1);
            ymax = max(ymax, Y1); ymin = min(ymin, Y1);
            xmax2 = max(xmax2, X2); xmin2 = min(xmin2, X2);
            ymax2 = max(ymax2, Y2); ymin2 = min(ymin2, Y2);
        }
        if((xmax-xmin)*(ymax-ymin) < (xmax2-xmin2)*(ymax2-ymin2)) r = ub;
        else l = lb;
    }
    cout << setprecision(15) << (xmax-xmin)*(ymax-ymin) << "\n";
    return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#pragma warning(disable : 4996)
const int N = 1e5 + 5;
int stone[N], dp[N];

int min(int x, int y) { return x <= y ? x : y; }
int abs(int x) {
	if (x >= 0) return x;
	else return -x;
}

int main() {
	int num;
	scanf("%d", &num);
	for (int i = 1; i <= num; i++) scanf("%d", &stone[i]);
	dp[1] = 0, dp[2] = abs(stone[2] - stone[1]);
	for (int i = 3; i <= num; i++) {
		dp[i] = min(dp[i - 1] + abs(stone[i] - stone[i - 1]), dp[i - 2] + abs(stone[i] - stone[i - 2]));
	}
	return 0*printf("%d\n",dp[num]);
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  vi nums;
  int now = 1;
  int cnt = 0;
  // 1-0-1-0-1の形の配列を作る
  // 0番目の区間が0なら、(1,0)が先頭に追加される
  // 0番目の区間が1なら、そのまま数えられる
  rep(i,n) {
    if (s[i] == (char)('0' + now)) cnt++;
    else {
      nums.pb(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  // 最後の区間がまだついていないので付け加える
  if (cnt != 0) nums.pb(cnt);
  // numsのサイズが偶数の場合、1-0-1-0の形になってしまっているので、
  // 後ろに(1,0)を追加して、1-0-1-0-1の形にする
  if (nums.size()%2 == 0) nums.pb(0);

  // k = 1: 1-0-1 -> 1-1-1
  //                 |   |
  //                 l   l+2*k
  // k = 2: 1-0-1-0-1 -> 1-1-1-1-1
  //                     |       |
  //                     l       l+2*k
  int add = 2*k + 1;

  // 累積和を作る
  // 0 1 2 3 4 5 6
  //  0 1 2 3 4 5

  vi sum(nums.size()+1);
  rep(i,nums.size()) {
    sum[i+1] = sum[i] + nums[i];
  }

  int ans = 0;

  int tmp = 0; // [left, right)のsum
  // 1-0-1...の1から始めるので、偶数番目だけ見る
  for (int i = 0; i < nums.size(); i+=2) {
    // 次のleft, right [left, right)
    int left = i;
    int right = min(i+add, (int)nums.size());
    int tmp = sum[right] - sum[left];

    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1272
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    while(1)
    {
        int n,m,a[10000],b[10000],lis1[500],lis2[500],x=0,y,z,cnt=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<m;i++)
        {
            y=0;
            cin>>a[i]>>b[i];
            if(a[i]==1)
            {
                if(x!=0)for(int j=0;j<x;j++)if(lis1[j]==b[i])y++;
                if(y==0)
                {
                    lis1[x]=b[i];
                    x++;
                }
            }
            if(b[1]==1)
            {
                if(x!=0)for(int j=0;j<x;j++)if(lis1[j]==a[i])y++;
                if(y==0)
                {
                    lis1[x]=a[i];
                    x++;
                }
            }
        }
        lis1[x]=1;
        y=0;
        for(int i=0;i<m;i++)
        {
            z=0;
            for(int j=0;j<=x;j++)
            {
                if(a[i]==lis1[j])
                {
                    if(b[i]!=1)
                    {
                        if(y!=0)for(int k=0;k<y;k++)if(lis2[k]==b[i])z++;
                        if(z==0)
                        {
                            lis2[y]=b[i];
                            y++;
                            cnt++;
                        }
                    }
                }
                if(b[i]==lis1[j])
                {
                    if(a[i]!=1)
                    {
                        if(y!=0)for(int k=0;k<y;k++)if(lis2[k]==a[i])z++;
                        if(z==0)
                        {
                            lis2[y]=a[i];
                            y++;
                            cnt++;
                        }
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

using ll = long long;

class union_find {
public:
    union_find(int n) : par(n, -1) {}

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) return;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }

    int size(int x) {
        return -par[root(x)];
    }

private:
    vector<int> par;
};

int main() {
    int n;
    while(cin >> n, n) {
        vector<string> word(n);
        for(auto& s : word) {
            cin >> s;
        }

        vector<int> in(26), out(26);
        union_find uf(26);
        for(auto& s : word) {
            const auto first = s[0] - 'a', last = s.back() - 'a';
            in[first]++;
            out[last]++;
            uf.unite(first, last);
        }

        bool ok = true;
        int comp_num = 0;
        for(int i = 0; i < 26; ++i) {
            comp_num += in[i] && uf.root(i) == i;
            ok &= in[i] == out[i];
        }
        ok &= comp_num == 1;

        cout << (ok ? "OK" : "NG") << endl;
    }
}



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

int main(){
    ll x;
    cin >> x;
    int ctr=0;
    ll money=100ll;
    while(money<x){
        ctr++;
        money*=1.01;
    }
    cout<< ctr << endl;
}

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

const int N = 200005;
int a[N];

int main()
{
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);

	if(n&1)
	{
		int num = n;
		while(num > 1)
		{
			printf("%d ",a[num]);
			num -= 2;
		}
		printf("%d ",a[1]);
		num = 2;
		while(num < n)
		{
			printf("%d ",a[num]);
			num += 2;
		}
	}
	else
	{
		int num = n;
		while(num > 1)
		{
			printf("%d ",a[num]);
			num -= 2;
		}
		printf("%d ",a[1]);
		num = 3;
		while(num < n)
		{
			printf("%d ",a[num]);
			num += 2;
		}
	}
	printf("\n");
	return 0;
}
/*
1
1

1 2
2 1

2 1 3
3 1 2

3 1 2 4
4 2 1 3

4 2 1 3 5
5 3 1 2 4

5 3 1 2 4 6
6 4 2 1 3 5

6 4 2 1 3 5 7
7 5 3 1 2 4 6
*/

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, K;
    cin >> N >> K;
    double ans = 0;
    FOR (i, 1, N + 1) {
        int num = 0, p = i;
        while (p < K) {
            num++;
            p *= 2;
        }
        ans += pow(0.5, num);
    }
    ans /= N;
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 2 << endl;
  } else if (n < 3) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = 0;
	if (n % 2 == 0) {
		rep(i, n) {
	        if (i < n / 2 -1) ans -= 2 * a[i];
			else if(i > n/2) ans += 2 * a[i];
			else if (i == n / 2 - 1) ans -= a[i];
			else ans += a[i];
		}
	}
	else {
		rep(i,n){
			if (i < n / 2 - 1) ans -= 2 * a[i];
			else if (i > n / 2 + 1) ans += 2 * a[i];
		}
		ll ans_a = ans, ans_b = ans;
		ans_a += a[n / 2 + 1] + a[n / 2] - 2 * a[n / 2 - 1];
		ans_b += 2 * a[n / 2 + 1] - a[n / 2] - a[n / 2 - 1];
		ans = max(ans_a, ans_b);
	}
	cout << ans << endl;
}

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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




/* main */




signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);




    int n = input();

    int t, a; cin >> t >> a;

    vi arr; rep(i,0,n) arr.push_back(input());

    float ans = inf; 
    int ind = -1;

    rep(i,0,n){
        if(abs(a - (t - (arr[i] * 0.006))) < abs(a - ans)){
            ind = i;
            ans = t - (arr[i] * 0.006);
        }
    }

    print(ind + 1);

    

    

    



    
    



    







    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;
int main()
{
    FLASH
    string s;
    cin >> s;
    if(s == "ABC")
        cout << "ARC";
        else
            cout << "ABC";
    return 0;
}



Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(S):
    S = [c for c in S]
    l = []
    r = []
    la = []
    for c in S:
        if c == ')':
            if l:
                l.pop()
            else:
                la.append('(')
        else:
            l.append('(')
    S = la + S + [')' for _ in range(len(l))]
    return ''.join(S)


def main():
    N = read_int()
    S = read_str().strip()

    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5456
from itertools import permutations
from math import sqrt

N = int(input())
l = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
n = 0

for i in permutations(l):
    for j in range(N-1):
        x1, y1 = i[j]
        x2, y2 = i[j+1]
        ans += sqrt((x1-x2)**2+(y1-y2)**2)
    n += 1

print(ans/n)

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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

MOD = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

Z=X+Y
if Z%3 == 0:
    D=int(Z/3)
    d=min(X,Y)
    print(cmb(D,d-D,MOD))
else:
    print(0)

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

int main() {
	string s;
	int m;
	while (1) {
		cin >> s;
		if (s == "-")break;
		cin >> m;
		for (int i = 0; i < m; ++i) {
			int h;
			cin >> h;
			s = s.substr(h) + s.substr(0, h);
		}
		cout << s << endl;
	}
	return 0;
}



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

bool dfs(int v, int const s, vector<vector<int>> const& es, vector<bool>& visited) {
    visited[v] = true;
    bool res = false;
    for(auto& u : es[v]) {
        if(!visited[u]) {
            res |= dfs(u, s, es, visited);
        } else if(visited[v] && u == s) {
            res = true;
            break;
        }
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> es(210);
    for(int i=0; i<n; ++i) {
        int u, d;
        string s;
        cin >> u >> s >> d;
        d += 100;
        if(s == "lock") {
            es[d].push_back(u);
        } else {
            es[u].push_back(d);
        }
    }
    bool res = false;
    for(int i=0; i<101; ++i) {
        vector<bool> visited(210);
        res |= dfs(i, i, es, visited);
    }
    cout << res << endl;
}

Measured memory_bytes: 3228
//Practice
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5 + 5;
const ll INF = 1e9 + 5;
const ll mxN = 1000000007;
const double E = 1e-9;

//------------------------------------------------------------------------------
int n;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int ini = 1;
	/*if (a[1] == 1)
	{
		cout << -1;
		return 0;
	}
	if (a[1] == 2)
	{
		cout << 0;
		return 0;
	}*/
	ll ans = 0;
	while (ans <= n)
	{
		++ans;
		if (a[ini] == 2)
		{
			cout << ans;
			return 0;
		}
		ini = a[ini];
	}
	cout << -1;
	return 0;
}
//29-08-2020 11:43:32
//------------------------------------------------------------------------------

Measured memory_bytes: 3728
import java.util.*;

public class Main {
    public static int gcd(int a, int b)
    {
        if(a==0)
            return b;
        return gcd(b%a, a);
    }

    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        long count = 0;
        for(int a=1;a<=K;a++)
        {
            for(int b=a;b<=K;b++)
            {
                for(int c=b;c<=K;c++)
                {
                    int gcd = gcd(gcd(a, b), c);
                    if(a!=b && b !=c && c!=a)
                        count += gcd*6;
                    else if(a == b && a != c)
                        count += gcd*3;
                    else if(b == c && a !=c)
                        count+=gcd*3;
                    else
                        count+=gcd;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35728
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int n;

	while(cin >> n, n) {
		int max = 0, min = 500;
		REP(i, n) {
			int a, b, c, d, e;
			int res;

			cin >> a >> b >> c >> d >> e;
			res = a+b+c+d+e;

			if(res > max) {
				max = res;
			}
			if(res < min) {
				min = res;
			}
		}

		cout << max << " " << min << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

using namespace std;

void solve()
{
   int n,w;
   cin>>n>>w;
   vector<vector<int> > v(n, vector<int>(2));
   int dp[n+1][w+1];
   memset(dp,-1,sizeof dp);

   for(int i=0;i<n;i++)
   {
    cin>>v[i][0]>>v[i][1];
    
   }

   dp[0][0]=0;


   for(int i=1;i<=n;i++)
   {
    for(int j=0;j<=w;j++)
    {
        dp[i][j] = max(dp[i][j],dp[i-1][j]);

        if(j-v[i-1][0]>=0)
          dp[i][j] = max(dp[i][j],dp[i-1][j-v[i-1][0]]+v[i-1][1]);  
    }

   
   }

   int ans = INT_MIN;
   for(int i=0;i<=w;i++)
    ans=max(ans,dp[n][i]);

cout<<ans<<endl;



}
signed main()

{
    FAST_IO;
    int t = 1;

    // cin>>t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 79232
#ABC179 b
n = int(input())
a = [list(map(int, input().split())) for l in range(n)]
count = 0
ans = 0
for i in range(n):
  if a[i][0] == a[i][1]:
    count += 1
  else:
    count = 0
  if count >= 3:
    ans = 1
if ans == 1:
  print('Yes')
else:
  print('No')

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	modulo inline operator + (modulo b) { int r = w + b; if (r > mod) r -= mod; return r; }
	modulo& operator += (modulo b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	modulo inline operator - (modulo b) { int r = w - b; if (r < 0) r += mod; return r; }
	modulo& operator -= (modulo b) { if ((w -= b.w) < 0) w -= mod; return *this; }
	modulo inline operator * (modulo b) { modulo r = *this; r *= b; return r; }
	modulo& operator *= (modulo b) { w = (num) w * b.w % mod; return *this; }
	modulo inline operator / (modulo b) { modulo r = *this; r /= b; return r; }
	modulo& operator /= (modulo b) { w = (num) w * b.inv() % mod; return *this; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
typedef modulo<998244353> rem;

const int nsz = int(2e5);
rem n, m, k, fac[nsz + 5], ifc[nsz + 5], ans;

void inline init() {
	fac[0] = ifc[0] = 1;
	cont (i, n) {
		fac[i] = fac[i - 1] * rem(i);
		ifc[i] = fac[i].inv();
	}
}

rem inline C(int n, int m) { return fac[n] * ifc[m] * ifc[n - m]; }

rem inline f(int n, int k) { return C(n - 1, k) * m * (m - rem(1)).pow(n - k - 1); }

int main() {
	scanf("%d%d%d", &n, &m, &k);
	if (m == 1) {
		printf("%d\n", k == n - rem(1));
		return 0;
	}
	init();
	circ (i, 0, int(k)) {
		ans += f(n, i);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 5276
#include<stdio.h>

int main(){
	int dice[6], x, i, y[25], a, b;
	for(i = 0; i < 6; i++){
		scanf("%d", &dice[i]);
	}
	scanf(" %d", &x);
	for(i = 0; i < x; i++){
		scanf(" %d %d", &a, &b);
		if(a == dice[0]){
			if(b == dice[1]){
				y[i] = dice[2];
			} else if(b == dice[2]){
				y[i] = dice[4];
			} else if(b == dice[3]){
				y[i] = dice[1];
			} else if(b == dice[4]){
				y[i] = dice[3];
			}
		} else if(a == dice[1]){
			if(b == dice[0]){
				y[i] = dice[3];
			} else if(b == dice[2]){
				y[i] = dice[0];
			} else if(b == dice[3]){
				y[i] = dice[5];
			} else if(b == dice[5]){
				y[i] = dice[2];
			}
		} else if(a == dice[2]){
			if(b == dice[0]){
				y[i] = dice[1];
			} else if(b == dice[1]){
				y[i] = dice[5];
			} else if(b == dice[4]){
				y[i] = dice[0];
			} else if(b == dice[5]){
				y[i] = dice[4];
			}
		} else if(a == dice[3]){
			if(b == dice[0]){
				y[i] = dice[4];
			} else if(b == dice[1]){
				y[i] = dice[0];
			} else if(b == dice[4]){
				y[i] = dice[5];
			} else if(b == dice[5]){
				y[i] = dice[1];
			}
		} else if(a == dice[4]){
			if(b == dice[0]){
				y[i] = dice[2];
			} else if(b == dice[2]){
				y[i] = dice[5];
			} else if(b == dice[3]){
				y[i] = dice[0];
			} else if(b == dice[5]){
				y[i] = dice[3];
			}
		} else if(a == dice[5]){
			if(b == dice[1]){
				y[i] = dice[3];
			} else if(b == dice[2]){
				y[i] = dice[1];
			} else if(b == dice[3]){
				y[i] = dice[4];
			} else if(b == dice[4]){
				y[i] = dice[2];
			}
		}
	}
	for(i = 0; i < x; i++){
		printf("%d\n", y[i]);
	}
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes" << endl;
    }
    else cout << "No" <<endl;
}

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

int main(){
    int N;
    cin >> N;
    long long int H[N];
    for(int i=0;i<N;++i){
        cin >> H[i];
    }
    long long int C[N];
   int num_jum=0;
   int tmp=0;
   int res=0;
       for(int j=res;j<N;++j){
           if(H[j]>=H[j+1]){
               ++num_jum;
           }
           else{
               if(num_jum>tmp){
               tmp=num_jum;
               res+=num_jum;
               num_jum=0;
               continue;
               }
               else{
                   res+=num_jum;
                   num_jum=0;
                   continue;
               }
           }
       }
   num_jum=tmp;
    cout << num_jum;
}

Measured memory_bytes: 1024