akhauriyash/Code-Regression huggingface dataset:
import itertools
n=int(input())
s=list(map(int,list(input())))

cnt=0
for i in range(1000):
  a=i//100
  b=(i-a*100)//10
  c=i-a*100-b*10
  if a in s:
    an=s.index(a)
    tmp=s[an+1:]
    if b in tmp:
      bn=tmp.index(b)
      tmp=tmp[bn+1:]
      if c in tmp:
        cnt+=1
print(cnt)

Measured memory_bytes: 4028
n = int(input())
*v, = map(int,input().split())
*c, = map(int,input().split())
#print(v)
#print(c)
mn = 0
for i in range(n):
  vc = v[i] - c[i]
  if mn + vc > mn:
    mn += vc
print(mn)

Measured memory_bytes: 3060
/*
author: Apoorv Singh
*/

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

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"

int modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a);
        a = (a*a);
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,p; cin >> n >> p;
    int cnt = 0;
    FOR(i,0,n)
    {
        int x; cin >> x;
        if (x&1)
            ++cnt;
    }
    if (cnt == 0)
    {
        if (p&1)
            cout << 0;
        else
            cout << fpow(2,n);
        return 0;
    }
    int even = fpow(2, n-cnt);
    int odd = 0;
    odd = fpow(2, cnt-1);
    cout << even*odd;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int p[N];
  for(int i=0;i<N;i++)cin>>p[i];
  int sum=0,max=0;
  for(int i=0;i<N;i++){
    if(max<p[i])max=p[i];
    sum+=p[i];
  }
  cout<<sum-max/2<<endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    p = list(map(int,input().split()))

    for i in range(n):
        if p[i]%2 == 0:
            if p[i]%3 != 0 and p[i]%5 != 0:
                print("DENIED")
                return

    print("APPROVED")

main()

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

bool compare(pair<int, int> a, pair<int, int> b) {
//  if(a.first != b.first) return a.first>b.first;
//  else return a.second<b.second;
  if(a.second != b.second) return a.second>b.second;
  else return a.first>b.first;
}

int main() {
  int N, M, a, b, ans=0, idx;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    V[i]= make_pair(a, b);
  }
  sort(V.begin(), V.end(), compare);
  idx=V[0].first;
  ans++;
  for (int i=1; i<M; i++) {
    if(V[i].second<=idx) {
      ans++;
      idx = V[i].first;
    }
    else idx = max(idx,V[i].first);
  }
  cout << ans << "\n";
//  for (int i=0; i<M; i++) {
//    cout << V[i].first << ' ' << V[i].second << "\n";
//  }  
  return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
const int mod = 1e9+7;
int main()
{
	vector<int> a(3);
	rep(i,3){
		cin >> a[i];
	}
	leftunique(a);
	if(a.size()==2){
		coY();
	} else{
		coN();
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll sum[100010]={0};
 
ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x%N;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res%N;
}
 
int main(void){
    ll n;
    cin>>n;
    vector<ll>x(n+1);
    ll ans = 0;
    ll kaijo = 1;
    for(ll i=1;i<=n-1;i++){
        kaijo = kaijo*i;
        kaijo = kaijo%N;
    }
    for(ll i=0;i<n;i++)cin>>x[i+1];
    sum[0]=0;
    for(ll i=0;i<n;i++){
        sum[i+1]=(sum[i]+x[i+1])%N;
    }
    for(ll p=1;p<=n-1;p++){
        ll tmp = (inv(n-p)*(x[n]-x[p]))%N;
        ans = (ans+tmp+N)%N;
    }
    for(ll p=1;p<=n-2;p++){
        ll tmp = inv(p*(p+1));
        ll tmp1 = (sum[n-1]-sum[p]-sum[n-1-p]);
        ll tmp2 = (tmp1+N)%N;
        ll tmp3 = (tmp*tmp2+N)%N;
        ans = (ans+tmp3+N)%N;
    }
    ans = (ans*kaijo)%N;
    cout<<(ans+N)%N<<endl;
    return 0;
}



Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>

using namespace std;

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

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

const long long MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

int main() {
    int n;
    cin >> n;
    vector<int> target(3);
    cin >> target;
    vector<int> l(n);
    cin >> l;
    
    const int INF = 100000;
    function<int(int, vector<int>&)> solve = [&](int p, vector<int> &k){
        if (p == n) {
            vector<int> sum(4), merged(4);
            rep(i, n) {
                sum.at(k.at(i)) += l.at(i);
                merged.at(k.at(i))++;
            }
            
            int res = 0;
            rep(i, 3) {
                if (merged.at(i) == 0) return INF;
                res += abs(sum.at(i) - target.at(i)) + (merged.at(i) - 1) * 10;
            }
            return res;
        }
        
        int mini = INF;
        rep(i, 4) {
            int temp = k.at(p);
            k.at(p) = i;
            chmin(mini, solve(p + 1, k));
            k.at(p) = temp;
        }
        return mini;
    };
	
    vector<int> kind(n, -1);
    cout << solve(0, kind) << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[105][2]; // i日目にjにいるときの収入の最大値

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vvll dp(3, vll(n+1));
  
  vvll g(2, vll(n));
  rep(i,2) rep(j,n) cin>>g[i][j];
  
  rep(i,2){
    rep(j,n){
      chmax(dp[i+1][j], dp[i][j]+g[i][j]);
      chmax(dp[i][j+1], dp[i][j]+g[i][j]);
    }
  }
  cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int n,cnt;
int a[110];
int main() {
    cin>>n;
    for(int i=0;i<n;i++)
       cin>>a[i];
    for(int i=1;i<n;i++)
            if(a[i]==a[i-1]) cnt++,a[i]=0;
    cout<<cnt<<endl;
system("pause");
return 0;
}


Measured memory_bytes: 504
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        char ch;
        if (x < y) System.out.println("a" + " < " + "b");
        else if (x > y) System.out.println("a" + " > " + "b");
        else System.out.println("a" + " == " + "b");
    }
}

Measured memory_bytes: 26168
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int findCount = 0;
		for (int i = 0; i < n; i++) {
			int num = Integer.parseInt(br.readLine());
			if (isPrime(num)) {
				findCount++;
			}
		}
		System.out.println(findCount);
	}

	public static boolean isPrime(int num) {
		if (num < 2) {
			return false;
		} else if (num == 2) {
			return true;
		} else if (num % 2 == 0) {
			return false;
		}

		double sqrtNum = Math.sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2) {
			if (num % i == 0) {
				return false;
			}
		}
		return true;
	}
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin>>a>>b;
    if(a>9 || b>9)
    {
        cout<<"-1\n";
    }
    else if(a<=9 && b<=9)
    {
        cout<<a*b<<"\n";
    }
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
#define Yes cout<<"Yes"<<endl; 
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl; 
#define NO cout<<"NO"<<endl;
#define yes cout<<"yes"<<endl; 
#define no cout<<"no"<<endl;

// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
int x;cin>>x;
if(x==0)
cout<<1<<endl;
else
{
    cout<<0<<endl;
}

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, i, j, k, a, b, c, id, q, s, x, y, ans;
	cin >> n;
	vector<vector<pair<long long, long long>>> adj(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b >> c;
		adj[a].push_back({ b,c });
		adj[b].push_back({ a,c });
	}
	cin >> q >> s;

	vector<long long>parent(n + 1, -1);
	vector<long long> d(n + 1, 0);
	parent[s] = 0;
	d[s] = 0;
	queue<long long> qq;
	qq.push(s);

	while (!qq.empty()) {
		id = qq.front();
		qq.pop();

		for (auto p : adj[id]) {
			if (parent[p.first] == -1) {
				parent[p.first] = id;
				d[p.first] = d[id] + p.second;
				qq.push(p.first);
			}
		}
	}

	while (q--) {
		cin >> x >> y;
		ans = d[x] + d[y];
		cout << ans << "\n";
	}


	return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    string s;
    cin >> s; 
    int n = s.size();
    int len = 0;
    REP(i,n){
        FOR(j,1,n - i + 1){
            string a = s.substr(i,j);
            bool flag = true;
            int cnt = 0;
            REP(k,a.size()){
                if(a[k] == 'A'|| a[k] == 'C'|| a[k] == 'G'|| a[k] == 'T'){
                    cnt++;
                }else
                    flag = false;
            }
            if(flag)
                CMAX(len,cnt); 
            cnt = 0;
            flag = true;
        }
    }
    cout << len << endl;
    return 0;
}

Measured memory_bytes: 256
let () =
  let arr = [|1; 1; 1; 2; 1; 2; 1; 5; 2; 2; 1; 5; 1; 2; 1; 14; 1; 5; 1; 5; 2; 2; 1; 15; 2; 2; 5; 4; 1; 4; 1; 51|] in
  Scanf.scanf "%d\n" @@ fun k -> Printf.printf "%d\n" arr.(k-1)

Measured memory_bytes: 384
def main():
    n, k = list(map(int, input().split()))
    sunukes = [0] * n
    for _ in range(k):
        d_tmp = int(input())
        aList = list(map(int, input().split()))
        for a in aList:
            sunukes[a-1] += 1
    print(sunukes.count(0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define fo(a,b) for (int i = a; i < b; i++) 
#define foi(a,b) for (int i = a; i <= b; i++) 
using namespace std;


typedef long long ll;
typedef unsigned long long ull;

bool is_perfect_square(int n) {
    if (n < 0)
        return false;
    int root(round(sqrt(n)));
    return n == root * root;
}

int main ()  {

	int a, b;
	cin >> a >> b;

	string astr = to_string(a);
	string bstr = to_string(b);

	int final = stoi(astr+bstr);
	if(is_perfect_square(final)) {	cout << "Yes";
	}
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  map<int, int> x;

  rep(i, 0, n) {
    int a;
    cin >> a;
    if (x.size() == 0)
      x[a]++;
    else {
      auto v = x.lower_bound(a);
      if (v != x.begin()) {
        v--;
        if (x[(*v).first] > 1)
          x[(*v).first]--;
        else
          x.erase(v);
      }
      x[a]++;
    }
  }

  int ans = 0;
  for (auto xx : x)
    ans += xx.second;

  cout << ans << endl;
}


Measured memory_bytes: 8120
A,B,C = input().split()
K = input()

a = int(A)
b = int(B)
c = int(C)
k = int(K)

#print(a)
#print(b)
#print(c)
#print(k)

out = 'No'

for i in range(k+1):
#  print(i)
#  print(''+str(a)+''+str(b)+''+str(c))
  if a >= b:
    b *=2
  elif b >= c:
    c *=2
  else:
    out = 'Yes'
#  print(''+str(a)+''+str(b)+''+str(c))
  

print(out)


Measured memory_bytes: 9176
#include <stdio.h>
int main(void){
 int n1,n2,n3,n4;
 int flag = 0;
 scanf("%d",&n1);
 scanf("%d",&n2);
 scanf("%d",&n3);
 scanf("%d",&n4);
 
 if((n1==1||n1==9||n1==4||n1==7)&&(n2==1||n2==9||n2==4||n2==7)
  &&(n3==1||n3==9||n3==4||n3==7)&&(n4==1||n4==9||n4==4||n4==7)
  && n1!=n2 && n1!=n3 && n1!=n4 && n2!=n3 && n2!=n4 && n3!=n4){
    flag =1;     
 } 
 
 if(flag == 1) printf("YES\n");
 else printf("NO\n");

 return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 




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

if(a == b){
  print("Draw");
  return 0;
}


if(a == 13 && b == 1){
   print("Bob");
}else if(b == 13 && a == 1){
  print("Alice");
}else if(a > b){
print("Alice");
}else if(a < b){
  print("Bob");
}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
          string[] Input = Console.ReadLine().Split(' ');
          string[] Input2 = Console.ReadLine().Split(' ');
          int N = int.Parse(Input[0]);
          int M = int.Parse(Input[1]);
          int sum = 0;
          var list = new List<int>{};
          for(int i = 0; i < N; i++)
          {
           int num = int.Parse(Input2[i]);
           sum += num;
           list.Add(num);
          }
     　　　list.Sort((a, b) => b - a);
          bool flag = false;
          for(int i = 0; i < M; i++){
            if((double)list[i] / sum < (double)1 / (4 * M))
            {
             flag = true;
            }
          }
          if(flag)
          {
           Console.WriteLine("No");
          }else
          {
            Console.WriteLine("Yes");
          }
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    char a, b, ans;
    cin >> a >> b;
    if (a == 'H' && b == 'H') ans = 'H';
    else if (a == 'H' && b == 'D') ans = 'D';
    else if (a == 'D' && b == 'D') ans = 'H';
    else ans = 'D';
    cout << ans << endl;
}

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

#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)(v).size())
#define FILL(v, x) memset((v), (x), sizeof(v))
#define DUMP(x) cerr << #x << " = " << (x) << endl;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
const double PI = acos(-1);



int main(void)
{
    double l;
    cin >> l;
    printf("%.18lf", l * l * l / 27);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n,k;
  cin >> n >> k;
  long ans = k;
  rep(i,n-1){
    ans *= (k-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int a, b, k; cin >> a >> b >> k;
  int cnt = 0;
  int tmp = __gcd(a, b);

  for (int i = tmp; i > 0; --i) {
    if (a % i == 0 && b % i ==0) {
      ++cnt;
      if (cnt == k) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

int main(){
    double r;
    cin >> r;
    r *= 6.28318530717958623200;
    printf("%.10f\n", r);
    return 0;
}

Measured memory_bytes: 3756
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

#define int long long

 main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n + 1);
    cin >> a;
    if (n == 0) {
        if (a[0] == 1)
            cout << 1;
        else
            cout << -1;
        return 0;
    }
    if (a[0] == 1)
        return cout << -1, 0;
    vector <vector <int>> b(n + 1, vector <int> (2));
    b[n][0] = b[n][1] = a[n];
    for (int i = n - 1; i >= 0; --i) {
        b[i][0] = (b[i + 1][0] + 1) / 2 + a[i];
        b[i][1] = b[i + 1][1] + a[i];
        if (i < 31)
            chkmin(b[i][1], 1 << i);
        if (b[i][0] > b[i][1])
            return cout << -1, 0;
    }
    /*forn (i, 0, n + 1) {
        cout << b[i] << "\n";
    }*/
    int lst = 1;
    long long ans = 1;
    forn (i, 1, n + 1) {
        int cur = min(2 * lst, b[i][1]);
        if (cur < b[i][0])
            return cout << -1, 0;
        ans += cur;
        lst = cur - a[i];
    }
    cout << ans;
    return 0;
}

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

int main() {
  int N , K;
  cin >> N >> K;
  int n = 1;
  int i = 0;
  int nibai , wa;
  while(i < N ){
    nibai = n * 2;
    wa = n + K;
    if(nibai >= wa){
   n = wa;
    }
    else{
      n = nibai;
    }
      i++;
  }
    cout << n << endl;
}


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

int sum(int a){
    return a%10+(a/10)%10+(a/100)%10+(a/1000)%10+(a/10000)%10;
}

int main(void){
    int N,A,m;
    cin>>N;
    
    int min=sum(1)+sum(N-1);
    for(A=2;A<N;A++){
        m=sum(A)+sum(N-A);
        if (min>m){
            min=m;
        }
    }
    cout<<min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
long x[1000],y[1000],z[1000],memo[1000],cnt,ans=0;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i];
	for(int a=-1;a<2;a+=2){
		for(int b=-1;b<2;b+=2){
			for(int c=-1;c<2;c+=2){
				for(int i=0;i<n;i++)memo[i]=(x[i]*a)+(y[i]*b)+(z[i]*c);
				sort(memo,memo+n);
				cnt=0;
				for(int i=n-1;i>=n-m;i--)cnt+=memo[i];
				ans=max(ans,cnt);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
s = deque(input())
cnt = 1
s1 = s.popleft()
while s != deque():
  if s1 != s[0]:
      s1 = s.popleft()
      cnt += 1
  else:
    if len(s) == 1:
      s.popleft()
    else:
      s1 = s.popleft() + s.popleft()
      cnt += 1
print(cnt)

Measured memory_bytes: 5216
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	string a, b, c; cin >> a >> b >> c;
	int len = a.length(); int l = b.length();
	if (a[len - 1] == b[0] && b[l - 1] == c[0])cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N, A, B;
    cin >> N >> A >> B;
    LL res = 0;
    res = (N/(A + B))*A + max<LL>(0, min<LL>(A, N - (N/(A + B))*(A + B)));
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN=2e5;
 
int main () 
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    int mx=a[0];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        mx=max(mx,a[i]);
        ans+=mx-a[i];
    }
    cout << ans;
}

Measured memory_bytes: 4376
#include <stdio.h>

int main(int argc,char* argv[]){
  int i,j,k;
  int number = 1;
  int dp_array[1001];
  int w_array[1001];
  int p_array[1001];  

  for(;;){
    
    int W;
    int N;
    int w_sum = 0;
    int p_sum = 0;

    scanf("%d",&W);
    if(W == 0){break;}
    scanf("%d",&N);
    w_sum = W+1;
    
    for(i = 1; i <= W; i++){
      dp_array[i] = -1;
    }
    dp_array[0] = 0;
    
    for(i = 0;i < N;i++){
      scanf("%d,%d", &p_array[i],&w_array[i]);
    }

    for(i = 0;i < N;i++){
      for(j = W;j >= 0;j--){
	if(dp_array[j] >= 0 && (j+w_array[i]) <= W){
	  if(dp_array[j+w_array[i]] < (dp_array[j] + p_array[i])){
	    dp_array[j+w_array[i]] = dp_array[j] + p_array[i];
	    
	    if(p_sum < dp_array[j+w_array[i]]){
	      p_sum = dp_array[j+w_array[i]];
	      w_sum = j+w_array[i];
	    }else if(p_sum == dp_array[j+w_array[i]]){ 
	      if(w_sum > (j+w_array[i])){
		w_sum = j+w_array[i];
	      }  
	    }
	  } 
	}
      }
    }
    
    printf("Case %d:\n",number);
    printf("%d\n",p_sum);
    printf("%d\n",w_sum);
    
    number++;
  }

  return 0;
  
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int score = 0;
  for (int i = 0; i < N - 1; i++)
  {
    if (S[i] == S[i + 1])
      score++;
  }
  cout << min(score + 2 * K, N - 1) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int n;
int p[200];
int a, b, c, d;

int main() {
    while (cin >> n) {
        memset(p, 0, sizeof(p));
        int m = n * (n-1) / 2;
        for (int i = 0; i < m; ++i) {
            cin >> a >> b >> c >> d;
            --a; --b;
            if (c > d) p[a] += 3;
            else if (c < d) p[b] += 3;
            else p[a] += 1, p[b] += 1;
        }
        vector<int> vec;
        for (int i = 0; i < n; ++i) {vec.PB(p[i]);}
        sort(ALL(vec), greater<int>());
        
        map<int,int> ma;
        for (int i = 0; i < vec.size(); ++i) {
            if (!ma.count(vec[i])) ma[vec[i]] = i+1;
        }
        for (int i = 0; i < n; ++i) cout << ma[p[i]] << endl;
    }
    return 0;
}


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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

int N; char S[MAX_N]; int Nr[MAX_N];

int main() {
	cin >> N; scanf("%s", S);
	for(int s=0; s<4; s++) {
		Nr[0] = s/2; Nr[1] = s%2;
		for(int i=2; i<N; i++) {
			int sum = Nr[i-2] + Nr[i-1];
			if(S[i-1] == 'o') Nr[i] = sum % 2;
			else Nr[i] = 1 - sum%2;
		}
		int f = (Nr[0] + Nr[1] + Nr[N-1]) % 2;
		int l = (Nr[N-2] + Nr[N-1] + Nr[0]) % 2;
		char test[5] = "ox";

		if(test[f] == S[0] && test[l] == S[N-1]) {
			for(int i=0; i<N; i++) printf("%c", Nr[i]==0?'S':'W');
			puts("");
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc057_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(M);
  vector<int> d(M);
  rep(i, N) {
    cin >> a[i];
    cin >> b[i];
  }
  rep(i, M) {
    cin >> c[i];
    cin >> d[i];
  }

  rep(i, N) {
    int x = a[i];
    int y = b[i];
    int dis = INF * 10;
    int ans = 0;
    rep(j, M) {
      int m = c[j];
      int n = d[j];
      int _dis = abs(x - m) + abs(y - n);
      if (dis > _dis) {
        dis = _dis;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        sc.nextLine();

        int[] tenbo = new int[N];
        int[] hitenbo = new int[N];

        for (int i = 0; i < N; i++) {
            tenbo[i] = sc.nextInt();
        }
        sc.nextLine();

        for (int i = 1; i <= M; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            hitenbo[a] = Math.max(hitenbo[a], tenbo[b]);
            hitenbo[b] = Math.max(hitenbo[b], tenbo[a]);
            sc.nextLine();
        }

        for (int i = 0; i < N; i++) {
            if (tenbo[i] > hitenbo[i]) {
                goodTenbo++;
            }
        }

        System.out.println(goodTenbo);
    }
}

Measured memory_bytes: 61256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
	ll n; cin>>n;
	for(ll i=1;i<=3500;i++)
	{
		for(ll j=1;j<=3500;j++)
		{
			ll num = 4LL*i*j-n*(j+i);
			if(num<=0) continue;
			ll denom = n*i*j;
			ll g=__gcd(denom,num);
			num/=g; denom/=g;
			if(num==1)
			{
				cout<<i<<' '<<j<<' '<<denom<<'\n';
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
m = 100010

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

a = primes(m * 2 + 100)
n = int(input())

from bisect import bisect_left
def index(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return True
    return False

def do(x):
    if index(a, x) and index(a, (x + 1) // 2):
        return True

dat = [-1] * m
count = 0
for i in range(len(a)):
    if a[i] > m:
        break
    if do(a[i]):
        count += 1
    dat[a[i]] = count
c = -1
for i in range(m):
    if dat[i] != -1:
        c = dat[i]
    else:
        dat[i] = c
dat[0] = dat[1] = 0

for _ in range(n):
    l, r = map(int, input().split())
    print(dat[r] - dat[l - 1])

Measured memory_bytes: 57944
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

struct C1 {
    ll N_{};
    ll Q_{};
    vector<vector<ll>> m_{};
    vector<ll> parents_{};
    vector<ll> added_values_{};
    vector<ll> added_value_total_{};
    explicit C1(ll N, vector<pll> r, vector<pll> v) : N_(N), Q_(v.size()) {
        parents_.resize(N);
        added_values_.resize(N, 0);
        added_value_total_.resize(N, -1);
        for(ll i=0; i < Q_; ++i) {
            auto p = v[i];
            added_values_[p.first-1] += p.second;
        }
        m_.resize(N_);
        for(ll i=0; i < N_-1; ++i) {
            auto p = r[i];
            m_[p.first-1].emplace_back(p.second-1);
            m_[p.second-1].emplace_back(p.first-1);
        }
        dfs(0, -1);
    }
    void dfs(ll cur, ll prev = -1) {
        parents_[cur] = prev;
        for(ll n : m_[cur]) {
            if (n != prev) {
                dfs(n, cur);
            }
        }
    }

    vector<ll> resolve() {
        vector<ll> ret{};
        for(ll i=0; i < N_; ++i) {
            ll value = 0;
            ll n = i;
            while(n != -1) {
                value += added_values_[n];
                n = parents_[n];
                if (n != -1 && added_value_total_[n] != -1) {
                    value += added_value_total_[n];
                    n = -1;
                }
            }
            ret.emplace_back(value);
            added_value_total_[i] = value;
        }
        return ret;
    }
};

int main() {
    ll N, Q;
    cin >> N >> Q;
    vector<pll> r{};
    for (int i=0; i < N-1; ++i) {
        ll a, b;
        cin >> a >> b;
        r.emplace_back(a,b);
    }
    vector<pll> v{};
    for (int i=0; i < Q; ++i) {
        ll p, x;
        cin >> p >> x;
        v.emplace_back(p, x);
    }
    C1 c{N, move(r), move(v)};
    auto ans = c.resolve();
    for(ll x : ans) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int N, D;
int ex[2000][2000];
int chokudai[2][2001][2001];

inline int get_rect(int t, int a, int b, int c, int d) {
  return chokudai[t][c][d] + chokudai[t][a][b] - chokudai[t][a][d] - chokudai[t][c][b];
}

bool check(int t) {
  int a = t / D;
  bool all = true;
  for(int i = 0; i < 2 * D; i++) {
    for(int j = 0; j < 2 * D; j++) {
      if(ex[i][j] > 1LL * (a + 1) * (a + 1)) return false;
      all &= ex[i][j] <= 1LL * a * a;
      chokudai[0][i + 1][j + 1] = ex[i][j] > 1LL * a * a;
      chokudai[1][i + 1][j + 1] = ex[i][j] > 1LL * a * (a + 1);
    }
  }
  if(all) return true;
  for(int k = 0; k < 2; k++) {
    for(int i = 1; i <= 2 * D; i++) {
      for(int j = 1; j <= 2 * D; j++) {
        chokudai[k][i][j] += chokudai[k][i - 1][j];
        chokudai[k][i][j] += chokudai[k][i][j - 1];
        chokudai[k][i][j] -= chokudai[k][i - 1][j - 1];
      }
    }
  }
  int b = t % D + 1;
  for(int i = 0; i < D; i++) {
    for(int j = 0; j < D; j++) {
      int add = 0;
      add += get_rect(0, i + b, j + b, i + D, j + D);
      add += get_rect(1, i, j, i + D, j + D);
      add -= get_rect(1, i, j, i + b, j + b);
      add -= get_rect(1, i + b, j + b, i + D, j + D);
      if(add == 0) return true;
    }
  }
  return false;
}


int main() {
  cin >> N >> D;
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    x %= D;
    y %= D;
    ++ex[x][y];
    ++ex[x][y + D];
    ++ex[x + D][y];
    ++ex[x + D][y + D];
  }
  int ok = (1 << 30) - 1;
  for(int k = 29; k >= 0; k--) {
    if(check(ok ^ (1 << k))) ok ^= 1 << k;
  }
  cout << ok << endl;
}


Measured memory_bytes: 47104
#include <iostream>
using namespace std;
typedef long long ll;

const int mod = 1000000007;
const int admax = 60;

int main() {
  int n;
  cin >> n;
  int count[admax] = {};
  int md = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    int d = 0;
    while (a) {
      if (a & 1) count[d]++;
      a >>= 1;
      d++;
    }
    md = max(md, d);
  }
  int ans = 0;
  for (int i = 0; i < md; i++) {
    int c = 1LL * (n-count[i]) * count[i] % mod;
    int x = (1LL << i) % mod;
    ans = (ans + 1LL * c * x) % mod;
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i, n)cin>>a[i];
  int q;cin>>q;
  vector<int>m(q);
  rep(i, q)cin>>m[i];

  map<int, bool>ans;
  rep(i, pow(2,n)){
    int tmp = 0;
    rep(j, n){
      if((i >> j) & 1)tmp += a[j];
      // cout<<i<<' '<<((i >> j) & 1)<<endl;
    }
    ans[tmp]=true;
  }

  rep(i, q){
    if(ans[m[i]]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

  return 0;
}



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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

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

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

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

int main()
{
    int r, g, b, n;
    ci >> r >> g >> b >> n;

    for(int i = 0; i * r <= n; i++) {
	int sumr = i * r;
	
	for(int j = 0; j * g <= n - sumr; j++) {
	    int sumg = j * g + sumr;

	    if((n - sumg) % b == 0) cnt++;
	}
    }

    co << cnt << en;
  
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int x, y, t;
  scanf("%d%d", &x, &y);
  int tx = x, ty = y;
  while(ty) {
    t = tx % ty;
    tx = ty;
    ty = t;
  }
  if(tx == y) printf("-1");
  else printf("%d", x);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//



//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c ;
  cin >> a>> b >> c  ;
  int d = a+b+c ;
  if(d>=22){
    cout <<"bust"<<endl ;
  }
  else{
    cout <<"win"<<endl ;
  }
  
  
  
  return 0 ;
}




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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  string T = "CODEFESTIVAL2016";
  
  int count = 0;
  for (int i = 0; i < N; i++){
    if (S.at(i) != T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3628
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

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

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n; ll k;
    cin >> n >> k;
    V<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 lw = -1, up = TEN(13);

    while (up - lw > 1) {
        ll md = (lw + up) / 2;
        ll sm = 0;
        for (int i = 0; i < n; i++) {
            // (a[i] - k) * f[i] <= md
            // a[i] - k <= md / f[i]
            // a[i] - md / f[i] <= md
            sm += max(0LL, a[i] - md / f[i]);
        }
        if (sm <= k) up = md;
        else lw = md;
    }
    cout << up << endl;
    return 0;
}


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


int main()
{

  string word , a;
  int words = 0 , counts[26];
  
  for( int j = 0; j < 26; j++ )
    {
      counts[j] = 0;
    }
  
  while( cin >> word )
    {
      for( int i = 0; i < word.size(); i++ )
	{ 
	  if( isupper(word[i]) ) word[i] = tolower(word[i]);
	  words = word[i] - 'a';
	  counts[words]++;
	  
	}
    }
  
  
  for( int i = 0; i < 26; i++ ) 
    {
      a[i]  = (char)i + 'a';
      cout << a[i] << " " << ":" << " " << counts[i] << endl;
    }
  
  return 0;
  
}
 

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

bool tassei = false;
int kosu = 0;
int h, w;
string s[8];

void dfs(P ichi, int now_kosu) {
    if(now_kosu == kosu){
        if(ichi.first == h-1 && ichi.second == w-1) {
         tassei = true;
        }
        return;
    } else {
        if(ichi.first < h - 1) {
            /* 下に行く */
            if(s[ichi.first+1][ichi.second] == '#') {
                ichi.first++;
                dfs(ichi, now_kosu+1);
            }
        }
        if(ichi.second < w - 1) {
            /* 右に行く */
            if(s[ichi.first][ichi.second+1] == '#') {
                ichi.second++;
                dfs(ichi, now_kosu+1);
            }
        }
    }
}

int main(){
    cin >> h >> w;
    REP(i, h) cin >> s[i];

    REP(i, h) REP(j, w) {
        if(s[i][j] == '#') kosu++;
    }

    P start;
    start.first = start.second = 0;

    dfs(start, 1);

    if(tassei) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main(){
    ll n; cin >> n; 
    vector<ll> a(n);
    for(ll i=0; i<n; ++i){cin >> a[i];}
    vector<ll> sum(n, 0); sum[0] = 0;  
    for(ll i=0; i<n-1; ++i){
        sum[i+1] = (sum[i]+a[n-1-i])%mod; 
    }

    ll res = 0;
    for(ll i=1; i<n; ++i){
        res += (sum[i]*a[n-1-i])%mod;
    }
    res %= mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6396