akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll h[maxn], v[maxn], n;
ll tree[4*maxn];

void update(int x, ll value, int li=0, int ri=n, int index=1) {
    if(li == ri) tree[index] = value;
    else {
        int mid = (li+ri)/2;
        if(x <= mid) update(x, value, li, mid, 2*index);
        else update(x, value, mid+1, ri, 2*index+1);
        tree[index] = max(tree[2*index], tree[2*index+1]);
    }
}

ll query(int ql, int qr, int li=0, int ri=n, int index=1) {
    if(li > qr || ri < ql) return 0LL;
    else if(li >= ql && ri <= qr) {
        return tree[index];
    }
    else {
        int mid = (li+ri)/2;
        return max(query(ql,qr,li,mid,2*index), query(ql,qr,mid+1,ri,2*index+1));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>h[i];
    }
    for(int i=1;i<=n;i++) {
        cin>>v[i];
    }
    ll result = 0LL;
    for(int i=1;i<=n;i++) {
        ll curr = query(0, h[i]-1) + v[i];
        update(h[i], curr);
        result = max(result, curr);
    }
    cout<<result<<"\n";
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

ll power(ll x,ll n)
{
    ll res=1;
    while(n){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
//B=lcm*(1/Aの和)
void solve() 
{
    vector<ll>lcm(1500000,0);
    ll n,ans=0;cin>>n;
    ll a[n];REP(i,n)cin>>a[i],(ans+=power(a[i],mod-2))%=mod;//ans=Aの逆元の和
    REP(i,n){
        ll tmp=a[i];
        for(ll j=2;j*j<=tmp;j++){//lcmを素因数分解してからansに掛け算
            if(tmp==1)break;
            if(tmp%j==0){
                ll cnt=0;
                while(tmp%j==0)tmp/=j,cnt++;
                while(lcm[j]<cnt)(ans*=j)%=mod,lcm[j]++;
            }
        }
        while(tmp&&!lcm[tmp])(ans*=tmp)%=mod,lcm[tmp]++;//a[i]は素数
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int N, A, B;
	scanf("%lld%lld%lld", &N, &A, &B);
	if((B - A) % 2 == 0){
		printf("%lld\n", (B - A) / 2);
	}
	else{
		printf("%lld\n", min((B + A - 1) / 2, (2 * N - A - B + 1) / 2));
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	string s,t,u;
	int a,b;
	cin >> s >> t >>a>>b>> u;
	
	if(s==u)
	a--;
	else
	{
		b--;
	}
	cout<<a<<' '<<b<<endl;
	
	return 0;
}

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

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

Measured memory_bytes: 256
import sys
import numpy as np
def input():
    return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    a = [int(e) for e in input().split()]

    x = [0 for _ in range(n)]
    x[0] = sum(a) - (sum(a[1:n:2]) * 2)
    for i in range(2, n, 2):
        x[i] = x[i-2] + ((a[i-1] - a[i-2]) * 2)
    x[1] = sum(a) - (sum(a[2:n:2]) * 2)
    for i in range(3, n, 2):
        x[i] = x[i-2] + ((a[i-1] - a[i-2]) * 2)
    print(*x)
main()

Measured memory_bytes: 23112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  string a;
  cin >> a;
  bool f=true;
  sort(a.begin(),a.end());
  for(int i=1;i<a.size();i++){
    if(a[i]==a[i-1]){
      f=false;
    }
  }
  if(f){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }
}


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

using namespace std;

int main(void){
    int A,B,T;
    cin>>A>>B>>T;
    int sum=0;
    for(int i=A;i<T+0.5;i+=A){
        sum+=B;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

N,X,Y = map(int,input().split(' '))
M = -(-(X+Y)//2)
ANS = []
for i in range(N):
    for j in range(i+1,N):
        d = j-i
        dd = abs(X-1-i)+1+abs(Y-1-j)
        ANS.append(min(d,dd))
ANS.sort()
L = len(ANS)
cnt = 0
ans = [0]*(N-1)
while cnt != L:
    k = ANS[cnt]
    ans[k-1] += 1
    cnt += 1
for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 118860
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <sstream>

using namespace std;

map< string, vector<string> > e;
set<string> vis;
set<string> cnt;

int rec(string s)
{
  int sum = 0;
  vis.insert( s );
  vector<string> v = e[s];
  for(int i=0; i<v.size(); ++i){
    if( vis.count( v[i] ) )continue;
    if( e.find( v[i] ) == e.end() ) cnt.insert( v[i] );
    else sum += rec( v[i] );
  }
  return sum;
}

int main(void)
{
  int n;
  while( cin >> n && n ){    
    cnt.clear();
    e.clear();
    vis.clear();
    string f = "";
    for(int i=0; i<n; ++i){
      string s;
      cin >> s;
      for(int j=0; j<s.size(); ++j){
	if( s[j] == ':' || s[j] == ',' || s[j] == '.' )s[j] = ' ';
      }
      istringstream iss( s );
      string src, dst;
      vector<string> v;
      for( iss >> src; iss >> dst; v.push_back(dst));
      e[src] = v;
      if( f.size() == 0 )f = src;
      //cout << src << " : "; for(int j=0; j<v.size(); ++j)cout << v[j] << ' '; cout << endl;
   }    
    rec(f);
    cout << cnt.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

typedef long long int64;

char GetChar(int64 a, int64 b, int i) {
	int64 bigGroup = b / (a + 1) + (b % (a + 1) != 0 ? 1 : 0);


	int64 sepAs, leftBs, groupAs, leftAs;

	auto Calc = [&](int mid) {
		sepAs = mid / bigGroup + (mid % bigGroup == 0 ? -1 : 0);
		leftBs = b - mid;
		groupAs = leftBs * bigGroup;
		leftAs = a - sepAs - groupAs;
	};

	int64 lo = 0, hi = b + 1;
	while (hi - lo > 1) {
		int64 mid = ((lo + hi) >> 1);
		Calc(mid);
		if (leftAs > bigGroup) {
			hi = mid;
		} else {
			lo = mid;
		}
	}

	Calc(lo);

	// cerr << lo << " " << sepAs << " " << leftBs << " " << groupAs << " " << leftAs << "\n";

	if (i <= sepAs + lo) {
		if (i % (bigGroup + 1) == 0) {
			return 'A';
		}
		return 'B';
	} else {
		i = a + b - i + 1;
		if (i % (bigGroup + 1) == 0) {
			return 'B';
		}
		return 'A';
	}
}

string GetSub(int a, int b, int c, int d) {
	string s;

	if (a > b) {
		swap(a, b);
		for (int i = c; i <= d; ++i) {
			s += GetChar(a, b, i);
		}

		for (int i = 0; i < s.length(); ++i) {
			if (s[i] == 'B')
				s[i] = 'A';
			else s[i] = 'B';
		}
	} else {
		for (int i = a + b - c + 1; i >= a + b - d + 1; --i) {
			s += GetChar(a, b, i);
		}
	}

	return s;
}

void Solve() {
	int q;

	cin >> q;

	for (int i = 1; i <= q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		auto s = GetSub(a, b, c, d);

		cout << s << "\n";
	}
}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
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 vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const long long INF = 1LL<<60;
int H, W;
vector<string> fi;
 
int main(){
  cin >> H >> W;
  vector<vector<long long>> dp(H, vector<long long>(W, INF));
  fi.resize(H);
  for(int i=0; i<H; i++) cin >> fi[i];
  if(fi[0][0] == '#') dp[0][0] = 1;
  else dp[0][0] = 0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      for(int dir=0; dir<2; dir++){
         int ni = i + dx[dir], nj = j + dy[dir];
         if (ni >= H || nj >= W) continue;
         int add = 0;
         if (fi[ni][nj] == '#' && fi[i][j] == '.') add = 1;
         chmin(dp[ni][nj], dp[i][j] + add);
      }
    }
  }
  cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

bool value_comparer(map<P, int>::value_type &i1, map<P, int>::value_type &i2) {
  return i1.second<i2.second;
}

void _main() {
  int N;
  cin >> N;
  vp xy(N);
  rep(i, 0, N) cin >> xy[i].fi >> xy[i].se;
  sort(all(xy));

  map<P, int> cnt;
  rep(i, 0, N) rep(j, i+1, N) {
    int dx = xy[j].fi - xy[i].fi;
    int dy = xy[j].se - xy[i].se;
    ++cnt[P(dx, dy)];
    ++cnt[P(-dx, -dy)];
  }

  int ans = max(1, N - max_element(all(cnt), value_comparer)->se);
  cout << ans << endl;
}

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

int main() {
  int A,B,C,K,ans;
  cin >> A >> B >> C >> K;

if(K > A+B){
    ans = A - (K - A -B);
}
else {
    if(A<=K){
        ans = A;
    }
    else{
        ans = K;
    }
}

     cout << ans << endl;

}


Measured memory_bytes: 3580
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MAX_N = 100000;

int main() {
	int n, a[MAX_N],ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == a[k])continue;
		if ((i - k) % 2) {
			ans++;
		}
		k = i;
	}
	if ((n - k) % 2) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

vector<vector<int>> dp(405 , vector<int>(405 , -1));
vector<int> a;

int solve(int L , int R) {
    if(L == R) return dp[L][R] = a[R]-a[L-1];
    else if(dp[L][R] != -1) return dp[L][R];
    else {
        dp[L][R] = INT64_MAX;
        int cost = a[R]-a[L-1];
        for(int k = L; k < R; k++) dp[L][R] = min(dp[L][R] , cost + solve(L,k) + solve(k+1 , R));
        return dp[L][R];
    } 
}

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

	int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) a[i] += a[i-1];
    cout << solve(1,n)-a[n] << "\n";

    return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
using namespace std;
string s;

int main(){
	cin>>s;
	if((s[0]==s[1] and s[0]==s[2]) or (s[1]==s[2] and s[1]==s[3]))printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

#define int long long
//nitin try to think of dp(running state, point),segment tree generalised,binary search,trie (in last greedy)!!!!!!!!!!!!
#define ci(m)           for(int i=0;i<m;i++)
#define cj(m)           for(int j=0;j<m;j++)
#define ck(m)           for(int k=0;k<m;k++)
#define cis(m)          for(int i=1;i<=m;i++)
#define cjs(m)          for(int j=1;j<=m;j++)
#define cks(m)          for(int k=1;k<=m;k++)
#define rci(m)          for(int i=m-1;i>=0;i--)
#define rcj(m)          for(int j=m-1;j>=0;j--)
#define rck(m)          for(int k=m-1;k>=0;k--)
#define rcis(m)         for(int i=m;i>=1;i--)
#define rcjs(m)         for(int j=m;j>=1;j--)
#define rcks(m)         for(int k=m;k>=1;k--)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int e[200000][26];
int32_t main() {
    nitin;
    string str;
    cin>>str;
    int n=str.length();
    ci(n) e[i][str[i]-'a']++;
    rci(n) if(i!=n-1){
        cj(26)
        e[i][j]+=e[i+1][j];
    }
    int ans=0;
    ci(n) if(i!=n-1){
        cj(26) if(j!=str[i]-'a')
            ans+=e[i+1][j];
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 44356
while True:
	arr = list(map(int, input().split()))
	n = arr[0]
	x = arr[1]

	if n == 0 and x == 0:
		break
	c = 0
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			for k in range(j + 1, n + 1):
				if i + j + k == x:
					c += 1
	print(c)
	c = 0



Measured memory_bytes: 5592
#include<iostream>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<cstring>
#include <algorithm>
 using namespace std;

int main()
{
	int a, b, n;
	cin >> a >> b >> n;
	if(a>b) a^=b^=a^=b;
	cout << ceil(n*1.0/b);

	return 0;
}


Measured memory_bytes: 256
import scala.math._
import scala.util.control.TailCalls._
object Main {
  def solve1(x: Int, y: Int): Int = {
    (x, y) match {
      case (0, 0) =>
        1
      case (x, y) if x < 0 || y < 0 =>
        0
      case _ =>
        val m = solve1(x - 1, y - 2)
        val n = solve1(x - 2, y - 1)
        m + n
    }
  }
  def solve2(x: Int, y: Int): Int = {
    val memo = scala.collection.mutable.Map.empty[(Int, Int), Int]
    def go(x: Int, y: Int): Int = {
      memo.get((x, y)) match {
        case Some(v) =>
          v
        case None =>
          (x, y) match {
            case (0, 0) =>
              memo((0, 0)) = 1; 1
            case (x, y) if x < 0 || y < 0 =>
              0
            case _ =>
              val r = go(x - 1, y - 2) + go(x - 2, y - 1)
              memo((x, y)) = r; r
          }
      }
    }
    go(x, y)
  }

  def solve3(x: Int, y: Int): Int = {
    val memo = scala.collection.mutable.Map.empty[(Int, Int), Int]
    def go(x: Int, y: Int): TailRec[Int] = {
      memo.get((x, y)) match {
        case Some(v) =>
          done(v)
        case None =>
          (x, y) match {
            case (0, 0) =>
              memo((0, 0)) = 1; done(1)
            case (x, y) if x < 0 || y < 0 =>
              done(0)
            case _ =>
              for(m <- tailcall(go(x - 1, y - 2)); n <- tailcall(go(x - 2, y - 1)))
                yield {
                  memo((x, y)) = m + n
                  m + n
                }
          }
      }
    }
    go(x, y).result
  }

  def solve4(x: Int, y: Int, X: Int, Y: Int): Int = {
    val memo = scala.collection.mutable.Map.empty[Int, Int]
    def index(x: Int, y: Int): Int = x + y * (X + 1)
    def go(x: Int, y: Int): TailRec[Int] = {
      val i = index(x, y)
      memo.get(i) match {
        case Some(v) => done(v)
        case None =>
          (x, y) match {
            case (0, 0) =>
              memo(0) = 1; done(1)
            case (x, y) if x < 0 || y < 0 =>
              done(0)
            case _ =>
              for(m <- tailcall(go(x - 1, y - 2)); n <- tailcall(go(x - 2, y - 1)))
                yield {
                  memo(i) = m + n
                  m + n
                }
          }
      }
    }
    go(x, y).result
  }


  def solve5(x: Int, y: Int): BigInt = {
    def f(n: BigInt): BigInt = BigInt(0).to(n).foldLeft(BigInt(0))(_ * _)
    if((x + y) % 3 != 0) return 0
    val m = 2 * x - y
    val n = 2 * y - x
    f(n + m) / f(n) * f(m - n)
  }

  def solve6(n: Int, r: Int): BigInt = {
    val Mod = 1000000007
    val m = (n - r + 1 to n).foldLeft(1L){(z, l) => z * l % Mod}
    val BIMod = BigInt(Mod)
    (BigInt(2) to BigInt(r)).foldLeft(BigInt(m)){(z, l) => l.modInverse(BIMod) * z % Mod}
  }

  def main(args: Array[String]): Unit = {
    val line = Console.in.readLine()
    val Array(tx, ty) = line.split(" ")
    val X = tx.toInt
    val Y = ty.toInt
    if((X + Y) % 3 != 0 || (X * 2 < Y || Y * 2 < X)) {
      print(0)
    } else {
      val n = (X + Y) / 3
      val r = X - n
      print(solve6(n, r))
    }
  }
}

Measured memory_bytes: 108896
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
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;
}

int main(){
    COMinit();
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ll ans = 0;
    ll u = H-A-1;
    ll r = B;
    while(true){
        ans += COM(u+r, u) * COM(H-u-1 + W-r-1, H-u-1);
        ans %= MOD;
        u--;
        r++;
        if(u < 0 or B == r) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8328
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  //            1 2 3 4 5 6 7 8 9 101112
  int a[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1};
  long x, y;
  cin >> x >> y;
  if (a[x] == a[y]) puts("Yes");
  else puts("No");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))


perm = []
for i in range(1, n + 1):
    perm.append(i)

cnt_perm = []
for perms in itertools.permutations(perm, n):
    cnt_perm.append(list(perms))

print(abs(cnt_perm.index(p)- cnt_perm.index(q))) 

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string O, E;
    cin >> O >> E;
    REP(i, O.length())
    {
        cout << O[i];
        if (E.length() > i)
            cout << E[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func intAbs(x int) int {
	return int(math.Abs(float64(x)))
}

func main() {
	sc.Split(bufio.ScanWords)

	INF := int(math.Pow10(11))
	A, B, Q := scanInt(), scanInt(), scanInt()
	L, X := make([][]int, 2), make([]int, Q)

	L[0] = make([]int, A+2)
	L[0][0], L[0][A+1] = -INF, INF
	for i := 1; i <= A; i++ {
		L[0][i] = scanInt()
	}
	L[1] = make([]int, B+2)
	L[1][0], L[1][B+1] = -INF, INF
	for i := 1; i <= B; i++ {
		L[1][i] = scanInt()
	}
	for i := 0; i < Q; i++ {
		X[i] = scanInt()
	}

	for _, x := range X {
		index := make([]int, 2)
		index[0] = sort.Search(len(L[0]), func(i int) bool { return L[0][i] >= x })
		index[1] = sort.Search(len(L[1]), func(i int) bool { return L[1][i] >= x })

		ans := 4 * INF
		for i := 0; i < 2; i++ {
			for j := 0; j < 2; j++ {
				for k := 0; k < 2; k++ {
					ans = intMin(ans, intAbs(x-L[k][index[k]-i])+intAbs(L[k][index[k]-i]-L[1-k][index[1-k]-j]))
				}
			}
		}

		fmt.Println(ans)
	}
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < b)
        rep(i, b) cout << a;
    else
        rep(i, a) cout << b;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
using namespace std;

int a, b, c;
vector<int>V;
int x[10], y[10], z[10];
bool S;
int MAX = -1;
vector<int>Copy;
void DFS(int d) {
	if(a==d){
		bool K = true;
		for (int i = 0; i < c; i++) {
			int sum = 0;
			for (int j = x[i]; j <= y[i]; j++) {
				sum += V[j];
			}
			if (sum != z[i]) {
				K = false;
			}
		}
		if (K) {
			int n = 0;
			for (int i = 0; i < a; i++) {
				n += V[i];
			}
			if (n > MAX) {
				MAX = n; Copy = V;
			}
			S = true;
		}
		return;
	}
	for (int i = 0; i <= b; i++) {
		V.push_back(i);
		DFS(d + 1);
		V.pop_back();
	}
}
signed main() {
	scanf("%d%d%d", &a, &b, &c);
	for (int i = 0; i < c; i++) { scanf("%d%d%d", &x[i], &y[i], &z[i]); x[i]--; y[i]--; }
	DFS(0);
	if (!S)puts("-1");
	else {
		for (int i = 0; i < a; i++) {
			if (i)cout << " ";
			cout << Copy[i];
		}
		puts("");
	}
}

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

int main(){
    string s;
    cin >>s;
    int cha_n = s.size()-2;
    char ini_c = s.at(0);
    char last_c = s.at(s.size()-1);
    cout << ini_c << cha_n << last_c << endl;
    
}

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

int main(){
  long long int n, x, y, ctr = 0, d;
  cin >> n >> d;
  for(int i = 0 ; i < n ; i++){
	cin >> x >> y;
    if( (x * x + y * y) <= (d * d) )
      ctr++;
  }
  cout << ctr << endl;
  return(0);
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>

int main(void){
    char s[1001],t[1001];
    scanf("%s%s",s,t);
    int slen = strlen(s);
    int tlen = strlen(t);
    int ans = 1001;
    int tmp;
    for(int i = slen-tlen;i >= 0;i--){
        tmp = 0;
        for(int j = 0;j < tlen;j++)if(s[i+j] != t[j])tmp++;
        ans = tmp < ans ? tmp : ans;
    }
    printf("%d",ans);
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include <cmath>
#include <random>
#include <functional>
#include <climits>
using namespace std;
using lint=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint n,m,cnt=0;
  cin>>n>>m;
  vector<pair<lint ,lint >> v(n);
  for(int i=0;i<n;i++) cin>>v[i].first>>v[i].second;
  sort(v.begin(),v.end());
  //for(int i=0;i<n;i++) cout<<v[i].first<<" "<<v[i].second<<endl;
  for(int i=0;i<n;i++){
    if(m-v[i].second<=0){
      cnt+=v[i].second*v[i].first;
      m-=v[i].second;
      if(m<0) cnt-=abs(m)*v[i].first;
      break;
    }
    else {
      cnt+=v[i].second*v[i].first;
      m-=v[i].second;
      if(m==0) break;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 1792
k = gets.split(' ').first.to_i
a = gets.split(' ').map(&:to_i)
dis_array = a.map.with_index { |pos, i| (a[i + 1]) ? a[i + 1] - pos : k - pos + a[0] }
print dis_array.sort[0..-2].inject(0) { |sum, p| sum + p }

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N;
ll H[25];
ll ans;
int main() {
	cin >> N;
	REP(i,0,N) cin>>H[i];
	REP(i,0,N){
		bool ok=true;
		REP(j,0,i){
			if(H[j] > H[i]){
				ok=false;
				break;
			}
		}
		if(ok) ans++;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

x, y, z = inm()
print(z, x, y)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1), s(n, 0) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
        if (s[u] == 0 || s[v] == 0) s[u] = 0; else s[u] += s[v];
    }
    vector<int> p;
    vector<ll> s;
};

struct P {
    int a, b, c;
};

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

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

    vector<P> p[2];
    vector<int> x[2];
    int k[2];
    int s[2];

    for (int h = 0; h < 2; h++) {
        p[h].resize(n[h]);
        for (auto& [a, b, c] : p[h]) {
            cin >> a >> b >> c;
            x[0].push_back(a);
            x[h].push_back(b);
            x[1].push_back(c);
        }
        x[h].push_back(0);
    }
    for (int h = 0; h < 2; h++) {
        sort(x[h].begin(), x[h].end());
        k[h] = unique(x[h].begin(), x[h].end()) - x[h].begin();
        x[h].resize(k[h]);
    }
    for (int h = 0; h < 2; h++) {
        for (auto& [a, b, c] : p[h]) {
            a = lower_bound(x[0].begin(), x[0].end(), a) - x[0].begin();
            b = lower_bound(x[h].begin(), x[h].end(), b) - x[h].begin();
            c = lower_bound(x[1].begin(), x[1].end(), c) - x[1].begin();
        }
        s[h] = lower_bound(x[h].begin(), x[h].end(), 0) - x[h].begin();
    }
    
    vector<vector<char>> u(x[0].size(), vector<char>(x[1].size(), 0));
    for (const auto& [a, b, c] : p[0]) {
        for (int i = a; i < b; i++) {
            u[i][c] |= 1;
        }
    }
    for (const auto& [a, b, c] : p[1]) {
        for (int j = b; j < c; j++) {
            u[a][j] |= 2;
        }
    }

    UnionFind uf(k[0] * k[1]);
    for (int i = 0; i < k[0]; i++) {
        for (int j = 0; j < k[1]; j++) {
            int t = k[1] * i + j;
            if (i < k[0] - 1 && j < k[1] - 1) {
                uf.s[t] = (ll)(x[0][i + 1] - x[0][i]) * (x[1][j + 1] - x[1][j]);
            }
            if (!(u[i][j] & 1)) {
                if (j == 0) uf.s[t] = 0; else uf.unite(t, t - 1);
            }
            if (!(u[i][j] & 2)) {
                if (i == 0) uf.s[t] = 0; else uf.unite(t, t - k[1]);
            }
        }
    }

    ll r = uf.s[uf.root(k[1] * s[0] + s[1])];
    if (r == 0) {
        cout << "INF" << endl;
    } else {
        cout << r << endl;
    }

    return 0;
}

Measured memory_bytes: 117788
s = list(input())
n = len(s)
c = (n - 1) // 2
s_reversed = s[::-1]
if s != s_reversed:
    print('No')
else:
    s_former = s[0:c]
    sf_reversed = s_former[::-1]
    s_later = s[c + 1:]
    sl_reversed = s_later[::-1]
    if s_former == sf_reversed and s_later == sl_reversed:
        print('Yes')
    else:
        print('No')

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

#define DELETE 0

bool func(int h, int w, int n, vector<vector<int> > puyo){
  // ??\????????????????????????????????????????????????????????????????????????????????§???
  // ?????????????????´??????????????????
  for(int k = 0; k < h; k++)
    for(int i = 1; i < h; i++)
      for(int j = 0; j < w; j++)
        if(puyo[i][j] == DELETE)
          swap(puyo[i][j], puyo[i - 1][j]);

  
    // ???????¶????????????§??°?????????
  bool flag;
  do{
    // ?????????????????°????????£?????????
    flag = false;

    // ??????????£???????????????£?????????
    vector<vector<bool> > deletePuyo(h, vector<bool>(w, false));

    // ??????????????°???????????????
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(puyo[i][j] == DELETE){ continue; }
          
        // ??????[i][j]?????????????????¨??????
        // ??????????????§????????????????±???????
        // ??£?¶??????????n??\????????£???????¶????
        int seg;
        for(seg = 1; j + seg < w; seg++)
          if(puyo[i][j] != puyo[i][j + seg])
            break;
        if(seg >= n)
          for(int k = 0; k < seg; k++)
            deletePuyo[i][j + k] = true;

        // ??????????§????
        for(seg = 1; i + seg < h; seg++)
          if(puyo[i][j] != puyo[i + seg][j])
            break;
        if(seg >= n)
          for(int k = 0; k < seg; k++)
            deletePuyo[i + k][j] = true;  
      }
    }

    // ??????????£????DELETE?????????
    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++)
        if(deletePuyo[i][j]){
          flag = true;
          puyo[i][j] = DELETE;
        }
    
    // DELETE ????????£????????????????????????????????????
    // (???????????????????????????)
    for(int k = 0; k < h; k++)
      for(int i = 1; i < h; i++)
        for(int j = 0; j < w; j++)
          if(puyo[i][j] == DELETE)
            swap(puyo[i][j], puyo[i - 1][j]);
     
  }while(flag);

  
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
      if(puyo[i][j] != DELETE)
        return false;
  
  return true;
}

int main(void){
  int h, w, n;
  cin >> h >> w >> n;

  // ?????¢???????????????
  char input;
  vector<vector<int> > puyo(h, vector<int>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> input;
      if(input == '.'){ puyo[i][j] = DELETE; }
      else{ puyo[i][j] = input - 'A' + 1; }
    }
  }
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w - 1; j++){
      swap(puyo[i][j], puyo[i][j + 1]);        
      if(func(h, w, n, puyo)){
        cout << "YES" << endl;
        return 0;
      }
      swap(puyo[i][j], puyo[i][j + 1]);
    }
  }

  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3160
/*C - Welcome to AtCoder*/

#include <bits/stdc++.h>

using namespace std;

int main(){
   
	map <int, int> WA;
	set <int> AC;
	int ansWA = 0;
	int problems;
	int submit;
	
	 cin >> problems >> submit;
	 string veredict;
	 int p; 

	  for(int i = 0; i < submit; i++){
		cin >> p >> veredict;
		if(veredict == "AC")
		   AC.insert(p);
		
		if(veredict == "WA"){
 
		  if(AC.count(p) == 0)
			 if(WA.count(p))
				WA[p]++;
			 else
				 WA[p]= 1;
		  } 
	   }

	 map <int, int> ::  iterator it;
	
	 for(it = WA.begin(); it != WA.end(); it++){
	 	if(AC.count(it -> first))
	  		ansWA += it -> second;
	  }

	cout << AC.size() << " " << ansWA;

   return 0;
}


Measured memory_bytes: 4992
/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                   ____/`---'\____
                  /  \\|     |//  \
                 / \\||| /:\ |||// \
                / _||||| -:- |||||- \
               |   | \\\ \-/ /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
            ____'. .'  /--.--\  `. .'_____
          /"" '<  `.___\_<|>_/___.' >' "" \
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` / _/
          `-.____`.___ \_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    I_LOVE_ADITI_GOEL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const long double DEL = 1e-12;
const int mod =  1000000007;
const int LIM = 100005;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define deb(a) cerr << #a << ": " << a << endl
#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define Rev(v) reverse(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define mem(a,b) memset(a,b,sizeof(a))
#define umii unordered_map<int,int>
#define all(a) a.begin() , a.end()
#define vvi vector<vector<int>>
#define pq priority_queue<int>
#define sqr(a) (((a) * (a)))
#define double long double
#define dbg cout<<"\nhi\n"
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define vi vector<int>
#define nl cout<<"\n"
#define pb push_back
#define int long long
#define sp <<" "<<
#define ss second
#define ff first
 
int fpow(int x, int n)
{
    int res = 1;
    while(n){
          if(n&1){
                res = res * x % mod;
          }
          x = x * x % mod;
          n>>=1;
    }
    return res;
}
int gcd(int a,int b)
{
    if(b == 0)
    {
          return a;
    }
    return gcd(b,a % b);
}
void sieve(int n)
{
      bool prime[5*LIM];
      memset(prime, true, sizeof(prime));
      int rootn = (int)sqrt(n);
      for (int p = 2; p <= rootn; p++)
      {
            if (prime[p] == true)
            {
                  for (int i = p*p; i <= n; i += p)
                  {
                        prime[i] = false;
                  }
            }
      }
      prime[1] = 0;
}
int cnt, sum, mid, mx, mn, ans, a[2*LIM];
int n, m, d, p, q, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;

//******************************************* CHECK CONSTRAINTS **************************************************


int32_t main()
{     fio;
      cin>>n>>s;
      i = 0;
      j = n-1;
      while(i<j)
      {
            if(s[i] == 'R')
            {
                  i++;
                  continue;
            }
            else if(s[j] == 'R')
            {
                  cnt++;
                  s[i] = 'R';
                  s[j] = 'W';
                  i++;
            }
            j--;
      }
      cout<<cnt;
     
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=405;
const int MM=1e5+5;
int n,m,a[MM],b[MM];
bool f[MN][MN],vis[MN];
int main(){
	scanf("%d%d",&n,&m);
	for(reg int i=1;i<=m;i++)scanf("%d%d",a+i,b+i);
	for(reg int i=1;i<=n;i++){
		f[i][i]=1;
		for(reg int j=m;j;j--){
			if(f[i][a[j]]&&f[i][b[j]]){vis[i]=true;break;}
			if(f[i][a[j]])f[i][b[j]]=1;
			if(f[i][b[j]])f[i][a[j]]=1;
		}
	}
	reg int ans=0;
	for(reg int i=1;i<=n;i++)
		for(reg int j=i+1;j<=n;j++){
			if(vis[i]||vis[j])continue;
			reg int flg=1;
			for(reg int k=1;k<=n;k++)
				if(f[i][k]&&f[j][k])flg=0;
			ans+=flg;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int p(int A,int B){
  if(!B)return 1;
  if(B%2)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
int k[10000000];
int c(int A,int B){
  return k[A]*p(k[A-B]*k[B]%mod,mod-2)%mod;
}
signed main(){
  k[0]=1;
  for(int i=1;i<10000000;i++)
    k[i]=k[i-1]*i%mod;
  int K;
  string S;
  cin>>K>>S;
  int N=S.size(),ans=0;
  for(int i=0;i<=K;i++)
    ans=(ans+c(N+K-i-1,N-1)*p(25,K-i)%mod*p(26,i)%mod)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 83372
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int N,M;
	cin >> N>>M;
	vector<int> a(N),b(N),c(M),d(M);
	for (int i = 0; i < N; i++) {
		cin >> a[i]>>b[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> c[i] >> d[i];
	}
	vector<int> ans(N);
	for (int i = 0; i < N; i++) {
		int min_dis = 1000000000;
		for (int j = 0; j < M; j++) {
			if (min_dis > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				min_dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans[i] = j+1;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i]<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		    Scanner sc = new Scanner(System.in);

		    String s_original = sc.nextLine();
		    String[] s = s_original.split("",0);
		    int flg=0;

		    for(int i=0; i<s.length-1;i++) {
		    	if(s[i].equals(s[i+1])) {
		    		System.out.println("Bad");
		    		flg=1;
		    		break;
		    	}
		    }
		    if(flg==0) {
		    	System.out.println("Good");
		    }

		    sc.close();
	}
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long f = 0;

		for (int i = n; i > 0; i /= 10) {
			f += i % 10;
		}

		if (n % f == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23124
while 1:
	n=list(raw_input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print "NA"
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print count
			break
		n=sorted(n)
		l=int("".join(map(str,n[::-1])))
		s=int("".join(map(str,n[n.count("0"):])))
		n=list(str(l-s))
		n=["0"]*(4-len(n))+n
		count+=1

Measured memory_bytes: 4236
def roll(die, d):
    if d == "E":
        return [die[3], die[1], die[0], die[5], die[4], die[2]]
    if d == "N":
        return [die[1], die[5], die[2], die[3], die[0], die[4]]
    if d == "S":
        return [die[4], die[0], die[2], die[3], die[5], die[1]]
    if d == "W":
        return [die[2], die[1], die[5], die[0], die[4], die[3]]
    if d == "L":
        return [die[0], die[3], die[1], die[4], die[2], die[5]]
    if d == "R":
        return [die[0], die[2], die[4], die[1], die[3], die[5]]

def checkdice(die1, die2):
    ans = False
    for d in "RRRNRRRNRRRSRRRSRRRNRRRR":
        if die1 == die2:
            ans = True
            break
        die2 = roll(die2, d)
    return ans

dice = []
msg = "Yes"
n = int(input())
for _ in range(n):
    dice.append(list(map(int, input().split())))
for i in range(n):
    for j in range(i + 1, n):
        if checkdice(dice[i], dice[j]):
            msg = "No"
print(msg)

Measured memory_bytes: 7808
#include<iostream>
using namespace std;
int main() {
	string S;
	int count = 0;
	cin >> S;
	for (int i = 0; i < (S.size()) / 2; i++) {
		if (S[i] != S[S.size() - i - 1]) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

const int INF = 0x3f3f3f3f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i + j < n) {
        dp[i + j] = min(dp[i + j], dp[i] + (int) abs(h[i] - h[i + j]));
      }
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vector <int> d;
  for(int i=0;i<n;i++){
    int dd;
    cin >> dd;
    d.push_back(dd);
  }
  int t = 0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      t += d[i]*d[j];
    }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


int main(){
  int l, r, maxl, minr, n, m;
  cin >> n >> m;
  maxl = 1;
  minr = n;
  REP(i,m){
    cin >> l >> r;
    if(l > maxl) maxl = l;
    if(r < minr) minr = r;
  }
  cout << max(0, minr - maxl + 1);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int GCD(int a,int b){
    if(a%b==0)return b;
    else return GCD(b,a%b);
}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
int main(){
    vector <long long> v;
    long long a,j,b,c,d,i,p[101];
    string s;
    cin>>a>>b;
    for(i=1;i<=a;i++){
    	p[i]=0;
	}
    for(i=1;i<=b;i++){
    	cin>>c;
    	for(j=1;j<=c;j++){
    		cin>>d;
    		p[d]=1;
		}
	}
	d=0;
	for(i=1;i<=a;i++){
		if(p[i]==0){
			d++;
		}
	}
	cout<<d;
}

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


int main(int argc, const char * argv[]) {
  string s;
  cin>>s;
  if (s.length() == 0 || s.length() == 1) {
    cout<< s.length();
    return 0;
  }
  vector<long long int> alpha(26,0);
  long long int pairs = 0;
  long long int result = 0;
  for (long long int i = 0; i < s.length(); i++) {
    ++alpha[s[i] - 'a'];
  }
  for (long long int j = 0; j < 26; j++) {
    pairs += alpha[j] * (alpha[j] - 1) / 2;
  }
  result = result + s.length() * (s.length() - 1) / 2 - pairs + 1;
  cout << result;
  return 0;
}


Measured memory_bytes: 640
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

words = input().split()
ans = ""
flag = True
for i in range(len(words)):
    s = words[i]
    s = s.replace(" ","")
    s = s.replace(",","")
    s = s.replace(".","")
    if len(s) > 2 and len(s) < 7:
        if flag:
            ans = s
            flag = False
        else:
            ans = ans + " " + s
print(ans)


Measured memory_bytes: 5556
L,R = gets.split.map &:to_i
r = [R, L + 2019].min

min = 2019
L.upto(r-1) do |i|
  (i+1).upto(r) do |j|
    a = (i*j)%2019
    if a == 0
      puts 0
      exit
    end
    if a < min
      min = a 
    end
  end
end

puts min

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

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    for (int i = 0; i < n; ++i) cin >> c[i] >> d[i];
    int ans = 0;

    for (int i = 0; i < n; ++i) {
        // c_min: bA最小
        auto c_min = min_element(c.begin(), c.end());
        int cd_idx = distance(c.begin(), c_min);

        vector<int> t_idx;
        vector<int> t_num;
        for (int i = 0; i < a.size(); ++i) {
            if (a[i] < *c_min && b[i] < d[cd_idx]) {
                t_idx.push_back(i);
                t_num.push_back(b[i]);
            }
        }

        if (!t_idx.size()) {
            c.erase(c_min);
            d.erase(d.begin() + cd_idx);
            continue;
        }

        auto ab_max = max_element(t_num.begin(), t_num.end());
        int  ab_max_idx = t_idx[distance(t_num.begin(), ab_max)];

        if (ab_max != t_num.end()) {
            a.erase(a.begin() + ab_max_idx);
            b.erase(b.begin() + ab_max_idx);
            c.erase(c.begin() + cd_idx);
            d.erase(d.begin() + cd_idx);
        }

        ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=100010;
const int inf=2147483647;
LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
LL b[70],S=0,a[Maxn];int n;
void insert(LL x)
{
	for(int i=60;i>=0;i--)
	if(!(S&(1LL<<i))&&(x&(1LL<<i)))
	{
		if(!b[i]){b[i]=x;return;}
		x^=b[i];
	}
	for(int i=60;i>=0;i--)
	if((S&(1LL<<i))&&(x&(1LL<<i)))
	{
		if(!b[i]){b[i]=x;return;}
		x^=b[i];
	}
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)S^=(a[i]=read());
	for(int i=1;i<=n;i++)insert(a[i]);
	LL ans=0;
	for(int i=60;i>=0;i--)
	if(!(S&(1LL<<i))&&!(ans&(1LL<<i)))ans^=b[i];
	for(int i=60;i>=0;i--)
	if((S&(1LL<<i))&&(ans&(1LL<<i)))ans^=b[i];
	printf("%lld",ans+(S^ans));
}

Measured memory_bytes: 1024