akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 307, INF = 1e18;
int n, m;
string a[N];

int p[2 * N][N];
int dp[N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    function <int(string, string)> solve = [&](string s, string t) {

        for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) dp[i][j] = INF;

        for (int sh = -n; sh <= n; ++sh) {
            for (int i = 0; i < n; ++i) {
                p[sh + n][i + 1] = p[sh + n][i] + (0 <= i + sh && i + sh < n && s[i] == t[i + sh]);
            }   
        }   

        dp[0][0] = 0;
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= n; ++j) {
                int add = p[i - j + n][n - i];
                if (i < n) {
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + add);
                }
                if (j < n) {
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + add);
                }
            }   
        }   
        return dp[n][n];
        
    };  

    int ans = 0;            
    for (int j = 0; j < m - 1; ++j) {
        string s, t;
        for (int i = 0; i < n; ++i) {
            s += a[i][j];
            t += a[i][j + 1];
        }   
        ans += solve(s, t);
    }   
    cout << ans << endl;
}


Measured memory_bytes: 5924
def make_num(a, b):
    num = ""
    for i in range(b):
        num += str(a)
    return num

def slove(a, b):

    num1 = make_num(a, b)
    num2 = make_num(b, a)
    
    return min(num1, num2)

if __name__ == "__main__":

    a, b = [int(i) for i in input().split()]
    ans = slove(a, b)
    print(ans)

Measured memory_bytes: 3060
z[2002],*a=z,*b=z+999,m,i,j,t,u;main(n){for(;m=scanf("%d",&n)-++n;printf("%d\n",m))for(i=n;i--;j=a,a=b,b=j)for(j=n;j--;t>m?m=t:0)b[j]=t=n+~i&&getchar()>45?1+fmin(u=a[j],t<u?t:u):0;}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b;
    string s;
    cin >> a >> s >> b;

    if(s.at(0)=='+') cout << a + b << endl;
    else cout << a - b << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string s;cin >> s;
    bool cc = false;
    bool ff = false;

    rep(i,s.size()){
        if(s[i] == 'C'){
            cc = true;
        }
        if(cc){
            if(s[i] == 'F'){
                ff = true;
            }
        }
    }

    if(ff)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t n,ans=0;
  cin>>n;
  vector<int64_t>a(n);
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  sort(a.begin(),a.end());
  int64_t k=0,j=n-1;
  while(k<n){
  	if(k>0){
        ans+=a[j];
    	if(k%2==1) j--;
    }
    k++;
  }
  cout<<ans;
}

Measured memory_bytes: 4840
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, m; cin>>n>>m;
    vector<vector<int>> G(n);
    for(int i=0; i<m; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    vector<int> v(n);
    iota(v.begin(), v.end(), 0);

    int ans = 0;
    do{
        if(v[0] != 0) continue;

        bool valid = true;
        for(int i=0; i<n-1; i++){
            int cv = v[i];
            int nv = v[i+1];

            bool can_go = false;
            for(int j:G[cv]){
                if(j == nv) can_go = true;
            }

            if(!can_go) valid = false;
        }

        ans += valid;

    }while(next_permutation(v.begin(), v.end()));

    cout << ans << endl;
}

Measured memory_bytes: 256
n = list(input())
n[0] = int(n[0])
n[1] = int(n[1])
n[2] = int(n[2])
while (not (n[0] == n[1] == n[2])):
    if n[2] == 10:
        n[2] = 0
        n[1] = int(n[1])+1
    if n[1] == 10:
        n[1] = 0
        n[0] = int(n[0])+1
    n[2] = int(n[2]) + 1
print(n[0]*100+n[1]*10+n[2])

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

int main(){
	ll n, m, r; cin >> n >> m >> r;
	ll dp[n][n];
	for(ll i = 0; i < n; ++i)
		for(ll j = 0; j < n; ++j)dp[i][j] = (i == j ? 0 : 1145141919);

	vector<ll> rr;
	for(ll i = 0; i < r; ++i){
		ll a; cin >> a;
		rr.push_back(--a);
	}

	sort(rr.begin(), rr.end());
	for(ll i = 0; i < m; ++i){
		ll a, b; cin >> a >> b;
		cin >> dp[--a][--b];
		dp[b][a] = dp[a][b];
	}

	for(ll i = 0; i < n; ++i)
		for(ll j = 0; j < n; ++j)
			for(ll k = 0; k < n; ++k) dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
	ll ans = 1145141919;
	do{
		ll dist = 0;
		for(ll i = 0; i < rr.size() - 1; ++i) dist += dp[rr[i]][rr[i + 1]];
		ans = min(dist, ans);
	}while(next_permutation(rr.begin(), rr.end()));

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

Measured memory_bytes: 512
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;
const ll oo=1ll<<60;

int A[N],B[N];
int X,n,q,t,a,x;
ll b2,l2,r2,b[N],l[N],r[N];

void Dec(ll &b,ll &l,ll &r,int v){
	b-=v;
	l=max(l,-b);
	r=max(r,-b);
}
void Inc(ll &b,ll &l,ll &r,int v){
	b+=v;
	l=min(l,X-b);
	r=min(r,X-b);
}

int main(){
	X=IN(),n=IN();
	For(i,1,n+1) A[i]=B[i]=IN();
	for (int i=n;i;i--) A[i]-=A[i-1];
	b[0]=0;l[0]=0;r[0]=oo;
	For(i,1,n+1){
		b[i]=b[i-1];
		l[i]=l[i-1];
		r[i]=r[i-1];
		if (i&1){
			Dec(b[i],l[i],r[i],A[i]);
		} else{
			Inc(b[i],l[i],r[i],A[i]);
		}
	}
	for (int q=IN();q--;){
		t=IN(),a=IN();
		x=upper_bound(B+1,B+n+1,t)-B-1;
		b2=b[x];
		l2=l[x];
		r2=r[x];
		if (x&1){
			Inc(b2,l2,r2,t-B[x]);
		} else{
			Dec(b2,l2,r2,t-B[x]);
		}
		if (a<l2){
			printf("%lld\n",l2+b2);
		} lf (a<r2){
			printf("%lld\n",a+b2);
		} else{
			printf("%lld\n",r2+b2);
		}
	}
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
 
int main(){
  int n,w;
  cin>>n>>w;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  vector<vector<long long>> dp(n+100,vector<long long>(w+100));
  for(int i=0;i<n;i++){
    for(int j=0;j<w+10;j++){
      if(j>=a[i]){
        dp[i+1][j]=max(dp[i][j],dp[i][j-a[i]]+b[i]);
      }
      else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout<<dp[n][w]<<endl;
}

      


Measured memory_bytes: 157824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> coin(m);
    REP(i,m){
        scanf("%d", &coin[i]);
    }

    vector<int> dp(n + 1,inf);
    dp[0] = 0;
    REP(i,m){
        REP(j,n+1-coin[i]){
            dp[j + coin[i]] = min(dp[j + coin[i]], dp[j] + 1);
        }
    }
    cout << dp[n] << endl;

    return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	ll a[n];
	rep(i,n) cin >> a[i];

	cout << a[n-1];
	for(int i = n-3;i>=0;i-=2)  cout << " " << a[i];
	if(n % 2 == 0){
		for(int i = 0;i<n;i+=2) cout << " " << a[i];
	}else{
		for(int i = 1;i<n;i+=2) cout << " " << a[i];
	}
	
	cout << endl;
}

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

#define int long long 

struct Data {
  int val, num;
  bool operator < (const Data &d) const {
    if(val < d.val) return (true);
    if(val > d.val) return (false);
    return (num < d.num);
  }
};

struct Bit {
  
  vector < int > data;
  
  Bit(int n) {
    data.assign(n + 114, 0);
  }
  
  void add(int k, int val) {
    for(++k; k <= data.size(); k += k & -k) data[k] += val;
  }
  
  int query(int k) {
    int ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }
  
};

#define SIZE (200005)

Data getData(int num);

int n, k;
int pos[SIZE];
int ans = 0;

Data sum[SIZE];


main()
{ 
  Bit tree(SIZE);
  
  cin >> n >> k;
  
  tree.add(0, 1); sum[0] = (Data) { 0, 0 };
  for(int i = 1; i <= n; i++) {
    sum[i] = getData(i);
    sum[i].val += sum[i - 1].val - k;
    tree.add(i, 1);
  }

  sort(sum, sum + n + 1);

  for(int i = 0; i <= n; i++) pos[sum[i].num] = i;

  for(int i = 0; i <= n; i++) {
    ans += tree.query(n) - tree.query(pos[i]);
    tree.add(pos[i], -1);
  }

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

Data getData(int num)
{
  Data data;
  cin >> data.val; data.num = num;
  return (data);
}


Measured memory_bytes: 6528
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let r = scan!(i64);
    let g = scan!(i64);

    println!("{}", 2 * g - r)
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
	int n;
	cin >> n;
	int q, k;
	vector < vector<pair<int, long long>>> vec(n + 10);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		long long c;
		cin >> a >> b >> c;
		vec[a].emplace_back(make_pair(b, c));
		vec[b].emplace_back(make_pair(a, c));
	}
	priority_queue<pair<long long, int>,vector<pair<long long, int>>,greater<pair<long long, int>>> que;
	long long co[100010];
	for (int i = 0; i < 100010; i++) {
		co[i] = 10000000000000007;
	}
	cin >> q >> k;
	que.push(make_pair(0, k));
	while (!que.empty()) {
		long long y = que.top().first;
		int x = que.top().second;
		que.pop();
		for (int i = 0; i < vec[x].size(); i++) {
			if (y + vec[x][i].second < co[vec[x][i].first]) {
				co[vec[x][i].first] = y + vec[x][i].second;
				que.push(make_pair(y + vec[x][i].second, vec[x][i].first));
			}
		}
	}
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		cout << co[l] + co[r] << endl;
	}
	return 0;
}


Measured memory_bytes: 11120
#include <stdio.h>
#define bit(n,m)(((n)>>(m))&1)

unsigned long f;
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		int t,x;
		scanf("%d",&t);
		if(t<4)scanf("%d",&x);
		switch(t){
			case 0:
				printf("%lu\n",bit(f,x));
				break;
			case 1:
				f|=1UL<<x;
				break;
			case 2:
				f&=~(1UL<<x);
				break;
			case 3:
				f^=1UL<<x;
				break;
			case 4:
				printf("%d\n",!(f+1));
				break;
			case 5:
				printf("%d\n",f!=0);
				break;
			case 6:
				printf("%d\n",f==0);
				break;
			case 7:
				printf("%d\n",__builtin_popcountll(f));
				break;
			case 8:
				printf("%lu\n",f);
				break;
		}
	}
}


Measured memory_bytes: 2112
ans = 0
N = int(input())
blue = []
for i in range(N):
    blue.append(input())
M = int(input())
red = []
for i in range(M):
    red.append(input())

for word in set(blue):
    ans_n = blue.count(word) - red.count(word)
    if ans_n > ans:
        ans = ans_n
print(ans)


Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, M, A, B, P, Q = map(int, readline().split())
    ans = M
    if A == B == 1:
        v = P+Q
        k = min(N, M // v)
        ans = min(ans, M - k*v)
        if k+1 <= N:
            ans = min(ans, (k+1)*v - M)
    else:
        k = 0
        V = []
        va = 1; vb = 1
        while k < N:
            v = P*va + Q*vb
            V.append(v)
            if v > M:
                break
            va *= A; vb *= B
            k += 1
        def make(S):
            s = {0}
            for v in S:
                t = set(s)
                for e in s:
                    t.add(e + v)
                s = t
            return sorted(s)
        L = len(V)
        S0 = make(V[:L//2]); S1 = make(V[L//2:])
        t = len(S1)-1
        for s0 in S0:
            while t > 0 and s0 + S1[t] > M:
                t -= 1
            if s0 + S1[t] <= M:
                ans = min(ans, M - s0 - S1[t])
        t = len(S1)-1
        for s0 in S0:
            while t > 0 and s0 + S1[t-1] >= M:
                t -= 1
            if s0 + S1[t] >= M:
                ans = min(ans, s0 + S1[t] - M)
    write("%d\n" % ans)
solve()


Measured memory_bytes: 217936
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int N;
    cin >> N;
    vector<ll> R(N);
    for(int i = 0; i < N; i++) cin >> R[i];
    ll min_n = R[0];
    ll max_n = -LL_INF;
    for(int i = 1; i < N; i++){
        max_n = max(max_n, R[i] - min_n);
        min_n = min(min_n, R[i]);
    }
    cout << max_n << endl;
}



Measured memory_bytes: 4372
import sys
A , B = map(int,input().split())

socket = 0
count  = 0
#最初についている1口で足りるとき
if B == 1:
	print(0)
	sys.exit()

#電源タップを追加する時
while True:
	count  += 1
	socket += A-1
	if B - socket <= 1:
		print(count)
		sys.exit()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  string str;
  cin >> N >> str;
  int sum=1;
  for(int i=0;i<N-1;i++){
    if(str.at(i)!=str.at(i+1)){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 = 998244353;
ll N;
string X;
vector<ll> divisors;
vector<ll> ans;

ll g(string X) {
    ll tmp = 0;
    for(int i = 0; i < X.size(); i++) {
        tmp *= 2;
        if(X[i] == '1') tmp++;
        tmp %= mod;
    }
    return tmp;
}

int main() {
    cin >> N >> X;
    for(ll i = 1; i * i <= N; i++) {
        if(N % i != 0) continue;
        int j = N / i;
        if(j&1) divisors.push_back(i);
        if(i&1) divisors.push_back(j);
    }
    sort(divisors.begin(), divisors.end());
    divisors.erase(unique(divisors.begin(), divisors.end()), divisors.end());
    ans.resize(divisors.size());
    ll sum = 0;
    for(int i = 0; i < divisors.size(); i++) {
        ans[i] = g(X.substr(0, divisors[i]));
        string T = X.substr(0, divisors[i]);
        string rev = T;
        for(auto &c : rev) {
            if(c == '1') c = '0';
            else c = '1';
        }
        for(int j = 1; ; j++) {
            if(T.size() == X.size()) break;
            if(j & 1) T += rev;
            else T += X.substr(0, divisors[i]);
        }
        //cerr << i << " " << divisors[i] << " " << T << endl;
        if(T <= X) ans[i]++;
        for(int j = 0; j < i; j++) {
            if(divisors[i] % divisors[j] == 0) ans[i] -= ans[j];
            ans[i] += mod;
            ans[i] %= mod;
        }
        //cerr << i << " " << divisors[i] << " " << ans[i] << endl;
        sum += divisors[i] * 2 * ans[i];
        sum %= mod;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1076
n,m=map(int,input().split())
d,c,wa=[0]*n,0,0
for _ in range(m):
    p,a=input().split()
    p=int(p)-1
    if d[p]!=-1:
        if 'W' in a:
            d[p]+=1
        else:
            wa+=d[p]
            d[p]=-1
            c+=1
print(c,wa)

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

end = w[0][-1]
flag = 0

memo={}
memo[w[0]] = "_"

for i in range(1,n):
  if w[i] in memo:
    flag=1
    break
  memo[w[i]] = "_"
  start = w[i][0]
  if end != start:
    flag = 1
    break
  else:
    end = w[i][-1]
    
if flag == 1:
  print("No")
else:
  print("Yes")
  

Measured memory_bytes: 3064
def f():
    K, A, B = map(int, input().split())

    if A+1 >= B:
        print(K+1)
        return

    if K <= A:
        print(K+1)
        return

    res = A

    K -= A-1
    if K % 2 == 1:
        res += 1
        K -= 1

    res += (K//2) * (B-A)
    
    print(res)
    return

f()

Measured memory_bytes: 9140
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll sign(ll a){
    if(a>0){return 1;}
    if(a<0){return -1;}
    return 0;
}

ll count(vector<ll> a){
    if(a.size()==0){return 0;}
    ll ret=1;
    vector<ll> b={a[0]};
    for(int i=1;i<a.size();i++){
        if(a[i]!=b[b.size()-1]){
            b.push_back(a[i]);
        }
    }
    if(b.size()==1){return 1;}
    ll k=sign(b[1]-b[0]);
    for(int i=2;i<b.size();i++){
        if(sign(b[i]-b[i-1])!=k){
            ret++;
            if(b.size()==i+1){return ret;}
            else{
                k=sign(b[i+1]-b[i]);
            }
        }
    }
    return ret;
}



int main(){
    ll n;
    cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
    }
    cout<<count(a)<<endl;
    
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  bool p, w, g, y = false;
  
  for (int i = 1; i <= N; i++) {
    char A;
    cin >> A;

    if (A == 'P') {
      p = true;
    } else if (A == 'W') {
      w = true;
    } else if (A == 'G') {
      g = true;
    } else if (A == 'Y') {
      y = true;
    }
  }
  
  int count = p + w + g + y;
  
  if (count == 3) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}



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

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
int n, a[300005], s[300005];
bool b[300005];
int main(){
	scanf("%d", &n);
	for (register int i = 0; i < (1 << n); ++i) scanf("%d", a + i);
	std :: sort(a, a + (1 << n)), std :: reverse(a, a + (1 << n));
	b[0] = 1, s[0] = a[0];
	for (register int i = 0; i < n; ++i){
		int sz = 1 << i, k = 0;
		for (register int j = 0; j < (1 << n); ++j)
			if (!b[j] && k < sz && a[j] < s[k]) s[sz + k] = a[j], b[j] = 1, ++k;
		if (k < sz) return puts("No"), 0;
		std :: sort(s, s + (sz << 1)), std :: reverse(s, s + (sz << 1));
	}
	printf("Yes\n");
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll h, w;
	cin >> h >> w;
	string  s[h];
	zep(i, 0, h){
		cin >> s[i];
	}
	
	bool bh[h], bw[w];
	memset(bh, 0, sizeof(bh));
	memset(bw, 0, sizeof(bw));
	
	zep(i, 0, h){
		zep(j, 0, w){
			if(s[i][j] == '#'){
				bh[i] = true;
				bw[j] = true;
			}
		}
	}
	
	zep(i, 0, h){
		zep(j, 0, w){
			if(bh[i] && bw[j]){
				cout << s[i][j];
			}
		}
		if(bh[i]){
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 
#endif

#define df(b, e) ((b) > (e))
#define fore(i, b, e) for (auto i = (b) - df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rm(int l, int r) {
  uniform_int_distribution<int> dis(l, r); 
  return dis(rng);
}

using ulli = unsigned long long;
using lli = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;

const int N = 4e5 + 5;
lli n, mod, rootAns[N], ans[N];
vector<int> graph[N], pre[N], suf[N];

void dp(int u, int pr = -1) {
  rootAns[u] = 1;
  for (int v : graph[u])
    if (v != pr) {
      dp(v, u);
      (rootAns[u] *= ((rootAns[v] + 1) % mod)) %= mod;
    } 
}

void getPre(int u, int pr = -1) {
  for (int v : graph[u])
    if (v != pr) {
      if (sz(pre[u]))
        pre[u].pb((pre[u].back() * (rootAns[v] + 1)) % mod);
      else 
        pre[u].pb((rootAns[v] + 1) % mod);
      getPre(v, u);
    }
}

void getSuf(int u, int pr = -1) {
  for (int v : graph[u])
    if (v != pr) {
      if (sz(suf[u]))
        suf[u].pb((suf[u].back() * (rootAns[v] + 1)) % mod);
      else 
        suf[u].pb((rootAns[v] + 1) % mod);
      getSuf(v, u);
    }
}

void reroot(int u, int pr = -1, int acc = 1) {
  bool pastParent = false;
  fore (j, 0, sz(graph[u])) {
    int v = graph[u][j];
    if (v == pr)
      pastParent = true;
    if (v != pr) {
      int i = j - pastParent;
      ans[v] = rootAns[v] % mod;
      debug(u, v);
      debug(sz(pre[u]), i);
      debug(pre[u]);
      debug(suf[u]);
      lli excluded = 1;
      if (sz(pre[u]) >= i && i > 0) {
        (excluded *= pre[u][i - 1]) %= mod;
        debug(ans[v]);
      }
      if (sz(suf[u]) >= i + 1 && i < sz(suf[u]) - 1) {
        (excluded *= suf[u][i + 1]) %= mod;
        debug(ans[v]); 
      }
      debug(excluded, acc);
      (ans[v] *= ((excluded * acc) % mod + 1) % mod) %= mod;
      reroot(v, u, ((excluded * acc) % mod + 1) % mod);
    }
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);
  
  cin >> n >> mod;
  // mod = 1e9;

  fore (i, 0, n - 1) {
    int u, v;
    cin >> u >> v;
    graph[u].pb(v);
    graph[v].pb(u);
  }

  #ifdef LOCAL
  fore (u, 1, n + 1) {
    dp(u);
    debug(u, rootAns[u]);
  }
  #endif

  dp(1);
  
  getPre(1);

  fore (u, 1, n + 1) 
    reverse(all(graph[u]));

  getSuf(1);

  fore (u, 1, n + 1) {
    reverse(all(graph[u]));
    reverse(all(suf[u]));
  }

  reroot(1);

  cout << rootAns[1] << '\n';
  fore (u, 2, n + 1)
    cout << ans[u] % mod << '\n';
  return 0;
}


Measured memory_bytes: 48540
N = int(input())
a = []
for i in range(N):
    a.append(input())


ans = 1

if len(a) != len(set(a)):
    ans = 0

for i in range(0, N-1):
    if a[i][-1] != a[i+1][0]:
        ans = 0

if ans == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 10000;

vector<int> g[MAX_V];

int N;
vector<int> c;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  c.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int ai, bi;
    cin >> ai >> bi;
    ai--;
    bi--;
    g[ai].push_back(bi);
    g[bi].push_back(ai);
  }
  for (int i = 0; i < N; i++) {
    cin >> c[i];
  }
  sort(c.begin(), c.end(), greater<int>());

  int sum = 0;
  vector<int> vals(N, 0);
  int cur = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (vals[v] != 0) {
      continue;
    }
    vals[v] = c[cur];
    cur++;
    sum += vals[v];
    for (int i = 0; i < g[v].size(); i++) {
      q.push(g[v][i]);
    }
  }

  cout << sum - c[0] << endl;
  for (int i = 0; i < N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << vals[i];
  }
  cout << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int s[2005],n,nr=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    sort(s+1,s+n+1);
    for(int i=1;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<=n;k++)
            {
                if(s[i]+s[j]>s[k])
                    nr++;
            }
        }
    }
    cout<<nr;
    return 0;
}


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

int main() {
  int N, ans = 0;
  string S;
  string R = "ABC";
  cin >> N;
  cin >> S;
  for (int i = 0; i < N - 2; i++) {
    bool check = true;
    for (int j = 0; j < 3; j++) {
      if (S[i + j] != R[j]) {
        check = false;
      }
    }
    if (check) {
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long cub(int x) {
    return 1ll * x * x * x;
}

int main() {
    int n, k;
    cin >> n >> k;
    if (k & 1) {
        cout << cub(n/k) << endl;
    } else {
        k /= 2;
        cout << cub((n+k)/k/2) + cub(n/k/2) << endl;
    }

    return 0;
}


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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))



int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,M,RN;
    cin >>N>>M>>RN;

    int rs;
    vector<int> r(RN);
    rep(i,RN){
        cin >> rs;
        r[i]=rs-1;
    }
    vector<vector<ll>> cost(N,vector<ll>(N,LLINF));

    rep(i,N){
        cost[i][i]=0;
    }
    int a,b,c;
    rep(i,M){
        cin >> a>>b>>c;
        a--;b--;
        cost[a][b]=c;
        cost[b][a]=c;
    }
    rep(rel,N)rep(a,N){
        rep(b,N){
            if(cost[a][rel]==LLINF||cost[rel][b]==LLINF)continue;
            ll nc=cost[a][rel]+cost[rel][b];
            if(nc<cost[a][b]){
                cost[a][b]=nc;
            }
        }
    }

    //printf("ee\n");
    //-----------------------------------
    vector<int> v(RN,0);
    iota(v.begin(),v.end(),0);
    
    ll ans=LLINF;
    do {
        ll sm=0;
        rep(i,RN-1){
            sm+=cost[r[v[i]]][r[v[i+1]]];
        }
        chmin(ans,sm);
    } while (std::next_permutation(v.begin(), v.end()));

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

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
  
  	vector<int> check(3);
  		check.at(0)=a;
		check.at(1)=b;
		check.at(2)=c;
  	sort(check.begin(),check.end());
  
  	if(check.at(2)==check.at(0)+check.at(1)){
      cout << "Yes" <<endl;
    }
    else
      cout << "No" <<endl;
  
}


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

int main()
{
    int64_t N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> AAcc(N + 1), BAcc(M + 1);
    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++)
    {
        cin >> AAcc[i + 1];
        AAcc[i + 1] += AAcc[i];
    }
    for (int64_t i = 0; i < M; i++)
    {
        cin >> BAcc[i + 1];
        BAcc[i + 1] += BAcc[i];
    }
    int64_t i = 0, j = M;
    while (i <= N)
    {
        while(j >= 0 && AAcc[i] + BAcc[j] > K){
            j--;
        }
        if(j >= 0){
            ans = max(ans, i + j);
        }
        i++;
    }
    cout << ans << endl;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int dsu[100001], ranks[100001], arr[100001];

int find(int node){
    if(dsu[node] == node)
        return node;
    return dsu[node] = find(dsu[node]);
}

void combine(int a, int b){
    a = find(a); b = find(b);
    if(a == b) return;
    if(ranks[a] < ranks[b]){
        dsu[a] = b;
    } else if(ranks[b] < ranks[a]){
        dsu[b] = a;
    } else {
        dsu[a] = b;
        ranks[b]++;
    }
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < n; ++i){
        cin >> arr[i];
        arr[i]--;
        dsu[i] = i;
    }

    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        combine(a - 1, b - 1);
    }

    int tot = 0;
    for(int i = 0; i < n; ++i){
        if(find(arr[i]) != find(i)) continue;
        ++tot;
    }

    cout << tot;

    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong H1, H2, M1, M2, K;

  cin >> H1 >> M1 >> H2 >> M2 >> K;

  llong a = H1 * 60 + M1;
  llong b = H2 * 60 + M2;

  cout << b - a - K << endl;

  return 0;
}

Measured memory_bytes: 3632
/*------------------------Original Copyright belongs to-------------------------/
!      																			!
!      ##  ##                                                		##  ##	    !
!      #   #             											#   #		!		                
!      				 ###  ####  ###   ###     ##         #                      !
!					#     #  #  #  #  #  #   #  #       ##                      !
!					#	  #  #  ###   ###    ####        #                      !
!					#     #  #  #  #  #  #   #  #        #                      !
!					 ###  ####  ###   #   #  #  #  ###  ### 			        !
!                                                                               !
/------------------------------------------------------------------------------*/
#include<bits/stdc++.h>
using namespace std;
//------------Template begins--------------------//
#define ss string
#define last(s) s.length()-1
#define lli long long int
#define v(type) vector<type>
#define pr(type1,type2) pair<type1,type2>
#define ma(type1,type2) map<type1,type2>
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define L(i,start,end) for(lli i=start;i<=end;i++)
#define R(i,start,end) for(lli i=start;i>=end;i--)
#define inp(var,start,end,array) for(var=start;var<=end;var++) cin>>array[var];
#define whatIs(x) cout<<#x<<" is "<<x<<endl
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for (lli i=s1;i<=e1;i++) {cout<<i<<"th :"; for(lli j=s2;j<e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}

lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
const lli LINF = 1e18;
const lli INF = 1e9;
const lli mod = 1e9+7;
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
 		lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); }
//---------------Template ends------------------//
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	//freopen("ip.txt","r",stdin);
	//freopen("op.txt","w",stdout);
	#endif
//#################### CATCH HERE ##########################
   	/* Uncomment if t test cases
	lli t;
	cin>>t;
	while(t--)
	{
		lli n,ans,i,j;

		cout<<ans<<endl;
	}
	*/
	lli n,m,i;
	cin>>n>>m;
	map<lli,lli> fre;
	set <lli> ms;
	set <lli> :: iterator it;
	L(i,1,n)
	{
		lli val;
		cin>>val;
		ms.insert(val);
		fre[val]++;
	}
	lli v1,v2;
	L(i,1,m)
	{
		cin>>v1>>v2;
		while(v1)
		{
			if((*ms.begin())<v2)
			{
				if(fre[*ms.begin()]<=v1)
				{
					lli val=(*ms.begin());
					lli fr=fre[val];
					fre.erase(val);
					ms.erase(ms.begin());
					ms.insert(v2);
					fre[v2]+=fr;
					v1-=fr;
				}
				else
				{
					fre[*ms.begin()]-=v1;
					ms.insert(v2);
					fre[v2]+=v1;
					v1=0;
				}
			}
			else
				break;
		}
	}
	lli sum=0;
	for(it=ms.begin();it!=ms.end();it++)
	{
		sum+=((*it)*fre[*it]);
	}
	cout<<sum<<endl;
//##########################################################
	return 0;
} 

Measured memory_bytes: 11520
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    // 4/N = 1/h + 1/n + 1/w
    // 4nhw = N * (nw + hw + nh)
    // n = Nhw / (4hw-Nh -Nw)
    ll N;
    cin >> N;
    for(ll h = 1; h <= 3500; h++) {
        for(ll w = 1; w <= 3500; w++) {
            if ((h*w*4-N*(h+w)) <= 0) continue;
            if ((N * h * w) % (h*w*4-N*(h+w)) == 0) {
                ll res = (N * h * w) / (h*w*4-N*(h+w));
                cout << res << " " << h << " " << w << endl;
                return 0;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)

l = r = 0
count = 0

current = 0
while l < n
  while r < n
    break unless (current + a[r]) == (current ^ a[r])
    current ^= a[r]
    r += 1
  end
  count += (r - l)
  current ^= a[l]
  l += 1
end
puts count

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

int gcd(int a, int b, int c) {

    int min_num = min(a,min(b,c));
    int base;
    for (int i=1; min_num+1; i++) {
        if (min_num%i==0) {
            base = min_num/i;

        }
        if ((a%base==0)&&(b%base==0)&&(c%base==0)) {
            return base;
        }
    }
    return 0;
}

int main() {
    int K;
    cin >> K;
    int ans = 0;
    for (int i=1;i<=K;i++) {
        for (int j=i;j<=K;j++) {
            for (int k=j;k<=K;k++) {
                if (i==j && j==k) {
                    ans += gcd(i,j,k);
                }
                else if (i!=j && j!=k && k!=i) {
                    ans += gcd(i,j,k)*6;
                }
                else {
                    ans += gcd(i,j,k)*3;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long N, K;
  cin >> N >> K;
  cout << (N - K + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    char max = 'a';

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        dfs("a");
    }

    void dfs(String s) {
        if (s.length() == n) {
            System.out.println(s);
        } else {
            if (s.charAt(s.length()-1) > max) {
                max = s.charAt(s.length()-1);
                char tmp = max;
                tmp += 1;
                for (char c='a'; c<=tmp; c++) {
                    dfs(s + c);
                }
                --max;
            } else {
                char tmp = max;
                tmp += 1;
                for (char c='a'; c<=tmp; c++) {
                    dfs(s + c);
                }
            }
        }
    }
}

Measured memory_bytes: 44528
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll cap = (n-1)*(n-2)/2;
    if(cap<k)cout<<-1<<endl;
    else{
      cout<<n-1 + cap-k <<endl;
      FOR(i,2,n+1){
        cout<<1<<" "<<i<<endl;
      }

      FOR(i,2,n+1){
        if(cap==k)break;
        FOR(j,i+1,n+1){
          if(cap==k)break;
          cout<<i<<" "<<j<<endl;
          cap--;
        }
      }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[15][15];
int alg[15];
int n, m, x, sol = INT_MAX, tmp;
void bt(int idx) {
	if(idx == n) {
		bool flag = true;
		for(int i = 1; i <= m; i++) {
			if(alg[i] < x)	flag = false;
		}
		if(tmp < sol && flag)	sol = tmp;
		return;
	}
	tmp += arr[idx][0];
	for(int i = 1; i <= m; i++)	alg[i] += arr[idx][i];
	bt(idx + 1);
	tmp -= arr[idx][0];
	for(int i = 1; i <= m; i++)	alg[i] -= arr[idx][i];
	bt(idx + 1);
}
int main() {
	cin >> n >> m >> x;
	for(int i = 0; i < n; i++) {
		cin >> arr[i][0];
		for(int j = 1; j <= m; j++)	cin >> arr[i][j];
	}
	bt(0);
	if(sol != INT_MAX)	cout << sol << "\n";
	else	cout << "-1\n";
	return 0;
}

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

int main()
{
	long long n;
	cin >> n;
	vector<long long> a(n+1, 0), input(n);

	for (int i=0; i< n; i++)
	{
		long long num;
		cin >> num;
		input.at(i) = num;
		a.at(num)++;
	}

	long long all=0;
	for (auto cnt:a)
	{
		if ( cnt>1)
		{
			all += cnt*(cnt-1)/2;
		}
	}

	vector<long long> b(n+1,0);
	for (int i=1; i< n+1; i++)
	{
		long long cnt = a.at(i);
		b.at(i) =  max( cnt*(cnt-1)/2 - (cnt-1)*(cnt-2)/2 , 0ll);
	}

	for (int i=0; i<n; i++)
	{
		cout << all - b.at( input.at(i) ) << endl;
	}
}


Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

const int N = 13;
const vector<vector<int>> NEXT = {
    {2},
    {2, 5},
    {0, 1, 3, 6},
    {2, 7},
    {5},
    {1, 4, 6, 9},
    {2, 5, 7, 10},
    {3, 6, 8, 11},
    {7},
    {5, 10},
    {6, 9, 11, 12},
    {7, 10},
    {10},
};

class Node {
public:
    vector<int> puzzle;
    int depth;
    Node(const vector<int>& p, int d) :puzzle(p), depth(d) {}
};

map<vector<int>, int> memo1;
map<vector<int>, int> memo2;

void bfs(const vector<int>& puzzle, map<vector<int>, int>& memo) {
    queue<Node> q;
    q.push(Node(puzzle, 0));
    while(!q.empty()) {
        Node current(q.front()); q.pop();
        if(current.depth > 10) continue;
        if(memo.count(current.puzzle)) continue;
        memo[current.puzzle] = current.depth;
        for(int i = 0; i < N; ++i) {
            if(current.puzzle[i] != 0) continue;
            for(const auto& j: NEXT[i]) {
                vector<int> next(current.puzzle);
                swap(next[i], next[j]);
                q.push(Node(next, current.depth + 1));
            }
        }
    }
}

int main() {
    bfs({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0}, memo1);
    vector<int> puzzle(N);
    while(cin >> puzzle[0], puzzle[0] != -1) {
        for(int i = 1; i < N; ++i) cin >> puzzle[i];
        memo2.clear();
        bfs(puzzle, memo2);
        int answer = 21;
        for(auto& i: memo1) if(memo2.count(get<0>(i))) answer = min(answer, get<1>(i) + memo2[get<0>(i)]);
        if(answer > 20) cout << "NA" << endl;
        else cout << answer << endl;
    }
}

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

int main(int argc, char const *argv[])
{
	string s,t="keyence";
	cin>>s;
	int a=0,b=0;
	while (a<t.size())
	{
		if (s[a]==t[a])
		{
			++a;
		}
		else
		{
			break;
		}
	}
	while (b<t.size())
	{
		if (s[s.size()-b-1]==t[t.size()-b-1])
		{
			++b;
		}
		else
		{
			break;
		}
	}
	if (a+b>=7)
	{
		cout<<"YES\n";
	}
	else
	{
		cout<<"NO\n";
	}
	return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
store = [list(map(int, input().split())) for _ in range(n)]

store = sorted(store)

money = 0
items = 0

for i in range(len(store)):
    if items + store[i][1] >= m:
        money += store[i][0] * (m - items)
        break
    money += store[i][0] * store[i][1]
    items += store[i][1]

print(money)


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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
const ll INF = 1001001000100010;
const ld PI = 3.14159265358979323846;


int main() {
int N,M;
cin>>N>>M;
int S[12][12];
int K[12];
int p[12];
rep(i,M){
    cin>>K[i];
    rep(j,K[i]){
        cin>>S[i][j];
        S[i][j]--;
       
    }
   
}

rep(i,M){
    cin>>p[i];
}

int count1=0;
int count2;
bool judge;
rep(i,1<<N){
    judge=true;
    rep(j,M){
        count2=0;
        rep(k,K[j]){
            if((i>>S[j][k])&1){
                count2++;
            }
        }
        
        if(count2%2!=p[j]){
            judge=false;
        
        }

    }
    if(judge){
        count1++;
    }
}
cout<<count1<<endl;
return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

#define NUMBER 100


void print_array(int array[],int num)
{
	int i;
	
	for(i = 0; i < num - 1; i++){
		
		printf("%d ", array[i]);
	}
	printf("%d\n", array[i]);
	
}
	
void insertSort(int array[],int num)
{
	int i, v, j;
	for(i = 1; i <= num - 1; i++){
		print_array(array, num);
		v = array[i];
		j = i - 1;
		while(j >= 0 && array[j] > v){
			array[j + 1] = array[j];
			j--;
			
		}
		array[j + 1] = v;
	
    }
}

int main(void)
{
	int i, num;
	int array[NUMBER];

	scanf("%d", &num);
	
	for(i = 0; i < num; i++)
	{
		scanf("%d", &array[i]);
	}
	
	insertSort(array , num);
	
	print_array(array , num);
	
	
	return 0;
}


Measured memory_bytes: 2732