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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
    for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
    int64 n, l, r;
    while (cin >> n >> l >> r && n+l+r) {
        vector<int64> A(n);
        REP(i, n) cin >> A[i];

        int64 res = 0;
        FOR(i, l, r+1) {
            bool ok = 1;
            REP(j, A.size()) {
                if (i % A[j] == 0) {
                    if (j % 2 == 0) {
                        res++;
                    }
                    ok = 0;
                    break;
                }
            }
            if (ok && n % 2 == 0) {
                res++;
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3100
#!/usr/bin python3
# -*- coding: utf-8 -*-

n, x, m = map(int, input().split())

s = set([])
v = []
for i in range(m+1):
    s.add(x)
    v.append(x)
    x = pow(x,2,m)
    if x in s:
        break
st = v.index(x)
lp = len(v)-st
lps = sum(v[st:])

k = (n-(st+lp)+(lp-1))//lp
ret = lps * k
n -= lp * k
ret += sum(v[:n])

print(ret)

Measured memory_bytes: 13124
#include <bits/stdc++.h>
using namespace std;
 
#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)
#define _cos(xxxx) cos(xxxx*acos(-1)/180)
#define _sin(xxxx) sin(xxxx*acos(-1)/180)
#define _tan(xxxx) tan(xxxx*acos(-1)/180)
#define PE cout<<fixed
#define sqr(x) ((x)*(x))
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
 
const ld pi=acos(-1);

ll n,sum,a[500009],kq1,kq2,kq3,i;

int main() {
    IO;
    cin>>n;
    for (i=1;i<=n;i++) {
        cin>>a[i];
        sum+=a[i];
    }
    sum/=n;
    for (i=1;i<=n;i++) {
        kq1+=sqr(a[i]-sum+1);
        kq2+=sqr(a[i]-sum);
        kq3+=sqr(a[i]-sum-1);
    }
    cout<<min(kq1,min(kq2,kq3));
}
    

Measured memory_bytes: 3656
N, M = [int(x) for x in input().split()]
L = [0] * (N + 1)
for m in range(M):
  l, r = [int(x) for x in input().split()]
  L[l-1] += 1
  L[r] -= 1
  
for i, l in enumerate(L[1:], start=1):
  L[i] = L[i-1] + l
 
print(L.count(M))

Measured memory_bytes: 7920
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k,ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	for (int i = 0; i <= n - 1; i++) {
		int s = i*c - (n - 1 - i)*d,
			m = i*d - (n - 1 - i)*c;
		if (s <= b - a&&b - a <= m) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
	getchar(); getchar();
}

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

using namespace std;
using ll = long long;

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

void ch(vector<int>& a, int b, int c, int& count, int n){
  REP(i, b){
    if (count>n-1) break;
    if (a[count]<c){
      a[count]=c;
      count++;
      }
    else break;
  }
}

bool gre(const pair<int,int>& fst, const pair<int,int>& snd){
  return (fst.second > snd.second);
}

int main () {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  REP(i, n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());

  //  int* array = &a[0];
  vector<pair<int,int> > bc(m);
  REP(i, m){
    cin >> bc[i].first >> bc[i].second;
  }
  sort(bc.begin(), bc.end(), gre);
  int count =0;
  REP(i, m){
    ch(a, bc[i].first, bc[i].second, count, n);
  }

  
  cout << accumulate(a.begin(), a.end(), 0LL) << '\n';

  return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      	int a1=sc.nextInt();
      	int b1=sc.nextInt();
      	int a2=sc.nextInt();
      	int b2=sc.nextInt();
      	int o= a1!=a2? 1:0;
      	System.out.println(o);
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    double T,X; cin>>T>>X;
    cout<<setprecision(10)<<T/X<<endl;
}


Measured memory_bytes: 256
using System;
class _0102
{
    public static void Main()
    {
        int sum, n = int.Parse(Console.ReadLine());
        int[,] matrix;
        string[] data;
        while (n != 0)
        {
            matrix = new int[n + 1, n + 1];
            for (int i = 0; i < n; i++)
            {
                data = Console.ReadLine().Split();
                for (int j = 0; j < n; j++) matrix[i, j] = int.Parse(data[j]);
            }
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    sum = 0;
                    for (int k = 0; k < n; k++) sum += matrix[j, k];
                    matrix[j, n] = sum;
                }
                for (int j = 0; j < n; j++)
                {
                    sum = 0;
                    for (int k = 0; k < n; k++) sum += matrix[k, j];
                    matrix[n, j] = sum;
                }
            }
            sum = 0;
            for (int i = 0; i < n; i++) sum += matrix[i, n];
            matrix[n, n] = sum;
            for (int i = 0; i < n + 1; i++)
            {
                for (int j = 0; j < n; j++) Console.Write("{0,5}", matrix[i, j]);
                Console.WriteLine("{0,5}", matrix[i, n]);
            }
            n = int.Parse(Console.ReadLine());
        }
    }
}

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


int main() {
    int N, M; cin >> N >> M;
    vector<bool> broken(N, 0);
    for(int i=0; i<M; i++){
        int a; cin >> a;
        broken[a] = true;
    }

    vector<int> dp(N+2, 0);
    const int mod = 1000000007;
    dp[N] = 1;
    for(int i=N-1; i>=0; i--){
        if(broken[i]){
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2]) % mod;
    }

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <set>
#include <deque>
#include <vector>
#define MAX 25000
#define rep(i,p) for(int i=0;i<p;i++)
#define rep1(i,p) for(int i=1;i<=p;i++)
#define pb push_back
using namespace std;
int n,m,sum,num;
int A[MAX];
int B[MAX];
int C[MAX];
int V[MAX];
pair<int,int> bridge[MAX];
int root (int child) {
  int a = child;
  while (V[a] != a) {
    a = V[a];
  }
  return a;
}
int main(){
  while (1) {
    cin >> n >> m;
    if (n==0 && m==0) return 0;
    // n : city
    // m : bridge
    rep(j,m) {
      cin >> A[j] >> B[j] >> C[j];
      bridge[j].first = C[j];
      bridge[j].second = j;
    }
    // sort by lenght of bridge
    sort(bridge, bridge+m);
    sum = 0;
    // Union Find Tree
    rep(i,m) V[i] = i;
    rep(i,m) {
      num = bridge[i].second;
      int ra = root(A[num]);
      int rb = root(B[num]);
      if (ra != rb) {
        V[ra] = rb;
        sum += bridge[i].first;
      }
      // cout << bridge[i].first << " " << bridge[i].second << endl;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1376
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
      int A,B;
      String an = scan.nextLine();
      String atai[] = an.split(" ",0);
      A = Integer.parseInt(atai[0]);
      B = Integer.parseInt(atai[1]);
       //System.out.println(N);
      cal(A,B);
        scan.close();
    }
  
  public static void cal(int a,int b){
   int s = 0;
    s = a*b;
    System.out.println(s);
    return;
  }
}

Measured memory_bytes: 35808
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

int main(){int N;cin>>N;
           vector<int> H(N);
           
           for(int i=0;i<N;i++){
             cin >> H.at(i);
           }
           
           int sum=0,C,X=0;
           for(int i =0; i<N-1; i++){
             
             if(H.at(i)<H.at(i+1)){
               sum=0;}
             
             else{
               sum++; 
               C=max(sum,C);
                X=max(sum,C);
              
             }
          
           }
           cout << X << endl;}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    # KeyInsight:
    # ◯: 配列の要素の合計を前計算しておく
    # △: 尺取り法に気がつけなかった。
    # △: 解説動画を見て自分で実装したら、サンプルのインデックスエラーが消えずに詰んだ。
    # See:
    # https://www.youtube.com/watch?v=v8ppNGf49Nk&feature=youtu.be
    time = 0

    for bi in b:
        time += bi

    j = m
    ans = 0

    for i in range(n + 1):
        # bの要素を選択できる、かつ、kより所要時間が長いときに、本を減らす
        while (j > 0 and time > k):
            j -= 1
            time -= b[j]

        # 全てのbの要素を除外したケースへの対応
        if time > k:
            break

        # aとbの要素数と、これまでの最大値とを比較
        ans = max(ans, i + j)

        # 実装上の工夫:
        # 配列参照外を防ぐ
        if (i == n):
            break

        # 実装上の工夫:
        # aの要素を次のループの前に計算しておく
        time += a[i]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39984
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    ll p[N];
    for(ll i = 0; i < N; i++) cin >> p[i];
    ll po[N + 1] = {};
    for(ll i = 0; i < N; i++) po[p[i]] = po[p[i] - 1]  + 1;
    cout << N - *max_element(po, po + N + 1) << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
vector <int> v[160],alo[1000000];
int i,j,b,k,n,t,hey;
long long mas[160][106];
long long s,ks;
long long pre[1000000],dp[1000000];
int main()
    {
    cin>>n;
    for (i=0;i<n;i++)
        for (j=0;j<n;j++)
            cin>>mas[i][j];
    for (b=1;b<(1<<n);b++)
        {
        hey=0;
        for (i=0;i<n;i++)
            if (b&(1<<i))
                {
                alo[b].push_back(i);
                hey++;
                }
        v[hey].push_back(b);
        }
    for (b=1;b<(1<<n);b++)
        for (i=0;i<alo[b].size();i++)
            for (j=i+1;j<alo[b].size();j++)
                pre[b]+=mas[alo[b][i]][alo[b][j]];
           // cout<<"PL"<<endl;
    for (k=2;k<=n;k++)
        {
       // cout<<k<<endl;
        for (i=0;i<v[k].size();i++)
            {
            b=v[k][i];
            for (j=0;(j+1)<(1<<k);j++)
                {
                s=0;
                for (t=0;t<k;t++)
                    if (j&(1<<t))
                        s+=(1<<alo[b][t]);
                dp[b]=max(dp[b],dp[s]+pre[b-s]);    
                }
            }
        }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
    }



Measured memory_bytes: 34048
#include <iostream>

using namespace std;

int main()
{
    int M, N, i;
    cin >> N >> M;
    int a[N];
    double sum = 0.0;
    int cnt = 0 ;
    for(i=0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    // cout << a[2] << " " <<sum << endl;
    double tmp = sum / (4 * M);
    // cout << tmp << endl;
    for(i=0;i < N ; i++){
        if(a[i] >= tmp){
            cnt += 1;
        }
    }
    if(cnt >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;        
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;


void solve(){
	int a,b,c;
	cin >> a >> b >> c;
	for(int i =0;i<=200;i++){
		int x  = a*i;
		x %=b;
		if(x == c){
			cout<<"YES\n";
			return;
		}
	}
	cout<<"NO\n";
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define elif else if
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

const int N = 3e5, M = N;
//=======================
void solve() {
 int a;
  cin >> a;
  cout << a + a*a + a*a*a;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}




Measured memory_bytes: 3628
n = int(input())
num = list(map(int, input().split()))
limit = 10**18
 
num.sort()
result = num[0]

if result == 0:
    print(0)
else:
    for i in num[1:]:
        result *= i
        if result > limit:
            print(-1)
            exit()

    print(result)

Measured memory_bytes: 84644
from scipy.sparse import*;(n,m),*d=[map(int,o.split())for o in open(0)];*w,a=zip(*[(i,j+n-1,1)for i,(_,*d)in enumerate(d)for j in d]);print("YNEOS"[1in csgraph.connected_components(csr_matrix(((a,w)),[n+m]*2))[1][:n]::2])

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int h, w;
vector<int> r(105, 0);
vector<int> c(105, 0);
string s[105];

signed main()
{
	IOS;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				r[i] = 1;
				c[j] = 1;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		if (r[i]) {
			for (int j = 0; j < w; j++) {
				if (c[j]) {
					cout << s[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];

    ll ans = 1e14;
    rep(i,n-k+1){
        ll right = x[n-1-i];
        ll left = x[n-i-k];
        ll tmp =0;
        
        if (left >= 0) tmp = right;
        else if(right <= 0) tmp = abs(left);
        else{
            if(abs(left) >= right)tmp = right*2+abs(left);
            else tmp = right+abs(left)*2;
        }

        ans = min(ans,tmp);
    }

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


Measured memory_bytes: 1024
//ヘッダー
#include<bits/stdc++.h>
using namespace std;
 
//型定義
typedef long long ll;
 
//定数
const int INF=1e+9;
const int MOD=1e+9+7;
 
//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)
 
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
 
//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値
 
int N,M,Q;
 
ll ans=0;
void dfs(vector<int> &A,vector<int> a,vector<int> b,vector<int> c,vector<int> d){
    if(A.size()==N){
        ll tmp=0;
        for(int i=0;i<Q;i++){
            if(A[b[i]]-A[a[i]]==c[i]) tmp+=d[i];
        }
        ans=max(ans,tmp);
        return;
    }
 
    if(A.size()==0){
        for(int v=0;v<M;++v){
            A.push_back(v);
            dfs(A,a,b,c,d);
            A.pop_back();
        }
    }else{
        for(int v=A[A.size()-1];v<M;++v){
            A.push_back(v);
            dfs(A,a,b,c,d);
            A.pop_back();
        }
    }
    
 
}
int main(){
    cin>>N>>M>>Q;
    vector<int> a(Q),b(Q),c(Q),d(Q);
    REP(i,Q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    
    //全探索
    vector<int> A;
    dfs(A,a,b,c,d);
    cout<<ans<<endl;
 
    
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vi32 a(n);
  vi32 sums(n);
  reps(i, n - 1) {
    int c = 0;
    while (i % exp(2, c + 1) == 0) c += 1;
    sums[i] = c;
    sums[i] += sums[i - 1];
  }
  rep(i, n) a[i] = s[i] - '1';
  auto f = [&](vi32 a) {
    int n = sz(a);
    int acc = 0;
    rep(i, n) {
      if (sums[n - 1] == sums[i] + sums[n - 1 - i]) {
        acc += a[i] & 1;
        acc %= 2;
      }
    }
    return acc;
  };
  if (f(a)) {
    cout << 1 << endl;
    return;
  }
  bool one = false;
  rep(i, n) one |= a[i] == 1;
  if (one) {
    cout << 0 << endl;
    return;
  }
  rep(i, n) a[i] >>= 1;
  cout << f(a) * 2 << endl;
}


Measured memory_bytes: 13084
import java.util.Scanner;
import java.util.ArrayList;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      
      	int N = sc.nextInt();
      	int M = sc.nextInt();
        int C = sc.nextInt();
      	
      	// 要素M個のBを入力する
        ArrayList<Integer> B = new ArrayList<Integer>();
      	for (int i=0; i<M; i++) {
         	B.add(sc.nextInt()); 
        }
      
      	
      	int total = 0;
      	int count = 0;
      	int A = 0;
      	for (int i=0; i<N; i++) {
          	total = 0;
        	for (int j=0; j<M; j++) {
            	A = sc.nextInt();
              	total += A * B.get(j);
            }
          	total += C;
          	if (total > 0) {
            	count++;
            }
        }
      
      	System.out.println(count);
    }
}

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

ll const MOD = 2019;
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % MOD;
      a = a * a % MOD;
      n >>= 1;
  }
  return res;
}

int main() {
    string s;
    std::cin >> s;
    ll n = s.size();
    map<ll,ll> cnt;

    ll last = 0;
    cnt[last]++;

    for (int i = 0; i < n; i++) {
        last += modpow(10,i)*(s[n-1-i]-'0')%MOD;
        last %= MOD;
        cnt[last]++;
    }
    
    ll ans = 0;
    for (auto e : cnt) {
        ans += e.second*(e.second-1)/2;
    }
    
    std::cout << ans << std::endl;
}



Measured memory_bytes: 3756
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
#define N 1000015
int n,m,b[5002][202],pre[N],nxt[N],s[N],tot;
ll c[5002][5002],a[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=2;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&b[i][j]);
	for(int i=1;i<=m;i++)
	{tot=0;
		for(int j=1;j<=n;j++)
		{
			while(tot&&b[s[tot]][i]<=b[j][i])nxt[s[tot]]=j,tot--;
			s[++tot]=j;
		}
		while(tot)nxt[s[tot]]=n+1,tot--;tot=0;
		for(int j=n;j;j--)
		{
			while(tot&&b[s[tot]][i]<b[j][i])pre[s[tot]]=j,tot--;
			s[++tot]=j;
		}
		while(tot)pre[s[tot]]=0,tot--;
		for(int j=1;j<=n;j++)
		{
			c[pre[j]+1][j]+=b[j][i];
			c[j+1][j]-=b[j][i];
			c[pre[j]+1][nxt[j]]-=b[j][i];
			c[j+1][nxt[j]]+=b[j][i];
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)c[i][j]+=c[i][j-1];
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)c[i][j]+=c[i-1][j];
	ll ans=0;
	for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)ans=max(ans,c[i][j]-(a[j]-a[i]));
	printf("%lld\n",ans);
}


Measured memory_bytes: 209024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        boolean[] a = new boolean[26];
        char[] chars = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        
        for (int i = 0; i < s.length(); i++) {
            a[(int)s.charAt(i)-97] = true;
        }
        
        String ans = "None";
        for (int i = 0; i < 26; i++) {
            if (a[i] == false) {
                ans = String.valueOf(chars[i]);
                break;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;
typedef long long ll;
int main()
{
    ll n , t , x , y , k, m ;
    cin >> n >> x >> y;
    k=(n/x);
    if(n%x!=0)
    {
        k++;
    }
    cout << k*y ;
    return 0;
}


Measured memory_bytes: 3592
N, M = gets.split(' ').map(&:to_i)
MOD = 10 ** 9 + 7
rootM = M ** 0.5

def nCr(n, r)
  return 1 if r == 0 || r == n
  ans = 1
  1.upto(r) do |i|
    ans *= (n - i + 1)
    ans /= i
  end
  return ans % MOD
end

m = M
pl = []
cnt = 0
k = 2
while true
  if m % k == 0
    m /= k
    cnt += 1
  else
    pl.push(cnt)
    k += 1
    cnt = 0
    break if m == 1
  end
  if k > rootM && m > 1
    pl.push(1)
    break
  end
end

puts pl.collect{|n| nCr(N - 1 + n, n)}.inject{|x, y| (x * y) % MOD} % MOD

Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
bool f[5001][5001];
int main()
{
	bool flag=0;
	char a[10000];
	gets(a);
	int len=strlen(a);
	for(int i=0;i<len;i++)
	{
		if(a[i]=='C')
		{
			for(int j=i+1;j<len;j++)
			{
			if(a[j]=='F')
			{
				cout<<"Yes"<<endl;
				return 0;
			}
				
			}
		}
	}
	cout<<"No"<<endl;
	                       
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define pb push_back
const ll mod=1e9+7;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
int a[55];
int main(int argc, char** argv) {
	int n;
	cin>>n;
	int fgz=0,fgf=0,mx=0,mn=0,bg,sm;
	rep(i,1,n)
	scanf("%d",&a[i]);
	rep(i,1,n)
	{
		if(a[i]>0)fgz=1;
		if(a[i]<0)fgf=1;
		if(a[i]>=mx)bg=i;
		mx=max(mx,a[i]);
		if(a[i]<=mn)sm=i;
		mn=min(mn,a[i]);
	}
	if(!fgf&&!fgz)
	{
		cout<<0;
	}
	vector<pair<int,int> >ans;
	if(!fgz&&fgf)
	{
		printf("%d\n",n-1);
		rep2(i,n-1,1)
		{
			printf("%d %d\n",i+1,i);
		}
	}
	if(fgz&&!fgf)
	{
		printf("%d\n",n-1);
		rep(i,2,n)
		{
			printf("%d %d\n",i-1,i);
		}
	}
	if(fgz&&fgf)
	{
		if(abs(mx)>=abs(mn))
		{
			rep(i,1,n)
			{
				if(i==bg)continue;
				ans.pb({i,bg});
			}
			rep(i,2,n)
			{
				ans.pb({i,i-1});
			}
			cout<<ans.size()<<endl;
			rep(i,0,ans.size()-1)cout<<ans[i].second<<" "<<ans[i].first<<endl;
		}
		if(abs(mx)<abs(mn))
		{
			rep(i,1,n)
			{
				if(i==sm)continue;
				ans.pb({i,sm});
			}
			rep2(i,n-1,1)
			{
				ans.pb({i,i+1});
			}
			cout<<ans.size()<<endl;
			rep(i,0,ans.size()-1)cout<<ans[i].second<<" "<<ans[i].first<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a;
    rep(i,n){
        int t;cin>>t;
        a.push_back(t);
    }
    bool win = false;
    // 全部2の倍数だとlose = 奇数があれば勝ち
    for(auto t : a){
        if(t%2 == 1) win=true;
    }

    cout<< (win? "first":"second")<<endl;
}

Measured memory_bytes: 892
from itertools import product

n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

cnt = 0
for pat in product([0, 1], repeat=n):
    for i, ksi in enumerate(ks):
        tmp = sum(pat[ksi[j + 1] - 1] for j in range(ksi[0]))
        if  tmp % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 9156
#include<stdio.h>
#include<string.h>
int main(){
	int m,n,p,f=0,i,j;
	scanf("%d %d",&m,&n);
	char l;
	char s[m][n][5], s1[8];
	strcpy(s1,"snuke");
	for( i=0;i<m;i++){
		for( j=0;j<n;j++){
			scanf("%s",s[i][j]);
			if(f==0){
				int k;
				for( k=0;k<5;k++){
					if(s[i][j][k]!=s1[k]){
							break;
					}
				}
				if(k==5){
					f=1;
					p = i;
					l = j;
				}
			}
		}
	}
	printf("%c%d\n",l+65,p+1);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    
    List<Character> list1 = new ArrayList<>();
    List<Character> list2 = new ArrayList<>();
    for(int i = 0; i < S.length(); i++){
      list1.add(S.charAt(i));
    }
    for(int i = 0; i < T.length(); i++){
      list2.add(T.charAt(i));
    }
    
    Collections.sort(list1);
    Collections.sort(list2, Collections.reverseOrder());
    
    String s = "";
    String t = "";
    for(int i = 0; i < S.length(); i++){
      s = s + String.valueOf(list1.get(i));
    }
    for(int i = 0; i < T.length(); i++){
      t = t + String.valueOf(list2.get(i));
    }
    
    
    System.out.println(s.compareTo(t) < 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main(){
 
	int H, W;
  
  	while(true){
    	cin >> H >> W;
      	
      	if(H==0 && W==0)
          break;
      
      	for(int j=0; j<H; j++){
        	for(int i=0; i<W; i++){
            	if((j%2==0 && i%2==0) || (j%2!=0 && i%2!=0)){
                	cout << "#";
                }
              	else
                  cout << ".";
            }
          cout << endl;
        }
      cout << endl;
    }
  
  return 0;
}


Measured memory_bytes: 3080
#include <cstdio>
#include <queue>
#include <iostream>
using namespace std;

int main() {
    priority_queue<char, vector<char>, greater<char> > que_s;
    priority_queue<char> que_t;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.length(); i++) {
        que_s.push(s[i]);
    }
    for (int i = 0; i < t.length(); i++) {
        que_t.push(t[i]);
    }
    while(!que_s.empty() && !que_t.empty()) {
        if (que_s.top() > que_t.top()) {
            printf("No\n");
            return 0;
        }else if (que_s.top() < que_t.top()) {
            printf("Yes\n");
            return 0;
        }
        que_s.pop(); que_t.pop();
    }
	if (que_s.size() < que_t.size()) printf("Yes\n");
	else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <atcoder/all>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3000000;
const int K = 100000;
const int mod = 1e9 + 7;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, d;
    cin >> n >> d;
    two_sat ts(2 * n);
    vector <int> a(2 * n);
    for (int i = 0; i < n; i++){
        cin >> a[2 * i] >> a[2 * i + 1];
        ts.add_clause(2 * i, true, 2 * i + 1, true);
        ts.add_clause(2 * i, false, 2 * i + 1, false);
    }
    int l = 0;
    for (int i = 0; i < a.size(); i++){
        for (int j = i + 1; j < a.size(); j++){
            if (abs(a[i] - a[j]) < d){
                ts.add_clause(i, false, j, false);
            }
        }
    }
    bool ans = ts.satisfiable();
    if (ans){
        cout << "Yes" << endl;
        vector <bool> res = ts.answer();
        for (int i = 0; i < 2 * n; i++){
            if (res[i]){
                cout << a[i] << endl;
            }
        }
    } else{
        cout << "No";
    }
}


Measured memory_bytes: 3808
// 2012/02/03 Tazoe

#include <iostream>
using namespace std;

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

	int S[100001];		// ツ宿ツ湘ェツ陳ャ1ツつゥツづァツづ個仰猟猟」ツ（100000ツづ環づつスツ余ツづィツ）
	S[1] = 0;
	for(int i=2; i<=n; i++){
		int s;
		cin >> s;

		S[i] = (S[i-1]+s)%100000;
	}

	int sum = 0;
	int x = 1;
	for(int i=0; i<m; i++){
		int a;
		cin >> a;

		if(a>0){
			sum += (S[x+a]+100000-S[x]);
			x += a;
		}
		else{
			a = -a;
			x -= a;
			sum += (S[x+a]+100000-S[x]);
		}

		sum %= 100000;
	}

	cout << sum << endl;

	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
ll D;
ll A[202020];
ll L[202020],R[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>D;
	ll ret=0;
	FOR(i,N) {
		cin>>A[i];
		ret+=A[i];
		
		L[i]=max((i?L[i-1]:-1LL<<60),i*D-A[i]);
	}
	ret+=(N-1)*D;
	
	for(i=N-1;i>=0;i--) {
		R[i]=min((i<N-1?R[i+1]:1LL<<60),i*D+A[i]);
		if(i>0 && i<N-1) ret+=min(i*D-L[i],R[i]-(i*D));
	}
	
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		
		if(N==100){N++;}
		
		switch(D){
		case 2:
			N*=100;
		case 1:
			N*=100;
		case 0:
		default: 
			break;
		
		}
		System.out.println(N);
	}
}

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

using namespace std;

const int N = 3e5 +1 , mod = 1e9 +7 ;

int main()
{
    set<int> s;
    for(int i = 0;i<3;i++)
    {
        int t;
        cin>>t;
        s.insert(t);
    }
    if(s.size()==2)
        cout<<"Yes";
        else cout<<"No";
    return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    int a[n][m],b[m],c=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int j=0;j<n;j++){
        for(int k=0;k<m;k++){
            c+=a[j][k]*b[k];
        }
        cout<<c<<endl;
        c=0;
    }

    return 0;
}


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

using namespace std;

int main() {
    int n, x, cnt = 0;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a.at(i);
    sort(a.begin(), a.end());
    for (int i = 0; i < n - 1; ++i) {
        x -= a.at(i);
        if (x < 0) break;
        ++cnt;
    }
    if (x == a.back()) ++cnt;
    cout << cnt << endl;
    return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "YES";
const string NO = "NO";

int main(){
    string s, t;
    cin >> s >> t;
    int sn = sz(s), tn = sz(t);
    vector<vi> sums(2, vi(sn+1)), sumt(2, vi(tn+1));
    rep(i, sn) {
        sums[0][i+1] = sums[0][i] + (s[i]=='A'?1:0);
        sums[1][i+1] = sums[1][i] + (s[i]=='B'?1:0);
    }
    rep(i, tn) {
        sumt[0][i+1] = sumt[0][i] + (t[i]=='A'?1:0);
        sumt[1][i+1] = sumt[1][i] + (t[i]=='B'?1:0);
    }
    int q;
    cin >> q;
    rep(i, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a; --b; --c; --d;
        int snum = (sums[0][b+1]-sums[0][a])%3+(3-(sums[1][b+1]-sums[1][a])%3+3)%3;
        int tnum = (sumt[0][d+1]-sumt[0][c])%3+(3-(sumt[1][d+1]-sumt[1][c])%3+3)%3;
        if (snum%3==tnum%3) cout << YES << endl;
        else cout << NO << endl;
    }
    return 0;
}


Measured memory_bytes: 5540
import java.lang.reflect.Array;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int []v=new int[n];
		int []c=new int[n];
		int []ans=new int[n];
		int k=0;
		for(int i=0;i<n;i++) {
			v[i]=sc.nextInt();
		};
		for(int i=0;i<n;i++) {
			c[i]=sc.nextInt();
		};
		
		for(int i=0;i<n;i++) {
			ans[i]=v[i]-c[i];
		}
		Arrays.sort(ans);
		for(int i=0;i<n;i++) {
			if(ans[i]<0) {
				;
			}else {
				k+=ans[i];
			}
			
		}
		
		System.out.println(k);
	}

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
const ll mod = 1000000007;
int main(){
    int n=in();
    vec a(n);
    rep(i,n)a[i]=in();
    vec num(n);
    ll ans=1;
    int cnt_0 = 3;
    REP(e,a){
        num[e]++;
        if(e==0){
            ans*=cnt_0;
            cnt_0--;
        }else{
            ans*=num[e-1];
            num[e-1]--;
        }
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N

    r = []
    for i in reversed(range(N)):
        t = sum(B[i::i + 1]) & 1
        B[i] = abs(A[i] - t)
        if B[i]:
            r.append(i)
    print(len(r))
    if r:
        print(' '.join(str(i + 1) for i in r))

main()


Measured memory_bytes: 19944
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF 1e9+1
#define endl '\n'

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

//struct cmp {
//	bool operator() (int a, int b)
//	{
//		return a > b;
//	}
//};

int main()
{
    IOS;
    int a, b;
    cin >> a >> b;
    cout << max(a - 2 * b, 0);
    return 0;
}

Measured memory_bytes: 3644
while True:
    a, op, b = map(str, input().split(" "))
    if op == "?":
        break
    a, b = int(a), int(b)
    if op == "+":
        c = a + b
    elif op == "-":
        c = a - b
    elif op == "*":
        c = a * b
    else:
        c = a // b
    print(c)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 2e5+5;
ld val[N];

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, k; cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int t; cin >> t;
    val[i] = ((ld) t+1) / 2.0;
  }
  ld ans = 0;
  ld cur = 0;
  queue<ld> past;
  for (int i = 0; i < n; ++i) {
    cur += val[i];
    past.push(val[i]);
    if (past.size() > k) {
      cur -= past.front();
      past.pop();
    }
    if (past.size() == k) {
      ans = max(ans, cur);
    }
  }
  cout << ans << nl;
  return 0;
}



Measured memory_bytes: 6656