akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string s,ans="YES";
    cin >> s;
    reverse(s.begin(),s.end());
    for(int i = 0;i < s.size();){
        if(s.substr(i,5)=="maerd" || s.substr(i,5)=="esare"){
            i += 5;
            continue;
        }
        if(s.substr(i,7)=="remaerd"){
            i += 7;
            continue;
        }
        if(s.substr(i,6)=="resare"){
            i += 6;
            continue;
        }
        ans = "NO";
        break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
package main
import (
  "fmt"
)

func max(a, b int) int {
  if a < b {
    return b
  }
  return a
}

func main() {
  var a, b int
  fmt.Scan(&a, &b)
  sum := a+b
  dif := a-b
  num := max(sum, dif)
  prod := a*b
  result := max(num, prod)
  fmt.Println(result)
  
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

map<pair<string, string>, ll> GetMap(string s, bool rightHalf) {
  map<pair<string, string>, ll> result;
  int n = s.size();
  for (int mask = 0; mask < (1 << n); ++mask) {
    string s0, s1;
    for (int i = 0; i < n; ++i) if (!(mask & (1 << i))) s0 += s[i];
    for (int i = n - 1; i >= 0; --i) if (mask & (1 << i)) s1 += s[i];
    if (rightHalf) swap(s0, s1);
    result[make_pair(s0, s1)]++;
  }
  return result;
}

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<pair<string, string>, ll> left, right;
  left = GetMap(s.substr(0, n), false);
  right = GetMap(s.substr(n, n), true);
  ll result = 0;
  for (auto p : left) {
    if (p.second * right[p.first] > 0) {
      //cout << p.first.first << "," << p.first.second << " " << p.second * right[p.first] << endl;
    }
    result += p.second * right[p.first];
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 108288
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<vector<pair<int, int>>> edge(N);
	vector<int> color(N);
	queue<pair<int, int>> q;
	for (auto i = 0; i < N - 1; ++i)
	{
		int u, v;
		long long w;
		cin >> u >> v >> w;
		--u;
		--v;
		edge[u].push_back(make_pair(v, w % 2));
		edge[v].push_back(make_pair(u, w % 2));
	}

	q.push(make_pair(0, 0));
	while (!q.empty())
	{
		auto p = q.front();
		q.pop();
		auto u = p.first;
		if (color[u] != 0)
		{
			continue;
		}

		if (p.second % 2 == 0)
		{
			color[u] = 1;
		}
		else
		{
			color[u] = 2;
		}

		auto& list = edge[u];
		for(auto e : list)
		{
			if (color[e.first] == 0)
			{
				q.push(make_pair(e.first, p.second + e.second));
			}
		}
	}

	for (auto i = 0; i < N; ++i)
	{
		if (color[i] <= 1)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << 1 << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 6784
n = int(input())

words = [input() for i in range(n)] 

def checkRule(words):
  if len(words) != len(set(words)):
    print("No")
    return

  tail= words[0][0]
  for w in  words:
    if w[0] != tail:
      print("No")
      return
    else:
      tail = w[-1]

  print("Yes")

checkRule(words)

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

int main () { 
    string x;
    cin >> x;
    int a,b,c,d;
    a = x[0] - '0';
    b = x[1] - '0';
    c = x[2] - '0';
    d = x[3] - '0';
    int n = 3;
    int array[3] = {b,c,d};
   
    for(int bits = 0; bits < (1 << n); ++bits) {
        int sum = a;
        char op[n] = {'-','-','-'};
       
        for(int i = 0; i < n ; ++i) {
            if(bits & (1 << i)) {
                // bitsのiビット目に1が立っている
                sum += array[i];
                op[i] = '+';
            }
            else {
                sum -= array[i];
            }
        }
    
        if(sum == 7) {
            cout << a;
            for(int i = 0; i < n ; ++i) {
                cout << op[i] << array[i];
            }          
            cout << "=7"; 
            exit(0);
        }
    }
    
}

Measured memory_bytes: 256
/*s1190073  Rina Sato
  File name: prog5b.c
  This is a Merge Sort program.*/

#include <stdio.h>
#define SENTINEL 1000000003

int Merge(int S[],int left,int mid,int right){
  int n1,n2,i,j,k,count=0; 
  int L[500000],R[500000];

  n1 = mid - left;
  n2 = right - mid;
  
  for(i = 0 ; i < n1 ; i++){
    L[i] = S[left+i];
  }
  for(j = 0 ; j < n2 ; j++){
    R[j] = S[mid+j];
  }
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  
  i = 0;
  j = 0;
  
  for(k = left ; k < right ; k++){
    if(L[i] <= R[j]){	
      S[k] = L[i];
      i++;
    }
    else {
      S[k] = R[j];
      j++;
    }
    count++;
  }
  return count;
}

int MergeSort(int S[],int left,int right){
  int mid=0,count=0;
  int count1=0,count2=0,count3=0;
  if(left+1 < right){
    mid = (left+right)/2;
    
    count1 = MergeSort(S,left,mid);
    count2 = MergeSort(S,mid,right);
    count3 = Merge(S,left,mid,right);
  }
  count = count1+count2+count3;
  return count;
}
int main(void){
  int n,S[500000],i,count=0;
  int left,right,mid;
  
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
 
  count = MergeSort(S,0,n);

  for(i = 0 ; i < n ; i++){
    printf("%d",S[i]);
    if(i <= n-2){
      printf(" ");
    }
  }
  
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 4328
// ※※※ 解答不能 ※※※
// 以下のソースを勉強する.
// E869120氏.
// https://atcoder.jp/contests/jsc2019-qual/submissions/7107452
#include <bits/stdc++.h>
using namespace std;
#pragma warning (disable: 4996)
using LL = long long;

LL mod = 1000000007;
LL N, K, A[100009], B1, B2;

int main(){
    
    scanf("%lld %lld", &N, &K);
    for(int i = 0; i < N; i++) scanf("%d", &A[i]);
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            if(A[i] > A[j]) B1++;
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(A[i] > A[j]) B2++;
        }
    }
    LL C1 = K;
    LL C2 = K * (K - 1) / 2LL;
    C2 %= mod;
    printf("%lld\n", (B1 * C1 + B2 * C2) % mod);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;

int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int sum=1, maxsugar=0;

  for(int i=0; i*a*100<=f; i++){
    for(int j=0; j*b*100+i*a*100<=f; j++){
      for(int k=0; k*c+j*b*100+i*a*100<=f; k++){
        for(int l=0; l*d+k*c+j*b*100+i*a*100<=f; l++){
          int sugar=k*c+l*d;
          int wat=(i*a+j*b)*100;
          if(wat!=0 && 1.0*100*sugar/wat<=e && 1.0*sugar/(sugar+wat)>=1.0*maxsugar/sum){
            sum=wat+sugar;
            maxsugar=sugar;
          }
        }
      }
    }
  }

  cout << sum <<' '<< maxsugar << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  bool ok = true, ok1 = true, ok2 = true;
  rep(i, n/2) if (s[i] != s[n-1-i]) ok = false;
  rep(i, (n-1)/4) if (s[i] != s[(n-1)/2-1-i]) ok1 = false;
  for (int i = (n+3)/2-1; i < n/2; i++){
    if (s[i] != s[n-1-i]) ok = false;
  }
  if (ok && ok1 && ok2) cout << "Yes\n";
  else cout << "No\n";
}


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

struct Team {
  int score, id;
  string name;
  bool operator < (const Team &t) const {
    if(score != t.score) return score > t.score;
    return id < t.id;
  }
};

int n;
Team t[10];

int main() {
  while(cin >> n && n) {
    for(int i = 0; i < n; ++i) {
      int a, b, c;
      cin >> t[i].name >> a >> b >> c;
      t[i].score = a*3 + c;
      t[i].id = i;
    }
    sort(t, t+n);
    static int tc = 0;
    if(tc++) cout << endl;
    for(int i = 0; i < n; ++i) {
      cout << t[i].name << "," << t[i].score << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector


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

int H, A; cin >> H >> A;

cout << (H + A -1) / A << "\n";

}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize ("-O3")

using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long double PI = 3.14159265358979323846;

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    multiset<int> ms;
    for (int i = 0; i < (1<<n); i ++)
    {
        int a;
        cin >> a;
        ms.insert(a);
    }
    bool np = false;
    vector<int> res;
    res.push_back(*ms.rbegin());
    ms.erase(ms.find(*ms.rbegin()));
    while(!ms.empty())
    {
      if (np)
        break;
        vector<int> nv;
        for (int x: res)
        {
            auto it = ms.lower_bound(x);
            if (it == ms.begin())
            {
                np = true;
                break;
            }
            else
            {
                -- it;
                nv.push_back(*it);
                ms.erase(it);
            }
        }
        for (int x: nv)
            res.push_back(x);
    }
    if (np)
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 16828
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 200005
#define INF 0x3f3f3f3f
int a[MAXN+5],b[MAXN+5];
int main(){
	LL sum=0;
	int n=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),b[i]=read(),sum+=a[i];
	bool f=0;
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i]){
			f=1;
			break;
		}
	if(!f){
		puts("0");
		return 0;
	}
	int tmp=INF;
	for(int i=1;i<=n;i++)
		if(a[i]>b[i])
			tmp=min(tmp,b[i]);
	printf("%lld\n",sum-tmp);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long j,n,m,k,q;
long long ans = 0;
long long point[50], a[50], b[50], c[50];
vector<long long> row(10, 0);

void search(long long size){
    long long i;
    if(size == n+1){
        long long tmp = 0;
        for(i = 0; i < q; i++){
            if(row[b[i]]-row[a[i]]==c[i]) tmp += point[i];
        }
        if(tmp > ans) ans = tmp;
        return;
    }
    for(i = row[size-1]; i <= m; i++){
        row[size] = i;
        search(size+1);
    }
}

int main(){
    long long i;
    cin >> n >> m >> q;
    for(i = 0; i < q; i++){
        cin >> a[i] >> b[i] >> c[i] >> point[i];
    }
    row.resize(n+1);
    row[0] = 1;
    search(1);
    cout << ans << endl;
}

Measured memory_bytes: 3640
package main

import (
        "fmt"
)

// https://www.youtube.com/watch?v=Ra0y0EZ24ZM&t=460s
// https://atcoder.jp/contests/abc164/submissions/12362793
func solution(s string) int {
        l := len(s)
        sum_of_digits := 0
        cnts := make([]int, 2019)
        cnts[0] = 1

        d := 1
        for i := l - 1; i >= 0; i-- {
                sum_of_digits += (int(s[i]) - 48) * d
                sum_of_digits %= 2019
                d *= 10
                d %= 2019
                cnts[sum_of_digits] += 1
        }

        ans := 0
        for _, cnt := range cnts {
                ans += cnt * (cnt - 1) / 2
        }
        return ans
}

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,m,a[100][100]={{}},b[100]={};
  cin >> n >> m;
  for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
          cin >> a[i][j];
      }
  }
  for(int i=0; i<m; i++) {
      cin >> b[i];
  }
  for(int i=0; i<n; i++) {
      int c=0;
      for(int j=0; j<m; j++) {
          c+=a[i][j]*b[j];
      }
      cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 3144
#include<iostream>

int main()
{
    int inputNum = 0;
    
    std::cin >> inputNum;
    
    int resultNum = inputNum;
    
    for (int i = 0; i < 2; i++)
    {
        resultNum *= inputNum;
    }
    
    std::cout << resultNum << std::endl;
    
    return 0;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    string s;cin>>s;
    map<char,int> m;
    rep(i,s.size())m[s[i]]++;
    for(auto i = m.begin();i!=m.end();i++){
        if(i->second>1){co("no");return 0;}
    }
    co("yes");
}

Measured memory_bytes: 256
#ATCoder

s= input()
slist= list(s)
alist= []

def fun1(i):
    target= slist[i]
    if i==len(s)-1:
        if slist[i]=='A' or slist[i]=='C' or slist[i]=='G' or slist[i]=='T':
            return 1
        else:
            return 0
    elif slist[i]=='A' or slist[i]=='C' or slist[i]=='G' or slist[i]=='T':
        return fun1(i+1)+1
    else:
        return 0

for i in range(len(slist)):
    alist.append(fun1(i))

print(max(alist))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
vector<bool>prime_table(int n){
  vector<bool>prime(n + 1,true);
  if(n >= 0)prime[0] = false;
  if(n >= 1)prime[1] = false;
  for(int i = 2; i * i <= n; i++){
    if(!prime[i])continue;
    for(int j = i + i; j <= n; j += i){
      prime[j] = false;
    }
  }
  return prime;
}
int main(){
  int n = 1;
  auto v = prime_table(10000000);
  vector<int>cnt;
  REP(i,13,10000001){
    if(v[i] && v[i - 2] && v[i - 6] && v[i - 8])cnt.push_back(i);
  }
  while(1){
    int n;
    cin >> n;
    if(n == 0)return 0;
    if(cnt[lower_bound(all(cnt),n) - cnt.begin()] == n){
      cout << n << endl;
    }
    else{
      cout << cnt[lower_bound(all(cnt),n) - cnt.begin() - 1] << endl; 
    }
  }
  return 0;
}



Measured memory_bytes: 3948
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e5;
LL a[N+1];
LL bck[N+1];
LL f[N+1];
LL solve(LL a[], int n)
{
	if(a[0] > 0) //and depth >= 1
		return (a[0]==1 && n==0) ? 1 : -1;
	bck[n] = a[n];
	for(int i = n-1; i >= 0; i--)
		bck[i] = bck[i+1]+a[i];

	f[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		f[i] = min(2LL*(f[i-1]-a[i-1]),bck[i]);
		if(f[i] < a[i])
			return -1;
	}

	LL ans = 0;
	for(int i = 0; i <= n; i++)
		ans += f[i];
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n; cin >> n;
	for(int i = 0; i <= n; i++)
		cin >> a[i];
	cout<<solve(a,n)<<endl;

	cout<<flush;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vi a(m);
  re(i, m) cin >> a[i];

  int s = 0, t = 0;
  re(i, n) {
    re(j, m) {
      if(i == a[j]) {
        if(i < x) s++;
        else t++;
      }
    }
  }
  cout << min(s, t) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    ll h, w;
    cin >> h >> w;

    if ( h == 1 || w == 1 ) cout << 1 << endl;
    else cout << (h * w + 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,x=100;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(1000000){
		x+=x/100;
		if(x>=n){
			print1(i+1);
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  auto f = [&](int a, int b) {
    vector<string> T = S;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        T[i][j] = S[(i + a) % N][(j + b) % N];
      }
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (T[i][j] != T[j][i]) return false;
      }
    }
    return true;
  };
  int res = 0;
  for (int b = 0; b < N; b++) {
    if (f(0, b)) res += N;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define F first
#define S second 
#define pb(n) push_back(n)
const int N=1e5+6;
const ll M=1e9+7;
ll dp[N],a[N],n,k;
void  rec(ll i)
{
	// printf("i= %d\n",i);
	if(dp[i]!=-1)
	{
		// printf("reached here1\n");
		return ;
	}
	
	if(i>=n-1)
	{
		dp[i]=0;
		// printf("reached here2 %d %d\n",i,n-1);
		return ;
	}
	ll ans=1e18,pos=-1;
	for(ll j=i+1;j<=min(i+k,n-1);j++)
	{
		rec(j);
		ll val=abs(a[i]-a[j])+dp[j];
		if(val<ans)
		{
			ans=val;
			pos=j;
		}
	}
	// printf("for i= %d and n= %lld ans 1 = %lld ans2 = %lld\n",i,n,ans1,ans2);	
	// if(i==0)
	// 	printf("pos = %lld\n",pos);
	dp[i]=ans;
}
int main()
{
	lscn(n);lscn(k);
	for(int i=0;i<n;i++)
		lscn(a[i]);
	
	memset(dp,-1,sizeof(dp));
	
	rec(0ll);
	// for(int i=0;i<n;i++)
	// 	printf("%lld ",dp[i]);
	lpri(dp[0]);
}

Measured memory_bytes: 4864
#include<stdio.h>
int main()
{
  int n,k,s=1,i;
  scanf("%d%d",&n,&k);
  for(i=1;i<=n;i++)
     if(2*s<s+k) s=2*s;
      else       s=s+k;
    printf("%d\n",s);
   
   return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        char[] inputs = line.toCharArray();
        
        int red = 0, yellow = 0;
        for(char c : inputs) {
            if(c == '0') red++;
            else yellow++;
        }
        int ans = Math.min(red, yellow)*2;

		System.out.println(ans);
	}
}


Measured memory_bytes: 27852
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int answer = 0;

		while (true) {
			if (N <= (2 * D + 1) * answer) break;
			answer++;
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
	string str;
	std::cin >> str;
	for (size_t i = 0; i < str.size()-1; i++) {
		if (str[i] == 'A' && str[i+1] == 'C') {
			std::cout << "Yes" << '\n';
			return 0;
		}
	}
	std::cout << "No" << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

const ll MX=100000;



int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> dp(MX,0),nx(MX,0);
    vector<ll> _dp(MX,0),_nx(MX,0);
    dp[1]=1;
    const ll LS=MX-1;
    for(ll i=0;i<=k;i++){
        for(ll j=1;j<MX;j++){
            nx[min(n/j,LS)]+=dp[j];
            nx[min(n/j,LS)]%=MOD;
            nx[j]+=_dp[j]*max(0LL,n/j-max(LS,n/(j+1)))%MOD;
            nx[j]%=MOD;
            if(n/j>LS){
                _nx[j]+=dp[j];
                _nx[j]%=MOD;
            }
        }
        swap(dp,nx);
        swap(_dp,_nx);
        cset(_nx,0LL);
        cset(nx,0LL);
        for(ll j=LS;j>0;j--){dp[j]%=MOD; dp[j-1]+=dp[j];}
        _dp[1]%=MOD;
        for(ll j=2;j<LS;j++){_dp[j]+=_dp[j-1]; _dp[j]%=MOD;}
    }
    cout<<dp[1]<<endl;
    
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main(){

	int a, b, n;
	int ans = 0;

	cin >> n >> a >> b;

	for(int j=1; j<=n; j++){
		
		int i = j;

		int k1 = i % 10;
		i = i / 10;
		k1 = k1 + i % 10;
		i = i / 10;
		k1 = k1 + i % 10;
		i = i / 10;
		k1 = k1 + i % 10;
		i = i / 10;
		k1 = k1 + i % 10;

		if(k1 >= a && k1 <= b)
			ans += j;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int a = stdin.nextInt();
        int b = stdin.nextInt();
        long ans = IntStream.rangeClosed(a, b).filter(Main::isPalindromic).count();
        System.out.println(ans);
    }
    
    public static boolean isPalindromic(int x) {
        List<Integer> digits = new ArrayList<>();
        while (x > 0) {
            digits.add(x % 10);
            x /= 10;
        }
        
        int len = digits.size();
        return IntStream.range(0, len).allMatch(i -> digits.get(i).equals(digits.get(len - i - 1)));
    }
}

Measured memory_bytes: 42768
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int a, b;
	cin >> a >> b;
	if (a <= 9 && b <= 9) {
		cout << a * b << '\n';
	} else {
		cout << -1 << '\n';
	}
 	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

using namespace std;

int main()
{
	int_least32_t n, m;
	cin >> n >> m;

	vector<int_least64_t> x(n);
	for(auto& e : x) {
		cin >> e;
	}

	vector<int_least64_t> y(m);
	for(auto& e : y) {
		cin >> e;
	}

	int_fast64_t sum_x{ 0 };
	for(auto i = 0; i < x.size(); ++i) {
		sum_x += (i * x[i] - (n - i - 1) * x[i]);
	}

	int_fast64_t sum_y{ 0 };
	for(auto i = 0; i < y.size(); ++i) {
		sum_y += (i * y[i] - (m - i - 1) * y[i]);
	}

	sum_x %= 1'000'000'000 + 7;
	sum_y %= 1'000'000'000 + 7;

	cout << (sum_x * sum_y) % (1'000'000'000 + 7) << endl;
}


Measured memory_bytes: 1792
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($L,$R,$d) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
$res=0;
for($i=$L;$i<=$R;$i++) {
  if ($i % $d == 0) {
    $res++;
  }
}
printf("%d\n",$res);


Measured memory_bytes: 15988
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ill long long int
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  ill a, c;
  cin >> a >> c;
  int b = 2 * c - a;
  cout << b << "\n";
}
  

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N),F(N);
    for(int i=0; i < N; i++) cin >> A[i];
    for(int i=0; i < N; i++) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<ll>());

    ll l = -1;
    ll r = 1e12;

    while(r > l+1){
        ll m = (r+l)/2;
        ll cnt = 0;
        for(int i = 0; i < N; i++){
            ll B = m/F[i];
            cnt += max(0LL, A[i]-B);
        }
        if(cnt <= K) r = m;
        else l = m;
    }
    cout << r << endl;

    
}

Measured memory_bytes: 3328
// By Atul Rathore

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

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007


int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;
	int n, m;
	cin >> n >> m;
	int height[n];
	f(n)cin >> height[i];
	int a[n] = {};
	while (m--)
	{
		int x, y;
		cin >> x >> y;
		if (height[x - 1] > height[y - 1])a[y - 1] = 1;
		else if (height[x - 1] < height[y - 1])a[x - 1] = 1;
		else
		{
			a[y - 1] = 1;
			a[x - 1] = 1;
		}
	}
	int ans = 0;
	f(n)
	{
		if (a[i] == 0)ans++;

	}
	cout << ans;







}


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

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> map(H);
  vector<string> tsp(W, "");
  
  // template for all dots.
  string dots = ".";
  for (int i=1; i < W; i++)
    dots += '.';
  // transposed template.
  string tspdots = ".";
  for (int i=1; i < H; i++)
    tspdots += '.';

  for (int i=0; i < H; i++) {
    cin >> map.at(i);
    for (int j=0; j < W; j++) {
      tsp.at(j) += map.at(i).at(j);
    }
  }
  
  vector<int> remain_row;
  vector<int> remain_col;
  for (int i=0; i < H; i++) {
    if (map.at(i) == dots)
      continue;
    remain_row.push_back(i);
  }
  
  for (int i=0; i < W; i++) {
    if (tsp.at(i) == tspdots)
      continue;
    remain_col.push_back(i);
  }
  
  for (int i : remain_row) {
    for (int j : remain_col) {
      cout << map.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
	int a, b, soma, sub, mul, maior=0;
	scanf("%d %d\n", &a, &b);
	soma = a + b;
	sub = a - b;
	mul = a * b;
	if (soma > sub && soma > mul)
	{
		maior = soma;
	}else if (sub > mul)
	{
		maior = sub;
	}else
		maior = mul;
	/*if (maior < sub)
	{
		maior = sub;
	}
	if (maior < mul)
	{
		maior = mul;
	}*/
	printf("%d\n", maior);
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
        int N,D,X;

        scanf("%d %d %d", &N, &D, &X);

        for(int i=0; i<N; i++) {
                int A;
                scanf("%d", &A);
                X += ((D - 1) / A)+1;
        }

        printf("%d", X);
}

Measured memory_bytes: 128
#include <iostream>
#define rep(i, n) for (i = 1; i <= n; i++)
using namespace std;

const int N = 110;

int x[N];

int main() {
	int n, i, j;
	cin >> n;
	rep(i, n) cin >> x[i];
	
	int res = 1e+18;
	for (i = 1; i <= 100; i++) {
		int cst = 0;
		rep(j, n) {
			cst += (i - x[j]) * (i - x[j]);
		}
		res = min(res, cst);
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,n,k[102],l[102],x=0;
    cin>>a>>b>>n;
    for(int i=1;i<=n;i++){
       cin>>k[i]>>l[i];
       if(b<=k[i]||l[i]<=a){
          x=0;
       }
       else{
          x=1;
          break;
       }
    }
    cout<<x<<endl;
    return 0;
}


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

int main(){
  	int h,w,cnt;
  	cin >> h >> w;
  	char cells[h][w];
  	int numbers[h][w];
  	
  	rep(i,0,h){
      rep(j,0,w){
       	cin >> cells[i][j]; 
      }
    }
  
  	rep(i,0,h){
      rep(j,0,w){
        cnt = 0;
        if(cells[i][j] == '.'){
          	if(i > 0 && j > 0 && cells[i-1][j-1] == '#'){
          		cnt++;
          	}
        	if(i > 0 && cells[i-1][j] == '#'){
          		cnt++;
        	}
        	if(i > 0 && j < w-1 && cells[i-1][j+1] == '#'){
          		cnt++;
        	}
        	if(j > 0 && cells[i][j-1] == '#'){
          		cnt++;
        	}
        	if(j < w-1 && cells[i][j+1] == '#'){
          		cnt++;
        	}
        	if(i < h-1 && j > 0 && cells[i+1][j-1] == '#'){
          		cnt++;
          	}
        	if(i < h-1 && cells[i+1][j] == '#'){
          		cnt++;
        	}
        	if(i < h-1 && j < w-1 && cells[i+1][j+1] == '#'){
          		cnt++;
        	}
          
			cells[i][j] = (char)(cnt + 48);
        }
      }
    }
  
  	rep(i,0,h){
      rep(j,0,w){
       	cout << cells[i][j]; 
      }
      cout << endl;
    }
  	
  	return 0;
}

Measured memory_bytes: 256
import math

def comb(n, r, mod):
    return math.factorial(n + r - 1)//(math.factorial(n - 1)*math.factorial(r))%mod

n, k = map(int, input().split())
mod = 10**9 + 7
red = n - k

for i in range(k):
    ans = 0
    redmod = red - i
    if redmod < 0:
        print(0)
        continue
    redplace = 2 + i
    bluemod = k - (i + 1)
    if i == 0:
        bluemod = 0
    blueplace = i + 1
    ans += comb(redplace, redmod, mod)*comb(blueplace, bluemod, mod)
    print(ans%mod)

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

using namespace std;

long long a, b;

inline bool can_do(long long m)
{
    long long create_s = max(0ll, (m - a));
    long long ost_c = b - 2 * create_s;
    if (ost_c >= 2 * m) {
        return true;
    } else {
        return false;
    }
}


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

    cin >> a >> b;

    long long l = 0;
    long long r = a + b + 1;
    while (l < r - 1) {
        long long m = l + (r - l) /2;

        if (can_do(m)) {
            l = m;
        } else {
            r = m;
        }
    }

    cout << l << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
#include <sstream> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;





int main()
{
    unsigned int n;

    cin >> n;
    vector<unsigned int> a(n);

    rep(i, n) {
        cin >> a[i];
    }

    unsigned int sum = 0;
    rep(i, n) {
        sum = (sum ^ a[i]);
     
    }

    unsigned int ans;
    rep(i, n) {
        ans = (sum ^ a[i]);

        cout << ans << " ";
    }
}




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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n+1);
  vector<int> b(n);
  
  REP(i,n+1) cin >> a[i];
  REP(i,n) cin >> b[i];
  
  ll ans = 0;
  REP(i,n){
    if(b[i] >= a[i]){
      b[i] -= a[i];
      ans += a[i];
      if(b[i] <= a[i+1]){
        ans += b[i];
        a[i+1] -= b[i];
      }
      else{
        ans += a[i+1];
        a[i+1] = 0;
      }
    }
    else{
      ans += b[i];
    }
  }
  
  cout << ans << endl;
      
        
      
  
  
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
int n;
const int INF = numeric_limits<int>::max();
int activity[100005][3];
int dp[100005][3];

int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		for(int j=0; j<3; j++) cin>>activity[i][j];
	}
	//dp[i][j] = i번째 날에 j활동으로 끝낼 때 최대 행복
	dp[1][0] = activity[1][0];
	dp[1][1] = activity[1][1];
	dp[1][2] = activity[1][2];
	for(int i=1; i<=n; i++){
		for(int j=0; j<3; j++){
			for(int k=0; k<3; k++){
				if(j!=k) dp[i+1][k] = max(dp[i+1][k],dp[i][j]+activity[i+1][k]);
			}
		}
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2])); 
}

Measured memory_bytes: 5940
function Main(input) {
  input = input.trim()
// input = input.split("\n").map(Number);
if(input=="abc"||input=="acb"||input=="cab"||input=="cba"||input=="bac"||input=="bca"){
  console.log("Yes")
}else{
  console.log("No")
}
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
	int N, K;
	cin >> N >> K;
	int a=1;
    rep(i, N) {
        if (a < K) a *= 2;
        else a += K;
    }
    cout << a << endl;
}


Measured memory_bytes: 3600
# https://atcoder.jp/contests/agc016/tasks/agc016_a
# 真ん中らへんの文字を採用すれば結構早く同じ文字になる
# 最終的にどの文字にしたいかターゲットを絞って、操作するのを繰り返せば？(100*100*答え回の探索ですむ)
from collections import Counter
S = input()
cnt = Counter(S)
ans = 10**5
for k in cnt:
    # cnt_k = cnt[k]  # 個数管理用
    ans_k = 0
    T = list(S)
    # print(cnt_k)
    while not all([t == k for t in T]):
        ans_k += 1
        new_T = []
        for i in range(len(T) - 1):
            if T[i] == k:
                new_T.append(k)
            elif T[i + 1] == k:
                new_T.append(k)
            else:
                new_T.append(T[i])
        T = new_T
    # print(T, cnt_k)
    ans = min(ans, ans_k)
print(ans)


Measured memory_bytes: 74192
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,c[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",c+i);
    sort(c+1,c+n+1);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i==n){
            ans=Add(ans,Mul(c[i],Pow(2,i-1)));
        }
        else{
            int x=Pow(2,n-i);
            x=Add(x,Mul(n-i,Pow(2,n-i-1)));
            x=Mul(x,c[i]);
            x=Mul(x,Pow(2,i-1));
            ans=Add(ans,x);
        }
    }
    ans=Mul(ans,Pow(2,n));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
import collections
n = int(input())
v = list(map(int, input().split(' ')))
a = v[::2]
b = v[1::2]

a_count = []
b_count = []

a_count = collections.Counter(a).most_common(3)
b_count = collections.Counter(b).most_common(3)

if a_count[0][0] != b_count[0][0]:
    print(n-int(a_count[0][1])-int(b_count[0][1]))
else:
    if len(a_count)!= 1 and len(b_count)!= 1:
        print(min(n-int(a_count[0][1])-int(b_count[1][1]),n-int(a_count[1][1])-b_count[0][1]))
    elif len(a_count) == 1 and len(b_count)!=1:
        print(n-int(a_count[0][1])-int(b_count[1][1]))
    elif len(b_count)==1 and len(a_count)!= 1:
        print(n-int(a_count[1][1])-int(b_ocunt[0][1]))
    else:
        print(int(n/2))

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != 0) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}
// Combination
ll modcomb(ll n, ll r)
{
  if(n < r) return 0;
  ll res = fact(n);
  (res *= ppow(fact(r), M-2)) %= M;
  (res *= ppow(fact(n-r), M-2)) %= M;
  return res;
}

//GCD and LCM
llt gcd(llt x, llt y)
{
  if(y == 0) return x;
  return gcd(y, x%y);
}
llt lcm(llt x, llt y)
{
  return (x / gcd(x, y)) * y;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find
// Find()
int parent[N], ran[N];
int find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
// Union()
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(ran[x]<ran[y])
        parent[x]=y;
    else{
        parent[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}

// Main Code
map<ll, ll> co;

int main()
{
  vector<ll> v;
  int n;
  cin>>n;
  ll arr[n];
  rep(i, 0, n)
  {
    int a;
    cin>>a;
    arr[i] = a;
    co[a]++;
  }
  rep(i, 0, n)
  {
    if(co[arr[i]] >= 2)
    {
      v.pb(arr[i]);
      co[arr[i]] -= 2;
    }
  }
  if(v.size() < 2)
  {
    cout<<0<<endl;
    return 0;
  }
  sort(v.begin(), v.end(), greater<int>());
  cout<<(v[0]*v[1])<<endl;
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  int64_t W;
  cin >> N >> W;
  
  vector<int> weight(N), value(N);
  for (int i = 0; i < N; i++) cin >> weight.at(i) >> value.at(i);

  vector<vector<int64_t>> dp(N+1, vector<int64_t>(W+1, 0));
                               
  for (int i = 0; i < N; ++i) {
    for (int sum_w = 0; sum_w <= W; sum_w++) {

      if (sum_w - weight.at(i) >= 0) {
        dp.at(i+1).at(sum_w) = max(dp.at(i+1).at(sum_w),
                                   dp.at(i).at(sum_w - weight.at(i)) + value.at(i));
      }

       dp.at(i+1).at(sum_w) = max(dp.at(i+1).at(sum_w), dp.at(i).at(sum_w));
    }
  }

  cout << dp.at(N).at(W) << endl;
  
  return 0;
}

Measured memory_bytes: 80256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn print<T: std::fmt::Display>(x: T) -> () {
    println!("{}", x);
}

fn main() {
    let n: usize = read();
    let vs: Vec<i64> = read_vec();
    let cs: Vec<i64> = read_vec();

    let mut ans: i64 = 0;

    for i in 0..n {
        let v = vs[i];
        let c = cs[i];
        let diff = v - c;
        if diff > 0 {
            ans += diff;
        }
    }
    print(ans);
}


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

using namespace std;

const int limit = 1e6 + 2; 

int a[limit] ;

void func(){
    
    for(int i=1;i<=limit;i++) a[i]=1;
    
    for(int i=2;i<=limit;i++)
    {
        for(int j=i;j<=limit;j+=i) a[j]++ ;
    }
}

int main() {
    func() ;
    int n , total=0 ;
    cin>>n ;
    for(int i=n-1;i>=1;i--)
    {
        total += a[n-i] ;
    }
    cout<<total ;
}


Measured memory_bytes: 7532
#include <stdio.h>
char s[5];
int main()
{
    scanf("%s", &s);
    if (s[0]==s[1]&&s[1]==s[2]) puts ("Yes");
    else if (s[1]==s[2]&&s[2]==s[3]) puts ("Yes");
    else puts ("No");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int mat[60][60],used[60][60],v[60];
int cnt,t,n,m,ans;
void dfs(int src)
{
    v[src]=t;
    cnt++;
    for(int i=1; i<=n; i++)
    {
        if(mat[src][i] && v[i]!=t)
            dfs(i);
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int u,v;
        cin>>u>>v;
        mat[u][v]=1;
        mat[v][u]=1;
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(mat[i][j] && !used[i][j])
            {
                mat[i][j]=0;
                mat[j][i]=0;
                used[i][j]=1;
                used[j][i]=1;
                t++;
                cnt=0;
                dfs(1);
                mat[i][j]=1;
                mat[j][i]=1;
                if(cnt!=n)
                    ans++;
            }

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


Measured memory_bytes: 3632
a, b = map(int,input().split())
list1=[]
list2=[]
for i in range (a):
     x,y=map (int,input().split())
     list1.append(x)
     list2.append(y)
mini= 0x3f3f3f3f
for i in range (a) :
    if list1[i] < mini and list2[i] <= b :
        mini=list1[i]

if (mini!= 0x3f3f3f3f):
    print(mini)
else :
    print ("TLE")



Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int K, A[100000];

LL high(){
	LL ng = -1;
	LL ok = 100000000000002LL;
	while(ok-ng > 1){
		LL m = (ng + ok) / 2;
		LL tmp = m;
		for(int i=0; i<K; i++){
			tmp -= tmp % A[i];
		}
		if(tmp >= 2) ok = m;
		else ng = m;
	}
	LL tmp = ok;
	for(int i=0; i<K; i++){
		tmp -= tmp % A[i];
	}
	if(tmp != 2) return -1;
	else return ok;
}

LL low(){
	LL ok = -1;
	LL ng = 100000000000002LL;
	while(ng-ok > 1){
		LL m = (ng + ok) / 2;
		LL tmp = m;
		for(int i=0; i<K; i++){
			tmp -= tmp % A[i];
		}
		if(tmp <= 2) ok = m;
		else ng = m;
	}
	return ok;
}

int main(){
	cin >> K;
	for(int i=0; i<K; i++) cin >> A[i];
	
	LL a = high();
	LL b = low();
	if(a == -1) cout << -1 << endl;
	else cout << a << " " << b << endl;
	
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
 
using ll = long long;
using namespace std;
 

void solveCase() {
   int n;
   cin >> n;
   vector<int> l(2 * n);
   for(int i = 0; i < 2 * n; i++) {
      cin >> l[i];
   }
   sort(l.rbegin(), l.rend());
   int ans = 0;
   for(int i = 0; i < 2 * n; i += 2) {
      ans += min(l[i], l[i + 1]);
   }
   cout << ans << endl;
}
 
int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solveCase();
   }
 
   return 0;
}

Measured memory_bytes: 3620