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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int amax=0;
  for(int i=0;i<n;i++){
    int cnt=0;
    for(char j='a';j<='z';j++){
      bool a=false;
      bool b=false;
      for(int k=0;k<i;k++){
        if(s[k]==j){
          a=true;
        }
      }
      for(int k=i;k<n;k++){
        if(s[k]==j){
          b=true;
        }
      }
      if(a&&b){
        cnt++;
      }
    }
    amax=max(cnt,amax);
  }
  cout << amax << endl;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main() {
    char s[11];
    int l = 0,i,flag=1,c=0;
    for (i = 0; i < 11; i++)
        s[i] = '\0';
    scanf("%s", s);
    while (s[l] != '\0')
        l++;
    for (i = 0; i < l; i++) {
        if (i == 0) {
            if (s[0] != 'A')
                flag = 0;
        }
        else if (i > 1 && i < l - 1) {
            if (s[i] == 'C')
                c++;
          else if (s[i]<'a')
                flag = 0;
        }
        else {
            if (s[i]<'a')
                flag = 0;
        }
    }
    if (flag == 1 && c == 1)
        printf("AC\n");
    else
        printf("WA\n");
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n%2 == 0) {
        cout << n/2;
    } else {
        cout << (n/2)+1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
vector<vector<int>> graph;
map<char,ll> mp;
int main(){
int n;
cin>>n;
string s;
cin>>s;
int ans=0;
for(int i=0;i<n-1;i++){
    if(s.at(i)=='O'&&s.at(i+1)=='X'){ans++;i++;}
    else if(s.at(i)=='X'&&s.at(i+1)=='O'){ans++;i++;}
}
cout<<ans<<endl;
}



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

const int N=200009;
int n,a[N],b[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a+1,a+n+1);

	for(int i=1;i<=n;i++)
	{
		if(b[i]<=a[n/2])
			printf("%d\n",a[n/2+1]);
		else if(a[n/2+1]<=b[i])
			printf("%d\n",a[n/2]);
	}

	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;

long long calc(long long a){
    long long ans=1;
    for(long long i=a;i>1;i--){
        ans*=i;
        ans%=mod;
    }
    return ans;
}

int main(){
    long long a,b;cin >> a >> b;
	if(abs(a-b)>1){
		cout << 0 << endl;
		return 0;
	}
    long long ans=calc(a);
    ans*=calc(b);
    ans%=mod;
    if(abs(a-b)==1) cout << ans << endl;
    else{
        ans*=2;
        ans%=mod;
        cout << ans << endl;
    }
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
        i=0;
        j=0;
        while(i < H){
            for(j = 0; j < W; j++){
                if(i%2 == 1 && j%2 == 1){
                    cout << '#';
                }
                else if(i%2 == 1 && j%2 == 0){
                    cout << '.';
                }
                else if(i%2 == 0 && j%2 == 1){
                    cout << '.';
                }
                else{
                    cout <<'#';
                }
            }
            i++;
            cout <<endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;
int main(){
    int n,a,b;
    cin >> n >>a >>b;

    cout << min(n*a,b) <<endl;
}

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

// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384



using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

ll INF=1e18;



// prevent collisions in unordered_map
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
void read(T arr[],ll n) {rep(i,0,n) cin>> arr[i];}

typedef unordered_map <long long, long long, custom_hash> umap;


// standard functions
ll mystoi(string str)
{
    stringstream ss(str);
    ll ans=0;
    ss >> ans;

    return ans;
}

ll exp(ll x, ll ex, ll p) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%p;
        ex >>= 1ll;
        x = (x * x)%p;
    }
    return ans;
}

bool sort_cond(const pair<ll,ll> &a, const pair <ll,ll> &b)
{
    return ((a.f-a.s)>(b.f-b.s));
}

// code beigns in main
int main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
        ld a,b;
        cin >> a >>b;

        ll d=a*b;
        ll ans=d;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

int two(int x) {
    int tmp = 0;
    while (!(x&1)) {
        tmp++;
        x /= 2;
    }
    return tmp;
}

bool solve() {
    int n; cin >> n;
    int ans = 0;
    REP (i,n) {
        int x; cin >> x;
        ans += two(x);
    }
    cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var line = new int[2][];
        line[0] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        line[1] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var max = 0;
        for (var i = 0; i < num; i++)
        {
            var a = 0;
            for (var j = 0; j < num; j++)
                if (i == j) a += line[0][j] + line[1][j];
                else if (j < i) a += line[0][j];
                else a += line[1][j];
            max = Max(max, a);
        }
        WriteLine(max);
    }
}


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

int main(){
    int N;
    cin>>N;
    string s;
    int count=0;
    int max=0;
    map<string,int>str;
    for(int i=0;i<N;i++){
        cin>>s;
        if (str.count(s)){
            str[s]++;
            
            continue;
        }else{
            str[s]=1;
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 19132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int64_t>a(N+1);
  a.at(0) = 2, a.at(1) = 1;
  
  for(int i = 0; i < N-1; i++) {
    a.at(i+2) = a.at(i) + a.at(i+1);
  }
  cout << a.at(N) << endl;
  return 0;
}


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

bool comparator(string a,string b){
    if(a!=b){
        return b>a;
    }
    return b.size()>a.size();
}

int main(){
    int n,t;
    cin>>n>>t;
    vector<string> s(n);
    for(int i=0;i<n;++i){
        cin>>s[i];
    }
    string ans="";
    sort(s.begin(),s.end(),comparator);
    for(int i=0;i<n;++i){
        ans+=s[i];
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	vector<int>A(3);
	for (int i = 0; i < 3; i++)cin >> A.at(i);
	sort(A.begin(), A.end());
	cout << A.at(0) + A.at(1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    char s[1201];
    scanf("%[^\n]", s);

    for (int i = 0; s[i] != '\0'; i++)
    {
        char c = s[i];

        if (65 <= c && c <= 90)
        {
            s[i] = c + 32;
        }
        else if (97 <= c && c <= 122)
        {
            s[i] = c - 32;
        }
        
    }

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



Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    cout << ((n<1000) ? "ABC" : "ABD") << endl;
}

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

int main(){
	int n, k, x, y;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < k; ++i){
		scanf("%d%d", &x, &y);
		x = min(x - 1, n - x);
		y = min(y - 1, n - y);
		printf("%d\n", min(x, y) % 3 + 1);
	}
}

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

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

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

int main()
{
    int n;
    cin >> n;
    int sum = 0,num = INF;
    for(int i = 0; i < n; i++){
        int s;
        cin >> s;
        sum += s;
        if(s % 10 != 0) num = min(num,s);
    }
    if(sum % 10 != 0) cout << sum << endl;
    else{
        if(num != INF) cout << sum - num << endl;
        else cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner cin = new Scanner(System.in);
		String line;
		for (; cin.hasNext();) {
			line = cin.nextLine();
			String[] s = line.split(" ");
			String S = s[0]; // 文字列

			ArrayList<String> list = new ArrayList<String>();
			String[] ar = S.split("");

			for(String str : ar){
				switch(str){
				case "0":
					list.add("0");
					break;
				case "1":
					list.add("1");
					break;
				case "B":
					if(!list.isEmpty()){
						list.remove(list.size() - 1);
					}
					break;
				default:
					//何もしない
				}
			}

			String result = "";
			for(String word : list){
				result += word;
			}
			System.out.println(result);

		}
	}
}


Measured memory_bytes: 9428
dic = {'a':'b', 'b':'c', 'c':'d', 'd':'e', 'e':'f', 'f':'g', 'g':'h', 'h':'i', 'i':'j', 'j':'k', 'k':'l', 'l':'m', 'm':'n', 'n':'o', 'o':'p', 'p':'q', 'q':'r', 'r':'s', 's':'t', 't':'u', 'u':'v', 'v':'w', 'w':'x', 'x':'y', 'y':'z'}
c = input()
print(dic[c])

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

#define double ld
double p[305][305][305], e[305][305][305];

int main()
{
	#ifdef DGC
		freopen("a.txt", "r", stdin);
	#endif
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	
	vector<int> a(3);
	for (int i = 0, x; i < n; ++i)
	{
		cin >> x;
		++a[x-1];
	}

	p[a[0]][a[1]][a[2]] = 1;
	
	for (int k = n; k >= 0; --k)
		for (int j = n; j >= 0; --j)
			for (int i = n; i >= 0; --i)
				if (p[i][j][k] > 0)
				{
					double z = 1 - (double)(n-i-j-k) / n;
					double _z = 1 / z; // probability of move
					z = 1 / (z * z); // expected value of move

					if (i > 0)
					{
						e[i-1][j][k] += (e[i][j][k] * _z + p[i][j][k] * z) * i / n;
						p[i-1][j][k] += p[i][j][k] * _z * i / n;
					}
					if (j > 0)
					{
						e[i+1][j-1][k] += (e[i][j][k] * _z + p[i][j][k] * z) * j / n;
						p[i+1][j-1][k] += p[i][j][k] * _z * j / n;
					}
					if (k > 0)
					{
						e[i][j+1][k-1] += (e[i][j][k] * _z + p[i][j][k] * z) * k / n;
						p[i][j+1][k-1] += p[i][j][k] * _z * k / n;
					}
				}

	cout << setprecision(20) << fixed << e[0][0][0] << "\n";

	return 0;
}


Measured memory_bytes: 874752
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	vector<int> xy;
	for (int i = 1; i < 1111; ++i)
		for (int j = i; (ll)i*i*i + j*j*j < 1111*1111*1111; ++j)
			xy.push_back(i*i*i + j*j*j);
	sort(all(xy));

	int z;
	while (scanf("%d", &z), z)
		printf("%d\n", z*z*z - *(lower_bound(all(xy), z*z*z) - 1));
}

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

using std::ios_base;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::fixed;

using std::vector;
using std::string;
using std::stack;
using std::queue;
using std::deque;
using std::map;
using std::set;
using std::unordered_map;
using std::unordered_set;

using std::tuple;
using std::make_tuple;
using std::pair;
using std::make_pair;

using std::sort;
using std::reverse;
using std::nth_element;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

const int MAXN = 200005;
const int INF = 1e9;
const int MOD = 1e9+7;
const int64_t L_INF = 4e18;

int n;
int a[MAXN];
int64_t sump[MAXN], sums[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sump[i] = sump[i - 1] + abs(a[i] - a[i - 1]);
    }
    for (int i = n; i >= 1; i--) {
        sums[i] = sums[i + 1] + abs(a[i] - a[i + 1]);
    }

    for (int i = 1; i <= n; i++) {
        cout << sump[i - 1] + sums[i + 1] + abs(a[i - 1] - a[i + 1]) << '\n';
    }

    #ifdef LOCAL
        cerr << "\n== " << 1.0 * clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;




template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}
template <typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}
template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){d = extgcd(b,a%b,y,x); y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,mod);
    if(n&1) resp = resp*x%m;
    return resp;
}
template <typename T> T modinverse(T a, T m) {
    T x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
struct combination {
    ll M = mod;
    vector<ll> fact;vector<ll> ifact;
    combination(ll n):fact(n+1),ifact(n+1){
        fact[0]=1;ifact[0]=1;
        for (ll i = 0; i<n; i++) {fact[i+1] = fact[i]*(i+1) % M;ifact[i+1] = ifact[i]*modpow(i+1, M-2, M) % M;}
    }
    ll com(ll a, ll b){
        if(a == 0 && b == 0)return 1;if(a < b || a < 0)return 0;
        ll tmp = ifact[a-b]* ifact[b] % M;
        return tmp * fact[a] % M;
    }
};





int main()
{

    int N;
    cin >> N;
    vl C(N);in(N,C);
    ll a = modpow<ll>((ll)2,(ll)N,mod);
    
    ll b = 1;
    sort(all(C));
    ll ans = 0;
    
    rep(i,N){
        ll v = modpow<ll>(2,(ll)(N-i-1),mod)*((modpow<ll>(2,(ll)(i),mod) + ((ll)i)*modpow<ll>(2,(ll)(i-1),mod)) % mod)%mod;
        ans += v*C[N-i-1]%mod;
        ans %= mod;
    }
    ans *= a;
    ans %= mod;
    out(ans);
    
    
    

    return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b; cin >> a >> b;
	string s1 = "", s2 = "";
	for (int i = 0; i < a; i++) {
		s1 += '0' + b;
	}
	for (int i = 0; i < b; i++) {
		s2 += '0' + a;
	}
	cout << min(s1, s2) << endl;
	return 0;	
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> x(m);
    rep(i,m){
        cin >> x[i];
    }
    sort(x.begin(),x.end());
    vector<int> b(m-1);
    int64_t sum=0;
    if(m==1){
        cout << 0<<endl;
    }
    else{
        rep(i,m-1){
            b[i] =x[i+1]-x[i];
            sum += b[i];
        }
        //cout <<"sum="<<sum<<endl;
        sort(b.begin(),b.end());
        if(n>=m){
            sum=0;
        }
        else{
        rep(i,n-1){
        sum -= b[m-2-i];
        }
        }
        cout <<sum<<endl;
    }



}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main()
{
	int h, w;
	cin >> h >> w;
	int sy, sx;
	cin >> sy >> sx;
	sy += 1; sx += 1;
	int fy, fx;
	cin >> fy >> fx;
	fy += 1;
	fx += 1;
	vector<vector<char>> grid(h+4, vector<char>(w+4,'#'));
	for (int i = 2; i <= h + 1; i++) {
		for (int j = 2; j <= w + 1; j++) {
			cin >> grid[i][j];
		}
	}
	/*for (int i = 0; i <= h + 3; i++) {
		for (int j = 0; j <= w + 3; j++) {
			if (i == sy && j == sx) cout << 'S'; 
			else if (i == fy && j == fx) cout << 'F';
			else cout << grid[i][j];
		}
		cout << "\n";
	}*/
	
	vector<vector<long long>> vis(h + 4, vector<long long>(w + 4));
	queue<pair<int, int>> q;
	vector<pair<int, int>> v;
	q.push({ sy,sx });
	v.push_back({ sy,sx });
	vis[sy][sx] = 1;
	long long ans = 0;
	while (!q.empty() && vis[fy][fx] == 0) {
		auto cell = q.front();
		int y = cell.first, x = cell.second;
		q.pop();
		if (vis[y + 1][x] == 0 && grid[y + 1][x] == '.') {
			v.push_back({ y+1,x });
			q.push({ y + 1,x });
			vis[y + 1][x]++;
		}
		if (vis[y - 1][x] == 0 && grid[y - 1][x] == '.') {
			v.push_back({ y - 1,x });
			q.push({ y - 1,x });
			vis[y - 1][x]++;
		}
		if (vis[y][x + 1] == 0 && grid[y][x + 1] == '.') {
			v.push_back({ y ,x+1 });
			q.push({ y,x + 1 });
			vis[y][x + 1]++;
		}
		if (vis[y][x - 1] == 0 && grid[y][x - 1] == '.') {
			v.push_back({ y ,x-1 });
			q.push({ y,x - 1 });
			vis[y][x - 1]++;
		}
		if (q.empty() && vis[fy][fx]==0) {
			ans++;
			vector<pair<int,int>> v2;
			for (auto e : v) {
				int y = e.first, x = e.second;
				for (int i = y - 2; i <= y + 2; i++) {
					for (int j = x - 2; j <= x + 2; j++) {
						if (vis[i][j] == 0 && grid[i][j] == '.') {
							q.push({ i,j });
							v2.push_back({ i,j });
							vis[i][j]++;
						}
					}
				}
			}
			v.clear();
			v = v2;
		}
	

		
	}
	if (vis[fy][fx] == 0)cout << -1;
	else  cout << ans;
}


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

using namespace std;

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

    cin >> x;

    int h;

    h = x / 500 * 1000 + x % 500 / 5 * 5;

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

    return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    inlis = list()
    for _ in range(n):
        h = int(input())
        inlis.append(h)
    inlis.sort()
    ans = 10 ** 10
    for i in range(n-k+1):
        tmp = inlis[i+k-1] - inlis[i]
        if tmp < ans:
            ans = tmp
    print(ans)
            



if __name__ == "__main__":
    main()

Measured memory_bytes: 81124
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n,m,x,y,xmax,ymin;
    cin>>n>>m>>xmax>>ymin;
    for(int i=0;i<n;i++){
        cin>>x;
        xmax=max(xmax,x);
    }
    for(int i=0;i<m;i++){
        cin>>y;
        ymin=min(ymin,y);
    }
    if(xmax<ymin)cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}


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

int main(void){
        int N,f,e,i,j,k,cnt=0;
        int count[10][10] = {0};
        cin >> N;
        for(i=1;i<=N;i++){
                f = i/(pow(10,(int)log10(i)));
                e = i%10;
                count[f][e]++;
        }
        for(j=0;j<10;j++){
                for(k=0;k<10;k++){
                        cnt += count[j][k]*count[k][j];
                }
        }
        cout << cnt << endl;
        return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main (String[ ] args) throws Exception
    {
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
         
        double r = Double.parseDouble(br.readLine());
         
        double b = Math.PI * r * r;
        double c = 2 * Math.PI * r;
 
        System.out.printf("%.5f %.5f\n", b, c);
    }
}

Measured memory_bytes: 24636
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1141&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

#define PRIME_MAX 1000000

using namespace std;

int main() {

	int A, D, N;

	bool is_prime[PRIME_MAX];

	is_prime[0] = false;
	is_prime[1] = false;
	REP(i,2,PRIME_MAX) is_prime[i] = true;
	REP(i,2,PRIME_MAX) {
		if (is_prime[i]) {
				for (int j=i+i; j<PRIME_MAX; j+=i) is_prime[j] = false;
		}
	}

	while(cin >> A >> D >> N)
	{
		if(A == 0 && D == 0 && N == 0){ break; }
		
		int nth = A;
		int count = 0;
	
		for(int d=0; d<PRIME_MAX; d+=D)
		{
			if(is_prime[nth]){ count++; }
			if(count == N){ break; }
			nth += D;
		}

		cout << nth << endl;
	}

	return 0;
}

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

using namespace std;

template<typename T>
int LIS(const vector<T>& v){
    if(v.empty()) return 0;
	vector<T> a(v.size(), v[0]);
    auto end = a.begin();
    ++end;
	for(int i=1;i<v.size();i++){
		auto l = lower_bound(a.begin(), end, v[i]);
        if(l == end) ++end;
        *l = v[i];
	}
	return distance(a.begin(), end);
}

int main(){
    int n;
    while(cin >> n){
        vector<int> a(n);
        for(auto& t : a) cin >> t;
        cout << LIS(a) << endl;
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int H, W; cin >> H >> W;
  string s[H]; rep(i,H) cin >> s[i];

  int sum1[H*3][W*3] = {};
  rep(h,H) rep(w,W) sum1[H+h][W+w] = sum1[H+h-1][W+w-1] + (s[h][w]=='#');
  repr(h,H,H*3) repr(w,W,W*3) {
    if (h<=2*H-1&&w<=2*W-1) continue;
    sum1[h][w] = sum1[h-1][w-1];
  }
  // rep(i,H*3) debug(sum1[i],sum1[i]+W*3);

  ll r1 = 0;
  rep(hl,H) rep(wl,W) {
    if (s[hl][wl]!='#') continue;
    ll diff = 1;
    while (hl+diff<H&&wl+diff<W) {
      if (s[hl+diff][wl+diff]=='#') {
        int count_1 = sum1[H+hl][W+wl+diff*2] - sum1[H+hl-diff-1][W+wl+diff-1];
        int count_2 = sum1[H+hl+diff*2][W+wl] - sum1[H+hl+diff-1][W+wl-diff-1];
        r1 += count_1 + count_2;
        // cout << hl << "," << wl << " " << hl+diff << "," << wl+diff << endl;
        // cout << count_1 << " " << count_2 << endl;
        // cout << hl << "," << wl+diff*2 << "~" << hl-diff-1 << "," << wl+diff-1 << endl;
      }
      diff++;
    }
  }

  int sum2[H*3][W*3] = {};
  per(h,H) rep(w,W) sum2[H+h][W+w] = sum2[H+h+1][W+w-1] + (s[h][w]=='#');
  per(h,H*2) repr(w,W,W*3) {
    if (h>=H&&w<=2*W-1) continue;
    sum2[h][w] = sum2[h+1][w-1];
  }
  // rep(i,H*3) debug(sum2[i],sum2[i]+W*3);

  ll r2 = 0;
  rep(hl,H) rep(wl,W) {
    if (s[hl][wl]!='#') continue;
    ll diff = 1;
    while (hl-diff>=0&&wl+diff<W) {
      if (s[hl-diff][wl+diff]=='#') {
        int count_1 = sum2[H+hl-diff*2+1][W+wl-1] - sum2[H+hl-diff][W+wl-diff];
        int count_2 = sum2[H+hl+1][W+wl+diff*2-1] - sum2[H+hl+diff][W+wl+diff];
        r1 += count_1 + count_2;
        // cout << hl << "," << wl << " " << hl-diff << "," << wl+diff << endl;
        // cout << count_1 << " " << count_2 << endl;
        // cout << hl << "," << wl+diff*2 << "~" << hl-diff-1 << "," << wl+diff-1 << endl;
      }
      diff++;
    }
  }

  ll result = r1 + r2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 6784
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
AB = sorted(AB, key=lambda x:x[1])
flag = True
time = 0

for i in AB:
    time += i[0]
    if time > i[1]:
        flag = False
        break

print("Yes" if flag else "No")

Measured memory_bytes: 42712
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val m = int()
    val s = string()
    val t = string()
    val len = lcm(n.toLong(), m.toLong())
    val g = gcd(n.toLong(), m.toLong()).toInt()
    var ret = len
    for (i in 0 until g) {
        if (s[i * n / g] != t[i * m / g]) {
            ret = -1
            break
        }
    }
    println(ret)
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

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



int main(){
	char S[101];
	int K;
	cin >> S;
	cin >> K;
	int num=0;
	for(int i=0;i<100;i++){
		if(S[i]!='1'){
			num=i;
			goto out;
		}
	}
	out:
	if(K<=num){cout << 1;}
	else{cout << S[num];}
	return 0;
}
	

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  REP(i, N) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  int ans = 1e8 * 4;
  REP(i, N - K + 1) {
    ans = min(ans, min(abs(x[i]) + abs(x[i + K - 1] - x[i]), abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i])));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
def is_uniq(seq):
    return len(seq) == len(set(seq))

count = int(input())

i = 0
str_list = []
while i < count:
    str_list.append(input())
    i += 1


# 重複判定
result_a = is_uniq(str_list)

result_b = True
for i, word in enumerate(str_list):
    # 最初の単語ではない場合
    if i != 0:
        # １つ前の単語の最後尾を取得
        pre_str_tail = str_list[i - 1][-1]
        str_head = str_list[i][0]

        if pre_str_tail != str_head:
            result_b = False
            break

if result_a and result_b:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
const int MAX=2e9+1e5;
 
int main(){
	int x,y;
	cin>>x>>y;
	
	int ans=MAX;
	if(x<=y)ans=min(ans,y-x);
	if((-1)*x<=y)ans=min(ans,y+x+1);
	if(x<=(-1)*y)ans=min(ans,1-y-x);
	if((-1)*x<=(-1)*y)ans=min(ans,2-y+x);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
// D - Maximum Average Sets

// 組み合わせを計算する解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

const int N_MAX = 50;

ll comb[N_MAX + 1][N_MAX + 1];

void init_comb() {
	comb[0][0] = 1;
	for (int i=1; i<=N_MAX; i++) {
		for (int j=0; j<=i; j++) {
			comb[i][j] += comb[i-1][j];
			if (j > 0) comb[i][j] += comb[i-1][j-1];
		}
	}
}

long double v[51];
map<long double, int> v_cnt; // vの各値の個数
map<long double, int> v_first_appear_idx; // 降順ソート後にvの各値が最初に出てくるindex
vector<int> last_v_idx_list; // 平均が最大となるときの最後に選んだvのindex

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	for (int i=0; i<N; i++) {
		cin >> v[i];
		v_cnt[v[i]]++;
	}

	sort(v, v+N, greater<long double>());

	// vの各値が最初に出てくるindexを求めておく
	v_first_appear_idx[v[0]] = 0;
	for (int i=1; i<N; i++) {
		if (v[i] != v[i-1]) {
			v_first_appear_idx[v[i]] = i;
		}
	}

	// ---- 平均値の最大値を求める ---- //
	long double total = 0;
	long double max_mean = 0;
	for (int i=0; i<N; i++) {
		total += v[i];
		if (i+1 >= A && i+1 <= B) {
			long double tmp_mean = total / (long double)(i+1);
			if (tmp_mean > max_mean) {
				max_mean = tmp_mean;
				last_v_idx_list.clear();
				last_v_idx_list.push_back(i);
			} else if (tmp_mean == max_mean) {
				last_v_idx_list.push_back(i);
			}
		}
	}

	// ---- 場合の数を求める ---- //
	init_comb();
	ll num_ways = 0;
	for (int last_v_idx : last_v_idx_list) {
		long double last_v = v[last_v_idx];
		int num_selected_last_v = last_v_idx - v_first_appear_idx[last_v] + 1;
		num_ways += comb[v_cnt[last_v]][num_selected_last_v];
	}

	cout << fixed << setprecision(10);
	cout << max_mean << endl;
	cout << num_ways << endl;

	return 0;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

string s;
int q;
int sign = 1;
string sp, sm;

int main(void){
    cin >> s >> q;
    sp = "";
    sm = "";
    rep(i, q){
        int t;
        cin >> t;
        if(t == 1){
            sign = -sign;
            continue;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 2) f = -1;
            else f = 1;

            if(f*sign > 0){
                sp+=c;
            }else{
                sm+=c;
            }
        }
    }

    reverse(sp.begin(), sp.end());

    if(sign > 0){
        s = sp + s + sm;
    }else{
        reverse(sp.begin(), sp.end());
        reverse(s.begin(), s.end());
        reverse(sm.begin(), sm.end());
        s = sm + s + sp;
    }


    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
long long ans(int n){
  long long ret =1;
  while(n){
    ret=ret*2%mod;
    n--;
  }
  return ret;
}
int main(){
  int n;
  cin>>n;
  vector<int>a(n),b(n,0);
  b[0]=1;
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[a[i]]++;
  }
  if(n%2==1){
    for(int i=0;i<n;i++){
      if(i%2==0){
        if(b[i]!=2){cout<<0;return 0;}
      }
      else if(b[i]>0){cout<<0;return 0;}
    }
  }
  else{
    for(int i=0;i<n;i++){
      if(i==0){continue;}
      else if(i%2==1){
        if(b[i]!=2){cout<<0;return 0;}
      }
      else if(b[i]>0){cout<<0;return 0;}
    }
  }
  cout<<ans(n/2);
}

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

typedef long long ll;
ll MOD = 1000000007;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
vector.erase(vector.begin() + index);
}

int main(){
  string S,T;
  cin >> S >> T;
  int N = S.size();
  vector<int> cnts(26),cntt(26);
  for(int i = 0;i < N;i++){
    for(int j = 0;j < 27;j++){
      if(S[i] == 'a' + j){
        cnts[j]++;
      }
      if(T[i] == 'a' + j){
        cntt[j]++;
      }
    }
  }
  sort(cnts.begin(),cnts.end());
  sort(cntt.begin(),cntt.end());
  bool frag = true;
  for(int i = 0;i < 26;i++){
    if(cnts[i] != cntt[i]){
      frag = false;
    }
  }
  if(frag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 776
from collections import defaultdict
while 1:
    N = int(input())
    if N == 0:
        break
    D = defaultdict(list)
    S = [None]*N
    for i in range(N):
        name, _, *ts = input().split()
        S[i] = name
        for t in map(int, ts):
            D[t].append(i)
    P = [0]*N
    for vs in D.values():
        p = N+1 - len(vs)
        for v in vs:
            P[v] += p
    m = min(P)
    U = [S[i] for i in range(N) if P[i] == m]
    print(m, min(U))


Measured memory_bytes: 5996
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        
        int shopCount = sc.nextInt();
        int needDrinkCount = sc.nextInt();
        
        long[][] shopDatas = new long[shopCount][2];
        for (int i = 0; i < shopCount; i++) {
            long price = sc.nextLong();
            long maxBuyCount = sc.nextLong();
            shopDatas[i][0] = price;
            shopDatas[i][1] = maxBuyCount;
        }
        
        Arrays.sort(shopDatas, (price, maxBuyCount)->Long.compare(price[0], maxBuyCount[0]));
        
        long needMoney = 0;
        
        for (int i = 0; i < shopCount; i++) {
            long price = shopDatas[i][0];
            long maxBuyCount = shopDatas[i][1];
            if (maxBuyCount <= needDrinkCount) {
                needMoney += price * maxBuyCount;
                needDrinkCount -= maxBuyCount;
            } else {
                needMoney += price * needDrinkCount;
                needDrinkCount -= needDrinkCount;
            }
            
            if (needDrinkCount == 0) break;
        }
        
        System.out.println(needMoney);
    }
}

Measured memory_bytes: 94820
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm> // sort
#include<functional> // pair


using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	char s[100+2], t[100+2], c[100*2+2];

	while(scanf("%100[a-z]\n%100[a-z]\n", s, t)==2)
	{
		sprintf(c, "%s%s", s, s);
		int ans=(strstr(c, t)!=NULL);
		printf("%s\n", ans?"Yes":"No");
	}

	return 0;
}


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

int main()
{
  int D, G;
  int p[11], c[11];
  int res=99999999;
  cin >> D >> G;

  for(int i=0;i<D; i++){
    cin >> p[i] >> c[i];
  }

  for(int i=0; i<(1<<D); i++) {
    int sum=0;
    int num=0;
    for(int j=D-1;j>=0;j--){
      if(i & (1<<j)) {
        for(int k=0; k<p[j]; k++){
          sum += (j+1)*100;
          num++;
          //cout << "sum: " << sum << " @num=" << num << endl;                           
          if(k==p[j]-1) sum+=c[j];
          if(sum>=G) break;
        }
      }
    }
    if(sum>=G) {
      res = min(res, num);
    }
  }

  cout << res << endl;
}



Measured memory_bytes: 256
N,M,*L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for a,b in zip(*[iter(L)]*2):
  dic[a].append(b)
  dic[b].append(a)
used = [False]*(N+1)
used[1] = True
q = [1]
ans1 = []
while q:
  p = q.pop()
  ans1.append(p)
  for v in dic[p]:
    if not used[v]:
      used[v] = True
      q.append(v)
      break
q = [1]
ans2 = []
while q:
  p = q.pop()
  ans2.append(p)
  for v in dic[p]:
    if not used[v]:
      used[v] = True
      q.append(v)
      break
print(len(ans1)+len(ans2)-1)
print(' '.join(map(str,(ans1[::-1]+ans2[1:]))))

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

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

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 




int main(int argc, char** argv) {
    fast_io
   
	
	int a, b;
	cin >> a >> b;
	
	cout << a*b << " " << 2*(a + b) << endl;
	
	

    return 0;
}























Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(_, k) {
    vector<int> b(n+1);
    rep(i, n) {
      int x = a[i];
      b[max(0, i-x)]++;
      b[min(n, i+x+1)]--;
    }
    rep(i, n) b[i+1] += b[i];
    b.pop_back();
    if (a == b) break;
    a = b;
  }
  rep(i, n) cout << a[i] << " \n"[i == n-1];
}

Measured memory_bytes: 4900
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.fi << ' ' << p.se << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9+10;
//const int mod=1000000007;
const int mod=998244353;

int n,m,k;
const int N=3e5+10;




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin >> n;
    vll a(n);
    for(int i=1; i<n; i++){
        for(int j=i; j<n; j+=i){
            a[j]++;
        }
    }
    cout << acc(a) << el;
    return 0;
}








Measured memory_bytes: 11112