akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll K;
    cin >> K;
    vector<ll> A(K);
    rep(i,K) cin >> A[i];
    if(A[K-1] != 2){
        cout << -1 << endl;
        return 0;
    }
    ll M = 3,m = 2;
    rrep(i,K-1){
        if(M < A[i] || M < m){
            cout << -1 << endl;
            return 0;
        }
        M = (M / A[i]) * A[i] + A[i] - 1;
        m = ((m + A[i] - 1) / A[i]) * A[i];
    }
    if(M < m){
        cout << -1 << endl;
        return 0;
    }
    cout << m << ' ' << M << endl;
}


Measured memory_bytes: 1024
S=input()

N=len(S)
s0=list(S)

a=0
b=0
c=0

for i in range(N):
    if s0[i]==s0[N-1-i]:
        c=c+1

for i in range((N-1)//2):
    if s0[i]==s0[(N-1)//2-1-i]:
        a=a+1

for i in range((N+3)//2-1,N):
    if s0[i]==s0[N+(N+3)//2-i-2]:
        b=b+1

if a==b==(N-1)//2 and c==N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(void) {
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    const long double PI = 3.14159265358979323846264338327950L;

    cout << setprecision(18) <<  sqrtl((long double)(A*A + B*B) - (long double)(2*A*B)*cos((long double)(PI * 11.0 * (60.0 * H + M) /360.0))) << endl;
    return 0;
}


Measured memory_bytes: 4096
n = int(input())
lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

for i in range(1, 33):
    if i == n:
        print(lis[i-1])

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

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> P(N);
    rep(i,N) cin >> P[i];
    UnionFind uf(N+1);
    rep(i,M){
        int x,y;
        cin >> x >> y;
        uf.merge(x,y);
    }
    int ans = 0;
    rep(i,N){
        if(uf.issame(i+1,P[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a[110][110];

int main(){	
	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll ans=0;
	if(a+b>2*c){
		if(x>y){
			ans+=y*2*c;
			x-=y;
			if(a>2*c){
				ans+=x*2*c;
			}else ans+=x*a;
		}else{
			ans+=x*2*c;
			y-=x;
			if(b>2*c){
				ans+=y*2*c;
			}else ans+=y*b;
		}
	}else ans+=x*a+y*b;
	cout<<ans;
	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 maketime = sc.nextInt();
   int makecookie = sc.nextInt();
   int timelimit = sc.nextInt();
   int sum = 0;
   while(timelimit >= maketime)
   {
     timelimit -= maketime;
     sum += makecookie;
   }
    System.out.print(sum);
 }
}

Measured memory_bytes: 23252
import Data.List
import Control.Monad

foo :: [String] -> Int
foo = foldl (\acc x -> acc + (x-1)*x `div` 2) 0 . map length . group . sort . map sort

main = do
  num <- read <$> getLine :: IO Int
  ss  <- replicateM num getLine
  print $ foo ss



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

int main() {
  int N,K;
  scanf("%d %d", &N,&K);
  int a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }

  sort(a,a+N);

  int min = 1000000000;

  for(int i = 0; i < N-K+1; ++i){
    if(min>a[i+K-1]-a[i]) min = a[i+K-1]-a[i];
  }

  cout << min << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll get(string a, string b)
{
    ll ans = 0;
    rep(a.length())
        if(a[i]!=b[i])
            ans++;
    return ans;        
}

int main()
{
  FAST/**/
   
   string s,t;
   cin>>s>>t;
   
   ll l1 = s.length();
   ll l2 = t.length();
   
   ll ans = l2;
   
   for(ll i=0;i+l2-1<l1;i++)
   {
       string s1 = s.substr(i,l2);
       ans = min(ans, get(s1,t));
   }
   
   cout<<ans;
   
   
   return 0;        
}  

  
          
   

Measured memory_bytes: 3656
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)

//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

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

void solve()
{
    IN(n, p);
    string s; cin >> s;
    if (p == 2 || p == 5)
    {
        ll sum = 0;
        rep(i, n)
        {
            if ((s[i] - '0') % p == 0)
            {
                sum += i + 1;
            }
        }
        cout << sum << endl;
    }
    else
    {
        ll k[10005];
        k[0] = 1;
        ll r = 0;
        for (int i = n - 1; i >= 0; --i)
        {
            r = (r + (s[i] - '0') * modpow(10, n - i - 1, p)) % p;
            k[r]++;
        }
        ll sum = 0;
        rep(i, p)
        {
            sum += k[i] * (k[i] - 1) / 2;
        }
        cout << sum << endl;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 848
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll M, D;
    cin >> M >> D;
    ll ans = 0;
    for (ll m = 1; m <= M; m++) {
        for (ll d = 22; d <= D; d++) {
            ll mult = 1;
            ll copy_d = d;
            while (copy_d > 0) {
                if (copy_d % 10 == 1) {
                    mult = 0;
                    break;
                }
                mult *= copy_d % 10;
                copy_d /= 10;
            }
            if (mult == m) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

const DX: [i32; 4] = [1, 0, -1, 0];
const DY: [i32; 4] = [0, 1, 0, -1];

fn main() {
   input! {
      h: usize,
      w: usize,
      _s: [String; h]
   }
   let mut s: Vec<Vec<usize>> = vec![vec![0; w]; h];
   for i in 0..h {
      for (j, &b) in _s[i].as_bytes().iter().enumerate() {
         if b == b'#' {
            s[i][j] = 1;
         }
      }
   }
   for i in 0..h {
      for j in 0..w {
         if s[i][j] == 1 {
            let mut flag = false;
            for k in 0..4 {
               let ni = i as i32 + DX[k];
               let nj = j as i32 + DY[k];
               if ni < 0 || h as i32 <= ni {
                  continue;
               }
               if nj < 0 || w as i32 <= nj {
                  continue;
               }
               if s[ni as usize][nj as usize] == 1 {
                  flag = true;
                  break;
               }
            }
            if !flag {
               println!("No");
               return;
            }
         }
      }
   }
   println!("Yes");
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int a, b, c;
    cin >> a >> b >> c;

    REP(i, 100) {
        if ((a * i) % b == c) {
            std::cout << "YES" << std::endl;
            return 0;
        }
    }

    std::cout << "NO" << std::endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define pb push_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9;
//const ll INF = 1e18;
//const ll mod = 1000000007;
const ll mod = 998244353;

void solve(int tc){
    int n, k;
    cin >> n >> k;
    vpi s(k);

    for(int i = 0; i < k; i++){
        cin >> s[i].f >> s[i].s;
    }

    vl pref_sum(n+1, 0), dp(n+1, 0);
    dp[0] = 0; 
    dp[1] = 1;
    pref_sum[0] = 0;
    pref_sum[1] = 1;

    for(int i = 2; i <= n; i++){
        for(pii x : s){
            if(i - x.s > 0)
                (dp[i] += pref_sum[i-x.f] - pref_sum[i-x.s-1] + mod) %= mod;
            else if(i - x.f > 0)
                (dp[i] += pref_sum[i-x.f]) %= mod;
        }
        (pref_sum[i] = pref_sum[i-1] + dp[i]) %= mod;   
    }


    cout << dp[n] << "\n";
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    
    int tc = 1;
    //cin >> tc;
    for (int t = 0; t < tc; t++) solve(t);

    return 0;
}

Measured memory_bytes: 6308
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define mod 1000000007
using namespace std;
typedef long long int LL;

bool comp_x_greater(pair<int, int> &a, pair<int, int> &b) {
    return a.first  < b.first;
}
bool comp_y_lower(pair<int, int> &a, pair<int, int> &b) {
    return a.second  > b.second;
}

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

    vector<pair<int, int> > red;
    vector<pair<int, int> > blue;

    rep(i, N) {
        int a, b;
        cin >> a >> b;
        red.push_back(make_pair(a, b));
    }
    rep(i, N) {
        int c, d;
        cin >> c >> d;
        blue.push_back(make_pair(c, d));
    }
    sort(red.begin(), red.end(), comp_y_lower);
    sort(blue.begin(), blue.end(), comp_x_greater);

    int cnt = 0;
    bool is_used[N];
    rep(i, N)  {
        is_used[i] = false;
    }
    rep(b, N) {
        rep(a, N) {
            if (red[a].first < blue[b].first
                and red[a].second < blue[b].second
                and is_used[a] == false) {
                cnt++;
                is_used[a] = true;
                break;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

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

	i64 ans = 1;
	std::vector<i64> latte(30, 0);
	for(auto c: s) {
		int p = c - 'a';
		for(int i = 0; i < latte.size(); i++) {
			if(i == p) continue;
			ans += latte[i];
		}
		latte[p]++;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int n, k, m, a;

int main(){
	cin >> n >> k;
	a = (n-1)*(n-2)/2;
	if (k > a){
		cout << -1;
		return 0;
	}
	m = n - 1 + a - k;
	printf("%d\n", m);
	for (int i = 2; i <= n; ++i) printf("%d %d\n", 1, i);
	for (int i = 2; i < n && k < a; ++i){
		for (int j = i+1; j <= n && k < a; ++j, ++k){
			printf("%d %d\n", i, j);
		}
	}
}

Measured memory_bytes: 256
n = input().split()
x = int(n[0])
y = int(n[1])
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if (x in a) == True and (y in a) == True:
  print('Yes')
elif (x in b) == True and (y in b) == True:
  print('Yes')
elif (x in c) == True and (y in c) == True:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

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

  int ans = 1;
  for (int i = 1; i < S.size(); ++i){
    if (S[i] != S[i - 1]) ans++;
  }
  cout << ans << endl;
}


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

int main() {
  int a,b,k;
  cin >> a >> b >> k;
  int s = 0;

  
  for(int i =100 ; i > 0 ; i--){
    if(a%i == 0 && b%i == 0){
      s++;
      if( s == k){
        cout << i << endl;
        break;
      }
    }
  }
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

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

ll solve(string& s) {
    int L = s.size();
    vector<ll> dp(4, 0LL);
    dp[3] = 1;
    rep(i,L){
        vector<ll> dp2(4, 0LL);
        switch (s[i]) {
            case 'A':
                dp2[0] = dp[0];
                dp2[1] = dp[1];
                dp2[2] = dp[2];
                dp2[3] = dp[3];

                dp2[0] = ADD(dp2[0], dp[3]);
                break;
            case 'B':
                dp2[0] = dp[0];
                dp2[1] = dp[1];
                dp2[2] = dp[2];
                dp2[3] = dp[3];

                dp2[1] = ADD(dp2[1], dp[0]);
                break;
            case 'C':
                dp2[0] = dp[0];
                dp2[1] = dp[1];
                dp2[2] = dp[2];
                dp2[3] = dp[3];

                dp2[2] = ADD(dp2[2], dp[1]);
                break;
            case '?':
                dp2[0] = MUL(dp[0], 3);
                dp2[1] = MUL(dp[1], 3);
                dp2[2] = MUL(dp[2], 3);
                dp2[3] = MUL(dp[3], 3);

                dp2[0] = ADD(dp2[0], dp[3]);
                dp2[1] = ADD(dp2[1], dp[0]);
                dp2[2] = ADD(dp2[2], dp[1]);
                break;
        }
        dp = dp2;
    }
    return dp[2];
}

int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
    return 0;
}


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

int main (){
  int A,B,M;
  cin >> A>>B>>M;
  vector<int> a(A),b(B),sum(M);
  
  for (int i=0;i<A;i++){
    cin >> a[i];
  }
  for (int i=0;i<B;i++){
    cin >> b[i];
  }
  
  for (int i=0;i<M;i++){
    int x,y,c;
    cin >> x >> y >> c;
    sum[i] = a[x-1]+b[y-1]-c;
  }
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(sum.begin(),sum.end());
  
  cout << min(a[0]+b[0],sum[0]) << endl;
}

Measured memory_bytes: 1408
s=input()
a,b,c,d=list(map(int,s))
for ope1 in [-1,1]:
    for ope2 in [-1,1]:
        for ope3 in [-1,1]:
            if a+ b*ope1 + c*ope2 + d*ope3 == 7:
                print(str(a)+("+" if ope1==1 else "-")+str(b)+("+" if ope2==1 else "-")+str(c)+("+" if ope3==1 else "-")+str(d)+"=7")
                exit()

Measured memory_bytes: 3064
import java.lang.Math.abs
import java.util.*
import kotlin.math.max
import kotlin.math.min

// solution is at the bottom

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(true) {
            when(c) {
                '\n', Char.MIN_VALUE -> return@buildString
                else -> {
                    append(c)
                    c = readChar()
                }
            }
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }


fun main() {
    val n = readInt()
    var s = ""
    for (i in 1..n) s += "ACL"
    println(s)
}



Measured memory_bytes: 33916
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e9;

int dp[1 << 18][18];

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i, 0, n) cin >> a[i];
	rep(i, 0, n) cin >> b[i];
	rep(i, 0, 1 << n) rep(j, 0, n) dp[i][j] = INF;
	rep(i, 0, n) dp[1 << i][i] = 0;
	for(int mask = 0; mask < (1 << n); mask++){
		int c = __builtin_popcountll(mask);
		for(int i = 0; i < n; i++){
			if(dp[mask][i] == INF) continue;
			if(mask & (1 << i)){
				int r = 0;
				for(int j = 0; j < n; j++){
					if(mask & (1 << j)){
						r++;
						continue;
					}
					int pre = (((c - 1) % 2 == i % 2) ? a[i] : b[i]);
					int nxt = ((c % 2 == j % 2) ? a[j] : b[j]);
					if(pre <= nxt){
						dp[mask | (1 << j)][j] = min(dp[mask | (1 << j)][j], dp[mask][i] + abs(c - r));
					}
				}
			}
		}
	}
	int ans = INF;
	rep(i, 0, n) ans = min(ans, dp[(1 << n) - 1][i]);
	if(ans >= INF) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 37120
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , k;
  	cin >> n >> k;
	int a[n];
    rep(n) cin >> a[i];
	int c = 1;
	n -= k;
	while( n > 0 ) {
		n = n - k + 1;
	    c++;
	}
    cout << c;
}


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

int main()
{
	long long k;
	int n;
	scanf("%d%lld", &n, &k);
	int a[210000];
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int h = 1;
	int height[210000];
	vector<bool> visited(n+1, false);
	int st = 1;
	while(k && !visited[st]) {
		visited[st] = true;
		height[st] = h;
		h++;
		k--;
		st = a[st];
	}
	if(k) {
		k %= (h-height[st]);
		while(k) {
			st = a[st];
			k--;
		}
	}
	printf("%d\n", st);
}

Measured memory_bytes: 5336
#include<stdio.h>
#include<string.h>
 
int main()
{
    int i=0 ;
    int lenw=0 ,lent=0 ;
    int flg=0 ;
    char w[11] = {0} ;
    char t[1001] = {0} ;
 
    scanf("%s",w) ;
    lenw=strlen(w) ;
 
    for (i=0 ;i<lenw ;i++)
    {
        if (w[i] >= 'A' && w[i] <= 'Z')
        {
            w[i] = w[i] + 32 ;
        }
    }
 
    while (1)
    {
        scanf("%s",t) ;
 
        if (strcmp(t ,"END_OF_TEXT") == 0) break ;
 
        lent=strlen(t) ;
        for (i=0 ;i<lent ;i++)
        {
            if (t[i] >= 'A' && t[i] <= 'Z')
            {
                t[i] = t[i] + 32 ;
            }
        }
 
        if (strcmp(t ,w) == 0) flg++ ;
 
    }
 
    printf("%d\n",flg) ;
 
    return 0 ;
}


Measured memory_bytes: 2112
from collections import deque
lst = list(input().split())
stack = deque()

for i in lst:
    if (i.isdigit()):
        stack.append(i)
    else:
        a = stack.pop()
        b = stack.pop()
        c = eval(b+i+a)
        stack.append(str(c))
print(int(stack.pop()))


Measured memory_bytes: 5996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

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

int main(){
    int n, m, ac_ans = 0, wa_ans = 0;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    rep(i,m){
        cin >> p[i] >> s[i];
    }

    vector<int> ac(n,0);
    vector<int> wa(n,0);
    rep(i,m){
        if(s[i] == "AC"){
            ++ac[p[i]-1];
        }
        else if(ac[p[i]-1] == 0){
            ++wa[p[i]-1];
        }
    }

    rep(i,n){
        if(ac[i] != 0){
            ++ac_ans;
        }
    }
    rep(i,n){
        if(wa[i] != 0 && ac[i] != 0){
            wa_ans += wa[i];
        }
    }

    cout << ac_ans << ' ' << wa_ans << endl;

    return 0;
}


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

using namespace std;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int count = 0;
    for (; l <= r; ++l) {
        if (l % d == 0)
            ++count;
    }
    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    long double a, b;
    cin >> a >> b;
    cout.unsetf(ios::scientific);
    cout << (ll)floor(a*b) << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  
  for (int i = 0; i < N; i++) {
    string Si;
    cin >> Si;
    S.push_back(Si);
  }
  int C0 = 0;
  int C1 = 0;
  int C2 = 0;
  int C3 = 0;
  
  for (string &Si : S) {
 	if (Si == "AC") C0++;
    else if (Si == "WA") C1++;
    else if (Si == "TLE") C2++;
    else if (Si == "RE") C3++;
  }
  cout << "AC x " << C0 << endl;
  cout << "WA x " << C1 << endl;
  cout << "TLE x " << C2 << endl;
  cout << "RE x " << C3 << endl;
}

Measured memory_bytes: 9616
#include <stdio.h>
#include <stdlib.h>

int head,u , tail;
int q[1000001];
int map[1001][1001];
int dis[1001][1001];
int fac[10];
int sum = 0;
int w,h,n;

void enque(int x) {
  q[tail] = x;
  if(tail == 1000000) tail = -1;
  tail++;

}

int deque() {
  int x = q[head];

  if(head == 1000000) head = -1;
  head ++;
  return x;

}

int bfs(int s,int g) {
  int i,j;
  int dx[4] = {0,-1,0,1};
  int dy[4] = {1,0,-1,0};
  int nx,ny;
  head = tail = 0;

  enque(s);

  for(j = 0;j<h;j++) {
    for(i =0;i<w;i++) {
      dis[j][i] = -1;
    }
  }

  dis[s/w][s%w] = 0;
 
  while(tail != head) {

    u = deque(); 
     
    for(i=0;i<4;i++) {

      nx = u/w + dx[i];
      ny = u%w + dy[i];
      if(nx >=0 && ny >= 0 && nx <h && ny < w) {
	if(map[nx][ny] != -2 && dis[nx][ny] == -1) {
	  dis[nx][ny] = dis[u/w][u%w]+1;
	  enque(nx*w+ny);
	}
      }
    }
  }
  // printf("dis[%d][%d] = %d\n",g/w,g%w,dis[g/w][g%w]);
  return dis[g/w][g%w];
  
  
	 
}
       

int main() {
 
  int i,j,k;
  char ch[1002];
  int start;

  scanf("%d %d %d",&h,&w,&n);


  k = 0;
  for(i=0;i<h;i++) {
 scanf("%s",ch);
    for(j=0;j<w;j++) {
     
      if(ch[j] == 'S') {
	start = i*w+j;
	map[i][j] = 0;
      }
      else if(ch[j] == '.') map[i][j] = -1;
      else if(ch[j] == 'X') map[i][j] = -2;
      else {
	map[i][j] = ch[j] - '0';
	fac[ch[j]-'0'] = i*w+j;
      }
    }
  }

  /* for(j=0;j<h;j++) {
    for(i=0;i<w;i++) {
      printf("%d ",map[j][i]);
    }
    printf("\n");
    }*/

  for(i=1;i<=n;i++) {

    sum += bfs(start,fac[i]);
    start = fac[i];

  }

  printf("%d\n",sum);

  return 0;

}

  

Measured memory_bytes: 12328
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    s = insr()
    q = "Yes"
    for i in range(len(s)):
        if (i % 2 == 0 and s[i] == "L") or (i % 2 != 0 and s[i] == "R"):
            q = "No"
    print(q)
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1],1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

#-----------------------------------------------------------------------#
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Measured memory_bytes: 62656
from functools import reduce
import math

N = int(input())
sum = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(1,N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            sum += gcd(i,j,k)
print(sum)

Measured memory_bytes: 69784
#include<iostream>
#include<cstring>
#include<stdbool.h>
using namespace std;
int main(){
  char str[100001];
  bool ans[26];
  char out;
  for(int i=0;i<26;i++)
    ans[i]=true;

  cin >> str;
  for(int i=0;i<strlen(str);i++){
    ans[str[i]-'a']=false;
  }
  
  int cnt;
  for(cnt=0;cnt<26;cnt++){
    if(ans[cnt]){
      out='a'+cnt;
      break;
    }
  }
   
  if(cnt==26)
    cout << "None" << endl;
  else
    cout << out << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(void){

  int N;
  cin >> N;

  if(N==3){
    cout << "2 5 63" << endl;
  }
  else if(N==4){
    cout << "2 3 4 9" << endl;
  }
  else if(N>4 && N<8){
    cout << "2 3 4 9 " ;
    for(int i=0;i<N-4;i++){
      cout << 6*(i+1) << " ";
    }
    cout << endl;
  }
  else{
    for(int i=0;i<N/8;i++){
      for(int j=0;j<3;j++){
	cout << 12*(i+1) - 6 - 3 - 1 + j  << " ";
      }
      cout << 12*(i+1) -6<< " ";
      for(int j=0;j<3;j++){
	cout << 12*(i+1) - 3 - 1 + j  << " ";
      }
      cout << 12*(i+1) << " ";      
    }
    int amari=N%8;
    //for(int i=0;i<amari;i++){
    //cout << 12*(N/8) + 6*(i+1) << " ";
    //}
    switch(amari){
    case 0:
      break;
    case 1:
      cout << 12*(N/8) + 6 << " ";
      break;
    case 2:
      cout << 12*(N/8) + 6 << " " << 12*(N/8+1)<< " ";
      break;      
    case 3://to change
      cout << 12*(N/8) + 3 << " ";
      cout << 12*(N/8) + 6 << " ";
      cout << 12*(N/8) + 9 << " ";      
      break;      
    case 4://to change
      cout << 12*(N/8) + 3 << " ";
      cout << 12*(N/8) + 6 << " ";
      cout << 12*(N/8) + 9 << " ";
      cout << 12*(N/8) + 12 << " ";      
      break;      
    case 5://to change
      cout << 12*(N/8) + 2 << " ";
      cout << 12*(N/8) + 3 << " ";
      cout << 12*(N/8) + 4 << " ";      
      cout << 12*(N/8) + 6 << " ";
      cout << 12*(N/8) + 9 << " ";      
      break;      
    case 6:
      for(int j=0;j<3;j++){
	cout << 12*(N/8) +2 + j  << " ";
      }
      for(int j=0;j<3;j++){
	cout << 12*(N/8) +8 + j  << " ";
      }
      break;      
    case 7:
      for(int j=0;j<3;j++){
	cout << 12*(N/8) +2 + j  << " ";
      }
      cout << 12*(N/8) + 6 << " ";
      for(int j=0;j<3;j++){
	cout << 12*(N/8) +8 + j  << " ";
      }
      break;      
    }
    
  }
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,mod=1e9+7;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}
int power(int a,int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int n,u,v,k,inv,fac[maxn],invf[maxn];
vector<int> a[maxn];
int ncr(int N,int R){
    if(R==0||R==N)return 1;
    return mul(fac[N],mul(invf[R],invf[N-R]));
}
int pnr(int N,int R){
    if(R>N){
        printf("0");
        exit(0);
    }
    if(R==N)return fac[N];
    return mul(fac[N],invf[N-R]);
}
int dfs(int nod,int pa,int dep){
    int res=1;
    if((int)a[nod].size()==1&&nod!=1)return 1;
    for(int i:a[nod]){
        if(i!=pa){
            res=mul(res,dfs(i,nod,dep+1));
           // if(nod==1)cout<<res<<' ';
        }
    }
    res=mul(res,dep>0?pnr(k-2,(int)a[nod].size()-1):pnr(k,(int)a[nod].size()+1));
    return res;
}

int main(){
    scanf("%d%d",&n,&k);
    fac[0]=1;
    for(int i=1;i<=100000;i++){
        fac[i]=mul(fac[i-1],i);
    }
    for(int i=1;i<=100000;i++){
        invf[i]=power(fac[i],mod-2);
    }
    invf[0]=1;
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    printf("%d\n",dfs(1,0,0));
}


Measured memory_bytes: 17792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, x; cin >> n >> x;
	vi a(n), mn(n, inf);
	rep(i, n) cin >> a[i];
	ll ans = 1e18;
	rep(s, n){
		ll sum = (ll)x * s;
		rep(i, n){
			mn[i] = min(mn[i], a[(i + n - 1 - s) % n]);
			sum += mn[i];
		}
		//dbg(s, mn, sum);
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
 
int main() {
    int n;
    cin >> n;
    string c;
    cin >> c;
    vector<int> w;
    vector<int> r;
    rep(i, n) {
        if (c[i] == 'W') {
            w.push_back(i);
        } else {
            r.push_back(i);
        }
    }

    reverse(w.begin(), w.end());

    int ans = 0;
    while(w.size() != 0 && r.size() != 0 && w[w.size()-1] < r[r.size()-1]) {
        ans++;
        w.pop_back();
        r.pop_back();
        if (w.size() == 0) break;
        if (r.size() == 0) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,k,a[MAXN];
map<ll,ll> mp;
int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	ll ans=0,s=0;
	for(ll i=1;i<=n;i++)
	{
		s+=a[i];
		if(mp.find(s)==mp.end()) mp[s]=1;
		else {ans+=mp[s]; mp[s]++;}
		if(s==0) ans++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int main() {
    int X, Y, Z;
    cin>>X>>Y>>Z;
    cout << Z << " " << X  << " " << Y << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll D;
ll c[26];
ll s[366][26];
ll t[366];

//スコア計算
ll score(ll days){
	ll ans=0;
	ll last[26];
	rep(i,26)last[i]=0;
	for(ll d=1;d<=days;d++){
		ans+=s[d][t[d]];
		last[t[d]]=d;
		rep(i,26){
			ans-=c[i]*(d-last[i]);
		}
	}
	return ans;
}

ll whole_score;
ll score_typ[26];
void recalc(ll i){
	ll ans=0;
	ll last=0;
	for(ll d=1;d<=D;d++){
		if(t[d]==i){
			ans+=s[d][i];
			last=d;
		}
		ans-=c[i]*(d-last);
	}
	whole_score-=score_typ[i];
	score_typ[i]=ans;
	whole_score+=score_typ[i];
}
void init_score(){
	whole_score=0;
	rep(i,26){
		score_typ[i]=0;
		recalc(i);
	}
}

//貪欲法
void greedy(){
	for(ll d=1;d<=D;d++){
		ll ma=-1e17,pt=0;
		rep(i,26){
			t[d]=i;
			ll res=score(d);
			if(ma<res){
				ma=res;
				pt=i;
			}
		}
		t[d]=pt;
	}
}

//局所探索
void local_search(){
	rep(u,50000){
		ll d=rand()%D+1;
		ll q=rand()%26;
		ll b=t[d];
		ll bef_score=whole_score;
		t[d]=q;
		recalc(b);
		recalc(q);
		ll aft_score=whole_score;
		if(bef_score>aft_score){
			t[d]=b;
		}
		recalc(b);
		recalc(q);
	}
}


int main(){
	cin>>D;
	rep(i,26)cin>>c[i];
	for(ll d=1;d<=D;d++)rep(j,26)cin>>s[d][j];
	greedy();
	init_score();
	local_search();
	for(ll d=1;d<=D;d++){
		cout<<t[d]+1<<"\n";
	}
}


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

int main(void){
    int n;
    cin >> n;
    int v[n];
    int c[n];
    rep(i,n){
        int x;
        cin >> x;
        v[i] = x;
    }
    rep(i,n){
        int x;
        cin >> x;
        c[i] = x;
    }
    int ans = 0;
    rep(i,n){
        if(v[i]-c[i] > 0){
            ans += v[i]-c[i];
        }
    }
    cout << ans << endl;
    
    return 0;
}

































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

signed main() {
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);

    cout << x << " " << y << " " << z << endl;
    
 
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A_list = []
for i in range(N):
    A = int(input())
    A_list.append(A)
sort_A = sorted(A_list, reverse = True)
max_f = sort_A[0]
max_s = sort_A[1]
for i in range(N):
    print(max_s) if A_list[i] == max_f else print(max_f)

Measured memory_bytes: 14112
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt(s *bufio.Scanner) int {
	if s.Scan() {
		t := s.Text()
		v, err := strconv.Atoi(t)
		if err == nil {
			return v
		}
		panic(err)
	} else {
		panic(s.Err())
	}
}

type node struct {
	x, d int
	c    []int
}

type robots []*node

func (r robots) Len() int           { return len(r) }
func (r robots) Less(i, j int) bool { return r[i].x < r[j].x }
func (r robots) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }

func dfs(i, m int, r []*node) int {
	res := 1
	for _, j := range r[i].c {
		res *= dfs(j, m, r)
		res %= m
	}
	return (res + 1) % m
}

func main() {
	sc := newScanner()
	const m int = 998244353
	n := scanInt(sc)

	r := make(robots, n)
	for i := 0; i < n; i++ {
		x, d := scanInt(sc), scanInt(sc)
		r[i] = &node{x, d, []int{}}
	}
	sort.Sort(r)

	l := list.New()
	for i := n - 1; i >= 0; i-- {
		e := l.Front()
		for e != nil {
			a, _ := e.Value.([]int)
			x := a[0]
			j := a[1]
			if r[i].x+r[i].d > x {
				r[i].c = append(r[i].c, j)
				e1 := e
				e = e1.Next()
				l.Remove(e1)
			} else {
				break
			}
		}
		l.PushFront([]int{r[i].x, i})
	}

	res := 1
	for e := l.Front(); e != nil; e = e.Next() {
		a, _ := e.Value.([]int)
		i := a[1]
		res *= dfs(i, m, r)
		res %= m
	}

	fmt.Println(res)
}


Measured memory_bytes: 79872
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    string s;
    cin >> s;
    int c = 0;
    int w = 1;
    if (s[0] == 'A') {
        for (int i = 1; i < s.length(); i++) {
            if (s[i] >= 'a' && s[i] <= 'z') {
                w++;
            }
        }
        
        for (int i = 2; i <= s.length() - 2; i++) {
            if (s[i] == 'C') {
                c++;
                w++;
            }
        }
        
    }
    if (c == 1 && w == s.length()) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

#[allow(dead_code)]
fn cast<T: FromStr>(s: &str) -> T {
    s.parse().ok().expect("parse error.")
}

#[allow(dead_code)]
fn get_word<T: FromStr>() -> T {
    cast(&get_line())
}

#[allow(dead_code)]
fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(cast::<T>).collect()
}



/* ---------- ここまでテンプレ ---------- */


fn main() {
    let v: Vec<u64> = get_vec();
    println!("{}",
        match v[0] * v[1] % 2 {
            0 => "No",
            1 => "Yes",
            _ => "",
        }
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N, K, X, Y;

    cin >> N >> K >> X >> Y;
    int sum = 0;

    if (N > K)
    {
        sum = K * X;
        sum += (N - K) * Y;
    }
    else
    {
        sum = N * X;
    }
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 256