akhauriyash/Code-Regression huggingface dataset:
// OURL: https://atcoder.jp/contests/abc134/tasks/abc134_d
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void divide(vector<int>&ps, int a) {
  ps[0]++; // 1
  if (a == 2) return;
  if (a == 4) {
    ps[1]++;
    return;
  }
  for (int i=2;i<=sqrt(a)+1;i+=1) {
    if (a % i == 0) {
      int c = a/i;
      if (c < i) {
        break;
      } else if (c == i) {
        ps[i-1]++;
      } else {
        ps[i-1]++;
        ps[a/i-1]++;
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  auto as = make_v<int>(n);
  auto ps = make_v<int>(n);
  REP(i,n) {
    cin >> as[i];
  }
  vector<int> bs;
  bs.reserve(n);
  for(int i=n-1;i>=0;i--) {
    bool ad = (ps[i] + as[i]) % 2 != 0;
    if (ad) {
      bs.push_back(i+1);
      divide(ps, i+1);
    }
    debug(i+1,ad, ps);
  }
  cout << bs.size() << endl;
  for(int i = bs.size() - 1; i>=0; i--) {
    cout << bs[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long mod=1e9+7;
   int n,m;
   scanf("%d %d",&n,&m);
   vector<string> a(n);
   vector<vector<long long>> ans(n,vector<long long> (m, 0));
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   
   ans[0][0]=1;
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<m;j++)
       {
           if(a[i][j]=='.')
           {
               if(i-1>=0)ans[i][j]+=ans[i-1][j];
               if(j-1>=0)ans[i][j]+=ans[i][j-1];
               if(ans[i][j]>=mod)ans[i][j]-=mod;
           }
       }
   }
   cout<<ans[n-1][m-1];
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    ll N , P , count = 0 , ans = 1;
    cin >> N >> P;
    vector <int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] % 2 == 1){
            count++;
        }
    }
    if(count == 0){
        if(P == 0){
            for(int i = 0; i < N; i++){
                ans *= 2;
            }
            cout << ans << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else{
        for(int i = 0; i < N - 1; i++){
            ans *= 2;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3596
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, vis[N];
vector<int> a[N];

bool dfs(int node, int& depth){
    vis[node] = 1;
    if(node == 1){
        depth = 0;
        return true;
    }
    depth = 1e9;
    int ok = 0;
    for (auto i: a[node]){
        int curdep;
        if(!vis[i]&&dfs(i, curdep)){
            ok = 1;
            depth = min(depth, curdep + 1);
        }
    }
    if(ok)return true;
    
    return false;
    
    
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    int at;
    for (int i = 1; i <= n; i++){
        cin>>at;
        if(at!=i)a[at].push_back(i);
    }
    
    
    int depth = 0;
    bool res = dfs(2, depth);
    if(res){
        cout<<depth<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 12416
import java.util.Scanner;

/**
 * https://abc076.contest.atcoder.jp/tasks/abc076_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		
		long ans = 1;
		for(int i=0; i<N; i++){
			ans = Math.min(ans+K, ans*2);
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(){
    int r;
    string ans;
    cin >> r;
    if(r<1200){
        ans = "ABC";
    }else if(r<2800){
        ans ="ARC";
    }else{
        ans = "AGC";
    }
    cout << ans << endl;
}


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

 
#define int long long
 
using namespace std;
 
typedef long long ll;
 
typedef long double ld;
 
const int oo = 1e18;
 
int N, A, B;
 
int32_t main()
{
  
    cin >> N >> A >> B;
    int K = A+B;
    int sum = (N/K)*A;
    N %= K;
 
    if(N >= A)
    {
        sum=sum+A;
    }
    else
    {
        sum=sum+N;
    }
 
    cout << sum << '\n';
 
    return 0;
}

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

int main(){
   string s,t;
   cin>>s>>t;
   int n = s.size();
   int m=t.size();
   int i=0,j=0;
   int ans=10001;
   while(i<=n-m){
       j=0;
       int temp=0;
       while(j<m){
           if(s[i+j] == t[j]){
               ++temp;
           }
           ++j;
       }
       ans= min(ans, m-temp);
       ++i;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3608
import java.util.*;

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

	public Main(){
		new AOJ2006().doIt();
	}
	
	class AOJ2006{
		ArrayList<Data> list;
		char[][] map;
		void solve(){
			for(int i=0;i<list.size();i++){
				System.out.print(map[list.get(i).index][list.get(i).n%map[list.get(i).index].length]);
			}
			System.out.println();
		}
		
		void doIt(){
			map = new char[10][];
			map[1] = ".,!? ".toCharArray();map[2] = "abc".toCharArray();map[3]="def".toCharArray();
			map[4]="ghi".toCharArray();map[5]="jkl".toCharArray();map[6]="mno".toCharArray();map[7]="pqrs".toCharArray();
			map[8]="tuv".toCharArray();map[9]="wxyz".toCharArray();
			int n = in.nextInt();
			for(int i=0;i<n;i++){
				String a = in.next();
				list = new ArrayList<Data>();
				int[] b = new int[a.length()];for(int s=0;s<a.length();s++)b[s] = Integer.parseInt(a.charAt(s)+"");
				int sum=0;int before=-1;
				for(int s=0;s<a.length();s++)if(b[s]!=0){
					before = b[s];break;
				}
				for(int s=0;s<a.length();s++){
					if(b[s]==0){
						if(sum==0)continue;
						list.add(new Data(before, sum));
						sum = 0;
						for(int k=s+1;k<a.length();k++)if(b[k]!=0){
							before = b[k];break;
						}
					}else{
						sum++;
					}
				}
				solve();
			}
//			for(int i=0;i<list.size();i++)System.out.println(list.get(i).index+" "+list.get(i).n);
		}
		
		class Data{
			int index,n;
			public Data(int index,int n) {
				this.index = index;
				this.n = n-1;
			}
		}
	}
	
}

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

int main(){
	int a, b;
	while(1){
		cin >> a >> b;
		if(a == 0 && b == 0)
			break;
		for(int i = 0; i < a; i++){
			for(int j = 0; j < b; j++){
				if(i == 0 || i == a-1 || j == 0 || j == b-1)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


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

// マクロ
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

int main() {

	int N;

	cin >> N;

	vi vec(N);
	int p;
	rep(i, N) {
		cin >> p;
		vec[i] = p;
	}
	int count = 0;
	int smallest = 2e5 + 1;
	rep(i, N) {
		if (smallest > vec[i]) {
			smallest = vec[i];
			count++;
		}
	}
	cou(count);
}

Measured memory_bytes: 1152
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int N = 0;
    int K = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &N, &K);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = N % K;
    
    if(ans == 0){
      /* 真の場合の処理 */
      ans = 0;
    }else{
      /* 偽の場合の処理 */
      ans = 1;
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}






Measured memory_bytes: 128
#include<iostream>
#include<climits>
#include<numeric>
#include<algorithm>
#include <sstream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<utility>
#include<array>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<forward_list>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif
string s;
cin>>s;

for (int i = 0; i < s.length(); ++i)
{
	/* code */
	if(i%2==0){
		if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
			continue;
		}
		else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	else{
		if (s[i]=='L'||s[i]=='U'||s[i]=='D')
		{
			continue;
			/* code */
		}
		else
			{
				cout<<"No"<<endl;
				return 0;
			}

	}
}
cout<<"Yes"<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e15+7;
const int N=2e5+5;
int gcd(int x,int y)
{
	if(x==0)
		return y;
	else
		return gcd(y%x,x);
}
struct line
{
	int m,b;
	//y=mx+b;
};
long double intersectX(line X,line Y)
{
	//X.m*x+X.b=Y.m*x+Y.b
	//x=(Y.b-X.b)/(X.m-Y.m);
	if(X.m==Y.m)
	{
		return MOD;
	}
	else
		return (long double)(Y.b-X.b)/(long double)(X.m-Y.m);
}
int eval(int x,line X)
{
	return (X.m)*x+X.b;
}
deque<line>st;
vector<long double>points;
void addline(line X)
{
	if(st.empty())
	{
		st.pb(X);
		return;
	}
	if(st.size()==1)
	{
		points.pb(intersectX(X,st.back()));
		st.pb(X);
		return;
	}
	while(points.size())
	{
		//l1 -> l2 ->X
		//if intersection of l1 and X lies before the intersection
		//l2 and l1 then l2 is a useless line so we remove from hull;
		line l2=st.back();
		st.pop_back();
		line l1=st.back();
		if(intersectX(X,l1)>points.back())
		{
			st.push_back(l2);
			break;
		}
		else
		{
			points.pop_back();
		}
	}
	points.pb(intersectX(X,st.back()));
	st.pb(X);

}
int findbest(int x)
{
	int idx=lower_bound(points.begin(),points.end(),x)-points.begin();
	return eval(x,st[idx]);
}	
int a[N],dp[N];
int32_t main()
{
	IOS;
	int n,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	line l;
	l.m=-2*a[1];
	l.b=a[1]*a[1];
	addline(l);
	for(int i=2;i<=n;i++)
	{
		dp[i]=findbest(a[i])+a[i]*a[i]+c;
		l.m=-2*a[i];
		l.b=dp[i]+a[i]*a[i];
		addline(l);
	}
	cout<<dp[n]<<endl;

	



	
}


Measured memory_bytes: 11248
N = int(input())
A = list(map(int, input().split()))
O = []
E = []
def inv(X):
    X_new = []
    for i in range(len(X)):
        X_new.append(X[len(X)-i-1])
    return X_new
for i in range(N):
    if i % 2 == 0:
        O.append(A[i])
    else:
        E.append(A[i])
if N % 2 == 0:
    print(' '.join(map(str, inv(E)+O)))
else:
    print(' '.join(map(str, inv(O)+E)))


Measured memory_bytes: 31300
#include <stdio.h>

int A[100000],n;

int search(int t){
  int left=0,right=n,mid;
  while (left<right){
    mid=(left+right)/2;
    if(t==A[mid])return 1;
    if(t>A[mid])left=mid+1;
    else if(t<A[mid])right=mid;
  }
  return 0;
}


int main(){
  int i,ans=0,q,t;

  scanf("%d",&n);

  for(i=0;i<n;i++)
        scanf("%d",&A[i]);

  scanf("%d",&q);

   for(i=0;i<q;i++){
          scanf("%d",&t);
          if(search(t))
              ans++;

     }

printf("%d\n",ans);
  return 0;
}





Measured memory_bytes: 2124
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, x;
    cin >> n;
    vi v;
    for(int i = 0; i < n; i++){
        cin >> x;
        v.pb(x);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(v[i]!=(i+1)){
            ans++;
        }
    }
    if((ans==2) || (ans == 0)){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        lefts[i]--;
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 21728
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut l_gcd = vec![0; n+2];
    l_gcd[1] = a[0];
    for i in 1..n {
        l_gcd[i+1] = gcd(a[i], l_gcd[i]);
    }

    let mut r_gcd = vec![0; n+2];
    r_gcd[n] = a[n-1];
    for i in (0..n-1).rev() {
        r_gcd[i+1] = gcd(a[i], r_gcd[i+2]);
    }
    
    let mut ans = 1;
    for i in 0..n {
        let res = gcd(l_gcd[i], r_gcd[i+2]);
        ans = max(ans, res);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
    return 0;
}



Measured memory_bytes: 256
// Created by martinezdiego on 23/4/19

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int a = 0, b = 0, n = s.size();
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      if (s[i] != '0')
        a++;
    }
    else {
      if (s[i] != '1')
        a++;
    }
  }
  
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      if (s[i] != '1')
        b++;
    }
    else {
      if (s[i] != '0')
        b++;
    }
  }
  
  cout << min(a,b) << '\n';
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

char str[100005];

int main(int argc, char* argv[])
{
    int n,K;
    int R[3];
    scanf("%d%d%d%d%d", &n, &K, &R[0], &R[1], &R[2]);
    scanf("%s", str);

    vector<int> flag(n);
    ll sum=0;
    int i;
    for(i=0; i<n; i++) {
        int tmp=0;
        if(str[i]=='r') {
            tmp=R[2];
        }
        else if(str[i]=='s') {
            tmp=R[0];
        }
        else {
            tmp=R[1];
        }
        if(i>=K && str[i-K]==str[i] && flag[i-K]==0) {
            tmp=0;
            flag[i]=1;
        }
        sum+=tmp;
    }
    printf("%lld\n", sum);

    return 0;
}



Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        StringBuilder s = new StringBuilder(scanner.next());
        StringBuilder left = new StringBuilder();
        StringBuilder right = new StringBuilder();
        final long q = scanner.nextLong();
        int rev = 0;
        String qi;
        int fi;
        for (int i = 0; i < q; i++) {
            qi = scanner.next();
            if (qi.equals("1")) {
                rev++;
            } else {
                fi = scanner.nextInt();
                if (fi == 1) {
                    if (rev % 2 == 0) {
                        left.insert(0,scanner.next());
                    } else {
                        right.append(scanner.next());
                    }
                } else {
                    if (rev % 2 == 0) {
                        right.append(scanner.next());
                    } else {
                        left.insert(0,scanner.next());
                    }
                }
            }
        }
        if (rev % 2 == 1) {
            s.reverse();
            System.out.println("" + right.reverse() + s + left.reverse());
        } else {
            System.out.println("" + left + s + right);
        }
    }
}

Measured memory_bytes: 94628
s=list(input())
cnt=0
if s[0]!='A':
    print('WA')
    exit()
for i in range(2,len(s)-1):
    if s[i]=='C':
        cnt+=1
if cnt!=1:
    print('WA')
    exit()
cnt=0
for i in s:
    if i.isupper():
        cnt+=1

if cnt!=2:
    print('WA')
else:
    print('AC')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define vt vector
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)x
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 1e2 + 5;
const ll M = 1e3 + 5;

ll n, cap, sum, temp, ans;
ll w[N], v[N];
ll dp[N][N * M];

ll f(ll idx, ll val) {
    if(idx > n) return val == 0 ? 0 : INF;
    ll &sol = dp[idx][val];
    if(sol != -1) return sol;
    return sol = min(f(idx + 1, val - v[idx]) + w[idx], f(idx + 1, val));
}

void solve() {
    cin >> n >> cap;
    for(ll i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    memset(dp, -1, sizeof(dp));
    for(ll i = 1; i <= sum; i++) {
        temp = f(1, i);
        if(temp == INF) continue;
        if(temp <= cap) ans = i;
    }
    cout << ans << "\n";
}

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

    solve();
    
}

Measured memory_bytes: 90216
let digit = string >> Seq.length >> int64
let max64 (a: int64) (b: int64) = if a <= b then b else a
let min64 (a: int64) (b: int64) = if a <= b then a else b
let selectMin64 n a acc =
    if n % a = 0L then
        let newDigit = max64 (digit a) (digit (n / a))
        min64 acc newDigit
    else acc

let rec maxDivisorDigit n a acc =
    if n = 1L then 1L
    elif n <= a * a then selectMin64 n a acc
    else maxDivisorDigit n (a + 1L) (selectMin64 n a acc)

//for n in [| 1L; 2L; 10000L; 1000003L; 9876543210L |] do maxDivisorDigit n 1L n |> printfn "%i"

[<EntryPoint>]
let main argv =
    let n = stdin.ReadLine() |> int64
    maxDivisorDigit n 1L n |> printfn "%i"
    0

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

#define pb push_back
#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 55;

int n, cnt;
vector<int> A[N], B[N];

int fa[N], fab[N], deg[N];
bool bad[N];

void DFS_init(int o, bool cur = true) {
	if (cur) ++cnt;
	bad[o] = !cur, deg[o] = 0;
	for (int v : A[o]) {
		if (v == fa[o]) continue;
		fa[v] = o;
		bool flag = cur;
		if (flag) flag &= find(B[o].begin(), B[o].end(), v) != B[o].end();
		DFS_init(v, flag);
		++deg[o];
	}
}

void DFS_getfa(int o) {
	for (int v : B[o]) {
		if (v == fab[o]) continue;
		fab[v] = o;
		DFS_getfa(v);
	}
}

int ans;

int work(int i) {
	cnt = 0;
	fa[i] = 0;
	DFS_init(i);
	if (cnt < ans) return -1;
	fab[i] = 0;
	DFS_getfa(i);

	set<int> S;
	For(j, 1, n) if (bad[j] && !deg[j]) S.insert(j);
	while (true) {
		int o = -1;
		for (int x : S) if (!bad[fab[x]]) { o = x; break; }
		if (o == -1) break;
		S.erase(o), bad[o] = false;
		if (bad[fa[o]] && !--deg[fa[o]]) S.insert(fa[o]);
	}
	For(j, 1, n) if (bad[j]) { cnt = -1; break; }
	return cnt;
}

void del(vector<int> &vec, int x) {
	vec.erase(find(vec.begin(), vec.end(), x));
}

int main() {

	int Case;
	scanf("%d", &Case);
	while (Case--) {

		scanf("%d", &n);
		For(i, 1, n) A[i].clear(), B[i].clear();
		For(i, 2, n) {
			int u, v;
			scanf("%d%d", &u, &v);
			A[u].pb(v), A[v].pb(u);
		}
		For(i, 2, n) {
			int u, v;
			scanf("%d%d", &u, &v);
			B[u].pb(v), B[v].pb(u);
		}

		ans = -1;
		For(i, 1, n) ans = max(ans, work(i));

		if (ans == -1) {
			For(i, 1, n) if (A[i].size() == 1u) {
				int v = A[i][0];
				del(A[i], v), del(A[v], i);
				For(j, 1, n) if (j != i && j != v) {
					A[i].pb(j), A[j].pb(i);
					ans = max(ans, work(i) - 1);
					del(A[i], j), del(A[j], i);
				}
				A[i].pb(v), A[v].pb(i);
			}
		}

		printf("%d\n", ans == -1 ? -1 : n - ans);

	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
long long n,q,x,y,z,pa[222222],lst,dist[222222],ans;
pair<long long,pair<long long,long long> > ed[444444];
long long root(long long x)
{
	if (pa[x]!=x) pa[x]=root(pa[x]);
	return pa[x];
}
bool Union(long long x,long long y)
{
	long long rx=root(x),ry=root(y);
	if (rx==ry) return 0;
	pa[rx]=ry;
	return 1;
}
int main()
{
	scanf("%lld%lld",&n,&q);
	for (long long i=0;i<=n;i++) dist[i]=1e18;
	for (long long i=1;i<=q;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		ed[i]=make_pair(z,make_pair(x,y));
		dist[x]=min(dist[x],z+1);
		dist[y]=min(dist[y],z+2);
	}
	for (long long i=0;i<n;i++)
	{
		if (dist[(i+1)%n]>dist[i]+2) dist[(i+1)%n]=dist[i]+2;
	}
	for (long long i=0;i<n;i++)
	{
		if (dist[(i+1)%n]>dist[i]+2) dist[(i+1)%n]=dist[i]+2;
	}
	for (long long i=0;i<n;i++)
	{
		ed[q+1+i]=make_pair(dist[i],make_pair(i,(i+1)%n));
	}
	for (long long i=1;i<=n;i++) pa[i]=i;
	sort(ed+1,ed+q+n+1);
	for (long long i=1;i<=q+n;i++)
	{
		if (Union(ed[i].second.first,ed[i].second.second)) ans+=ed[i].first;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 17024
#include <iostream>

using namespace std;

int N, M;
int x[100005], y[100005];

int DP[100005];
bool state[100005];

int main(void) {

	//=============
	cin >> N >> M;

	for (int i = 1; i <= M; i++) {
		cin >> x[i]; cin >> y[i];
	}

	//========= init
	state[1] = true;
	for (int i = 2; i <= N; i++) {
		state[i] = false;
	}
	for (int i = 1; i <= N; i++) {
		DP[i] = 1;
	}

	//================
	for (int i = 1; i <= M; i++) {
		if (state[x[i]] == true) { state[y[i]] = true; }
		DP[x[i]]--; DP[y[i]]++;
		if (DP[x[i]] == 0) { state[x[i]] = false; }
	}
	//==================

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (state[i] == true) { ans++; }
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

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


int f(int n) {
	int ret = 0;
	if(n == 2) ret = 1;
	else if(n == 4 || n == 6 || n == 9 || n == 11) ret = 2;
	return ret;
}

int main() {
	int x, y; cin>>x>>y;
	bool ans = f(x) == f(y);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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

int main() {
  int N;
  string ans;
  cin>>N;
  switch (N%10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      ans = "hon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      ans = "pon";
      break;
    case 3:
      ans = "bon";
      break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3032
a = int(input())
hantei = []
for n in range(a):
    hantei.append(input())
print('AC x {}'.format(hantei.count('AC')))
print('WA x {}'.format(hantei.count('WA')))
print('TLE x {}'.format(hantei.count('TLE')))
print('RE x {}'.format(hantei.count('RE')))

Measured memory_bytes: 16184
n=int(raw_input().strip())
lst=[]
minval=0x3f3f3f3f
ans=-0x3f3f3f3f
for i in xrange(n):
    val=int(raw_input().strip())
    if(i>=1):
        #print val,minval
        ans=max(ans,val-minval)
    minval = min(minval, val)
print ans



Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

int st[1050000][26];
const int mid = 524288;
//int st[16][26];
//const int mid = 8;

void upd(int idx, char c) {
    int v = c - 'a';
    for (int i = 0; i < 26; ++i) {
        if (st[mid+idx][i]) st[mid+idx][i]--;
    }
    st[mid+idx][v] = 1;
    for (int i = (mid + idx) >> 1; i > 0; i >>= 1) {
        for (int j = 0; j < 26; ++j) {
            st[i][j] = st[i<<1][j] + st[(i<<1)+1][j];
        }
    }
}

void getv(int idx, int l, int r, int ll, int rr, int nelements, int c[26]) {
    if (l > rr || r < ll) return;
    if (l == ll && r == rr) {
        for (int i = 0; i < 26; ++i) c[i] = st[idx][i];
        return;
    }
    int c1[26]; for (int i = 0; i < 26; ++i) c1[i] = 0;
    getv(idx<<1, l, min(r, ll + (nelements >> 1) - 1), ll, ll + (nelements >> 1) - 1, nelements >> 1, c1);
    int c2[26]; for (int i = 0; i < 26; ++i) c2[i] = 0;
    getv((idx<<1) + 1, max(l, ll + (nelements >> 1)), r, ll + (nelements >> 1), rr, nelements >> 1, c2);
    for (int i = 0; i < 26; ++i) {
        c[i] = c1[i] + c2[i];
    }
}

void pr() {
    for (int i = 0; i < 26; ++i) {
        char c = 'a' + i;
        cout << c << ": ";
        for (int j = 1; j < 16; ++j) {
            cout << st[j][i];
        }
        cout << "\n";
    }
}

void work() {
    int n; cin>>n;
    for (int i = 0; i < n; ++i) {
        char c; cin>>c;
        int v = c - 'a';
        st[i+mid][v]++;
    }
    for (int i = mid - 1; i > 0; --i) {
        for (int j = 0; j < 26; ++j) {
            st[i][j] = st[i<<1][j] + st[(i<<1)+1][j];
        }
    }
    int q; cin>>q;
    for (int i = 0; i < q; ++i) {
        int t; cin >> t;
        if (t == 1) {
            int a; char b; cin>>a>>b;
            upd(a-1, b);
        } else {
            int a,b; cin>>a>>b;
            int c[26]; for (int i = 0; i < 26; ++i) c[i] = 0;
            getv(1, a-1, b-1, 0, mid - 1, mid, c);
            int ans = 0;
            for (int i = 0; i < 26; ++i) {
                if (c[i]) ++ans;
            }
            cout << ans << endl;
            //pr();
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    work();
    return 0;
}


Measured memory_bytes: 104704
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  for (auto& e1 : c) {
    for (int& e2 : e1) cin >> e2;
  }
  vector<vector<int>> A(H, vector<int>(W));
  for (auto& e1 : A) {
    for (int& e2 : e1) cin >> e2;
  }
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int answer=0;
  for (auto& e1 : A) {
    for (int& e2 : e1) {
      if(e2>-1)answer+=c[e2][1];
    }
  }
  cout<<answer;

}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
char p[1010000];
int n;
bool Pos(int K){
    int i;
    int b[2]={0,1},e[2]={K,K-1}, CK[2]={0,0};
    if(K&1)swap(e[0],e[1]);
   // printf("%d\n",K);
    for(i=0;p[i];i++){
        int b0=b[0],b1=b[1],e0=e[0],e1=e[1];
        if(p[i]=='1'){
            b[0]=b1+1;
            b[1]=b0+1;
            e[0]=e1+1;
            e[1]=e0+1;
            if(e[0]>K)e[0]-=2;
            if(e[1]>K)e[1]-=2;
        }
        if(p[i]=='0'){
            b[0]=b1-1;
            b[1]=b0-1;
            e[0]=e1-1;
            e[1]=e0-1;
            if(b[0]<0)b[0]+=2;
            if(b[1]<0)b[1]+=2;
        }
        if(p[i]=='?'){
            b[0]=b1-1;
            b[1]=b0-1;
            e[0]=e1+1;
            e[1]=e0+1;
            if(b[0]<0)b[0]+=2;
            if(b[1]<0)b[1]+=2;
            if(e[0]>K)e[0]-=2;
            if(e[1]>K)e[1]-=2;
        }
        if(b[0]>e[0])CK[0]=1;
        if(b[1]>e[1])CK[1]=1;
        if(CK[0]&&CK[1])return false;
        swap(CK[0],CK[1]);
    }
    return true;
}
int main(){
    scanf("%s",p);
    int i;
    for(i=0;p[i];i++);
    n=i;
    int b=1,e=n,r=n;
    while(b<=e){
        int mid=(b+e)>>1;
        if(Pos(mid)){
            r=mid;
            e=mid-1;
        }
        else b=mid+1;
    }
    printf("%d\n",r);
}


Measured memory_bytes: 2676
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(2, n):
    if min(p[i - 2], p[i - 1], p[i]) != p[i - 1] and max(p[i - 2], p[i - 1], p[i]) != p[i - 1]:
        cnt += 1
    #print(p[i - 2], p[i - 1], p[i]) 
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <string>
#include<algorithm>

using namespace std;

int f(int a) {
	int m = 0;
	if (a % 2 == 0) {
		m = a / 2;
	} else {
		m = 3 * a + 1;
	}
	return m;
}

int main() {

	int s = 0;
	int n = 1000000;
	int a[n];
	cin >> s;

	map<int, int> list;
	list.insert((pair<int, int>(s, 1)));

	int m = 0;
	a[0] = s;
	for (int i = 1; i < n; i++) {

		a[i] = f(a[i-1]);

		map<int, int>::iterator it;
		it = list.find(a[i]);
		if (it == list.end()) {
			list.insert((pair<int, int>(a[i], i+1)));
		} else {
			cout << i + 1 << endl;
			break;
		}

	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    string s;
    int ans=0;
    cin>>s;
    rep(i,s.size()){
        int c=0;
        while(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            i++;
            c++;
            ans = max(ans,c);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 3007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}
	
	int u, v, last;
}edge[MAXN*2];

int n;
int a[MAXN];
int ke, la[MAXN];

void init ();
void input ();
void work ();

bool dfs ( int now, int fa );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
	int u, v;
	INIT ( la, -1 );
	lp ( i, 1, n ){
		scanf ( "%d%d", &u, &v );
		edge[ke].setd ( u, v, la[u] );
		la[u] = ke++;
		edge[ke].setd ( v, u, la[v] );
		la[v] = ke++;
	}
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ){
		if ( !dfs ( i, -1 ) ){
			printf ( "%d ", i );
		}
	}
	putchar ( '\n' );
}



bool dfs ( int now, int fa )
{
	bool cur = true, ret;
	int v;
	for ( int i = la[now]; ~i; i = edge[i].last ){
		if ( ( v = edge[i].v ) ^ fa ){
			ret = dfs ( v, now );
			if ( ret && ( a[v] < a[now] ) ){
				cur = false;
				break;
			}
		}
	}
	return cur;
}

Measured memory_bytes: 512
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int n;
    cin >> n;
    map<string, Int> a;
    for (Int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (!a.insert({s, 1}).second) {
            a[s]++;
        }
    }

    cout << a.size() << endl;

    return 0;
}


Measured memory_bytes: 19224
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int par[100010];
int urank[100010];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	}

	if (urank[x] < urank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
	}
	if (urank[x] == urank[y]) {
		urank[x]++;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> p(n + 10);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	init(n);

	int x, y;
	for (int i = 1; i <= m; i++) {
		cin >> x >> y;
		unite(x, y);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (same(i, p[i])) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  while(cin>>n>>q,n){
    int d[101]={};
    for(int i=0;i<n;++i){
      int m; cin>>m;
      for(int j=0;j<m;++j){
        int x; cin>>x;
        d[x]++;
      }
    }
    int a=0,ans=0;
    for(int i=0;i<101;++i)
      if(d[i]>=q && d[i]>a) ans=i, a=d[i];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U> void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
using ld = long double;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type>
ostream& operator<<(ostream& os, T const& v) { os << "{"; for (auto const& x : v) os << " " << x; return os << " }"; }
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } my_init;

template <class T, size_t d, class = typename enable_if<(d == 0)>::type> constexpr auto make_v(T const& x = {}) { return x; }
template <class T, size_t d, class... U, class = typename enable_if<(d > 0)>::type> constexpr auto make_v(size_t n, U... x) { auto val = make_v<T,d-1>(x...); return vector<decltype(val)>(n, move(val)); }
template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> constexpr bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> constexpr bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> constexpr auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
const ll INF = (1LL<<62)-1; // ~ 4.6e18
////////////////////////////////

int32_t main() {
    int n,ww; cin >> n >> ww;
    vector<int> w(n),v(n);
    rep (i,n) cin >> w[i] >> v[i];
    const int NN = 1e5 + 10;
    vector<int> dp(NN,INF);
    dp[0] = 0;
    rep (i,n) repR (j,NN) if (j+v[i] < NN) chmin(dp[j+v[i]], dp[j]+w[i]);
    int ma = -1;
    rep (j,NN) if (dp[j] <= ww) ma = j;
    cout << ma << endl;

}


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

int main(){

  int n;
  int sum;
  int count;

  while(cin >> n){
    if(n==0){ break; }

    count = 0;

    for(int i=1; i<n/2+1; i++){
      int j=i;
      sum=0;
      while(sum <= n){
        sum += j;
        if(sum == n){count ++; break;}
        j++;
      }
    }

    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
n = int(input())
p = list(map(float, input().split()))
dp = [[0.0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1.0
for i in range(1, n + 1):
    for j in range(n + 1):
        dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
ans = sum(dp[n][i] for i in range(n // 2 + 1, n + 1))
print(ans)


Measured memory_bytes: 116444
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
int i,j,k,l,n,m;
cin>>m>>n;
int a[n];
 for(i=0;i<n;i++)
 {
 	cin>>a[i];
 }
 int b[n],sum=0;
 int mini=0;
 for(i=1;i<n;i++)
 {
 	b[i-1]=a[i]-a[i-1];
 	sum+=b[i-1];
 	mini=max(mini,b[i-1]);
 }
 b[n-1]=m-sum;
 mini=max(mini,b[n-1]);
   int sum2=sum+b[n-1];
   int ans=sum2-mini;
   cout<<ans<<"\n";
   return 0;
}

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

int main() {
  long long int N; cin >> N;
  long long int ac=N-1;
  if(N==2)  ac=0;
  else{
    for(long long int i=2; i*i<N; i++){
      if(N%i==0 && N%(N/i-1)!=0)  ac+=N/i-1;
    }
  }
  cout << ac;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

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

    sort(a.begin(),a.end());
    int ans = 0;
    rep(i,k) ans +=a[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

long long int K,N;

long long int a[55];

void OPE(void) {

	long long int max;
	int I;

	I = 1; max = a[1];
	for (int i = 1; i <= 50; i++) {
		if (a[i] > max) { max = a[i]; I = i; }
	}

	a[I] -= (long long int) 50;
	for (int i = 1; i <= 50; i++) {
		if (i == I) { continue; }
		a[i]++;
	}

};

long long int COUNT(long long int K, int N)
{
	long long int count = 0;

	long long int max = a[1]; int I = 1;
	while (1) {
		max = 0;
		for (int i = 1; i <= N; i++) {
			if (a[i] > max) { max = a[i]; I = i; }
		}
		//cout << "max= " << max << endl;
		if (max <= N - 1) { /*cout << "check" << endl; */return count; }

		a[I] -= N;
		for (int i = 1; i <= N; i++) {
			if (i == I) { continue; }
			a[i]++;
		}
		///for (int i = 1; i <= N; i++) { cout << " " << a[i]; }cout << endl;
		count++;
	}
	return count;
};

int main(void) {

	cin >> K;

	if (K == 0) {
		N = 4;
		a[1] = 3; a[2] = 3; a[3] = 3; a[4] = 3;
	}
	else if (K==1){
		N = 3; a[1] = 1; a[2] = 1; a[3] = 3;
    }else if (K < 50) {

		N = K;
		//cout << K << endl;
		for (int i = 1; i <= K; i++) {
			a[i] = K;
		}
	}
	else {
		N = 50;
		long long int R;

		R = (long long int) (K + 49) / 50;

		//cout << "K= " << K << endl;

		for (int i = 1; i <= 50; i++) {
			a[i] = (long long int) 49 + R;
		}

		long long int count;
		count =(long long int) 50 * R - K;    //cout << "count= " << count << endl;

		for (int i = 0; i < count; i++) {
			OPE();
		}

		
	}

	cout << N << endl;
	for (int i = 1; i <= N; i++) {
		if (i != 1) { cout << " "; }
		cout << a[i];
	}cout << endl;

	//cout << "count num " << COUNT(K, N) << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#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++)
using namespace std;
typedef unsigned long ul;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    ll n, p;
    cin >> n >> p;
    ll a, i, o=0, e=0, ans;
    
    for(i=0; i<n; i++) {
        cin >> a;
        if(a%2==1)
            o++;
        else
            e++;
    }
    
    if(e==n) {
        if(p==0)
            ans=pow(2, n);
        else
            ans=0;
    }else
        ans=pow(2, n-1);
    cout << ans << endl;
    
}


Measured memory_bytes: 256
import sys

N = int(raw_input())
S = raw_input()

printed = False

for zero_is in range(2):
	for one_is in range(2):
		type = [0 for i in range(N)]
		type[0] = zero_is
		type[1] = one_is
		this_works = True

		for j in range(1, N):
			ind_prev = j - 1
			ind_next = (j + 1) % N

			if S[j] == 'o' and type[j] == 0 or S[j] == 'x' and type[j] == 1:
				type[ind_next] = type[ind_prev]
			else:
				type[ind_next] = not type[ind_prev]

		for j in range(0, N):
			ind_prev = (j + N - 1) % N
			ind_next = (j + 1) % N

			if S[j] == 'o' and type[j] == 0 or S[j] == 'x' and type[j] == 1:
				if type[ind_prev] != type[ind_next]:
					this_works = False
			else:
				if type[ind_prev] == type[ind_next]:
					this_works = False

		if this_works is True and printed is False:
			for i in type:
				if i == 0:
					sys.stdout.write('S')
				else:
					sys.stdout.write('W')
			printed = True

if printed is False:
	print -1
else:
	sys.stdout.write('\n')

Measured memory_bytes: 9580
#include <complex>
#include <cmath>
#include <iostream>
#include <cstdio>

using namespace std;

typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b) {
  return (conj(a)*b).real();
}

double cross_product(xy_t a, xy_t b) {
  return (conj(a)*b).imag();
}

int main() {
  xy_t P[100];
  int n;

  cin >> n;
  
  for (int i = 0; i < n; i++) {
    double x, y;
    cin >> x >> y;
    P[i] = xy_t(x,y);
  }

  //center all coordinates based on first element
  for (int i = 1; i < n; i++) {
    P[i] -= P[0];
  }
  
  //calculate sum
  double sum = 0.0;
  for (int i = 1; i+1 < n ; i++) {
    xy_t  a = P[i] , b = P[i + 1];
    sum += cross_product(a, b) / 2.0;
  }

  printf("%.1f\n", abs(sum));
  
}

Measured memory_bytes: 1252