akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void) {
    char string1[11], string2[11];
    int i, j, l, k, length;
    while(scanf("%s",string1) != EOF) {
        for(i = 0; i < 10; i++ ) {
            string1[i] -= 48;
        }
        for(l = 10; l > 0; l-- ) {
            for(i = 0; i < l - 1; i++ ) {
                string2[i] = (string1[i] + string1[i + 1]) % 10;
            }

            for(i = 0; i < l - 1; i++ ) {
                string1[i] = string2[i];
            }
        }
        printf("%d\n",(int)string1[0]);
    }
    return 0;
}

Measured memory_bytes: 540
#include<stdio.h>
int main(){
	int a,b,c,i;
	scanf("%d %d %d",&a,&b,&c);
	for(i=1;i<=b;i++)
    {
        if(i*a%b==c)
        {
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
stri=input()
c1=0
c2=0
n=len(stri)
i=0

c1beg=0
c2beg=1
while(i<n):
	if(int(stri[i])!=(c1beg%2)):
		c1+=1
	if(int(stri[i])!=(c2beg%2)):
		c2+=1
	c1beg+=1
	c2beg+=1
	i+=1
print(min(c1,c2))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    double cnt=0;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        cnt+=1.0/a;
    }
    cout<<1.0/cnt<<endl;
    
}



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

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    for (int i=n-1; i>0; --i) {
        if (h[i] < h[i-1]) h[i-1]--;
    }
    bool ans = true;
    for (int i=0; i<n-1; ++i) {
        if (h[i] > h[i+1]) ans = false;
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
fun main() {
    val s= readLine()!!
    val n=s.length
    val k= readLine()!!.toInt()
    var subs= mutableSetOf<String>()
    for (i in 0 until n){
        for (j in i until Math.min(n, i+k)){
            val sub=s.slice(i until j+1)
            subs.add(sub)
        }
    }
    println(subs.sorted()[k-1])
}

Measured memory_bytes: 45420
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#define RG register
using namespace std;
const int N=1e5+10;
struct dabt{ int next,to; }e[N<<1];
struct node{
	int id,num;
	bool operator <(const node&x)const{return x.num<num;}
};
int head[N],k,n,m,num[N];
bool vis[N],fx[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
inline void add(int from,int to){e[++k]=(dabt){head[from],to}; head[from]=k;}
priority_queue<node>pn;
int main()
{
//	freopen("Integers on a Tree.in","r",stdin);
	read(n);
	for(RG int i=1,a,b;i<n;i++)
	{
		read(a,b);
		add(a,b); add(b,a);
	}
	read(m);
	for(RG int i=1,a,b;i<=m;i++)
	{
		read(a,b);
		num[a]=b; fx[a]=1;
		pn.push((node){a,b});
	}
	while(!pn.empty())
	{
		node u=pn.top(); pn.pop();
		int id=u.id, x=u.num; vis[id]=1;
		for(RG int i=head[id];i;i=e[i].next)
		{
			int v=e[i].to, tt=x+1;
			if(vis[v]) continue ;
			if(!fx[v])
			{
				vis[v]=1; num[v]=tt;
				pn.push((node){v,tt});
			}
			else if(num[v]!=tt) return printf("No\n"), 0;
		}
	}
	printf("Yes\n"); for(RG int i=1;i<=n;i++) printf("%d\n",num[i]);
	return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

/* a と b の最小公倍数を求める */
long long LCM(long long a, long long b)
{
    long long g = GCD(a, b);
    return a / g * b;
}

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

signed main()
{
    int K, N;
    cin >> K >> N;
    int ans = 0;
    int tmp;
    int in;
    int bef;
    REP(i, N)
    {
        if (i == 0)
        {
            cin >> in;
            tmp = in;
            bef = in;
        }
        else if (i == N - 1)
        {
            cin >> in;
            tmp += (K - in);
            ans = max(ans, in - bef);
            ans = max(ans, tmp);
        }
        else
        {
            cin >> in;
            ans = max(ans, in - bef);
            bef = in;
        }
    }
    cout << K - ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int n;

vvector<ll> dp;
vector<pll> balloons;
int x;

ll get_min(int target, int carry){
	if(target==n+1){
		return balloons[n].first;
	}
	if(dp[target][carry]>=0)return dp[target][carry];
	ll res = INFLL;
	pii before = balloons[target-1];
	int now_time = before.second;
	int now_pos = before.first;
	int next_time = balloons[target].second;
	int next_pos = balloons[target].first;
	if(carry<3){
		int dis = abs(next_pos-now_pos);
		int need_time = now_time + dis * (carry+1);
		if(need_time<=next_time){
			chmin(res, get_min(target+1, carry+1) + dis);
		}
	}
	{
		int need_time = now_time + now_pos * (carry+1) + next_pos;
		if(need_time<=next_time){
			chmin(res, get_min(target+1, 1) + now_pos+next_pos);
		}
	}
	if(res>=INFLL){
		chmax(x, target);
	}
	return dp[target][carry] = res;
}

int main(){
	while(cin>>n&&n){
		balloons.assign(n, pll(0, 0));
		foreach(i, balloons)cin>>i.first>>i.second;
		balloons.insert(balloons.begin(), pll(0, 0));
		dp.assign(n+1, vector<ll>(4, -1));
		x = -1;
		ll ans = get_min(1, 0);
		if(ans>=INF){
			cout << "NG" << " " << x << endl;
		}else{
			cout << "OK" << " " << ans << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 2996
#include<cstdio>
#include<algorithm>
using namespace std;
using LL=long long;

int N,W,w,v;
LL dp[100005];

int main()
{
	scanf("%d%d",&N,&W);
	for(int i=1;i<=N;i++)
	{
		scanf("%d%d",&w,&v);
		for(int j=W;j>=w;j--)
			dp[j]=max(dp[j],dp[j-w]+v);
	}
	printf("%lld",dp[W]);
	return 0;
} 

Measured memory_bytes: 896
#include<stdio.h>

int main(void)
{
  int a,b,c;
  int temp;


  scanf("%d%d%d",&a,&b,&c);


  if(b>c){
    temp=c;
    c=b;
    b=temp;
  }
if(a>b){
  temp=b;
  b=a;
  a=temp;

  }
 if(b>c){
    temp=c;
    c=b;
    b=temp;
  }

 printf("%d %d %d\n",a,b,c);

  return 0;
}

Measured memory_bytes: 1768
// https://atcoder.jp/contests/dp/tasks/dp_o

#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mp make_pair
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
void init() {
  int n;
  cin >> n;
  vector<vector<int>> match(n, vector<int>(n));
  vector<int>dp(1<<n);
  dp[0]=1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> match[i][j];
    }
  }
  for(int mask=0;mask<((1<<n)-1);mask++){
    int men = __builtin_popcount(mask);
    for(int women=0;women<n;women++){
      if(match[men][women] and !(mask & (1<<women))){
        int m2 = mask^(1<<women);
        (dp[m2]+=dp[mask])%=mod;
      }
    }
  }
  cout<<dp[(1<<n) - 1]<<endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
int a[N];
int n;

int main() {
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum ^= a[i];
    }
    for (int i = 0; i < n; ++i) {
        cout << (sum ^ a[i]) << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4396
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

void isSquare(int a){
    double b= sqrt(a);
    for(int i=2;i<=b;i++){
        if(i*i==a){cout<<"Yes"<<endl;return;}
    }
    cout<<"No"<<endl;
    return;
}

int main(){
    string a,b,c;
    cin>>a>>b;
    c=a+b;
    int num;
    num=stoi(c);

    isSquare(num);

    return 0;
}



Measured memory_bytes: 256
# 2019-11-23 21:00:35(JST)
import sys

def main():
    H, W, K = map(int, sys.stdin.readline().split())
    s = ['.' * (W+1)] + ['.' + sys.stdin.readline().rstrip() for _ in range(H)]


    res = [[None for _ in range(W + 2)]] + [[None] + [0 for _ in range(W)] + [None] for _ in range(H)] + [[None for _ in range(W + 2)]]

    number = 1
    for i in range(1, H+1):
        if not '#' in s[i]:
            continue
        else:
            j = 1
            while j <= W:
                res[i][j] = number
                if s[i][j] == '#':
                    res[i][j] = number
                    if '#' in s[i][j+1:]:
                        number += 1
                j += 1
            number += 1

    for i in range(1, H+1):
        if res[i][1] == 1:
            count = i
            break
    
    for i in range(1, count):
        res[i] = res[count]

    for i in range(1, H):
        if res[i+1][1] == 0:
            res[i+1] = res[i]
    
    for i in range(1, H+1):
        print(' '.join(map(str, res[i][1:W+1])))
    



        

if __name__ == '__main__':
    main()


Measured memory_bytes: 7280
def main():
    from itertools import permutations

    n, m, r, *x = map(int, open(0).read().split())
    to = x[:r]

    dis = [[10 ** 8] * (n + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        dis[i][i] = 0

    for a, b, c in zip(*[iter(x[r:])] * 3):
        dis[a][b] = c
        dis[b][a] = c

    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

    ans = 10 ** 8
    for p in permutations(to):
        tmp = 0
        nw = p[0]
        for nx in p[1:]:
            tmp += dis[nw][nx]
            nw = nx

        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83656
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
    long long int k, a, b, ans = 0;
    cin >> k >> a >> b;
    
    if (b - a > 2) {
        k -= a-1;
        ans += a;
        ans += k/2*(b-a) + k%2;
    } else {
        ans += k + 1;
    }
    
    cout << ans << "\n";
 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a=0,b=1,c=1,d=1,n,max=-1,k,ans=0;
    string s,s2;
    cin >> a;
    vector<bool> e(a+1);
    e[1] = true;
    for(int i=2;i<=a;i++){
        b=i*i;
        while(b<=a){
            e[b]=true;
            b *= i;
        }
    }
    for(int i=a;i>=1;i--){
        if(e[i]){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = input()
    k = ni()

    l = len(n)

    dp_true = [[0 for _ in range(k + 2)] for i in range(l + 1)]
    dp_false = [[0 for i in range(k + 2)] for j in range(l + 1)]
    dp_false[0][0] = 1

    for i in range(l):
        num = int(n[i])

        for j in range(k + 1):
            dp_true[i + 1][j] += dp_true[i][j]
            dp_true[i + 1][j + 1] += dp_true[i][j] * 9

            if num > 0:
                dp_true[i + 1][j + 1] += dp_false[i][j] * (num - 1)
                dp_true[i + 1][j] += dp_false[i][j]

            if num > 0:
                dp_false[i + 1][j + 1] += dp_false[i][j]
            else:
                dp_false[i + 1][j] += dp_false[i][j]

    print(dp_true[l][k] + dp_false[l][k])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10724
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
    int N = 0;
    int K = 0;
    unsigned long long int score_1 = 1;
    unsigned long long int score_2 = 1;
    unsigned long long int temp = 0;
    vector<unsigned long long int> A;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> temp;
        A.push_back(temp);
    }

    for (int i = 0; i < N - K; i++) {
        score_1 = A[i];
        score_2 = A[i + K];
        if (score_2 > score_1) {
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
        score_1 = score_2;
    }
    return 0;
}

Measured memory_bytes: 4844
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007



int main() {
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans = 1000000000;

  for (ll i = 0; i <= max(X, Y); i++) {
    ll x, y;
    X - i >= 0 ? x = X - i : x = 0;
    Y - i >= 0 ? y = Y - i : y = 0;
    ans = min(ans, A * x + B * y + C * 2 * i);
  }

  cout << ans << endl;


}


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

int main()
{

	int k;
	cin >> k;

	int l;
	if ((k%7)==0)
	{
		l=9*k/7;
	}
	else
	{
		l=9*k;
	}

	if ( (l%2==0) || (l%5==0) )
	{
		cout << -1 << endl;
		return 0;
	}

	int64_t pow10=10;
	for (int i=1;i<=l;++i)
	{
		if (pow10%l==1)
		{
			cout << i << endl;
			return 0;
		}
		pow10*=10;
		pow10%=l;
	}
	cout << -1 << endl;
	return 0;
}





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

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

            

            int[] a = new int[5];
            for(int b = 0; b < 5; ++b)
            {
                a[b] = int.Parse(Console.ReadLine());
            }
            int k = int.Parse(Console.ReadLine());
            for(int i = 0; i < 5; ++i)
            {
                for(int ii = 0; ii < 5; ++ii)
                {
                    if (a[ii] - a[i] > k)
                    {
                        Console.WriteLine(":(");
                        return;
                    }
                }
            }Console.WriteLine("Yay!");
        }
    }
}

Measured memory_bytes: 13140
#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 <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef long long ll;

int N;
ll A[300000 + 100];
ll cumsum[60 + 10][300000 + 100];

const ll MOD = 1000000007;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	for (int i = 0; i < 60; i++) {
		for (int j = 0; j < N; j++) {
			if ((A[j] >> i) & 1)cumsum[i][j + 1]++;
			cumsum[i][j + 1] += cumsum[i][j];
		}
	}

	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < 60; j++) {
			if ((A[i] >> j) & 1) {
				//j桁目が立ってる場合
				ans += ((1LL << j) % MOD) * ((N - 1LL - i) - (cumsum[j][N] - cumsum[j][i + 1]));
				ans %= MOD;
			}
			else {
				//j桁目が立ってない場合
				ans += ((1LL << j) % MOD) * (cumsum[j][N] - cumsum[j][i + 1]);
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 144128
#include <stdio.h>

using namespace std;

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

	for(int i = 1; i<= n; i++)
	{
		if(i%3 == 0){
			printf(" %d",i);
		}else{
			x = i;
			do{
				if(x%10 == 3){
					printf(" %d",i);
					break;
				}
				x /=10;
			}while(x);
		}
	}
	printf("\n");
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int n,cnt=0;
    ll sum=0;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    vector<vector<ll>> dp(n+1,vector<ll>(2));
    dp[0][0]=0;
    dp[0][1]=-LongINF;
    rep(i,n){
        dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
        dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
    }
    cout<<dp[n][0]<<endl;
    
    return 0;
}

//a=97,z=122

Measured memory_bytes: 6144
s=input()
k=int(input())

if k==1:
    print(int(s[0]))

elif int(s[0])==1:

    if len(s)<k:
        num=1
        for i in range(1, len(s)):
            if int(s[i])!=1:
                num=int(s[i])
                break
        print(num)

    else:
        if s[:k]=="1"*k:
            print(1)
        else:
            num=1
            for i in range(1, len(s)):
                if int(s[i])!=1:
                    num=int(s[i])
                    break
            print(num)

elif int(s[0])!=1:
    print(int(s[0]))

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int n;
    cin >> n;

    int answer = 0;
    int position = 1;
    while(n!=0){
        int residue = n % 10;
        if(residue == 1){
            answer += position * 9;
        }else{
            answer += position * 1;
        }
        n /= 10;
        position *= 10;
    }

    p(answer);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int k;
    cin >> k;
    
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    int ans = v[k-1];
    cout << ans << endl;
    
    return 0;
}


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

int ans[365],c[26],s[365][26],last[26],nowscore,csum;
const int INF=1e9,d=365;

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

void FIN(int a){
  if(a){
    ofstream fout("output.txt");
    REP(i,d)fout<<ans[i]+1<<"\n";
    fout.close();
    return;
  }
  REP(i,d)cout<<ans[i]+1<<"\n";
  return;
}

int score(){
  int res=0,minus=csum;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    minus-=c[ans[day]]*(day-last[ans[day]]);
    last[ans[day]]=day;
    res-=minus;
    minus+=csum;
  }
  return res;
}
void swap(){
  int A=rand();
  int day=A%(d-16),diff=(A&15)+1;
  swap(ans[day],ans[day+diff]);
  int R=score();
  if(R<nowscore)swap(ans[day],ans[day+diff]);
  else nowscore=R;
}
void onechange(){
  int day=rand()%d;
  int nowans=ans[day];
  REP(i,26){
    if(i==nowans)continue;
    int tmp=ans[day];
    ans[day]=i;
    int R=score();
    if(R<nowscore)ans[day]=tmp;
    else nowscore=R;
  }
}

int main(){
  memset(last,-1,sizeof(last));
  cin>>c[0];
  REP(i,26)cin>>c[i];
  REP(i,26)csum+=c[i];
  REP(i,d)REP(j,26)cin>>s[i][j];
  REP(day,d){
    int idx,mx=-INF;
    REP(i,26){
      int A=c[i]*(day-last[i])+s[day][i];
      if(mx<A)mx=A,idx=i;
    }
    ans[day]=idx,last[idx]=day;
  }
  nowscore=score();
  REP(_,170000){
    onechange();
    swap();
  }
  FIN(0);
}


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

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

    string s;
    cin >> s;
    int count = 0;

    for(int i = 0, size = s.size(); i < size; i++){
        if(s[i] == 'o'){
            count += 1;
        }
    }

    cout << 700 + 100 * count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long n,k,h[200000],dp[200000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>h[i];
	for(int i=2;i<=n;i++){
		if(i<=k){
			long mn=LONG_MAX;
			for(int j=1;j<=i-1;j++){
				mn=min(mn,dp[j]+abs(h[i]-h[j]));
			}
			dp[i]=mn;
		}else{
			long mn=LONG_MAX;
			for(int j=i-k;j<=i-1;j++){
				mn=min(mn,dp[j]+abs(h[i]-h[j]));
			}
			dp[i]=mn;
		}
	}
	cout<<dp[n];
}

Measured memory_bytes: 1792
a, b = map(int, input().split())
s = input()
ok = True
for i in range(a):
    if s[i] == '-': ok = False
if s[a] != '-': ok = False
for i in range(a + 1, a + b + 1):
    if s[i] == '-': ok = False
if ok: print('Yes')
else: print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    ll S;
    cin >> S;
    ll x2 = 1e9, y2 = 1;
    ll x3 = (x2 - S % x2) % x2;
    ll y3 = (S + x3) / x2;
    cout << "0 0 " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}


Measured memory_bytes: 256
from collections import deque

class mf_graph:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
    
    def add_edge(self,v,w,cap):
        edge = [w,cap,None]
        edge[2] = rev_edge = [v,0,edge]
        self.graph[v].append(edge)
        self.graph[w].append(rev_edge)
    
    def bfs(self,s,t):
        self.level = [None]*self.N
        dq = deque([s])
        self.level[s] = 0
        while dq:
            v = dq.popleft()
            nlevel = self.level[v]+1
            for w,cap,_ in self.graph[v]:
                if cap and self.level[w] is None:
                    self.level[w] = nlevel
                    dq.append(w)
        return self.level[t] is not None
    
    def dfs(self,s,v,f):
        if v == s:
            return f
        for rev in self.it[v]:
            w,_,e = rev
            cap = e[1]
            if cap and self.level[w] is not None:
                if self.level[v] > self.level[w]:
                    d = self.dfs(s,w,min(f,cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
        return 0
    
    def flow(self,s,t,flow_limit=float('inf')):
        flow = 0
        while self.bfs(s,t):
            *self.it, = map(iter,self.graph)
            f = flow_limit
            while f:
                f = self.dfs(s,t,flow_limit-flow)
                flow += f
        return flow

    def min_cut(self,s):
        visited = [False]*self.N
        dq = deque([s])
        while dq:
            v = dq.pop()
            visited[v] = True
            for w,cap,_ in self.graph[v]:
                if cap and not visited[w]:
                    dq.append(w)


N,M = map(int, input().split())
S = [list(input()) for i in range(N)]
dc = mf_graph(N*M+2)

s =N*M
t = N*M+1
for i in range(N):
    for j in range(M):
        if (i + j) % 2 == 0:
            dc.add_edge(s,M*i+j,1)
        else:
            dc.add_edge(M*i+j,t,1)

for i in range(N):
    for j in range(M):
        if j+1 < M and S[i][j] == "." and S[i][j+1] == ".":
            u,v = M*i+j,M*i+j+1
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u, v, 1)
        if i+1 < N and S[i][j] == "." and S[i + 1][j] == ".":
            u,v = M*i+j, M*(i+1)+j
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u, v, 1)

print(dc.flow(s, t))
for u in range(N*M+2):
    for v, cap, _ in dc.graph[u]:
        ui, uj = divmod(u, M)
        vi, vj = divmod(v, M)
        if (ui+uj) % 2 == 0 and cap == 0 and u != s and u != t and v != s and v!= t:
            if ui+1 == vi:
                S[ui][uj] = "v"
                S[vi][vj] = "^"
            elif ui == vi+1:
                S[ui][uj] = "^"
                S[vi][vj] = "v"
            elif uj+1 == vj:
                S[ui][uj] = ">"
                S[vi][vj] = "<"
            elif uj == vj+1:
                S[ui][uj] = "<"
                S[vi][vj] = ">"

for res in S:
    print("".join(res))


Measured memory_bytes: 86220
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
#define len(a)           int((a).size())
#define prec(n)          fixed<<setprecision(n)
#define cnt(n)           __builtin_popcountll(n)
#define pi               pair<int, int>
const int mod = 1000000007;
using namespace std;
// const int N = 1e5 + 5; 
// int n;
// int a[N];



int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;

const int N = 1e5 + 5;
// cin >>t;
while(t--){
	int n,k;
cin >> n >> k;
	int f[N];
	for(int i = 1; i <= k; i++)
	{
		int x;
		cin >> x;
		for(int j = 1; j <= x; j++)
		{
			int y;
			cin >> y;
			f[y]++;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
		ans += (f[i] == 0);
	cout << ans;





}
return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f;

struct e{
    int ai, bi;
}a[maxn];
bool cmp(e a, e b){return a.ai == b.ai ? a.bi > b.bi : a.ai > b.ai;}
priority_queue<int, vector<int>, greater<int> > pi;
stack<int> si;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)  cin >> a[i].ai >> a[i].bi;
    sort(a, a + n, cmp);

    int ans = 0, day = 0, p = 0;
    while (p < n){
        if (day + a[p].ai <= m){
            ++day;
            ans += a[p].bi;
            pi.push(a[p].bi);
        }else{
            while (!pi.empty() && a[p].bi > pi.top() && day + a[p].ai > m){
                si.push(pi.top());
                ans -= pi.top();
                --day;
                pi.pop();
            }
            if (day + a[p].ai <= m){
                ++day;
                ans += a[p].bi;
                pi.push(a[p].bi);
                while (!si.empty()) si.pop();
            }else{
                while (!si.empty()){
                    si.push(si.top());
                    ans += si.top();
                    ++day;
                    si.pop();
                }
            }
        }
        ++p;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

int dp[3010][3010];

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

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	dp[A][B] = 1;
	for(int i=A;i<=C;i++){
		for(int j=B;j<=D;j++){
			if(i==A && j==B) continue;
			if(i==A){
				dp[i][j] += dp[i][j-1] * A;
			}
			else if(j==B){
				dp[i][j] += dp[i-1][j] * B;
			}
			else{
				dp[i][j] += dp[i][j-1]*i+dp[i-1][j]*j-dp[i-1][j-1]*(i-1)*(j-1);
			}
			dp[i][j] += MOD*MOD;
			dp[i][j] %= MOD;
		}
	}
	cout << dp[C][D] << endl;
}

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


int main(){
   cout << fixed << setprecision(12);
   double r;
   cin>>r;

   double PAI = acos(-1);
   double area = r * r * PAI;
   double cir = (r * 2) * PAI;
   cout<<area<<" "<<cir<<endl;


 return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define pb push_back
#define inf 10e9
using namespace std;
int solve(vector<int> arr,int k)
{
    int n=arr.size();
    int dp[n]={};
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        int ans=inf;
        for(int j=1;j<=k;j++){
            
            if(i-j>=0){
                int op1=abs(arr[i]-arr[i-j])+dp[i-j];
                ans=min(ans,op1);
            }
        }
        dp[i]=ans;
    }
    return dp[n-1];
}
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int tmp;
        cin>>tmp;
        arr.pb(tmp);
    }
    cout<<solve(arr,k);
}


Measured memory_bytes: 4512
import math
n, m = map(int, input().split())

# 偶数足す偶数
# 奇数たす奇数
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=0
if (n==0 and m>=2):
    ans = ans + combinations_count(m, 2)

elif (n>=2 and m== 0):
    ans = ans + combinations_count(n, 2)
else:
    if (n!=1):
        ans = ans+ combinations_count(n, 2)
    
    if (m != 1):
        ans = ans + combinations_count(m, 2)



print(ans)

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

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

	vector<int> A(1005);
	for (int i = 2; i <= n; i++) {
		int a = i;
		for (int j = 2; a > 1; j++) {
			while (a % j == 0) {
				A[j]++;
				a /= j;
			}
		}
	}

	long long sum = 1;
	const long long mod7 = 1e9 + 7;
	for (int i = 0; i < A.size(); i++) {
		if (A[i] == 0) continue;
		sum = (sum * (A[i] + 1)) % mod7;
	}
	cout << sum;
}

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

int main() {
	ll A,B,C,K,val=0;
	
	cin  >> A >> B >> C >> K;

	for (ll i = 0; i < K; i++) {
		if (i < A)
			val++;
		if (i >= A + B)
			val--;
	}

		
	cout << val << endl;

}


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

using namespace std;


using ul = unsigned long;
ul gcd(ul x, ul y)
{
    if (x < y) {
        ul t = y;
        y = x;
        x = t;
    }


    ul r;
    while (y > 0) {
        r = x % y;
        x = y;
        y = r;
    }

    return x;
}


int main()
{
    ul N, X;
    vector<ul> x;

    cin >> N >> X;
    for (ul i = 0; i < N; i++) {
        ul tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    x.push_back(X);

    sort(x.begin(), x.end());
    vector<ul> ds;
    for (ul i = 0; i < x.size() - 1; i++) {
        ds.push_back(max(x[i], x[i+1]) - min(x[i], x[i+1]));
    }

    ul ans = gcd(ds[0], ds[1]);
    for (ul i = 2; i < ds.size(); i++)
        ans = gcd(ans, ds[i]);
    cout << ans << endl;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
typedef long long ll;
using namespace std;
 
int main(){
    int N; cin >> N;
    double cnt=0;
    double ans=N;
    for (int i=1; i<=N; i++){
        if(i%2!=0) cnt++;
    }
    cout << fixed << setprecision(10) << cnt/ans; 
}

Measured memory_bytes: 256
def main(N,K,R,S,P,T):
    T_takahashi = T.replace('r','x').replace('s','y').replace('p','z').replace('x','p').replace('y','r').replace('z','s')
    ans = 0
    i = 0
    for i in range(N):
        if i+K <= N-1:
            if T_takahashi[i] in 'spr' and T_takahashi[i] == T_takahashi[i+K]:
                T_takahashi = T_takahashi[:i+K] + T_takahashi[i+K].replace(T_takahashi[i], 'w') + T_takahashi[i+K+1:]
    for hand in T_takahashi:
        if hand == 'r':
            ans += R
        elif hand == 's':
            ans += S
        elif hand == 'p':
            ans += P
        else:
            ans += 0
    return ans

N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
print(main(N,K,R,S,P,T))

Measured memory_bytes: 3580
#include <iostream> 
using namespace std; 
int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    if (a == b) 
        return a; 
   
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main() 
{ 
   long long int a, b; 
    cin>>a>>b;
   long long int g=gcd(a,b);
   long long int GCD=a*b/g;
    cout<<GCD<<endl;
    return 0; 
} 

Measured memory_bytes: 256
def insertionSort( nums, n, g ):
	cnt = 0
	i = g
	while i < len( nums ):
		v = nums[i]
		j = i - g
		while 0 <= j and v < nums[j]:
			nums[ j+g ] = nums[j]
			j -= g
			cnt += 1
		nums[ j+g ] = v
		i += 1
	
	return cnt


def shellSort( nums, n ):
	cnt = 0
	g = []
	val =0
	for i in range( 0, n ):
		val = 3*val+1
		if  n < val:
			break
		g.append( val )

	g.reverse( )
	m = len( g )
	print( m )
	print( " ".join( map( str, g ) ) )
	for i in range( 0, m ):
		cnt += insertionSort( nums, n, g[i] )
	print( cnt )


n = int( raw_input( ) )
nums = []
for i in range( 0, n ):
	nums.append( int( raw_input( ) ) )

shellSort( nums, n )
for val in nums:
	print( val )

Measured memory_bytes: 67796
import sys
input = lambda: sys.stdin.readline().rstrip()

n= int(input())
a=list(input())

v=a.count('1')

ans=[0]*n
A=[0]*n
# n以下の残り回数を記録
for i in range(n):
    x=i
    cnt=0
    while x>0:
        cnt+=1
        r = 0
        for j in range(19):
            if (x>>j)&1:
                r+=1
            if x>>j==0:
                break
        x=x%r
    ans[i]=cnt

# 各桁をv＋１で割ったあまり
q = [0]*n
# 各桁をv-1で割ったあまり
r = [0]*n
for i in range(n):
    if a[i]=='1':
        if v!=0:
            q[i] = pow(2, n-i-1,v+1) 
        if v!=1:
            r[i] += pow(2, n-i-1,v-1) 
qq=sum(q)
rr=sum(r)

for i in range(n):
    if a[i]=='1':
        if v!=1:
            z = rr - pow(2,n-i-1,v-1)
            cnt = z % (v - 1)
            A[i] = 1 + ans[cnt]
    else:
        z=qq+pow(2,n-i-1,v+1)
        cnt=z%(v+1)
        A[i]=1+ans[cnt]

for i in A:
    print(i)


Measured memory_bytes: 89364
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//double pow(int x, int y) { int ret = 1; for(int i = 0 ; i < y ; i++) ret *= x; return ret; }

int main() {
  int N;
  cin >> N;
  int d = 0, tmp = N;
  while(tmp) {
    d++;
    tmp /= 10;
  }
  int ans = 0, p = 1;
  for(int i=1; i<d; i+=2)
    ans += 9*pow(10, i-1);
  if(d%2)
    ans += N-(pow(10, d-1)-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define VT(T) vector<T>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;
typedef unsigned long long int ull;

ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
 
ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}
 
ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}
 
ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
 
	int n;
	cin>>n;
	const int B=62;
	vint cnt(B,0);
	vlong arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];

	ll ans=0, mod=1e9+7, pn=0;
	for(int i=n-1; i>=0; i--){
		string str=bitset<B>(arr[i]).to_string();
		// cout<<str<<endl;
		// for(auto y : cnt) cout<<y<<" ";
		// cout<<endl;
		ll val=1, tmp=0;
		for(int j=B-1, l=0; j>=0; j--,l++){
			if(str[j]=='1'){
				tmp+=(pn-cnt[l])*val;
			} else {
				tmp+=cnt[l]*val;
			}
			val<<=1;
			val%=mod;
		}
		// cout<<tmp<<endl;
		ans=(ans+tmp)%mod;
		for(int j=B-1, l=0; j>=0; j--,l++){
			if(str[j]=='1'){
				cnt[l]++;
			}
		}
		pn++;
	}

	cout<<ans<<endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;

int main(){
    long int n; cin>>n;long int a[n];long int ans = 0;long int max = 0;
    for (int i = 0; i < n; i++){
        cin>>a[i]; ans += a[i];
    }
    if(ans%10 == 0){
        for (int i = 0; i < n; i++){
            ans -= a[i];
            if (ans%10 != 0){
                if (max < ans){
                    max = ans;
                    //ans += a[i];
                }          
            }
            else {
                //ans += a[i];
            }
            ans += a[i];
        }
        cout << max; return 0;
    }
    
    if (ans%10 == 0){cout<<'0';return 0;}
    cout<<ans;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((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 FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

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

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

  bool same(int x, int y){
	return find(x) == find(y);
  }
};

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

  int N, M; cin >> N >> M;
  VVI lang(N);
  UnionFind uf(M);
  REP(i,N){
	int K; cin >> K;
	REP(j,K){
	  int l; cin >> l;
	  --l;
	  lang[i].PB(l);
	}
	REP(j,K-1){
	  uf.unite(lang[i][j], lang[i][j+1]);
	}
  }

  VI sum(M);
  REP(i,N) sum[uf.find(lang[i][0])]++;

  bool ok = false;
  REP(i,M){
	if(sum[i] == N) ok = true;
  }
  cout << (ok?"YES":"NO") << endl;

  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int V[100100];
int C[100100];
int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    if (V[i] - C[i] > 0) {
      sum += V[i] - C[i];
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

#define _USE_MATH_DEFINES
#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>
#include <stack>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

struct pair_hash {
public:
    std::size_t operator()(const std::pair<u64, u64> &x) const
    {
        return std::hash<u64>()(x.first) ^ std::hash<u64>()(x.second);
    }
};
#include <random>

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;

i64 n, m;
i64 k[MAXN];
vector<i64> s[MAXN];
i64 p[MAXN];

bool check(vector<i64> q) {
    for (auto e : q) {
        cerr << e << " ";
    }
    cerr << endl;

    for (i64 i = 1; i <= m; i++) {
        i64 t = 0;

        for (auto e : s[i]) {
            t += q[e];
        }

        if (t % 2 != p[i]) {
            return false;
        }
    }

    return true;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    i64 a, p;
    cin >> a >> p;

    cout << (a * 3 + p) / 2 << endl;


    return 0;
}

Measured memory_bytes: 2560