akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

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

using namespace std;

typedef long long int lli;
typedef pair<lli, lli> POS;

int main() {
    int N, K;
    cin >> N >> K;
    vector<POS> pos(N);
    REP (i, 0, N) {
        lli x, y;
        cin >> x >> y;
        pos[i] = {x, y};
    }
    sort(begin(pos), end(pos));
    const lli inf = 1LL << 62;
    lli ans = inf;
    REP (k, K - 1, N) {
        REP (i, 0, N - k) {
            vector<lli> nlist;
            REP (j, 0, k + 1) {
                nlist.push_back(pos[i + j].second);
            }
            sort(begin(nlist), end(nlist));
            lli m = inf;
            REP (t, 0, k - K + 2) {
                m = min(m, nlist[K + t - 1] - nlist[t]);
            }
            ans = min(ans, m * (pos[k + i].first - pos[i].first)); 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,mini;
  cin >> n;
  vector <string> data1(n),data2(n);
  for(int i=0;i<n;i++){
    cin >> data1[i];
    data2[i] = data1[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(data1[j][1]<data1[j-1][1]) swap(data1[j],data1[j-1]);
    }
  }
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data2[j][1]<data2[mini][1]) mini = j;
    }
    if(mini != i) swap(data2[i],data2[mini]);
  }
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data1[i];
  cout << endl << "Stable" << endl;
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data2[i];
  if(data1==data2) cout << endl << "Stable" << endl;
  else cout << endl << "Not stable" << endl;
  return 0;
}


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

ostream& operator<<(ostream &out, string str) {
	for(char c : str) cout << c;
	return out;
}

template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}

template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}

void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}

#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif

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

template<class T> int size(T && a) {
	return a.size();
}

using LL = long long;
using PII = pair<int, int>;

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

	int l, r;
	cin >> l >> r;

	int mod = 2019;
	LL ans = 1e18;
	LL lmod = l % mod;
	for(LL i = l; i < r; i++) {
		LL imod = i % mod;
		if(i != l && imod == lmod) break;
		for(LL j = i + 1; j <= r; j++) {
			LL jmod = j % mod;
			if(j != (i + 1) && jmod == (i + 1) % mod) break;
			ans = min(ans, (imod * jmod) % mod);
		}
	}

	cout << ans << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){
	int a,b,c,d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	a=a+b+c+d;
	printf("%d\n", a/60);
             printf("%d\n",a%60);
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	ll a[n];
	rep(i,n){
		int x;
		cin>>x;
		a[x-1]=i+1;
	}
	set<ll> st;
	st.insert(0);
	st.insert(n+1);
	ll ans=0;
	rep(i,n){
		auto itr=st.lower_bound(a[i]);
		ll  up=*itr;
		--itr;
		ll down = *itr;
		ans+=(i+1)*(a[i]-down)*(up-a[i]);
		st.insert(a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>

int main(void)
{
	int A,B,C,D,L=0,R=0;

	scanf("%d%d%d%d",&A,&B,&C,&D);
	L = A+B;
	R = C+D;
	if(L>R) printf("Left\n");
	else if(L<R) printf("Right\n");
	else printf("Balanced\n");
	return 0;
}



Measured memory_bytes: 128
N, K = map(int, input().split())
x = list(map(int, input().split()))

l1 = []
l2 = []
for i in range(N):
    if x[i] == 0:
        K -= 1
    elif x[i] > 0:
        l1.append(x[i])
    else:
        l2.append(-x[i])

l2.sort()

ans = 10**9
if K == 0:
    ans = 0
else:
    if K <= len(l1):
        ans = min(ans, l1[K-1])
    if K <= len(l2):
        ans = min(ans, l2[K-1])

for i in range(max(1, K-len(l1)), min(K, len(l2)+1)):
    ans = min(ans, l1[K-1-i]+l2[i-1]*2, l1[K-1-i]*2+l2[i-1])

print(ans)

Measured memory_bytes: 14568
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF=10**9


def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,a[max_n];
vector<int> v[2];
bool cmp(int x,int y)
{
    return abs(x)>abs(y);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)
    {
        if(a[i]<0)v[0].push_back(a[i]);
        else if(a[i]>0)v[1].push_back(a[i]);
        else
        {
            if(v[0].size()<v[1].size())v[0].push_back(a[i]);
            else v[1].push_back(a[i]);
        }
    }
    for(int i=0;i<2;i++)sort(v[i].begin(),v[i].end(),cmp);
    if(v[0].empty())v[0].push_back(v[1].back()),v[1].pop_back();
    if(v[1].empty())v[1].push_back(v[0].back()),v[0].pop_back();
    int ans=0;
    for(auto x:v[0])ans-=x;
    for(auto x:v[1])ans+=x;
    printf("%d\n",ans);
    if(v[0].size()>=v[1].size())
    {
        for(int i=1;i<v[1].size();i++)printf("%d %d\n",v[0][i],v[1][i]);
        printf("%d %d\n",v[1][0],v[0][0]);
        int now=v[1][0]-v[0][0];
        for(int i=v[1].size();i<v[0].size();i++)
        {
            printf("%d %d\n",now,v[0][i]);
            now-=v[0][i];
        }
        for(int i=1;i<v[1].size();i++)
        {
            printf("%d %d\n",now,v[0][i]-v[1][i]);
            now-=v[0][i]-v[1][i];
        }
    }
    else
    {
        int x=v[1].back();v[1].pop_back();
        swap(v[0],v[1]);
        for(int i=1;i<v[1].size();i++)printf("%d %d\n",v[0][i],v[1][i]);
        printf("%d %d\n",v[1][0],v[0][0]);
        int now=v[1][0]-v[0][0];
        for(int i=v[1].size();i<v[0].size();i++)
        {
            printf("%d %d\n",now,v[0][i]);
            now-=v[0][i];
        }
        for(int i=1;i<v[1].size();i++)
        {
            printf("%d %d\n",now,v[0][i]-v[1][i]);
            now-=v[0][i]-v[1][i];
        }
        printf("%d %d\n",x,now);
    }
    return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> monsters(n+1);
    vector<int> b(n);
    for(int i = 0; i < n+1; i++) cin >> monsters[i];
    for(int i = 0; i < n;i++) cin >> b[i];
    long long ans = 0;
    for(int i = 0; i < n; i++){
        int panch;
        panch = min(b[i], monsters[i]);
        b[i] -= panch;
        ans += panch;
        panch = min(b[i], monsters[i+1]);
        b[i] -= panch;
        ans += panch;
        monsters[i+1] -= panch;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, d = 0;
    cin >> a >> b >> c;
    for (int i = 1; i <= 328; i++) {
        d += a;
        if (d % b == c) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const c = arg.map(n=>n.split(" ").map(l=>parseInt(l)));
    
    // a1の仮定100通りを試す
    for(let a1=0; a1<=100; a1++) {
        // a1が決まればb1,b2,b3も決まる
        const b1 = c[0][0] - a1;
        const b2 = c[1][0] - a1;
        const b3 = c[2][0] - a1;
        
        // そうすると、他のaの値も全て確定するので正しいか検証する
        for(let a2=0; a2<=100; a2++) {
            if(a2 + b1 !== c[0][1]) continue;
            if(a2 + b2 !== c[1][1]) continue;
            if(a2 + b3 !== c[2][1]) continue;

            for(let a3=0; a3<=100; a3++) {
                if(a3 + b1 !== c[0][2]) continue;
                if(a3 + b2 !== c[1][2]) continue;
                if(a3 + b3 !== c[2][2]) continue;
                
                console.log("Yes");
                return;
            }
        }
    }
    
    console.log("No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)1e5+5;
const int mod = (int)1e9+7;

void solve()
{
    int n;
    cin>>n;
    string s[n];
    map <string, int> mp;
    f(i, 0, n) cin>>s[i], mp[s[i]]++;
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6792
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>

using namespace std;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/
int main(){
    string s;
    cin >> s;
    int flag=0;
    sort(s.begin(),s.end());
    for(int i = 0; i<2;i++){
        if(s[i] == s[i+1]) {
            flag =1;
            break;
        }
    }
    if(flag == 0) cout << "Yes\n";
    else cout << "No\n";
    return 0;  
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

S = list(input())
N = len(S)

masu = []
char = ""
for i, s in enumerate(S):
    if char == "":
        char += s
        continue
    if char[-1] == s:
        char += s
        continue
    if char[-1] != s:
        masu.append(len(char))
        char = s
        continue
if char:
    masu.append(len(char))

import math

ans = []
for l, r in zip(masu[::2], masu[1::2]):
    n = len(ans)
    l_num = math.ceil(l / 2) + r // 2
    r_num = l // 2 + math.ceil(r / 2)
    for _ in range(l-1):
        ans.append(0)
    ans.append(l_num)
    ans.append(r_num)
    for _ in range(r-1):
        ans.append(0)

print(*ans)

Measured memory_bytes: 7828
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


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

    if(N % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    
    ll count2 = 0;
    ll count5 = 0;
    ll power2 = 1;
    ll power5 = 2;
    //power2をN以下最大にする。
    while(power2 * 2 <= N){
        power2 *= 2;
    }
    //power5をN以下最大にする。
    while(power5 * 5 <= N){
        power5 *= 5;
    }
    while(power2 > 1){
        count2 += N / power2;
        power2 /= 2;
    }
    while(power5 > 2){
        count5 += N / power5;
        power5 /= 5;
    }

    cout << min(count2, count5) << endl;

    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

int main() {
  long long N;
  string S;
  cin >> N >> S;
  long long r[3][4001] = {0};
  vector<long long> v[3];
  rep(i, N) {
    if(S[i] == 'R') {
      r[0][i+1] = 1; 
      v[0].push_back(i);
    }
    if(S[i] == 'G') {
      r[1][i+1] = 1;
      v[1].push_back(i);
    } 
    if(S[i] == 'B') {
      r[2][i+1] = 1; 
      v[2].push_back(i);
    }
  }
  rep(i, N) {
    r[0][i+1] += r[0][i];
    r[1][i+1] += r[1][i];
    r[2][i+1] += r[2][i];
  }

  char a[3] = {'R', 'G', 'B'};
  long long ans = 0;

  rep(i, 3) {
    rep(j, 3) {
      if(i == j) continue;
      rep(k, 3) {
        if(k == i || k == j) continue;
        rep(p, v[i].size()) {
          rep(q, v[j].size()) {
            if(v[i][p] >= v[j][q]) continue;
            ans += r[k][v[j][q]] - r[k][v[i][p]+1];
            // cout << i << " " << j << endl;
            // cout << a[i] << " " << a[j] << " " << a[k] << " " << v[i][p] << " " << v[j][q] << endl;
            // cout << ans << endl;
            if((v[j][q]+v[i][p])%2 == 0 && S[(v[j][q]+v[i][p]) / 2] == a[k]) {
              ans -= 1;
            }
            // cout << ans << endl;
          }
        }
      }
    }
  }
  cout << ans << endl;

  // rep(i, 3) {
  //   rep(j, N+1) {
  //     cout << r[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  map<ll, ll> mp;

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    mp[a]++;
    ans += a;
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    ll b, c;
    cin >> b >> c;
    ans -= (mp[b] * b);
    ans += (mp[b] * c);
    mp[c] += mp[b];
    mp[b] = 0;
    cout << ans << '\n';
  }
  return 0;
}



Measured memory_bytes: 9436
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
a = iprow()
b = sorted(a)
if n%2:
    s = 2
else:
    s = 1
    b.insert(0,0)
if n%2 != 0 and b[0] != 0:
    print(0)
    exit(0)
for i in range(1,n):
    if b[i]!=s:
        print(0)
        exit(0)
    if i%2 == 0:
        s+=2
print(pow(2,n//2,rem))

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}



void solve(std::istream &in, std::ostream &out) {
  int n, k;
  in >> n >> k;
  vector<int> dp(n + 1);
  vector<int> h(n);
  for (int &i : h) {
    in >> i;
  }
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; ++i) {
    dp[i] = numeric_limits<int>::max();
    for (int j = 1; j <= min(k, i); ++j) {
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  out << dp[n - 1] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N;
    cin >> N;
    set<string> st;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19224
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define max 200000000

int Hash[max];
char text[13];
//int x,y,z;

int getC(char C)
{
  if(C=='A') return 1;
  else if(C=='C') return 2;
  else if(C=='G')return 3;
  else return 4;
}

int getK(void)
{
  int i;
  int sum=0,p=1;
  int len=strlen(text);

  for(i= 0;i<len;i++)
    {
      sum+=p*(getC(text[i]));
      p*=5;
    }
  return sum;
}

int find(void)
{
  int key=getK();
  
  if(Hash[key])
    {
      return 1;
    }

  return 0;
}

void insert(void)
{
  Hash[getK()]=1;
}


int main()
{
  int n;
  char in[7];

  scanf("%d",&n);
  while(n--)
    {
    scanf("%s%s",in,text);
    
    if(strcmp(in,"insert")==0)  insert();
    else
      {
	if(find()) printf("yes\n");
	else printf("no\n");
      }
    }

return 0;
}



		    
		
	      
	    


	  
       



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

int main(){
    int N;
    int A,B;
    int temp;

    cin >> N >> A >> B;
    
    temp = B / N;
    temp = temp * N;

    if(temp >= A){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;

    }

}

Measured memory_bytes: 3620
#include <stdio.h>
#define MOD 998244353

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int s = a;
	while(b)
	{
		if(b%2==1) ans*=s, ans%=MOD;
		b/=2;
		s*=s, s%=MOD;
	}
	return ans;
}
long long int inv(long long int k)
{
	return power(k,MOD-2);
}

long long int sum[200010];
long long int func(int l, int r)
{
	return (sum[r]-sum[l-1]+MOD)%MOD;
}

struct segTree{
	long long int value[800010];
	int lazy[800010];
	void setValue(int L, int R, int val, int l=1, int r=200000, int v=1)
	{
		if(L<=l&&r<=R)
		{
			lazy[v] = val;
			value[v] = (func(l,r)*val)%MOD;
		}
		else if(r<L) return;
		else if(R<l) return;
		else
		{
			int h = (l+r)/2;
			if(lazy[v]!=0)
			{
				value[2*v] = (func(l,h)*lazy[v])%MOD;
				value[2*v+1] = (func(h+1,r)*lazy[v])%MOD;
				lazy[2*v] = lazy[v];
				lazy[2*v+1] = lazy[v];
				lazy[v] = 0;
			}
			
			
			setValue(L,R,val,l,h,2*v);
			setValue(L,R,val,h+1,r,2*v+1);
			value[v] = (value[2*v] + value[2*v+1])%MOD;
		}
	}
	long long int getSum(int L, int R, int l=1, int r=200000, int v=1)
	{
		if(L<=l&&r<=R) return value[v];
		else if(r<L) return 0;
		else if(R<l) return 0;
		else
		{
			int h = (l+r)/2;
			if(lazy[v]!=0)
			{
				value[2*v] = (func(l,h)*lazy[v])%MOD;
				value[2*v+1] = (func(h+1,r)*lazy[v])%MOD;
				lazy[2*v] = lazy[v];
				lazy[2*v+1] = lazy[v];
				lazy[v] = 0;
			}
			
			long long int S1 = getSum(L,R,l,h,2*v);
			long long int S2 = getSum(L,R,h+1,r,2*v+1);
			return (S1+S2)%MOD;
		}
	}
}T;


int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	
	for(int i=1;i<=a;i++) sum[i] = inv(power(10,i));
	for(int i=1;i<=a;i++) sum[i] = (sum[i]+sum[i-1])%MOD;
	
	T.setValue(1,a,1);
	for(int i=1;i<=b;i++)
	{
		int c,d,e;
		scanf("%d%d%d",&c,&d,&e);
		T.setValue(c,d,e);
		long long int S = T.getSum(1,a);
		printf("%lld\n",(S*power(10,a))%MOD);
	}
}

Measured memory_bytes: 10048
from collections import defaultdict, deque

v, n = map(int, input().split())  #v:頂点数 n:辺の数
es = [[int(x) for x in input().split()] for _ in range(n)]

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)

for i in res:
    print(i)


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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], X[200000], Y[200000], V[200000];
str S, T, U; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> a >> b >> n;
	for (int i = 0; i < a; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> X[i] >> Y[i] >> V[i];
		Min = min(A[X[i] - 1] + B[Y[i] - 1] - V[i], Min);
	}
	sort(A, A + a);
	sort(B, B + b);
	Min = min(A[0] + B[0], Min);

	cout << Min << endl;
	return 0;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  vector<Int> cnt(n,0);
  for(Int i=0;i<n;i++){
    if(i) cnt[i]=cnt[i-1];
    if(i+1<n&&s[i]=='A'&&s[i+1]=='C') cnt[i]++;
  }
  cnt.emplace(cnt.begin(),0);
  for(Int i=0;i<q;i++){
    Int l,r;
    cin>>l>>r;
    l--;r--;
    cout<<cnt[r]-cnt[l]<<endl;
  }
  return 0;
}


Measured memory_bytes: 2048
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
# import sys
# sys.setrecursionlimit(10**4)
# import time

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


p = _i()
a_list = np.array(_li())

factorial_invs = {0: 1, 1: 1}
for i in range(2, p):
    factorial_invs[i] = (factorial_invs[i-1] * pow(i, p-2, p)) % p
np_fact_invs = np.tile(np.array(list(factorial_invs.values()))
                       .reshape(1, -1), (p, 1))

pow_table = np.ones((p, p), dtype=int)
pow_table[1, :] = np.arange(p)
for i in range(2, p):
    pow_table[i] = (pow_table[i-1] * pow_table[1]) % p
pow_table = pow_table.T

fact_pminus1 = pow(factorial_invs[p-1], p-2, p)

coefs = np.zeros(p, dtype=int)
# for i, a in enumerate(a_list):
#     if a == 1:
#         for k in range(1, p):
#             coefs[k] = coefs[k] - (-1)**(k % 2) * pow(i, p-1-k, p)\
#                     * fact_pminus1\
#                     * factorial_invs[k]\
#                     * factorial_invs[p-1-k]
#             coefs[k] %= p

coefs[0] = a_list[0]
sign_array = np.tile(((-1) ** (np.arange(1, p) % 2)).reshape(1, -1), (p, 1))
coefs[1:] = - ((((sign_array[a_list == 1, :]
                  * pow_table[a_list == 1, :-1][:, ::-1]
                  * fact_pminus1) % p
                 * np_fact_invs[a_list == 1, 1:]) % p
                * np_fact_invs[a_list == 1, :-1][:, ::-1]
                ) % p).sum(axis=0)
coefs %= p

print(*coefs)


Measured memory_bytes: 434308
from collections import *

N=int(input())
S=input()
c=Counter(S)

ans=c['R']*c['G']*c['B']

for i in range(1,N//2+1):
  for j in range(i,N-i):
    if S[j-i]!=S[j] and S[j]!=S[j+i] and S[j+i]!=S[j-i]:
      ans-=1

print(ans)


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

int main()
{
    int n;
    cin>>n;
    int x=n/2;
    string s="", s1="", s2="";
    cin>>s;
    for(int i=0; i<x; i++) {
        s1 = s1 + s[i];
    }
    for(int i=x; i<n; i++) {
        s2 = s2 + s[i];
    }
    if(s1==s2) {
        cout<<"Yes";
    }
    else {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
n = int(input())
a = list(map(int, input().split()))
num = []

for i in range(0, n):
    if a[i] % 2 == 0:
       num.append(a[i])

#print(num)

if len(num) == 0:
    print('APPROVED')
    exit()
else:
    for j in range(0, len(num)):
        if num[j] % 3 != 0 and num[j] % 5 != 0:
            print('DENIED')
            exit()

print('APPROVED')

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    while (true) {
        val (m, f, r) = readLine()!!.split(" ").map(String::toInt)

        if (m==-1 && f==-1 && r==-1) break

        val rank =
            if (m == -1 || f == -1) "F"
            else if (m + f >= 80) "A"
            else if (m + f >= 65) "B"
            else if (m + f >= 50) "C"
            else if (m + f >= 30 && r >= 50) "C"
            else if (m + f >= 30 && r <= 49) "D"
            else "F"
        println(rank)
    }
}


Measured memory_bytes: 31992
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
vector<int>e[N];
int dep[N],md[N],fa[N],n,s,t;
void dfs(int u,int f)
{
	dep[u]=md[u]=dep[f]+1,fa[u]=f;
	for(auto v:e[u])
		if(v!=f)
			dfs(v,u),md[u]=max(md[u],md[v]);
}
int main()
{
	scanf("%d%d%d",&n,&s,&t);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(t,0);
	int ans=0,x=s;
	while(1)
	{
		if(dep[s]-dep[x]>=dep[x]-dep[t])
			break;
		ans=max(ans,md[x]-1);
		x=fa[x];
	}
	printf("%d\n",ans-1);
	return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;
using Graph = vector<vector<int>>;

signed _main(){
  int N; cin >> N;
  v<int> A(N+1),A2(N+1);
  for(int i=1;i<=N;i++){
    int a; cin >> a;
    A[i]=i+a;
    A2[i]=i+a;
  }
  int ans=0;
  sort(ALL(A2));
  for(int j=1;j<=N;j++){
    int val=2*j-A[j];
    //cout << "val " << val << endl;
    int first=lower_bound(ALL(A2),val)-A2.begin();
    int last=upper_bound(ALL(A2),val)-A2.begin();
    //cout << first << " " << last << endl;
    if(val!=0) ans+=last-first;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define inf -999999999
int main()
{	
	int a,b,c;
	cin>>a>>b;
	int s=a+b;
	if(s==3)
		cout<<3;
	else if(s==4)
		cout<<2;
	else cout<<1;
		
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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 (b<a) { a=b; return 1; } return 0; }

int N;
string S;

int up_dfs( int key )
{
    if( key < 0 || key >= N ) return 0;
    set<char> left;
    set<char> right;

    rep(i,key) left.insert(S[i]);
    REP(i,key,N) right.insert(S[i]);

    int ans = 0;

    for(set<char>::iterator itr = right.begin(); itr != right.end(); itr++)
    {
        if( left.find(*itr) != left.end() )ans++;
    }
    chmax(ans, up_dfs(key+1));
    return ans;
}

int down_dfs( int key )
{
    if( key < 0 || key >= N ) return 0;
    set<char> left;
    set<char> right;

    rep(i,key) left.insert(S[i]);
    REP(i,key,N) right.insert(S[i]);

    int ans = 0;

    for(set<char>::iterator itr = left.begin(); itr != left.end(); itr++)
    {
        if( right.find(*itr) != right.end() )ans++;
    }
    chmax(ans, down_dfs(key-1));
    return ans;
}
    

int main()
{
    cin >> N >> S;
    cout << max( up_dfs(N/2+1), down_dfs(N/2)) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// nCr mod を計算する O(n)
const int MAX_N = 1000010;
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; 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;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
// O(logn)
ll modpow(ll a, ll n, ll mod=MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n;
    cin>>n;

    COMinit();
    ll ans=modpow(10,n);
    ll tmp1=modpow(9,n);
    ll tmp2=modpow(9,n);
    ll tmp3=modpow(8,n);
    ll tmp=(tmp1+tmp2)%MOD;
    tmp-=tmp3;
    if(tmp<0) tmp+=MOD;
    ans-=tmp;
    if(ans<0) ans+=MOD;

    cout<<ans<<endl;
} 


Measured memory_bytes: 27080
#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 a,b,c;
    cin>>a>>b>>c;
    int cnt=0;
    bool flag=true;
    if((a%2||b%2)||c%2)flag=false;
    else if(a==b&&b==c){
        flag=false;
        cnt=-1;
    }
    while(flag){
        int i=a,j=b,k=c;
        a=j/2+k/2;
        b=i/2+k/2;
        c=i/2+j/2;
        cnt++;
        if((a%2||b%2)||c%2)flag=false;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

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

	int N, K, Q = 0;

	protected void doIt() {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		K = scan.nextInt();
		Q = scan.nextInt();
		String nextLine = System.lineSeparator();
		int[] correct = new int[N];
		for (int i=0; i < Q; i++) {
			int correcter = scan.nextInt();
			correct[correcter - 1]++;
		}

		StringBuilder sb = new StringBuilder();
		for (int i=0; i < N; i++) {
			int point = K - Q + correct[i];
			if (point > 0) {
				sb.append("Yes" + nextLine);
			}
			else {
				sb.append("No" + nextLine);
			}
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 62756
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

signed main(){
    
    int n,c;
    cin >> n >> c;
    int ans = 0;

    if((n*c)%2 == 0)cout << "No";
    else cout << "Yes";

    
    return 0;
}
//g++ -std=c++14 code1.cpp


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if (N <= K)
    {
        cout << N * X << endl;
    }
    else
    {
        cout << K * X + (N - K) * Y << endl;
    }
}

Measured memory_bytes: 3636
N = int(input())
W = []
for i in range(N):
    W.append(input())
if len(W) != len(set(W)):
    print('No')
else:
    for i in range(1, N):
        if W[i][0] != W[i - 1][-1]:
            print('No')
            exit()
    print('Yes')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

ll _find(string &str){
    int n=str.l();
    ll last=0;
    ll ans=0;
    for(int i=n-1;i>=0;i--){
        if(str[i]=='B'){
            ans+=last;
        }
        else{
            last++;
        }
    }
    return ans;
}

void solve(){
    string str;
    cin>>str;
    
    cout<<_find(str)<<endl;
}

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

Measured memory_bytes: 3788
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

typedef vector<int> vi;
int n,y[4],x[4];
vi ans(32);

int main(){
  for(int i=0;i<4;i++){
    for(int j=0;j<7;j++){
      ans[i*8+j] = (i+1)*10 + j+1;
    }
    ans[i*8+7] = 0;
  }

  cin >> n;
  while(n--){
    vi t(32);
    for(int i=0;i<4;i++){
      for(int j=0;j<7;j++){
	int pos = i*8+j+1;
	cin >> t[pos];
	if(t[pos]%10 == 1){
	  int id = t[pos]/10-1;
	  t[id*8] = t[pos];
	  t[pos] = 0;
	}
      }
    }

    queue<vi> q;
    q.push(t);
    map<vi,int> m;
    m[t] = 0;

    while(q.size()){
      vi v = q.front(); q.pop();
      if(v==ans)break;

      int num = 0;
      for(int i=0;i<4;i++){
	for(int j=0;j<8;j++){
	  if(!v[i*8+j]){
	    y[num] = i; x[num] = j;
	    num++;
	  }
	}
      }

      int dis = m[v];

      while(num--){
	int ny = y[num], nx = x[num]-1;
	int pos = ny*8+nx;
	if(!v[pos] || v[pos]%10 == 7)continue;
	int val = v[pos]+1, ty,tx;
	for(int i=0;i<4;i++){
	  for(int j=0;j<8;j++){
	    if(v[i*8+j] == val){
	      ty = i; tx = j;
	    }
	  }
	}
	
	swap(v[y[num]*8+x[num]],v[ty*8+tx]);
	if(m.find(v)==m.end()){
	  m[v] = dis + 1;
	  q.push(v);
	}
	swap(v[y[num]*8+x[num]],v[ty*8+tx]);
      }
    }	

    if(m.find(ans)==m.end())cout << -1 << endl;
    else cout << m[ans] << endl;
  }
}

Measured memory_bytes: 15996
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var Aij = new long[3][];
            Aij[0] = Sarray();
            Aij[1] = Sarray();
            Aij[2] = Sarray();
            var Bing = new bool[3, 3];
            var N = Sarray()[0];
            for (var i = 0; i < N; ++i)
            {
                var b = Sarray()[0];
                for (var j = 0; j < 3; ++j)
                    for (var k = 0; k < 3; ++k)
                    {
                        if (Aij[j][k] == b)
                            Bing[j, k] = true;
                    }
            }
            var ans = false;
            var sla = true;
            var isla = true;
            for (var i = 0; i < 3; ++i) {
                if (!Bing[i, i]) sla = false;
                if (!Bing[i, 2 - i]) isla = false;
                var brow = true;
                var bcol = true;
                for (var j = 0; j < 3; ++j)
                {
                    if (!Bing[i, j]) brow = false;
                    if (!Bing[j, i]) bcol = false;
                }
                ans |= brow | bcol;
            }
            ans |= sla | isla;

            WriteLine(ans ? "Yes" : "No");

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
a = input()
suuziretu = input().split(' ')
record_times = []
for n in range(int(a)):
    times = 0
    while True:
        if int(suuziretu[n])%2 != 0 or int(suuziretu[n]) == 0:
            record_times.append(times)
            break
        if times == 0:
            b = int(suuziretu[n])
        if b % 2 == 0:
            b = b /2
            times += 1
        else:
            record_times.append(times)
            break
print(min(record_times))

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define FOR(i,a,n) for(ll i=a;i<=n;i++)
#define ROF(i,n,a) for(ll i=n;i>=a;i--)

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    vector<int> a(n-1);
    FOR(i,0,n-2)
      cin>>a[i];
    sort(a.begin(),a.end());
    FOR(i,1,n){
        vector<int>::iterator lower,upper; 
        lower = lower_bound (a.begin(), a.end(), i);  
        upper = upper_bound (a.begin(), a.end(), i);
        cout<<upper-lower<<endl;  
    }  
   return 0; 
}

Measured memory_bytes: 3988
N = int(input())
T, A = map(int, input().split())
T *= 1000
A *= 1000
H = [int(a) for a in input().split()]

m = abs(T - H[0] * 6 - A)
n = 1
for i in range(N):
    if abs(T - H[i] * 6 - A) <= m:
        m = abs(T - H[i] * 6 - A)
        n = i + 1
        
print(n)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			int[][] a = new int[h][w];
			IntStream.range(0, h).forEach(i -> IntStream.range(0, w).forEach(j -> a[i][j] = scanner.nextInt()));
			List<Move> moves = new ArrayList<>(), currentMoves = new ArrayList<>();
			int prevX = -1, prevY = -1;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int x = i, y = (0 == (x & 1)) ? j : w - 1 - j;
					if ((prevX >= 0) && (prevY >= 0)) {
						currentMoves.add(new Move(prevX, prevY, x, y));
						if (0 != (a[x][y] & 1)) {
							prevX = -1;
							prevY = -1;
							moves.addAll(currentMoves);
							currentMoves.clear();
						} else {
							prevX = x;
							prevY = y;
						}
					} else if (0 != (a[x][y] & 1)) {
						prevX = x;
						prevY = y;
					}
				}
			}
			System.out.println(moves.size());
			moves.stream().forEach(System.out::println);
		}
	}

	/**
	 * 移動方法を表すクラス
	 */
	private static class Move {
		int x1, y1, x2, y2;

		Move(int x1, int y1, int x2, int y2) {
			super();
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;
		}

		@Override
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append(x1 + 1).append(" ");
			sb.append(y1 + 1).append(" ");
			sb.append(x2 + 1).append(" ");
			sb.append(y2 + 1);
			return sb.toString();
		}
	}
}


Measured memory_bytes: 68496
import java.util.Scanner;

public class Main {

	public static long mod = (long) (Math.pow(10, 9) + 7);

	public static int MAX = 510000;
	public static int MOD = 1000000007;
	public static long[] inv = new long[MAX];

	public static long Calc(long ret, long n) {
		if(n == 1)
			return ret;
		else if(n % 2 == 1) {
			return (ret * Calc(ret, n - 1)) % mod;
		} else {
			return Calc((ret * ret) % mod, n / 2);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long ans = 2;
		ans = Calc(ans, n);
		inv[1] = 1;
		for(int i = 2; i < MAX; i++) {
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		}
		long[] com = new long[Math.max(a, b) + 1];
		com[0] = 1;
		for(int i = 1; i < Math.max(a, b) + 1; i++) {
			com[i] = com[i - 1] * (n - i + 1);
			com[i] %= mod;
			com[i] *= inv[i];
			com[i] %= mod;
		}
		while(ans < 0)
			ans += mod;
		ans -= 1;
		ans -= com[a];
		ans -= com[b];
		while(ans < 0)
			ans += mod;
		System.out.println(ans);
	}

}


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

int main() {
  int N, P;
  cin >> N >> P;
  int even = 0, odd = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A % 2 == 0) even++;
    else odd++;
  }

  long long ans = 1;
  if (even == N) {
    if (P == 0) {
      for (int i = 0; i < N; i++) ans *= 2;      
    } else {
      ans = 0;
    }
  } else {
    for (int i = 0; i < N - 1; i++) ans *= 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	string s;
	cin >> s;
	int ans = 0;
	int l = 0, r = s.length() - 1;
	while (l < r) {
		// cout << l << " " << r << endl;
		if (s[l] == s[r]) {
			l++;
			r--;
		} else if (s[l] == 'x') {
			l++;
			ans++;
		} else if (s[r] == 'x') {
			r--;
			ans++;
		} else {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,m;cin>>n>>m;
  vvl data(n);
  rep(i,m){
    ll a,b;cin>>a>>b;
    a--;b--;
    data[a].push_back(b);
    data[b].push_back(a);
  }
  ll count=0;
  vector<ll>vec;
  rep(i,n-1)vec.push_back(i+1);
  do{
    bool ok=true;
    ll point=0;
    for(auto x:vec){
      bool part=false;
      rep(j,data[point].size()){
        if(data[point][j]==x)part=true;
      }
      if(part)point=x;
      else ok=false;
    }
    if(ok)count++;
  }while(next_permutation(vec.begin(),vec.end()));
  cout<<count<<endl;
}
    
  

Measured memory_bytes: 256
#include <iostream>

long long a,b,c;
int main(){
  std::cin>>a>>b>>c;
  auto x=a;
  auto y=b;
  auto z=c;
  long long ans=-1;
  int cnt=0;
  long long res=0;
  while(true){
    if(x==a&&y==b&&z==c){
      if(cnt>0)
        break;
      ++cnt;
    }
    if(x%2==1||y%2==1||z%2==1){
      ans=res;
      break;
    }
    long long nx,ny,nz;
    nx=y/2+z/2;
    ny=x/2+z/2;
    nz=x/2+y/2;
    x=nx;
    y=ny;
    z=nz;
    ++res;
  }
  std::cout<<ans<<std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    String s = sc.next();
    int[] c = new int[n];
    int count = 0;
    for (int i =0;i<n-1;i++){
      if ("AC".equals(s.substring(i,i+2))){
        count++;
      }
      c[i+1] = count;
    }
    int l,r,ans;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;i<q;i++){
      //l = sc.nextInt();
      //r = sc.nextInt();
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      ans = c[r-1]-c[l-1];
      //System.out.println(ans);
      sb.append(ans);
      sb.append("\n");
    }
    System.out.println(sb.toString());
    sc.close();
  }
}

Measured memory_bytes: 50972
//By Bibi
///                 .-~~~~~~~~~-._       _.-~~~~~~~~~-.
///             __.'              ~.   .~              `.__
///           .'//                  \./                  \`.
///        .'//                     |                     \`.
///       .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \`.
///     .'//.-"                 `-.  |  .-'                 "-.\`.
///   .'//______.============-..   \ | /   ..-============.______\`.
/// .'______________________________\|/______________________________`.
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1010;
int n, X[N], Y[N];
char s[40];
 
int iabs(int x) { return x > 0 ? x : -x; }
 
int main() {
    scanf("%d", &n);
    int c = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &X[i], &Y[i]);
        if ((X[i] + Y[i]) & 1) c++;
        else c--;
    }
    if (iabs(c) != n) {
        puts("-1"); return 0;
    }
    int m = 31 + (c < 0);
    printf("%d\n", m);
    for (int i = 0; i <= 30; i++) printf("%d ", 1 << i);
    if (c < 0) printf("1 ");
    puts("");
    for (int i = 1; i <= n; i++) {
        int x = X[i], y = Y[i], sign = 0;
        if (c < 0) s[31] = 'R', x--;
        for (int j = 30; j >= 0; j--) {
            if (iabs(x) < iabs(y)) swap(x, y), sign ^= 1;
            if (x > 0) x -= 1 << j, s[j] = sign ? 'U' : 'R';
            else x += 1 << j, s[j] = sign ? 'D' : 'L';
        }
        printf("%s\n", s);
    }
    return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 2e5+1;
int n, k, C, F[N + 1];
char c[N];

int main()
{
  fastio;
  cin >> n >> k >> C;
  for (int i = 1; i <= n; i++) cin >> c[i];
  vector <int> memo;
  int pre = -INF;
  for (int i = 1; i <= n; i++){
    if (c[i] == 'x') continue;
    if (i - C > pre){
      memo.push_back(i);
      pre = i;
    }
    if (memo.size() == k) break;
  }
  if (memo.size() < k) return cout << -1, 0;
  F[n + 1] = 0; pre = INF;
  for (int i = n; i > 0; i--){
    F[i] = F[i + 1];
    if (c[i] == 'x') continue;
    if (i + C < pre){
      pre = i; F[i]++;  
    }  
  }
  for (int i = 0; i < k; i++){
    int cur = memo[i];
    if (i + F[cur + 1] + 1 == k) cout << cur << '\n';
  }
  return 0;
}

Measured memory_bytes: 3444