akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define inf 1000000000000000000
using namespace std;

typedef struct {
  long long s, t, c;
} edges;
long long n, m, ans;
vector<edges> edge;
long long dis[1005] = {0};

void prians(bool answer) {
  if(answer)
    cout << "inf" << endl;
  else
    cout << ans << endl;
}
bool solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    edges e;
    cin >> e.s >> e.t >> e.c;
    --e.s;
    --e.t;
    e.c *= -1;
    edge.push_back(e);
  }
  prians(solve());
  return 0;
}

bool solve() {
  for(int i = 0; i < n; ++i) dis[i] = inf;
  dis[0] = 0;
  for(int i = 0; i < n; ++i) {
    bool update = 0, upn = 0;
    for(int j = 0; j < m; ++j) {
      edges now = edge[j];
      if(dis[now.s] != inf &&
         dis[now.s] + now.c < dis[now.t]) {
        update = 1;
        if(now.t == n - 1) upn = 1;
        dis[now.t] = dis[now.s] + now.c;
      }
    }
    if(!update) break;
    if(upn && i == n - 1) return 1;
  }
  ans = -dis[n - 1];
  return 0;
}

Measured memory_bytes: 384
// agrawal117
// segment tree // lazy propagation method

#include<bits/stdc++.h>
#define mod 998244353
#define endl '\n'
typedef long long int ll ;
using namespace std;

#define MAX 200004
ll arr[MAX];
ll tree[800005];
ll lazy[800005];
ll pw[MAX];
ll dp[10][MAX];
ll combine(ll a, ll b,ll c)
{
    ll val=(a*pw[c])%mod;
    val=(val+b)%mod;
    return val;
}

void build(ll start,ll end,ll node)							//sum program segment tree;
{
	if(start==end){
		tree[node]=arr[start];
		return;
	}
	ll mid=(start+end)>>1;
	
	build(start,mid,2*node);
	build(mid+1,end,(2*node)+1);
	//combine function 
	tree[node]=combine(tree[2*node], tree[2*node+1], end-mid);
}

ll query(ll start,ll end,ll node, ll l,ll r)
{
	if(lazy[node]!=0) {
	    
		tree[node]+=(end-start+1)*lazy[node]; 				// if that has to be updated;
		if(start!=end){
			lazy[2*node]+=lazy[node];
			lazy[(2*node)+1]+=lazy[node];
		}
		lazy[node]=0;
	}
	
	if(start>r || l>end) {				//no overlap case  return that value which does not affect the ans 
		return 0 ;
	}
	
	else if(l<=start && r>=end) {
		return tree[node];           // case of fully overlap
	}
	else{
		ll mid=(start+end)>>1;								//partial overlap so call both children
		ll child1=query(start,mid,2*node,l,r); //cout<<"child1 "<<child1<<endl;
		ll child2=query(mid+1,end,(2*node)+1,l,r); //cout<<"child2 "<<child2<<endl;
		return child1+child2;
	}
}

void update(ll start,ll end,ll node,ll l,ll r,ll value)		//update in range of l to r 
{																	// increase values upto given value.
	ll mid=(start+end)>>1;
	if(lazy[node]!=0) {
		tree[node]=dp[lazy[node]][end-start+1]; 				// if that has to be updated;
		if(start!=end){
			lazy[2*node]=lazy[node];
			lazy[(2*node)+1]=lazy[node];
		}
		lazy[node]=0;
	}
	
	if(start>r || l>end) {				//no overlap case  return that value which does not affect the ans 
		return ;
	}
	else if(l<=start && r>=end) {
		 tree[node]=dp[value][end-start+1];          // case of fully overlap
		if(start!=end){
			lazy[2*node]=value;
			lazy[(2*node)+1]=value;
		}
		return;
	}
	else{
										//partial overlap so call both children
		update(start,mid,2*node,l,r,value);
		update(mid+1,end,(2*node)+1,l,r,value); 
		tree[node]=combine(tree[2*node],tree[2*node+1],end-mid);
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.flush();
	
    pw[0]=1;
    for(int i=1;i<MAX;i++){
        pw[i]=(pw[i-1]*10)%mod;
    }
    for(int i=1;i<=9;i++){
        for(int j=1;j<MAX;j++){
            dp[i][j]=((dp[i][j-1]*10)%mod + i )%mod;
        }
    }
    
	ll n; ll q;
	cin>>n>>q; 
	for(int i=1;i<=n;i++) arr[i]=1;
	build(1,n,1);
	 //for(int i=1;i<16;i++) cout<<tree[i]<<endl;
	ll a,b,c,value;
	for(ll i=0;i<q;i++){
    	cin>>b>>c>>value;
    	update(1,n,1,b,c,value);
    	cout<<tree[1]%mod<<endl;
	}
	
}


Measured memory_bytes: 29048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> vv;


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

Measured memory_bytes: 256
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    P = read_list()
    C = read_list()

    res = V(max)
    for i in range(N):
        t = []
        c = 0
        p = i
        while len(t) == 0 or p != i:
            p = P[p] - 1
            c += C[p]
            t.append(c)

        m = len(t)
        # print(f"m: {m}, t: {t}, c: {c}")
        if m > K or c <= 0:
            res.ud(max(t[:K]))
        else:
            s = K // m * c
            k = K % m
            # print(f"s: {s}, k: {k}")
            tmp = V(max)
            for i in range(k):
                tmp.ud(s + t[i])
            
            s -= c
            for v in t:
                tmp.ud(s + v)
            
            res.ud(tmp.v)

    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 83252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main(){
    int n; cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    rep(i,n){
        if (a.at(i) == b.at(i)){
            if (b.at(i) != c.at(i)) ans++;
        }
        else if (a.at(i) == c.at(i) || b.at(i) == c.at(i)) ans++;
        else ans += 2;
    }
    cout << ans << endl;
}

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

int main() {
  long long s,yon=0;
  cin >> s;
  if(s == 1 || s == 2 || s == 4){
    cout << 4 << endl;
    return 0;
  }
  int i=0;
  while(s != 4){
    if(s%2 == 0){
      s /= 2;
    }
    else{
     s = s*3+1;
    }
    i++;
  }
  cout << i+4 << endl;
}


Measured memory_bytes: 3592
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        int home[][][] = new int[4][3][10];
        int b = 0;
        int f = 0;
        int r = 0;
        int v = 0;
        int i = 0;
        int j = 0;
        int k = 0;
        Scanner sc = new Scanner(System.in);
        for(i = 0 ; i < 4 ; i++)
        {
            for(j = 0 ; j < 3 ; j++)
            {
                for(k = 0 ;k < 10 ; k++)
                    home[i][j][k] = 0;
            }
        }
        int n = sc.nextInt();
        for(i = 0 ; i < n ; i++)
        {
            b = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();
            v = sc.nextInt();
            home[b-1][f-1][r-1] += v;
        }
        for(i = 0 ; i < 4 ; i++)
        {
            for(j = 0 ; j < 3 ; j++)
            {
                for(k = 0 ; k < 10 ; k++)
                    System.out.print(" " + home[i][j][k]);
                System.out.println();
            }
            if(i != 3)
            {   
                System.out.println("####################");
            }
        }
    }
}


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

using namespace std;

const int NS = (int)2e5 + 4;
int N;
int A[NS], B[NS];
priority_queue < pair < int, int > > pq;

int main(){
    scanf("%d", &N);
//    N = (int)2e5;
    for(int i = 1; i <= N; ++i){
        scanf("%d", A + i);
//        A[i] = 1;
    }
    for(int i = 1; i <= N; ++i){
        scanf("%d", B + i);
//        B[i] = (i % 2 ? 1 : 999999999);
        pq.push(make_pair(B[i], i));
    }
    long long ans = 0;
    while(!pq.empty()){
        auto top = pq.top(); pq.pop();
        if(top.first == A[top.second]){
            continue;
        }
        int gap = (B[top.second] - max(B[(top.second - 1) + (top.second == 1) * N], max(A[top.second], B[top.second % N + 1])))/
                (B[(top.second - 1) + (top.second == 1) * N] + B[top.second % N + 1]);
        if(!gap) gap = 1;
        B[top.second] -= (B[(top.second - 1) + (top.second == 1) * N] + B[top.second % N + 1]) * gap;
        ans += gap;
        if(B[top.second] < A[top.second]){
            puts("-1"); return 0;
        }
        pq.push(make_pair(B[top.second], top.second));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;

vector<int> elem;
vector<int> elmrank;

void init(int num)
{
    elem = vector<int>(num, 0);
    elmrank = vector<int>(num, 0);
    
    for (int i = 0; i < num; ++i)
    {
        elem[i] = i;
    }
}

int dfs(int num)
{
    if (elem[num] == num)
    {
        return num;
    }
    else
    {
        elem[num] = dfs(elem[num]);
        return elem[num];
    }
}

void unite(int a, int b)
{
    a = dfs(a);
    b = dfs(b);
    
    if (a == b)
    {
        return;
    }
    else
    {
        if (elmrank[a] < elmrank[b])
        {
            elem[a] = b;
        }
        else
        {
            if (elmrank[a] == elmrank[b])
            {
                elmrank[a]++;
            }
            elem[b] = a;
        }
    }
}


int main() {
    
    
    int n;
    cin >> n;
    init(n);
    map<int, int> xx;
    map<int, int> yy;
    
    vector<int> x(n);
    vector<int> y(n);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i] >> y[i];
        if (xx.count(x[i]))
        {
            unite(xx[x[i]], i);
        }
        else
        {
            xx[x[i]] = i;
        }
        
        if (yy.count(y[i]))
        {
            unite(yy[y[i]], i);
        }
        else
        {
            yy[y[i]] = i;
        }
    }
    
    vector<set<int>> xc(n);
    vector<set<int>> yc(n);
    
    for (int i = 0; i < n; ++i)
    {
        xc[dfs(i)].insert(x[i]);
        yc[dfs(i)].insert(y[i]);
    }
    
    long long ret = 0;
    for (int i = 0; i < n; ++i)
    {
        ret += xc[i].size() * yc[i].size();
    }
    
    ret -= (long long)n;
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 20608
eval'*A=#'+`tr ' ' ,`;f=->a{l=[[0,i=0]];a.map{|x|l.pop while(t=l[-1])[0]>x;l<<[x,i+=1];i-t[1]}}
r=0;A.zip(f[A],f[A.reverse].reverse){|a,b,c|r+=a*b*c};p r

Measured memory_bytes: 48748
fun main(args: Array<String>) {
    readLine()
    val S = readLine()!!

    var x = 0
    var res = 0
    for (c in S.toCharArray()) {
        if (c == 'I') {
            x++
        } else {
            x--
        }
        res = Math.max(res, x)
    }
    println(res)
}

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

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

    int r, b;
    r = b = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == 'R'){
            r++;
        }else{
            b++;
        }
    }

    if(r > b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n, m;
  constexpr int max_n = 1e6+1;
  vector<int> H = {1};
  int p[] = {2,3,5};
  for(int i = 0; i < 3; ++i){
    int s = H.size();
    for(int k = 0; k < s; ++k){
      int h = H[k];
      while(h*p[i] < max_n){
        h *= p[i];
        H.push_back(h);
      }
    }
  }
  sort(H.begin(),H.end());
  // for(auto h : H){
  //   cerr << h << " ";
  // }
  // cerr << endl;
  while(cin >> m, m){
    cin >> n;
    int a = upper_bound(H.begin(),H.end(),n) - lower_bound(H.begin(),H.end(),m);
    cout << a << endl;
  }
}



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

int main() {
int n, m;
  cin >> n >> m;
  vector<int> A(m);
  for(int i =0;i<m;++i){
    cin >> A.at(i);
  }
  int sum = 0;
  for(int i=0; i<m; ++i){
    sum += A.at(i);
  }
  if(n-sum>=0) cout << n-sum << endl;
  else cout << -1 << endl;
  
  
}


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

int N,A,B,C;
vector<int> D;
int dp[100][100]; //○個まで、△以降

int solve(int now, int nokori){
    if(now == N) return 0;
    if(nokori == 0) return 0;
    if(dp[now][nokori] != -1) return dp[now][nokori];

    dp[now][nokori] = max(solve(now+1,nokori),solve(now+1,nokori-1)+D[now]);
    return dp[now][nokori];
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        D.push_back(tmp);
        for(int j=0; j<N; j++){
            dp[i][j] = -1;
        }
    }

    int ans = C/A;
    for(int i=1; i<N; i++){
        ans = max(ans,(solve(0,i)+C)/(A+B*i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3156
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; Next(a); return a; }
  template<class A, class B>void Next(pair<A, B>& a) { cin >> a.first >> a.second; }
  template<class A>void Next(A& a) { cin >> a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) (*this), i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;
/*---------------------------------------------------------------------*/


void Calc() {

  int n = in;
  if (n == 1) {
    cout << ("Hello World") << endl;
  }
  else {
    int a = in;
    int b = in;
    cout << (a + b) << endl;
  }
}


Measured memory_bytes: 892
import math

S = input()

n = len(S)

case1 = [0, 1] * int(math.floor(n/2))
case2 = [1, 0] * int(math.floor(n/2))

if n % 2 == 1:
    case1.append(0)
    case2.append(1)


# print(case1)
# print(case2)

c1 = 0
c2 = 0
for i in range(n):
    if int(S[i]) != case1[i]:
        c1 += 1
    if int(S[i]) != case2[i]:
        c2 += 1

if c1 < c2:
    print(c1)
else:
    print(c2)


Measured memory_bytes: 4852
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        getAns(a, n, m);
    }
    static void getAns(int[] a, int n, int m)
    {
        Array.Reverse(a);
        var count = 0;
        var hs = new HashSet<int>();
        for (int i = 0; i < n; i++)
            if (hs.Add(a[i]))
            {
                Console.WriteLine(a[i]);
                count++;
                if (count == m) return;
            }
    }
}



Measured memory_bytes: 24832
n = int(input())
if n < 2:
	print(1)
elif 2<= n < 4:
	print(2)
elif 4 <= n < 8:
	print(4)
elif 8 <= n < 16:
	print(8)
elif 16 <= n < 32:
	print(16)
elif 32 <= n < 64:
	print(32)
else:
	print(64)

Measured memory_bytes: 3060
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

def dinum(N, C, D):
    return N - (N//C + N//D - N//lcm(C, D))

A, B, C, D = LI()

print(dinum(B, C, D) - dinum(A-1, C, D))


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

ll binary_search(const vector<ll> &v, ll x){
    ll n = 0;
    for (int i = 0, N = v.size(); i < N; i++)
    {
        n += v.end() - upper_bound(v.begin(), v.end(), x - v[i]);
    }
    return n;
}

int main(){
    ll N, M; cin >> N >> M;
    vector<ll> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];
    sort(v.begin(), v.end());

    ll ok = 2 * v[N-1] + 1;
    ll ng = 0;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        if(binary_search(v, mid)<=M) ok = mid;
        else ng = mid;
    }

    ll num = 0;
    ll ans = 0;
    vector<ll> cusum(N+1);
    cusum[0] = 0;
    for (int i = 0; i < N; i++) cusum[i+1] = cusum[i] + v[N-1-i];    
    for (int i = 0; i < N; i++)
    {
        ll  x = v.end() - lower_bound(v.begin(), v.end(), ok-v[i]);
        num += x;
        ans += v[i] * x + cusum[x];
    }
    ans -=(num-M)*ok;
    cout << ans << endl;
}


Measured memory_bytes: 1920
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <time.h>
using namespace std;
long double esp=1e-11;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p,c) memset(p,c,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef long long int LL;
const long double PI = acos((long double)-1);
const LL INF=0x3f3f3f3f3f3f3f3fll;
const int MOD =1000000007ll;
const int maxn=210100;
int ro1[maxn];
int up1(int u){return(ro1[u]==u)?u:ro1[u]=up1(ro1[u]);}
int ro2[maxn];
int up2(int u){return(ro2[u]==u)?u:ro2[u]=up2(ro2[u]);}
vector<pair<int,int> >node[maxn];
int c[maxn][2];
int ans[maxn];
int main()
{
    //freopen("in9.txt", "r", stdin);
    //freopen("in9.txt", "r", stdin);
    //freopen("out9.txt", "w", stdout);
    //::iterator iter;                  %I64d
    //for(int x=1;x<=n;x++)
    //for(int y=1;y<=n;y++)
    //scanf("%d",&a);
    //printf("%d\n",ans);
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    for(int x=1;x<=n;x++)ro1[x]=ro2[x]=x,node[x].clear();
    for(int x=1;x<=k;x++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        ro1[up1(u)]=up1(v);
    }
    for(int x=1;x<=n;x++)
        node[up1(x)].pb(mp(x,0));
    for(int x=1;x<=l;x++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        ro2[up2(u)]=up2(v);
    }
    mem(ans,0);
    mem(c,0);
    for(int x=1;x<=n;x++)
    {
    	for(int y=0;y<node[x].size();y++)
		{
			node[x][y].se=up2(node[x][y].fi);
			if(c[node[x][y].se][1]!=x)
			{
				c[node[x][y].se][1]=x;
				c[node[x][y].se][0]=0;
			}
			c[node[x][y].se][0]++;
		}
		for(int y=0;y<node[x].size();y++)
			ans[node[x][y].fi]=c[node[x][y].se][0];
    }
    for(int x=1;x<=n;x++)
        printf("%d%c",ans[x]," \n"[x==n]);
    return 0;
}


Measured memory_bytes: 15232
#include <iostream>


int gcd(int i, int j)
{
	if (j == 0)
		return i;
	return gcd(j, i % j);
}

int gcd(int i, int j, int k)
{
	int r = gcd(i, j);
	return gcd(r, k);
}

int main()
{
	int K;
	std::cin >> K;
	int sum = 0;
	for (int i = 1; i <= K; i++)
	{
		for (int j = 1; j <= K; j++)
		{
			for (int k = 1; k <= K; k++)
			{
				sum += gcd(i, j, k);
			}
		}
	}
	std::cout << sum;

}

Measured memory_bytes: 3600
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = []
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans.append(max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(min(ans))

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

using namespace std;

void printVector ( vector<int> &v )
{
  for (int i = 0, ilen = v.size(); i < ilen; ++i)
  {
    cout << v[i] << (((i+1) == ilen) ? '\n' : ' ');
  }
}

int main ( void )
{
  int n;
  vector<int> v;

  cin >> n;

  v = vector<int>(n);

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

  for (int i = 0; i < n; ++i)
  {
    for (int j = i-1; (j >= 0) && (v[j] > v[j+1]); --j)
    {
      swap(v[j], v[j+1]);
    }
    printVector(v);
  }

  return 0;
}

Measured memory_bytes: 1212
a, b, c, d = gets.split(" ").map(&:to_i)

ans = (b - (b / c) - (b / d) + (b / c.lcm(d))) - (a - (a / c) - (a / d) + (a / c.lcm(d)))
if a % c != 0 && a % d != 0
  ans += 1
end
  
puts ans

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int xx = int.Parse(Console.ReadLine());

            int ans = 0;

            for(int j = 0; j< a+1; j++)
            {
                for(int k = 0; k < b+1; k++)
                {
                    for (int l = 0; l < c + 1; l++)
                    {
                        if (500 * j + 100 * k + 50 * l == xx)
                        {
                            ans++;
                        }
                    }
                }
            }

            Console.WriteLine(ans);


        }
    }
 }


Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int out (int a[],int n){
    int i;
    for(i=0;i<n;i++)i==n-1?cout<<a[i]<<endl:cout<<a[i]<<" ";
    return 0;
}
int main(void){
    int n,i,j,num,a[100+1],min,count,v;
    cin>>n;
    for(i=0;i<n;i++)cin>>a[i];
    v=0;
    for(i=0;i<n;i++){
        min=100,count=0;
        for(j=i;j<n;j++){
            if(a[j]<min)min=a[j],num=j,count++;
        }
        if(count>=2)swap(a[i],a[num]),v++;
        
    }
    out(a,n);
    cout<<v<<endl;
    return 0;
}

Measured memory_bytes: 3096
def f(n, s, max)
  # s????????????max?????????
  max_min = ((2*s/n.to_f+n-1)/2)
  if n == 1
    # n=1?????¨??????s???????????´??°?????????????????????0???????????????
    if max >= s and s != 0
      return 1
    else
      return 0
    end
  elsif max < max_min
    return 0
  else
    result = 0
    max = s if s < max
    for i in (max_min.ceil)..max
      result += f(n-1, s-i, i-1)
    end
    return result
  end
end
while (n, x = gets.split(" ").map(&:to_i)) != [0,0]
  puts f(3, x, n)
end

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

int main() {
  long long A,B;
  cin >> A >> B;
  int j = 0;
  int i = 2;
  
  vector<int>a(40,0);
  while (A > 1){
    if (A % i == 0){
      for (int k = 0; k < 40; k++) {
        if (A % i == 0){
          A = A/i;
        }
        else {
          a.at(j) = i;
          j++;
          break;
        }
      }
    }
    else {
      i++;
      if (i > 1000000){
        A *= -1;
      }
    }
  }
  
  j = 0;
  i = 2;
  vector<int>b(40,0);
  while (B > 1){
    if (B % i == 0){
      for (int k = 0; k < 40; k++) {
        if (B % i == 0){
          B = B/i;
        }
        else {
          b.at(j) = i;
          j++;
          break;
        }
      }
    }
    else {
      i++;
      if (i > 1000000){
        B *= -1;
      }
    }
  }
  
  int count = 1;
  
  if (A < 1 && A == B){
    count++;
  }
  
  for (int k = 0; k < 40; k++) {
    for (int l = 0; l < 40; l++) {
      if (a.at(k) > 1 && a.at(k) == b.at(l)){
        count++;
      }
    }
  }
  cout << count << endl;
}




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

using namespace std;
 
int main(){
  
  int s, i;
  
  map<int,int>mp;
  
  cin >> s;
  
  mp[s]++;
  
  i = 1;
  
  while(1 == 1){
    
    i++;
    
    if(s % 2 == 0){
      
      s = s/2;
      
      mp[s]++;
    }
    else{
      
      s = 3*s + 1;
      
      mp[s]++;
    }
    if(mp[s] > 1){
      
      cout << i;
      
      return 0;
    }
  }
}

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

for a in range(n, -1, -1):
    b_max = n-a
    for b in range(b_max, -1, -1):
        c = b_max-b
        sum = a*10000 + b*5000 + c*1000
        if sum == y :
            print(a, b, c)
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")


Measured memory_bytes: 2940
W, a, b = map(int, input().split())
if (a > b):
    a_left = a
    b_right = b + W
    if (b_right >= a_left):
        print("0")
    else:
        ans = a_left - b_right
        print(ans)
else:
    b_left = b
    a_right = a + W
    
    if (a_right >= b_left):
        print("0")
    else:
        ans = b_left - a_right
        print(ans)


Measured memory_bytes: 2940
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

struct Node {
    int key;
    Node* parent;
    Node* left;
    Node* right;
    Node(int k) : key(k) {}
};

void bintree_insert(Node*& root, int key)
{
    Node* node = new Node(key);
    if(!root) {
        root = node;
        return;
    }

    Node* parent = root;
    for(;;) {
        Node*& child = key < parent->key ? parent->left : parent->right;
        if(!child) {
            child = node;
            break;
        }
        parent = child;
    }
}

void bintree_print_inorder(Node* node)
{
    if(!node) return;

    bintree_print_inorder(node->left);
    printf(" %d", node->key);
    bintree_print_inorder(node->right);
}

void bintree_print_preorder(Node* node)
{
    if(!node) return;

    printf(" %d", node->key);
    bintree_print_preorder(node->left);
    bintree_print_preorder(node->right);
}

void bintree_print(Node* root)
{
    bintree_print_inorder(root);
    puts("");

    bintree_print_preorder(root);
    puts("");
}

void interpret()
{
    int n;
    scanf("%d\n", &n);

    Node* root = nullptr;

    char buf[256];
    REP(_, n) {
        scanf("%s", buf);
        if(strcmp(buf, "insert") == 0) {
            //puts("insert");
            int key;
            scanf("%d", &key);
            bintree_insert(root, key);
        }
        else if(strcmp(buf, "print") == 0) {
            //puts("print");
            bintree_print(root);
        }
    }
}

int main()
{
    interpret();

    return 0;
}

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

struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
              return x>a.x;
    }

};

vector<int> v[1];
//bitset<4001000> b;
int a,c,i,b,n,m,k,d;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[332111];
int l[833331];
int j[855551];
int e;
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=998244353,mod2=1000000009,mod3=2017;
long long z;
double pi=3.14159265;
P u[1];
stack<int> s;

//set<long long> s;
queue<int> q,q1;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;

string r,r1;
//char r[111331];
//deque<int> de;

bool as(P a,P b)
{
    //if(a.x!=b.x)
        return a.x<b.x;
    //return a.y<b.y;
}

long long f(int n,int m)
{
    long long x=0;
    for(;n<m;)
    {
        if(n%2) x+=j[n],n++;
        else if(m%2==0) x+=j[m],m--;
        else n/=2,m/=2;
    }
    return x+j[n];
}

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;m=max(m,o[t]),t++)
        scanf("%d",&o[t]);
    n=1;
    for(i=1;i<200001;i*=2);
    for(;n<m;)
    {
        memset(l,0,sizeof(l));
        memset(j,0,sizeof(j));
        x=0;
        int h=(n+m)/2+1;
        l[0]=100001;
        j[100000+i]=1;
        for(int u=(100000+i)/2;u;u/=2)
            j[u]=j[u*2]+j[u*2+1];
        for(int t=1;t<=a;t++)
        {
            if(o[t]>=h) l[t]=l[t-1]+1;
            else l[t]=l[t-1]-1;

            //printf("%lld ",f(i,l[t]+i-1));
            x+=f(i,l[t]+i-1);
            j[l[t]+i-1]++;
            for(int u=(l[t]+i-1)/2;u;u/=2)
                j[u]=j[u*2]+j[u*2+1];

        }
        //printf("%d %lld\n",h,x);
        //for(int t=1;t<=a;t++)
          //  printf("%d ",l[t]);
        if(x>=(long long)a*(a+1)/2-((long long)a*(a+1))/4) n=h;
        else m=h-1;
    }
    printf("%d",n);
}


Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N;
long long int K;
int Q;
int A[100005];
long long int P[100005];/*獲得した得点*/

int main(void) {
  cin >> N >> K >> Q;
  for(int i=0; i<Q; i++) cin >> A[i];
  for(int i=0; i<Q; i++) A[i]--;/*正解者の番号を1ずらす*/  
  
  for(int j=0; j<N; j++) P[j]=0;
  
  for(int i=0; i<Q; i++){
    P[A[i]]++; 
  }
  
  for(int i=0; i<N; i++){
    if(P[i]>Q-K)  cout << "Yes" << endl;
    if(P[i]<=Q-K)  cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1792
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {   
                string[] s = Console.ReadLine().Split();
                int h = int.Parse(s[0]);
                int w = int.Parse(s[1]);

                if (h == 0 && w == 0)
                {
                    break;
                }
                for (int i = 0; i < h; i++)
                {
                    for (int j = 0; j < w; j++)
                       {
                           Console.Write("#");
                       }
                    Console.WriteLine("");
                }
                Console.WriteLine("");
            }
        }
    }
}

Measured memory_bytes: 8852
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    string s;
    int y,m,d;
    while(cin>>s&&s!="#"){
        cin>>y>>m>>d;
        if(y>31||(y==31&&m>4)){
            s="?";
            y-=30;
        }
        printf("%s %d %d %d",s.c_str(),y,m,d);
        cout<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3264
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int ans[10010];
int main()
{
	int N;
	cin >> N;
	for (int x = 1; x <= 110; x++) {
		for (int y = 1; y <= 110; y++) {
			for (int z = 1; z <= 110; z++) {
				if (x * x + y * y + z * z + x * y + y * z + x * z <= N) {
					ans[x * x + y * y + z * z + x * y + y * z + x * z]++;
				}
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long

ll n;


int main ( void )
{
	cin >> n;
	for ( int i = sqrt ( n ) ; i >= 1 ; i-- ) {
			if ( n % i == 0 ) {
				cout << ( n / i ) + i - 2 << endl;
				break;
			}
	}
	return 0;
}

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

using namespace std;

const int N = 1e5 + 6;
bool prime[N];

void sieve() {
    memset(prime , 1 , sizeof prime);
    prime[0] = prime[1] = 0;
    for (int i = 2 ;i * i < N ;i++)
        if (prime[i])
            for (int j = i * i ;j < N ;j += i)
                prime[j] = 0;
}

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

    for (int i = n ; ;i++) {
        if (prime[i]) {
            cout << i;
            return 0;
        }
    }
}


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

#include<random> 

#define int long long 

#define pp pair<int,int> 

#define ss second 

#define ff first 

#define pb push_back 

#define mod 1000000007 

using namespace std; 

void fastio() 

{ 

    #ifndef ONLINE_JUDGE 

        freopen("INPUT.txt","r",stdin); 

            freopen("OUTPUT.txt","w",stdout); 

                #endif 

                    ios_base :: sync_with_stdio(false); 

                        cin.tie(NULL) ; 

                            cout.tie(NULL); 

                            }

signed main() 

{ 

    fastio(); 

        int t=1;

           // cin>>t;

                while(t--)

                    {

                         int n,c=0,m=0;

                         cin>>n;

                         int a[n];

                         for(int i=0;i<n;i++)

                             cin>>a[i];           

                          for(int i=0;i<n-1;i++){

                                  if(a[i]>=a[i+1])  

                                  c++;

                                  else

                                  {

                                     m=max(c,m);

                                     c=0;

                                  }

                                  }

                                  m=max(c,m);

                                  cout<<m;

    }

    }

    

Measured memory_bytes: 4424
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC145A
{
    class Program
    {
        static void Main(string[] args)
        {
            int r = int.Parse(Console.ReadLine());
            Console.WriteLine(r * r);
        }
    }
}


Measured memory_bytes: 27512
import java.io.*;
import java.util.*;

class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().trim().split(" ");
        long n = Long.parseLong(s[0]);
        long m = Long.parseLong(s[1]);
        long ans = 0;
        int k = (int)m;
        for(int i=k+1; i<=n; i++) {
            int z = (int)(n)/i;
            long x = 0;
            if(n%i!=0) {
                x = n%i - k + 1;
                if(k==0) x--;
            }
            long y = (i-k)*z + (x<0?0:x);
            ans += y;
//            System.out.println("y: " + y + "  i: " + i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int K = s.nextInt();
		int sum = 0;
		int xs[] = new int[N];
		for (int i = 0; i < N; i++)
		{
			xs[i] = s.nextInt();
		}
		for (int k = 0; k < N; k++)
		{
			if (Math.abs(xs[k]) > Math.abs(K - xs[k]) )
			{
				sum += 2 * Math.abs(K - xs[k]);
			} else 
			{
				sum += 2 * xs[k];
			}
		}
		System.out.println(sum);
	}

}


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

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

Measured memory_bytes: 1160
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int n, m;
    cin >> n >> m;
    n--;
    m--;
    cout << n * m << endl;


    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	r := []rune(s)
	if r[2] == r[3] && r[4] == r[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
// Aizu 1174: Identically Colored Panels Connection
// 2017.9.17 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int r, c; } Q;
Q q[70]; int top, end;
char mk[8][8];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
char map[8][8]; int h, w, color;
int ans;

int count(char p[8][8])
{
	int i, r, c, r2, c2, f;
	q[0].r = q[0].c = 0, top = 0, end = 1, memset(mk, 0, sizeof(mk)), mk[0][0] = 1, f = 1;
	while (top < end) {
		r = q[top].r, c = q[top++].c;
		for (i = 0; i < 4; i++) {
			r2 = r + mv[i][0], c2 = c + mv[i][1];
			if (r2 < 0 || r2 >= h || c2 < 0 || c2 >= w || p[r2][c2] != p[r][c] || mk[r2][c2]) continue;
			mk[r2][c2] = 1, f++, q[end].r = r2, q[end++].c = c2;
		}
	}
	return f;
}

void combi(int c0, int k, char p[8][8])
{
	int i, j, r, c, r2, c2, m;
	char t[8][8];

	if (k == 5) return;
	for (j = 1; j <= 6; j++) {
		if (j == c0) continue;
		memcpy(t, p, sizeof(t)); t[0][0] = j;
		q[0].r = q[0].c = 0, top = 0, end = 1, memset(mk, 0, sizeof(mk)), mk[0][0] = 1;
		while (top < end) {
			r = q[top].r, c = q[top++].c;
			for (i = 0; i < 4; i++) {
				r2 = r + mv[i][0], c2 = c + mv[i][1];
				if (r2 < 0 || r2 >= h || c2 < 0 || c2 >= w || t[r2][c2] != c0 || mk[r2][c2]) continue;
				mk[r2][c2] = 1, t[r2][c2] = j, q[end].r = r2, q[end++].c = c2;
			}
		}
		if (j == color) if ((m = count(t)) > ans) ans = m;
		combi(j, k+1, t);
	}
}

int main()
{
	int a, r, c;

	while(scanf("%d%d%d", &h, &w, &color) && h) {
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) scanf("%d", &a), map[r][c] = a;
		ans = 0; if (map[0][0] == color) ans = count(map);
		combi(map[0][0], 0, map);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1768
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int n;

	cin >> n;

	pair<int, int> p[n];
	
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n);
	for (int i = 0; i < n; i++) {
		cout << p[i].first << " " << p[i].second << endl;
	}
}




Measured memory_bytes: 3856
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,K,ans=0;
  cin >> N >> K;
  int V[N];
  rep(i,N) cin >> V[i];
  int X=min(N,K);
  for(int i=0;i<=X;i++){
    for(int j=0;j<=X-i;j++){
      int R=K-i-j;
      int sum=0,count=0;
      int jewel[i+j];
      rep(k,i) jewel[count]=V[k],count++;
      for(int k=N-1;k>N-1-j;k--) jewel[count]=V[k],count++;
      sort(jewel,jewel+count);
      rep(k,R) if(jewel[k]<0 && k<i+j) jewel[k]=0;
      sum=accumulate(jewel,jewel+count,0);
      ans=max(ans,sum);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//ポイント：ビットごとに考える、(X(,Y)の選び方に) 依存しないものを探す。
//まずスコア = X + Y = Σ2^i * (Xi + Yi)
//適当にX,Yを選んでXi≠Yi (Xi,Yi={0,1})になったら、他の選び方でもXi≠Yi。このときXi+Yi=1。
//適当にX,Yを選んでXi=Yiになったら、他の選び方でもXi=Yi, このときXi+Yi=2Xi (Xの選び方に依存).
//↑をもうちょっと書きやすい形にすると、全体のxor = Wとおくことで、
//Wi=1なら、常にXi+Yi=1
//Wi=0なら、Xi+Yi=2Xi
//つまり、Wi = 1なるiについては常にスコア += 2^i、合計で += W。
//Wi = 0なるiについてはスコア += 2 * 2^i * Xi。
//ここで、Wj=0なるjについてAiのjビット目を0に置き換えたものをAi'とおく。すると、同じ要素の選び方について、
//Σ2^i * (Xi + Yi) (Wi = 0)は、Aiを使ってもAi'を使っても変化しないので、以降はAi'を用いてみる。
//すると、Wi = 0が常になりたつことになり、スコア = 2Xに変形できる。よって、Xを最大化すればよい。
//今度は、A1'～AN'のうちいくつかを選ぶことで作れるxorの条件（集合）を考える。
//（0個選んでも、全部選んでもxor=0より、そのような場合も考えて良いことに注意する）
//すると、F2上の線形和みたいなので表せる形が条件になることが分かって、線形和（線形従属）といえば掃き出し法なので、
//掃き出し法を実行してみる（(Ai', Aj') -> replace -> (Ai', Ai' xor Aj')してみる）と、作れるxorの集合は変化しない
//ことに気付く。よって、掃き出し法ができ、「自明に貪欲できる形」に変形することができる。

#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

int n;
int a[100000];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	int w = 0;
	rep(i, n) w ^= a[i];
	rep(i, n) a[i] &= ~w;
	
	int cor = 0;
	rrep(i, 60) {
		for (j = cor; j < n; j++) {
			 if ((a[j] >> i) & 1) break;
		}
		if (j == n) continue;
		swap(a[cor], a[j]);
		for (j = cor + 1; j < n; j++) {
			if ((a[j] >> i) & 1) a[j] ^= a[cor];
		}
		cor++;
	}
	
	int x = 0;
	rep(i, n) {
		if ((x ^ a[i]) > x) x ^= a[i];
	}
	
	cout << 2 * x + w << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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 int mod = 998244353;
struct mint {
    ll x; // using long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m, k;
    cin>>n>>m>>k;

    combination comb(n + 10);
    mint ans = 0;
    vector<mint> ps(n + 1);
    ps[0] = 1;
    rep(i, n) ps[i + 1] = ps[i] * (m - 1);
    rep(i, k + 1) {
        ans += ps[n - i - 1] * m * comb(n - 1, i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7840
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a;
	cin>>b;
	if((a+b)%3==0||a%3==0||b%3==0)
		cout<<"Possible"<<endl;
	else 
		cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
from math import ceil
s=list(input())
n=len(s)
l=[]
m=[]
buf=[]
for i in range(n):
    if s[i]!="x":
        l.append(s[i])
m=l[::-1]
#print(l,m)
left=[]
right=[]
ans=0
if m==l:
    flag=1
    for i in range(ceil(len(l)/2)):
        buf.append(l[i])
    piv=0
    cnt=0
    #print(buf)
    for i in range(n):
        if piv==len(buf):
            break
        if s[i]==buf[piv]:
            left.append(cnt)
            cnt=0
            piv=piv+1
        else:
            cnt=cnt+1
    piv=0
    cnt=0
    for i in range(n-1,-1,-1):
        if piv==len(buf):
            break
        if s[i]==buf[piv]:
            right.append(cnt)
            cnt=0
            piv=piv+1
        else:
            cnt=cnt+1
    #print(left,right)
    for i in range(len(left)):
        ans=ans+abs(left[i]-right[i])
    print(ans)
else:
    print("-1")


Measured memory_bytes: 50060
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)

	reg := regexp.MustCompile(`ABC`)
	result := reg.FindAllStringSubmatch(S, -1)
	fmt.Println(len(result))
}


Measured memory_bytes: 640