akhauriyash/Code-Regression huggingface dataset:
k = int(input())

if k == 1:
    print(1)
    exit()
elif k == 2:
    print(9)
    exit()

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

ans = 0
for a in range(1, k+1):
    ans += a
    for b in range(a + 1, k+1):
        d = gcd(a, b)
        ans += d * 6
        for c in range(b + 1, k+1):
            ans += gcd(d, c) * 6

print(ans)

Measured memory_bytes: 68068
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;
	int matrix[100][100];
	int vector[100];
	int answer[100];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> matrix[i][j];
	for (int i = 0; i < m; i++)
		cin >> vector[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			answer[i] += matrix[i][j] * vector[j];

	for (int i = 0; i < n; i++)
		cout << answer[i] << endl;
	return 0;
}



Measured memory_bytes: 3104
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,ans;
string s;
map<string , int> mp;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

        cin >> n;
        for(int i=1;i<=n;i++){
            cin >> s;
            sort(all(s));
            ans+=mp[s];
            mp[s]++;
        }
        cout << ans << endl;



return 0;
}
///....


Measured memory_bytes: 11264
#include<stdio.h>
int main()
{
    int h,w,n,ans;
    scanf("%d%d%d",&h,&w,&n);
    if(h>=w)
    {
        if(n%h==0)
            ans=n/h;
        else
            ans=n/h+1;
    }
    else
    {
        if(n%w==0)
            ans=n/w;
        else
            ans=n/w+1;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>

#define MAX 10000
#define NIL -1

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

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
	if(T[u].parent == NIL) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	int deg = 0;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int i, v, l, r, root = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++) T[i].parent = NIL;
	for(i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(i=0;i<n;i++) print(i);
	
	return 0;
}

/*
9
0 1 4
1 2 3
2 -1 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 -1
*/


Measured memory_bytes: 2044
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  ll sum = 0;
  ll count = 0;
  ll m = numeric_limits<ll>::max();
  rep(i, N) {
    if(A[i] < 0) count++;
    ll absA = abs(A[i]);
    sum += absA;
    m = min(m, absA);
  }
  if(count%2 == 1) {
    sum -= 2 * m;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
bool node[2010];
int N,K;
int ans=1<<30;
std::vector<int> G[2010];

void dfs(int n,int s){
    node[n]=true;
    if(s==K/2){
        return;
    }
    for(auto u:G[n]){
        if(!node[u])dfs(u,s+1);
    }
}

int solve(int n){
    int res=1<<30;
    for(auto u:G[n]){
        for(int i=1;i<=N;i++)node[i]=false;
        node[n]=true;
        if(K%2)node[u]=true,dfs(u,0);
        dfs(n,0);
        int sum=0;
        for(int i=1;i<=N;i++)if(!node[i])sum++;
        res=std::min(res,sum);
    }
    return res;
}

int main(){
    std::cin>>N>>K;
    for(int i=1;i<N;i++){
        int A,B;
        std::cin>>A>>B;
        G[A].emplace_back(B);
        G[B].emplace_back(A);
    }
    for(int i=1;i<=N;i++){
        ans=std::min(ans,solve(i));
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
b = bin(n)[2:]
MOD = 10 ** 9 + 7

dp1, dp2, dp3 = 1, 0, 0

for d in b:
    if d == '1':
        dp1, dp2, dp3 = dp1 % MOD, (dp1 + dp2) % MOD, (dp2 * 2 + dp3 * 3) % MOD
    else:
        dp1, dp2, dp3 = (dp1 + dp2) % MOD, dp2, (dp2 + dp3 * 3) % MOD

print((dp1 + dp2 + dp3) % MOD)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a;
    REP(i,n){
        int tmp;
        cin>>tmp;
        a.push_back(tmp);
    }
    set<int> ans(a.begin(),a.end());
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lps(i,j,n) for(int i=j;i<n;i++)
#define lp(i,n) lps(i,0,n)
#define DEKAI 1000000007
#define INF (1<<28)
#define int long long

pair<int,int> l[1000001],l2[1000001];

int nx[501],ny[501],ux[501],uy[501],nn1,nn2,uu1,uu2;

signed main(){
  int n,u,v,m;
  cin>>n>>u>>v>>m;
  lp(z,2){
    lp(i,n){
      lp(j,n){
	int a;
	cin>>a;
	if(z==0){
	  l[a]=make_pair(i+1,j+1);
	}
	if(z==1){
	  l2[a]=make_pair(i+1,j+1);
	}
      }
    }
  }
  int us=0,nek=0,stat=0;
  lp(i,m){
    int a;
    cin>>a;
    if(stat==1) continue;
    pair<int,int> usrg=l[a];
    pair<int,int> nekrg=l2[a];
    if(usrg.first!=0||usrg.second!=0){
      ux[usrg.first]++;
      if(ux[usrg.first]==n) us++;
      uy[usrg.second]++;
      if(uy[usrg.second]==n) us++;
      if(usrg.first==usrg.second){
	uu1++;
	if(uu1==n) us++;
      }
      if(usrg.first+usrg.second==n+1){
	uu2++;
	if(uu2==n) us++;
      }
    }
    if(nekrg.first!=0||nekrg.second!=0){
      nx[nekrg.first]++;
      if(nx[nekrg.first]==n) nek++;
      ny[nekrg.second]++;
      if(ny[nekrg.second]==n) nek++;
      if(nekrg.first==nekrg.second){
	nn1++;
	if(nn1==n) nek++;
      }
      if(nekrg.first+nekrg.second==n+1){
	nn2++;
	if(nn2==n) nek++;
      }
    }
    if(n==1){
      if(nek!=0) nek=1;
      if(us!=0) us=1;
    }
    if(us>=u&&nek<v){
      cout<<"USAGI"<<endl;
      stat=1;;
    }
    if(us>=u&& nek>=v){
      cout<<"DRAW"<<endl;
      stat=1;
    }
    if(us<u&&nek>=v){
      cout<<"NEKO"<<endl;
      stat=1;
    }
    //cout<<us<<" "<<nek<<endl;
  }
  if(stat==0){
    cout<<"DRAW"<<endl;
  }
  return 0;
  
}



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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std; 

int main(void)
{
    int n, m;
    cin >> n >> m;
    
    v2_char s(n, v_char(n)), t(m, v_char(m));
    irep(i, n) {
        irep(j, n) {
            cin >> s[i][j];
        }
    }
    irep(i, m) {
        irep(j, m) {
            cin >> t[i][j];
        }
    }
    irep(i, n) {
        irep(j, n) {
            bool ok = true;
            if(i+m-1< n && j+m-1 < n) {
                irep(k, m) irep(l, m) {
                    if(s[i+k][j+l] != t[k][l]) {
                        ok = false;
                    }
                }
                if(ok) { puts("Yes"); return 0; }
            }
        }
    }
    puts("No"); 
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
using namespace std;

int main(void) {
	// Your code here!
	cin.tie(0);
	ios::sync_with_stdio(false);

    int cost;
    int money;
    int max1;
    
    cin >> cost >> money >> max1;
    //cout << cost << "," << money << "," << max1 << "\n";

    int count = money / cost;
    cout << min(count, max1);
	
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int N;
  long long ans = 0;
  cin >> N;
  map<string, long long> S;
  REP(i ,N) {
    string tmp;
    cin >> tmp;
    sort(ALL(tmp));
    if (S.find(tmp) != S.end()) {
      S[tmp]++;
    } else {
      S[tmp] = 1;
    }
  }
  for( auto i = S.cbegin(); i != S.cend() ; ++i ) {
    long long val = i->second;
    ans += val * (val - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    356
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );
using namespace std;
ll n, a, b, x, y;
void solve()
{
    cin >> n;
    for( int i = 1; i <= n; i ++ )
    {
        cin >> a >> b;
        x += b;
        y += a * b;

    }
    x --;
    y --;
    x += y / 9;
    cout << x;
}
int main()
{
    ll tt = 1;
    //sc( "%d", &tt );
    for( ll i = 1; i <= tt; i ++ )
    {
        solve();
    }
}












Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


using ll=long long;

class mod_ll
{
public:
	ll m_v;
	static const ll m_m=1000000007; // prime value ex. 1000000009
	mod_ll(ll v=0) : m_v(v%m_m) {}
	mod_ll operator = (ll rhs)
	{
		m_v=rhs%m_m;
		return *this;
	}
	ll operator ()(){return m_v;}
	mod_ll operator = (mod_ll rhs)
	{
		m_v=rhs.m_v;
		return *this;
	}
	mod_ll operator += (mod_ll rhs)
	{
		m_v=(m_v+rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator + (mod_ll rhs)
	{
		auto ret=*this;
		return ret+=rhs;
	}
	mod_ll operator -= (mod_ll rhs)
	{
		m_v=(m_v-rhs.m_v+m_m)%m_m;
		return *this;
	}
	mod_ll operator - (mod_ll rhs)
	{
		auto ret=*this;
		return ret-=rhs;
	}
	mod_ll operator *= (mod_ll rhs)
	{
		m_v=(m_v*rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator * (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret*=rhs;
	}
	mod_ll operator ^ (ll rhs)
	{
		mod_ll t=*this;
		mod_ll ret(1LL);

		for(;rhs>0;rhs>>=1)
		{
			if(rhs&1) ret*=t;
			t*=t;
		}
		return ret;
	}
	mod_ll operator /= (mod_ll rhs)
	{
		return *this*=(rhs^(m_m-2));
	}
	mod_ll operator / (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret/=rhs;
	}
};


mod_ll mod_fact(int n)
{
	static vector<mod_ll> memo(1);

	if((int)memo.size()<=n)
	{
		if(memo.size()==1)
		{
			memo[0]=1;
		}
		for(int i=memo.size();i<=n;i++)
		{
			memo.push_back(memo.back()*i);
		}
	}
	return memo[n];
}


mod_ll mod_nCr(int n, int r)
{
	if(n<=0) return 1;
	mod_ll bunsi=mod_fact(n);
	mod_ll bunbo=mod_fact(n-r)*mod_fact(r);
	return bunsi/bunbo;
}


mod_ll mod_nCr2(int n, int r)
{
	mod_ll bunsi(1);
	mod_ll bunbo(1);
	if(r*2>n) r=n-r;

	for(int i=0;i<r;i++)
	{
		bunsi*=(n-i);
		bunbo*=(i+1);
	}

	return bunsi/bunbo;
}


mod_ll mod_nPr(int n, int r)
{
	return mod_fact(n)/mod_fact(n-r);
}



struct solve
{
	solve(){}
	ll operator()(int n, int m) {
		mod_ll ret(0);
		vector<mod_ll> p(n+1);

		for(int i=0;i<=n;i++)
		{
			p[i]=mod_nPr(m-i, n-i)*mod_nCr(n, i);
			if(i&1) ret-=p[i];
			else ret+=p[i];
		}
//for(auto&mp:p) cout << mp() << " "; cout << "\n";
		ret*=mod_nPr(m, n);

		return ret();
	}
};

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

	for(;;)
	{
		int n, m;
		cin >> n >> m;
		if(cin.fail()) break;
		cout << solve()(n, m) << "\n";
	}
	return 0;
}


Measured memory_bytes: 11192
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  REP(i,n) cin >> w[i];
  int s1 = 0;
  int s2 = 0;
  int mx = 1000000;
  for(int i = 0; i < n ; ++ i){
    s1 = 0; s2 = 0;
    for(int j = 0; j < i; ++ j) s1 += w[j];
    for(int j = i; j < n; ++ j) s2 += w[j];
    //cout << s1 << " " << s2 << endl;
    mx = min(mx, abs(s1-s2));
  }

  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;cin>>k;
	string s;cin>>s;
	int p=s.size();
	if(p<=k)
	cout<<s;
	else{
		for(int i=0;i<k;i++)cout<<s[i];
		cout<<"...";
		
	}
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main()
{
    char vowels[5] = {'a', 'e', 'i', 'o', 'u'};

    char c;
    cin >> c;

    bool prime = false;

    for (int i=0; i<5; i++)
    {
        if (c==vowels[i])
        {
            prime = true;
            break;
        }
    }

    if (prime==true) {cout << "vowel" << endl;}
    else {cout << "consonant" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int dx[4]={0,0,1,-1};
constexpr int dy[4]={1,-1,0,0};

int H,W,sx,sy,gx,gy,dist[1000][1000];
string S[1000];

int main(){
	cin>>H>>W>>sx>>sy>>gx>>gy;
	sx--;
	sy--;
	gx--;
	gy--;
	for(int i=0;i<H;i++){
		cin>>S[i];
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			dist[i][j]=-1;
		}
	}
	deque<pair<int,int>>q;
	int d=0;
	q.push_back({sx,sy});
	q.push_back({0xE869120,0xE869120});
	while(q.size()>=2){
		int x=q.front().first;
		int y=q.front().second;
		q.pop_front();
		if(x==0xE869120){
			d++;
			q.push_back({0xE869120,0xE869120});
			continue;
		}
		if(x<0||H<=x||y<0||W<=y||S[x][y]=='#'||dist[x][y]!=-1)continue;
		dist[x][y]=d;
		for(int i=0;i<4;i++){
			q.push_front({x+dx[i],y+dy[i]});
		}
		for(int i=x-2;i<=x+2;i++){
			for(int j=y-2;j<=y+2;j++){
				q.push_back({i,j});
			}
		}
	}
	cout<<dist[gx][gy]<<endl;
}


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

using namespace std;

string s;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin >> s;
	if (s == "ABC") cout << "ARC";
	else cout << "ABC";

	return 0;
}

Measured memory_bytes: 3668
import numpy as np
n = int(input())
w = list(map(int, input().split()))
s1 = 0
s2 = 0
s = sum(w)
mn = 10000000000
         
for i in range(n):
         s1 += w[i]
         s2 = s -s1
         mn = min(mn, np.abs(s1-s2))
print(mn)

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007

int main(){
	ios::sync_with_stdio(0); 
    cin.tie(0); 
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ll a;
	cin >> a;
	ll ans = a + pow(a, 2) + pow(a, 3);
	cout << ans << "\n";
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  char x, tmp;
  int ans = 0;
  
  // x != tmp : ans += 1, tmp <- x
  // x == tmp : continue; 
  for(int i = 0; i < N; i++){
    cin >> x;
    if(i == 0){
      tmp = x;
      ans = 1;
      continue;
    }
    if(x == tmp){
      continue;
    } else {
      ans += 1; 
      tmp = x;
    }
  }
  
  cout << ans << endl;
    
}

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

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 0;i<n-1;i++)
	{
		if(s.substr(i,2)=="AC")
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main() {
 
  int N; 
  cin >> N;
  int max =0;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];
  for(int i=0;i<N;i++) max += a[i];
  int min =0;
  int b[N];
  for(int i=1;i<N;i=i+2) min += a[i];
  b[0] = ((max/2)-min)*2;
  for(int i=1;i<N;i++) b[i] = (2*a[i-1] - b[i-1]);
  for(int i=0;i<N;i++) cout << b[i] << " " ;
}
  
  

Measured memory_bytes: 2048
#include <iostream>
using namespace std;
int main(void){
    int n, a, b, total_a, total_b;
    while(1){
        cin >> n;
        if(n == 0){
            break;
        }
        total_a = 0;
        total_b = 0;
        for(int i=1; i<=n; i++){
            cin >> a >> b;
            if(a > b){
                total_a += a + b;
            }
            else if(b > a){
                total_b += a + b;
            }
            else{
                total_a += a;
                total_b += b;
            }
        }
        cout << total_a << " " << total_b << endl;
    }
    return 0;
    
}



Measured memory_bytes: 3076
count = 0

def main():
    A = list(map(int,input().split()))
    b1 = max(A)
    A.remove(b1)
    b2 = max(A)
    A.remove(b2)
    b3 = max(A)
    global count
    if b2 % 2 == b3 % 2:
        cal(b1,b2,b3)
    else:
        b1 += 1
        b2 += 1
        count += 1
        cal(b1,b2,b3)

def cal(b1,b2,b3):
    global count
    for _ in range(b2,b1):
        b2 += 1
        b3 += 1
        count += 1
    while b3 < b1:
        b3 += 2
        count += 1
    print(count)

main()


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

int n;
vector<int> par(100010);

int root(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]);
}

void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
        return;
    par[rx] = ry;
}

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

    int m;
    cin >> n >> m;

    rep(i, n) par[i + 1] = i + 1;
    rep(i, m)
    {
        int x, y,z;
        cin >> x >> y>>z;
        unite(x, y);
    }
    set<int> st;
    rep(i, n) st.insert(root(i + 1));

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

    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

    long long a, b, c;
    cin >> a >> b >> c;

    long long d = c - a - b;

    if(d<0){
        cout << "No" << endl;
    }else{
        unsigned long long dd = d;
        unsigned long long aa = a, bb = b;

        if (4 * aa * bb < dd * dd) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

}

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

using namespace std;

int n;
int a[100010];
long long total = 0;
int ans[100010];
long long prefeven[100010], prefodd[100010];

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

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

		if(i & 1) prefodd[i] += a[i];
		else prefeven[i] += a[i];

		prefodd[i] += prefodd[i - 1];
		prefeven[i] += prefeven[i - 1];
	}

	total >>= 1;

	for(int i = 1; i <= n; i++){
		if(i & 1) ans[i] = total - (prefeven[n] - prefeven[i]) - prefodd[i - 1];
		else ans[i] = total - (prefodd[n] - prefodd[i]) - prefeven[i - 1];
		
		ans[i] <<= 1;

		if(i > 1) printf(" ");
		printf("%d", ans[i]);
	}
	printf("\n");
	
	return 0;
}

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

//---------- 最大公約数 ----------
int64_t gcd(int64_t a, int64_t b){
    if (b > a) return gcd(b, a);

    if(a % b == 0) return b;
    else return gcd(b, a % b);
}

int main(){
  int64_t N, K;
  vector<int64_t> A(100010);

  cin >> N >> K; 
  for(int i=0; i<N; i++) cin >> A[i];
   
  int64_t g = A[0];
  for(int i=0; i<N; i++) g = gcd(g, A[i]);

  sort(A.begin(), A.begin()+N);

  if(A[N-1] >= K && K % g == 0){
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  
}
  
  

Measured memory_bytes: 1024
import java.util.*;
 
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long[] l = {a * c, a * d, b * c, b * d};

		Arrays.sort(l);

		System.out.println(l[3]);
	}
}

Measured memory_bytes: 35856
/*
    Author: Shivam Shukla
    Title : DP_I_Modified.cpp
    Date : 27/08/2020   >> 20:37:13
*/

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
#define INF(x) numeric_limits<x>::max()
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
    fastio();
    auto tstart= clock();
 
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      freopen("error.txt","w",stderr);
    #endif   

    int n; cin >> n;
    vc(dub) p(n); repa(i, n) cin >> p[i];

    vc(vc(dub)) dp(n + 1, vc(dub)(n + 1, 0));
    
    dp[0][0] = 1.0;
    rep(i, 1, n + 1) 
        dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);

    rep(i, 1, n + 1) {
        rep(j, 1, i + 1) {
            dp[i][j] = (dp[i - 1][j - 1] * p[i - 1]) + (dp[i - 1][j] * (1 - p[i - 1]));
        }
    }

    long double ans = 0.0;
    rep(i, (n >> 1) + 1, n + 1)
        ans += (dp[n][i]);

    cout << setprecision(10) << ans << endl;    

    cerr << setprecision(2) << fixed<<"Time elapsed: " << (double)(clock() - tstart)/CLOCKS_PER_SEC << endl; 
    return 0; 
}

Measured memory_bytes: 73756
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int MAX = 410000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
//invの要素にはiの逆元が格納されている
//前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;//i!(mod MOD)を計算
        inv[i] = MOD - inv[MOD%i]* (MOD / i) % MOD;//iの逆元を計算
        finv[i] = finv[i - 1] * inv[i] % MOD;//i!(mod MOD)の逆元を計算
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;//nCk = n!/(k!*(n-k)!)を計算
}
//例のアレ
long long nPm(int n, int m){
    if(n < m) return 0;
    if(n < 0 || m < 0) return 0;
    return fac[n] * finv[n - m] % MOD;
}
map<long long, long long> divide(long long n){//素因数分解
    map<long long, long long> res;
    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
int main(){
    int N;
    long long M;
    cin >> N >> M;
    COMinit();
    map<long long, long long> m = divide(M);
    long long ans = 1;
    for(auto v: m){
        ans = ans * COM(v.second + N - 1, v.second) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13188
#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
p=0
Q=[]
for a in A: Q.append((a,1))
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    Q.append((c,b))
Q.sort();Q.reverse()
n=0;s=0
for c,b in Q:
    if b+n<=N:
        s+=c*b
        n+=b
    else:
        s+=c*(N-n)
        break
print(s)

Measured memory_bytes: 55008
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
using ll=long long int;

int main(){
    int N;
    cin >> N;
    vector<int> vec;
    int cnt;
    int ans=0;
    for(int i=1;i<=N;i++){
        cnt=0;
        for(int j=1;j<=sqrt(i);j++){
            if(i%j==0){
                cnt++;
            }
        }
        if(cnt==4&&i%2==1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int X=stdIn.nextInt();
		int A=stdIn.nextInt();
		if(X<A)
			System.out.println(0);
		else
			System.out.println(10);
	}
}

Measured memory_bytes: 22868
#include <stdio.h>
int rec(int N, int a[])
{
    int i;
    for (i = 0; i < N; i++)
    {
        scanf("%d", &a[i]);
    }
}

int main(void) {
    int N, i, noBreak_num = 1;
    scanf("%d", &N);
    int a[N];

    rec(N, a);

    for(i=0; i<N; i++)
    {
        if(a[i] == noBreak_num)
        {
            noBreak_num++;
        }
    }

    if (noBreak_num == 1)
    {
        printf("%d", -1);
    } else {
        printf("%d", N - (noBreak_num - 1));
    }

    return 0;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()

	max := MinInt

	if max < a+b {
		max = a + b
	}
	if max < a-b {
		max = a - b
	}
	if max < a*b {
		max = a * b
	}
	fmt.Printf("%d\n", max)
}


Measured memory_bytes: 640
using System;

class Program
{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    char[] cs = s.ToCharArray();
    Array.Sort(cs);
    string t = Console.ReadLine();
    char[] ct = t.ToCharArray();
    Array.Sort(ct);
    Array.Reverse(ct);
    if (new string(cs).CompareTo(new string(ct)) == -1)
    {
      Console.WriteLine("Yes");
    }
    else
    {
      Console.WriteLine("No");
    }
  }
}


Measured memory_bytes: 18316
program ABC_051_B_SumofThreeIntegers
   implicit none
   integer X, Y, Z, K, S, countN
   read(*, *) K, S
   countN = 0
   do X = 0, K
       do Y = 0, K
	      Z = S - (X + Y)
		  if(X + Y + Z == S .and. Z >=0 .and. Z <= K ) then
			  countN = countN + 1
		  end if
	   end do
   end do
   write(*, *) countN
end program ABC_051_B_SumofThreeIntegers

Measured memory_bytes: 384
#include <cstdio>
int initial, battery, junk;
int dr[] = { -1, 0, 1, 0 }, dc[] = { 0, -1, 0, 1 };
double memo[3][3][16];
double func(int r, int c, int n)
{
	if (n == 0) return (3*r+c == battery);
	double& res = memo[r][c][n];
	if (res > -0.5) return res;

	res = 0;
	for (int i=0; i<4; ++i) {
		int nr = r + dr[i], nc = c + dc[i];
		if (nr<0 || nr>=3 || nc<0 || nc>=3 || 3*nr+nc==junk)
			res += func(r, c, n-1) / 4;
		else
			res += func(nr, nc, n-1) / 4;
	}
	return res;
}
int main()
{
	int n;
	while (scanf("%d ", &n), n) {
		for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) for (int k=0; k<16; ++k)
			memo[i][j][k] = -1;

		char s, t, b;
		scanf("%c %c %c ", &s, &t, &b);
		initial = s - 'A';
		battery = t - 'A';
		junk = b - 'A';
		printf("%.10f\n", func(initial/3, initial%3, n));
	}
	return 0;
}

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

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

Measured memory_bytes: 2560
#include <cstdio>

int Solve(int n){
	int c = 100000;
	int self;
	for(int i = 0;i < n;i++){
		c *= 1.05;
		self = c % 1000;
		if(self > 0){
			c -= self;
			c += 1000;
		}
	}
	return c;
}

int main(){
	int n;
	while(scanf("%d",&n) != EOF){
		printf("%d\n",Solve(n));
	}
	return 0;
}

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

#define lli long long int
#define Sort(n) sort(n.begin(), n.end());
#define Reve(n) reverse(n.begin(), n.end());

int main(void) {
  lli n, k, sum = 0;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0;i < n;i++) {
    cin >> h.at(i);
  }
  Sort(h);
  Reve(h);
  for(int i = k;i < n;i++) {
    sum += h.at(i);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict

def t():
    return 0

n = int(input())
a = [int(x) for x in input().split()]

counter = defaultdict(t)

for x in a:
    counter[x] += 1
# print(dict(counter))

s = sum(a)

q = int(input())
for i in range(q):
    b, c = [int(x) for x in input().split()]
    s = s - b*counter[b] + c*counter[b]
    print(s)
    counter[c] += counter[b]
    counter[b] = 0
    # print(dict(counter))


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);
    if (a + b <= a + c && a + b <= b + c) {
        printf("%d",a+b);
    } else if (a + b >= a + c && c + b >= a + c) {
        printf("%d",a+c);
    } else {
        printf("%d",c+b);
    }
}









Measured memory_bytes: 3764
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
	ll a, b, c; cin >> a >> b >> c;
	cout << min({ a + b,b + c,c + a }) << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> xy(n);
    vector<ll> x(n), y(n);
    for(int i = 0; i < n; ++i){
        ll xi, yi;
        cin >> xi >> yi;
        xy.at(i) = make_pair(xi, yi);
        x.at(i) = xi;
        y.at(i) = yi;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    ll ans = (x.back() - x.front()) * (y.back() - y.front());
    for(int xsi = 0; xsi < n; ++xsi){
        for(int xei = xsi + 1; xei < n; ++xei){
            for(int ysi = 0; ysi < n; ++ysi){
                for(int yei = ysi + 1; yei < n; ++yei){
                    const ll xs = x.at(xsi);
                    const ll xe = x.at(xei);
                    const ll ys = y.at(ysi);
                    const ll ye = y.at(yei);
                    ll count = 0;
                    for(auto p : xy){
                        if(xs <= p.first && p.first <= xe &&
                           ys <= p.second && p.second <= ye){
                            count++;
                        }
                    }
                    const ll area = (xe - xs) * (ye - ys);
                    if(count >= k){
                        ans = min(ans, area);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ll x;
    cin >> x;
    auto p=[](ll a)
    {
        ll res=1;
        for(int i=1;i<=5;i++) res*=a;
        return res;
    };
    for(ll i=-200;i<=200;i++)
    {
        for(int j=-200;j<=200;j++)
        {
            if(p(i)-p(j)==x)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3624
N = int(input())
S = {}
for i in range(N):
    s = input()
    if s in S.keys():
        S[s] += 1
    else:
        S[s] = 1
M = int(input())
T = {}
for i in range(M):
    t = input()
    if t in T.keys():
        T[t] += 1
    else:
        T[t] = 1

ans = 0
for key in S:
    if key in T.keys():
        ans_ = S[key] - T[key]
    else:
        ans_ = S[key]
    ans = max(ans, ans_)

print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0;i<(n);i++)
const int INF = 1001001001;
int n, u, k;
int D[100];
vector<int> edges[100];
void bfs(int src) {
	
	
	queue<int> Q;	
	Q.push(src);
	D[src] = 0;//D[*]が始点から点*への距離
	while (!Q.empty()) {
		int cur = Q.front();//curは今取り扱ってる点
		Q.pop();
		
		for (int dst = 0; dst < n; dst++) {//dstはcurから移動可能な点
			vector<int>::iterator result = find(edges[cur].begin(), edges[cur].end(), dst);
			if (result != edges[cur].end() && D[dst] == INF) {
				D[dst] = D[cur] + 1;
				Q.push(dst);
			}
		}
	}
}

int main() {
	cin >> n; //n頂点
	

	for (int i = 0; i < n; i++)//iは頂点
	{
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			int l;
			cin >> l;
			edges[u - 1].push_back(l-1);
		}//入力終わり
		D[i] = INF;
	}
		bfs(0);
	for (int i = 0; i < n; i++) {
		if (D[i] != INF)cout << i + 1 << " " << D[i] << endl;
		else cout << i + 1 << " " << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3160
using System;

class Program
{
    static long N;
    static long X;

    static void Main(string[] args)
    {
        Console.Write(MysteriousLightEmulator());
    }

    private static string MysteriousLightEmulator()
    {
        readData();

        return LightLength().ToString();
    }

    /// <summary>
    /// データを読み込む
    /// </summary>
    private static void readData()
    {
        string[] line = Console.ReadLine().Split(' ');

        N = long.Parse(line[0]);

        X = long.Parse(line[1]);
    }

    private static long LightLength()
    {
        return forwardRay() + backRay();
    }

    private static long forwardRay()
    {
        return N;
    }

    private static long backRay()
    {
        long l = 0;
        long traiangleSize = N - X < X ? N - X : X;
        long n = N - traiangleSize;

        while (n > 0 && traiangleSize > 0)
        {
            l += goUp(ref n, traiangleSize);

            long tmp = n;
            n = traiangleSize;
            traiangleSize = tmp;
        }

        return l;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="n">移動距離</param>
    /// <param name="t">三角形の一辺の長さ</param>
    /// <returns></returns>
    private static long goUp(ref long n, long t)
    {
        long p = n / t;

        n = n - t * p;

        return n == 0 ? 2 * t * p - t : 2 * t * p;
    }

}



Measured memory_bytes: 11092
H, W, K=map(int,input().split())
x=[input() for i in range(H)]
x=list(map(list,x))
ans=0
for i in range(2**H):
  for j in range(2**W):
    count=0
    for l in range(H):
      for m in range(W):
        if i>>l&1 and j>>m&1 and x[l][m]=="#":
          count+=1
    if count==K:
      ans+=1
print(ans)

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

int main()
{
    string s;cin>>s;
    vector<string> day={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    int i;
    for(i=0;i<7;i++)
    {
        if(day.at(i)==s)cout<<7-i<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    t=1;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        string s[n];
        for(int i=0;i<n;i++)cin>>s[i];
        ll arr[n][m];
        if(s[0][0]=='#')
            arr[0][0]=1;
        else
            arr[0][0]=0;
        for(int i=1;i<n;i++)
        {
           arr[i][0]=arr[i-1][0];
           if(s[i][0]=='#')
           {
               if(s[i-1][0]!='#')
                arr[i][0]++;
           }
        }
        for(int i=1;i<m;i++)
        {
            arr[0][i]=arr[0][i-1];
            if(s[0][i]=='#' && s[0][i-1]!='#')
                arr[0][i]++;
        }
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<m;j++)
            {
                arr[i][j]=min(arr[i-1][j],arr[i][j-1]);
                if(s[i][j]=='#')
                {
                    ll a=arr[i-1][j];if(s[i-1][j]=='.')a++;
                    ll b=arr[i][j-1];if(s[i][j-1]=='.')b++;
                    arr[i][j]=min(a,b);
                }
            }
        }
        cout<<arr[n-1][m-1];
    }
}


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

int main()
{
	int m, f, r;
	while (1)
	{
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)
			break;
		if (m == -1 || f == -1 || m + f < 30)
			cout << 'F' << endl;
		else if (m + f >= 80)
			cout << 'A' << endl;
		else if (m + f >= 65)
			cout << 'B' << endl;
		else if (m + f >= 50 || (m + f >= 30 && r >= 50))
			cout << 'C' << endl;
		else 
			cout << 'D' << endl;
	}
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


using Weight=int;
struct Edge{
  int src,dst;
  Weight weight;
  Edge():src(0),dst(0),weight(0){}
  Edge(int s,int d,Weight w):src(s),dst(d),weight(w){}
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;

pair<int,int> dfs(const Graph &g,int idx,int par){
  pair<int,int>ret(0,idx);
  for(auto &e:g[idx]){
    if(e.dst==par)continue;
    auto cost=dfs(g,e.dst,idx);
    cost.first+=e.weight;
    ret=max(ret,cost);
  }
  return ret;
}
int TreeDiamiter(const Graph&g){
  auto p=dfs(g,0,-1);
  auto q=dfs(g,p.second,-1);
  return q.first;
}


signed main(){
  int n;
  cin>>n;
  Graph g(n);
  REP(i,n-1){
    int s,t,w;
    cin>>s>>t>>w;
    g[s].emplace_back(s,t,w);
    g[t].emplace_back(t,s,w);
  }
  cout<<TreeDiamiter(g)<<endl;
  return 0;
}



Measured memory_bytes: 19152
#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) sort(a.rbegin(),a.rend())
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(UI i=0;i<n;i++)

int main(int argc, const char * argv[]) {

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

	LL N, M;
	LL sum = 0;

	cin >> N >> M;

	vector<LL>X((UI)M);

	rep(i,M) {
		cin >> X.at(i);
	}

	Sort(X);
	vector<LL>Y;

	for(UI i=0;i + 1 < X.size();i++){
		Y.push_back(X[i + 1] - X[i]);
	}

	rSort(Y);

	for(UI i=0;i < N - 1 && i < Y.size();i++){
		sum += Y[i];
	}

	cout << X.back() - X.front() - sum << endl;

	return 0;

}

Measured memory_bytes: 2168
import sys
N=input()
A=[None]+map(int, sys.stdin.readline().split())
B=[None]+map(int, sys.stdin.readline().split())
C=[None]+map(int, sys.stdin.readline().split())

ans=0
prev=None
for a in A:
    if a is None: continue
    ans+=B[a]
    if prev is not None and prev+1==a:
        ans+=C[prev]
    prev=a

print ans

Measured memory_bytes: 28012
//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000007
#define OO 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

vector <int> rep, sz;

int numOfCon;

int findu(int u){
    return (rep[u] == u) ? u : rep[u] = findu(rep[u]);
}

void join(int a, int b){
    a = findu(rep[a]);
    b = findu(rep[b]);
    if(a == b)
        return;
    if(sz[a] < sz[b])
        swap(a, b);
    rep[b] = a;
    sz[a] += sz[b];
    --numOfCon;
}

struct edge{
    pair<ll, ll> from, to;
};

int main() {
    Data_Nerd

    ll n; cin >> n;

    vector <pair<ll, ll>> sx, sy;

    map <pair<ll, ll>, ll> mp;

    for(int i = 0; i < n; ++i){
        ll a, b; cin >> a >> b;
        sx.push_back({a, b});
        sy.push_back({b, a});
        mp[{a, b}] = i;
    }

    sort(sx.begin(), sx.end());
    sort(sy.begin(), sy.end());

    map<ll, vector<edge>> mpp;

    for(int i = 0; i < n - 1; ++i){
        pair<ll, ll> fromx = {sx[i].first, sx[i].second};
        pair<ll, ll> tox = {sx[i + 1].first, sx[i + 1].second};
        pair<ll, ll> fromy = {sy[i].second, sy[i].first};
        pair<ll, ll> toy = {sy[i + 1].second, sy[i + 1].first};
        mpp[abs(sx[i].first - sx[i + 1].first)].push_back({fromx, tox});
        mpp[abs(sy[i].first - sy[i + 1].first)].push_back({fromy, toy});
    }

    rep.resize(n + 1);
    sz.resize(n + 1);

    for(int i = 1; i <= n; ++i)
        rep[i] = i, sz[i] = 1;

    ll res = 0;

    for(auto i : mpp){
        for(int j = 0; j < i.second.size(); ++j){
            pair<ll, ll> from(i.second[j].from), to(i.second[j].to);
            if(findu(mp[from]) == findu(mp[to]))
                continue;
            join(mp[from], mp[to]);
            res += i.first;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 26200