akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define ll long long

const int M = 1000000000 + 7;
const int N = 2010;

struct re {
    int x, y;
//    const bool operator < (const re &a) const {
//        if (x != a.x) return x < a.x;
//        return y < a.y;
//    }
};

int n, m;
re a[N];
vector<int> e[N];
int f[N], tr[N];

void trace(int x, int y) {
    if (tr[y] == x) f[x] = y; else {
        trace(x, tr[y]);
        f[tr[y]] = y;
    }
}

void write(int x, int y, int c) {
    if (tr[y] == x) {
        cout << c + 1 << endl;
        cout << x << endl;
        cout << y << endl;
    }
    else {
        write(x, tr[y], c + 1);
        cout << y << endl;
    }
}

bool bfs(int x, int y) {
    queue<int> q;
    memset(tr, 255, sizeof(tr));
    tr[x] = 0;
    q.push(x);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : e[u])
        if (tr[v] == -1) {
            tr[v] = u;
            q.push(v);
        }
    }

    if (tr[y] == -1) return false;

    memset(f, 255, sizeof(f));
    trace(x, y);
    ff(u, 1, n)
    if (f[u] > -1) {
        for (int v : e[u])
        if (f[v] > -1 && f[u] != v) {
            return false;
        }
    }

    write(x, y, 1);

    return true;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("", "r" , stdin);
    //freopen("", "w", stdout);
    cin >> n >> m;
    ff(i, 1, m) {
        cin >> a[i].x >> a[i].y;
        e[a[i].x].push_back(a[i].y);
    }

    ff(i, 1, m) {
        if (bfs(a[i].y, a[i].x)) return 0;
    }
    cout << -1;
}
//This code belongs to s34vv1nd


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
#define endl '\n'
#define F first
#define S second
const int MAX_N=1e5+5;

int n;

int a[MAX_N][3];
int dp[MAX_N][3];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) for(int j=0;j<3;j++)
		scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++) for(int k=0;k<3;k++)
			if(j!=k) dp[i][k]=max(dp[i][k],dp[i-1][j]+a[i][k]);
	printf("%d\n",max({dp[n][0],dp[n][1],dp[n][2]}));
	return 0;
}



Measured memory_bytes: 2560
import java.util.*;

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

        int N = sc.nextInt();
        int A[] = new int[N];
        int B[] = new int[N];

        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }

        Arrays.sort(B);
        
        int max = B[N - 1];
        int next_max = max;
        boolean flag = false;

        for(int i = N - 2; i >= 0; i--){
            if(B[i] != max){
                next_max = B[i];
                break;
            }
            flag = true;
        }

        for(int i = 0; i < N; i++){
            if(A[i] != max){
                System.out.println(max);
            }else if(flag){
                System.out.println(max);
            }else{
                System.out.println(next_max);
            }
        }

        sc.close();
    }
}

Measured memory_bytes: 114588
#include <cassert>
#include "limits.h"
#include <limits>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename H,typename... T>
void debug_out(H head,T... tail){
  std::cerr<<" "<<head;
  debug_out(tail...);
}

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;

  std::multiset<ll> slime;

  std::multiset<ll> used;

  rep(i,0,1ll<<n){
    ll a;
    std::cin>>a;
    slime.insert(a);
  }

  used.insert(*slime.rbegin());
  slime.erase(--slime.end());

  rep(bit,0,n){
    std::multiset<ll> temp;
    for(auto itr=used.rbegin();itr!=used.rend();itr++){
      auto t=slime.lower_bound(*itr);
      if(t==slime.begin()){
        std::cout<<"No\n";
        return 0;
      }
      t--;
      temp.insert(*t);
      slime.erase(t);
    }
    for(auto e:temp){
      used.insert(e);
    }
  }

  std::cout<<"Yes\n";

  return 0;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 r;
    cin >> r;
    cout << r * r << endl;
}


Measured memory_bytes: 3624
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0&&n/i<=9){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

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

int main() {
  
  double n, t, a;
  cin >> n >> t >> a;
  
  double m = 10000;
  int ans = 0;
  REP(i,n) { 
    double h;
    cin >> h;
    double c = abs(a-(t-h*0.006));
    m = min(m,c);
    if (m == c) ans = i+1;    
  }
 
  cout << ans << endl;
  
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
priority_queue<double ,vector<double>,greater<double> > Q;
int  main()
{
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		double x;
		cin>>x;
		Q.push(x);
}
	for(int i=0;i<n-1;i++)
	{
		double x=Q.top();
		Q.pop();
		double y=Q.top();
		Q.pop();
		Q.push((x+y)/2);
	}
	printf("%lf\n",Q.top());
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,p;
    cin >> a >> p;
    PRINT((3*a+p)/2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n;
    string s;
    cin >> n >> s;
    ll cnt = 0;
    rep(i,n){
        if(s[i] == '1')cnt++;
    }

    ll ama1 = 0;
    rep(i,n){
        ama1 *= 2;
        ama1 += s[i] - '0';
        ama1 %= (cnt + 1);
    }

    ll ama2 = 0;
    if(cnt >= 2){
        rep(i,n){
            ama2 *= 2;
            ama2 += s[i] - '0';
            ama2 %= (cnt - 1);
        }
    }

    int dp[MAX_N] = {};

    srep(i,1,MAX_N){
        int ii = i;
        while(ii > 0){
            dp[i]++;
            int M = __builtin_popcount(ii);
            ii = ii % M;
        }
    }

    /*
    rep(i,10){
        cout << dp[i] << ' ';
    }
    */

    int ans[n] = {};

    rep(i,n){
        if(s[i] == '0'){
            ll tmp = ama1 + mod_pow(2,n-1-i,cnt+1);
            tmp %= cnt+1;
            ans[i] = 1 + dp[tmp];
        }else{
            if(cnt == 1){
                ans[i] = 0;
            }else{
                ll tmp = ama2 + (cnt-1) - mod_pow(2,n-1-i,cnt-1);
                tmp %= cnt-1;
                ans[i] = 1 + dp[tmp];
            }
        }
    }

    rep(i,n)cout << ans[i] << endl;

    return 0;
}




Measured memory_bytes: 5284
#include <iostream>
#include <vector>
#include <math.h>
#include <map>
typedef long long LL;
using namespace std;

const int INF = 1e9;

int N, W;
vector<pair<LL, LL> > A;
const int SZ = 100011;

LL memo[SZ][200];
bool vis[SZ][200];

LL go(LL weight, LL pos){
  
  if(pos >= N or weight >= W){
     return 0;
  }
  if(vis[weight][pos]){ return memo[weight][pos]; }
  LL res = 0, res1 = 0, best = 0;
  //lo tomo
  if(weight + A[pos].first <= W){
     res = A[pos].second + go(weight + A[pos].first, pos + 1);
  }
  
  //no lo tomo
  
  res1 = go(weight, pos + 1);
  
  best = max(res, res1);
  vis[weight][pos] = 1;
  memo[weight][pos] = best;
  return best;
}

int main() {
  cin>>N>>W;
  LL w, v;
  for(int i = 0; i < N; i++){
     cin>>w>>v;
     A.push_back(make_pair(w, v));
  }
  cout<<go(0, 0);
  return 0;
}

Measured memory_bytes: 175616
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    loop(i, n)
        if (s[i] != s[n - i - 1]) {
            cout << "No"; return;
        }
    loop(i, n / 2)
        if (s[i] != s[n / 2 - i - 1]) {
            cout << "No"; return;
        }
    cout << "Yes";
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 256
import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let input = readLine()!.split(" ")
let A = input[0]
let B = input[1]
let K = input[2]

var divisor = [1]
for i in 2...100 {
    if (A % i == 0) && (B % i == 0) {
        divisor.append(i)
    }
}

print(divisor[divisor.count-K])

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ll;

int n,m;
string s,t;

int main() {
  cin >> n >> m;
  if(n==1 && m==1)
  cout << 1 << endl;
  else if(n==1 && m>1)
  cout << m-2 << endl;
  else if(n>1 && m==1)
  cout << n-2 << endl;
  else 
  cout << (ll)(n-2)*(m-2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+1];
    vector<int>x,y;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            x.push_back(a[i]);
        else
            y.push_back(a[i]);
    }
    sort(a,a+n+1);
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    vector<pair<int,int> >ans;
    int sz1=x.size();
    int sz2=y.size();
    int res=0;
    if(sz1&&sz2)
    {
        int tt=x[0];
        for(int i=0;i<sz2-1;i++)
        {
            ans.push_back({tt,y[i]});
            tt-=y[i];
        }
        int ff=y[sz2-1];
        for(int i=1;i<sz1;i++)
        {
            ans.push_back({ff,x[i]});
            ff-=x[i];
        }
        ans.push_back({ff,tt});
        res=ff-tt;
    }
    else if(sz1)
    {
        int tt=x[0];
        ans.push_back({x[sz1-1],tt});
        tt=x[sz1-1]-tt;
        for(int i=1;i<sz1-1;i++)
        {
            ans.push_back({tt,x[i]});
            tt-=x[i];
        }
        res=tt;
    }
    else if(sz2==2)
    {
        ans.push_back({y[1],y[0]});
        res=y[1]-y[0];
    }
    else
    {
        int tt=y[0];
        ans.push_back({tt,y[sz2-1]});
        tt-=y[sz2-1];
        for(int i=1;i<sz2-2;i++)
        {
            ans.push_back({tt,y[i]});
            tt-=y[i];
        }
        ans.push_back({y[sz2-2],tt});
        tt=y[sz2-2]-tt;
        res=tt;
    }
    cout<<res<<'\n';
    for(auto i:ans)
        cout<<i.first<<" "<<i.second<<"\n";

} 



Measured memory_bytes: 5872
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;
int grid[3][3];
int mask[3][3];
int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    f(i, 3) f(j, 3) cin >> grid[i][j];
    int n; cin >> n;
    f(i, n){
      ll b; cin >> b;
      f(i, 3) f(j, 3) if(grid[i][j] == b) mask[i][j] = 1;
    }
    bool b = 0;
    f(i, 3) b = b || (mask[i][0] && mask[i][1] && mask[i][2]);
    f(i, 3) b = b || (mask[0][i] && mask[1][i] && mask[2][i]);
    b = b || (mask[0][0] && mask[1][1] && mask[2][2]);
    b = b || (mask[0][2] && mask[1][1] && mask[2][0]);
    if(b) cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    k, s = input().split()
    k, s = int(k), int(s)

    count = 0
    for x in range(k+1):

        if k*2 + x < s:
            continue

        for y in range(k+1):
            if 0 <= (s - x - y) <= k:
                count += 1

    print(count)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	unsigned long long n, a[100001];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a, a + n);

	if (a[0] == 0) {
		cout << 0;
		return 0;
	}

	unsigned long long ans = 1;
	for (int i=0; i < n; i++) {
		if (ans <= 1000000000000000000 / a[i])
			ans *= a[i];
		else {
			cout << -1;
			return 0;
		}
			
		
	}

	cout << ans;

	return 0;
}

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

int r[10005],g[10005],b[10005];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    string s;
    cin>>n>>s;

    for (int i=n-1;~i;i--)
    {
        r[i]+=r[i+1];
        g[i]+=g[i+1];
        b[i]+=b[i+1];

        if (s[i]=='R') r[i]++;
        if (s[i]=='G') g[i]++;
        if (s[i]=='B') b[i]++;
    }

    long long sum=0;
    for (int i=0;i<n;i++)
    {
        for (int j=i+1;j<n;j++)
        {
            if (s[i]=='R'&&s[j]=='G')
                if (s[j+(j-i)]=='B')
                    sum+=b[j+1]-1;
                else sum+=b[j+1];
            else if (s[i]=='R'&&s[j]=='B')
                if (s[j+(j-i)]=='G')
                    sum+=g[j+1]-1;
                else sum+=g[j+1];
            else if (s[i]=='B'&&s[j]=='G')
                if (s[j+(j-i)]=='R')
                    sum+=r[j+1]-1;
                else sum+=r[j+1];
            else if (s[i]=='G'&&s[j]=='R')
                if (s[j+(j-i)]=='B')
                    sum+=b[j+1]-1;
                else sum+=b[j+1];
            else if (s[i]=='B'&&s[j]=='R')
                if (s[j+(j-i)]=='G')
                    sum+=g[j+1]-1;
                else sum+=g[j+1];
            else if (s[i]=='G'&&s[j]=='B')
                if (s[j+(j-i)]=='R')
                    sum+=r[j+1]-1;
                else sum+=r[j+1];

        }
    }

    cout<<sum<<'\n';
    return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s,ans="Yes";
  int i;
  map<char,int> m;
  cin>>s;
  for(i=0;i<4;i++){
    if(m.count(s.at(i))) m.at(s.at(i))++;
    else m[s.at(i)]=1;
  }
  if(m.size()!=2) ans="No";
  else{
    for(auto z:m) if(z.second!=2) ans="No";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    long int a,b,c;
    long int k;
    cin>>a>>b>>c>>k;
    long int littleSum = 0;
    long int temp = max(a,b);
    temp = max(temp,c);
    
    if(temp == a) {
        littleSum = b+c;
    } else if(temp == b) {
        littleSum = a+c;
    } else {
        littleSum = a+b;
    }
    
    for(int i=0; i<k; i++) {
        temp=temp*2;
    }
    cout<<littleSum+temp<<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;
using ll = long long;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> s;
  vector<int> ord(n+1,-1);
  int c = 1, l = 0;
  {
    int v = 1;
    while (ord[v] == -1) {
      ord[v] = s.size();
      s.push_back(v);
      v= a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];
  }

  if(k < l) cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[l+k] << endl; 
  }
  return 0;
}


Measured memory_bytes: 5820
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define N_MAX 40010
#define INF 1e9
#define F_MAX 200000

int h, w, k;

int score(vector<queue<int> > vq, int n){
    vector<queue<int> > vq_next(w);
    int res = 0;
    REP(p,h){
        VI a(w+1);
        REP(j,w){
            if (!vq[j].empty()) {
                a[j] = vq[j].front();
                vq[j].pop();
            }
        }
        // REP(i,w){
        //     cout << a[i];
        // }
        // cout << endl;
        REP(i,w){
            int j = 0;
            while (a[j+i] == a[i] && j+i < w) j++;
            if (j >= k) {
                res += a[i] * j;
                REP(q,j) a[i+q] = 0;
            }
            i += j-1;
        }
        REP(i,w){
            if (a[i] > 0)
                vq_next[i].push(a[i]);
        }
    }
    res *= (1<<n);
    if (res == 0) return res;
    else return res + score(vq_next, n+1);
}

int main() {
    cin >> h >> w >> k;
    VVI c(w,VI(h));

    REP(i,h){
        string s;
        cin >> s;
        REP(j,w) c[j][h-1-i] = s[j] - '0';
    }

    int ans = 0;
    REP(ei,w) REP(ej,h){
        vector<queue<int> > vq(w);
        REP(i,w) REP(j,h){
            if (i != ei || j != ej)
                vq[i].push(c[i][j]);
        }
        int res = score(vq, 0);
        ans = max(ans, res);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 752
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
vector<string> a (n);
for(int i=0;i<n;i++){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  a.at(i)=s;
}
sort(a.begin(),a.end());
long long ans = 0;
long long che =1;
for(int i=1;i<n;i++){
  if(a.at(i-1)==a.at(i)){
    che++;
  } 
   else if (a.at(i-1)!=a.at(i)){
    for(int j=che;j>0;j--){
      ans+=j-1;
    }
    che =1;
   }
  if(i==n-1){
        for(int j=che;j>1;j--){
      ans+=(j-1);
  }

  }
}
cout << ans << endl;
}


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

#define ll long long

using namespace std;
int main() {
	ll n, l, r;
	while(cin>>n>>l>>r, n>0){
		vector<ll> a(n);
		ll ans = 0;
		for(int i=0; i<n; i++) cin>>a[i];
		for(int i=l; i<=r; i++){
			ll mini=-1;
			for(int j=0; j<n; j++){
				if (i%a[j]==0){
					mini = j+1;
					break;
				}
			}
			if (mini == -1){
				if (n%2==0){
					ans++;
				}
			}else{
				if (mini%2==1){
					ans++;
				}
			}
		}
		cout << ans << "\n";
	}
}



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


// 入力
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k){
                  continue;
                }
                dp[i+1][k]=max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int i = 0; i < 3; ++i) res=max(res, dp[N][i]);
    cout << res << endl;
}


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

using namespace std;

long long n, m;
int a[1111];

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int res = 0;
	for (int i = 2; i < n; i++) {
		int tmp = 0;
		if (a[i] == a[i-1]) {
			tmp = 1;
			while (a[i] == a[i-1] or a[i] == a[i+1]) {
				a[i]++;
				if (a[i] == 10001)
					a[i] = 1;
			}
		}
		res += tmp;
	}
	if (a[n-1] == a[n]) {
		res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double pi=3.141592653589793;
int main(){
    double a,b,x;
    cin>>a>>b>>x;
    if(x>=a*a*b/2){
        double c=(2.0*(a*a*b-x))/(a*a*a);
        printf("%.10f",(atan(c)/pi)*180.0);
    }
    else{
        double c=b/(2.0*x/(b*a));
        printf("%.10f",(atan(c)/pi)*180.0);
    }
}

Measured memory_bytes: 512
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,R;
  cin>>N>>R;
  if(N>10)
    cout<<R<<endl;
  else
    cout<<R+(10-N)*100<<endl;

}


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

int main() {
    int n;
    cin>>n;
    vector<vector<int>> f(n,vector<int>(10));
    for(int i = 0;i < n;++i) {
        for(int j = 0;j < 10;++j) {
            cin>>f[i][j];
        }
    }
    vector<vector<int>> p(n,vector<int>(11));
    for(int i = 0;i < n;++i) {
        for(int j = 0;j <= 10;++j) {
            cin>>p[i][j];
        }
    }
    int ans=-1000000007;
    for(int bit = 1;bit < (1<<10);++bit) {
        int tans=0;
        for(int i = 0;i < n;++i) {
            int c=0;
            for(int j = 0;j < 10;++j) {
                if((bit&(1<<j))&&f[i][j]==1)++c;
            }
            tans+=p[i][c];
        }
        ans=max(ans,tans);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int k,a,b;
  cin>>k>>a>>b;
  bool flag =false;
  for(int i=a;i<=b;i++){
    if (i%k==0) flag =true;
  }
  if (flag) cout <<"OK";
  else cout << "NG";
}
  


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
template<typename TypeInt>
TypeInt G_C_D(TypeInt a, TypeInt b)
{
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    while (b != 0) {
        a %= b;
        if (a == 0) return b;
        b %= a;
    }
    return a;
}


template<typename TypeInt>
TypeInt L_C_M(TypeInt a, TypeInt b) {
    if( a == 0 && b == 0)return 0;
    return a / G_C_D(a, b) * b;
}

int main() {
  ll A, B, C, D;

  cin >> A >> B >> C >> D;

  ll lcm = L_C_M(C, D);

  ll ans = B / lcm - A/ lcm;
  if (A % lcm == 0) ans++;


  ll ans1 = B / C - A / C;
  ll ans2 = B / D - A / D;
  if (A % C == 0) ans1++;
  if (A % D == 0) ans2++;

  //cout << ans << ", " << ans1 << ", " << ans2 << endl;
  cout << (B - A + 1 + ans - ans1 - ans2) << endl;

  return 0;
}


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


 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
  
  int a,b;
  cin >> a >> b;
  int c=b/(a-1);
  if(a==2){c=b-1;}
  else if(b%(a-1)>1){c++;}
  cout << c << "\n";
  
  

}


Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()

    sum_A = 0
    sum_pow2 = 0
    for a in A:
        sum_A += a
        sum_A %= P
        sum_pow2 += a**2
        sum_pow2 %= P
    
    print((sum_A**2 % P - sum_pow2)%P*pow(2,P-2,P)%P)


    
main()

Measured memory_bytes: 94344
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Dist(A, B *[]float64) float64 {
  return math.Sqrt(math.Pow((*B)[0] - (*A)[0], 2.0) + math.Pow((*B)[1] - (*A)[1], 2.0))
}

func MaxFloat64(A *[]float64) float64 {
  ret := (*A)[0]
  for _, a := range (*A) {
    if ret < a { ret = a }
  }
  return ret
}
func IncircleRadius(A, B, C *[]float64) float64 {
  AB := Dist(A, B)
  BC := Dist(B, C)
  CA := Dist(C, A)
  _B := []float64{(*B)[0] - (*A)[0], (*B)[1] - (*A)[1]}
  _C := []float64{(*C)[0] - (*A)[0], (*C)[1] - (*A)[1]}
  return math.Abs(_B[0] * _C[1] - _B[1] * _C[0]) / (AB + BC + CA)
}

func main() {
  A := NextFloatVec()
  B := NextFloatVec()
  C := NextFloatVec()
  AB := Dist(&A, &B)
  BC := Dist(&B, &C)
  CA := Dist(&C, &A)
  L := MaxFloat64(&[]float64{AB, BC, CA})
  r := IncircleRadius(&A, &B, &C)
  Write(L * r / (2 * r + L))
  Output()
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0, mx = 0;
  rep(i, n) {
    ans += max(0LL, mx - a[i]);
    chmax(mx, a[i]);
  }
  cout << ans << '\n';

  
  return 0;
}

Measured memory_bytes: 4748
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

ll llmin(ll x, ll y){
	if (x > y) return y;
	return x;
}

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

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

ll modinv(ll a) {
    return modpow(a, MOD - 2);
}

int main(){
	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll> > vec;
	if (n == k){
		ll ans = 1;
		for (int i = 0; i < n; i++){
			ll x;
			cin >> x;
			ans = ans * x % MOD;
		}
		if (ans < 0) cout << ans + MOD << endl;
		else cout << ans << endl;
		return 0;
	}
	ll tmp = 0;
	for (int i = 0; i < n; i++){
		ll x;
		cin >> x;
		if (x < 0) tmp++;
		if (x == 0) vec.push_back(make_pair(0, 0));
		else vec.push_back(make_pair(abs(x), x/abs(x)));
	}
	if (tmp == n && k%2){
		ll ans = 1;
		sort(vec.begin(), vec.end());
		for (int i = 0; i < k; i++){
			ans = ans * vec[i].first % MOD;
		}
		if (ans == 0 || vec[n-1].first == 0) cout << 0 << endl;
		else cout << MOD - ans << endl;
		return 0;
	}
	sort(vec.begin(), vec.end(), greater<pair<ll, ll> >());
	ll ans = 1, coun = 0;
	for (int i = 0; i < k; i++){
		ans = ans * vec[i].first % MOD;
		if (vec[i].second == -1) coun++;
	}
	if (vec[k-1].second == 0){
		cout << 0 << endl;
		return 0;
	}
	if (coun % 2){
		ll minplus = MOD, minminus = MOD;
		ll maxplus = 0, maxminus = 0;
		for (int i = 0; i < k; i++){
			if (vec[i].second == 1){
				minplus = llmin(minplus, vec[i].first);
			}else if (vec[i].second == -1){
				minminus = llmin(minminus, vec[i].first);
			}
		}
		for (int i = k; i < n; i++){
			if (vec[i].second == 1){
				maxplus = llmax(maxplus, vec[i].first);
			}else if (vec[i].second == -1){
				maxminus = llmax(maxminus, vec[i].first);
			}
		}
		if ((minminus != MOD && maxplus != 0) && (minplus != MOD && maxminus != 0)){
			if (maxminus*minminus > maxplus*minplus){
				cout << (ans*modinv(minplus)%MOD)*maxminus%MOD << endl;
			}else{
				cout << (ans*modinv(minminus)%MOD)*maxplus%MOD << endl;
			}
		}else if (minminus != MOD && maxplus != 0){
				cout << (ans*modinv(minminus)%MOD)*maxplus%MOD << endl;
		}else{
				cout << (ans*modinv(minplus)%MOD)*maxminus%MOD << endl;
		}
	}else{
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 7444
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

int main() {
		int N, Y;
		cin >> N >> Y;
		for (int x = 0; x <= N; x++) {
				for (int y = 0; y <= N; y++) {
						int z = N - x - y;
						if (z < 0) continue;
						int sum = 10000 * x + 5000 * y + 1000 * z;
						if (sum == Y) {
								cout << x << " " << y << " " << z << endl;
								return 0;
						}
				}
		}
		cout << "-1 -1 -1" << endl;
		return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
 int h, w;

 cin >> h >> w;

 while(h != 0 || w != 0) {
  for(int i = 0;i < h;i++) {
   for(int j = 0;j < w;j++) {
    cout << "#";
   }
   cout << endl;
  }
 
  cin >> h >> w;
  cout << endl;
 }

 return 0;
}

Measured memory_bytes: 3088
N = int(input())
a = list(map(int,input().split()))
a.sort()
alice = 0
bob = 0
for i in range(N): #合計N回引く
    if i%2 == 0:#偶数回＝Alice
        alice += max(a)
        del a[-1]
    else:
        bob += max(a)
        del a[-1]
print(alice - bob)

Measured memory_bytes: 3060
using System;
    using System.Linq;
    using System.Text.RegularExpressions;
    class A{
      static void Main(){
        var s = Console.ReadLine();
        var a = s.StartsWith("A");
        var b = s.Substring(2, s.Length - 3).Count(x => x == 'C') == 1;
        var c = !Regex.IsMatch(string.Join("", s.Substring(1).Split('C')), "[A-Z]");
        Console.WriteLine(a && b && c ? "AC" : "WA");
      }
    }

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

int main()
{
    int H, W;
    string str[50];
    cin >> H >> W;

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


    for(int i = 0; i < H; i++) cin >> str[i];   


    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            if(str[i][j] == '.')
            {
                int cnt = 0;
                for(int k = 0; k < 8; k++)
                {
                    int x = i + dy[k];
                    int y = j + dx[k];

                    if(x < 0 || x >= H) continue;
                    if(y < 0 || y >= W) continue;

                    if(str[x][y] == '#'){
                        cnt++;
                    }
                }
                
                str[i][j] = (char)('0' + cnt);
            }
        }
    }

    for(int i = 0; i < H; i++) cout << str[i] << endl;
    
    return 0;

}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL factrial(int n) {
  if(n == 1) return 1;
  else return n * factrial(n-1);
}

int main() {
  int n;

  cin >> n;

  cout << factrial(n) << endl;
}

Measured memory_bytes: 1156
n = gets.to_i
a = gets.split.map(&:to_i)
r = sum = xor = count = 0

n.times do |l|
  while r < n && sum + a[r] == xor ^ a[r]
    sum += a[r]
    xor ^= a[r]
    r += 1
  end

  count += r - l

  if r == l
    r += 1
  else
    sum -= a[l]
    xor ^= a[l]
  end
end

puts count

Measured memory_bytes: 27208
#include<stdio.h>
int main()
{
	int n,a,b,c,d,e;
	while(scanf("%d",&n),n)
	{
		while(n--)
		{
			scanf("%d%d%d",&a,&b,&c);
			d=(a+b+c)/3;
			e=(a+b)/2;
			if(a>99||b>99||c>99||e>89||d>79)puts("A");
			else if(d>69||d>49&&(a>79||b>79))puts("B");
			else puts("C");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int x, y, z;
    cin >> x >> y >> z;

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


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

int main() {
  int d, n; cin >>d >>n;
  int ans = 1;
  if (d==1) ans = 100;
  else if (d==2) ans = 10000;
  if (n<100) ans *= n;
  else ans *= (n+1);
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100
#define INF (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i = 0;i<n;i++){
    d[i] = INF;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INF;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u=i;
	minv = d[i];
      }
    }
    if(u==-1) break;
    color[u] = BLACK;
    for(int v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v] != INF){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] =GRAY;
	}
      }
    }
  }
  int sum = 0;
  for(int i = 0;i<n;i++){
    if(p[i] != -1)sum += M[i][p[i]];
  }
  return sum;
}

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j = 0;j<n;j++){
      int e;
      cin >> e;
      M[i][j] = (e == -1) ? INF : e;
    }
  }
  cout << prim() << endl;
  
  return 0;
}



Measured memory_bytes: 3120
h,w=map(int,input().split())
one=(h+1)//2
two=h//2 
if h==1 or w==1:
    print(1)
else:
    if w%2==0:
        print(one*(w//2)+two*(w//2))
    else:
        print(one*(w//2+1)+two*(w//2))

Measured memory_bytes: 38256
n=int(input())
a=list(map(int,input().split()))


if n==0:
    if a[0]==1:
        print(1)
    else:
        print(-1)
    exit()

if a[0]==1 and n!=0:
    print(-1)
    exit()

suma=sum(a)

cnt=1
bk=1

for i,aa in enumerate(a[1:]):
    node=min(suma,bk*2)
    cnt+=node
    #print(i,aa,node)
    bk=node-aa
    suma-=aa

if bk==0:
    print(cnt)
else:
    print(-1)










Measured memory_bytes: 85452
import java.io.*;
import java.util.*;
import static java.lang.System.*;

public class Main {
	static FastScanner sc = new FastScanner(System.in);
	public static void main(String[] args) {
		HashSet<String> set = new HashSet<>();
		int n = sc.nextInt();
		for (int i=0; i<n; i++) {
			String s = sc.next();
			if (s.equals("insert")) {set.add(sc.next());}
			else {out.println(set.contains(sc.next())?"yes":"no");}
		}
	}
}



class FastScanner implements Closeable {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	public FastScanner(InputStream in) {this.in = in;}
	private boolean hasNextByte() {
		if (ptr < buflen) {return true;}
		else{
			ptr = 0;
			try {buflen = in.read(buffer);}
			catch (IOException e) {e.printStackTrace();}
			if (buflen <= 0) {return false;}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {throw new NumberFormatException();}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){return minus ? -n : n;}
			else{throw new NumberFormatException();}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public void close() {
		try {in.close();}
		catch (IOException e) {}
	}
}


Measured memory_bytes: 162912
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll A,B,N;
  cin>>A>>B>>N;
  ll p,q,r;
  ll ans1 = 0;
  ll ans2 = (A/B)-A*(1/B);
  ll ans3 = (A*N)/B-A*(N/B);
  ll ans = max(ans1,max(ans2,ans3));
  if(N>=(B-1)){
    ll ans4 = ((A*(B-1))/B);
    ans = max(ans,ans4);
  }
  if(N>=(2*B-1)){
    ll ans5 = ((A*(2*B-1))/B)-A;
    ans = max(ans,ans5);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  int sum=0;
  for(int i=0;i<n;i++)
    	cin>>a[i];
   sort(a,a+n);
  for(int i=0;i<k;i++)
    	sum+=a[i];
 cout<<sum<<endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

int main() {
	set<int> _set;
	for(int i = 1; i <= 9; i++) {
		for(int j = 1; j <= 9; j++) {
			_set.insert(i * j);
		}
	}
	int N;
	scanf("%d", &N);
	if(_set.count(N)) printf("Yes\n"); else printf("No\n");
	return  0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int res = 0;
    for(int i=0;i<n;i++){
        if(i%2==0&&s[i]!='0'){
            res++;
        }
        if(i%2==1&&s[i]!='1'){
            res++;
        }
    }
    int res2 = 0;
    for(int i=0;i<n;i++){
        if(i%2==0&&s[i]!='1'){
            res2++;
        }
        if(i%2==1&&s[i]!='0'){
            res2++;
        }
    }
    cout << min(res,res2) << endl;
    return 0;
}

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

template<typename A, typename B>
bool chmin(A &a, const B &b){
  return b < a && (a = b, true);  
}

int main(){
  string s;
  cin >> s;
  int len = s.size(), minv = 1000;

  for(int i = 0; i < len-2; ++i){
    int tmp = stoi(s.substr(i,3));
    chmin(minv, abs(tmp - 753));
  }

  cout << minv << '\n';

  return 0; 
}

Measured memory_bytes: 256