akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//深さ優先探索
//全て添字で扱うこと
void dfs(ll n, vector<vll> &next, vll &cnt, ll start) {
  stack<ll> task;
  task.push(start);
  vll seen(n, 0);
  seen[start] = 1;
  while (task.size() > 0) {
    queue<ll> subtask;
    for (ll i = 0; i < next[task.top()].size(); i++) {
      if (seen[next[task.top()][i]] == 0) {
        cnt[next[task.top()][i]] += cnt[task.top()];
        subtask.push(next[task.top()][i]);
        seen[next[task.top()][i]] = 1;
      }
    }
    task.pop();
    while (subtask.size() > 0) {
      task.push(subtask.front());
      subtask.pop();
    }
  }
  return;
}

int main() {
  ll n, q;
  cin >> n >> q;
  vll a(n - 1), b(n - 1);
  for (ll i = 0; i < n - 1; i++) cin >> a[i] >> b[i];
  vll p(q), x(q);
  for (ll i = 0; i < q; i++) cin >> p[i] >> x[i];
  vector<vll> next(n, vll(0));
  for (ll i = 0; i < n - 1; i++) {
    next[a[i] - 1].push_back(b[i] - 1);
    next[b[i] - 1].push_back(a[i] - 1);
  }
  vll cnt(n, 0);
  for (ll i = 0; i < q; i++) cnt[p[i] - 1] += x[i];
  dfs(n, next, cnt, 0);
  for (ll i = 0; i < n - 1; i++) cout << cnt[i] << " ";
  cout << cnt[n - 1] << endl;
}

Measured memory_bytes: 24276
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <chrono>
using namespace std;

int main() {
	vector<vector<int>>C(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> C[i][j];
		}
	}

	vector<int>A(3,1e9);
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			A[i] = min(A[i], C[i][j]);
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			C[i][j] -= A[i];
		}
	}
	bool flag = true;
	for (int i = 0; i < 3; i++) {
		if (flag)flag = (C[0][i] == C[1][i] && C[1][i] == C[2][i]);
	}

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

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int counter = 1;
		while (sc.hasNext()) {
			String s1 = sc.next();
			if (s1.equals("0")) {
				break;
			}
			System.out.println("Case "+counter+": "+s1);
			counter++;
		}
	}
}

Measured memory_bytes: 42308
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  string s;
  int b[200]={};

  cin>>s;
  for(int i=0;i<s.size();i++){
    b[(int)s[i]]+=1;
  }

  for(int i=1;i<n;i++){
    int a[200]={};
    cin>>s;

    for(int j=0;j<s.size();j++){
      a[(int)s[j]]+=1;
    }

    for(int k=0;k<200;k++){
      b[k]=min(b[k],a[k]);
    }
  }

  for(int i=0;i<200;i++){
    while(b[i]>0){
      cout<<(char)i;
      b[i]-=1;
    }
  }
  
  
  return 0;
}


Measured memory_bytes: 256
$N=<>;@A=glob<>;$#D=$N;
for($i=$N-1;$i>=0;$i--){
    $c=0;
    for($j=$i*2+1;$j<$N;$j+=$i+1){$c++if$D[$j]}
    $D[$i]=($A[$i]+$c)%2;
}
print$c+$D[0],$/;
for(1..$N){print"$_ "if$D[$_-1]}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

const int MN = 16;
ll sm[1<<MN];
ll dp[1<<MN];
bool vis[1<<MN];

ll solve(int f) {
    if (f == 0) return 0;
    if (vis[f]) return dp[f];
    vis[f] = true;
    int g = 0;
    ll ans = 0;
    do {
        g = ((g | (~f)) + 1) & f;
        if (!g) break;
        assert(g);
        ans = max(ans, solve(f ^ g) + sm[g]);
    } while (true);
    return dp[f] = ans;
}

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

    int n;
    cin >> n;
    VV<int> a(n, V<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    for (int f = 0; f < (1<<n); f++) {
        for (int i = 0; i < n; i++) {
            if (!(f & (1<<i))) continue;
            for (int j = i + 1; j < n; j++) {
                if (!(f & (1<<j))) continue;
                sm[f] += a[i][j];
            }
        }
    }

    cout << solve((1<<n) - 1) << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

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

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






int main() {
  ll a,b,c,d; // 変数の宣言
  cin >> a>>b>>c>>d; // 標準入力
  ll ans =0;

  ans = max(a*c,a*d);
  ans = max(ans,b*c);
  ans = max(ans,b*d);
  


  
  cout << setprecision(12) << ans << endl; // 標準出力
}

Measured memory_bytes: 3632
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nml = readln.split.to!(int[]);
    auto N = nml[0];
    auto M = nml[1];
    long L = nml[2];
    auto G = new long[][](N, N);
    foreach (ref g; G) g[] = long.max/3;
    foreach (_; 0..M) {
        auto abc = readln.split.to!(int[]);
        auto A = abc[0]-1;
        auto B = abc[1]-1;
        long C = abc[2];
        G[A][B] = C;
        G[B][A] = C;
    }

    foreach (k; 0..N) foreach (i; 0..N) foreach (j; 0..N) {
        if (G[i][j] > G[i][k] + G[k][j]) G[i][j] = G[i][k] + G[k][j];
    }

    auto H = new int[][](N, N);
    foreach (ref h; H) h[] = int.max/3;
    foreach (i; 0..N) foreach (j; 0..N) if (G[i][j] <= L) H[i][j] = 1;
    foreach (k; 0..N) foreach (i; 0..N) foreach (j; 0..N) {
        if (H[i][j] > H[i][k] + H[k][j]) H[i][j] = H[i][k] + H[k][j];
    }
    foreach (i; 0..N) foreach (j; 0..N) if (H[i][j] == int.max/3) H[i][j] = 0;

    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto st = readln.split.to!(int[]);
        auto s = st[0]-1;
        auto t = st[1]-1;
        writeln(H[s][t]-1);
    }
}

Measured memory_bytes: 11032
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

int main(){
    int H, W;
    
    cin >> H >> W;
    
    string S[H];
    
    for(int i = 0; i < H; ++i){
        cin >> S[i];
    }
    
    int dx[3] = {-1, 0, 1};
    
    int dy[3] = {-1, 0, 1};
    
    for(int x = 0; x < H; ++x){
        for(int y = 0; y < W; ++y){
            if(S[x][y] == '#'){
                cout << '#';
                continue;
            }
            int cnt = 0;
            for(int i = 0; i < 3; ++i){
                for(int j = 0; j < 3; ++j){
                    int tx = x + dx[i], ty = y + dy[j];
                    if(tx >= 0 && tx < H && ty >= 0 && ty < W){
                        if(S[tx][ty] == '#'){
                            cnt++;
                        }
                    }
                }
            }
            cout << cnt;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d%d",&n,&m);
	m=m/1000;
	if(m>10*n||m<n)
	{
		printf("-1 -1 -1\n");
		return 0;
	}
	for(i=0;10*i<=m;i++)
	{
		int a=m-10*i;
		y=n-i;
		if((a-y)%4==0&&(a-y)/4>=0&&y-(a-y)/4>=0)
		{
			printf("%d %d %d\n",i,(a-y)/4,y-(a-y)/4);
			return 0;
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(ll i=a;i<=(ll)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;
ll power(ll a,ll b) {
    ll t=1;
    while(b) {
        if(b&1) t=(t*a)%M;
        b>>=1;a=(a*a)%M;
    }
    return t;
}
void solve(ll n,ll r) {
    if(n<0||r<0) {cout<<0;return;}
    ll ans=1;
    repp(i,1,r) {
        ans=(ans*n)%M;
        n--;
    }
    repp(i,1,r) {
        ans=(ans*power(i,M-2))%M;
    }
    cout<<ans;
}
int main() {
    cs
    int x,y;cin>>x>>y;
    if((x+y)%3) bye(0)
    ll a=(2*y-x)/3,b=y-2*a;
    solve(a+b,min(a,b));
}

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

using namespace std;

vector<int> path[100010];
bool visited[100010];

int dfs(int v) {
    visited[v] = true;
    int ret = 0;
    for (int sv : path[v]) {
        if (visited[sv]) continue;
        ret ^= (dfs(sv) + 1);
    }
    return ret;
}

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

    for (int i = 0; i < N - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        path[x].push_back(y);
        path[y].push_back(x);
    }

    fill(visited, visited + N, false);

    cout << (dfs(0) > 0 ? "Alice" : "Bob") << endl;

    return 0;
}


Measured memory_bytes: 8960
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-9
# define MOD 1024523
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int 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*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=200005;

int main ()
{
    int A, B, C;
    scanf("%d%d%d",&A,&B,&C);
    puts(C%__gcd(A,B)==0?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
  #define pb push_back
#define f first
#define s second
  #define MAXN 100005
using namespace std;
int arr[MAXN];
int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin>>s;

	int n=s.length();
	int mx=1000;
	for(int i=0; i<n-2; i++) {
		string sa=s.substr(i,3);
		int a=stoi(sa);
		mx=min(mx,abs(753-a));
	}
	cout<<mx<<endl;

	return 0;
}


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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,si 2)

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))
LL gcd(LL x,LL y)
{
    if(x<y)
        swap(x,y);
    LL temp=y;
    while(temp!=0)
    {
        temp=x%y;
        x=y;
        y=temp;
    }
    return x;
}
int main()
{
    int i,j,n,m;
    LL a[101]= {0};
    cin>>n;
    for(i=0; i<n; i++)
        cin>>a[i];
    LL ans=a[0];
    for(i=1; i<n; i++)
        ans=ans/gcd(ans,a[i])*a[i];
    cout<<ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[110],x,y,m,t;
	while(cin>>n)
	{
		int i,sum=0;
		for(i=1;i<=n;i++)
			cin>>a[i];
		cin>>m;
		while(m--)
		{
			sum=0;
			cin>>x>>y;
			t=a[x];
			a[x]=y;
			for(i=1;i<=n;i++)
				sum+=a[i];
			a[x]=t;
			cout<<sum<<endl;
		}
	}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, m, a, b, s, t, u, steps;
vector< vector< int > > adj( 1e5 + 5 ), visited( 1e5 + 5, vector< int >( 3, 0 ) );
queue< pair< int, int > > q;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n >> m;
	for( int i = 1; i <= m; ++i )
	{
		cin >> a >> b;
		adj[ a ].emplace_back( b );
	}
	cin >> s >> t;
	q.push( { s, 0 } );
	visited[ s ][ 0 ] = 1;
	while( !q.empty() )
	{
		auto f = q.front();	q.pop();
		u = f.first;
		steps = f.second;
		if( u == t && steps % 3 == 0 )
		{
			cout << steps / 3 << "\n";
			exit( EXIT_SUCCESS );
		}
		for( int v : adj[ u ] )
		{
			if( !visited[ v ][ ( steps + 1 ) % 3 ] )
			{
				visited[ v ][ ( steps + 1 ) % 3 ] = 1;
				q.push( { v, steps + 1 } );
			}
		}
	}
	cout << -1 << "\n";
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    reverse(all(s));
    vec cnt(2019, 0);

    ll sum=0;
    ll b = 1;
    cnt[0]++;
    rep(i, s.size()){
        ll tmp = s[i]-'0';
        sum += tmp * b;
        sum %= 2019;
        cnt[sum]++;

        b *= 10;
        b %= 2019;
    }

    ll res = 0;
    rep(i, 2019){
        res += (ll)cnt[i]*(cnt[i]-1)/2;
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7820
#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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> l(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(ALL(l));
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        for (ll j = i + 1; j < n; j++)
        {
            ll mn = abs(l[i] - l[j]);
            ll mx = l[i] + l[j];
            ll left = upper_bound(ALL(l), mn) - l.begin();
            ll right = lower_bound(ALL(l), mx) - l.begin();
            if (right - left > 1)
            {
                ll tmp = right - left;
                if (left <= i && i <= right)
                {
                    tmp--;
                }
                if (left <= j && j <= right)
                {
                    tmp--;
                }
                // if (tmp > 0)
                // {
                //     cout << i << ' ' << j << ' ' << left << ' ' << right << endl;
                //     cout << tmp << endl;
                // }
                ans += max(tmp, 0LL);
            }
        }
    }
    cout << ans / 3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define _start  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb 		push_back
#define ss 		second
#define ff 		first
#define ll		long long
#define int     long long
#define mk      make_pair
#define ld 		long double
#define vi 		vector<int>
#define pi		pair<int,int>
#define mod 	1000000007
#define pqg     priority_queue<int>
#define pqs     priority_queue<int,vi,greater<int> >
#define forn(n) for(int i=0;i<n;i++)
#define w(t) 	int t; cin>>t; while(t--)
#define kick(t) int t; cin>>t; for(int p=0;p<t;p++)
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> oset;
ll powmod(ll base,ll exp,ll MOD=mod){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}

int32_t main(){
    _start
    string str;
    cin>>str;
    int len=0,ans=0;
    for(int i=0;i<3;i++){
        if(str[i]=='R'){
            len++;
            ans=max(len,ans);
        } else {
            len=0;
            ans=max(len,ans);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
import Control.Applicative

main :: IO ()
main = do
    ns <- map read . lines <$> getContents
    mapM_ print $ solve ns

solve :: [Int] -> [Int]
solve [] = []
solve (n':ns) = (solve' n'):(solve ns)
    where
        solve' :: Int -> Int
        solve' n = length [
            [a,b,c,d] | a <- [0..9],
                        b <- [0..9],
                        c <- [0..9],
                        d <- [0..9],
                        n == sum [a,b,c,d]
            ]

Measured memory_bytes: 3932
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll h,w,n; cin >> h >> w >> n;
    ll r,c; cin >> r >> c;
    string s,t; cin >> s >> t;
    ll x = c;
    rep(i,n){
        if(s[i]=='R'){
            x++;
        }
        if(x > w){
            puts("NO");
            return 0;
        }
        if(t[i]=='L'){
            x = max(x-1,1LL);
        }
    }
    x = c;
    rep(i,n){
        if(s[i]=='L'){
            x--;
        }
        if(x == 0){
            puts("NO");
            return 0;
        }
        if(t[i]=='R'){
            x = min(x+1,w);
        }
    }
    ll y = r;
    rep(i,n){
        if(s[i]=='D'){
            y++;
        }
        if(y > h){
            puts("NO");
            return 0;
        }
        if(t[i]=='U'){
            y = max(y-1,1LL);
        }
    }
    y = r;
    rep(i,n){
        if(s[i]=='U'){
            y--;
        }
        if(y == 0){
            puts("NO");
            return 0;
        }
        if(t[i]=='D'){
            y = min(y+1,h);
        }
    }
    puts("YES");
}


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

#define ll long long int 
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main()
{
	_fastio
	ll a;
	long double b,c;
	cin>>a>>b;
	c=(double)a;
	c=c*b;
 
	a=(ll)c;
 
	cout<<a<<en;
}

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

int main(){
  int N;
  cin >> N;
  
  int A[N];
  int B[N];
  int C[N];
  for(int i=1;i<=N;i++)
    cin >>A[i];
  for(int i=1;i<=N;i++)
    cin >>B[i];
  for(int i=1;i<N;i++)
    cin >>C[i];
  
  int ans=0;
  
  for(int i=1;i<N;i++){
    ans+=B[i];
    if(A[i]+1==A[i+1]){
      ans+=C[A[i]];
    }
    else
      continue;
  }
  
  ans+=B[N];
  
  cout << ans;
  
  return 0;
}



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

int main()
{
	long long n,k;
	cin>>n>>k;
	long long f=0,h=0;
	for(long long i=1;i<=n;i++){
		if(i%k == 0) f++;
		if(i%k == k/2) h++;
	}
	long long res;
	res = f*f*f;
	if(k%2 == 0){
		res += (h*h*h);
	}

	cout<<res;

	
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
la = [list(map(int,input().split())) for i in range(h)]
for i in range(h):
    l = list(map(int,input().split()))
    for j,num in enumerate(l):
        la[i][j] = abs(la[i][j]-num)
dp = [[0 for i in range(w)] for j in range(h)]
k = (h+w)*80+2
dp[0][0] = 1 << (k+la[0][0]) | 1 << (k-la[0][0])

for i in range(h):
    for j in range(w):
        if i:
            dp[i][j] |= (dp[i-1][j] << la[i][j]) | dp[i-1][j] >> la[i][j]
        if j:
            dp[i][j] |= (dp[i][j-1] << la[i][j]) | dp[i][j-1] >> la[i][j]
        
s = bin(dp[-1][-1])[2:]
l = len(s)-1
ans = float('inf')
for i in range(l,-1,-1):
  if s[i]=='1':
    m = abs(l-i-k)
    if m<ans:
      ans = m
print(ans)


Measured memory_bytes: 20340
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

string S;

int main(){
    cin>>S;
    int N=S.size();

    for(int i=0;i<N;i++){
        if(S[i]!=S[N-i-1]){
            cout<<"No";
            return 0;
        }
    }

    for(int i=0;i<(N-1)/2;i++){
        if(S[i]!=S[(N-1)/2-i-1]){
            cout<<"No";
            return 0;
        }
    }

    for(int i=(N+1)/2;i<N;i++){
        if(S[i]!=S[N-(i-(N+1)/2)-1]){
            cout<<"No";
            return 0;
        }
    }

    cout<<"Yes";
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int N;
    cin >> N;
    vector<pli> A(N);
    for (int i=0; i<N; i++) {
      ll a;
      cin >> a;
      A[i] = {a, i};
    }

    // resolve
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    ll dp[2001][2001];
    memset(dp,0,sizeof(0));
    for (int l=0; l<N; l++) {
      for (int r=0; r<N; r++) {
        if (l+r == N) break;
        ll activeness = A[l+r].first;
        int org_place = A[l+r].second;
        dp[l][r+1] = max(dp[l][r] + activeness * abs(org_place-(N-r-1)),dp[l][r+1]);
        dp[l+1][r] = max(dp[l][r] + activeness * abs(org_place-l),dp[l+1][r]);
      }
    }

    // output
    ll ans = 0;
    for (int l=0; l<N; l++) {
      for (int r=0; r<N; r++) {
        ans = max(ans,dp[l][r]);
      }
    }
    cout << ans << endl;

    return 0;
}


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

int N, W;
int v[100], w[100];
int DP[10001];

int main(void) {
  cin >> N >> W;
  for (int i=0; i<N; i++) {
    cin >> v[i] >> w[i];
  }

  for (int i=0; i<N; i++) {
    for (int j=W; j>=w[i]; j--) {
      DP[j] = max(DP[j], DP[j-w[i]]+v[i]);
    }
  }

  cout << DP[W] << endl;

  return 0;
}

Measured memory_bytes: 1204
n,q=map(int,input().split())
s=list(input())
sum=[0]*n

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        sum[i+1]=sum[i]+1
    else:
        sum[i+1]=sum[i]
for j in range(q):
    l,r=map(int,input().split())
    print(sum[r-1]-sum[l-1])

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

int main(){
	string s;
	bool balance = true;
	int a,b;
	cin >> s;
	if (s.length() == 2){
		if (s[0] == s[1]){
			balance = false;
			a = 0; b = 1;
		} 
	} else if (s.length() > 2){
	for (int i = 0;i <= s.length() - 3;i++){
		if ((s[i] == s[i + 1])||(s[i] == s[i+2])||(s[i+1] == s[i+2])){
			balance = false;
			a = i; b = i + 2;
			break;
		}
	}
}
	if (balance) {
		cout << "-1 -1\n";
	} else cout << a + 1 << " " << b + 1 << endl;
}

Measured memory_bytes: 512
object Main extends App {
    val n = io.StdIn.readLine().toInt
    val st = io.StdIn.readLine().split(' ')
    val s = st(0)
    val t = st(1)

    var ans: String = ""
    for(i <- 0 until n){
        ans += s(i)
        ans += t(i)
    }
    println(ans)
}

Measured memory_bytes: 25500
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))

pos = [1]

for i in range(2 * n):
	nxt = A[pos[-1]]
	pos.append(nxt)

if k < n + 1:
	print(pos[k])
	exit()

loop_end = n
loop_start = n - 1

while pos[loop_start] != pos[loop_end]:
	loop_start -= 1

period = loop_end - loop_start
m = n - period
k = m + (k - m) % period

print(pos[k])

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    int mat[3][3];
    for(int i = 0; i<3; i++){
        for(int j = 0; j<3; j++) cin>>mat[i][j];
    }
    int n, x; cin>>n;
    for(int i = 0; i<n; i++){
        cin>>x;
        bool found  = 0;
        for(int p = 0; p<3; p++){
            for(int q = 0; q<3; q++){
                if(mat[p][q]==x){
                    mat[p][q] = -1;
                    found = 1;
                    break;
                }
            }
            if(found) break;
        }
    }

    bool bingo = 0;
    for(int i = 0; i<3; i++){
        if(mat[i][0]==mat[i][1] && mat[i][1]==mat[i][2] && mat[i][0]==-1){
            bingo = true;
            break;
        }
    }
    if(bingo) return cout<<"Yes\n", 0;

    for(int i = 0; i<3; i++){
        if(mat[0][i]==mat[1][i] && mat[1][i]==mat[2][i] && mat[0][i]==-1){
            bingo = true;
            break;
        }
    }
    if(bingo) return cout<<"Yes\n", 0;
    
    if(mat[0][0]==mat[1][1] && mat[1][1]==mat[2][2] && mat[0][0]==-1) bingo = true;
    if(bingo) return cout<<"Yes\n", 0;
    
    if(mat[0][2]==mat[1][1] && mat[1][1]==mat[2][0] && mat[1][1]==-1) bingo = true;
    if(bingo) return cout<<"Yes\n", 0;
    
    cout<<"No\n";
    return 0;
}

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

int main() {
    int N, D, X, A;
    cin >> N >> D >> X;
    int ans = X;
    rep(i, N) {
        cin >> A;
        ans += (D - 1) / A + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
t = int(input())
m = list(map(int,input().split()))
q={}
mod=10**9+7
z=False
cnt0=0
for i in range(t):
    d=m[i]
    a=(t-1-d)//2
    if d==0:
        cnt0+=1
    if (a,a+d) not in q:
        q[(a,a+d)]=0
    q[(a,a+d)]+=1
    if q[(a,a+d)]>2:
        z=True
        break
if z or cnt0>1:
    print(0)
elif cnt0==1 and t%2==0:
    print(0)

   
else:
    res=1
    for i in q:
        if i[0]==i[1]:
            res=res*1
        else:
            res=res*2
    print(res%mod)

Measured memory_bytes: 18856
#include <bits/stdc++.h>
 
std::string str[128][128];
char field[128][128];
int W, H;
 
void Load() {
  scanf("%d %d", &W, &H);
  for(int i = 0; i < H; ++i) {
    scanf("%s", field[i]);
  }
}
 
void init() {
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      str[i][j].clear();
    }
  }
}
std::string& greater(std::string& a, std::string& b) {
  if( a.size() != b.size() ) {
    if( a.size() < b.size() ) return b;
    else return a;
  }
  if( a < b ) {
    return b;
  }
  return a;
}
 
void solve() {
  for(int r = 0; r < H; ++r) {
    for(int c = 0; c < W; ++c) {
      if( not ( '0' <= field[r][c] and field[r][c] <= '9' ) ) continue;
      std::string t1;
      std::string t2;
      if( 0 <= c - 1 ) {
        t1 = str[r][c-1];
      }
      if( 0 <= r - 1 ) {
        t2 = str[r-1][c];
      }
      std::string t = greater(t1, t2);
      if( t.size() == 0 and field[r][c] == '0' ) continue;
      str[r][c] = greater(t1, t2) + field[r][c];
    }
  }
}
 
int main() {
  for(;;) {
    init();
    Load();
    if( W == 0 and H == 0 ) break;
    solve();
    std::string ans;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        ans = greater(ans, str[i][j]);
      }
    }
    if( ans.empty() ) {
      std::cout << 0 << std::endl;
    }
    std::cout << ans << std::endl;
  }  
   
  return 0;
}


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

const int INF = 1e9;
int d,n;
int a[110],e[110],r[110];
int memo[110][110];

int rec(int hp, int exp){
  if(hp==0)return 0;
  if(memo[hp][exp]>=0)return memo[hp][exp];

  int res = INF;
  for(int i=0;i<n;i++){
    if(exp>=r[i]){
      int nhp = max(0,hp-a[i]), nexp = min(100,exp+e[i]);
      if(hp == nhp && exp == nexp)continue;
      res = min(res, rec(nhp, nexp) + 1 );
    }
  }
  return memo[hp][exp] = res;
}

int main(){
  while(scanf("%d%d",&d,&n), d){
    for(int i=0;i<n;i++)scanf("%d%d%d",a+i,e+i,r+i);

    memset(memo,-1,sizeof(memo));
    int ans = rec(d,0);
    if(ans==INF)puts("NA");
    else printf("%d\n",ans);
  }
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int N;
vector<ll> d[1000001];
ll memo[1000001];
bool used[1000001];

ll dfs(ll x){
    if(memo[x]!=0) return memo[x];
    used[x]=true;
    if(d[x].size()==0) return memo[x]=1;
    ll ans=0;
    for(int i=0;i<d[x].size();i++) {
        ll y=d[x].at(i);
        if(used[y]&&memo[y]==0) return memo[x]=-1;
        ll k=dfs(y);
        if(k==-1) return memo[x]=-1;
        ans=max(ans,k+1);
    }

    return memo[x]=ans;

}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        vector<ll> kari;
        kari.push_back(0);
        for(int j=0;j<N-1;j++){
            int x,y; cin>>x; y=i; x--;
            if(x>y) swap(x,y);
            kari.push_back(x*1000+y);
        }

        for(int j=0;j<N-1;j++) d[kari.at(j)].push_back(kari.at(j+1));
    }
    ll ans=dfs(0)-1;
    if(ans==-2) cout<<-1<<endl;
    else cout<<ans<<endl;

}



Measured memory_bytes: 48128
/*
 ABC-166
 */
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

const int N=300005;


void solve()
{
    string s;
    cin>>s;
    if(s[1]=='B')
        s[1]='R';
    else
        s[1]='B';
    cout<<s<<endl;
}

int32_t main()
{
    IOS;
    // startTime=clock();
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    // cout<<getCurrentTime()<<endl;
    return 0;
}



Measured memory_bytes: 3652
num = int(input())
cards = [int(i) for i in input().split()]

def bubble_sort(num, cards):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in range(num-1, 0, -1):
			if cards[j] < cards[j-1]:
				card_tmp = cards[j]
				cards[j] = cards[j-1]
				cards[j-1] = card_tmp
				flag = 1
				count += 1
	return output(cards), count

def output(cards):
	sorting = [str(i) for i in cards]
	return (" ".join(sorting))

output, count = bubble_sort(num, cards)
print(output)
print(count)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

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

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

int main(){
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s, t;
    cin >> s >> t;
    vector<ll> v(s.size()+1, 0), v2(t.size()+1, 0);
    ll sum = 0;
    for (int i = 0; i < s.size(); ++i) {
        sum += (s[i] == 'A' ? 1 : 2);
        v[i+1] = sum;
    }
    sum = 0;
    for (int i = 0; i < t.size(); ++i) {
        sum += (t[i] == 'A' ? 1 : 2);
        v2[i+1] = sum;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        ll x = v[b]-v[a-1], y = v2[d]-v2[c-1];
        x = x%3, y = y%3;
        puts(x == y ? "YES" : "NO");
    }
    return 0;
}


Measured memory_bytes: 2432
from sys import stdin

n = int(stdin.readline().strip())
x1 = n // 1.08
x2 = n // 1.08 + 1

if int(x1 * 1.08) == n:
  print(int(x1))
elif int(x2 * 1.08) == n:
  print(int(x2))
else:
  print(":(")

Measured memory_bytes: 3060
def function(N, K):

	nums = 0
	if N%2 == 0:
		nums = len([_ for _ in range(N) if (_+1)%2==0])
	else:
		nums = len([_ for _ in range(N) if (_+1)%2==1])
		
	if nums >= K:
		print('YES')
	else:
		print('NO')
	

def main():
	nums = input().split(' ')
	function(int(nums[0]), int(nums[1]))

if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int n,k;
int p[100010],q[100010];

struct Array{
	int a[100010];
	void show(){
		rep1(i,n){
			printf("%d%c",a[i],(i==n)?'\n':' ');
		}
	}
}I;
void init(){
	rep1(i,n)I.a[i] = i;
}

void inv(Array &a){
	int a_[100010];
	rep1(i,n)a_[a.a[i]] = i;
	rep1(i,n)a.a[i] = a_[i];
}
Array pro(Array &a,Array &b){
	Array ret;
	rep1(i,n)ret.a[i] = a.a[b.a[i]];
	return ret;
}
Array pow(Array &a, int e){
	if(e == 0)return I;
	Array ret = pow(a,e/2);
	ret = pro(ret,ret);
	if(e%2 == 1){
		ret = pro(ret,a);
	}
	return ret;
}

Array f(Array &a,Array &b){
	inv(a);
	Array ret = pro(b,a);
	inv(a);
	return ret;
}

int main(){
	scanf("%d%d",&n,&k);
	rep1(i,n)scanf("%d",&p[i]);
	rep1(i,n)scanf("%d",&q[i]);
	init();
	
	static Array P,Q;
	rep1(i,n){
		P.a[i] = p[i];
		Q.a[i] = q[i];
	}
	static Array P_inv = P; inv(P_inv);
	static Array Q_inv = Q; inv(Q_inv);
	static Array F;
	F = pro(P_inv,Q);
	F = pro(F,P);
	F = pro(F,Q_inv);
	static Array R = pow(F,(k-1)/6);
	static Array L = R; inv(L);
	
	//P.show();
	//Q.show();
	//L.show();
	//R.show();
	
	int x = 6*((k-1)/6)+1;
	int y = x+1;
	static Array A = pro(P,R); A = pro(L,A);
	static Array B = pro(Q,R); B = pro(L,B);
	//cout << x << " " << y << endl;
	//A.show();
	//B.show();
	
	static Array C;
	while(y < k){
		C = f(A,B);
		A = B;
		B = C;
		x ++;
		y ++;
	}
	if(x == k)A.show();
	else B.show();
}


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

const int limit = 50;

int V, E;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

// 頂点vからどこまで訪問できるか深さ優先探索
void dfs(int v) {
  // 頂点vを訪問する
  visited[v] = true;
  for (int v2 = 0; v2 < V; ++v2) {
    // 頂点v2が隣接していなければ次の頂点
    if (graph[v][v2] == false) continue;
    // 頂点v2が隣接していて，訪問済みなら次の頂点に遷移
    if (visited[v2] == true) continue;
    // 頂点v2が隣接していて，未訪問なら訪問する
    dfs(v2);
  }
}

int main() {
  cin >> V >> E;

  for (int i = 0; i < E; ++i){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;

  for (int i = 0; i < E; ++i){
    // 辺を1個消す
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    // 訪問履歴の初期化
    for (int j = 0; j < V; ++j) visited[j] = false;

    dfs(0);

    // パスの存在確認
    bool bridge = false;
    for (int j = 0; j < V; ++j) if(visited[j] == false) bridge = true;
    if (bridge) ans += 1;

    // 辺を元に戻す
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
	input!(n: usize);
	input!(a: [i64; n]);

	// 0,2,4・・・が正
	let mut sum: i64 = 0;
	let mut ans: i64 = 0;
	for i in 0..n {
		sum += a[i];
		if i % 2 == 0 {
			if sum <= 0 {
				ans += 1 - sum;
				sum += 1 - sum;
			}
		}
		else {
			if sum >= 0 {
				ans += sum + 1;
				sum -= sum + 1;
			}
		}
	}
//	println!("ans={}", ans);

	// a[0]が負
	let mut sum: i64 = 0;
	let mut ans2: i64 = 0;
	for i in 0..n {
		sum += a[i];
		if i % 2 == 1 {
			if sum <= 0 {
				ans2 += 1 - sum;
				sum += 1 - sum;
			}
		}
		else {
			if sum >= 0 {
				ans2 += sum + 1;
				sum -= sum + 1;
			}
		}
	}
//	println!("ans2={}", ans2);

	println!("{}", std::cmp::min(ans, ans2));
}



Measured memory_bytes: 3708
use proconio::{input, fastout};


#[fastout]
fn main() {
    input! {
        n: u32,
        a: u32,
        b: u32,
    }

    let ans: u32 = (1..=n).filter(|n| {
        let sum = n.to_string().chars().map(|c| {
            (c as u8 - b'0') as u32
        }).sum();
        a <= sum && sum <= b
    }).sum();
    println!("{}", ans);
}


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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

ll gcdll(ll a, ll b){
    if(!b) return a;
    return gcdll(b, a%b);
}

void seive(int n){
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;

    for(int i=2; i*i<=n; i++){
        if(is_prime[i]){
            for(int j=i*i; j<=n; j+=i){
                is_prime[j] = false;
            }
        }
    }
}

vector<int> constructZFunc(string s){
    int n = s.size();
    vector<int> z(n);
    int l, r;
    l = r = 0;
    z[0] = 0;
    rep(i, 1, n-1){
        z[i] = 0;
        if(i<=r){
            z[i] = min(r-i+1, z[i-l]);  /// initialization, req. for linear time approach.
        }
        while(i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if(i+z[i]-1 > r){
            r = i+z[i]-1;
            l = i;
        }
    }
    return z;
}

#define pi 3.14159265358979323846

void solve(){
    double r;
    cin>>r;
    cout<<2*pi*r;
}

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

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

    return 0;
}



Measured memory_bytes: 3808
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	String c = sc.next();
	char op = c.charAt(0);
	int b = sc.nextInt();
	while(op=='+'||op=='-'||op=='*'||op=='/'){
            if (op == '+') {
                System.out.println(a+b);
            } else if (op == '-') {
                System.out.println(a-b);
            } else if (op =='*'){
                System.out.println(a*b);
            }else if (op =='/'){
                System.out.println(a/b);
            }else{
                break;
            }
         a = sc.nextInt();
        c = sc.next();
         op = c.charAt(0);
        b = sc.nextInt();
        }


    }
}



Measured memory_bytes: 26456
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
using vii = vector<vector<int>>;
using vi = vector<long>;


int main()
{
    long n, m;
    cin >> n >> m;
    vector<long> ac(n, 0), wa(n, 0);

    rep(i, m) {
        long tp;
        string ts;
        cin >> tp >> ts;
        tp--;
        
        if (ts == "AC") {
            ac[tp] = 1;
        }
        else if(ts == "WA"){
            if (ac[tp] == 0) {
                wa[tp]++;
            }
        }
    }

    long ansac = 0, answa = 0;
    rep(i, n) {
        ansac += ac[i];
        if(ac[i]) answa += wa[i];
    }

    cout << ansac << " " << answa << endl;
    return 0;
}

Measured memory_bytes: 1792