akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  s="$"+s+"$";
  int n=s.size();
  string t;
  int ans=0;
  vector<int> r(n,-1);
  for(int i=0;i<n;i++){
    if(s[i]=='x') ans++;
    else{
      r[t.size()]=i;
      t+=s[i];
    }
  }
  string u=t;
  reverse(u.begin(),u.end());
  if(t!=u){
    cout<<-1<<endl;
    return 0;
  }
  //cout<<t<<endl;
  int x=t.size();
  if(x==0){
    cout<<0<<endl;
    return 0;
  }
  if(x%2){
    for(int i=1;i<=x/2;i++){
      int tmp=min(r[x/2-i+1]-r[x/2-i]-1,r[x/2+i]-r[x/2+i-1]-1);
      //cout<<i<<":"<<tmp<<endl;
      ans-=tmp*2;
    }
  }else{
    //assert(0);
    ans-=r[x/2]-r[x/2-1]-1;
    for(int i=1;i<x/2;i++){
      int tmp=min(r[x/2-1-i+1]-r[x/2-1-i]-1,r[x/2+i]-r[x/2+i-1]-1);
      ans-=tmp*2;
    }
    
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;

struct UnionFind {
  // 要素に対応する値は自分の根。根は要素数の-1倍したものを代入する。
  // 根ならそのグループの要素数(負)が、子であれば親の番号が入る。初期値-1。
  vector<int> uni;
  UnionFind(){
    uni = vector<int>(200100, -1);
  }

  // 頂点aの所属するグループを調べる。
  int root(int a)
  {
    // uni[a]が負の値なら親はa自身
    if (uni[a] < 0) return a;
    // 正の値であれば、親ルートを調べ戻り値で根に直接つなぐ。
    else {
      uni[a] = root(uni[a]);
      return uni[a];
      // return uni[a] = root(uni[a]);
    }
  }

  // 頂点aとbをつなぐ、もともと同じグループの場合falseを返す。
  bool connect(int a, int b)
  {
    a = root(a);
    b = root(b);
    if (a == b) return false;

    // aを大きなグループにしたいので、逆であれば入れ替える。
    if (uni[a] > uni[b])
    {
      int hoge = a;
      a = b;
      b = hoge;
    }

    //aとbを結合し、bをaの親とする。
    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  //  頂点a, bが同じグループか
  bool isConnect(int a, int b)
  {
    return root(a) == root(b);
  }

  // 頂点aを含むグループの頂点数を調べる
  int size(int a)
  {
    return -uni[root(a)];
  }

};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  UnionFind uni;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    uni.connect(a, b);
  }

  int res = -1;
  for (int i = 0; i < n; ++i) {
    chmax(res, uni.size(i));
  }

  cout << res << endl;

}


Measured memory_bytes: 3988
y=raw_input()
f=0
if len(y)==1:
    print -1,-1
elif len(y)==2:
    if y[0]==y[1]:
        print 1,2
    else:
        print -1,-1
else:
    for i in range(len(y)-2):
        if y[i]==y[i+1] or y[i+1]==y[i+2] or y[i+2]==y[i]:
            print i+1,i+3
            f=1
            break
    if f!=1:
        print -1,-1

Measured memory_bytes: 5892
#include <bits/stdc++.h>
#define int long long
#define ld long double

using namespace std;


void solve(){
    int n;
    cin >> n;
    bool bad = false;
    vector < int > a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    bad = (a[0] != 0);
    for(int i = 0; i < n - 1; ++i){
        if(a[i + 1] - a[i] > 1)bad = 1;
    }
    if(bad){
        cout << -1;
        return;
    }
    vector < int > mx(n, 0);
    for(int i = 0; i < n; ++i){
        mx[i - a[i]] = max(mx[i - a[i]], a[i]);
    }
    int ans = 0;
    for(int i = 0; i < mx.size(); ++i)ans += mx[i];
    cout << ans << "\n";
}




signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        cin >> t;
    #endif
    for(int i = 0; i < t; ++i){
        solve();
    }
}


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

vector<int> z_algorithm(const string &s) {
  vector<int> prefix(s.size(), 0);
  for (int i = 1, j = 0; i < s.size(); i++) {
    if (i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while (i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    prefix[i] = min(i, prefix[i]);
  }
  return prefix;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    auto t = s.substr(i, n - i);
    auto z = z_algorithm(t);
    ans = max(ans, *max_element(begin(z), end(z)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    negative = len([True for ai in a if ai <= 0])
    ans = sum([abs(ai) for ai in a])
    if negative % 2 == 0:
        print(ans)
    else:
        m = min([abs(ai) for ai in a])
        print(ans - m * 2)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 14412
#include <stdio.h>

int main(void){
    long int i,j,tmp,N,M,K,A[200000],B[200000],ans=0,time;
    scanf("%ld %ld %ld",&N,&M,&K);

    for(i=0;i<N;i++){
        scanf("%ld",&A[i]);
    }
    for(i=0;i<M;i++){
        scanf("%ld",&B[i]);
    }

    long int A2[200001],B2[200001];
    A2[0] = 0;
    B2[0] = 0;

    for(i=1;i<=N;i++){
        A2[i] = A2[i-1] + A[i-1];
    }
    for(i=1;i<=M;i++){
        B2[i] = B2[i-1] + B[i-1];
    }

    tmp=M;

    for(i=0;i<=N;i++){
        for(j=tmp;j>=0;j--){
            if(A2[i] + B2[j] <= K){
                if(ans < i+j) ans = i+j;
                tmp = j;
                break;
            }
        }
    }

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

    return 0;
}

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

int n,q;
int xarr[200001];
int yarr[200001];
typedef pair<int,int> P;
P query[200000];

int main() {
    scanf("%d %d",&n,&q);
    for(int i=0;i<q;i++) {
        int type,x;
        scanf("%d %d",&type,&x);
        query[i]=P(type,x);
        if (type==1) {
            xarr[x]=1;
        }
        else {
            yarr[x]=1;
        }
    }
    int mxx=n-1;
    int mxy=n-1;
    long long ret=1LL*(n-2)*(n-2);
    for(int i=0;i<q;i++) {
        if (query[i].first==1) {
            if (query[i].second>mxx) {
                continue;
            }
            for(int j=mxx;j>=query[i].second;j--) {
                if (xarr[j]) {
                    ret-=mxy-1;
                }
            }
            mxx=query[i].second-1;
        }
        else {
            if (query[i].second>mxy) {
                continue;
            }
            for(int j=mxy;j>=query[i].second;j--) {
                if (yarr[j]) {
                    ret-=mxx-1;
                }
            }
            mxy=query[i].second-1;
        }
    }
    printf("%lld",ret);
}

Measured memory_bytes: 6792
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;
static const int MAX_M = 20;

int N, M;
int K[MAX_N];
int sum[MAX_M][MAX_N + 1];
int dp[1 << MAX_M];

int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++) cin >> K[i];
	fill(sum[0], sum[M], 0);
	for(int i = 0; i < N; i++) sum[K[i] - 1][i + 1]++;
	for(int i = 0; i < M; i++){
		for(int j = 1; j <= N; j++){
			sum[i][j] += sum[i][j - 1];
		}
	}
	fill(dp, dp + (1 << M), 0);
	for(int i = 1; i < (1 << M); i++){
		int minimum_num = MAX_N + 1;
		for(int j = 0; j < M; j++){
			if(!(i & (1 << j))) continue;
			int replaced_doll_num = 0;
			for(int k = 0; k < M; k++){
				if(j == k) continue;
				if(i & (1 << k)) replaced_doll_num += sum[k][N];
			}
			minimum_num = min(minimum_num, dp[i - (1 << j)] + sum[j][N] - (sum[j][replaced_doll_num + sum[j][N]] - sum[j][replaced_doll_num]));
		}
		dp[i] = minimum_num;
	}
	cout << dp[(1 << M) - 1] << endl;
	return 0;
}


Measured memory_bytes: 15392
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

vector<vector<int>> v(200020);
ll n,c[200020];
vector<vector<ll>> cnt(200020);
ll rem[200020];

int dfs(int p, int pre){
    int ret = 1;
    for(auto i:v[p]){
        if(i != pre){
            int t = dfs(i,p);
            cnt[p].push_back(t);
            ret += t;
        }
    }
    rem[p] = n - ret;
    return ret;
}

ll ans[200020];
ll used[200020];

void f(int p,int pre){
    ll sum = 0;
    for(auto i:cnt[p]){
        sum += i;
    }
    ans[c[p]] += sum + rem[p] - used[c[p]]+1;
    ans[c[p]] += (rem[p] - used[c[p]]) * sum;
    ll tmp = sum;
    for(auto i:cnt[p]){
        sum -= i;
        ans[c[p]] += i*sum;
    }
    int k = 0;
    for(auto i:v[p]){
        if(i != pre){
            int t = used[c[p]];
            used[c[p]] = rem[i];
            f(i,p);
            used[c[p]] = t;
            k++;
        }
    }
    used[c[p]] += tmp+1;
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>c[i];
        c[i]--;
    }
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0,-1);
    f(0,-1);
    for(int i=0;i<n;i++){
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 49980
n=input()

l=len(n)
if int(n)>9:
  ans=[9]
else:
  print(int(n))
  exit()
tmp=n[l-1]
for i in range(2,l+1):
  #print(tmp, int(n[l-i]))
  if int(tmp) != 9:
    tmp=int(n[l-i])-1
    #print("tmp:",tmp)
  else:
    tmp=int(n[l-i])
  if i==l:
    ans.append(int(tmp))
  else:
    ans.append(9)
  #print(ans)
print(sum(ans))

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    ll cnt = 0;
    ll ans = 0;
    for (int i = 0; i < 3; i++) {
        if(S[i] == 'R'){
            cnt++;
        } else {
            ans = max(cnt,ans);
            cnt = 0;
        }
    }
    ans = max(cnt,ans);
    cout << ans << endl;
}

Measured memory_bytes: 3620
from collections import deque
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
nord = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for i in range(Q):
    a, b = map(int, input().split())
    nord[a-1] += b

d = deque()
d.append(0)
Done = [-1]*N

while d:
    x = d.popleft()
    for i in edge[x]:
        if Done[i] != -1:
            continue
        nord[i] += nord[x]
        d.append(i)
    Done[x] += 1

for i in nord:
    print(i)


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

int main() {
	// your code goes here
	string s;
	string c;
	long long int i,d=0;
	cin>>s>>c;
	for(i=0;i<s.size();i++)
	{
		if(s[i]==c[i])d++;
	}
	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;
// const ll MOD = 1000000007;

int main() {
  int N;
  ll M;
  cin>>N>>M;
  ll ans = 1;
  for (ll i = M / N; i >= 2; i--) {
    if (M % i != 0) continue;
    if ((M - i) % i == 0) {
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Number
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string s = Console.ReadLine().Trim('\n');
                if(s == "0 0") break;
                int[] i = s.Split(' ')
                           .Select(e => int.Parse(e))
                           .ToArray();
                int a = i[0];
                int b = i[1];
                for(int j = 0; j < a; j++)
                {
                    string _c = (j % 2) == 0 ? "#." : ".#";
                    string _t = "";
                    for(int k = 0; k < b; k++)
                    {
                        _t = _t + ((k % 2) == 0 ? _c[0] : _c[1]);
                    }
                    Console.WriteLine(_t);
                }      
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9648
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = 0
for a in A:
    if x >= a:
        cnt += 1
        x -= a
    else:
        x = 0
if x > 0:
    cnt -= 1
print(cnt)

Measured memory_bytes: 3568
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

int main(){
  ll n;
  cin>>n;
  cout<<n*n*n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;
class Prime_Numbers{
 private:
    std::vector<int> PN;
    std::vector<bool> isp;
 public:
    Prime_Numbers(int N){
        isp.resize(N+1,true);
        isp[0]=isp[1]=false;
        for(int i=2;i<=N;++i) if(isp[i]){
            PN.push_back(i);
            for(int j=2*i;j<=N;j+=i) isp[j]=false;
        }
    }
    int operator[](int i){return PN[i];}
    int size(){return PN.size();}
    int back(){return PN.back();}
    bool isPrime(int q){return isp[q];}
};
int main(){
    int X;cin>>X;
    Prime_Numbers p(X+100000);
    REP(i,p.size()) if(p[i]>=X){
        cout<<p[i]<<endl;
        return 0;
    }
}

Measured memory_bytes: 512
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.IORef
import Control.Monad.ST
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete


main = map fst . filter ((>=25) . snd) . map ((\[s,w,h] -> (s, readDouble w / readDouble h ^ 2)) . wordsBy (==',')) . lines <$> getContents >>= mapM_ putStrLn

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		String S = nextString();
		long K=nextLong();
		char[] X = (S).toCharArray();
		long[] n = new long[S.length()];
		Arrays.fill(n, 0);
		int idx=0;
		long repC=1;
		for(int i=0;i<X.length-1;i++){
			if(X[i]==X[i+1]){
				repC++;
			}else{
				n[idx]=repC;
				idx++;
				repC=1;
			}
		}
		n[idx]=repC;
		long a=n[0];
		long b=repC;
		long c=0;
		for(int i=0;i<n.length;i++){
			c+=n[i]/2;
		}
		c=c-(a/2+b/2);
		long ans;
		if(repC==S.length()){
			ans=(repC*K)/2;
		}else{
			if(X[0]==X[X.length-1]){
				ans = a/2+b/2+(c)*K +((a+b)/2)*(K-1);
			}else{
				ans = (a/2+b/2+c)*K;
			}
		}
		System.out.println(ans);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 21588
MOD = 10**9 + 7
S = int(input())
Comb = [[0 for __ in range(S+1)] for _ in range(S+1)]
#DP[n][m]=nCm
for n in range(S+1):
    for m in range(n+1):
        if n*m==0:
            Comb[n][m] = 1
        else:
            Comb[n][m] = (Comb[n-1][m] + Comb[n-1][m-1])%MOD
        if n + 2*m > S:
            break

# sを0以上l+1個に分割する→S-3L-3+L C Lを考えたい
#s + L = S-2L 
#ここで、S = Sorig - 3L より、S + L < S

ans = 0
for L in range(S//3):
    ans += Comb[S-2*L-3][L]
    ans %= MOD
print(ans)

Measured memory_bytes: 100684
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N], dp[N][2];

int main(){
    int n; scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    dp[2][0] = abs(a[2] - a[1]);
    //cout << dp[2][0] << endl;
    dp[2][1] = 1e8;
    for(int i = 3; i <= n; i++){
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][1])+ abs(a[i] - a[i - 1]);
        dp[i][1] = min(dp[i - 2][0], dp[i - 2][1]) + abs(a[i] - a[i - 2]);
      // cout << dp[i][0] << " " << dp[i][1] << endl;
    }
    printf("%d\n", min(dp[n][0], dp[n][1]));


}

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

int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  vector<int> time(N);
  for (int i = 0; i < N; i++){
    cin >> button.at(i);
  }
  int a = button.at(0);
  int m = 1;
  time.at(0) = 1;
  while (a != 2){
    m++;
    time.at(a - 1)++;
    if (time.at(a - 1) > 1){
      cout << -1 << endl;
      break;
    }
    a = button.at(a - 1);
  }
  if (a == 2)
    cout << m << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cctype>
#include <iostream>
using namespace std;

int n;
set<string> st;
vector<vector<string> > group;
map<string,int> gindex;
vector<bool> flag;


void func(int index){
	flag[index] = true;
	map<string,int>::iterator it;

	for(int i = 0; i < group[index].size(); ++i){
		it = gindex.find(group[index][i]);

		if( it == gindex.end() ){
			st.insert(group[index][i]);
		}
		else if( !flag[it->second] ){
			func(it->second);
		}
	}
}


void check_name(string s){
	if(s.empty() || s.size() > 15){
		throw 0;
	}
	for(int i = 0; i < s.size(); ++i){
		if(!islower(s[i])){
			throw 0;
		}
	}
}


int main(){
	char str[64] = "";
	int n;

	string ln;
	while(1){
		getline(cin, ln);
		int d0 = -9, d1 = -9;
		char cc = 0;
		sscanf(ln.c_str(), " %n%d%c", &d0, &n, &cc);
		if(d0 != 0 || cc != 0){
			throw 0;
		}
		if(n == 0){ break; }
		
		if(n > 100){ throw 0; }
		
		group.assign(n, vector<string>());
		flag.assign(n, false);
		st.clear();
		gindex.clear();

		for(int i = 0; i < n; ++i){
			getline(cin, ln);
			const char *ptr = ln.c_str();

			d0 = d1 = -9;
			sscanf(ptr, " %n%[^:]:%n", &d0, str, &d1);
			if(d0 != 0 || d1 == -9){ throw 0; }
			gindex[str] = i;
			ptr += d1;
			
			check_name(str);

			char ch = ',';
			while(ch != '.'){
				d0 = d1 = -9;
				ch = 0;
				sscanf(ptr, " %n%[^,.]%c%n", &d0, str, &ch, &d1);
				if(d0 != 0 || d1 == -9 || (ch != '.' && ch != ',')){
					throw 0;
				}
				group[i].push_back(str);
				ptr += d1;
				check_name(str);
			}
			if(*ptr){
				throw 0;
			}
			
			if(group[i].empty() || group[i].size() > 10){
				throw 0;
			}
		}

		func(0);
		cout << st.size() << endl;
	}
	
	if(!cin.good()){
		throw 0;
	}
	cin.peek();
	if(cin.good()){
		throw 0;
	}
	
	for(volatile int i = 0; i < 100000000; ++i);
}

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

int main()
{
    string s_ball, t_ball;
    cin >> s_ball >> t_ball;
    
    int s_num, t_num;
    cin >> s_num >> t_num;

    string go_away_ball;
    cin >> go_away_ball;

    if(go_away_ball==s_ball) s_num -= 1;
    if(go_away_ball==t_ball) t_num -= 1;

    cout << s_num << " " << t_num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    int n, ch;
    vector<int> b(110);
    vector<int> ans(110);
    cin >> n;
    rep(i,n) {
        cin >> b[i];
    }
    rep(i,n) {
        ch = 0;
        for(int j = n - i - 1;j > -1; j--) {
            if(b[j] == j + 1) {
                ch = 1;
                ans[n - i - 1] = j + 1;
                for(int k = j;k < n - i;k++) {
                    b[k] = b[k+1];
                }
                break;
            }
        }
        if(ch == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}

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

int main(void) {
    ll x; cin >> x;
    ll cnt = 0, money = 100;

    while(1) {
      money += money/100;
      cnt++;
      if(money >= x) break;
    }

    cout << cnt << endl;
    
    return 0;
}

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

int main(){
  
  using namespace std;
  
  int N, D;
  cin >> N >> D;
  
  vector<int> X(N);
  vector<int> Y(N);
  
  int count = 0;
  
  for(int i = 0; i < N; i++){
    cin >> X.at(i) >> Y.at(i);
    if(sqrt(pow(X.at(i), 2) + pow(Y.at(i), 2)) <= D){
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
  
}

Measured memory_bytes: 4828
#include<stdio.h>
#define NUM 10000

int main(){
  int i,j,count=0,n;
  int a[NUM];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    for(j=2;j*j<=a[i];j++){
      if(a[i]%j==0){
	count++;
	break;
      }
    }
    
  }

  printf("%d\n",n-count);
  return 0;
}



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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

const string chars[10] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};

int n;

void rec(string s, int m){
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    for(int i=0;i<m;i++){
        rec(s + chars[i], m);
    }
    rec(s + chars[m], m + 1);
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n;
    rec("a", 1);
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>

#define N 530

int main(void)
{
	char s[N][N],a[N];
	int n,l,i,j;
	scanf("%d%d",&n,&l);
	for(i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(strcmp(s[j-1],s[j])>0){
				strcpy(a,s[j-1]);
				strcpy(s[j-1],s[j]);
				strcpy(s[j],a);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s",s[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
# 2019-11-23 01:28:44(JST)
import sys


def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    # 各indexを基点として、右側の白の数と左側の黒の数の和の最小値を求めればいい
    black_count = s.count('#')
    
    left_black = 0
    right_white = n - black_count
    minimum = left_black + right_white
    for i in range(0, n):
        if s[i] == '#':
            left_black += 1
        elif s[i] == '.':
            right_white -= 1
        minimum = min(minimum, left_black + right_white)
    
    print(minimum)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n;
	cin >> n;
	map<int,int> a;
	REP(i,n){
		int input;
		cin >> input;
		a[input]++;
	}

	ll b=0;
	for(auto x: a){
		b += x.second - 1;
	}
	
	if(b%2==0){
		cout << a.size() << endl;
	}else{
		cout << a.size()-1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 8056
import sys
h, w = map(int, input().split())
if h == 1 or w == 1:
    print(1)
    sys.exit()
if w % 2 == 0:
    a = w // 2
else:
    a = (w // 2) + 1

if h % 2 == 0:
    print(w * (h//2))
else:
    print(w * (h//2) + a) 

Measured memory_bytes: 38256
#include <stdio.h>
int main(){

  char a[11];
  int amo=0,i,result=0;

  scanf("%s",a);

  for(i = 0; a[i] != '\0'; i++) amo++;

  for(i = 0; i < amo/2; i++){

    if(a[i] == 'i' && a[amo-1-i] != 'i') result++;
    if(a[i] == 'w' && a[amo-1-i] != 'w') result++;
    if(a[i] == '(' && a[amo-1-i] != ')') result++;
    if(a[i] == ')' && a[amo-1-i] != '(') result++;

  }

  if(amo%2 == 1){

    if(a[amo/2] != 'i'){

      if(a[amo/2] != 'w'){

        result++;

      }

    }

  }
  
  // printf("%d\n",amo);
  printf("%d\n",result);

  return 0;

}
    

Measured memory_bytes: 2740
def rect?(arr)
   arr[2] ** 2 == arr[0] ** 2 + arr[1] ** 2
end
def loze?(arr)
   arr[0] == arr[1]
end
#main
arr = Array.new
r = 0
l = 0
while line = gets
   arr << line
end
arr.each do |i|
   a = i.split(",")
   a.map!{|j| j.to_i}
   if rect?(a)
      r += 1
   elsif loze?(a)
      l += 1
   end
end
puts r
puts l

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
    
int main(){
	int m1,m2,d;
    cin>>m1>>d;
    cin>>m2>>d;
    int ans=0;
    if(m1!=m2){
        ans=1;
    }
    OUT(ans);
	return 0;
}

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

const double EPS = 0.05;
inline double dis(vector<double> a, vector<double> b){
  double res = 0;
  for(int i=0;i<3;i++)res += (a[i]-b[i])*(a[i]-b[i]);
  return sqrt(res);
}

int main(){
  int casenum;
  cin >> casenum;
  while(casenum--){
    double qr,rp,pq;
    cin >> qr >> rp >> pq;
    int n;
    cin >> n;
    vector< vector<double> > vp(n,vector<double>(3));
    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++)cin >> vp[i][j];
    }

    bool f = true;
    for(int i=0;f && i<n;i++){
      for(int j=0;f && j<n;j++){
	if(i==j)continue;
	for(int k=0;f && k<n;k++){
	  if(i==k)continue;

	  double d1 = dis(vp[j],vp[k]), d2 = dis(vp[k],vp[i]), d3 = dis(vp[i],vp[j]);
	  double ratio = d1/qr;
	  if( abs(ratio*rp-d2)<EPS && abs(ratio*pq-d3)<EPS){
	    cout << i+1 << " " << j+1 << " " << k+1 << endl;
	    f = false;
	  }
	}
      }
    }
  }
}

Measured memory_bytes: 1256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int X, Y, T, N, i;
	scanf("%d", &N);

	X = 0, Y = 0, T = 0;
	while (N--) {
		int nx, ny, nt;
		scanf("%d %d %d", &nt, &nx, &ny);

		int d = abs(X - nx) + abs(Y - ny);
		if (d % 2 != (nt - T) % 2 || d > nt - T) return !printf("No\n");

		X = nx, Y = ny, T = nt;
	}
	return !printf("Yes\n");
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	set<int> cnt;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (cnt.count(a)) {
			cnt.erase(a);
		}
		else {
			cnt.insert(a);
		}
	}
	cout << cnt.size() << "\n";
}

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int N,M; cin >> N >> M;
    VVI pref(N,VI(M,0));
    REP(i,N){
        int k; cin >> k;
        REP(j,k){
            int a; cin >> a; a--;
            pref[i][a] = 1;
        }
    }
    int ans = 0;
    REP(i,M){
        bool flag = true;
        REP(j,N){
            if(pref[j][i] == 0){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

//aのp乗を求める
ll modpow(ll a, int p) {
    if(p == 0) return 1;
    if(p % 2 == 0) {
        int halfP = p / 2;
        ll half = modpow(a, halfP);
        //a^(p/2)をhalfとして、half*halfを計算
        return half * half % MOD;
    } else {
        //pが奇数のときは偶数にするために1減らす
        return a * modpow(a, p-1) % MOD;
    }
}

//10C3 (10*9*8) / (3*2*1) 
//(10*9*8):ansMul (3*2*1):ansDiv 
ll calcComb(int a, int b) {
    if(b > a - b) return calcComb(a, a - b);

    ll ansMul = 1;
    ll ansDiv = 1;
    rep(i, b) {
        ansMul *= (a - i);
        ansDiv *= (i + 1);
        ansMul %= MOD;
        ansDiv %= MOD;
    }
    //ansMul / ansDiv をしたい
    //ansDivの逆元を求める
    ll ans = ansMul * modpow(ansDiv, MOD - 2) % MOD;

    return ans;
}

int main() {
    int n, m; 
    cin >> n >> m;
    
    int MNokori = m;
    ll ans = 1;
    for(int i = 2; i * i <= MNokori; i++) {
        if(MNokori % i == 0) {
            int cnt = 0;
            while (MNokori % i == 0) {
                cnt++;
                MNokori /= i;
            }
            ans *= calcComb(n + cnt - 1, cnt);    
            ans %= MOD;
        }
    }
    if(MNokori != 1) {
        //最後に素数が残っている分を処理する
        ans *= calcComb(n + 1 - 1, n - 1);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from math import sin, cos, pi, sqrt


A, B, H, M = map(int, input().split())

x = pi / 2 - 2 * pi * M / 60
y = pi / 2 - 2 * pi * (60 * H + M) / 720

x1, y1 = (B * cos(x), B * sin(x))
x2, y2 = (A * cos(y), A * sin(y))

l = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print(l)


Measured memory_bytes: 9508
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int a,b;
  cin >> a >> b;
  //if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
    //else{cout<<"Impossible"<<endl;}
 cout <<(a-1)*(b-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <double,double>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
//const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("robot.in","r",stdin);
   freopen("robot.out","w",stdout);
}
const ll INF = (ll)1e9 + 7ll;
const ll INF1 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTmx = (int)1e9;
const ld EPS = (ld)1e-9;
const int N = 2e3 + 100;
ll dp[N][N];
bool u[N][N];
pll a[N];
void calc(int l,int r)
{
	pll mx = a[r - l + 1];
	u[l][r] = 1;
	if(l == r)
	{
		dp[l][r] = mx.f * abs(mx.s - l);
		return;
	}
	if(!u[l + 1][r])
	{
		calc(l + 1,r);
	}
	if(!u[l][r - 1])
	{
		calc(l,r - 1);
	}
	ll ans = 0;
	ll dd = mx.f * abs((mx.s - l));
	ll tt = mx.f * abs((mx.s - r));
	ans = max(ans,dp[l + 1][r] + dd);
	ans = max(ans,dp[l][r - 1] + tt);
	dp[l][r] = ans;
}
int main()
{
    //file();
    boos();
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
    	cin >> a[i].f;
    	a[i].s = i;
	}
	sort(a + 1,a + n + 1);
	calc(1,n);
	cout << dp[1][n];
}

Measured memory_bytes: 30932
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)

	for i := x; i <= 100003; i++ {
		if isPrime(i) {
			fmt.Println(i)
			return
		}
	}
}

func isPrime(n int) bool {
	for i := 2; i < n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
const int MAXN = 65535 + 5;
const double INF = 2e9;
const ll MOD = 1e9 + 7;
ll dp[63][2];
ll ans = 0;
//#define DEBUG

int main(){
  FastIO;
  #ifdef DEBUG
    freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  ll powe[63];
  powe[0] = 1;
  for (int i = 1; i < 63; ++i)
  {
    powe[i] = powe[i - 1] * 2 % MOD;
  }
  forn(i, n)
  {
    unsigned long long a;
    cin >> a;
    ll k = 62;
    while(k >= 0)
    {
      int ch = ((a >> k) & 1);
      if (ch == 1)
      {
        ans += dp[k][0] * powe[k];
        ans %= MOD;
        dp[k][1]++;
      }
      else
      {
        ans += dp[k][1] * powe[k];
        ans %= MOD;
        dp[k][0]++;
      }
      --k;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 3010;
const int mo = 1e+9+7;

LL f1[N][N],f2[N][N];
int n,m;

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();m=get();
	fo(i,1,n)f1[0][i]=1;
	f2[0][0]=1;
	fo(i,0,m-1){
		fo(j,0,n){
			if (f1[i][j]){
				if (j>1)f1[i+1][j-1]=add(f1[i+1][j-1],f1[i][j]);
				if (j==1)f2[i+1][0]=add(f2[i+1][0],f1[i][j]);
				if (j>1)f1[i+1][j]=add(f1[i+1][j],f1[i][j]);
				if (j==1)f2[i+1][1]=add(f2[i+1][1],f1[i][j]);
				if (j<n)f1[i+1][j]=add(f1[i+1][j],f1[i][j]);
				if (j<n)f1[i+1][j+1]=add(f1[i+1][j+1],f1[i][j]);
			}
			if (f2[i][j]){
				if (j>=1)f2[i+1][j-1]=add(f2[i+1][j-1],f2[i][j]),f2[i+1][j]=add(f2[i+1][j],f2[i][j]);
				if (j<n)f2[i+1][j]=add(f2[i+1][j],f2[i][j]),f2[i+1][j+1]=add(f2[i+1][j+1],f2[i][j]);
			}
		}
	}
	LL ans=0;
	fo(i,0,n)ans=add(ans,f2[m][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 139904
#include <stdio.h>

int main(void)
{
	int i, j;
	int now;
	char str[101], ans[1000];
	
	while (~scanf("%s", str)){
		for (i = now = 0; str[i] != '\0'; i++){
			if (str[i] != '@'){
				ans[now] = str[i];
				now++;
			}
			else {
				for (j = 0; j < str[i + 1] - '0'; j++, now++){
					ans[now] = str[i + 2];
				}
				i += 2;
			}
		}
		ans[now] = '\0';
		printf("%s\n", ans);
	}
	
	return (0);
}

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

using namespace std;

#define MAX 1000001
using ull = unsigned long long;

const ull b = 1000000007ULL;

vector<ull> rolling_hash(char* S, int N, vector<ull>& p)
{
    vector<ull> h(N + 1);
    for (int i = 0; i < N; i++) {
        h[i + 1] = h[i] * b + S[i];
        p[i + 1] = p[i] * b;
    }
    return h;
}

int main()
{
    char S[MAX];
    scanf("%s", S);
    
    int N = strlen(S);
    vector<ull> p(N + 1);
    p[0] = 1;
    
    auto h = rolling_hash(S, N, p);    
    
    int mini = MAX;
    for (int i = 0; i < N; i++) {
        int A = i + 1;
        int B = (N - 3 * A) / 2;

        if (B <= 0) continue;
        if ((N - 3 * A) % 2 != 0) continue;

        auto A1 = h[A] - h[0] * p[A];
        auto B1 = h[A + B] - h[A] * p[B];
        auto A2 = h[A * 2 + B] - h[A + B] * p[A];
        auto B2 = h[2 * (A + B)] - h[A * 2 + B] * p[B];
        auto A3 = h[N] - h[2 * (A + B)] * p[A];

        if (A1 == A2 && A2 == A3 && B1 == B2) {
            mini = min(mini, A + B);
        }
    }    
    
    if (mini == MAX) {
        printf("mitomerarenaiWA\n");
    } else {
        printf("Love ");
        for (int i = 0; i < mini; i++) {
            printf("%c", S[i]);
        }
        printf("!\n");
    }        
    return 0;
}

Measured memory_bytes: 19468
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()

mas = []
for i in range(H):
    mas.append(s())

for i in range(H):
    for j in range(W):
        if mas[i][j] == '#':
            if (i > 0 and mas[i-1][j] == '#') or \
               (i < H-1 and mas[i+1][j] == '#') or \
               (j > 0 and mas[i][j-1] == '#') or \
               (j < W-1 and mas[i][j+1] == '#'):
                pass
            else:
                print('No')
                import sys
                sys.exit()

print('Yes')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int N,K;
    cin>>N>>K;
    int D[K];
    for(int i=0;i<K;i++){
        cin>>D[i];
    }
    int check[10];
    for(int i=0;i<10;i++){
        check[i]=1;
    }
    for(int i=0;i<10;i++){
       for(int j=0;j<K;j++){
           if(i==D[j]) check[i]=0;
       }
    }
    for(int i=N;i<10*N;i++){
        int num=i;
        int a=num%10; num=num/10;
        int b=num%10; num=num/10;
        int c=num%10; num=num/10;
        int d=num%10; num=num/10;
        int e=num%10;
        if(check[a]!=0&&check[b]!=0&&check[c]!=0&&check[d]!=0&&check[e]!=0) {cout<<i; break; }
        else if(check[a]!=0&&check[b]!=0&&check[c]!=0&&check[d]!=0&&e==0) {cout<<i; break;}
        else if(check[a]!=0&&check[b]!=0&&check[c]!=0&&d==0&&e==0) {cout<<i; break;}
        else if(check[a]!=0&&check[b]!=0&&c==0&&d==0&&e==0) {cout<<i; break;}
        else if(check[a]!=0&&b==0&&c==0&&d==0&&e==0) {cout<<i; break;}
    }
    
    return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> dp(n, 0);
    int ans = n;
    int b, a;
    
    for (int i = 1; i < n; i++) {
        if (s[i] == 'E') {
            dp[0]++;
        }
    }
    
    for (int i = 1; i < n; i++) {
        dp[i] = dp[i - 1];
        
        if (s[i - 1] == 'W') {
            dp[i]++;
        }
        
        if (s[i] == 'E') {
            dp[i]--;
        }
    }
    
    rep(i, n) {
        ans = min(ans, dp[i]);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll n, l;
    cin >> n >> l;

    vector<ll> as(n);
    rep (i, n) { as[i] = l + i; }

    ll sum = 0;
    rep (i, n) { sum += as[i]; }

    ll distance = static_cast<ll>(1e9);
    ll ans = 0;

    rep (i, n)
    {
        const ll val = abs(as[i]);

        if (val < distance)
        {
            ans = sum - as[i];
            distance = val;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()

    if K == 1:
        print(0)
    else:
        print(N - K)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>

#define rep(p,q) for(int i = p;i < q;i++)

using namespace std;

const int cons = 1e9 + 7;

int main(void) {
	long long int people[6]{0,0,0,0,0,0};
	long long int viecle[5];
	long long int n;
	cin >> n >> viecle[0] >> viecle[1] >> viecle[2] >> viecle[3] >> viecle[4];
	long long int ans = 0;
	int index = -1;
	long long int mini = 1e15 + 7;
	rep(0, 5) {
		if (mini > viecle[i]) {
			mini = viecle[i];
			index = i;
		}
		
	}
	if (n % viecle[index] != 0) n += viecle[index];
	ans = mini > n ? 5 : 4 + n / viecle[index];
	cout << ans << endl; 


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vll a(2*m),b(2*m);
  rep(i,m) {
    cin>>a[i]>>b[i];
    b[i+m]=a[i];
    a[i+m]=b[i];
  }
  vll t(n);
  rep(i,n){
    t[i]=i+1;
  }
  ll ans=0;
  do{
    if(t[0]!=1) break;
    ll cu=0;
    rep(i,n-1){
      rep(j,2*m){
        if(t[i]==a[j]&&t[i+1]==b[j]){
          cu++;
        }
      }

      if(cu==n-1){

        ans++;
      }
    }
  }while(next_permutation(t.begin(), t.end()));
  COUT(ans);
}


Measured memory_bytes: 256