akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
vector<int> input;
int visited[10] = {};
int gogo[3] = {};
int n;
int killing(int itr) {
	if (itr == 3) return 0;
	int cost = 100000;
	for (int i = 1; i < (1 << (n)); ++i) {
		int bad = 1;
		int now_go = 0;
		int now = i;
		int now_cost = -10;
		for (int q = 0; now != 0; ++q) {
			if (now % 2 == 1) {
				now_go += input[q];
				now_cost += 10;
				if (visited[q] == 1) {
					bad = 0;
				}
			}
			now /= 2;
		}
		if (bad == 1) {
			now = i;
			for (int q = 0; now != 0; ++q) {
				if (now % 2 == 1) {
					visited[q] = 1;
				}
				now /= 2;
			}
			cost = min(cost, now_cost + abs(now_go - gogo[itr]) + killing(itr + 1));
			now = i;
			for (int q = 0; now != 0; ++q) {
				if (now % 2 == 1) {
					visited[q] = 0;
				}
				now /= 2;
			}
		}
	}
	return cost;
}
int main() {
	cin >> n;
	REP(i, 3) {
		cin >> gogo[i];
	}
	REP(i, n) {
		int d;
		cin >> d;
		input.push_back(d);
	}
	cout << killing(0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void change(char *str){
  int len=strlen(str);
  int i;
  for(i=0;i<len;i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]-=32;
    }
  }
}
int main(void)
{
  char W[10],T[1000];
  int count=0;

  scanf("%s",W);
  change(W);
  while(1)
  {
    scanf("%s",T);
    if(strcmp(T,"END_OF_TEXT")==0) break;
    change(T);
    if(strcmp(T,W)==0) count++;
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2040
N, K = map(int, input().split())
result = []
check = []
for i in range(N):
  check.append(i)
for i in range(K):
  d = int(input())
  A = list(map(int, input().split()))
  for x in A:
    result.append(x)
result_number = len(check) - len(set(result))
print(result_number)

Measured memory_bytes: 9188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int n; cin >> n;
	getline(cin, s);
	for (int j = 0; j < n; j++){
		getline(cin, s);
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'H'&&s[i + 1] == 'o'&&s[i + 2] == 's'&&s[i + 3] == 'h'&&s[i + 4] == 'i'&&s[i + 5] == 'n'&&s[i + 6] == 'o') {
				cout << "Hoshina";
				i += 6;
			}
			else cout << s[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
def main():
    N, P = (int(i) for i in input().split())
    A = [int(i) % 2 for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if P == 0:
        odd = 2**(c[1]-1) if c[1] > 0 else 0
        even = 2**c[0]
        if 0 < odd:
            even *= odd
    else:
        odd = 2**(c[1]-1) if c[1] > 0 else 0
        even = 2**c[0]
        odd *= even
    print(odd if P == 1 else even)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
n = int(input())
arr = list(map(int,input().split()))
q = int(input())
from collections import Counter
arr = Counter(arr)
ans = sum([i*arr[i] for i in arr])

for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)

Measured memory_bytes: 23024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 1000000;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;

		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
		cout << flush;
	}
}


int main(){

	// ツ素ツ青板づーツ仰づ淞づゥ
	erats();

	int n;
	while(cin>>n&&n!=0){
		int sum=0;
		for(int i = 0; i < n; i++){
			int pp,mm;
			cin>>pp>>mm;
			int cnt=0;
			for(int j = 0; j < p; j++){
				if(prime[j]>=pp-mm&&prime[j]<=pp+mm){
					cnt++;
				}
				else if(prime[j]>pp+mm)
					break;
			}
			sum+=max(0,cnt-1);
			if(cnt==0)
				sum--;
		}
		cout<<max(0,sum)<<endl;
	}

	return 0;
}

Measured memory_bytes: 2148
import math


def insertion_sort(alist, step):
    size = len(alist)
    count = 0

    for i in range(step, size): 
        v = alist[i]
        j = i - step
        while j >= 0 and alist[j] > v:
            alist[j+step] = alist[j]
            j -= step
            count += 1
        alist[j+step] = v

    return (count, alist)


def shell_sort(alist, steps):   
    total_count = 0
    sorted_list = alist

    for step in steps:
        (count, sorted_list) = insertion_sort(sorted_list, step)
        total_count += count

    return (total_count, sorted_list)


def run():
    n = int(input())
    nums = []
    for i in range(n):
        nums.append(int(input()))

    steps = create_steps(n)
    (cnt, nums) = shell_sort(nums, steps)

    print(len(steps))
    print(" ".join([str(s) for s in steps]))
    print(cnt)
    for n in nums:
        print(n)


def create_steps(n):
    steps = []
    k = 1
    while True:
        steps = [k] + steps
        k =  2 * k + int(math.sqrt(k)) + 1
        if k >= n:
            break

    return steps


if __name__ == '__main__':
    run()



Measured memory_bytes: 45588
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        const long Mod = 1000000000 + 7;

        static Dictionary<string, long> Solve(int n)
        {
            if (n == 1)
            {
                return new Dictionary<string, long>
                {
                    ["A"] = 1,
                    ["G"] = 1,
                    ["C"] = 1,
                    ["T"] = 1,
                };
            }

            var previous = Solve(n - 1);
            var result = new Dictionary<string, long>();

            foreach (var pair in previous)
            {
                string str = pair.Key;
                long count = pair.Value;
                HashSet<char> chars = new HashSet<char> { 'A', 'C', 'G', 'T' };

                if (str.Length >= 3 && ((str[0] == 'G' && str[2] == 'C') || (str[1] == 'G' && str[2] == 'C')))
                {
                    chars.Remove('A');
                }
                else
                {
                    switch (str.Substring(0, Math.Min(2, str.Length)))
                    {
                        case "AC":
                            chars.Remove('G');
                            break;
                        case "CG":
                        case "GC":
                            chars.Remove('A');
                            break;
                        default:
                            break;
                    }
                }

                foreach (var c in chars)
                {
                    string key = (c + str).Substring(0, Math.Min(3, 1 + str.Length));
                    long value;
                    result.TryGetValue(key, out value);
                    value = (value + count) % Mod;
                    result[key] = value;
                }
            }

            return result;
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var dictionary = Solve(n);

            long ans = 0;
            foreach (var pair in dictionary)
            {
                ans = (ans + pair.Value) % Mod;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 15456
# 入力
N = int(input())
A_list = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(N-1):
    tmp_stock = 0
    if(A_list[i] < A_list[i+1]):
        #購入
        tmp_stock = money // A_list[i]
        money = money - A_list[i] * tmp_stock
        stock += tmp_stock
    elif(A_list[i] > A_list[i+1]):
        #売却
        tmp_stock = stock
        money = money + A_list[i] * tmp_stock
        stock -= tmp_stock
    else:
        pass
        #何もしない

#最終日売却
tmp_stock = stock
money = money + A_list[N-1] * tmp_stock
stock -= tmp_stock

print(money)


Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 305;
int a[3];
double dp[maxn][maxn][maxn];

int main() {
    int n;
    scanf("%d", &n);
    int x;
    REP(i, n) {
        scanf("%d", &x);
        a[x - 1]++;
    }
    double p = 1. / n;
    REP(k, n + 1) REP(j, n + 1) REP(i, n + 1) {
        x = n - i - j - k;
        if (x == n) continue;
        if (x < 0) break;
        if (i) dp[i][j][k] += dp[i - 1][j][k] * i * p;
        if (j) dp[i][j][k] += dp[i + 1][j - 1][k] * j * p;
        if (k) dp[i][j][k] += dp[i][j + 1][k - 1] * k * p;
        dp[i][j][k] += 1;
        dp[i][j][k] /= 1 - x * p;
    }
    printf("%.10f\n", dp[a[0]][a[1]][a[2]]);
    return 0;
}


Measured memory_bytes: 219520
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, ans, cnt, sum, a[310000], b[310000];
string str;
bool f[11000];
char c[1100][1100];
int main() {
	cin >> n >> m;
	if (n < m)
		cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  string target = "AKIHABARA";
  int i, j;
  for (i = 0, j = 0; i < s.size(); i++) {
    if (target[j] == 'A' && s[i] != target[j]) {
      j++;
    }
    if (s[i] == target[j]) {
      j++;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (j == target.size() - 1) j++;

  // 解答
  cout << (target[j] == '\0' ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout<<(x-z)/(y+z)<<endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n; cin>>n;
    string s; cin>>s;
    if(s.size()<=n){
        cout<<s<<endl;
    }
    else{
        rep(i,n){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}











Measured memory_bytes: 3624
a,b = map(int,input().split())
if a + b > a * b:
    if a + b > a - b:
        print(a + b)
    else:
        print(a - b)
elif a * b > a - b:
    if a * b > a - b:
        print(a * b)
    else:
        print(a - b)
else:
    print(a - b)

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int const MAX_N = 100010;
vector<ll> prime;
vector<bool> is_prime(MAX_N,true);
void Eratosthenes() {
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false;
    for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i);
}

vector<P> prime_factorization(ll a) {
    vector<P> prime_factor;
    if (is_prime[0]) Eratosthenes();
    for (ll& i : prime) {
        if (i*i > a) break;
        if (a%i == 0) {
            P p = P(i,0);
            while (a%i == 0) {
                a /= i;
                p.second++;
            }
            prime_factor.push_back(p);
        }
    }
    if (a != 1) prime_factor.push_back(P(a,1));
    return prime_factor;
}

void rec(vector<ll>& div,vector<P>& fact,int i,ll d) {
    if (i == fact.size()) {
        div.push_back(d);
        return;
    }
    for (int j = 0;j <= fact[i].second;++j) {
        rec(div,fact,i+1,d);
        d *= fact[i].first;
    }
}

vector<ll> divisor(ll a) {
    vector<ll> div;
    vector<P> prime_factor = prime_factorization(a);
    rec(div,prime_factor,0,1);
    return div;
}

int main() {
    Eratosthenes();
    vector<int> sum(100010,0);
    for (int i = 12;i < 100010;++i) if (sum[i] == 0) {
        int cnt = 0;
        for (ll& j : prime) {
            if (j*j > i) break;
            if (i%j == 0) {
                cnt++;
                if (i%(j*j) == 0 && j*j*j*j <= i) cnt++;
            }
            if (cnt > 1) {
                sum[i] = 1;
                break;
            }
        }
    }
    // p_ary(sum,0,100,i);
    // for (int i = 0;i < 100;++i) if (sum[i]) cout << i << " ";
    for (int i = 1;i < 100010;++i) sum[i] += sum[i-1];
    int q;
    cin >> q;
    for (int i = 0;i < q;++i) {
        int n;
        cin >> n;
        cout << sum[n] << "\n";
    }
    return 0;
}


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

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(a+b>=x && a<=x) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long LL;
const int maxn = 1e5;
int n, a, b, m[maxn+3];

bool judge(LL x)
{
    LL sum = 0;
    for(int i=0; i<n; ++i)
    {
        LL t = m[i]-x*b;
        if(t>0)
        {
            sum += ceil(t*1.0/(a-b));
            if(sum > x || sum < 0)
                return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    
    for(int i=0; i<n; ++i) scanf("%d",&m[i]);
    LL l=0, r=1e9, mid;
    while(l<r)
    {
        mid = (l+r)/2;
        if(judge(mid)) r=mid;
        else l=mid+1;
    }
    printf("%lld\n",r);
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((c - (a - b)) > 0) {
		cout << c - (a - b) << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, K ,count = 0;
  cin >> A >> B >> K;
  for (int i=min(A,B); i >= 1; i--){
    if(A%i == 0 && B%i == 0){
      count++;
      if(count == K){
        cout << i << endl;
        break;
      }
      else
        continue;
    }
    else
      continue;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main()
{
  vector<ll>v;
  ll x,y,a,b,c,i,s=0;
  cin>>x>>y>>a>>b>>c; ll p[a],q[b],r[c];
  for(i=0;i<a;i++) cin>>p[i];
  for(i=0;i<b;i++) cin>>q[i];
  for(i=0;i<c;i++) cin>>r[i];
  sort(p,p+a); sort(q,q+b); sort(r,r+c);
  for(i=a-1;i>=a-x;i--) v.pb(p[i]);
  for(i=b-1;i>=b-y;i--) v.pb(q[i]);
  for(i=0;i<c;i++) v.pb(r[i]);
  sort(v.begin(),v.end(),greater<ll>());
  for(i=0;i<x+y;i++) s+=v[i];
  cout<<s;
}

Measured memory_bytes: 8816
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main() {
	string S;
	cin >> S;
	S.pop_back();
	int ans = 0;
	for (int len = 1; len <= S.size() / 2; len++) {
		if (S.substr(0, len) == S.substr(len, len)) ans = len * 2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
"""
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys"""
#input = sys.stdin.readline


#N=int(input())

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

lst=[[A[0],0,1]]
count=0

for i in range(1,N):
    m=1
    while lst and lst[-1][0]>A[i]:
        a,b,c=lst.pop()
        count+=a*(i-b)*c
        m+=c
    lst.append([A[i],i,m])
while lst:
    a,b,c=lst.pop()
    count+=a*(N-b)*c

print(count)


Measured memory_bytes: 37672
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <cctype>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	char c;
	int a[27];
	memset(a,0,sizeof(a));

	while(cin >> c)
	{
		if(isalpha(c))
		{
			c = tolower(c);
			a[c - 'a']++;
		}
	}

	rep(i,26)
	{
		cout << (char(i+'a')) << " : " << a[i] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1144
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		int n = str.length();
		String sub1 = str.substring(0, n/2);
		String sub2 = str.substring(((n+3)/2) -1 ,n );
		if (sub1.equals(sub2)) 
		    System.out.println("Yes");
		else 
		    System.out.println("No");
		
    }
}



Measured memory_bytes: 35616
#include <stdio.h>
int main(){
	int n,a;
	scanf("%d",&n);
	a=n%10;
	if(a==2||a==4||a==5||a==7||a==9)
    printf("hon\n");
	else if(a==0||a==1||a==6||a==8)
    printf("pon\n");
	else if(a==3)
    printf("bon\n");
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
//using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);
//string = to_string(数値)
//int = stoi(文字列)
//(int)(char-'0')
//string = itoa(int)
//円周率: M_PI

int main() {
    /*int a,b,n; cin >> a >> b >> n;


    if(n>=b){
        cout << ((n+1)/b)*b-1 << endl;
    }
    else{
        cout << n << endl;
    }*/

    //cout << 1000000000000000000LL/1.01 << endl;

    int64_t x; cin >> x;
    int64_t sum=100;
    for(int i=1; i<=3800; ++i){
        sum += sum/100;
        if(sum>=x){
            cout << i << endl;
            return 0;
        }
    }
}





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

int main()
{
    string s,t;
    cin >> s >> t;
    int m = s.length();
    int n = t.length();
    int dp[m+1][n+1];

    for(int i=0;i<=n;i++)
        dp[0][i] = 0;
    for(int i=0;i<=m;i++)
        dp[i][0] = 0;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    int temp = dp[m][n];
    string res;
    int i=m,j=n;
    while(temp>0 && i>0 && j>0)
    {
        if(s[i-1] == t[j-1]){
            res+=s[i-1];
            i--;
            j--;
            temp--;
        }
        else if(dp[i][j] == dp[i-1][j]){
            i--;
        }
        else
        {
            j--;
        }
    }
    reverse(res.begin(),res.end());
    cout << res << "\n";
}



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

int main(){
    int x,y,a,b;
    
    while(1){
        cin >>x >>y;
        if(x==0 && y==0) break;
        
        if(x<=y){
            a=x;
            b=y;
        } else {
            a=y;
            b=x;
        }
        cout << a << " " << b <<endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string solve(int N, int M, int Q) {
    vector<vector<int>> bulb_to_switch(M, vector<int>(N, 1));
    vector<int> ans(M);
    string ret;
    string S;
    for (int i = 0; i < N; i++) {
        S += '0';
    }
    for (int q = 0; q < Q; q++) {
        string s, B; cin >> s >> B;
        for (int i = 0; i < N; i++) {
            if (s[i] == '1') {
                if (S[i] == '1') S[i] = '0';
                else S[i] = '1';
            }
        }
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                if (B[i] == '0' && S[j] == '1') {
                    bulb_to_switch[i][j] = 0;
                }
                if (B[i] == '1' && S[j] == '0') {
                    bulb_to_switch[i][j] = 0;
                }
            }
        }
    }
    for (int i = 0; i < M; i++) {
        int sw = 100;
        for (int j = 0; j < N; j++) {
            if (bulb_to_switch[i][j] == 1) {
                if (sw == 100) sw = j;
                else {
                    sw = 100;
                    break;
                }
            }
        }
        ans[i] = sw;
    }
    for (int i = 0; i < M; i++) {
        if (ans[i] == 100) ret += '?';
        else if (ans[i] <= 9) ret += '0' + ans[i];
        else ret += 'A' + ans[i] - 10;
    }
    // for (int i = 0; i < M; i++) {
    //     for (int j = 0; j < N; j++) {
    //         cout << bulb_to_switch[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return ret;
}

int main(void) {
    int N, M, Q;
    vector<string> ans;
    while (1) {
        cin >> N >> M >> Q;
        if (N == 0) break;
        ans.push_back(solve(N, M, Q));        
    }
    for (auto i : ans){
        cout << i << endl;
    }
}





Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int max(int a, int b)
{
	if (a > b)
	{
		return a;
	}
	return b;
}

int main(void)
{
	int a, b, c, x, y;

	cin >> a >> b >> c >> x >> y;

	int xy = a * x + b * y;

	int big = max(x, y);

	int half = c * big * 2;

	int x_num = x;
		int y_num = y;
		int h = 0;
		int best = xy;

		while (true)
		{
			if (x_num != 0)
			{
				x_num--;
			}
			if (y_num != 0)
			{
				y_num--;
			}
			h += 2;

			int ans = a * x_num + b * y_num + c * h;

			if (ans > best)
			{
				cout << best << endl;
				return 0;
			}

			best = ans;
		}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> pic(h,vector<char>(w));
    rp(i,h){
        rp(j,w) cin >> pic[i][j];
    }
    int ctr=0;
    rp(i,1<<h){
        rp(j,1<<w){
            int black=0;
            rp(ii,h){
                rp(jj,w){
                    if(pic[ii][jj]=='#'&&(i&(1<<ii))&&(j&(1<<jj)))
                    black++;
                }
            }
            if(black==k) ctr++;
        }
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

Measured memory_bytes: 580
#include<iostream> 
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include <cstdlib>
using namespace std;

int main(){
	string s;
	cin>>s;
	if(s[1]=='B') cout<<"ARC";
	else cout<<"ABC";
	return 0;
}

Measured memory_bytes: 3036
#include<vector>
#include<iostream>
#include<cmath>

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> A(n+2,0);
  for(int i=0; i<n; i++){
    cin >> A[i+1];
  }
  int ans = 0;
  for(int i=1;i<n+2;i++){
    ans += abs(A[i]-A[i-1]);
  }
  for(int i=1; i < n+1; i++){
    cout << ans - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]) << endl;
  }
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

struct item{
    int left,right,up,down;
    char num;
};
int h,w;

bool canDelete(vector<string> data,item del){
    for(int i=del.up;i<=del.down;i++){
        for(int j=del.left;j<=del.right;j++){
            if( data[i][j]!=del.num && data[i][j]!='*')return false;
        }
    }
    return true;
}

void del(vector<string> &data, item del){
    for(int i=del.up;i<=del.down;i++){
        for(int j=del.left;j<=del.right;j++){
            data[i][j] = '*';
        }
    }
}

string solve(vector<string> data){
    item pos[300];
    rep(i,300){
        pos[i] = item{INF,0,INF,0};
    }
    
    rep(i,h){
        rep(j,w){
            char ch = data[i][j];
            if(ch=='.')continue;
            pos[ch].num     = (char)data[i][j];
            pos[ch].left    = min<ll>(pos[ch].left  ,j);
            pos[ch].right   = max<ll>(pos[ch].right ,j);
            pos[ch].up      = min<ll>(pos[ch].up    ,i);
            pos[ch].down    = max<ll>(pos[ch].down  ,i);
        }
    }
    
    vector<item> vec;
    rep(i,300){
        if(pos[i].left!=INF) vec.pb(pos[i]);
    }
    
    bool deleted[10]={};
    rep(i,vec.size()){
        rep(j,vec.size()){
            if(deleted[j])continue;
            if( canDelete(data,vec[j]) ){
                del( data ,vec[j] );
                deleted[j]=true;
                break;
            }
        }
    }
    
    rep(i,vec.size()){
        if(deleted[i]==false) return "SUSPICIOUS";
    }
    return "SAFE";
}


int main(){
    int t;
    cin>>t;
    rep(loop,t){
        cin>>h>>w;
        vector<string> data(h);
        rep(i,h){
            cin>>data[i];
        }
        cout<<solve(data)<<endl;
    }
}

Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)

int main()
{
  int n, k;
  cin >> n >> k;
  int count = 0;
  int num = 1;
  while (num <= n)
  {
    num *= k;
    count++;
    if (num > n)
    {
      cout << count << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

a , b , c = map(int, input().split())
x = int(input())

i = a
j = b
k = c
l = 0

while i >= j:
    j = j*2
    l += 1

while j >= k:
    k = k*2
    l += 1

can = False

if(k > j > i and l <= x):
    print("Yes")
    can = True
   

if not can:
    print("No")

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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N-1; i++) {
    B.at(i) = A.at(i+1) - A.at(i);
  }
  B.at(N-1) = A.at(0) + K - A.at(N-1);
  sort(B.begin(), B.end());
  cout << K - B.at(N-1) << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> p(n);
  rep(i,n)cin>>p[i];
  vector<int> a(n+1,0);
  rep1(i,n){
      a[i]=2*n*i;
  }
  int sum=2*n*n+n;
  vector<int> b(n+1,0);
  reverse(ALL(p));
  rep(i,n){
      b[p[i]]=sum-a[p[i]];
      --sum;
  }
  rep1(i,n){
      cout<<a[i]<<" ";
  }
  cout<<endl;
  rep1(i,n){
      cout<<b[i]<<" ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
ld a, b, x;
 
int main() {
    cin >> a >> b >> x;
    ld s = x/a;
    ld ang = 0.;
    if(s > (a*b/2.0)){
        ang = atan(2 * (a * b - s) / (a * a));
    }else{
        ang = atan(b * b / (2.0 * s) );
    }
    cout << setprecision(10) << ang*180.0/M_PI << endl;
}

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

int calc(int y, int m, int d){
    int ret = (y-1)/3 * 200 + (y-1 - (y-1)/3) * 195;
    if(y % 3 == 0)  ret += 20*(m-1);
    else            for(int i = 1; i < m; i++)  ret += 19 + (i%2 == 1);
    ret += d;
    return ret;
}

int main(){
    int n, y, m, d;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> y >> m >> d;
        cout << calc(1000,1,1) - calc(y,m,d) << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include<cstdio>
#include <map>
#include <iostream>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define f first
#define s second
#define mp make_pair

using namespace std;

int G[510][510];
bool f[510];

int main(){
  int n, mm;
  while(cin >> n >> mm && n + mm){
    string s, p, g;
    map<string, int> m;
    cin >> s >> p >> g;

    REP(i,n) REP(j,n) G[i][j] = -1;
    REP(i,mm){
      string a, b;
      int d, t;
      int aa, bb;
      cin >> a >> b >> d >> t;
      
      if(m.count(a) == 0) m[a] = m.size() - 1;
      aa = m[a];
      if(m.count(b) == 0) m[b] = m.size() - 1;
      bb = m[b];

      G[aa][bb] = G[bb][aa] = d / 40 + t;
    }
    
    int ans = 0;
    REP(kk,2){
      int start, end;
      if(kk == 0){
	start = m[s];
	end   = m[p];
      }else{
	start = m[p];
	end   = m[g];
      }

      priority_queue<pair<int, int>,
		     vector<pair<int, int> >,
		     greater<pair<int, int> > > pq;

      REP(i,n) f[i] = false;
      pq.push(mp(0, start));
      while(pq.size()){
	pair<int, int> pp = pq.top(); pq.pop();
	int tm  = pp.f;
	int pos = pp.s;

	if(f[pos]) continue;
	f[pos] = true;

	if(pos == end){
	  ans += tm;
	  break;
	}

	REP(i,n) if(G[pos][i] != -1){
	  if(!f[i]) pq.push(mp(tm + G[pos][i], i));
	}
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int n;
    ll a, b, s = 0;
    scanf("%d", &n);
    map<ll, ll> m;
    for (int i = 0; i < n; ++i) {
        scanf("%lld%lld", &a, &b);
        m[b] += a;
    }
    for (auto i = m.begin(); i != m.end(); ++i) {
        s += (*i).second;
        if (s > (*i).first) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(ALL(v), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> void chmax(T& x, const T y) { if (x < y) x = y; }
template<typename T> void chmin(T& x, const T y) { if (x > y) x = y; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
using T = pair<ll, P>;
const ll M = 1000000007;
signed main() {
  ll n;
  cin>>n;
  vector<ll> C(n);
  cin>>C;
  sort(C.rbegin(),C.rend());
  ll ans=0;
  vector<ll> fact(n+1);
  fact[0]=1;
  FOR(i,1,n+1)fact[i]=fact[i-1]*i%M;
  auto comb=[&](ll c,ll r){return fact[c]*inv(fact[c-r],M)%M*inv(fact[r],M)%M;};
  REP(i,n){
    // ll tmp=0;
    // REP(k,i+1){
    //   tmp+=(k+1)*comb(i,k)%M;
    //   tmp%=M;
    // }
    ll tmp=i==0?1:(i+2)*pow(2ll,i-1,M)%M;
    LOG(tmp);
    ans+=C[i]*tmp%M*pow(2ll,n-1-i,M)%M*pow(2ll,n,M)%M;
    ans%=M;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void dfs(int u) {
  V[u] = true;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!V[v]) dfs(v);
  }
  out.push_front(u);
}

void bfs(int u) {
  queue<int> q;
  q.push(u);
  V[u] = true;
  while (!q.empty()) {
    int u = q.front(); q.pop();
    out.push_back(u);
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      indeg[v]--;
      if (indeg[v] == 0 && !V[v]) {
        V[v] = true;
        q.push(v);
      }
    }
  }
}

void tsort_dfs() {
  for (int i = 0; i < N; i++) {
    if (!V[i]) dfs(i);
  }
}

void tsort() {
  for (int i = 0; i < N; i++) {
    indeg[i] = 0;
  }
  for (int u = 0; u < N; u++) {
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      indeg[v]++;
    }
  }

  for (int u = 0; u < N; u++) {
    if (indeg[u] == 0 && !V[u]) bfs(u);
  }

}

void print() {
  for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
    cout << *it << endl;
  }
}

int main() {
  int s, t, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    V[i] = false;
  }
  for (int i = 0; i < M; i++) {
    cin >> s >> t;
    G[s].push_back(t);
  }
  //tsort();
  tsort_dfs();
  print();
  return 0;
}



Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    cout << "No" << endl;
  } else if (A != B && A != C && B != C) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	ll dp[n+2] = {};
	ll zo[n+2] = {};
	int k; cin >> k;
	ll l[k], r[k];
	REP(i, k) cin >> l[i] >> r[i];
	dp[1] = 1;
	REP1(i, n){
		zo[i] += zo[i-1];
		zo[i] += MODB;
		zo[i] %= MODB;
		dp[i] += zo[i];
		dp[i] %= MODB;
		//cout << dp[i] << " ";
		REP(j, k){
			if(i+l[j] <= n){
				zo[i + l[j]] += dp[i];
				zo[i + l[j]] %= MODB;
			}

			if(i+r[j]+ 1<= n){
				zo[i + r[j]+1] -= dp[i];
				zo[i + r[j]+1] %= MODB;
			}
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 6752
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, k: usize);
    let s = it.next().unwrap();
    if s.len() <= k {
        println!("{}", s);
    } else {
        println!("{}...", &s[..k]);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2168
#include <stdio.h>

struct road{
  int from;
  int to;
  int distance;
};

int min(int p, int q)
{
  if(p<q) return p;
  else return q;
}

int main(void)
{
  int n;
  int a, b, c;
  struct road roads[45];
  int city_size;
  int max_distance;
  int d[10][10][11];
  int min_amount, amount;
  int min_city;
  int i, j, k;

  while(1){
    scanf("%d", &n);
    if(n==0) break;

    city_size=0;
    max_distance=0;
    for(i=0; i<n; i++){
      scanf("%d %d %d", &a, &b, &c);
      roads[i].from=a;
      roads[i].to=b;
      roads[i].distance=c;
      if(a<b && b>=city_size) city_size=b+1;
      else if(a>b && a>=city_size) city_size=a+1;
      if(max_distance<c) max_distance=c;
    }

    for(k=0; k<city_size+1; k++){
      for(i=0; i<city_size; i++){
	for(j=0; j<city_size; j++){
	  d[i][j][k]=max_distance*n+1;
	}
      }
    }
    for(i=0; i<n; i++){
      d[roads[i].from][roads[i].to][0]=roads[i].distance;
      d[roads[i].to][roads[i].from][0]=roads[i].distance;
    }
    //d[i][j][k]はk-1番目までの町のいずれかを経由してiからjへ
    //移動するときの最短距離。d[i][j][0]はどの町も経由しない
    //（iからjに直接向かう）ときの距離。
    for(k=1; k<city_size+1; k++){
      for(i=0; i<city_size; i++){
	for(j=0; j<city_size; j++){
	  d[i][j][k]=min(d[i][j][k-1], d[i][k-1][k-1]+d[k-1][j][k-1]);
	}
      }
    }

    min_amount=city_size*(max_distance*n+1);
    for(i=0; i<city_size; i++){
      amount=0;
      for(j=0; j<city_size; j++){
	if(i==j) continue;
	amount+=d[i][j][city_size];
      }
      if(min_amount>amount){
	min_amount=amount;
	min_city=i;
      }
    }
    printf("%d %d\n", min_city, min_amount);
  }
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> my;
//(x+y) (ax+by) x y
typedef pair<my,my> mypair;
#define inf 50001
int main(){
	while(1){
	ll a,b,d;
	cin>>a>>b>>d;
	if(a==0)break;
	mypair ans = mypair(my(inf,(a+b)*inf),my(0,0));
	for(int i=0;i<inf;i++){
		for(int j=0;j<inf&&ans.first.first>=i+j&&ans.first.second>=a*i+b*j;j++){
		if(a*i+b*j==d||a*i==b*j+d||b*j==a*i+d)ans=min(ans,mypair(my(i+j,a*i+b*j),my(i,j)));
		}
	}
	cout<<ans.second.first<<' '<<ans.second.second<<endl;

	}
	return 0;

}



Measured memory_bytes: 3060