akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    vector<ll> S(n + 2);
    S[0] = 0;
    for(int i = 0; i <= n; ++i){
        a[i] = i;
        S[i + 1] = S[i] + a[i];
    }
    modint ans = 0;
    for(int i = k; i <= n + 1; ++i){
        ll low = S[i], high = S[n + 1] - S[n + 1 - i];
        ans += high - low + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5584
'use strict'

const gcd = (a, b) => {
    const r = a % b
    if(r === 0){
        return b
    }
    return gcd(b, r)
}

const main = (input) => {
    input = input.split('\n')
    const n = parseInt(input[0].split(' ')[0])
    const x = parseInt(input[0].split(' ')[1])
    const arr = input[1].split(' ').map(v => {
        return Math.abs(parseInt(v) - x)
    }).sort((a, b) => a - b)
    console.log(arr.reduce((p, c) => gcd(p, c)))
    
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> cnt(n, 0);
    for (int i = 1; i < n; ++i) {
        int a;
        cin >> a;
        --a;
        cnt[a]++;
    }

    for (int i = 0; i < n; ++i) {
        cout << cnt[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
	int n;cin>>n;
    std::vector<int> cnt(n+1);
    for(int i=1;i<=n;i++) {
    	for(int j=i;j<=n;j+=i)
    		cnt[j]++;
    }
    ll ans=0;
    for(int i=n-1;i>=1;i--) {
    	ans+=cnt[n-i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7160
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n ;i++){
			char [] temp = sc.next().toCharArray();
			int num[] = new int[temp.length];
			for(int j = 0; j < temp.length; j++){
				num[j] = temp[j] -'0';
			}
			Arrays.sort(num);
			String ans = "";
			for(int j:num){
				ans += String.valueOf(j);
			}
			StringBuilder sb = new StringBuilder(ans);
			System.out.println(Integer.parseInt(sb.reverse().toString())-Integer.parseInt(ans));
		}
	}
}

Measured memory_bytes: 26152
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    ll n; cin >> n;
    ll ans = 1000;
    ll kb = 0;
    vector<ll> ar(n+2);
    rep(i,n) cin >> ar[i+1];
    ar[0] = ar[2];
    ar[n+1] = ar[n-1];
    int s = 0;
    int g = n;
    for (ll i = n; i > 0; i--){
        if (ar[i-1] <= ar[i] && ar[i] >= ar[i+1]){
            g = i;
            break;
        }       
    }
    repl(i,n){
        if (ar[i] >= ar[i+1] && ar[i+1] <= ar[i+2]){
            s = i;
            break;
        }
    }
    if (s > g) {cout << ans << endl; return 0;}
    vector<ll> al;
    repp(i,g+2,s) al.emplace_back(ar[i]);
    n = al.size() - 2;
    rep(i,n){
        if (al[i] <= al[i+1] && al[i+1] >= al[i+2]){
            ans += kb * al[i+1];
            kb = 0;
        }
        if (al[i] >= al[i+1] && al[i+1] <= al[i+2]){
            kb += ans / al[i+1];
            ans %= al[i+1];
        }
    }
    ans += kb * al[n];
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

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

    int ans = 0;
    REP(i, n) {
        int h; cin >> h;
        if (h >= k) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string S,T;
    cin >> S >> T;
    ll N = S.size();
    ll M = T.size();
    vector<vector<ll>> v(26);
    rep(i,N){
        v[S[i] - 'a'].push_back(i);
    }
    rep(i,N){
        v[S[i] - 'a'].push_back(i+N);
    }
    ll ans = 0;
    ll tmp = 0;
    rep(i,M){
        ll c = T[i] - 'a';
        if(v[c].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        tmp = *lower_bound(v[c].begin(), v[c].end(), tmp)+1;
        if(tmp >= N){
            tmp -= N;
            ans += N;
        }
    }
    ans += tmp;
    cout << ans << endl;
}
    /*
    rep(i,M){
        if(v[T[i] - 'a'].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        tmp = v[T[i] - 'a'].front();
        v[T[i] - 'a'].pop();
        if(ans < tmp){
            ans = tmp;
            v[T[i] - 'a'].push(tmp);        
        }else{
            bool flag = false;
            if(ans-tmp < N){
                rep(j,v[T[i] - 'a'].size()){
                    v[T[i] - 'a'].push(tmp);        
                    tmp = v[T[i] - 'a'].front();
                    v[T[i] - 'a'].pop();
                    if(ans < tmp){
                        ans = tmp;
                        v[T[i] - 'a'].push(tmp);
                        flag = true;
                        break;
                    }
                }
            }
            if(flag)continue;
            ll q = (ans-tmp)/N + 1;
            ans = tmp + q*N;
            v[T[i] - 'a'].push(tmp);        
        }
    }
    cout << ans+1 << endl;
}*/

Measured memory_bytes: 2800
N,Q=map(int,input().split())

S=input()

# 最初からNまでに何個ACがあったか
cnt=[0 for _ in range(N)]

prev=""

for i in range(N):
	if S[i]=="C":
		if prev=="A":
			cnt[i]+=1
	if i!=0:
		cnt[i]+=cnt[i-1]
	prev = S[i]

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = cnt[R-1]-cnt[L-1]
 	print(ans)


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N,K;
    cin >> N >> K;

    int ans = 1;
    for (int i = 0; i < N; ++i) {
        if (ans * 2 < ans + K) {
            ans *= 2;
        } else {
            ans += K;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static long divNum(long a, long x){
        return 1 + a/x;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        if(a<=0) System.out.println(divNum(b,x));
        else System.out.println(divNum(b,x)-divNum(a-1,x));
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>
int main(){
  int x,y;
  char a[11],b[11],c[11];
  scanf("%s %s %s",a,b,c);
  x=strlen(a);
  y=strlen(b);
  (a[x-1]==b[0] && b[y-1]==c[0])? puts("YES"):puts("NO");
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0554

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    times = [int(input()) for x in range(4)]
    total_time = sum(times)

    print(total_time // 60)
    print(total_time % 60)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7756
#include<iostream>
#include<string>
#include<vector>

using namespace std;

typedef long long ll;

int N;
int lenga[200000 + 100];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> lenga[i];

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (cnt + 1 == lenga[i]) {
			cnt++;
		}
	}
	if (cnt == 0) {
		cout << -1 << endl;
	}
	else {
		cout << N - cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

double dp[3010][3010], p[3010];

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

  int n;
  cin >> n;
  REP(i, n) cin >> p[i];

  REP(i, n) REP(j, n) dp[i][j] = 0;
  
  //dp[i][j] := i番目までのコインを使って、表がjの場合の確率
  //REP(i, n) dp[0][i] = 1;
  dp[0][0] = 1;
  REP(i, n){
    //jは0~i番目まで
    REP(j, i+1){
      //i番目が表
      dp[i+1][j+1] += dp[i][j] * p[i];
      //i番目が裏
      dp[i+1][j] += dp[i][j] * (1-p[i]);
    }
  }

  double ans = 0.0;
  FOR(i, n/2+1, n+1) ans += dp[n][i];  
  cout << setprecision(10) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 70784
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

// Range Sum Query
class SegmentTree{
public:
    int n;
    vector<ll> node;

    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void add(int x, ll val){
        x += (n - 1);
        node[x] += val;
        while(0 < x){
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];

        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);

        return vl + vr;
    }
};

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

    ll n, k; cin>>n>>k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<ll> b(n+1, 0);
    ll asum = 0;
    set<ll> st;
    st.emplace(0);
    for(int i=0; i<n; i++){
        asum += a[i];
        b[i+1] = asum - k * (i + 1);
        st.emplace(b[i+1]);
    }

    int id = 0;
    map<ll, ll> b2id;
    for(auto i:st) b2id[i] = id++;

    for(int i=0; i<=n; i++){
        b[i] = b2id[b[i]];
    }

    SegmentTree seg(vector<ll>(n+1, 0));
    ll ans = 0;
    for(int i=n; i>=0; i--){
        ans += seg.getsum(b[i], n + 1);
        seg.add(b[i], 1);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int N;
    string S,T;
    cin >> N;
    cin >> S >> T;
    int ans;
    for(ans=N;ans>=0;ans--){
        bool flag=true;
        for(int j=0;j<ans;j++){
            if(S[j+N-ans]!=T[j]){
                flag=false;
                break;
            }
        }
        if(flag){
            break;
        }
    }
    
    cout << 2*N-ans << endl;
    
    return 0;
}


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

using namespace std;
using namespace atcoder;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	int N,Q;
	cin >> N >> Q;
	dsu ds(N);
	while (Q--) {
		int t, v, u;
		cin >> t >> v >> u;

		if (t) {
			cout << ds.same(u, v) << endl;
		}
		else {
			ds.merge(u, v);
		}
	 }



	return 0;
}



Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
string s,tt;
long long k;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s>>k;
	tt=s+s;
	long long x=0LL,t=0LL,z=0LL,w=0LL;
	bool as=1;
	for(int i=1;i<s.size();i++)
		if(s[i]!=s[i-1])
			as=0;
	if(as){
		cout<<(long long)(s.size())*k/2<<endl;
		return 0;
	} 
	int cut,cu2;
	long long cur=0;
	for(int i=s.size();i<tt.size();i++){
		if(tt[i]!=tt[i-1]){
			cut=i-s.size();
			break;
		}
	}
	t=(cut)/2;
	cur=1;
	for(int i=cut+s.size()-2;i>=0;i--){
		if(tt[i]==tt[i+1]){
			cur++;
		}
		else{
			x+=cur/2;
			cu2=i;
			break;
		}
	}
	cur=1;
	for(int i=cut+1;i<=cu2;i++)
	{
		if(s[i]==s[i-1])
			cur++;
		else{
			z+=cur/2;
			cur=1;
		}
	}
	z+=cur/2;
	cur=1;
	for(int i=cu2+2;i<s.size();i++){
		if(s[i]==s[i-1])
			cur++;
		else{
			w+=cur/2;
			cur=1;
		}
	}
	w+=cur/2;
	cout<<t+z*k+x*(k-1)+w<<endl;
	return 0;
}


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

using namespace std;

int main(){
    vector<long long> a(7);
    for(int i = 0; i < 7; i++){
        cin >> a[i];
    }
    long long ans = 0;
    ans += a[0] & -2LL;
    ans += a[1];
    ans += a[3] & -2LL;
    ans += a[4] & -2LL;
    long long ans2 = 0;
    if(a[0] > 0 && a[3] > 0 && a[4] > 0){
        ans2 += 3;
        a[0]--; a[3]--; a[4]--;
    }
    ans2 += a[0] & -2LL;
    ans2 += a[1];
    ans2 += a[3] & -2LL;
    ans2 += a[4] & -2LL;
    cout << max(ans, ans2) << endl;
    return 0;
}


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

using namespace std;

int dp[(1<<15)+1][201][4];
int dfs(int n,int last,int idx){
    if(n==0)return 1;
    if(dp[n][last][idx]!=-1)return dp[n][last][idx];
    if(idx==4)return 0;
    int sum=0;
    for(int i=last;i<=200;i++){
        if(n-i*i>=0)
            sum+=dfs(n-i*i,i,idx+1);
    }
    return dp[n][last][idx]=sum;
}

int main(){
    int n;
    while(cin>>n&&n!=0){
        //memset(dp,-1,sizeof(dp));
        //int cnt=dfs(n,1,0);
        int cnt=0;
        for(int i=0;i*i<=n;i++){
            for(int j=i;j*j+i*i<=n;j++){
                for(int k=j;k*k+j*j+i*i<=n;k++){
                    for(int l=k;l*l+j*j+k*k+i*i<=n;l++){
                        int sum=i*i+j*j+k*k+l*l;
                        if(sum==n)
                            cnt++;
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

int main() {
  long long int N,A,B;
  long long int ab,times,rem;
  cin>>N>>A>>B;
  
  ab=A+B;
  if(ab!=0){
    times=N/ab;
    rem=N%ab;
  }
  else{
    times=0;
    rem=0;
  }
  
  if(A==0){
    cout<<"0"<<endl;
  }
  else if(B==0 && !(A==0)){
    cout<<N<<endl;
  }
  else{
    if(rem<A){
      cout<<A*times+rem<<endl;
    }
    else{
      cout<<A*times+A<<endl;
    }
  }

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(input())[: -1] for _ in range(H)]
c = H + W - 1
class FordFulkerson:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def dfs(self, v, t, f):
        if v == t:
            return f
        used = self.used
        used[v] = 1
        for e in self.G[v]:
            w, cap, rev = e
            if cap and not used[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        f = INF = c
        N = self.N
        while f:
            #print(f)
            self.used = [0]*N
            f = self.dfs(s, t, INF)
            flow += f
        return flow
flk = FordFulkerson(H * W * 2 + H + W + 1)
b = H * W
s = 0
t = 0
for i in range(H):
  for j in range(W):
    if a[i][j] != ".":
      flk.add_edge(b + i * W + j, b * 2 + i, c)
      flk.add_edge(b * 2 + i, i * W + j, c)
for j in range(W):
  for i in range(H):
    if a[i][j] != ".":
      flk.add_edge(b + i * W + j, b * 2 + H + j, c)
      flk.add_edge(b * 2 + H + j, i * W + j, c)
for i in range(H):
  for j in range(W):
    if a[i][j] != ".":
      flk.add_edge(i * W + j, b + i * W + j, 1)
    if a[i][j] == "S": s = b + i * W + j
    if a[i][j] == "T": t = i * W + j
if (s - b) % W != t % W and ((s - b) // W != t // W):
  if sum([x.count("o") for x in a]) == H * W - 2: print(min(H, W) * 2 - 2)
  else: print(flk.flow(s, t))
else: print(-1)


Measured memory_bytes: 83292
s = input()
t = input()
S = [c for c in s]
T = [c for c in t]
m = len(T)
for i in range(len(S)-len(T)+1):
  temp = 0
  for j in range(i,i+len(T)):
    if S[j] != T[j-i]:
      temp += 1
  if temp<m:
    m=temp
print(m)

Measured memory_bytes: 9132
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	long i=0,n,l,s,r;
	string str;
	cin>>str;
	n=str.size();
	vector<long> chi(n,0);
	while(i<n){
		l=i;
		while(str.at(i)=='R'){
			i++;
		}
		s=i;
		while(str.at(i)=='L'){
			i++;
			if(i==n){
				break;
			}
		}
		r=i-1;
		//cout<<l<<s<<r<<endl;
		chi.at(s-1)+=(s-l)/2+(s-l)%2;
		chi.at(s)+=(s-l)/2;
		chi.at(s-1)+=(r-s+1)/2;
		chi.at(s)+=(r-s+1)/2+(r-s+1)%2;
	}
	cout<<chi.at(0);
	for(i=1;i<n;i++){
		cout<<" "<<chi.at(i);
	}
	return 0;
}



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

int a[100002];

int main(void){
	int n,k;

	while(cin>>n>>k,n){
		for(int i=0;i<n;i++) cin>>a[i];

		int left=0, right=0, sum=0, ans=-999999999;

		while(right<n){
			while(right-left<k) sum += a[right++];
			ans = max(ans,sum);
			sum -= a[left++];
		}

		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int r,c;
	cin >> r >> c;
	vector<vector<int>> mx(r+1,vector<int>(c+1));

	for(int i = 0;i<r;i++)
	{
		for(int j = 0;j<c;j++)
		{
			cin >> mx[i][j];
		}
		int sum = 0;
		for(int j = 0;j<c;j++)
		{
			sum += mx[i][j];
		}
		mx[i][c] = sum;
	}
	
	
	for(int j = 0;j<c+1;j++)
	{int sum = 0;
		for(int i = 0;i<r;i++)
		{
			sum+=mx[i][j];
		}
		mx[r][j]=sum;
	}
	//cout<<0<<endl;
	for(int i =0;i<r+1;i++)
	{
		for(int j = 0;j<c+1;j++)
		{
			if(j)cout<<' ';
			cout<<mx[i][j];
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 3152
program main
implicit none
integer(8) :: i, j, k
integer(8) :: n
integer(8) , allocatable :: a(:)

read(*,*) n
allocate(a(n))
read(*,*) a
k = 0
do i = 1, n
   j = a(i)
   do while( mod(j,2) == 0 )
      k = k + 1
      j = j/2
   end do
end do
write(*,'(i0)') k

end program main


Measured memory_bytes: 384
use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let _n = input!(u32);
    let mut a = input!(u32,);
    let mut num = 0;
    for i in &mut a {
        while *i % 2 == 0 {
            *i /= 2;
            num += 1;
        }
    }
    println!("{}", num);
}


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

int main(){
  int N;
  ll a,b,c;
  cin >> N >> a >> b >> c;
  vector<string> ans, s(N+1);
  int ng = 0;
  REP(i,N) cin >> s[i];
  s[N] = "ZZ";

  REP(i,N) {
    if ( s[i] == "AB" ) {
      if (a == b) {
        if (a == 0) {
          ng = 1;
          break;
        } else {
          if ( (s[i+1][0] == 'A') || (s[i+1][1] == 'A')) {
            a++; b--;
            ans.push_back("A");
          } else {
            a--; b++;
            ans.push_back("B");
          }
        }
      } else if (a>b) {
        a--; b++;
        ans.push_back("B");
      } else {
        a++; b--;
        ans.push_back("A");
      }
    } else if ( s[i] == "BC" ) {
      if (b == c) {
        if (b == 0) {
          ng = 1;
          break;
        } else {
          if ( (s[i+1][0] == 'B') || (s[i+1][1] == 'B')) {
            b++; c--;
            ans.push_back("B");
          } else {
            b--; c++;
            ans.push_back("C");
          }
        }
      } else if (b>c) {
        b--; c++;
        ans.push_back("C");
      } else {
        b++; c--;
        ans.push_back("B");
      }
    } else {
      if (a == c) {
        if (a == 0) {
          ng = 1;
          break;
        } else {
          if ( (s[i+1][0] == 'A') || (s[i+1][1] == 'A')) {
            a++; c--;
            ans.push_back("A");
          } else {
            a--; c++;
            ans.push_back("C");
          }
        }
      } else if (a>c) {
        a--; c++;
        ans.push_back("C");
      } else {
        a++; c--;
        ans.push_back("A");
      }
    }
//    cout << a << " " << b << " " << c << endl;
//    cout << s[i] << endl;
//    for ( auto sv : ans ) cout << sv << " "; cout << endl;
  }
  if ( ng == 1 ) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for ( auto sv : ans ) {
      cout << sv << endl;
    }
  }
}


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

const int maxn = 1e5 + 10;
char s[maxn];
int dp[maxn];

int main() {
    int len, q;
    scanf("%d%d%s", &len, &q, s + 1);
    for (int i = 1; i <= len; i++) {
        dp[i] = dp[i - 1];
        if (s[i] == 'C' && s[i-1] == 'A') {
            dp[i]++;
        }
    }
    while (q--) {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", dp[r] - dp[l]);
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if (s.size() % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    string t1 = s.substr(0, s.size() / 2);
    string t2 = s.substr(s.size()/2, s.size()/2);
    if (t1 == t2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

char S[300][300+1];
int N;

bool check(int a) {
	for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) {
		if(S[(i+a)%N][j] != S[(j+a)%N][i]) return false;
	}
	return true;
}

int main() {
	scanf("%d", &N);
	for(int i=0;i<N;i++) {
		scanf("%300s", S[i]);
	}
	int count = 0;
	for(int a=0;a<N;a++) {
		if(check(a)) count++;
	}
	printf("%d\n", count * N);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size() , A = 200001 , Z = 0;
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'A'){
            if(A > i){
                A = i;
            }
        }
        if(s.at(i) == 'Z'){
            if(Z < i){
                Z = i;
            }
        }
    }
    cout << Z - A + 1 << endl;
}

Measured memory_bytes: 640
h,w=list(map(int,input().split()))
m=[]
for i in range(h):
  mm=[]
  for j in input():
    mm.append(1 if j=="#" else 0)
  m.append(mm)

wl=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=0
  t=0
  while t<w:
    while t<w and m[i][t]==0:
      t+=1
    for j in range(s,t):
      wl[i][j]=t-s
    s=t+1
    t=t+1
mx=0
for i in range(w):
  s=0
  t=0
  while t<h:
    while t<h and m[t][i]==0:
      t+=1
    for j in range(s,t):
      k=wl[j][i]
      if mx<k+t-s:
        mx=k+t-s
    s=t+1
    t=t+1


print(mx-1)

Measured memory_bytes: 141200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    T = IS(str)
    S = ''
    for i in range(len(T)):
        if T[i] == '?':
            S += 'D'
        else:
            S += T[i]
    
    print(S)

solve()


Measured memory_bytes: 9556
#include<stdio.h>
int main(){
	char str[20];
	int i,len=0;
	scanf("%s",str);
	while(str[len]!='\0'){
		len++;
	}
	for(i=len-1;i>=0;i--){
			printf("%c",str[i]);
		}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
 
 
vector<int> G[100000];
 
int dfs(int cur){
	vector<int> v;
	rep(i,G[cur].size()) v.pb( dfs(G[cur][i]) );
	
	sort(all(v),greater<int>());
 
	int ret = 0;
	for(int i=1;i<v.size()+1;i++){
		ret = max(i+v[i-1],ret);
	}
	
	return ret;
}
 
 
int main(){
	int n;
	cin>>n;
	
	for(int i=1;i<n;i++){
		int a;
		cin>>a;
		a--;
		G[a].pb(i);
	}
	
	cout<<dfs(0)<<endl;
}

Measured memory_bytes: 15104
s = input()
# YYMM
aa = int(s[0]+s[1])
bb = int(s[2]+s[3])
if aa>=13 or aa==0:
    if 0<bb<13:
        print('YYMM')
    else:
        print('NA')
else:
    if 0<bb<13:
        print('AMBIGUOUS')
    else:
        print('MMYY')

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

int main() {
    long long K;
    cin >> K;

    //ダイクストラ法をやる
    vector<long long> cost(K, INT_MAX);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    cost[1] = 1;
    pq.push({ 1, 1 });

    while (!pq.empty()) {
        auto top = pq.top();
        pq.pop();

        //+1していけるノード
        int plus_one = (top.second + 1) % K;
        if (top.first + 1 < cost[plus_one]) {
            cost[plus_one] = top.first + 1;
            pq.push({ cost[plus_one], plus_one });
        }

        //10倍して行けるノード
        int mult_ten = (top.second * 10) % K;
        if (top.first < cost[mult_ten]) {
            cost[mult_ten] = top.first;
            pq.push({ cost[mult_ten], mult_ten });
        }
    }

    cout << cost[0] << endl;
}

Measured memory_bytes: 2168
// AOJ 1092 Make KND So Fat
// 2018.2.3 bal4u

#include <stdio.h>
#include <string.h>

int k[101], w[101][51], p[101][51];
int f[101];
int dp[301];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int s, d, m, i, j, t, ans, money;

	do {
		s = in(), d = in(), m = in();
		for (i = 0; i < s; i++) {
			k[i] = in();
			for (j = 0; j < k[i]; j++) w[i][j] = in(), p[i][j] = in();
		}
		for (i = 0; i < d; i++) f[i] = in();

		memset(dp, 0, sizeof(dp));

		for (i = 0; i < d; i++) {
			s = f[i];
			for (j = 0; j < k[s]; j++) {
				for (t = m; t >= 0; t--) if (t + p[s][j] <= m) {
					int x = dp[t] + w[s][j];
					if (x > dp[t + p[s][j]]) dp[t + p[s][j]] = x;
				}
			}
		}

		ans = money = 0;
		for (i = 0; i <= m; i++) if (dp[i] > ans) ans = dp[i], money = i;
		printf("%d %d\n", ans, money);
	} while (getchar_unlocked() >= 0);
	return 0;
}


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

int main(){
   int n;
   int t[110000], x[110000], y[110000];
   cin >> n;
   for(int i=0; i < n; i++) cin >> t[i+1] >> x[i+1] >> y[i+1];

   bool can = true;
   for(int i = 0; i<n; i++){
       int dt = t[i+1] - t[i];
       int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
       if(dt < dist) can = false;
       if(dist % 2 != dt % 2) can = false;
   }

   if(can) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main()
{
    string s, t, test;
    char n;
    int i, j, a;
    cin >> s >> t;
    test=s;
    a=1;
    for (i=0; i<s.size(); i++)
    {
        for (j=0; j<s.size()-1; j++)
        {
            s[j+1]=test[j];
        }
        s[0]=test[j];
        if (t==s)
        {
            cout << "Yes";
            a=0;
            break;
        }
        test=s;
    }
    if (a!=0)
    {
        cout << "No";
    }
    return 0;
}


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

vector<vector<bool>> field(MAX, vector<bool>(MAX, false)); 
// vector<vector<int>> dist(MAX, vector<int>(MAX, INF));

int h,w;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int bfs(){
    deque<T> distMap;
    distMap.emplace_back(T(0,0,0));     //スタート地点
    int dist = 0;
    // bool reached = false;

    while(! distMap.empty()){
        T cp = distMap.front();
        distMap.pop_front();
        rep(i,4){
            int nx = get<0>(cp) + dx[i];
            int ny = get<1>(cp) + dy[i];
            dist = get<2>(cp) + 1;
            if(0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] == true){    //壁と一度通った道はfalseにする
                field[nx][ny] = false;
                if(nx == h - 1 && ny == w - 1) {
                    distMap.clear();     //ゴールに着いた時
                    // printf("reached\n");
                    break;
                }
                else{
                    distMap.emplace_back(T(nx, ny, dist));
                    // printf("else case");
                }
            }
        }
        // printf("No. %d\n", k);
        // printf("dist = %d\n", dist);
        // rep(i,h){
        //     // rep(j,w) printf("%d ", field[i][j]);
        //     rep(j,w) cout << field[i][j] << " ";
        //     cout << endl;
        // }
        // cout << endl;
    }
    // printf("dist = %d\n", dist);
    return dist + 1;        //スタート地点はdist=0のため、1追加して返す
}

int main(){
    cin >> h >> w;
    int res = h * w;
    rep(i,h) rep(j,w){
        char c; cin >> c;
        if(c == '.') field[i][j] = true;
        else res --;
    }
    res -= bfs();
    if(field[h-1][w-1] == true) res = -1;   //もしゴールに辿り着けなかったらゴール地点がtrueのままになっている
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,x,y,a,b;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>x>>y>>a>>b;
    cout<<min(x*a+y*b,(x*max(a,5)+y*max(b,2))*4/5)<<'\n';
  }
  return(0);
}



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

int main() {
	long long N, C, SUM[100010] = {}, ANS = 0, MAX;
	static pair<long long, long long> P[100010];
	cin >> N >> C;
	P[0] = { 0, 0 };
	for (int i = 1; i <= N; i++) {
		long long X, V;
		cin >> X >> V;
		P[i] = { X, V };
		SUM[i] = SUM[i - 1] + V;
	}
	for (int i = 1; i <= N; i++) {
		ANS = max(ANS, SUM[i] - P[i].first);
	}
	for (int i = N; i >= 1; i--) {
		ANS = max(ANS, (SUM[N] - SUM[i - 1]) - (C - P[i].first));
	}
	MAX = 0;
	for (int i = 1; i <= N; i++) {
		ANS = max(ANS, (SUM[N] - SUM[i - 1]) - (C - P[i].first) + MAX);
		MAX = max(MAX, SUM[i] - P[i].first * 2);
	}
	MAX = 0;
	for (int i = N; i >= 1; i--) {
		ANS = max(ANS, SUM[i] - P[i].first + MAX);
		MAX = max(MAX, (SUM[N] - SUM[i - 1]) - (C - P[i].first) * 2);
	}
	cout << ANS;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String taroh;
    String hanako;
    int t = 0;
    int h = 0;
    for(int i = 0; i < n; i++) {
      taroh = sc.next();
      hanako = sc.next();
      if(taroh.compareTo(hanako) > 0) {
        t += 3;
      } else if(taroh.compareTo(hanako) < 0) {
        h += 3;
      } else {
        t++;
        h++;
      }
    }
    System.out.println(t + " " + h);
  }
}



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

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; }
const long long INF = 1LL << 60;

int N;
long long W,w[110],v[110];
const int MAX_N = 110;
const int MAX_V = 100010;
long long dp[MAX_N][MAX_V]; // dp[N][V] - 制限をVとした時の、N番目までの最小の重さ

int main(){
    int sum = 0;
    cin >> N >> W;
    for(int i=0;i<N;++i){
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    for(int i=0;i<MAX_N;++i) for(int j=0;j<MAX_V;++j) dp[i][j] = INF;
    dp[0][0] = 0;

    for(int i=0;i<N;++i){
        for(int j=0;j<MAX_V;++j){
            chmin(dp[i+1][j],dp[i][j]); // i番目の品物を使わない。
            if(j>=v[i]) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]); // 使う。
        }
    }

    long long ans = 0;
    for(int i=0;i<MAX_V;++i){
        if(dp[N][i]<=W) ans = i;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 86144
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 220000
inline char gc(){
	static char now[1<<16],*S,*T;
	if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
	return *S++;
}
#define S 1<<19
inline int read(){
	int x=0,f=1;char ch=gc();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
	while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
	return x*f;
}
int f1[S],f2[S],n,num,bin[20],st[N],a[N],right[N][20],left[N][20],v;
int main(){
	//freopen("agc.in","r",stdin);
	n=read();v=read();int Log=0;
	for (int i=1;i<=n;++i) a[i]=read();
	while ((1<<Log)<=v) Log++;Log++;
	for (int i=0;i<=Log+1;++i) bin[i]=1<<i;
	num=1;for (int i=2;i<=n;++i) if (a[i]-a[i-1]>v) num++;
	for (int j=0;j<Log;++j){
		left[1][j]=1;right[n][j]=n;
		for (int i=2;i<=n;++i) if (a[i]-a[i-1]>(v>>j)) left[i][j]=i;else left[i][j]=left[i-1][j];
		for (int i=n-1;i>=1;--i) if (a[i+1]-a[i]>(v>>j)) right[i][j]=i;else right[i][j]=right[i+1][j];
	}	
	/*for (int j=0;j<Log;++j){
		for (int i=1;i<=n;++i) printf("%d ",right[i][j]);printf("\n");
		for (int i=n;i>=1;--i) printf("%d ",left[i][j]);printf("\n");
	}*/
	if (num>Log){
		for (int i=1;i<=n;++i) printf("Impossible\n");return 0;
	}
	for (int s=0;s<=bin[Log]-1;++s) {f1[s]=0,f2[s]=n+1;}
	for (int s=0;s<=bin[Log]-1;++s){
		for (int i=0;i<Log;++i){
			if (s&bin[i])continue;
			if (f1[s]==n) f1[s|bin[i]]=n;else f1[s|bin[i]]=max(f1[s|bin[i]],right[f1[s]+1][Log-i-1]);
			if (f2[s]==1) f2[s|bin[i]]=1;else f2[s|bin[i]]=min(f2[s|bin[i]],left[f2[s]-1][Log-i-1]);
		}
	}for (int i=0;i<=n;++i) st[i]=n+2;
	for (int s=0;s<=bin[Log-1]-1;++s){
		int s1=(bin[Log-1]-1)^s;
		st[f1[s]]=min(st[f1[s]],f2[s1]);
	} for (int i=n-1;i>=0;--i) st[i]=min(st[i],st[i+1]);
	//for (int i=0;i<=n;++i) printf("%d ",st[i]);printf("\n");
	for (int i=1;i<=n;++i){
		int l=left[i][0],r=right[i][0];
		if (st[l-1]<=r+1) printf("Possible\n");else printf("Impossible\n");
	}
	return 0;
}

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

int main() 
{
	string s;
	cin >> s;

	s += '<';
	const int numS = s.size();
	vector<int> ret(numS,-1);
	//if (s[0] == '<') {
	//	ret[0] = 0;
	//}
	//if (s[numS-1] == '>') {
	//	ret.back() = 0;
	//}
	//for (size_t i = 0; i < numS - 1; ++i) {
	//	if (s[i] == '>' &&s[i + 1] == '<') {
	//		ret[i + 1] = 0;
	//	}
	//}

	bool isL = false;
	int firstL = 0;
	for (int i = 0; i < numS; ++i) {
		if (s[i] == '>') 
		{
			if (isL) {
				continue;
			}
			else {
				if (i != 0) {
					ret[i] = ret[i - 1] + 1;
				}
				firstL = i;
				isL = true;
				continue;
			}
		}
		else //if (s[i] == '<')
		{
			if (isL) {
				int diff = i - firstL;
				if (ret[firstL] < diff) {
					ret[firstL] = diff;
				}
				ret[firstL + 1] = diff - 1;
				for (int j = 2; j < diff; ++j) {
					ret[firstL + j] = ret[firstL + j - 1] - 1;
				}
				ret[i] = 0;
				isL = false;
				continue;
			}
			else {
				if (i == 0) {
					ret[i] = 0;
					continue;
				}
				ret[i] = ret[i - 1] + 1;
				continue;
			}
		}
	}

	long long sum = 0;
	for (auto& i : ret) {
		sum += i;
	}

	cout << sum << endl;

	return 0;
}

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

int main() {
    int h,w,inf=100000,g=100001,ans=0;
    queue<pair<int,int>> q;
    vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
    pair<int,int> v;
    cin >> h >> w;
    vector<vector<int>> a(w+2,vector<int>(h+2));
    for (int i=0;i<h+2;i++){
      for (int j=0;j<w+2;j++){
        a.at(j).at(i)=0;
      }
    }


      
      v.first=1;v.second=1;
      q.push(v);
      a.at(1).at(1)=1;
      a.at(w).at(h)=g;
          for (int i=1;i<h+1;i++){
      for (int j=1;j<w+1;j++){
        char s;
        cin >> s;
        if (s=='.' && a.at(j).at(i)==0) {a.at(j).at(i)=inf;ans++;}
      }
    }
      while (!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for (int k=0;k<4;k++){
          if (a.at(x+dx.at(k)).at(y+dy.at(k))==inf){
            a.at(x+dx.at(k)).at(y+dy.at(k))=a.at(x).at(y)+1;
            v.first=x+dx.at(k);v.second=y+dy.at(k);
            q.push(v);
          }
          if (a.at(x+dx.at(k)).at(y+dy.at(k))==g) {cout << ans-a.at(x).at(y)+1 << endl;return 0;}
        }
      }
      cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits.h>

using namespace std;

int main()
{
	int n;
	int cx,cy;
	long ch;
	

	cin >> n;

	int *x = new int[n];
	int *y = new int[n];
	long *h = new long[n];

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	bool find;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			cx = i;
			cy = j;
			int delta_x;
			int delta_y;
			long delta_h;
			find = false;
			ch = LONG_MAX;

			int k;
			for (k = 0; k < n; k++) {
				delta_x = abs(x[k] - i);
				delta_y = abs(y[k] - j);
				long temp_ch = h[k] + delta_x + delta_y;
				if (temp_ch <= ch ) {
					ch = temp_ch;
				}
				else if (h[k] == 0) {
					continue;
				}
				else {
					break;
				}
			}
			for (k = 0; k < n; k++) {
				delta_x = abs(x[k] - i);
				delta_y = abs(y[k] - j);
				long temp_ch = h[k] + delta_x + delta_y;
				if (temp_ch <= ch) {
					ch = temp_ch;
				}
				else if (h[k] == 0) {
					continue;
				}
				else {
					break;
				}
			}
			if (k == n && ch < LONG_MAX) {
				find = true;
				break;
			}
		}
		if (find) {
			break;
		}
	}
	cout << cx << " " << cy << " " << ch << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N, D;
    char c;
    
    
    scanf("%d%c%d%c", &N, &c, &D, &c);
    
    if(N%(2*D+1))
        printf("%d\n", N/(2*D+1)+1);
    else
        printf("%d\n", N/(2*D+1));
        
    
    //system("pause");
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
            if (n == i * j) {
                cout << "Yes";
                return 0;
            }
    cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(){
  int n,a[3],b,cnt,j;
  int sum;
  int tmpr[]={600,800,1000,1200,1400,1600,0};
  int tmpb[]={60,80,100,120,140,160,0};
  int tmpw[]={2,5,10,15,20,25,0};
  while(1){
    cin >> n;
    if(n==0)break;
    cnt=0;
    for(int i=0;i<n;i++){
      cin >> a[0] >> a[1] >> a[2] >> b;
      j=0;
      int sum = a[0]+a[1]+a[2];
      for(int flg=0;j<6;j++,flg=0){
	if(tmpb[j]<sum) flg=1;
	if(tmpw[j]<b) flg=1;

	if(flg==0) break;
      }
      cnt += tmpr[j];
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

print(r)

Measured memory_bytes: 71828