akhauriyash/Code-Regression huggingface dataset:
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
  if (ch == '-') f = -1;
  ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
  x = 10 * x + ch - '0';
  ch = getchar();
  }
  return x * f;
}

const int mod = 998244353;
const int maxn = 330;
const int maxm = 100100;
int n;
int a[maxn];
int f[maxn][maxm], g[maxn][maxm];

inline int ksm(int x, int p) {
  int ret = 1;
  while (p) {
    if (p & 1) ret = ret * 1ll * x % mod;
    x = x * 1ll * x % mod; p >>= 1;
  }
  return ret;
}
inline void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}

void work() {
  n = read(); int s = 0;
  rep(i, 1, n) a[i] = read(), s += a[i];
  f[0][0] = 1; g[0][0] = 1;
  rep(i, 0, n - 1) rep(j, 0, s) {
    if (!f[i][j]) continue;
    // cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
    add(f[i + 1][j + a[i + 1]], f[i][j]);
    add(f[i + 1][j], f[i][j] * 2 % mod);
    add(g[i + 1][j + a[i + 1]], g[i][j]);
    add(g[i + 1][j], g[i][j]);
  }
  int num = ksm(3, n), sum = 0;
  rep(i, 0, s) {
    if (i >= s - i) {
      add(sum, f[n][i]);
    }
  }
  if (s % 2 == 0) sum = (sum - g[n][s / 2] + mod) % mod;
  num = num - (sum * 3ll % mod);
  num = (num % mod + mod) % mod;
  printf("%d\n", num);
}

int main() {
  #ifdef LZT
  freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}

Measured memory_bytes: 235776
#include <stdio.h>

int main(){
	int gramme;
	int weight[10]={512,256,128,64,32,16,8,4,2,1},onOff[10];
	int i,flag;
	
	while(scanf("%d",&gramme)!=EOF){
		flag=0;
		for(i=0;i<10;i++){
			onOff[i]=gramme/weight[i];
			gramme%=weight[i];
		}
		
		for(i=9;i>=0;i--){
			if(onOff[i]){
				if(flag){
					printf(" ");
				}else{
					flag=1;
				}
				printf("%d",weight[i]);
			}
		}
		printf("\n");
		
	}
	
	return 0;
}

Measured memory_bytes: 0
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,X = map(int,readline().split())
D = [0] + list(map(int,readline().split()))
readline()
Q = list(map(int,read().split()))

# 各日の出発座標
start = [X] * (N+2)
for n,d in enumerate(D[1:],1):
    x = start[n]
    y = min(x, abs(x - d))
    start[n+1] = y

# 各日において、失敗に至る出発座標の最小値
min_ng = [1] * (N+2)
for n in range(N,0,-1):
    d = D[n]
    x = min_ng[n+1]
    y = x + d
    if x + x <= d:
        y = x
    min_ng[n] = y

answer = ['YES' if x >= y else 'NO' for x,y in zip(start, min_ng[1:])]
print('\n'.join(answer[q] for q in Q))

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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string

#define sz(x) x.size()
#define INF LONG_MAX
#define IINF LLONG_MAX
#define PI (2.0*acos(0.0))

#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define sfd2(x,y) scanf("%lf %lf",&x,&y);

#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))

#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Rof(i, j, k) for(int i = j; i >= k; i--)
#define all(x) x.begin(),x.end()
#define asort(x) sort(all(x));
#define dsort(x) sort(all(x), greater<int>())
#define unq(x) x.erase(unique(x.begin(),x.end()),x.end())

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;

LL gcd(LL a,LL b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}

LL bigmod(LL base, LL power, LL mod)
{
    if(power==0) return 1;
    else if(power%2==1)
    {
        LL value1 = base % mod; LL value2 = (bigmod(base,power-1,mod))%mod;
        return (value1*value2)%mod;
    }
    else
    {
        LL value1 = (bigmod(base,power/2,mod))%mod;
        return (value1*value1)%mod;
    }
}


int main()
{
    S s1,s2;
    cin>>s1>>s2;

    if(sz(s1)+1==sz(s2))
    {
        bool check = false;
        for(int i=0; i<sz(s1); i++)
        {
            if(s1[i]!=s2[i])
            {
                check = true;
            }
        }

        if(check) printf("No");
        else printf("Yes");
    }
    else printf("No");
}


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

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

 int main() {
   int ans;
   string S;

   cin >> S;

   S.erase(unique(S.begin(), S.end()), S.end());

   if (S.length() == 1) ans = 0;

   else ans = S.length() - 1;

   cout << ans << endl;
 }


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> pp;
typedef pair<pp,int> P;
char t[2500001],p[1001];
int a[2500001],d[1000001],i;
P b[1000001];

void mk(){
  for(i=0;t[i]!=0;i++)
    b[i].f.f=t[i],b[i].s=i;
  b[i].f.f=0,b[i].s=i;

  for(int j=1;j<=i;j*=2){
    sort(b,b+i+1);
    a[b[0].s]=0;
    for(int k=1,l=0;k<=i;k++)
      if(b[k-1].f==b[k].f)a[b[k].s]=l;
      else a[b[k].s]=++l;
    for(int k=0,o=b[0].s;k<=i;k++,o=b[k].s)
      b[k]=P(pp(a[o],a[o+j]),o);
  }
  sort(b,b+i+1);
  a[b[0].s]=0;
  for(int k=1,l=0;k<=i;k++)
    if(b[k-1].f==b[k].f)a[b[k].s]=l;
    else a[b[k].s]=++l;
  for(int j=0;j<=i;j++)d[a[j]]=j;
}

void bs(int n){
  int l=0,r=i,m;
  while(l<r){
    m=(l+r)/2;
    if(strncmp(t+d[m],p,n)<0)l=m+1;
    else r=m;
  }
  if(strncmp(t+d[l],p,n) ==0 )cout<<"1"<<endl;
  else cout<<"0"<<endl;
}


int main(){
  int q;
  scanf("%s",t);
  mk();
  cin>>q;
  while(q--&&scanf("%s",p))bs(strlen(p));
  return 0;
}

Measured memory_bytes: 25760
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll dp[n+1];
    memset(dp,0,sizeof(dp));
    rep(i,1,n+1)
    {
        dp[i]+=dp[i-1];
        if(s[i-1]=='R')
            dp[i]++;
    }
    ll ans=min(dp[n],n-dp[n]);
    rep(i,1,n)
    {
        ll xr=dp[i],xw=i-dp[i];
        ll yr=dp[n]-dp[i],yw=n-i-yr;
        ll mini=min(xw,yr);
        ll res=mini;
        xw-=mini;
        xr+=mini;
        yr-=mini;
        yw+=mini;
        res=mini+xw+yr;
        ans=min(ans,res);
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5308
package main

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

func main() {
	io := newIo()
	n := io.nextInt()
	k := io.nextInt()

	dic := map[int]int{}
	for range make([]struct{}, n) {
		a := io.nextInt()
		dic[a]++
	}
	seq := []int{}
	for _, v := range dic {
		seq = append(seq, v)
	}
	sort.Ints(seq)

	cnt := 0
	for len(seq) > k {
		cnt += seq[0]
		seq = seq[1:]
	}
	fmt.Println(cnt)
}

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}


Measured memory_bytes: 23680
N, K = map(int, input().split())
*A, = map(int, input().split())
l = len(set(A))
if l <= K:
    print(0)
    exit()

dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
from operator import itemgetter
dic_s = sorted(dic.items(), key=itemgetter(1))
i = 0
ans = 0
while l > K:
    l -= 1
    k, v = dic_s[i]
    ans += v
    i += 1
print(ans)

Measured memory_bytes: 49848
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template<class T, class V> typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v){ t = v; } template<class T, class V> typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){ for(auto &e : t) fill(e, v); }
#define int long long
const int MOD = 1e9 + 7;

signed main(){

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

  int ans = k;
  function< void(int,int) > dfs =
  [&](int u, int pre){
    int have = k - 1;
    if(pre != -1) have--;
    for(int v : G[u]){
      if(v == pre) continue;
      dfs(v, u);
      ans = (ans * have) % MOD;
      have--;
    }
    return;
  };
  dfs(0, -1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

bool graph[55][55];
bool visited[55];

void dfs(int n) {
    if(visited[n]) return;
    visited[n] = true;
    for(int i = 0; i < 55; i++) {
        if(graph[n][i]) dfs(i);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        ab.push_back(make_pair(a, b));
        graph[a][b] = true;
        graph[b][a] = true;
    }

    int ans = 0;

    rep(i, m) {
        bool isAllReached = true;
        rep(j, n) visited[j] = false;
        graph[ab[i].first][ab[i].second] = false;
        graph[ab[i].second][ab[i].first] = false;
        dfs(0);
        rep(j, n) if(!visited[j]) isAllReached = false;
        graph[ab[i].first][ab[i].second] = true;
        graph[ab[i].second][ab[i].first] = true;
        if(!isAllReached) ans += 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int[] T = new int[N];
        for(int i=0; i<N; i++){
            T[i] = Integer.parseInt(sc.next());
        }
        
        int M = Integer.parseInt(sc.next());
        
        for(int i=0; i<M; i++){
            int p = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());
            
            int ans = 0;
            for(int j=0; j<N; j++){
                if(j == p-1){
                    ans += x;
                }else{
                    ans += T[j];
                }
            }
            
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 23892
#include<iostream>

using namespace std;
int main()
{
	int n,a[1010],big = -1,small = 2e9,ans = 0;
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		 big = max(big,a[i]);
		 small = min(small,a[i]);
	}
	
	cout << big - small << endl;
	
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
lis=[]
for i in range(n):
  lis.append([0,0])
for i in range(m):
  p,s=map(str,input().split())
  p=int(p)-1
  if s=="AC":
    lis[p][0]=1
  else:
    if lis[p][0]==0:
      lis[p][1]+=1
  
ac=0  
wa=0
for i in range(0,n):
  ac+=lis[i][0]
  if lis[i][0]==1:
    wa+=lis[i][1]
  
print(ac,wa)

Measured memory_bytes: 13172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<int> f(ll x){
    vector<int> ans(50);
    if(x%4 == 0 || x%4 == 3) ans[0] = 0;
    else ans[0] = 1;
    for(int i = 1;i < 50;i++){
        if(x%2 == 1) ans[i] = 0;
        else if(x%ll(pow(2,i+1)) < ll(pow(2,i))) ans[i] = 0;
        else ans[i] = 1;
    }
    return ans;
}

int main(){
    ll a,b; cin >> a >> b;
    vector<int> num;
    num = f(b);
    if(a != 0) {
        vector<int> num1 = f(a-1);
        rep(i,50){
            if(num1[i]) num[i] = 1-num[i];
        }
    }
    ll ans = 0;
    for(int i = 49;i >= 0;i--){
        ans = ans*2+num[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    int n, k;
    cin >> n >> k;
    vi dp(n, INF), a(n);
    for (auto &i: a) {
        cin >> i;
    }
    dp[0] = 0;
    rep(i,0,n) {
        rep(j,i+1,i+k+1) {
            if (j >= n) break;
            dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
        }
    }
    cout << dp[n-1] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  pr((n-1)*(m-1));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val n = StdIn.readLine().toInt
    val h = StdIn.readLine().toInt
    val w = StdIn.readLine().toInt
    val ans = (n - h + 1) * (n - w + 1)
    println(ans)
  }

}


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

bool sosuu(int x,int y){
  for(int i = 2;i <= y;i++){
    if(x%i == 0 && x != i) return false;
  }
  return true;
}

int main() {
  int n,ans = 0;
  cin >> n;
  for(int i = 0;i < n;i++){
    long a;
    cin >> a;
    if(sosuu(a,sqrt(a)+1)) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3104
/*input
3 2
#.#
.#.
#.#
#.
.#
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

string a[maxn],b[maxn];

int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) cin>>a[i];
	REP(i,m) cin>>b[i];

	REP(i,n-m+1) REP(j,n-m+1){
		bool flag = 1;
		REP(x,m) REP(y,m){
			if(a[x+i][y+j]!=b[x][y]) flag=0;
		}
		if(flag){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";


	return 0;
}


Measured memory_bytes: 4992
# - coding : utf-8 -*-

if __name__ == "__main__":

    n, k = map(int, input().split())
    an = list(map(int, input().split()))
    an.sort()

    p = [1] * 41
    for i in range(40):
        p[i+1] = p[i] * 2
        
    ans = 0
    x = 0
    for i in range(41):
        t = p[40-i]
        if x + t > k:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            ans += cnt * t
        else:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            if cnt <= n/2:
                x += t
            ans += max(cnt, n-cnt) * t
    print(ans)

Measured memory_bytes: 14708
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu


h, w = [int(i) for i in input().split()]
n = int(input())
a = [int(i) for i in input().split()]

# 単純に時計回りに配置していけばいいだけ
tile = [[0 for _ in range(w+2)] for _ in range(h+2)]
visited = [[False for _ in range(w+2)] for _ in range(h+2)]
for i in range(len(visited)):
    for j in range(len(visited[0])):
        if i == 0 or i == len(visited)-1 or j == 0 or j == len(visited[0])-1:
            visited[i][j] = True
color = [0 for _ in range(h*w)]
counter = 0
for i in range(len(a)):
    color[counter:counter+a[i]] = [i + 1 for _ in range(a[i])]
    counter += a[i]
# print("color:{}".format(color))
dir = "r" # r, l, u, d
x, y = [1, 1]
while True:
    if len(color) == 0:
        break
    _color = color.pop()
    tile[x][y] = _color
    visited[x][y] = True
    if dir == "r":
        if not visited[x+1][y]:
            x += 1
        else:
            dir = "d"
            y += 1
    elif dir == "d":
        if not visited[x][y+1]:
            y += 1
        else:
            dir = "l"
            x -= 1
    elif dir == "l":
        if not visited[x-1][y]:
            x -= 1
        else:
            dir = "u"
            y -= 1
    elif dir == "u":
        if not visited[x][y-1]:
            y -= 1
        else:
            dir = "r"
            x += 1
for i in range(1, len(tile)-1):
    print(listToString(tile[i][1:-1], " "))

Measured memory_bytes: 3696
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

data Direction = North | East | West | South | Right | Left deriving (Eq, Read, Show)

type Dice = (Int, Int, Int, Int, Int, Int)
initDice = (1,2,3,4,5,6) :: Dice

topDice :: Dice -> Int
topDice (t,_,_,_,_,_) = t

rot :: Direction -> Dice -> Dice
rot North (a1,a2,a3,a4,a5,a6) = (a2,a6,a3,a4,a1,a5)
rot East  (a1,a2,a3,a4,a5,a6) = (a4,a2,a1,a6,a5,a3)
rot West  (a1,a2,a3,a4,a5,a6) = (a3,a2,a6,a1,a5,a4)
rot South (a1,a2,a3,a4,a5,a6) = (a5,a1,a3,a4,a6,a2)
rot Main.Right (a1,a2,a3,a4,a5,a6) = (a1,a3,a5,a2,a4,a6)
rot Main.Left  (a1,a2,a3,a4,a5,a6) = (a1,a4,a2,a5,a3,a6)

main = do
    n <- getInt
    unless (n==0) $ do
        ops <- map (rot . read) <$> replicateM n getLine
        print $ sum $ map topDice $ scanl (flip ($)) initDice ops
        main
    


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




void solve()
{
       
       int n;  
       cin >> n ;
       double p[n];
       
       vector< vector< double > > memo( n+1, vector<double> (n+1, 0 )); 
       //double memo[n+1][n+1]; 
       
       // probality of getting 
       memo[0][0] = 1;
       for(int i = 1 ; i <= n ; i ++)
       {
            double p_head ; cin >> p_head;
            double p_tail = 1 - p_head; 

            for(int j = 0; j <= i ; j ++)
            {
            	if( j == 0 )
            	{
            		memo[i][j] = memo[i-1][j] * p_tail;
            	}
            	else if( j == i ) 
            	{
            		memo[i][j] = memo[i-1][j-1] * p_head;
            	}
            	else
            	{
                    memo[i][j] = memo[i-1][j] * p_tail;
                    memo[i][j] += memo[i-1][j-1] * p_head;
            	}
            }

       }

       int k = n/2 + 1 ;

       double res = 0 ;

       for(int i = k ; i <= n ; i ++)
       	   res += memo[n][i];

       	printf("%.10lf\n",res);   
       


}

int main()
{

	 //ios_base::sync_with_stdio(false);
	 //cin.tie(NULL);

	 int test = 0, t = 1;
	 if(test) cin >> t;
	 for(int i = 0 ; i < t ; i ++)
	 {
         solve(); 
	 }

	return 0;
}


Measured memory_bytes: 73732
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeScanner(1024)
	s := eGetLine(scanner)

	lastc := ' '
	for _, c := range s {
		if lastc == c {
			fmt.Println("Bad")
			return
		}
		lastc = c
	}
	fmt.Println("Good")
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	buf.WriteString("[")
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = ", "
	}
	buf.WriteString("]")
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}

// func min(a []int) int {
// 	m := a[0]
// 	for _, v := range a {
// 		if v < m {
// 			m = v
// 		}
// 	}
// 	return m
// }

func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}
func find(n int, a ints) int {
	for i, v := range a {
		if n == v {
			return i
		}
	}
	return -1
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int takahasi = Integer.parseInt(in.next());
            int aoki = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            boolean flg = true;

            for (int i = 0; i < k; i++) {
                if (flg) {
                    aoki += q(takahasi);
                    takahasi = q(takahasi);
                    flg = !flg;
                } else {
                    takahasi += q(aoki);
                    aoki = q(aoki);
                    flg = !flg;

                }
            }
            // 出力
            out.printf("%d %d\n", takahasi, aoki);

        }

        public static int q(int mine) {
            int tmp = 0;
            if (mine % 2 != 0) mine--;
            tmp = mine / 2;
            return tmp;
        }

    }
}



Measured memory_bytes: 23764
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i) 
const int N = 2005, inf = 1e9 + 7 ;
using namespace std ;

int n, a[N], cnt ;
bool G[N][N], vis[N] ;

int gcd(int x, int y) {
	return (y ? gcd(y, x % y) : x) ;
}

vector <int> dfs(int p) {
	vis[p] = false ;
	vector <int> res, A, B ;
	res.push_back(a[p]) ;
	rep(i, 0, n) A.push_back(0) ;
	rep(u, 1, n) if (G[p][u] && vis[u]) {
		B = dfs(u) ;
		int na = (int) res.size() - 2, nb = (int) B.size() - 1, topa = 0, topb = 0 ;
		rep(i, 0, na) A[i] = res[i + 1] ;
		rep(i, 1, nb + 1) res.push_back(0) ;
		rep(i, 1, na + nb + 2) {
			if (topa <= na && (topb > nb || A[topa] >= B[topb])) res[i] = A[topa ++] ; else res[i] = B[topb ++] ;
		} 
	}
	return res ;
}

int main() {
	scanf("%d", &n) ;
	cnt = 0 ;
	rep(i, 1, n) scanf("%d", &a[i]) ; sort(a + 1, a + n + 1) ;
	rep(i, 0, n) G[i][0] = G[0][i] = vis[i] = true ;
	rep(i, 1, n) rep(j, 1, n) G[i][j] = G[j][i] = (gcd(a[i], a[j]) != 1) ;
	vector <int> ans = dfs(0) ;
	rep(i, 0, n - 1) printf("%d ", ans[i + 1]) ; puts("") ;
	return 0 ; 
}

Measured memory_bytes: 20608
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int mid = a[(n / 2)-1];
	int nex = a[(n / 2)];
	cout << abs(nex - mid) << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    long long i,n,ans=0,a,s[100];
    s[0]=1;
    for(i=1;i<40;i++)
        s[i]=s[i-1]*2;
    scanf("%lld",&n);
    while(n--)
    {
        scanf("%lld",&a);
        for(i=39;i>=0;i--)
            if(a%s[i]==0) break;
        ans+=i;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main()
{
	string str;
	int data[10][10];
	while (cin>>str)
	{
		for (int j = 0; j < 10; j++)
		{
			data[0][j] = str[j] - '0';
		}

		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 9-i ; j++)
			{
				data[i + 1][j] = (data[i][j] + data[i][j + 1]) % 10;
			}
		}

		cout << data[9][0] << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
int l,r,d;
cin >> l >> r >> d;
int x = (l-1)/d;
int y = r/d;
cout << y - x << endl;

}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		int max = 0;
		int[] line = new int[n - 1];

		for (int i = 0; i < n - 1; i++) {
			line[i] = Integer.parseInt(sc.next());
		}

		max += line[0] + line[line.length - 1];

		for (int i = 0; i < n - 2; i++) {
			max += Math.min(line[i], line[i + 1]);
		}

		System.out.println(max);

	}
}

Measured memory_bytes: 21844
N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[1]
X=[True]*N
X[0]=False
num=1
for i in range(K):
    num=A[num-1]
    if X[num-1]:
        l.append(num)
        X[num-1]=False
    else:
        q=l.index(num)
        l=l[q:]
        print(l[(K-q)%len(l)])
        exit()
print(l[-1])

    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 32268
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <limits>
#include <cassert>

#define seq(i, n) for (int i = 0; i < (n); i++)
#define seq2(i, f, t) for (int i = (f); i < (t); i++)
#define rev(i, n) for (int i = (n); i >= 0; i--)
#define rev2(i, f, t) for (int i = (f); i >= (t); i--)
#define all(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;

int solve(int n,int a,int b) {
    return min({n*a,b});
}

int main() {
  #ifdef TEST
    solve();
  #else
    int n,a,b;
    cin>>n>>a>>b;
    cout<<solve(n,a,b)<<endl;
  
  #endif

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
  string s; cin >> s;
  int cnt = 0;
  rep(i, s.length()){
    if(s[i] == '2') cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int N, T;
	cin >> N >> T;

	vector<pair<int, int>> root(N);
	for (int i = 0; i < N; i++) cin >> root[i].first >> root[i].second;
	sort(root.begin(), root.end());

	for (int i = 0; i < N; i++) {

		if (root[i].second <= T) {
			cout << root[i].first << "\n";
			return 0;
		}

	}

	cout << "TLE" << "\n";

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}
    
void run(){
    int n;
    cin>>n;
    vi p(n),q(n),r(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    rep(i,n)r[i]=i+1;
    int a,b;
    int i=0;
    do{
        if(r==p)a=i;
        if(r==q)b=i;
        i++;
    }while(next_permutation(all(r)));
    cout<<abs(a-b)<<endl;
}

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

#define REP(i, a) for(int i=0; i<(int)(a); i++)
#define REP1(i, a, b) for(int i=(int)(a); i<=(int)(b); i++)
typedef long long LL;

const int MAX_N = 100005;
int n, k, A[MAX_N];

int cost(int a, int b) {
    return abs(A[a]-A[b]);
}

void solve() {
    scanf("%d %d", &n, &k);
    REP(i, n) {
        scanf("%d", &A[i]);
    }
    int dp[MAX_N]={};
    REP(i, n) dp[i] = 1e9;
    dp[0] = 0;
    REP(i, n) {
        // cout << dp[i] << endl;
        REP1(j, 1, k) {
            if(i+j<n) dp[i+j] = min(dp[i+j], dp[i] + cost(i, i+j));
        }
    }

    printf("%d\n", dp[n-1]);
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <tuple>
#include <queue>

using namespace std;

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

  char hw[h][w];
  queue<tuple<int, int, int>> q;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf("%c", &hw[i][j]);
      if (hw[i][j] == '#') {
        q.push(make_tuple(i, j, 1));
      }
    }

    scanf("\n");
  }

  int ans = 0;

  while (!q.empty()) {
    tuple<int, int, int> e = q.front();
    q.pop();

    int qc = q.size();
    int i = get<0>(e), j = get<1>(e), c = get<2>(e);

    if (i > 0 && hw[i - 1][j] == '.') {
      hw[i - 1][j] = '#';
      q.push(make_tuple(i - 1, j, c + 1));
    }

    if (i < h - 1 && hw[i + 1][j] == '.') {
      hw[i + 1][j] = '#';
      q.push(make_tuple(i + 1, j, c + 1));
    }

    if (j > 0 && hw[i][j - 1] == '.') {
      hw[i][j - 1] = '#';
      q.push(make_tuple(i, j - 1, c + 1));
    }

    if (j < w - 1 && hw[i][j + 1] == '.') {
      hw[i][j + 1] = '#';
      q.push(make_tuple(i, j + 1, c + 1));
    }

    if (qc != q.size() && c > ans) {
      ans = c;
    }
  }

  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 13328
#include <vector>
#include <iostream>

using namespace std;

vector<int> color;
int N;

int rec(const vector<vector<int> > &graph, int n, int depth) {
  if (depth == N) {
    return 1;
  }

  int sum = 0;
  for (auto t : graph[n]) {
    if (color[t]) continue;
    color[t] = 1;
    sum += rec(graph, t, depth + 1);
    color[t] = 0;
  }
  return sum;
}

int main() {
  int M;
  cin >> N;
  cin >> M;
  int a, b;
  color = vector<int>(N, 0);
  color[0] = 1;
  vector<vector<int> > graph(N);
  for (int i = 0; i < M; ++i) {
    cin >> a;
    cin >> b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  printf("%d\n", rec(graph, 0, 1));
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#define rep(i,n) for (int i=0;i<(int)n;i++)
#define pb push_back
typedef long long ll;
using namespace std;
int ans;
int main()
{
	ios_base::sync_with_stdio(false);
	string a,b;
	cin>>a>>b;
	if (a[0]==b[0]) ans++;
	if (a[1]==b[1]) ans++;
	if (a[2]==b[2]) ans++;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int arive[101][101];
int main(void){
  int n,m;
  while(cin>>n>>m){
    if(n==0) break;
    int ans = 0;
    vector<pair<int,PII> > route;
    REP(i,n)REP(j,n)arive[i][j] = 1;
    REP(i,m){
      int a,b,l;
      scanf("%d,%d,%d",&a,&b,&l);
      l = (l-1)/100;
      route.push_back(pair<int,PII>(l,PII(a,b)));
    }
    sort(route.begin(),route.end());
    REP(i,route.size()){
      int a = route[i].second.first;
      int b = route[i].second.second;
      if(arive[a][b]){
        arive[a][b] = arive[b][a] = 0;
        REP(k,n)REP(i2,n)REP(j,n) arive[i2][j] = min(arive[i2][j]
            ,arive[i2][k] + arive[k][j]);
        ans += route[i].first;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String []args) {
        Scanner in = new Scanner(System.in);
        String []unit = {
            "", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
                "Sei", "Sai", "Gok", "Ggs","Asg", "Nyt", "Fks", "Mts"
        };

        while (true) {
            BigInteger x = BigInteger.valueOf(10000);
            BigInteger M = in.nextBigInteger();
            int N = in.nextInt();
            if(N == 0){ break; }
            M = M.pow(N);
            BigInteger[] arr = new BigInteger[18];
            for(int i = 0 ; i < 18 ; i++) {
                arr[i] = M.mod(x);
                M = M.divide(x);
            }
            for(int i = 17 ; i >= 0 ; i--){
                if(arr[i].equals(BigInteger.ZERO)){ continue; }
                System.out.print(arr[i] + unit[i]);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 20592
import java.io.*;
import java.util.ArrayList;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        ArrayList<Integer> A = new ArrayList<>();
        int cont = 0;
        for (String s:str.split(" ")){
            if (Integer.parseInt(s) < 0){
                cont++;
            }
            A.add(Math.abs(Integer.parseInt(s)));
        }
        int min = 1_000_000_000;
        long ans = 0;
        for (int i:A){
            ans += (long)i;
            if (i < min){
                min = i;
            }
        }
        if (cont % 2 == 1){
            ans -= (long)min * 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50348
fun main(args: Array<String>) {
    // Your code here!
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)
    var total = A.last()
    var b = Math.pow(10.0,5.0).toInt()
    for (a in A) {
        total += Math.min(a, b)
        b = a
    }
    println(total)
}

Measured memory_bytes: 37744
import numpy as np
N, K, Q = map(int, input().split())
A = []
for i in range(Q):
  a = int(input())
  A.append(a)
participant = [] 
for i in range(N):
  participant.append(K)
participant_arr = np.array(participant) 
for i in range(Q):
  participant_arr -= 1
  participant_arr[A[i] - 1] += 1
for i in range(N):
  if participant_arr[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 32376
#include <cstdio>
long long n;
int main(){
    while(~scanf("%lld",&n)){
        long long t=n/11,r=n%11;
        if(r>6)printf("%lld\n",t*2+2);
        else if(r==0)printf("%lld\n",t*2);
        else printf("%lld\n",t*2+1);
    }return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int grid[3][3];
  for(int i=0;i<3;i++){
  	for(int j=0;j<3;j++){
  		cin>>grid[i][j];
  	}
  }

  if(grid[0][0]-grid[0][1]==grid[1][0]-grid[1][1]&&grid[0][0]-grid[0][1]==grid[2][0]-grid[2][1]&&
  	 grid[0][1]-grid[0][2]==grid[1][1]-grid[1][2]&&grid[0][1]-grid[0][2]==grid[2][1]-grid[2][2]){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}  







Measured memory_bytes: 256
/*
  -> Do Good Die Great
*/
#include <bits/stdc++.h>
#define int long long int
#define pii pair<int, int>
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define MOD 1000000007
#define Hiraishin                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr);
#define tests \
    int t;    \
    cin >> t; \
    while (t--)
using namespace std;

// global

void solve()
{
    int n, k;
    cin >> n;
    int arr[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    int dp[n + 1];
    dp[0] = 0;
    dp[1] = 0;
    for (int i = 2; i <= n; i++) {
        int res = INT_MAX, cost = 0;
        res = min(res, dp[i - 1] + abs(arr[i] - arr[i - 1]));
        if (i - 2 > 0)
            res = min(res, dp[i - 2] + abs(arr[i] - arr[i - 2]));
        dp[i] = res;
        //cout << dp[i] << ' ';
    }
    cout << dp[n] << '\n';
}

signed main()
{
    Hiraishin
    // tests
    solve();
    return 0;
}

Measured memory_bytes: 5192
#include <stdio.h>

int main(void){
    int n;
    int a[100000];
    scanf("%d", &n);
    int i, j, k;
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    long long int ans = 1;
    long long int mod = 1000000007;
    int co[] = {0, 0, 0};
    long long int cnt;
    //とりあえず，先頭の1人を赤，次の人を青と仮定して計算し，後で6倍する
    for(i = 0; i < n; i++){
        cnt = 0;
        for(j = 0; j < 3; j++){
            if(co[j] == a[i]){
                if(cnt == 0){
                    co[j]++;
                }
                cnt++;
            }
        }
        ans *= cnt;
        ans %= mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2112