akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;
  cin>>n;
  ll ans = 0;
  int d[n];
  vector<int> v[n];
  REP(i,n){
    d[i] = -1;
  }
  REP(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    v[a].pb(b);
    v[b].pb(a);
  }
  vector<int> c;
  REP(i,n){
    int t;cin>>t;
    c.pb(t);
    ans += t;
  }
  VSORT(c);
  ans -= c[c.size()-1];
  cout<<ans<<endl;
  queue<int> que;
  que.push(0);
  int counter = c.size()-1;
  while(!que.empty()){
    int now = que.front();
    que.pop();
    d[now] = c[counter];
    counter--;
    REP(i,v[now].size()){
      if(d[v[now][i]]<0){
        que.push(v[now][i]);
      }
    }
    if(counter<0)break;
  }

  REP(i,n){
    cout<<d[i]<<endl;
  }
 

  return 0;
}

Measured memory_bytes: 1024
import math
from functools import reduce

k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            temp = reduce(math.gcd,[i,j,l])
            if len(set([i,j,l])) == 1:
                ans += temp
            elif len(set([i,j,l])) == 2:
                ans += temp * 3
            elif len(set([i,j,l])) == 3:
                ans += temp * 6
print(ans)

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

int main() {
	string numbers;
	cin >> numbers;
	int a = numbers[0] - 48;
	int b = numbers[1] - 48;
	int c = numbers[2] - 48;
	int d = numbers[3] - 48;
	if (a - b - c - d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
	else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
	else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
	else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
	else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
	else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
	else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
	else if (a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
	return 0;
}

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

void dfs(vector<int> adj[],int node, int n,int visited[],int dp[]){
    visited[node] = 1;
    for(int i=0;i<adj[node].size();i++){
        if(!visited[adj[node][i]]){
            dfs(adj,adj[node][i],n,visited,dp);
            //  dp[node] = max(dp[node],1+dfs(adj,adj[node][i],n,visited,dp));
        }
        dp[node] = max(dp[node],dp[adj[node][i]]+1);
    }
}

int main() {
    
    int t;
    t=1;
   // cin >> t;
    while(t--){
        
        int n,m;
        cin >> n >> m;
        
        vector<int> adj[n+1];
        for(int i=0;i<m;i++){
            int u,v;
            cin >> u >> v;
            
            adj[u].push_back(v);
        }
        
        int ans = 0;
        int dp[n+1];
        int visited[n+1];
        memset(visited,0,sizeof(visited));
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++){
            if(!visited[i]){
                dfs(adj,i,n,visited,dp);
            }
        }
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i]);
        }
        cout << ans << endl;


    }
    return 0;

}

Measured memory_bytes: 9856
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		String S = sc.next();
		if(S.indexOf("YAKI") == 0) System.out.println("Yes");
		else System.out.println("No");
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename P, typename Q>
istream& operator >> (istream& is, pair<P, Q>& p)
{
  is >> p.first >> p.second;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v)
{
  each (i, v) is >> i;
  return is;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    bool f = a + b <= 16 && max(a, b) <= 8;
    cout << (f ? "Yay!" : ":(") << endl;
  }

  return 0;
}


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

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            
            
            for(var i = 1; i <= N; i++)
            {
                if(i != p[i - 1])
                {
                    for (var j = i + 1; j <= N; j++)
                    {
                        if (j != p[j - 1])
                        {
                            var tmp = p[j - 1];
                            p[j - 1] = p[i - 1];
                            p[i - 1] = tmp;
                            break;
                        }
                    }
                    break;
                }
            }
            var ok = true;
            for (var i = 1; i <= N; i++)
            {
                if (i != p[i - 1]) ok = false;
            }
            if (ok) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}


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

using namespace std;

int counter(int x){

if (x==0) return 0;
return counter(x>>1) + (x&1);
}
void solve(){
int N;
cin >> N;
int num=0;
int A[N],x[N][N],y[N][N];

for (int i = 0; i < N; i++)
{
	cin >> A[i];
	for (int j = 0; j < A[i]; j++)
	{
		cin >> x[i][j] >> y[i][j];
	}
}
for (int bits = 0; bits < (1 << N); bits++)
{
	int flag = 1;
	for (int i = 0; i < N; i++)
	{
		if (!((bits >> i)&1)) continue;
		else{
			for (int j = 0; j < A[i]; j++)
			{
				if(((y[i][j] ^ (bits >> (x[i][j]-1) & 1))))
				{
					
					flag = 0;
				}
			}
		}
		 
	}

	if (flag ==1)
	{
		num = max(counter(bits),num);
	}
}

cout <<  num;

}


int main(){

solve();

}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    K = I()
    a = K // 2
    b = K - a
    print(a*b)

main()



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

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

    if( a == b && b == c || a != b && b != c && c != a){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    lint ans=0;
    string S[301];
    lint N;
    cin >> N;
    for(int i=0;i<N;i++) cin >> S[i];

    for(lint A=0;A<N;A++){
        bool flg=true;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(S[(i+N-A)%N][j]!=S[(j+N-A)%N][i]){
                    flg=false;
                    break;
                }
            }
            if(!flg) break;
        }
        if(flg) ans++;
    }

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  int ans=0;
  rep(i,1,N){
    if(S[i]!=S[i-1]) ans=max(ans,min(i,N-i));
  }
  cout<<N-ans<<endl;
  }


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int matrix[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	cin >>matrix[i][j];
      }
    }
    int suma = 0;
    for(int i=0,sumc,sumr; i<n; i++){
      sumc = 0;
      sumr = 0;
      for(int j=0; j<n; j++){
	sumc+=matrix[i][j];
	sumr+=matrix[j][i];
      }
      suma+=sumc;
      matrix[i][n] = sumc;
      matrix[n][i] = sumr;
    }
    matrix[n][n] = suma;
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
	printf("%5d",matrix[i][j]);
      }
      cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){

int office[4][3][10]={};
int n,b,f,r,v;

scanf("%d",&n);

while(n--){

scanf("%d%d%d%d",&b,&f,&r,&v);
office[b-1][f-1][r-1] += v;

}

for(b=0;b<4;b++){
 for(f=0;f<3;f++){
  for(r=0;r<10;r++){
   printf(" %d",office[b][f][r]);
  }
  printf("\n");
 }
 if(b!=3){
  printf("####################\n");
 }
}


return 0;
}

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

int main(){
  int A, B, Q;
  ll x;
  cin >> A >> B >> Q;
  ll s[A], t[B], ans[Q];
  rep(i, A) cin >> s[i];
  rep(i, B) cin >> t[i];
  rep(i, Q){
    cin >> x;
    int su = lower_bound(s, s+A, x) - s;
    int tu = lower_bound(t, t+B, x) - t;
    ll d[4];
    rep(i, 4) d[i] = INF;
    if(su < A && tu < B) d[0] = max(s[su]-x, t[tu]-x);
    if(su < A && tu > 0) d[1] = min(s[su]-x+2*(x-t[tu-1]), 2*(s[su]-x)+x-t[tu-1]);
    if(su > 0 && tu < B) d[2] = min(x-s[su-1]+2*(t[tu]-x), 2*(x-s[su-1])+t[tu]-x);
    if(su > 0 && tu > 0) d[3] = max(x-s[su-1], x-t[tu-1]);
    sort(d, d+4);
    ans[i] =  d[0];
  }
  rep(i, Q) cout << ans[i] << endl;
  return 0;
}


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

int main(){
	string str;
	
	getline(cin, str);
	
	for(int i = 0; i < str.size(); i++){
		if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 32;
		}
		else if(str[i] >= 'A' && str[i] <= 'Z'){
			str[i] += 32;
		}
	}
	
	cout << str << endl;
	
	return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

    int A, B;
    cin >> A >> B;
    A = (A - 2 + 13) % 13;
    B = (B - 2 + 13) % 13;
    // db2(A, B);
    if (A == B)
        cout << "Draw\n";
    else if (A > B)
        cout << "Alice\n";
    else
        cout << "Bob\n";

    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        abc: [Chars;3],
    }

    print!("A{}C", abc[1][0]);

}


Measured memory_bytes: 2160
x=[]
n=int(input())
i=0
c=[]
while i!=n:
    i=i+1
    a=input().split()
    a[1]=int(a[1])
    a.append(i)

    x.append(a)
x=sorted(x, key=lambda x: -x[1])

x.sort()


while True:
    try:
        c=[]
        a=x[0]
        b=a[0]
        i=0
        c.append(x[0])
        del x[0]
        while True:
           try:

               a=x[0]
               bb=a[0]
               if b==bb:
                   c.append(x[0])
                   del x[0]
               else:
                   break
           except:
               break
        c = sorted(c, key=lambda x: -x[1])

        i=0
        while True:
            try:
                k=c[i]
                ans=k[2]
                i=i+1
                print(ans)
            except:
                break
    except:
        break

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

// 解説みた結果
// あーこれでもTLE。もうちょっと確認する
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());
    vector<bool> dp(A[N-1]+1);

    for (int i = 0; i < A[N-1] + 1; i++) dp[i] = true;

    for (int i = 0; i < N; i++) {
        if (i > 0 && A[i] == A[i - 1]) {
            dp[A[i]] = false;
            continue;
        }
        for (int j = A[i]; j <= A[N-1]; j += A[i]) {
            if (j > A[i]) {
                dp[j] = false;
            }
        }
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (dp[A[i]]) count++;

        // debug
        // cout << A[i] << " : ";
        // if (dp[A[i]]) cout << A[i];
        // cout << endl;
    }
    cout << count;
}

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

int main(){
  string S;
  cin >> S;
  if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

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

using namespace std;

int n,ans,cnt;
int ehead[maxl];
int du[maxl];
struct ed
{
	int to,nxt;
}e[maxl<<1];
bool vis[maxl];

inline void add(int u,int v)
{
	e[++cnt].to=v;e[cnt].nxt=ehead[u];ehead[u]=cnt;
}

inline void prework()
{
	for(int i=1;i<=n;i++)
		vis[i]=false,ehead[i]=0,du[i]=0;
	int u,v;
	cnt=0;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		u++;v++;
		add(u,v);du[v]++;
		add(v,u);du[u]++;
	}
}

inline int dfs(int u,int fa)
{
	int v;
	for(int i=ehead[u];i;i=e[i].nxt)
	{
		v=e[i].to;
		if(v==fa) continue;
		if(du[v]>2)
			return v;
		else
			return dfs(v,u);
	}
}

inline void mainwork()
{
	bool flag=true;
	for(int i=1;i<=n;i++)
	if(du[i]>2)
		flag=false;
	if(flag)
	{
		ans=1;
		return;
	}
	ans=0;
	for(int i=1;i<=n;i++)
	if(du[i]==1)
		vis[dfs(i,0)]=true,ans++;
	for(int i=1;i<=n;i++)
	if(vis[i])
		ans--;
}

inline void print()
{
	printf("%d\n",ans);
}

int main()
{
	while(~scanf("%d",&n))
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
#define NUMBER 10000

int main(void){
  int  i,num;
  int a[NUMBER];
  scanf("%d\n",&num);

  for(i=0;i<num;i++){
      scanf("%d ",&a[i]);
  }   long min,max,sum;

  min=max=sum=a[0];
  for(i=1;i<num;i++){
      if(a[i]>max){
      max=a[i];}

      if(a[i]<min){
      min=a[i];}

      sum+=a[i];

  }
  printf("%ld %ld %ld\n",min,max,sum);
 return 0;

}


  

 



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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int answer=max(a*b,c*d);

    cout<<answer<<endl;

}


Measured memory_bytes: 256
MAX = 10 ** 5 

n = int(input())
a = list(map(int, input().split()))
cnt = [0 for i in range(MAX)]
for i in a:
    cnt[i - 1] += 1
ans = 0
cnt2 = 0
for i in cnt:
    if i == 0:
        continue
    if i % 2 == 0:
        cnt2 += 1
    ans += 1
if cnt2 % 2 == 1:
    ans -= 1
print(ans)

Measured memory_bytes: 89696
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  rep(i, Size(s)) {
    if (s[i] == 'S')
      cnt++;
    else {
      if (cnt <= 0) continue;
      ans += 2;
      cnt--;
    }
  }
  ans = Size(s) - ans;
  Cout(ans);
  return 0;
}

Measured memory_bytes: 720
local n=io.read("*n")
local a={}
local total=0
for i=1,n do
    a[i]=io.read("*n")
    total=total+a[i]
end

local total_i=0
local diff=10^19
for i=1,n-1 do
    total_i=total_i+a[i]
    diff=math.min(diff,math.abs(total-2*total_i))
end
print(diff)

Measured memory_bytes: 4472
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, A, K = 0;
	map<int, int> mp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (mp[A] == 0) K++;
		mp[A]++;
	}
	if (K % 2 == 1) cout << K;
	else cout << K - 1;
}

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

using namespace std;

int main()
{
 	int n;
 	cin>>n;
 	string s;
 	cin>>s;
 	int x=0,y=0;
 	for(int i=0; i<n; i++)
 	{
 		if(s.at(i)=='I')x++;
 		if(s.at(i)=='D')x--;
 		if(y<x)y=x;
	 }
	 cout<<y;
	 return 0;
}


Measured memory_bytes: 256
N ,A ,B ,C ,D = list(map(int,input().split()))
S = input()
 
def judgeArrive(S, x, y):
    flag = "Yes"
    for i in range(x-1 ,y-2):
        if S[i] ==  S[i+1] == "#":
            flag = "No"
    return flag

def judgeJumpOver(S, x , y):
    flag = "No"
    for i in range(x-1 ,y):
        if S[i-1] ==  S[i] ==  S[i+1] == ".":
            flag = "Yes"
            break
    return flag
 
result = "Yes"
if(C > D):
    result = judgeJumpOver(S, B, D)
if(result == "Yes"):
    result = judgeArrive(S, B, D)
if(result == "Yes"):
    result = judgeArrive(S, A, C)
print(result)

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

int main(){
    //input
    long long D, G;
    cin >> D >> G;
    long long p[D], c[D];
    long long i;
    for(i=0; i<D; i++){
        cin >> p[i] >> c[i];
    }

    //calc
    long long count, count_min;
    long long score;
    long long bit;
    long long gred;
    count_min=0;
    for(i=0; i<D; i++){
        count_min += p[i];
    }
    for(bit=0; bit<(1<<D)-1; bit++){
        count=0;
        score=0;
        for(i=0; i<D; i++){
            if(bit&(1<<i)){
                count += p[i];
                score += 100*(i+1)*p[i] + c[i];
            }
        }
        for(gred=D-1; gred>=0; gred--){
            if(bit&(1<<gred)){
                continue;
            }
            break;
        }
        for(i=0; i<p[gred]-1; i++){
            if(score>=G){
                break;
            }
            count++;
            score += 100*(gred+1);
        }
        if(score>=G){
            count_min=min(count,count_min);
        }
    }

    //answer
    cout << count_min << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll INF = 1LL << 60;

ll luca[100];

ll luca_num(int n){
    if (n == 1) return 1LL;
    else if (n == 0) return 2LL;
    else if (luca[n] > 0) return luca[n];
    else return luca[n] = luca_num(n-1)+luca_num(n-2);
}

int main(){
    int n;
    cin >> n;
    cout << luca_num(n) << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))

lst = [0] * (N + 1)
for a in A:
    lst[a - 1] += 1
lst.sort() #頻度列

s = [0] * (N + 1)
for i in range(N):
    s[i + 1] = s[i] + lst[i + 1]

# print (lst)
# print (s)

def check(x, k):
    i = bisect_left(lst, x) - 1
    total = x * (N - i) + s[i]
    return total >= x * k

ans = N
for k in range(1, N + 1):
    while True:
        if check(ans, k):
            break
        ans -= 1
    print (ans)
        

Measured memory_bytes: 37884
#include <stdio.h>
#include <string.h>
char s[100001]={0};
int k;

int main(void) {
  scanf("%s %d",s,&k);
  int length=strlen(s),cost;
  for(int i=0;i<length;i++){
    cost=(26-s[i]+'a')%26;
    if(cost<=k){
      k-=cost;
      s[i]='a';
    }
  }
  if(k){
    cost=(s[length-1]-'a'+k)%26;
    s[length-1]='a'+cost;
  }
  printf("%s\n",s);
  return 0;
}

Measured memory_bytes: 384
from math import ceil, floor


def exist(A, B, x):
    """
    check if i and j exist such that Ai + Bj = x
    """
    max_i = x // A
    for i in range(max_i + 1):
        if (x - A * i) % B == 0:
            return True
    else:
        return False


A, B, C, D, E, F = [int(elem) for elem in input().split(' ')]

max_density = 0.
status_when_max_dens = {'water': 0, 'sugar': 0}
for x in range(1, F + 1):
    if exist(100 * A, 100 * B, x):
        for y in range(F - x + 1):
            if exist(C, D, y):
                density = y / (x + y)
                if (density >= max_density)\
                and (y <= x / 100 * E)\
                and (x + y <= F):
                    max_density = density
                    status_when_max_dens['water'] = x
                    status_when_max_dens['sugar'] = y


water = status_when_max_dens['water']
sugar = status_when_max_dens['sugar']
print(water + sugar, sugar)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	string s;

	cin >> s;

	if (s[0] == '9' || s[1] == '9') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    println(input()[6:7]>"04" ? "TBD" : "Heisei")
end
main()

Measured memory_bytes: 109608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i;


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

    
    
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int max = -1000;

    int[] data = {a+b,a-b,a*b};

    for (int i = 0; i < 3; i++) {
      max = Math.max(max,data[i]);
    }

    System.out.println(max);

  }
}


Measured memory_bytes: 21716
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 31000000
// #define M 19
 
// #define mod  11092019
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000000000

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll mul(ll a, ll b, ll mod) { return (long long) a*b%mod;}
inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b: a+b-mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
	return ret;
}

static inline void read(ll &x) { cin>>x;}

int main(){
	string s; cin>>s;
	ll n = sz(s);
	ll ans = 0, bit = 0;
	FER(i, 0, n){
		if(s[i] == '1') {
			ans = add(ans, mul(bp(2, bit, mod1), bp(3, n-1-i, mod1), mod1), mod1);
			bit++;
		}
	}
	ans = add(ans, bp(2, bit, mod1), mod1);
	cout<<ans<<"\n";
	return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

vector<int> num;

int main() {
	int n;
	scanf("%d", &n);
	rep(i, n) {
		int a;
		scanf("%d", &a);
		num.push_back(a);
	}
	repr(i, n - 1) {
		(i != 0) ? printf("%d ",num[i]) : printf("%d\n", num[i]);
	}
	return 0;
}

Measured memory_bytes: 3136
N,d,a = map(int,input().split())

# N: 処理する区間の長さ

data0 = [0]*(N+1)
data1 = [0]*(N+1)
# 区間[l, r)に x を加算
def _add(data, k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def add(l, r, x):
    _add(data0, l, -x*(l-1))
    _add(data0, r, x*(r-1))
    _add(data1, l, x)
    _add(data1, r, -x)

# 区間[l, r)の和を求める
def _get(data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def query(l, r):
    return _get(data1, r-1) * (r-1) + _get(data0, r-1) - _get(data1, l-1) * (l-1) - _get(data0, l-1)

xhl = []
for _ in range(N):
    x,h = map(int,input().split())
    xhl.append((x,h))

xhl = sorted(xhl)
xl = [x for x,h in xhl]

for idx in range(N):
    add(idx+1, idx+2, xhl[idx][1])

def ceil(a, b):
   return a // b + (a % b > 0)

import bisect

ans = 0
for i in range(N):
    hp = query(i + 1, i + 2)
    if hp > 0:
        count = ceil(hp, a)
        ans += count
        damage = count * a
        idx = bisect.bisect_right(xl, xl[i] + 2*d)
        add(i+1, idx+1, -damage)
print(ans)







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

#define fti(i, x, y) for(int i = (x), _y = (y); i <= _y; ++ i)
#define ftd(i, x, y) for(int i = (x), _y = (y); i >= _y; -- i)
#define ll unsigned long long

using namespace std;

const int N = 52;
int n;
ll S, d[N], res;

void inp()
{
    scanf("%d", &n);
    fti(i, 1, n) scanf("%llu", &d[i]), S += d[i];
}

void proc()
{
    fti(i, 1, n) S -= d[i], res += d[i] * S;
    printf("%llu\n", res);
}

int main()
{
    inp();
    proc();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> h(n);
    REP(i, 0, n) {
        cin >> h[i];
    }
    bool ok = true;
    for (int i = n - 2; i >= 0; i--) {
        if (h[i] > h[i + 1]) {
            h[i]--;
        }
        if (h[i] > h[i + 1]) {
            ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin>>n;
  ll a[n+1],b[n+1],c[n+1];
  for(ll i=1;i<=n;i++)
  {
  cin>>a[i]>>b[i]>>c[i];
  }
  ll dp[n+1][3];
  dp[1][0]=a[1];
  dp[1][1]=b[1];
  dp[1][2]=c[1];
  for(ll i=2;i<=n;i++)
  {
  dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
  dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
  dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
  }
  ll ans=0;
  for(int i=0;i<3;i++)
  {
  ans=max(dp[n][i],ans);
  }
  cout<<ans;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  REP(i, N) cin >> l[i];
  int ans = 0;
  sort(l.rbegin(), l.rend());
  for(int i = 0; i < K; i++) {
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
A = list(map(lambda x: x-K, A)) + A
minimum = -1
i = 0
for i in range(len(A)-N+1):
    cost = abs(A[i] - A[i+N-1])
    if minimum == -1 or cost < minimum:
        minimum = cost
print(minimum)


Measured memory_bytes: 26436
N = int(input())

ans = 0

def calc(i):
    lst = []
    while i!=0:
        lst.append(i%10)
        i = i//10
    lst.reverse()
    return lst
  
for a in range(1, N+1):
    lsta = calc(a)
    m = len(lsta)

    if lsta[0] > lsta[m-1]:
        if lsta[m-1]==0:continue
        ans += sum([2*10**(l) for l in range(m-1)])
    elif lsta[0] == lsta[-1]:
        if m <= 2:ans += 2*m-1
        else:
            ans += (a%(10**(m-1))//10)*2 +1
            for l in range(m-2):
                ans += 10**(l)*2
            ans += 2
      
    else:
        if m == 2:continue
        else:
            for l in range(m-2):
                ans += 2*10**(l)
print(ans)
    
                

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstring>
#define INF 0x3f3f3f3f
#define lb long double
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define random(x) (rand()%x)
#define rep(i, a, b) for(int i=a;i<b;i++)
#define req(j, a, b) for(int j=a;j<b;j++)
#define mem(a, b) memset(a, b, sizeof(a))
#define PI 3.14

using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const double eps = 1e-14;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;

int gw; //个位
int d[9];
int cf(int x)
{
    while(x!=0)
    {
        gw=x%10;
        x=(x-gw)/10;
        d[gw]++;//计数器加1
    }
}

int res[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{

    int m1, d1;
    int m2, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(d2 == 1 && m2 - m1 == 1)
    {
        cout << 1 << endl;
    }
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    
    public static void main(String[] args){
    		Scanner sc = new Scanner(System.in);
        	int a =sc.nextInt();
        	int b =sc.nextInt();
        	int c =sc.nextInt();
        	if(a < b && b < c){
            	System.out.println("Yes");
            }else{
				System.out.println("No");
			}
        sc.close();
    }
}



Measured memory_bytes: 26248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[505][505];
int n,k,h[305],b[305],he[305][305];
int main()
{
	scanf("%d%d",&n,&k);
	memset(dp,0x7f,sizeof(dp));
	ll ans=dp[0][0];
	int i,j;
	for(i=1;i<=n;i++) {
		scanf("%d",&h[i]);
		for(j=0;j<=k;j++) he[i][j]=h[i];
		//b[i]=h[i];
	}
	//sort(b+1,b+n+1);
	for(i=0;i<=k;i++)
	dp[0][i]=0;
//	for(i=1;i<=k;i++) dp[i][i]=0;
/*	for(i=1;i<=n;i++)
	  for(j=0;j<=k;j++){
	    if(h[i]>he[i-1][j])  dp[i][j]=min(dp[i][j],dp[i-1][j]+h[i]-he[i-1][j]);
	    else dp[i][j]=min(dp[i][j],dp[i-1][j]);
	    if(dp[i][j]>dp[i-1][j-1]&&j>=1){
	  	dp[i][j]=dp[i-1][j-1];
	  	he[i][j]=he[i-1][j-1];
		}
	  }
	for(i=1;i<=n;i++){
		 for(j=0;j<=k;j++) printf("%d ",dp[i][j]);
		 printf("\n");
	}
	 
	cout<<dp[n][k];*/
	for(i=1;i<=n+1;i++)
	  for(j=0;j<=min(k,i-1);j++)
	    for(int ii=0;ii<=j;ii++) 
		if(h[i]>h[i-ii-1])dp[i][j]=min(dp[i][j],dp[i-ii-1][j-ii]+h[i]-h[i-ii-1]);
		else dp[i][j]=min(dp[i][j],dp[i-ii-1][j-ii]);
	for(i=0;i<=k;i++) ans=min(ans,dp[n+1][i]);
	cout<<ans; 
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if((a*100+b*10+c)%4==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;
int n, d;
int ar[20][20];

bool ok(int i, int j){
	double res = 0.0;
	for(int k=1; k<=d; k++){
		res += (ar[i][k]-ar[j][k]) * (ar[i][k]-ar[j][k]);
	}
	res = sqrt(res);
	return res - (int)res == 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n >> d;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=d; j++)
			cin >> ar[i][j];
	}

	int res = 0;
	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(ok(i, j)) res++;
		}
	}

	cout << res;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] a_b = str.split(" ", 0);

		int a = Integer.parseInt(a_b[0]);
		int b = Integer.parseInt(a_b[1]);
		double af = a;
		double bf = b;

		int d = a / b;
		int r = a % b;
		double f = af / bf;

		System.out.print(d + " " + r + " ");
		System.out.printf("%.6f", f);
	}
}

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

typedef long long ll;
constexpr ll MOD = 998244353;

ll power(ll x, ll n){
    x %= MOD;
    ll res = 1;
    while(n > 0){
        if(n&1){
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    ll ans = 0, n;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        ans += a*power(a+1,i)%MOD*power(2,n-i-1)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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





int main() {
  int n;
  cin>>n;
  vector<int> data(n);
   
  for (int i=0;i<n;i++){
    cin>>data.at(i);
  }
  
  int answer=0;
    
    while (data.at(0)%2==0){
      answer+=1;
      data.at(0)/=2;
    }
  
    
    
    
    for (int i=1;i<n;i++){
      int count=0;
      while (data.at(i)%2==0){
        count+=1;
        data.at(i)/=2;
      }
      answer=min(answer,count);
    }
  
  cout<<answer<<endl;
  
      
    
      
  
}

  













Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8


def main():
    n, x = [int(i) for i in raw_input().split()]
    a_list = [int(i) for i in raw_input().split()]
    rel_sums = [a_list[i] if i == 0 else a_list[i-1]+a_list[i] for i in xrange(n)]
    count = 0
    for i in xrange(n-1):
        if rel_sums[i] > x:
            count += rel_sums[i] - x
            rel_sums[i+1] -= rel_sums[i] - x
    if rel_sums[n-1] > x:
        count += rel_sums[n-1] - x
        rel_sums[n-1] -= rel_sums[n-1] - x
    print count

if __name__ == '__main__':
    main()


Measured memory_bytes: 11828
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

template<class T>
void accum(vector<vector<T> > &v) {
	for (signed i(1); i < v.size(); ++i) {
		for (signed j(1); j < v[0].size(); ++j) {
			v[i][j] = v[i][j] + v[i][j - 1];
		}
	}
	for (signed i(1); i < v.size(); ++i) {
		for (signed j(1); j < v[0].size(); ++j) {
			v[j][i] = v[j][i] + v[j - 1][i];
		}
	}
}


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M, Q;
	cin >> N >> M >> Q;
	vvi lr(N + 1, vi(N + 1, 0)); 
	rep(i, 0, M) {
		int l, r;
		cin >> l >> r;
		++lr[l][r];
	}
	accum(lr);
	vi a(Q);
	rep(i, 0, Q) {
		int p, q;
		cin >> p >> q;
		a[i] = lr[q][q] - lr[p-1][q] - lr[q][p-1] + lr[p-1][p-1];
	}
	rep(i, 0, Q) {
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 2304
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll dp1[51], dp2[51];

ll solve(int n, ll x){
	if(x == 1) return (n == 0 ? 1 : 0);
	if(1 < x && x <= 1+dp1[n-1]) return solve(n-1, x-1);
	if(x == 2 + dp1[n-1]) return dp2[n-1] + 1;
	if(2 + dp1[n-1] < x && x <= 2 + 2*dp1[n-1]) return dp2[n-1]+1+solve(n-1, x-2-dp1[n-1]);
	if(x == 3+2*dp1[n-1]) return 2*dp2[n-1] + 1;
	return 0;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll x;
	cin >> n >> x;
	dp1[0] = dp2[0] = 1;
	rep(i,50){
		dp1[i+1] = 3 + 2 * dp1[i];
		dp2[i+1] = 1 + 2 * dp2[i];
	}
	cout << solve(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int h,i,n,arr[100000];
    scanf("%d %d",&h,&n);
    for(i=0;i<n;i++) {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n;i++) {
        h -= arr[i];
    }
    if(h>0)
       printf("No\n");
    else
        printf("Yes\n");

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

int main()
{
	vector<vector<ll>> v;
	vector<ll> u;
	ll n, k; cin >> n >> k;
	ll r, s, p; cin >> r >> s >> p;
	string t; cin >> t;
	string T = t;

	ll ans = 0;
	rep(i, 0, t.size()) {
		if (i < k) {
			if (t[i] == 'r') {
				ans += p;
				T[i] = 'p';
			}
			else if (t[i] == 's') {
				ans += r;
				T[i] = 'r';
			}
			else if (t[i] == 'p') {
				ans += s;
				T[i] = 's';
			}
		}
		else {
			if (t[i] == 'r') {
				if (T[i - k] != 'p') {
					ans += p;
					T[i] = 'p';
				}
				else {
					T[i] = '0';
				}
			}
			else if (t[i] == 's') {
				if (T[i - k] != 'r') {
					ans += r;
					T[i] = 'r';
				}
				else {
					T[i] = '0';
				}
			}
			else if (t[i] == 'p') {
				if (T[i - k] != 's') {
					ans += s;
					T[i] = 's';
				}
				else {
					T[i] = '0';
				}
			}
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 512
#include <cmath>
#include <complex>
#include <vector>
#include <cfloat>
#include <algorithm>
#include<iostream>
using namespace std;


//二次元幾何テンプレート
//点クラス point->x,y
//直線クラス line->s,v
//
class point;
class line;
point vec_add(point vec1,point vec2);//ベクトルの足し算
point vec_sub(point vec1,point vec2);//ベクトルの引き算
double inner_product(point a,point b);//内積
double outer_product(point a,point b);//外積
bool vec_parallel(point vec1,point vec2);//ベクトルの並行判定(交差判定falseとしても使える)
bool vec_angle_right(point vec1,point vec2);//ベクトルの直行判定
bool cross_line_segment(line a,point p1,point p2);//直線と線分の交差判定
//


class point{
public:
	double x,y;
	point(){
		x=0;
		y=0;
	}
	point(double a,double b){
		x=a;
		y=b;
	}
};

//直線クラス
class line{
public:
	point s,v;
public:
	line(point a,point b){
		s=a;
		v=vec_sub(a,b);
	}
};

//多角形(頂点を保持する)
typedef vector<point> polygon;

//ベクトルの足し算
point vec_add(point vec1,point vec2){
	point res(vec1.x+vec2.x,vec1.y+vec2.y);
	return res;
}
//ベクトルの引き算
point vec_sub(point vec1,point vec2){
	point res(vec1.x-vec2.x,vec1.y-vec2.y);
	return res;
}
//内積
double inner_product(point a,point b){
	return a.x * b.x + a.y * b.y;
}
//外積
double outer_product(point a,point b){
	return a.x * b.y - a.y * b.x;
}


//ベクトルの並行判定
bool vec_parallel(point vec1,point vec2){
	if(outer_product(vec1,vec2)==0){
		return true;
	}else{
		return false;
	}
}
//ベクトルの直交判定
bool vec_angle_right(point vec1,point vec2){
	if(inner_product(vec1,vec2)==0){
		return true;
	}else{
		return false;
	}
}

bool cross_line_segment(line l,point p1,point p2){
	p1=vec_sub(p1,l.s);
	p2=vec_sub(p2,l.s);
	if(outer_product(p1,l.v)*outer_product(p2,l.v)<0){
		return true;
	}else{
		return false;
	}
}



//
int main(){
	int n;
	point p[4];
	cin>>n;
	for(;n--;){
		for(int i=0;i<4;i++){
			cin>>p[i].x;
			cin>>p[i].y;
		}
		p[0]=vec_sub(p[0],p[1]);
		p[2]=vec_sub(p[2],p[3]);
		if(vec_parallel(p[0],p[2])){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int f[100005]={0};
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        f[a[i]]++;
        sum+=a[i];
    }
    int q;
    cin>>q;
    while(q--){
        int x,y;
        cin>>x>>y;
        sum=sum-f[x]*x+f[x]*y;
        cout<<sum<<endl;
        f[y]+=f[x];
        f[x]=0;
    }
    return 0;
}
    

Measured memory_bytes: 5212