akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

lint A, B, C, D;

int main()
{
    cin >> A >> B >> C >> D;
    if (A == C || B == D) cout << 0 << endl;
    else
    {
        lint tmp = abs(C - A) + abs(D - B);
        lint gcd = __gcd(abs(C - A), abs(D - B));
        cout << tmp - gcd << endl;
    }
}


Measured memory_bytes: 256
from collections import defaultdict

S = int(input())

if S <= 2:
    print(0)
    exit()
if S <= 5:
    print(1)
    exit()
if S <= 6:
    print(2)
    exit()

q = int(1e9+7)

result = [0]*S
result[3] = 1
result[4] = 1
result[5] = 1

for i in range(3, S - 1):
    for j in range(i + 3, S - 1):
        result[j] = (result[j] + result[i]) % q

ans = 0
for r in result:
    ans = (ans + r) % q

print(ans)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef vector<bool> vbool;
typedef vector<int> vint;


#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}


vlint base_3(int k){
    vlint ret; while (k > 0){ ret.pb(k % 3); k /= 3;} reverse(all(ret)); return ret;
}
map<lint, lint> trial_division(lint n){
    map<lint, lint> factor;
    lint tmp = (lint)(sqrt(n)) + 1;
    for (lint i = 2; i < tmp; ++i){
        while (n % i == 0){
            n /= i;
            factor[i] ++;
        }
    }
    if(n != 1) factor[n] ++;
    return factor;
}

lint dist(lint x1, lint y1, lint x2, lint y2){
    return (x1-x2) * (x1-x2) + (y1-y2) * (y1 - y2);
}

int main(){
    INT(d, t, s);

    print(Yes[s*t >= d]);

}

Measured memory_bytes: 3724
#import sys
#input = sys.stdin.readline
import random
import bisect
#from statistics import mean, median, variance, stdev

#template input

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)
def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val
def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

"""ここからメインコード"""


def main():
    n = IT()
    xu = []
    for i in range(n):
        xu.append(input().split())

    ans = 0
    for i in range(n):

        if xu[i][1] == "JPY":
            ans += float(xu[i][0])
        else:
            ans += float(xu[i][0]) * 380000


    print(ans)
    #print(n)
    #print(x)
    #print(u)

main()


Measured memory_bytes: 39280
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		int[] inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int X = inputintArray[0];
		int Y = inputintArray[1];
		int Z = inputintArray[2];

		Console.WriteLine(Z + " " + X + " " + Y);
	}
}



//int[] inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = inputintArray[0];
//int W = inputintArray[1];
//int N = int.Parse(Console.ReadLine());
//int[] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

//Console.WriteLine(ans);

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}

int gcd(int a, int b){
    if(a<b) swap(a, b);
    int t;
    while(b!=0){
        t = a;
        a = b;
        b = t%b;
    }
    return a;
}

int gcd3(int a, int b, int c){
    if(b<c) swap(b, c);
    if(a<b) swap(a, b);
    
    return gcd(gcd(a,b),c);
}
 
int main()
{
    int k;
    cin >> k;

    int ans=0;
    rep(i, k){
        rep(j, k){
            rep(l, k){
                ans += gcd3(i+1, j+1, l+1);
            }
        }
    }

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

Measured memory_bytes: 3756
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

class UnionFind:
    
    def __init__(self, n):
        self.parents = [-1]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)  

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x,y = y,x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

N,K,L = map(int, input().split())

road_union = UnionFind(N)
rails_union = UnionFind(N)

for i in range(K):
    p,q = map(int, input().split())
    p -= 1
    q -= 1

    road_union.union(p,q)
for i in range(L):
    r,s = map(int, input().split())

    r -= 1
    s -= 1
    rails_union.union(r,s)

d = defaultdict(int)

for i in range(N):
    d[(road_union.find(i), rails_union.find(i))] += 1


print(*[d[(road_union.find(i),rails_union.find(i))] for i in range(N)])

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

int main(){

long long N, max, mmax = 0,cnt = 1;
  cin >> N;
bool hantei = false;  
int A[N];
  for(int i = 0;i < N;i++) cin >> A[i];
  
  sort(A, A + N);

  max = A[N - 1];
  
  for(int i = N - 2;i >= 0;i--){
  if(A[i] == max) cnt++;
  if((cnt > 1) && (mmax == 0)){
    mmax = A[i];
    max = A[i];
    cnt = 0;
  }
  else if((cnt > 1) && (mmax != 0)){
    cout << mmax * max << endl;
    hantei = true;
    break;
  }
  else if(((cnt == 1) || (cnt == 0)) && (A[i] != max)){
    max = A[i];
    cnt = 1;
  } 
  }
  
  if(hantei == false) cout << 0 << endl;
  return 0;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(u==s) a--;
    if(u==t) b--;
    cout << a << ' ' << b  << "\n";
    return 0;
}



Measured memory_bytes: 256
program sample
    implicit none
    
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    integer(8), allocatable  ::x(:) 

    read(*,*) n,k
    if (n>k)then
        n=mod(n,k)
    end if
    
    a=k-n
    if (a<n)then
        write(*,*)a
    else
        write(*,*)n
    end if
    
    stop
end program sample
  



Measured memory_bytes: 2756
n=int(input())
a=list(map(int,input().split()))
tmp=0
csum_a=[]
for ai in a:
  tmp+=ai
  csum_a.append(tmp)
ans=0
tmp=0
plus=True
for si in csum_a:
  if plus and si+tmp>0:
    pass
  elif plus and si+tmp<=0:
    ans+=1-(si+tmp)
    tmp+=1-(si+tmp)
  elif not plus and si+tmp<0:
    pass
  elif not plus and si+tmp>=0:
    ans+=1+(si+tmp)
    tmp-=1+si+tmp
  plus=not plus

ans0=ans
ans=0
tmp=0
plus=False
for si in csum_a:
  if plus and si+tmp>0:
    pass
  elif plus and si+tmp<=0:
    ans+=1-(si+tmp)
    tmp+=1-(si+tmp)
  elif not plus and si+tmp<0:
    pass
  elif not plus and si+tmp>=0:
    ans+=1+(si+tmp)
    tmp-=1+si+tmp
  plus=not plus

print(min(ans0,ans))

Measured memory_bytes: 14332
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

class Dish {
	long t;
	long a;
	boolean used = false;
}
public class Main {
	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        int n = Integer.parseInt(line);
        List<Dish> t_list = new ArrayList<Dish>();
        List<Dish> a_list = new ArrayList<Dish>();
        for (int i = 0 ; i < n ; i++) {
            line = in.nextLine();
            String[] split = line.trim().split("\\s+");
            Dish d = new Dish();
            d.t = Integer.parseInt(split[0]);
            d.a = Integer.parseInt(split[1]);
            t_list.add(d);
            a_list.add(d);
        }
        Collections.sort(t_list, new Comparator<Dish>(){
            @Override
            public int compare(Dish d1, Dish d2) {
        		if ( (d1.t + d1.a) > (d2.t + d2.a) ) {
        			return -1;
        		} else if ((d1.t + d1.a) == (d2.t + d2.a)) {
        			if (d1.t > d2.t) {
        				return -1;
        			} else if (d1.t == d2.t) {
        				return 0;
        			} else {
        				return 1;
        			}
        		} else {
        			return 1;
        		}
        	}
        });
        Collections.sort(a_list, new Comparator<Dish>(){
            @Override
            public int compare(Dish d1, Dish d2) {
        		if ( (d1.t + d1.a) > (d2.t + d2.a) ) {
        			return -1;
        		} else if ((d1.t + d1.a) == (d2.t + d2.a)) {
        			if (d1.a > d2.a) {
        				return -1;
        			} else if (d1.a == d2.a) {
        				return 0;
        			} else {
        				return 1;
        			}
        		} else {
        			return 1;
        		}
        	}
        });

        in.close();

        boolean t_turn = true;
        long ans = 0;
        int t_ptr = 0;
        int a_ptr = 0;
        for (int i = 0 ; i < n ; i++) {
        	if (t_turn) {
        		Dish d;
        		while (true) {
        			d = t_list.get(t_ptr);
        			t_ptr++;
        			if (d.used == false) break;
        		}
        		d.used = true;
        		ans += d.t;
        		t_turn = !t_turn;
        	} else {
        		Dish d;
        		while (true) {
        			d = a_list.get(a_ptr);
        			a_ptr++;
        			if (d.used == false) break;
        		}
        		d.used = true;
        		ans = ans - d.a;
        		t_turn = !t_turn;
        	}
        }
        System.out.println(ans);
    }
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, tmp;
    cin >> N;
    vector<int64_t> list(N + 1);
    int64_t sum = 0;
    for (int i = 1; i < N + 1; i++)
    {
        cin >> tmp;
        list[i] = list[i - 1] + tmp;
        sum += tmp;
    }
    int64_t ans = large;
    for (int i = 1; i < N; i++)
    {
        tmp = sum - list[i];
        ans = min(ans, abs(tmp-list[i]));
    }
    cout << ans;
}

Measured memory_bytes: 1792
from collections import Counter
S = Counter(input()).most_common()
T = Counter(input()).most_common()

ans = 'Yes'
if len(S) != len(T):
    ans = 'No'
else:
    for i in range(len(S)):
        if S[i][1] != T[i][1]:
            ans = 'No'
            break
            
print(ans)

Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    Yn(n==m);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	long a, b, k;
	scanf("%ld", &a);
	scanf("%ld", &b);
	scanf("%ld", &k);
	if(a >= k){
		a = a - k;
	}
	else{
		if(b >= (k - a)){
			b = b - (k - a);
		}
		else{
			b = 0;
		}
		a = 0;
	}
	printf("%ld %ld\n", a, b);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>

using namespace std;

int d,a[31][12];

bool ok(int s,int g){
	for(int i=0;i<d;i++){
		if(a[i][s-1]==1)s--;
		else if(a[i][s]==1)s++;
	}
	if(s==g)return true;
	return false;
}

int main(void){

	int n,m,g;
	char in;
	
	while(cin >> n,n){
		
		fill(a[0],a[31],0);

		cin >> m >> g >> d;
		
		for(int i=0;i<d;i++){
			for(int j=1;j<n;j++){
				cin >>in;
				a[i][j]=in-'0';
			}
		}

		if(ok(m,g)){
			cout << 0 << endl;
			continue;
		}
		
		bool fg=false;
		int p,q;
		
		for(int i=0;i<d;i++){
			for(int j=1;j<n;j++){
				if(a[i][j]==0 && a[i][j-1]==0 && a[i][j+1]==0){
					a[i][j]=1;
					fg=ok(m,g);
					if(fg){
						p=i+1,q=j;
						break;	
					}
					a[i][j]=0;
				}
			}
			if(fg)break;
		}
		if(fg)cout << p << " " << q << endl;
		else cout << 1 << endl;
		
	}
	
return 0;
}

Measured memory_bytes: 1160
L, R = map(int, input().split())

# 前提として、LとRの差が2019より小さいとき

# modを比較し、LよりRの方が大きい時は2019の倍数を通り越していない
# modを比較し、LよりRの方が小さい時は2019の倍数を通り越している

deff = R - L
if (deff < 2019):
    min_num = 10**9 + 7
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            min_num = min(min_num, (i * j) % 2019)
    print(min_num)
else:
    print(0)


Measured memory_bytes: 9108
S = input()
for i in range(1 << 3):
    equation = [S[0]]
    for j in range(3):
        if i >> j & 1:
            equation += ["+"]
        else:
            equation += ["-"]
        equation += [S[j + 1]]
    equation = "".join(equation)
    if eval(equation) == 7:
        print(equation + "=7")
        break


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();

			int a = x.Max();
			int b = a / 2;
			int c = x.Min();
			int d = Math.Abs(b - c);
			for (int i = 0; i < n; i++) {
				int sub = Math.Abs(b - x[i]);
				if (sub < d) {
					c = x[i];
					d = sub;
				}
			}
			Console.WriteLine($"{a} {c}");
		}
	}
}


Measured memory_bytes: 38648
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  ll X; cin>>X;
  if (X >= 30)
    cout<<"Yes"<<endl;
  else
    cout <<"No" <<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
using M = map<int, int>;

int main()
{
  int n, y;
  cin >> n >> y;
  rep(i, 2001){
    rep(j, 2001 - i){
      if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y && (n - i - j) > -1){
        cout << i << " " << j << " " << (n - i - j) << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
        

  return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,memo[200],ans=1;
vector<int> v;

void Init_v();

main() {
    Init_v();
    rep(i,200) memo[i] = 1;
    cin >> n;
    for(int i=2;i<=n;i++) {
        int tmp = i;
        rep(j,v.size()) {
            if (!(tmp%v[j])) {
                memo[j]++;
                tmp /= v[j];
                j--;
                if (tmp == 1) break;
            }
        }
    }
    rep(i,200) ans = (ans*memo[i])%MOD;
    cout << ans << endl;
}

void Init_v() {
    int hoge = 1;
    v.pb(2);
    while(hoge += 2,hoge<=1000) {
        int border = (int)sqrt(hoge);
        bool f = true;
        for(int i=0;v[i] <= border;i++) {
            if (!(hoge%v[i])) {
                f = false;
                break;
            }
        }
        if (f) v.pb(hoge)
    }
}



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

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

using namespace std;

const int MAX = 200010;
int N,M,Q;
int prev[MAX], next[MAX];

void erase(int cur) {
  next[prev[cur]] = next[cur];
  prev[next[cur]] = prev[cur];
}

int main(){
  cin >> N >> M >> Q;
  rep(i,N) {
    prev[i] = ( i - 1 + N ) % N;
    next[i] = ( i + 1 + N ) % N;
  }
  int cur = 0,a,q;
  rep(i,M){
    cin >> a;
    if( a & 1 ) {
      rep(_,a) cur = prev[cur];
      int tmp = cur;
      cur = next[cur];
      erase(tmp);
    } else {
      rep(_,a) cur = next[cur];
      int tmp = cur;
      cur = next[cur];
      erase(tmp);
    }
  }
  set<int> S;
  rep(_,N){
    if( S.count(cur) ) break;
    S.insert(cur);
    cur = next[cur];
  }
  rep(i,Q){
    cin >> q;
    cout << (S.count(q)>0) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2756
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
//template<typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define ld long double
#define int long long

void SOLVE() {
	int a, b, k;
	cin >> a >> b >> k;
	if (k >= a) {
		k -= a;
		a = 0;
		if (k >= b) {
			k -= b;
			b = 0;
		}
		else {
			b -= k;
		}
	}
	else {
		a -= k;
	}
	cout << a << " " << b << "\n";
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout.precision(10);
	//freopen("longpath.in", "r", stdin);
	//freopen("longpath.out", "w", stdout);
	int Q = 1;
	//cin >> Q;
	while (Q--)
		SOLVE();

	return 0;
}
/*
*/

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

int N, A, B;

int main() {
    cin >> N >> A >> B;
    char buf;
    int passed = 0;
    int passed_f = 0;
    for (int i = 0; i < N; i++) {
        cin >> buf;
        switch (buf) {
            case 'a':
                if (passed < A + B) {
                    cout << "Yes" << endl;
                    passed++;
                }
                else
                    cout << "No" << endl;
                break;
            case 'b':
                if (passed < A + B && passed_f < B) {
                    cout << "Yes" << endl;
                    passed++;
                    passed_f++;
                }
                else
                    cout << "No" << endl;
                break;
            default:
                cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(a, max(b, c)) - min(a, min(b,c));
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;

int main(int argc, char *argv[])
{

  int N;
  cin >> N;
  int a[N];
  int result = 0;
  for (int i =0 ; i < N; i++) {
    cin >> a[i];
  }
  // for (int i  = 0; i < N; i++) {
  //   cout << a[i] << "\n";
  // }
  
  for (int i = 0; i < N; i++) {


    while ((a[i] % 2) == 0) {

      result++;
      a[i] = a[i]/2;
    }
  }
  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

class UnionFind{
  vector<int> parent, depth, size;
  int count;
public:
  UnionFind(int n): parent(n), depth(n,1), size(n,1), count(n){
    iota(ALL(parent),0);
  }
  int get_root(int i){
    if(parent[i] == i) return i;
    else return parent[i] = get_root(parent[i]);
  }
  bool is_same(int i, int j){return get_root(i) == get_root(j);}
  int merge(int i, int j){
    int ri = get_root(i), rj = get_root(j);
    if(ri == rj) return ri;
    else{
      --count;
      if(depth[ri] < depth[rj]){
        parent[ri] = rj;
        size[rj] += size[ri];
        return rj;
      }else{
        parent[rj] = ri;
        size[ri] += size[rj];
        if(depth[ri] == depth[rj]) ++depth[ri];
        return ri;
      }
    }
  }
  int get_size(int i){return size[get_root(i)];}
  int count_group(){return count;}
};







int main(){
  LLI n,m,q;
  while(cin >> n >> m >> q){
    vector<pair<int,int>> q0, q1;

    REP(i,q){
      int a,b,c; cin >> a >> b >> c;
      if(c == 0){
        q0.push_back({a,b});
      }else{
        q1.push_back({a,b});
      }
    }

    UnionFind uf(n);

    for(auto &p : q0){
      uf.merge(p.fst, p.snd);
    }

    bool ans = true;

    for(auto &p : q1){
      if(uf.is_same(p.fst, p.snd)){
        ans = false;
      }
    }

    if(ans){
      if(m == n-1){
        if(q1.size()) ans = false;
      }else{
        LLI k = uf.count_group();

        if(m > n-k + k*(k-1)/2){
          ans = false;
        }
      }
    }
    
    cout << (ans ? "Yes" : "No") << endl;
  }

  return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  string s;
  cin >> s;
  string ans;
  for(auto c:s) {
    if (c=='B') {
      if ((int)(ans.size())>0) ans.erase(ans.end()-1);
    }
    else ans.push_back(c);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a[20][20],dp[1<<16];
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%lld",&a[i][j]);
    for(int k=0;k<1<<n;k++){
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if((k>>i&1)&&(k>>j&1))dp[k]+=a[i][j];
            }
        }
    }
    for(int i=0;i<1<<n;i++){
        for(int j=i;;j=(j-1)&i){
            dp[i]=max(dp[i],dp[j]+dp[i^j]);
            if(j<=0)break;
        }
    }
    printf("%lld\n",dp[(1<<n)-1]);
}


Measured memory_bytes: 768
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();
    let N = buf_it.next().unwrap().parse::<isize>().unwrap();
    let mut A = buf_it.next().unwrap().chars();
    let mut B = buf_it.next().unwrap().chars();
    let mut C = buf_it.next().unwrap().chars();

    let mut ans = 0;
    for _ in 0..N{
        let mut s = HashSet::new();
        s.insert(A.next().unwrap());
        s.insert(B.next().unwrap());
        s.insert(C.next().unwrap());
        ans += s.len() - 1;
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<$n){
  $a[]=trim(fgets(STDIN));
  ++$i;
}
$i=0;
while($i<$m){
  $b[]=trim(fgets(STDIN));
  ++$i;
}
$i=0;
while($i<=$n-$m){
  $j=0;
  while($j<=$n-$m){
    if(substr($a[$i],$j,$m)==$b[0]){
      $flag=1;
      $k=$i+1;
      while($k<$i+$m){
        if(substr($a[$k],$j,$m)!=$b[$k-$i]){
          $flag=0;
          break;
        }
        ++$k;
      }
      if($flag){
        echo "Yes";
        exit;
      }
    }
    ++$j;
  }
  ++$i;
}
echo "No";

Measured memory_bytes: 4604
#include<stdio.h>

int main(){

  int i, j, n, q, cnt=0;

  scanf("%d", &n);

  int S[n];

  for(i=0;i<n;i++) scanf("%*c%d", &S[i]);

  scanf("%d", &q);

  int T[q];

  for(i=0;i<q;i++) scanf("%*c%d", &T[i]);

  for(i=0;i<q;i++){

    for(j=0;j<n;j++){

      if(S[j]==T[i]){

	cnt++;

	break;

      }

    }

  }

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

  return 0;

}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(void)
{
	int n, ans = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		bool prime = true;
		cin >> a;
		for(int k = 2; k * k <= a; k++) {
			if(a % k == 0){
				prime = false;
				break;
			}
		}
		if(prime) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main(){
  long n,a,b;
  cin >> n >> a >> b;

  if(a*n < b){
    cout << a*n << endl;
  }else{
    cout << b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)

#define pb push_back
#define ft first
#define sd second
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll power(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b % 2) {
            res *= a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}
const int N = 1e5 + 5;
const ll mod = 1e9+7;
int n, m;
int mat[105][105], dp[105][105][2];
const int INF = 2e9;

int solve(int i, int j, int last) {
    if(i == n && j == m) return last==0 && mat[i][j]==1;
    if(i > n || j > m) return INF;
    if(dp[i][j][last] != -1) return dp[i][j][last];
    if(mat[i][j] == 0) {
        return dp[i][j][last] = min(solve(i+1, j, 0), solve(i, j+1, 0));
    }
    else {
        return dp[i][j][last] = (last==0)+min(solve(i+1, j, 1), solve(i, j+1, 1));
    }
}

signed main() {
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    for(int i=1; i<=n; i++) {
        string s;
        cin >> s;
        for(int j=1; j<=m; j++) {
            mat[i][j] = (s[j-1] == '#');
        }
    }
    cout << solve(1, 1, 0) << '\n';
    return 0;
}


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

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

    static class CMarch {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long[] c = new long[256];
            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                c[in.next().charAt(0)]++;
            }
            long ans = 0;
            ans += c['M'] * c['A'] * c['R'];
            ans += c['M'] * c['A'] * c['C'];
            ans += c['M'] * c['A'] * c['H'];
            ans += c['M'] * c['R'] * c['C'];
            ans += c['M'] * c['R'] * c['H'];
            ans += c['M'] * c['C'] * c['H'];
            ans += c['A'] * c['R'] * c['C'];
            ans += c['A'] * c['R'] * c['H'];
            ans += c['A'] * c['C'] * c['H'];
            ans += c['R'] * c['C'] * c['H'];
            out.println(ans);
        }

    }
}



Measured memory_bytes: 45980
import numpy as np

n = int(input())
base = ["M","A","R","C","H"]
base_1 = np.zeros(5)

for i in range(n):
	s = input()
	for j in range(5):
		if s[0] == base[j]:
			base_1[j] += 1
			break
            
ans = 0
for i in range(2,5):
  for j in range(1,i):
    for l in range(0,j):
      ans += base_1[i]*base_1[j]*base_1[l]
      


print(int(ans))

Measured memory_bytes: 20624
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long ll;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int x;

int main() {
    cin >> x;
    int ans = 1;
    for(int i = 2; i <= x; ++i) {
        int ch = i*i;
        while(ch <= x) {
            chmax(ans, ch);
            ch *= i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
ll kpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	ll n,i,a[maxn]={0},ans=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	for(ll i=1;i<=n;i++)ans=(ans+(((a[i]*kpow(2,n-1))%mod*kpow(2,i-1))%mod*(n-i+2))%mod*kpow(2,n-i))%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

int main()
{
	LL n;
	cin >> n;
	vector<LL> b(n-1);

	for (auto &e : b) {
		cin >> e;
	}

	vector<LL> a(n, 0);
	a[0] = b[0];
	a[n-1] = b[n-2];

	for (int i = 1; i <= n-2; ++i) {
		a[i] = min(b[i-1], b[i]);
	}

	LL sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

int n, m;
int dp[N];
int tot, head[N], ver[M], nxt[M], in[N];

inline void add(int u, int v)
{
	ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;
}

int main()
{
	//File("");
	n = gi <int> (), m = gi <int> ();
	for (int i = 1; i <= m; i+=1) {int u = gi <int> (), v = gi <int> (); add(u, v), ++in[v];}
	queue <int> q;
	for (int i = 1; i <= n; i+=1) if (!in[i]) q.push(i);
	while (!q.empty())
	{
		int u = q.front(); q.pop();
		for (int i = head[u]; i; i = nxt[i])
		{
			int v = ver[i];
			dp[v] = max(dp[v], dp[u] + 1);
			if (!(--in[v])) q.push(v);
		}
	}
	int mx = 0;
	for (int i = 1; i <= n; i+=1) mx = max(mx, dp[i]);
	printf("%d\n", mx);
	return 0;
}


Measured memory_bytes: 5812
N = int(input())
S = input()
left = 0
right = S[1:].count('E')
ans = left + right
for i in range(1, N):
	if S[i] == "W":
		left += 1
	if S[i - 1] == "E":
		right -= 1
	ans = min(ans, left + right)
print(ans)

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

namespace ProjectContest
{
    class Test
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            var a = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32).ToList();
            int sum = a.Sum();
            var b = new int[n];
            b[0] = sum;
            for(int i = 0; i < n-1; i++)
                b[i+1] = b[i] - a[i];
            int min = sum;
            foreach (int i in b) min = Math.Min(min, Math.Abs(sum - 2 * i));
            Console.WriteLine(min);
        }

    }
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> para;
const int inf = 1e9 + 7;
const int maxN = 1e3 + 5;
const int maxN2 = 1e6 + 5;

int h, w, arr[maxN2], n;
int lastX, lastY;
int ans[maxN][maxN];

// parzysty wiersz - w prawo i w dol (jesli ostatnia)
// nieparzysty wiersz - w lewo i w dol (jesli pierwsza)
// wiersz kolumna
void color(int i) {
	while (arr[i] > 0) {
		ans[lastX][lastY] = i;
		if (lastX % 2 == 0) {
			lastY++;
			if (lastY == w) {
				lastY--;
				lastX++;
			}
		} else {
			lastY--;
			if (lastY == -1) {
				lastX++;
				lastY++;
			}
		}
		arr[i]--;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin>>h>>w;
	cin>>n;
	RI(i, n) cin>>arr[i];
	RI(i, n) {
		color(i);
	}
	REP(i, h) {
		REP(j, w)
			cout<<ans[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 2688
import sys
import itertools
INF = float("INF")

N = int(input())
AA = list(map(int, sys.stdin.readline().split()))
BB = list(map(int, sys.stdin.readline().split()))

cards = set()
for i,(a,b) in enumerate(zip(AA,BB)):
    if i%2 == 0:
        cards.add((a, b, i))
    else:
        cards.add((b, a, i))

def solve(ii):
    tmp = 0
    for i in range(N):
        for j in range(i+1,N):
            if ii[i] > ii[j]:
                tmp += 1
    return tmp

ans = INF
for Acards in itertools.combinations(cards, (N+1)//2):
    Bcards = cards - set(Acards)

    Ais = sorted([(card[0], card[2]) for card in Acards])
    Bis = sorted([(card[1], card[2]) for card in Bcards])

    bn = -1
    ii = []
    flag = False
    for i in range(N):
        if i%2 == 0:
            n,i = Ais[i//2]
        else:
            n,i = Bis[i//2]
        if bn > n: # 組み合わせた時広義単調増加になってない
            flag = True
            break
        bn = n
        ii.append(i)

    if flag: continue

    ans = min(ans,solve(ii))


if ans == INF:
    print(-1)
else:
    print(ans)


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

using namespace std;

bool check(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  if (s == t) return true;
  else return false;
}

int main() {
  string s;
  cin >> s;
  int n = (int)s.size();
  string s1 = "", s2 = "";
  for (int i=0; i<n; i++) {
    if (i < n / 2) s1 += s.at(i);
    else if (i > n / 2) s2 += s.at(i);
  }
  if (check(s) && check(s1) && check(s2)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int isPalindrome( string line ){
    int size = line.size();
    for ( int i = 0; i < size / 2; i++ ){
	if ( line[i] != line[size-1-i] ) return false;
    }
    return true;
}

int main(){
    string line;
    int sum = 0;
    while ( cin >> line ){
	if ( isPalindrome(line) ) sum++;
    }

    cout << sum << endl;
    return 0;
}

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

int func(int x) {
	if (x < 10) return x;
	return x % 10 + func(x / 10);
}

int main() {
	int n;
	cin >> n;
	int s = func(n);
	if (n % s == 0) {
			cout << "Yes" << endl;
			return 0;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){
	int forward,turn,direct=90;
	double x=0,y=0;
	while(1){
		scanf("%d,%d",&forward,&turn);
		if(forward==0 && turn==0){
			break;
		}
		x+=forward*cos(direct*2*M_PI/360);
		y+=forward*sin(direct*2*M_PI/360);
		
		direct-=turn;
		direct%=360;
	}
	
	printf("%d\n%d\n",(int)x,(int)y);
	
	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  string abc  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < 26; j++){
      if(s.at(i) == abc.at(j)){
        s.at(i) = abc.at((j + n) % 26);
        break;
      }
    }
  }
  cout << s;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S == "abc" || S == "acb" || S == "bac") {
		cout << "Yes" << endl;
	}
	else if (S == "bca" || S == "cab" || S == "cba") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256