akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vi a(n);
  vi b(n);
  rep(i, n){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(all(b));
  ll mx = b[n - 1];
  ll mx2 = b[n - 2];
  rep(i,n){
    if(a[i]==mx){
      print(mx2);
    }
    else{
      print(mx);
    }
  }
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;

int main(){
    int i,j,h,w,d,q;
    long long ans;
    cin >> h >> w >> d;
    vector<vector<int> > a(310,vector<int>(310)),b(d,vector<int >(h*w/d+1)),e(d,vector<int >(h*w/d+1));
    pair <int, int> c[h*w+1];
    vector<int> l(100010),r(100010);
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin >> a[i][j];
            c[a[i][j]] = make_pair(i,j);
        }
    }
    cin >> q;
    for(i=d+1;i<=h*w;i++){
        b[i%d][i/d] = abs(c[i].first - c[i-d].first) + abs(c[i].second - c[i-d].second);
        e[i%d][i/d] = e[i%d][i/d-1] + b[i%d][i/d];
    }
    for(i=0;i<q;i++){
        cin >> l[i] >> r[i];
        ans = e[r[i]%d][r[i]/d] - e[l[i]%d][l[i]/d];
        cout << ans << endl;
    }
}

Measured memory_bytes: 12160
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << "=" << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n);
    int a[n]; rep(i, n) in(a[i]);

    ll dp[n + 1][n + 1]; // dp[i][l] ans to a[i: i + l]
    bool turn = n&1; // Taro's turn if l&1 == turn

    rep(i, n + 1) dp[i][0] = 0;
    repr(l, 1, n + 1) {
        bool taro = (turn == (l&1));
        rep(i, n - l + 1) {
            if (taro)
            dp[i][l] = std::max(
                        a[i] + dp[i + 1][l - 1],
                        a[i + l - 1] + dp[i][l - 1]
                       );
            else
            dp[i][l] = std::min(
                        -a[i] + dp[i + 1][l - 1],
                        -a[i + l - 1] + dp[i][l - 1]
                       );
        }
    }
    out(dp[0][n]);
}

int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long

int main() {
  intll n ;
  cin >> n;
  intll ans = 1;
  
  rep(i,n){
    ans *= (i+1);
    ans %= 1000000007;
  }
  
  cout << ans % 1000000007   ;
}


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

namespace AtCoder
{
	public class Program
	{
		static int[] dp;

		static List<List<int>> graph;

		static void Main(string[] args)
		{
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			graph = new List<List<int>>();
			for (int i = 0; i < n; i++) {
				graph.Add(new List<int>());
			}
			for (int i = 0; i < m; i++) {
				int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
				graph[tmp[0] - 1].Add(tmp[1] - 1);
			}

			//for (int i = 0; i < graph.Count; i++) {
			//	System.Diagnostics.Debug.Write($"{i + 1}:");
			//	for (int j = 0; j < graph[i].Count; j++) {
			//		System.Diagnostics.Debug.Write($"{graph[i][j] + 1}, ");
			//	}
			//	System.Diagnostics.Debug.WriteLine("");
			//}

			dp = new int[n];
			for (int i = 0; i < dp.Length; i++) {
				dp[i] = -1;
			}

			int ans = 0;
			for (int i = 0; i < dp.Length; i++) {
				ans = Math.Max(ans, Compute(i));
			}
			Console.WriteLine(ans);
		}

		static int Compute(int v)
		{
			if (dp[v] != -1) {
				return dp[v];
			}
			int ans = 0;
			foreach (int nv in graph[v]) {
				ans = Math.Max(ans, Compute(nv) + 1);
			}
			//System.Diagnostics.Debug.WriteLine($"{v + 1}={ans}");
			return dp[v] = ans;
		}

	}
}

Measured memory_bytes: 32508
#include <stdio.h>

int main()
{
    int m = 0, f = 0, r = 0;
    while (m != -1 || f != -1 || r != -1)
    {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }

        if (m == -1)
        {
            printf("F\n");
        }
        else if (f == -1)
        {
            printf("F\n");
        }
        else if (m + f >= 80)
        {
            printf("A\n");
        }
        else if (m + f >= 65 && m + f < 80)
        {
            printf("B\n");
        }
        else if (m + f >= 50 && m + f < 65)
        {
            printf("C\n");
        }
        else if (m + f >= 30 && m + f < 50)
        {
            if (r >= 50)
            {
                printf("C\n");
            }
            else
            {
                printf("D\n");
            }
        }
        else if (m + f < 30)
        {
            printf("F\n");
        }
    }
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n;
long long c,mx,x[maxn],v[maxn],a[maxn],b[maxn];
int main()
{
	scanf("%d %lld",&n,&c);
	for (int i=1;i<=n;i++) 
	{
		scanf("%lld %lld",&x[i],&v[i]);
		a[i]=a[i-1]+x[i-1]-x[i]+v[i];
	}
	x[n+1]=c;
	for (long long i=n;i>=1;i--)
	{
		b[i]=b[i+1]+x[i]-x[i+1]+v[i];
	}
	for (int i=2;i<=n;i++)
	{
		a[i]=max(a[i],a[i-1]);
	}
	for (int i=n-1;i>=1;i--)
	{
		b[i]=max(b[i],b[i+1]);
	}
	for (int i=1;i<=n;i++)
	{
		mx=max(mx,a[i]),mx=max(mx,b[i]);
		mx=max(mx,a[i]-x[i]+b[i+1]);
		mx=max(mx,b[i]-(c-x[i])+a[i-1]);
	}
	printf("%lld\n",mx);
	return 0;
}

Measured memory_bytes: 3328
n = int(input())
if n < 10:
    print(n)
else:
    x = n // 10
    basenum = x * x + 8
    addnum = 0
    # print("{0} {1}".format(x* 10 + 1, n))
    hassame = False
    for i in range(x * 10 + 1, n + 1):
        # print(i)
        for j in range(1, n + 1):
            # print(j)
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                addnum += 1
                if i == j:
                    hassame = True
                # print("{0},{1}".format(i, j))
    res = basenum + addnum * 2
    if hassame:
        res -= 1
    # print("n={0}, x={1}, basenum={2}, addnum={3} res ={4}".format(n,x,basenum,addnum,res))
    print(res)


Measured memory_bytes: 40796
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin>>n>>k;
    vec<ll> x(n);
    rep(i,n) cin>>x[i];
    
    ll res=INF;
    for(ll i=0;i<=n-k;i++){
        res=min(res,min(abs(x[i]),abs(x[i+k-1]))+x[i+k-1]-x[i]);
    }
    cout<<res<<endl;
    return 0;
}


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


int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  cout << A * min(N, (B-1))/B;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N, M, K;
int A[MAX_N], B[MAX_N];

signed main()
{
  cin >> N >> M >> K;
  
  REP(n,N) {
    cin >> A[n];
  }

  REP(m,M) {
    cin >> B[m];
  }

  int index = -1;
  int sumA = 0;
  REP(n,N) {
    if (sumA + A[n] <= K) {
      sumA += A[n];
      index = n;
    } else {
      break;
    }
  }  

  int ans = max((LL)0, index+1);

  int sumB = 0;
  REP(m,M) {
    if (sumB + B[m] <= K) {
      sumB += B[m];
      while(sumA + sumB > K) {
        sumA -= A[index--];
      }
      ans = max(ans, m+1 + index+1);
    } else {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

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

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<int> ans(N);
  for (int i = 0; i < N; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      if (i == j)
        continue;
      else
      {
        ans[min(abs(j - i), abs(X - i) + abs(j - Y) + 1)]++;
      }
    }
  }
  for (int i = 1; i < N; i++)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

// 何も考えずにBFS，アドホックに求める


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << "[DBG] " << #X << "=" << (X) << '\n';
	#define SAY(X) cout << "[SAY] " << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MOD = (int)1e9 + 7;
inline int add(int x, int y) {
	return (x + y >= MOD ? x + y - MOD : x + y);
}

inline int sub(int x, int y) {
	return (x - y < 0 ? x - y + MOD : x - y);
}

inline int mult(int x, int y) {
	return (x * 1LL * y) % MOD;
}

int binpow(int x, int y) {
	if(x == 1 || y == 0) return 1;
	if(x == 0) return 0;
	int rez = binpow(x, y/2);
	rez = mult(rez, rez);
	if(y&1) rez = mult(rez, x);
	return rez;
}

inline int divide(int x, int y) {
	return mult(x, binpow(y, MOD - 2));
}

const int MAXN = (int)2e5 + 7;
vector<int> g[MAXN];
int n;
int subtree[MAXN];
int pw2[MAXN];

void dfs(int v, int p) {
	subtree[v] = 1;
	for(auto& u: g[v]) {
		if(u != p) {
			dfs(u, v);
			subtree[v] += subtree[u];
		}
	}
}

void solve() {
	pw2[0] = 1;
	for(int i = 1; i < MAXN; ++i) pw2[i] = add(pw2[i - 1], pw2[i - 1]);
	cin >> n;
	for(int i = 0; i < n - 1; ++i) {
		int v = fetch<int>() - 1;
		int u = fetch<int>() - 1;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(0, NIL);
	int answ = 0;
	for(int v = 0; v < n; ++v) {
		int cnt = len(g[v]);
		if(cnt <= 1) continue;
		int value = 1;
		for(auto& u: g[v]) {
			if(subtree[u] < subtree[v]) {
				value = sub(value, divide(1, pw2[n - subtree[u] - 1]));
				DBG(n - subtree[u] - 1);
			}
		}

		if(v != 0) {
			DBG(subtree[v] - 1);
			value = sub(value, divide(1, pw2[subtree[v] - 1]));
		}
		value = add(value, divide(cnt - 1, pw2[n - 1]));

		value = divide(value, 2);
		DBG(v + 1); DBG(value); DBG(cnt);
		answ = add(answ, value);
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 19456
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
     long long int a[200001];

     long long int res = 0;

    long n;
    cin >> n;
     long long int all = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all = (all + a[i]) % mod;
    }
     long long int current_sum = all;
    for(int i = 0; i < n; i++) {
         long long int val = 0;
        current_sum = (current_sum - a[i])%mod;
        if(current_sum < 0) {
            current_sum += mod;
        }
        //cout << current_sum << endl;
        val = (current_sum * a[i]) % mod;
        res = (res + val) % mod;
    }
    res = (res) % (mod);
    cout << res << endl;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define init(arr, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
const int inf = pow(10,9);
const int nil = -1;
int ans = 100;
long long int n, i;

int gcd(int p, int q) {
    if (p % q == 0) return p;
    return gcd(q, p%q);
}

int getDigit(long long int num){
    return log10(num)+1;
}

int main() {
    scanf(" %lld", &n);
    long long int f = sqrt(n);
    rep(1,f+1) if (n % i == 0) {
        ans = min(ans, max(getDigit(i), getDigit(n/i)));
    }

    printf("%d\n", ans);
}

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

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    ll mask1 = (1<<n);
    ll mask2 = (1<<m);
    string s[n];
    rep(i,0,n)  cin >> s[i];
    rep(i,0,mask1) rep(j,0,mask2){
        string t[n];
        rep(k,0,n)  t[k] = s[k];
        rep(k,0,n){
            if((i&(1<<k))){
                rep(l,0,m)  t[k][l] = '.';
            }
        }
        rep(k,0,m){
            if((j&(1<<k))){
                rep(l,0,n)  t[l][k] = '.';
            }
        }
        ll cnt = 0;
        rep(k,0,n)  rep(l,0,m){
            if(t[k][l] == '#')  cnt++;
        }
        if(cnt == k)    ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
// clang-format off
#include <bits/stdc++.h>

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

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
constexpr ll MOD = 1000000007;

constexpr int MAX = 100000;
string s, t;
ll as[MAX];
ll bs[MAX];
ll at[MAX];
ll bt[MAX];

ll as_num(int a, int b)
{
    if(s[a] == 'A'){
        return as[b]-as[a]+1;
    } else {
        return as[b]-as[a];
    }
}
ll bs_num(int a, int b)
{
    if(s[a] == 'A'){
        return bs[b]-bs[a];
    } else {
        return bs[b]-bs[a]+1;
    }
}
ll at_num(int a, int b)
{
    if(t[a] == 'A'){
        return at[b]-at[a]+1;
    } else {
        return at[b]-at[a];
    }
}
ll bt_num(int a, int b)
{
    if(t[a] == 'A'){
        return bt[b]-bt[a];
    } else {
        return bt[b]-bt[a]+1;
    }
}

int main()
{
    cin >> s >> t;
    rep(i, s.size()){
        if(i == 0){
            if(s[i] == 'A'){
                as[i] = 1;
            } else {
                bs[i] = 0;
            }
        } else {
            if(s[i] == 'A'){
                as[i] = as[i-1]+1;
                bs[i] = bs[i-1];
            } else {
                as[i] = as[i-1];
                bs[i] = bs[i-1]+1;
            }
        }
    }
    rep(i, t.size()){
        if(i == 0){
            if(t[i] == 'A'){
                at[i] = 1;
            } else {
                bt[i] = 0;
            }
        } else {
            if(t[i] == 'A'){
                at[i] = at[i-1]+1;
                bt[i] = bt[i-1];
            } else {
                at[i] = at[i-1];
                bt[i] = bt[i-1]+1;
            }
        }
    }
    int q;
    cin >> q;
    rep(i, q){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--,b--,c--,d--;
        ll s_div = as_num(a, b) - bs_num(a, b);
        ll t_div = at_num(c, d) - bt_num(c, d);
        const ll di = s_div - t_div;
        if(di % 3 == 0){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3968
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,m = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(m)]

#scを桁数で整理
keta_q_set = [set() for _ in range(n+1)]
for s,c in sc:
    keta_q_set[s].add(c)
ans = ""
for i in range(1,n+1):
    if len(keta_q_set[i])==0:
        if i==1 and n!=1:
            ans+="1"
        else:
            ans+="0"
    if len(keta_q_set[i])==1:
        #1桁目(かつn!=1)に0を指定していたら-1
        j = keta_q_set[i].pop()
        if i==1 and n!=1:
            if j ==0:
                ans="-1"
                break
            else:
                ans+=str(j)
        else:
            ans+=str(j)
    if len(keta_q_set[i])>=2:
        ans="-1"
        break
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [int(i) for i in input().split()]
a.append(0)
money = 1000
stock = 0
for i in range(n):
    if a[i] < a[i+1] and stock == 0:
        stock,money = money//a[i],money%a[i]
    elif a[i] > a[i+1]:
        stock,money = 0,money+stock*a[i]
print(money)

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

const int N = 100005;
vector<pair<int, ll> > g[N];
ll dist[N];
 
void dfs(int v, int p){
	for(auto x : g[v]){
		if(x.first == p)continue;
		dist[x.first] = dist[v] + x.second;
		dfs(x.first, v);
	}
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);
 
	string s, t; 
    cin >> s >> t;
    cout << t+s << "\n";
	return 0;
}

Measured memory_bytes: 2560
/**
 *    author:  tourist
 *    created: 24.02.2018 15:50:14       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  int ans = 0;
  for (int d = 1; d <= 9; d++) {
    long long x = d;
    if (x > n) {
      continue;
    }
    int sum = d;
    while (x * 10 + 9 <= n) {
      x = x * 10 + 9;
      sum += 9;
    }
    ans = max(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define inf 9223372036854775807;
#define pi 3.141592653589793238;
#define pb push_back;
#define umap unordered_map;
#define uset unordered_set;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void solve(){
    ll r;
    cin>>r;
    long double c = (long double) r;
    c *= 2*pi;
    cout<<setprecision(5)<<fixed<<c;
}
int main(){
    fast;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
}   

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
const double inf=1e9;
typedef long long ll;
typedef pair<int,int>pr;
const ll mod=1e9+7;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a;
        a=a*a;
        b>>=1;
    }
    return ans;
}
ll gcd(ll a,ll b){
    if(!b) return a;
    else return gcd(b,a%b);
}

int vis[30];
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s,t;
  cin>>s>>t;
   int num=0;
  for(int i=0;i<s.length();i++){
     if(s[i]==t[i]){
        num++;
     }
  }
  cout<<num<<endl;
  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;

#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define loopi(n) for(int i=0;i<n;i++)
#define loopj(n) for(int j=0;j<n;j++)
#define loop(a,b,c) for(int i=a;i<=b;i=i+c)

#define     deb(x)      cout<<#x<<"="<<x<<endl
#define     all(x)      (x).begin(),(x).end()
#define     reset(a)    memset(a,0,sizeof(a))
#define     sz(x)       ((int)(x.size()))
#define     pb          push_back
#define     pf          push_front
#define     pob	        pop_back
#define     pof         pop_front
#define     ins         insert
#define     F           first
#define     S           second
#define     mkp         make_pair
#define     mkt         make_tuple
#define     bitcount(x) __builtin_popcountll(x)
#define     gcd(a,b)    (__gcd(a,b))
#define     lcm(a,b)    ((a*b)/gcd(a,b))
#define PI 3.1415926535897932384626

const int mod = 998244353;

//=======================

void solve()
{
	int n;
	cin>>n;
	string s="ACL";
	while(n--)
		cout<<s;
}

int main() 
{
	sync;

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

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

const int md = 998244353;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % md);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (md)
  );
  return m;
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

const int N = 1000005;
vector<vector<int>> dis(N);

int main() {
  range(i, 1, N) {
    for(int j = i; j < N; j += i) dis[j].push_back(i);
  }
  int n;
  cin >> n;
  vector<int> sum(N);
  int total = 0;
  range(i, 0, n) {
    int a;
    scanf("%d", &a);
    for(int c : dis[a]) add(sum[c], a);
    add(total, a);
  }
  int res = 0;
  husk(i, N - 1, 0) {
    sum[i] = mul(sum[i], sum[i]);
    for(int j = 2 * i; j < N; j += i) sub(sum[i], sum[j]);
    add(res, mul(sum[i], inv(i)));
  }
  sub(res, total);
  res = mul(res, inv(2));
  cout << res;
  return 0;
}


Measured memory_bytes: 120716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ld a,b,x;
    cin >> a >> b >> x;
    x/=a;
    if (x<(a*b/2)){
        ld p=x/b*2;
        cout << setprecision(15) << 90-atan2(p,b)*(180/PI) << endl;
    }else{
        ld p=((a*b)-x)/a*2;
        cout << setprecision(15) << 90-atan2(a,p)*(180/PI) << endl;
    }
    return 0;
}

Measured memory_bytes: 3824
from itertools import combinations
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
arr=[0]*3

for i in range(N):
    if P[i]<=A:
        arr[0]+=1
    elif P[i]<=B:
        arr[1]+=1
    else:
        arr[2]+=1
print(min(arr))

Measured memory_bytes: 62128
from bisect import bisect_left


def solve(string):
    a, b, q, *stx = map(int, string.split())
    s = [-10**10] + stx[:a] + [2 * 10**10]
    t = [-10**10] + stx[a:a + b] + [2 * 10**10]
    # x = dict([])
    ans = []
    i_s = 0
    i_t = 0
    for _x in stx[-q:]:
        """
        while s[i_s] < _x:
            i_s += 1
        while t[i_t] < _x:
            i_t += 1
        """
        i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
        ls, rs = s[i_s - 1], s[i_s]
        lt, rt = t[i_t - 1], t[i_t]
        r_max = max(rs, rt) - _x
        l_min = _x - min(ls, lt)
        """
        x[_x] = min([
            r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
            rs - lt + min(rs - _x, _x - lt)
        ])
        """
        ans.append(
            str(
                min([
                    r_max, l_min, rt - ls + min(rt - _x, _x - ls), rs - lt + min(rs - _x, _x - lt)
                ])))
    # return "\n".join([str(x[_x]) for _x in stx[-q:]])
    return "\n".join(ans)


if __name__ == '__main__':
    n, m, l = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, l) + '\n'.join([input() for _ in range(n + m + l)])))


Measured memory_bytes: 39512
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
int main(){
    ll h, n; cin >> h >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i] >> b[i];
    ll dp[n + 1][h + 1];
    rep(i, n + 1){
        rep(j, h + 1){
            dp[i][j] = 2e8;
        }
    }

    rep(i, n) dp[i][0] = 0;
    rep(i, n){
        rep(j, h + 1){
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][min(j + a[i], h)] = min(dp[i + 1][min(j + a[i], h)], dp[i + 1][j] + b[i]);
        }
    }    
    cout << dp[n][h] << endl;
}

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

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

	int x = (1900 * m) + (100 * (n - m));
	double p = 1 / pow(2, m);

	int ans = x / p;

	cout << ans << endl;
}



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

signed main(){
  string s;int k;cin>>s>>k;
  for(int i=0;i<s.size()&&k;i++){
    if(s[i]=='a')continue;
    int res=s[i]-'a';
    res=26-res;
    if(res>k)continue;
    k-=res;
    s[i]='a';
  }
  k%=26;
  for(int i=0;i<k;i++){
    s[s.size()-1]=char(s[s.size()-1]+1);
    if(s[s.size()-1]>'z')s[s.size()-1]='a';
  }
  cout<<s<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  cin >> n>> m;

  ll s[n],t[m];
  for(int i=0;i<n;i++)cin >> s[i] ;
  for(int i=0;i<m;i++)cin >> t[i];

  ll dp[n+1][m+1];//i番目とj番目までの部分列で、かつi番目とj番目を使用している組 
  memset(dp,0,sizeof(dp));
  ll l[n+1][m+1];
  memset(l,0,sizeof(l));
  

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(s[i]==t[j])dp[i+1][j+1]=l[i][j]+1;
      dp[i+1][j+1]%=mod;
      l[i+1][j+1]+=l[i+1][j];
      l[i+1][j+1]%=mod;
      l[i+1][j+1]+=l[i][j+1];
      l[i+1][j+1]%=mod;
      l[i+1][j+1]-=l[i][j];
      l[i+1][j+1]+=mod;
      l[i+1][j+1]%=mod;
      l[i+1][j+1]+=dp[i+1][j+1];
      l[i+1][j+1]%=mod;
    }
  }

  cout << (l[n][m]+1)%mod << endl;


}

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

int main(void) {
  int a, b, c, d;
  cin >> a >> b >> c;
  d = a * 100 + b * 10 + c;
  if ((d % 4) == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll  = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>;
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n,c;cin >> n >> c;
  vector<pll> a(n), b(n);
  vector<pll> suma(n+1),sumb(n+1);
  for(int i = 0; i < n; ++i){
    ll x,v;cin >>x>> v;
    a[i]={x, v};
    suma[i+1].first=a[i].first;
    suma[i+1].second=suma[i].second+a[i].second;
  }
  for(int i = 0; i < n; ++i){
    b[i]={c - a[n-1-i].first, a[n-1-i].second};
    sumb[i+1].first=b[i].first;
    sumb[i+1].second=sumb[i].second+b[i].second;
  }
  
  vector<ll> maxr(n+1), maxl(n+1);
  for(int i = 1; i <= n; ++i){
    ll tmp1 = suma[i].second - 2*suma[i].first;
    maxr[i] = max(maxr[i-1], tmp1);
    ll tmp2 = sumb[i].second - 2*sumb[i].first;
    maxl[i] = max(maxl[i-1], tmp2);
  }
  ll ans = 0;
  for(int r = 0; r <= n; ++r){
    int l = n-r;
    ll dist = suma[r].first;
    ll score = maxl[l] + suma[r].second;
    ll tmp = score - dist;
    ans = max(ans, tmp);
  }
  
  for(int l = 0; l <= n; ++l){
    int r = n-l;
    ll dist = sumb[l].first;
    ll score = maxr[r] + sumb[l].second;
    ll tmp = score - dist;
    ans = max(ans, tmp);
  }
  
  
  cout << ans << endl;
}


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

int main(){
    int n, k;
    cin>>n>>k;
    int a[n];
    int dp[n] = {INT_MAX};
    for(int i = 0;i<n;i++){
        cin>>a[i];
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(int i = 1;i<=min(k, n);i++){
        for(int j = 0;j<i;j++){
            dp[i] = min(dp[i], dp[j] + abs(a[i]- a[j]));
        }
    }
    for(int i = k+1;i<n;i++){
        for(int j = i-k;j<i;j++){
            dp[i] = min(dp[i], dp[j] + abs(a[i]- a[j]));
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int m1 = fetch<int>();
	int d1 = fetch<int>();
	int m2 = fetch<int>();
	int d2 = fetch<int>();

	cout << (m1 != m2) << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long long LL;

const int MC = 2010;
const LL mod = 1e9 + 7;
LL fct[MC];
LL invfct[MC];
LL dp[MC][MC];
int N,K;

void build(){
	fct[0] = fct[1] = 1;
	repp(i,2,N+1){
		fct[i] = fct[i-1] * i % mod;
	}
	LL x = fct[N];
	invfct[N] = 1;
	for(int i = mod - 2 ; i > 0 ; i >>= 1){
		if(i % 2 == 1) (invfct[N] *= x) %= mod;
		(x *= x) %= mod;
	}
	repm(i,N,0){
		invfct[i-1] = invfct[i] * i % mod;
	}
}

LL comb(int x , int y){
	if(x < 0 || x < y) return 0;
	return fct[x] * invfct[y] % mod * invfct[x-y] % mod;
}

int main(){
	scanf("%d%d" , &N , &K);
	build();
	dp[0][0] = 1;
	repp(i,1,K){
		LL s = 0;
		repp(j,0,i){
			(s += dp[j][i-j-1]) %= mod;
			dp[j][i-j] = s;
		}
		dp[i][0] = s;
	}
	LL ans = 0;
	if(N==K){
		ans = dp[N-1][0];
	} else {
		repp(i,0,K){
			(ans += comb(N-i-2,N-K-1) * dp[i][K-i-1] % mod) %= mod;
		}
		repm(i,N-K-1,0){
			(ans += ans) %= mod;
		}
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 22784
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;

class Program
{
    static List<int>[] 横;
    static List<int>[] 縦;

    static void Main()
    {
        string[] input = Console.ReadLine().Split();
        int h = int.Parse(input[0]);
        int w = int.Parse(input[1]);
        string[] s = new string[h];
        for (int i = 0; i < h; i++)
            s[i] = Console.ReadLine();

        横 = new List<int>[h];
        縦 = new List<int>[w];
        for (int i = 0; i < h; i++)
        {
            横[i] = new List<int>();
            横[i].Add(0);
            for (int j = 1; j <= w; j++)
                if (s[i][j - 1] == '#')
                    横[i].Add(j);
            横[i].Add(w + 1);
        }
        for (int i = 0; i < w; i++)
        {
            縦[i] = new List<int>();
            縦[i].Add(0);
            for (int j = 1; j <= h; j++)
                if (s[j - 1][i] == '#')
                    縦[i].Add(j);
            縦[i].Add(h + 1);
        }

        long ans = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (s[i][j] == '#') continue;
                int y = BS.Lower_Bound(横[i], j + 1);
                int r_y = 横[i][y];
                int l_y = 横[i][y - 1];
                int t = BS.Lower_Bound(縦[j], i + 1);
                int r_t = 縦[j][t];
                int l_t = 縦[j][t - 1];
                long temp = (r_y - l_y - 1) + (r_t - l_t - 1) - 1;
                ans = Max(ans, temp);
            }
        }
        Console.WriteLine(ans);
    }
}

class BS
{
    /* 単調非減少なarrayから、array[i] >= kなる最小のiを返す(なければn) */
    public static int Lower_Bound(List<int> array, long k)
    {
        int l = -1;
        int r = array.Count;
        while (r - l > 1)
        {
            int m = (l + r) / 2;
            if (array[m] >= k) r = m;
            else l = m;
        }
        return r;
    }
}

Measured memory_bytes: 78484
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf,",");
				double x[] = new double[4];
				double y[] = new double[4];
				boolean flag = false;

				for (int i=0;i<4;i++) {
					x[i] = Double.parseDouble(st.nextToken());
					y[i] = Double.parseDouble(st.nextToken());
				}

				if (S(x[0],y[0],x[1],y[1],x[2],y[2])>0) {
					for (int i=1;i<4;i++)
						if (S(x[i%4],y[i%4],x[(i+1)%4],y[(i+1)%4],x[(i+2)%4],y[(i+2)%4])<0) {
							flag = true;
						}
				} else {
					for (int i=1;i<4;i++)
						if (S(x[i%4],y[i%4],x[(i+1)%4],y[(i+1)%4],x[(i+2)%4],y[(i+2)%4])>0) {
							flag = true;
						}
				}

				if (flag) System.out.println("NO");
				else System.out.println("YES");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static double S(double x1,double y1,double x2,double y2,double x3,double y3) {
		return (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
	}
}

Measured memory_bytes: 16920
#include <iostream>

using namespace std;

const int m[] = {500, 100, 50, 10, 10, 5, 1};

int main()
{
    int inp;

    while (cin >> inp, inp) {
        int ans = 0;

        inp = 1000 - inp;
        for (int i = 0; i < 7; i++) {
            if (inp <= 0)
                break;
            else if (inp / m[i]) {
                ans += inp / m[i];
                inp = inp % m[i];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long MOD = (long) (1e9 + 7);

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextLong();
		}
		int[] c = new int[62];
		for (int i = 0; i < N; ++i) {
			for (int shift = 0; shift < 62; ++shift) {
				if ((A[i] >> shift) % 2 == 1) {
					c[shift]++;
				}
			}
		}
		long ans = 0;
		for (int shift = 0; shift < 62; ++shift) {
			long one = c[shift];
			long zero = N - c[shift];
			ans += one * zero % MOD * ((1L << shift) % MOD) % MOD;
			ans %= MOD;
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 99576
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int n;
pair<int, int> point[100];
int ans[100];

main(){
  cin >> n;
  for(int i=0;i<n;i++){
    point[i].second = i;
  }
  for(int i=0;i<(n*(n-1))/2;i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    if(c == d){
      point[a].first++;
      point[b].first++;
    }else if(c > d){
      point[a].first += 3;
    }else{
      point[b].first += 3;
    }
  }
  sort(point, point+n);
  int tmp = 1;
  int pre = -1;
  for(int i=n-1, j=0;i>=0;i--, j++){
    if(point[i].first == pre){
      ans[point[i].second] = tmp;
    }else{
      ans[point[i].second] = j+1;
      tmp = j+1;
    }
    pre = point[i].first;
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long int 
using namespace std;


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			break;
		}
		if(i==b)
			cout<<"NG";
	}
	
	return 0; 
}

Measured memory_bytes: 3648
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main(void) {
    ll n;
    cin >> n;
    ll ans = inf;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i != 0) {
            continue;
        }
        ll x = n / i;
        ll count = 0;
        while (x) {
            x /= 10;
            count++;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3684
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a == b){
            System.out.println("a == b");
        }else if (a > b){
            System.out.println("a > b");
        }else{
            System.out.println("a < b");
        }
    }
}


Measured memory_bytes: 26140
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

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

    ll a, b, c;

    cin >> a >> b >> c;

    if (a == b && b == c) ans = 0;
    else if (a != b && b != c && c != a) ans = 0;
    else ans = 1;

    (ans) ? (cout << "Yes" << endl) : (cout << "No" << endl);


}

Measured memory_bytes: 256