akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main()
{ 
	int w, h, x, y, r;
	cin>>w>>h>>x>>y>>r;
        if (r <= x && x <= w - r && r <= y && y <= h - r) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
		
	
}


Measured memory_bytes: 3120
import sys
input = sys.stdin.readline

N = int(input())
A = [int(zz) for zz in input().split()]
B = [int(zz) for zz in input().split()]

ans = 0
p = 0
for i in range(N):
    ans += min(B[i]+p,A[i])
    if p < A[i]:
        p = max(0,B[i]-A[i]+p)
    else:
        p = B[i]

print(ans+min(A[-1],p))


Measured memory_bytes: 18624
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "Yes"<<endl
#define no  cout<< "No"<<endl
#define all(v) (v).begin(),(v).end()
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;    
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e10;
signed main()
{   
    fastio();
    int t=1;
    //cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       int a[n];
       for(int i=0;i<n;i++)
       cin>>a[i];
       int c=0;
       for(int i=0;i<n;i++)
       {
           for(int j=i+1;j<n;j++)
           {
               for(int k=j+1;k<n;k++)
               {
                   if(a[i]+a[j]<=a[k] ||a[i]+a[k]<=a[j]|| a[j]+a[k]<=a[i])
                   continue;
                   else if(a[i]==a[j]||a[j]==a[k]|| a[k]==a[i])
                   continue;
                   else
                   c++;
               }
           }
       }
       cout<<c;
       
    }
}

Measured memory_bytes: 3692
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        if(num%2 == 0){
          System.out.println(num/2);
        }else{
          System.out.println(num/2+1);
        }
    }
}

Measured memory_bytes: 23124
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,m,p,ans;

main(){
	cin>>n>>n;
	pint a[n];
	rep(i,n)cin>>a[i].se>>a[i].fi;
	sort(a,a+n);
	rep(i,n)(a[i].se>=p)?p=a[i].fi,ans++:0;
	dans;
}


Measured memory_bytes: 1792
n,k=io.read("*n","*n")
p=0
for i=1,n do
    if i<k then
        x=1
        while i*2^x<k do
            x=x+1
        end
        p=p+(1/n)*(1/2)^x
    else
        p=p+(1/n)
    end
end
print(string.format("%.12f",p))

Measured memory_bytes: 376
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int a,b,c;
           cin>>a>>b>>c;
           Yes(a<=c&&b>=c);
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	ll n, a, b;
	cin >> n >> a >> b;
	int s, t;
	vi dist(n - 1);
	rep(i, n) {
		cin >> t;
		if (i > 0)dist[i - 1] = t - s;
		s = t;
	}

	ll ans = 0;

	rep(i, n - 1) ans += min(a * dist[i], b);

	cout << ans << endl;

}

Measured memory_bytes: 768
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def is_ok(s: str, c: str):
    if (s[1:3] == "AG"\
      or s[1:3] == "GA"\
      or (s[0:1] == "A" and s[2:3] == "G")\
      or s[0:2] == "AG")\
      and c == "C":
        return False

    elif s[1:3] == "AC" and c == "G":
        return False

    else:
        return True

from collections import defaultdict

n = ni()

dic = defaultdict(int)
dic["xxx"] = 1

atcg = "ATCG"
MOD = 10**9 + 7

for i in range(n):
    new_dic = defaultdict(int)
    for key, val in dic.items():
        for ci in atcg:
            if is_ok(key, ci):
                new_dic[key[1:] + ci] += val
                new_dic[key[1:] + ci] %= MOD

    dic = new_dic

ans = 0

for _, val in dic.items():
    ans += val
    ans %= MOD

print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<string, pair<int, int>>PP;
typedef long long ll;

int main() {
	string s;
	int n, k;
	cin >> n >> k >> s;
	s[k - 1] += 32;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args)
  {
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int d = a/b;
    int r = a%b;
    double f = (double)a/(double)b;
    System.out.println(d+" "+r+" "+String.format("%.5f",f));
  }
}

Measured memory_bytes: 26380
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,m; cin >> n >> m;
	ll mn = inf, mx = 0;
	rep(i,m){
		ll l,r; cin >> l >> r;
		chmax(mx,l);
		chmin(mn,r);
	}
	cout << max(0LL,mn-mx+1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int head, tail;
	scanf("%d %d", &head, &tail);
	int n, count = 0;
	for ( n = head; n <= tail; n++)
	{
		if (
			(n / 10000 /*head*/ == n % 10 /*tail*/) &&
			((n % 10000) / 1000 /*thousand*/ == (n % 100) / 10 /*dars*/)
			)
			count++;
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
signed main(){
    constexpr ll MOD = 998244353;
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<int> cnt(100100,0);
    vector<int> a(n);
    ll ans=0;
    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
        ans+=a[i];
    }
    int q; cin >> q;
    rep(i,q){
        int b,c; cin >> b >> c;
        ans+=cnt[b]*(c-b);
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define isFile 0
#define NAME "taskA"
#define scan 1
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second

#define ins insert
#define all(v) v.begin(), v.end()
#define rep(i,a,n) for (int i=a;i<n;i++)
#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcountll(x)
#define rev(a) reverse(all(a))
#define skip continue
#define read(a) for(auto &i : a) cin >> i
#define print(a) for(auto i : a) cout << i << ' '
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())

//                D  R  U   L
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void faster() {
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll  INF = 1e18;
const int inf = 2e9;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;
const int ALPHA = 26;
const int N = (int)1e5 + 5;
const int M = 123;

ll dp[N];
ll a[N];
int n, k;

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];

    for(int i = 0; i < N; i++)
        dp[i] = inf;

    dp[1] = 0;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k && i + j <= n; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
        }
    }

    cout << dp[n] << endl;
}

int main() {
    faster();
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vi;

class UnionFind{
  vi p,r;
public:
  UnionFind(int n):p(n,-1),r(n,0){}
  int find(int x){return (p[x]<0)?x:(p[x] = find(p[x]));}
  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;
    if(r[x]<r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }
};

int main(){
  int n,m;
  cin >> n;
  map<string,int> id;
  vi x(n);
  rep(i,n){
    string s;
    cin >> s >> x[i];
    id[s] = i;
  }

  UnionFind uf(n);

  cin >> m;
  rep(i,m){
    string s,t;
    cin >> s >> t;
    uf.unite(id[s],id[t]);
  }
  
  const int INF = 1e9;
  vi cnt(n,0), val(n,INF);
  rep(i,n){
    int v = uf.find(i);
    cnt[v]++;
    val[v] = min(val[v],x[i]);
  }

  long long ans = 0;
  rep(i,n)ans += cnt[i]*val[i];
  cout << ans << endl;
}

Measured memory_bytes: 1884
#include <stdio.h>

int n,A[50];

int solve(int i, int m);

int main(){
  int x, M, i;

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

  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }
    
  return 0;
}

int solve(int i, int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
using P=pair<int,int>;

vector<bool> seen;
vector<int>  counter;


int main(){
    int n,q,i;cin>>n>>q;
    Graph G(n);
    seen.assign(n,false);//初期化
    counter.assign(n,0);//
    
    for(i=0;i<n-1;i++){//Graph作成
        int a,b;
        cin>>a>>b;a--;b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    for(i=0;i<q;i++){//rootと下に足すdata
        int proot,plus;cin>>proot>>plus;
        proot--;
        counter[proot]+=plus;
    }
    
    stack<int> st;//DFS
    st.emplace(0);//番号は0スタート
    seen[0]=true;
    while(st.size()!=0){
        int state=st.top();//now
        st.pop();
        for(auto next:G[state]){
            if(!seen[next]){
                counter[next]+=counter[state];//上から下へ足していく
                seen[next]=true;
                st.emplace(next);
            }
        }
    }

    for(i=0;i<n;i++){//答えを出力
        cout<<counter[i]<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 15604
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<(char)(a[0]-'a'+'A')<<(char)(b[0]-'a'+'A')<<(char)(c[0]-'a'+'A')<<endl;
  return 0;
}


Measured memory_bytes: 384
import sys

sintinel = 1000000001

def merge_sort(A, l, r):
    if l + 1 < r:
        mid = (l + r) // 2
        cnt1 = merge_sort(A, l, mid)
        cnt2 = merge_sort(A, mid, r)
        cnt3 = merge(A, l, mid, r)
        return (cnt1 + cnt2 + cnt3)
    else:
        return 0

def merge(A, l, mid, r):
    n1 = len(A[l:mid])
    L = A[l:mid] + [sintinel]
    R = A[mid:r] + [sintinel]
    i = j = 0
    cnt = 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            cnt += n1 - i
            A[k] = R[j]
            j += 1
    return cnt

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

c = merge_sort(A, 0, n)
print(c)

Measured memory_bytes: 30288
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;

int main()
{
	string s;
	cin >> s;
	if( s[1] == s[2] )
	{
		if( s[0] == s[1] or s[2] == s[3] )
			cout << "Yes";
		else
			cout << "No";
	}else
		cout << "No";
		
}

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

int main(int argc, char const *argv[])
{
    int n;cin>>n;
    int a[100010]={};
    int b[100010]={};
    for(int i=0;i<n;i++){
        int v;cin>>v;
        if(i%2==0)a[v]++;
        else b[v]++;
    }
    vector<pair<int,int>> aa;
    vector<pair<int,int>> bb;
    for(int i=0;i<100010;i++){
        aa.push_back(make_pair(a[i],i));
        bb.push_back(make_pair(b[i],i));
    }
    sort(aa.begin(),aa.end());
    sort(bb.begin(),bb.end());
    reverse(aa.begin(),aa.end());
    reverse(bb.begin(),bb.end());
    // cout << aa[0].first << " "<< aa[0].second<<endl;
    // cout << bb[0].first << " "<< bb[0].second<<endl;
    if(aa[0].second!=bb[0].second){
        cout << n-aa[0].first - bb[0].first << endl;
    }
    else{
        // if(aa[0].first>=bb[0].first){
        //     cout << n-aa[0].first-bb[1].first << endl;
        // }
        // else{
        //     cout << n-bb[0].first-aa[1].first << endl;
        // }
        cout << min(n-aa[0].first-bb[1].first, n-bb[0].first-aa[1].first);
    }
    return 0;
}


Measured memory_bytes: 2804
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

ll N, A, B;

int main()
{
  scanf( "%lld%lld%lld", &N, &A, &B );

  ll q = N/(A+B), r = N%(A+B);

  printf( "%lld\n", q*A+std::min(r,A) );

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, M;
  cin >> N >> M;

  if(2 * N >= M){
    cout << M / 2 << endl;
  } else{
    ll ans = 0;

    ans += N;
    M -= 2 * N;

    ans += M / 4;

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

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

using namespace std;
typedef pair<int, int> pii;

map<pii, double> memo;
double recur(int n, int room, int goal, int unused){
	if(n == 0){ return (room == goal) ? 1.0 : 0.0; }
	pii key(n, room);
	if(memo.find(key) != memo.end()){ return memo[key]; }
	double answer = 0.0;
	answer += recur(n - 1, (room % 3 == 0 || room - 1 == unused) ? room : (room - 1), goal, unused);
	answer += recur(n - 1, (room % 3 == 2 || room + 1 == unused) ? room : (room + 1), goal, unused);
	answer += recur(n - 1, (room / 3 == 0 || room - 3 == unused) ? room : (room - 3), goal, unused);
	answer += recur(n - 1, (room / 3 == 2 || room + 3 == unused) ? room : (room + 3), goal, unused);
	answer /= 4;
	memo.insert(make_pair(key, answer));
	return answer;
}
int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		char s, t, b;
		cin >> s >> t >> b;
		memo.clear();
		cout << recur(n, s - 'A', t - 'A', b - 'A') << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long n,a,b;
void solve()
{
    long long res=0;
    for (long long i=1;i<=n;i++)
    {
        long long x=i,ans=0;
        while(x) {ans+=x%10;x/=10;}
        if (ans>=a&&ans<=b) res+=i;
    }
    cout<<res<<endl;
}
int main()
{
    while(cin>>n>>a>>b)
        solve();
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{

    int s;
    scanf("%d", &s);
    s = s % 10;

    if (s==0 || s==6 || s==1 ||s==8)
    {
        printf("pon");
    }
    else if (s==3){
        printf("bon");
    }else
        printf("hon");

    printf("\n");
}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no2();
	}

	static void no2() {
		try (Scanner sc = new Scanner(System.in)) {
			Integer max = sc.nextInt();
			Integer width = sc.nextInt();
			Integer gap = sc.nextInt();

			int n = max / (width + gap);
			if (n * (width + gap) + gap > max)
				n--;
			System.out.println(n);
		}
	}
}

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

int main(){
  ll N;
  cin >> N;
  string seq;
  cin >> seq;
  ll res=0;
  
  ll left=0;
  ll right=N-1;
  

  while(left<right){
    if(seq[left]=='W' && seq[right]=='R'){
      seq[left] = 'R';
      seq[right] = 'W';
      left++;
      right--;
      res++;
    }
    else if(seq[left]=='W' && seq[right]=='W'){
      right--;
    }
    else{
      left++;
    }
  }
  
  cout << res;
  return 0;
}

Measured memory_bytes: 3716
class MyException < Exception; end

class Player
  def initialize(name)
    @name
    @win = 0
  end

  def -(other)
    if @win == 0
      raise MyException if other.win == 0
      other.win -= 1
      return other
    end
    if other.win == 0
      @win -= 1
      return self
    end
    raise MyException
  end

  attr_accessor :win
end

(?a..?z).each do |c|
  eval "#{c.upcase} = Player.new(?#{c})"
end

s = gets.chomp.tr('a-z[]', 'A-Z()')
while gets
  c, k = $_.chomp.split
  eval "#{c.upcase}.win = #{k}"
end

begin
  winner = eval s
  puts winner.win == 0 ? 'Yes' : 'No'
rescue MyException
  puts 'No'
end


Measured memory_bytes: 6928
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

template<typename CostType>
/// \brief 辺の情報
struct Edge{
  int      to;
  CostType cost;

  Edge(int t, CostType c): to(t), cost(c){
  }
};

template<typename CostType>
class Graph{

private:

  /// \brief adjacent_list_[n]=ノードnの隣接リストを表すvector<Edge>
  std::vector<std::vector<Edge<CostType>>> adjacent_list_;

public:

  /// \brief 頂点数
  const int NODE_SIZE_;

  /// \brief コンストラクタ
  /// \param node_size 頂点数
  explicit Graph(const int node_size): NODE_SIZE_(node_size),
                                       adjacent_list_(node_size){
  }

  /// \brief 有向グラフの辺を生やす
  /// \param from 辺の根本の頂点の番号
  /// \param to 辺の先の頂点の番号
  /// \param cost 辺のコスト
  void SetDirectedEdge(const int from, const int to, const CostType cost){
    adjacent_list_[from].push_back(Edge<CostType>(to, cost));
  }

  /// \brief 無向グラフの辺を生やす
  /// \param node_a 一方の頂点の番号
  /// \param node_b もう一方の頂点の番号
  /// \param cost 辺のコスト
  void
  SetUndirectedEdge(const int node_a, const int node_b, const CostType cost){
    SetDirectedEdge(node_a, node_b, cost);
    SetDirectedEdge(node_b, node_a, cost);
  }

  /// \brief ある頂点の隣接リストを取得
  /// \param node_num 頂点の番号
  /// \return 隣接リスト
  std::vector<Edge<CostType>> GetAdjacentList(int node_num) const{
    return adjacent_list_[node_num];
  }
};

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  Graph<int> graph(n+1);
  vector<int> h(n+1);
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }

  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    graph.SetUndirectedEdge(a,b,1);

  }

  int count=0;
  for(int i=1;i<=n;i++){
    bool isgood=true;
    for(auto e:graph.GetAdjacentList(i)){
      if(h[i]<=h[e.to]){
        isgood=false;
        break;
      }
    }
    if(isgood){
      count++;
    }
  }
  cout<<count<<endl;


  return 0;
}




Measured memory_bytes: 9520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
a_i*a_j <= a_i*a_k (j<=k)

k番目がx以下か？
*/

ll n,ans=0,k,na,nb;
ll R=2e18,L=-2e18;
vector<ll> a,b;

bool f(ll x){  // 積がx以下になるのはいくつあるか？
	ll sum=0,r;
	// ++ だんだんゆるくなる
	r=0;
	irep(i,na){
		if(a[0]*a[i]>x)continue;
		while(r<na-1 && a[r+1]*a[i]<=x)r++;
		sum+=r+1;
	}
	rep(i,na){
		if(a[i]*a[i]<=x){
			sum--;
		}else{
			break;
		}
	}
	// --
	r=0;
	irep(i,nb){
		if(b[0]*b[i]>x)continue;
		while(r<nb-1 && b[r+1]*b[i]<=x)r++;
		sum+=r+1;
	}
	rep(i,nb){
		if(b[i]*b[i]<=x){
			sum--;
		}else{
			break;
		}
	}
	sum/=2;
	// +- だんだんゆるくなる
	r=nb-1;
	rep(i,na){
		if(-a[i]*b[nb-1]>x)continue;
		while(r>0 && -a[i]*b[r-1]<=x)r--;
		sum+=nb-r;
	}
	// cerr<<x<<": "<<sum<<endl;
	return sum>=k;
}

void init(){
	cin>>n>>k;
	rep(i,n){
		ll x;
		cin>>x;
		if(x>0){
			a.push_back(x);
		}else{
			b.push_back(-x);
		}
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	// for(auto x:a)cerr<<x<<" ";
	// cerr<<endl;
	// for(auto x:b)cerr<<x<<" ";
	// cerr<<endl;
	na=a.size();
	nb=b.size();
}

int main(void){
	init();
	while(R-L>1){
		ll x=(R+L)/2;
		if(f(x)){
			R=x;
		}else{
			L=x;
		}
	}
	cout<<R<<endl;
	return 0;
}

Measured memory_bytes: 2420
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

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

#define endl '\n'
#define int long long

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i = 1; i < n; i++)
    {
        if(a[i] < a[i - 1])
        {
            int k = a[i - 1] - a[i];
            ans += k;
            a[i] += k;
        }
    }   
    cout << ans << endl;
}   

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 4780
#include <iostream>

bool areEqual(int a[], int b[], int N){
  for(int i=0;i<N;++i){
    if(a[i]!=b[i]) return false;
  }
  return true;
}

int main(){
 int N, a, b, permutation = 1;
 std::cin>>N;
 int P[N], Q[N], T[N];
 for(int i=0;i<N;++i){
   std::cin>>P[i];
   T[i] = i+1;
 }

  for(int i=0;i<N;++i){
   std::cin>>Q[i];
 }

 if(areEqual(T, P, N)) a = permutation;
 if(areEqual(T, Q, N)) b = permutation;

while(std::next_permutation(T, T + N)){
  ++permutation;
   if(areEqual(T, P, N)) a = permutation;
   if(areEqual(T, Q, N)) b = permutation;
}

std::cout<<abs(a-b);
  return 0;
}


Measured memory_bytes: 888
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi v;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            v.pb(i);
            if(i*i!=n)v.pb(n/i);
        }
    }
    int ans=0;
    for(int m:v){
        m--;
        if(m&&n/m==n%m)ans+=m;
    }
    cout<<ans<<endl;
}

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

typedef int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;

ll n,a,b,c,dp[N][3][3][3];
string s[N],ans="";

ll solve(ll id,ll x,ll y,ll z)
{
    x=min(x,2);
    y=min(y,2);
    z=min(z,2);
    if(x<0 or y<0 or z<0)
    {
        return 0;
    }
    if(id==n+1)
    {
        return 1;
    }
    ll &ans=dp[id][x][y][z];
    if(ans!=-1)
    {
        return ans;
    }
    ans=0;
    if(s[id]=="AB")
    {
        ans|=solve(id+1,x-1,y+1,z);
        ans|=solve(id+1,x+1,y-1,z);
    }
    else if(s[id]=="AC")
    {
        ans|=solve(id+1,x-1,y,z+1);
        ans|=solve(id+1,x+1,y,z-1);
    }
    else
    {
        ans|=solve(id+1,x,y+1,z-1);
        ans|=solve(id+1,x,y-1,z+1);
    }
    return ans;
}

void path(ll id,ll x,ll y,ll z)
{
    x=min(x,2);
    y=min(y,2);
    z=min(z,2);
    if(id==n+1)
    {
        return;
    }
    if(s[id]=="AB")
    {
        if(solve(id+1,x-1,y+1,z))
        {
            ans+='B';
            return path(id+1,x-1,y+1,z);
        }
        ans+='A';
        return path(id+1,x+1,y-1,z);
    }
    else if(s[id]=="AC")
    {
        if(solve(id+1,x-1,y,z+1))
        {
            ans+='C';
            return path(id+1,x-1,y,z+1);
        }
        ans+='A';
        return path(id+1,x+1,y,z-1);
    }
    else
    {
        if(solve(id+1,x,y+1,z-1))
        {
            ans+='B';
            return path(id+1,x,y+1,z-1);
        }
        ans+='C';
        return path(id+1,x,y-1,z+1);
    }
}

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        memset(dp,-1,sizeof(dp));
        cin>>n>>a>>b>>c;
        f(i,1,n)
        {
            cin>>s[i];
        }
        if(solve(1,a,b,c))
        {
            path(1,a,b,c);
            cout<<"Yes\n";
            for(auto x:ans)
            {
                cout<<x<<'\n';
            }
        }
        else
        {
            cout<<"No\n";
        }
    }
    return 0;
}


















Measured memory_bytes: 25264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,k,ans=0;
    string s;
    cin >> n >> k >> s;
    vector<int> v,u;//zero列の開始位置と終了位置
    if(n==1){
        cout << 1 << endl;
        return 0;
    }//サイズ１の時はv,uのサイズが２になってしまうので別処理

    v.push_back(-1);
    u.push_back(-1);//-1に0列の終点があることにしておく
    if(s.at(0)=='0'){
        v.push_back(0);
    }//一番左の0だけ先頭の条件が異なる
    for(int i=1;i < n;i++)
    {
        if(s.at(i)=='0'&& s.at(i-1)=='1')
        {
            v.push_back(i);
        }
        if(s.at(i)=='1'&& s.at(i-1)=='0')
        {
            u.push_back(i-1);
        }
    }
    if(s.at(n-1)=='0'){
        u.push_back(n-1);
    }//一番右の0だけ終端の条件が異なる
    v.push_back(n);
    u.push_back(n);//nに0列の先頭があることにしておく

    
    for(int i=1;i+k<v.size();i++)
    {
        ans = max(ans,v.at(i+k)-u.at(i-1)-1);
        //i番目からi+k-1番目の０列を反転する
        //連続する１の長さは（i+k番目の0列の先頭）-（i-1番目の0列の終点）-1で求まる
    }
    
    if(k>=v.size()-2){
        cout << n << endl;
    }else{
        cout << ans << endl;
    }
    
}
/*実験より0列を連続してk個とるとき、どの取り方が最も１が多く並ぶか調べればよい
うまく動かないときは、もう一度アルゴリズムを整理すること

v.size()は最初はintになってないので,intとして処理させるには(int)v.size()とかする*/

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

int main(){

    // 1. 入力情報.
    char a[22], b[22], c[22];
    scanf("%s %s %s", a, b, c);
    string A(a), B(b), C(c);
    
    // 2. しりとりになっているか？
    bool ok = (A.back() == B.front());
    ok &= (B.back() == C.front());
    
    // 3. 出力.
    printf("%s\n", ok ? "YES" : "NO");
    return 0;

}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
N,M,Q=map(int,input().split())
L=[]
for i in range(Q):
  LI=list(map(int,input().split()))
  L.append(LI)
  L[i][0]-=1
  L[i][1]-=1
R=range(1,M+1)
V=list(combinations_with_replacement(R,N))
ans=0
for arr in V:
  tmp=0
  for a,b,c,d in L:
    if arr[b]-arr[a]==c:
      tmp+=d
  ans=max(ans,tmp)
print(ans)       

Measured memory_bytes: 21552
import java.util.Scanner;
public class Main{
	static int N=100;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
       int i,j,k,l,n,m[][]=new int[N+1][N+1],p[]=new int[N+1];
       Scanner sca =new Scanner(System.in);
       n=sca.nextInt();
       for(i=0;i<n;i++){
    		   p[i]=sca.nextInt();
    		   p[i+1]=sca.nextInt();
    		   m[i+1][i+1]=0;
    	   }
       for(k=2;k<=n;k++){
    	   for(i=1;i<=n-k+1;i++){
    		   j=i+k-1;
    		   m[i][j]=Integer.MAX_VALUE;
    		   for(l=i;l<=j-1;l++){
    			   if(m[i][l]+m[l+1][j]+p[i-1]*p[l]*p[j]<m[i][j]){
    				   m[i][j]=m[i][l]+m[l+1][j]+p[i-1]*p[l]*p[j];
    			   }
    		   }
    	   }
       }
       System.out.println(m[1][n]);
       }
	}




Measured memory_bytes: 26520
#include<iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>

#define loop(k) for(int i=0;i<k;i++)
#define looop(k) for(int j=0;j<k;j++)
#define solve(s,c) {int judge{}; loop(n){if(s[i]!=c[i%3]) {judge=-1;break;}}cout<<(judge==-1?-1:m)<<endl;}
#define swap(a,b) a^=b^=a^=b;

using namespace std;

int main(){
    int n{},l{};
    cin>>n>>l;
    vector<string> s;
    string t;
    loop(n){
        cin>>t;
        s.push_back(t);
    }
    sort(s.begin(),s.end());
    loop(n){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (int) 1e5
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	int n,k;
	cin >> n >> k;
	int h[n];
	for(auto &x : h){
		cin>>x;
	}
	vector<int>dp(n, (int)1e9);

	dp[0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= min(k, i); j++){
			dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
		}
	}
	cout<<dp[n-1];
}

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

int main() {
  int X, Y, a, b;
  cin >> X >> Y;
  if (Y%2==1) {
    cout << "No" << endl;
  }
  else {
    if ((2*X-(Y/2) >= 0)&&((Y/2)-X >= 0)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

struct Read {
	long long operator()(void) {
		long long d;
		std::cin >> d;
		return d;
	}
}read;
struct ReadReal {
	double operator()(void) {
		double d;
		std::cin >> d;
		return d;
	}
}readReal;
struct ReadString {
	std::string operator()(void) {
		std::string s;
		std::cin >> s;
		return s;
	}
}readString;

struct Print {
	void operator()(double d, int digit) {
		std::cout << std::fixed << std::setprecision(digit) << d;
	}
	template <typename T>
	void operator()(T t) {
		std::cout << t;
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		if (v.empty()) return;
		Print()(v[0]);
		for(int i = 1;  i < v.size(); ++i) {
			Print()(sep);
			Print()(v[i]);
		}
		return;
	}
}print;
struct Println {
	void operator()(void) {
		std::cout << std::endl;
	}
	void operator()(double d, int digit) {
		print(d, digit);
		Println()();
	}
	template <typename T>
	void operator()(T t) {
		print(t);
		Println()();
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		print(v, sep);
		Println()();
		return;
	}
}println;

int BubbleSort(vector<int> *vec) {
	auto &v = *vec;
	int count = 0;
	bool flag = true;
	int i = 0;
	while(flag) {
		flag = false;
		for (int j = v.size() - 1; j > i; --j) {
			if (v[j - 1] > v[j]) {
				int tmp = v[j - 1];
				v[j - 1] = v[j];
				v[j] = tmp;
				flag = true;
				count++;
			}
		}
		i++;
	}
	return count;
}

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

	auto size = read();
	vector<int> v(size);
	REP(i, size) {
		v[i] = read();
	}
	int count = BubbleSort(&v);
	println(v);
	println(count);

	return 0;
}



Measured memory_bytes: 3224
card = []
3.times do card += gets.split.map{|n| [n.to_i, 0]} end
n = gets
while (i = gets)
  i = i.to_i
  if idx = card.find_index{|n| n[0] == i}
  	card[idx][1] = 1
  end
end

if (card[0][1] + card[3][1] + card[6][1] == 3) ||
    (card[1][1] + card[4][1] + card[7][1] == 3) ||
    (card[2][1] + card[5][1] + card[8][1] == 3)
  puts 'Yes'
  exit
end

if (card[0][1] + card[1][1] + card[2][1] == 3) ||
    (card[3][1] + card[4][1] + card[5][1] == 3) ||
    (card[6][1] + card[7][1] + card[8][1] == 3)
  puts 'Yes'
  exit
end

if (card[0][1] + card[4][1] + card[8][1] == 3) ||
    (card[2][1] + card[4][1] + card[6][1] == 3)
  puts 'Yes'
  exit
end

puts 'No'

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

int main() {
  int n, a, x = 0;
  cin >> n;
  rep(i, n){
    x += i+1;
    if(x >= n){
      a = i+1;
      break;
    }
  }
  cout << a << endl;
  return 0;
}

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

int main(){
  long n;
  long x, m;
  cin >> n >> x >> m;
  vector<long>a(m+100), ar(m+100);
  vector<long>numchk(m, -1); // 最後にその数字があった場所
  a[0]=x;
  ar[0]=0;
  numchk[x]=0;
  long loopstart, loopcnt;
  for(int i=1; i<=m; i++){
    a[i] = (a[i-1]*a[i-1])%m;
	if(numchk[a[i]]>=0){
      loopstart = numchk[a[i]];
      loopcnt = i-numchk[a[i]];
      ar[i]=ar[i-1]+a[i-1];
      break;
    }
    else numchk[a[i]]=i;
    ar[i]=ar[i-1]+a[i-1];
  }
  // for(int i=0; i<m; i++)cerr << ar[i] << ' ';
  if(n<=loopstart){
    cout << ar[n];
  }
  else{
    long ret=ar[loopstart];
    ret += (n-loopstart)/loopcnt*(ar[loopstart+loopcnt]-ar[loopstart]);
    ret += ar[loopstart+(n-loopstart)%loopcnt]-ar[loopstart];
    cout << ret;
  }
  return 0;
}

Measured memory_bytes: 5252
#include <algorithm>
#include <bits/stdc++.h>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <vector>

// lib/pow2.hpp
#ifndef POW2_HPP
#define POW2_HPP

/*
usage:

tools::pow2(5) => 32
*/


namespace tools {
  template <typename T, typename std::enable_if<std::is_unsigned<T>::value, std::nullptr_t>::type = nullptr>
  constexpr T pow2(const T x) {
    return static_cast<T>(1) << x;
  }

  template <typename T, typename std::enable_if<std::is_signed<T>::value, std::nullptr_t>::type = nullptr>
  constexpr T pow2(const T x) {
    return static_cast<T>(static_cast<typename std::make_unsigned<T>::type>(1) << static_cast<typename std::make_unsigned<T>::type>(x));
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 H, W, K;
  std::cin >> H >> W >> K;
  std::vector<std::string> c;
  tools::read(c, H);

  i64 answer = 0;
  for (i64 mask1 = 0; mask1 < tools::pow2<i64>(H); ++mask1) {
    for (i64 mask2 = 0; mask2 < tools::pow2<i64>(W); ++mask2) {
      i64 black = 0;
      for (i64 y = 0; y < H; ++y) {
        for (i64 x = 0; x < W; ++x) {
          if (c[y][x] == '#' && (mask1 & (1 << y)) == 0 && (mask2 & (1 << x)) == 0) {
            ++black;
          }
        }
      }

      if (black == K) {
        ++answer;
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 3620
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			cerr<<#x<<": "<<x<<endl
#define trace2(x, y)			 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)			 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin >> a >> b;
	if(a==1) a=inf;
	if(b==1) b=inf;
	if(a>b) cout << "Alice";
	else if(b>a) cout << "Bob";
	else if(a==b) cout << "Draw";
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0 for _ in range(size)]
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


N, K = list(map(int, sys.stdin.readline().split()))
A = [int(sys.stdin.readline()) for _ in range(N)]

# cumsum の最初を 0 にする
N += 1
# D[l-1] <= D[r] (l <= r) なら平均が K 以上。
D = list(itertools.accumulate([0] + [a - K for a in A]))


def compress(arr):
    """
    :param list of int arr:
    :return:
    """
    ret = [0] * len(arr)
    rank = 0
    prev = None
    for a, i in sorted([(a, i) for i, a in enumerate(arr)]):
        if a != prev:
            rank += 1
        ret[i] = rank
    return ret


def count(arr):
    """
    転倒数の逆。arr[L-1] <= arr[r] となる (L, r) の組み合わせ数
    :param list of int arr:
    :return:
    """
    ranks = compress(arr)
    bit = BinaryIndexedTree(size=max(ranks) + 1)
    ret = 0
    for i, rank in enumerate(ranks):
        ret += bit.sum(rank)
        bit.add(rank, 1)
    return ret


print(count(D))


Measured memory_bytes: 80964
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef unsigned long ul;
typedef unsigned long long ull;

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

  int a,b,c;
  std::cin >> a >> b >> c;
  if(a == 5){
    if(b == 5){
      if(c == 7){
        std::cout << "YES" << '\n';
        return 0;
      }
    }else if(b == 7){
      if(c == 5){
        std::cout << "YES" << '\n';
        return 0;
      }
    }
  }else if(a == 7){
    if(b == 5){
      if(c == 5){
        std::cout << "YES" << '\n';
        return 0;
      }
    }
  }
  std::cout << "NO" << '\n';
  return 0;
}


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

typedef long long ll;

int main(){
    int K;
    cin >> K;
    if(K%2==0){
        cout << K/2 * K/2 << endl;
    }
    else {
        cout << K/2 * (K/2+1) << endl;
    }
}


Measured memory_bytes: 256