akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int n;
  ll h,w,a[1010],b[1010];
  std::cin >> n >> h >> w;
  for(int i=0; i<n; i++) std::cin >> a[i] >> b[i];
  int ans=0;
  
  for(int i=0; i<n; i++){
    if(a[i]>=h && b[i]>=w) ans++;
  }

  std::cout << ans << '\n';
  return 0;
}


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


int main() {
  long long a,b,c,d;
  cin  >> a >> b >> c >> d;
  long long ans;
  ans = a*c;
  ans = max(ans, a*d);
  ans = max(ans, b*c);
  ans = max(ans, b*d);
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	string s[3];
	cin >> N >> s[0] >> s[1] >> s[2];
	int ans = 0;
	rep(i, N) {
		set<char>se;
		rep(j, 3)se.insert(s[j][i]);
		if (se.size() == 1)continue;
		else if (se.size() == 2)ans++;
		else ans += 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
w_lst = [int(x) for x in stdin.readline().rstrip().split()]
m = 100000

for p in range(n):
  a = abs(sum(w_lst[:p])-sum(w_lst[p:]))
  if a < m:
    m = a
    
print(m)

Measured memory_bytes: 2940
var dx=[-1,0,1,-1];
var dy=[-1,-1,-1,0];
var dz=[0,0,0,0];
dy=dy.concat([-1,0,1,-1]);
dz=dz.concat([-1,-1,-1,0]);
dx=dx.concat([0,0,0,0]);
dz=dz.concat([-1,0,1,-1]);
dx=dx.concat([-1,-1,-1,0]);
dy=dy.concat([0,0,0,0]);
dx=dx.concat([1,-1,1,-1]);
dy=dy.concat([-1,-1,-1,-1]);
dz=dz.concat([-1,-1,1,1]);

function bomb(ab,x,y,z){
   var max=0;
   for(var i=0;i<dx.length;i++){
      var X=x;
      var Y=y;
      var Z=z;
      while(true){
         X-=dx[i];
         Y-=dy[i];
         Z-=dz[i];
         if(X<0 || Y<0 || Z<0)break;
         if(X>=n || Y>=n || Z>=p)break;
      }
      var cnt=0;
      while(true){
         X+=dx[i];
         Y+=dy[i];
         Z+=dz[i];
         if(X<0 || Y<0 || Z<0)break;
         if(X>=n || Y>=n || Z>=p)break;
         if(ball[X][Y][Z]==ab)cnt++;
         else cnt=0;
         max=Math.max(max,cnt);
      }
   }
   return max;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var nmp=arr.shift();
   if(nmp=="0 0 0")break;
   nmp=nmp.split(" ").map(Number);
   var n=nmp[0];
   var m=nmp[1];
   var p=nmp[2];
   var ball=[];
   for(var i=0;i<n;i++){
      ball[i]=[];
      for(var j=0;j<n;j++){
         ball[i][j]=[];
         for(var k=0;k<p;k++){
            ball[i][j][k]=0;
         }
      }
   }
   var P=[];
   for(var i=0;i<p;i++)P.push(arr.shift().split(" ").map(Number));
   var ab=1;
   var draw=true;
   for(var i=0;i<p;i++){
      var xy=P[i];
      var x=xy[0]-1;
      var y=xy[1]-1;
      var cnt=0;
      while(true){
         if(ball[x][y][cnt]!==0)cnt++;
         else break;
      }
      ball[x][y][cnt]=ab;
      if(bomb(ab,x,y,cnt)>=m){
         console.log((ab==2)?"White":"Black",i+1);
         draw=false;
         break;
      }
      ab=2/ab;
   }
   if(draw)console.log("Draw");
}

Measured memory_bytes: 36068
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

ll N;

//dp
vector<vector<vector<double>>> table;

double dp(ll i,ll j,ll k){
  //cout<<i<<" "<<j<<" "<<k<<endl;
  if(i==0&&j==0&&k==0) return 0;
  if(table.at(i).at(j).at(k)>-1) return table.at(i).at(j).at(k);
  
  table.at(i).at(j).at(k)=0;
  if(i>0) table.at(i).at(j).at(k)+=dp(i-1,j,k)*i/N;
  if(j>0) table.at(i).at(j).at(k)+=dp(i+1,j-1,k)*j/N;
  if(k>0) table.at(i).at(j).at(k)+=dp(i,j+1,k-1)*k/N;
  table.at(i).at(j).at(k)+=1;
  
  return table.at(i).at(j).at(k)/=(double)(i+j+k)/N;
}

int main()
{
  cin>>N;
  vector<ll> vec(4,0); rep(i,N) {ll a; cin>>a; vec.at(a)++;}
  
  //dp
  table=vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));
  
  cout<<fixed<<setprecision(15)<<dp(vec.at(1),vec.at(2),vec.at(3))<<endl;
  /*
  rep(i,2) {
    if(i!=0) cout<<" ";
    cout<<table.at(0).at(0).at(i);
  }
  cout<<fixed<<setprecision(15)<<endl;
  */
  
  
  return 0;
}

Measured memory_bytes: 222816
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long N,K;
  cin >> N >> K;
  vector<int> x(N);
 
  for(int i = 0; i < N; i++){
    cin >> x.at(i);
    x.at(i) = (x.at(i) + 1);
  }
 
  long m = 0;
  long tmp = 0;
 
  for(int i = 0; i < K; i++){
    tmp += (long)x.at(i);
  }
 
  m = tmp;
  for(int i = 1; i < N - K + 1; i++){
    tmp = tmp - (long)x[i-1] + (long)x[i+K-1];
    if(tmp > m){
      m = tmp;
    }
  }
  
  cout <<std::setprecision(10) << (long double)(m) / 2.0 << endl;
 
}

Measured memory_bytes: 1152
n = int(input())
if n == 1:
    print(1)
    quit()
elif n <= 3:
    print(2)
    quit()
elif n <= 7:
    print(4)
    quit()
elif n <= 15:
    print(8)
    quit()
elif n <= 31:
    print(16)
    quit()
elif n <= 63:
    print(32)
    quit()
else:
    print(64)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

string query(int i) {
  string prev;
  cout << i << endl << flush;
  cin >> prev;
  return prev;
}
signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N;
  cin >> N;
  
  ll lb = 0;
  ll ub = N - 1;
  string vac = "Vacant";
  
  string sleft = query(lb);
  if(sleft == vac) return 0;
  string sright = query(ub);
  if(sright == vac) return 0;
  
  ll md;
  while(true) {
    md = (lb + ub) / 2;
    string ret = query(md);
    if(ret == vac) {
      return 0;
    }
    
    //偶数
    if((lb - md) % 2 == 0) {
      if(sleft == ret) {
        //反対側
        lb = md;
        sleft = ret;
      } else {
        ub = md;
        sright = ret;
      }
    } else {
      if(sleft == ret) {
        ub = md;
        sright = ret;
      } else {
        lb = md;
        sleft = ret;
      }
    }
  }
  
}

Measured memory_bytes: 880
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vll ans;
    ll tmp=0;
    ans.push_back(tmp);
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == 'I') {
            tmp++;
        } else {
            tmp--;
        }
        ans.push_back(tmp);
    }
    cout << *max_element(ALL(ans)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
 
using namespace std;
 
int main(){
    int ans=0;
    int n,q;
    vector<int> s;
    vector<int> t;
    cin>>n;
    for (int i=0; i<n; i++) {
        int input;
        cin>>input;
        s.push_back(input);
    }
    cin>>q;
    for (int i=0; i<q; i++) {
        int input;
        cin>>input;
        t.push_back(input);
    }
    for (int i=0; i<q; i++) {
        for (int j=0; j<n; j++) {
            if (t[i] == s[j]) {
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3264
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        char[] arr = sc.next().toCharArray();

        for (int i=0; i<arr.length; i++) {
            if (arr[i] == '?') {
                arr[i] = 'D';
            }
        }

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<arr.length; i++) {
            sb.append(arr[i]);
        }

        System.out.println(sb.toString());


    }
}


Measured memory_bytes: 42072
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 


 
signed main(){
    int n,m;
    cin>>n>>m;
    int a,b;
    pair<int,int> k[n];
    for(int i=0;i<n;i++){
        cin>>a>>b;
        k[i]=make_pair(a,b);
    }
    sort(k,k+n);
    priority_queue<int> b0;
    int i0=0,ans=0;
    for(int i=1;i<=m;i++){
        while(k[i0].first<=i){
            b0.push(k[i0].second);
            i0++;
        }
        if(!b0.empty()){
            ans+=b0.top();
        b0.pop();
        }
        
    }

    cout<<ans;
    return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int maximum = 0;
  rep(i,s.size()-t.size()+1){
    int cnt = 0;
    rep(j,t.size()){
      if(s[i+j]==t[j])cnt++;
    }
    maximum = max(maximum,cnt);
  }
  cout << t.size()-maximum << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    vector<int> v(3);
    v[0] = A + B;
    v[1] = A - B;
    v[2] = A*B;
    sort(v.begin(), v.end());
    cout << v[2] << endl;
    return 0;
}

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

int main(){
  while(1){
  int m,f,r;
  cin>>m>>f>>r;
  if(m== -1 && f== -1 && r== -1) break;
  string ans;
  if(m== -1||f== -1) ans="F";
  else if(m+f>=80) ans="A";
  else if(m+f>=65) ans="B";
  else if(m+f>=50) ans="C";
  else if(m+f>=30){
    if(r>=50) ans="C";
    else ans="D";
    }
  else ans="F";
  
  cout<<ans<<endl;
}

return 0;
}


Measured memory_bytes: 3036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define N 100005
using namespace std;

typedef long long ll;
int n, s, a, mx, v[N];
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a);
		if (a >= 0) v[a - 1]++;
		v[a]++;
		v[a + 1]++;
	}
	for (i = 0; i <= 100001; i++) {
		mx = max(mx, v[i]);
	}
	cout << mx;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Elem implements Comparable<Elem> {
		long val;
		int prevIndex;

		Elem(long val) {
			this.val = val;
			this.prevIndex = -1;
		}

		@Override
		public int compareTo(Elem o) {
			if (val < o.val) {
				return 1;
			} else if (val > o.val) {
				return -1;
			} else {
				return 0;
			}
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);

		int N = Integer.parseInt(in.readLine());
		long[] A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = Long.parseLong(in.readLine());
		}
		List<Long> list = new ArrayList<>();
		Map<Long, Integer> nums = new HashMap<>();
		for (int i = 0; i < N; ++i) {
			int index = Collections.binarySearch(list, A[i]);

			if (index >= 0) {
				if (index > 0) {
					nums.put(list.get(index - 1), nums.get(list.get(index - 1)) - 1);
					nums.put(list.get(index), nums.get(list.get(index)) + 1);
					if (nums.get(list.get(index - 1)) == 0) {
						nums.remove(list.get(index - 1));
						list.remove(index - 1);
					}
				} else {
					nums.put(list.get(index), nums.get(list.get(index)) + 1);
				}
			} else {
				// 挿入
				int j = (index + 1) * -1;
				if (j > 0) {
					list.add(j, A[i]);
					nums.put(A[i], 1);
					nums.put(list.get(j - 1), nums.get(list.get(j - 1)) - 1);
					if (nums.get(list.get(j - 1)) == 0) {
						nums.remove(list.get(j - 1));
						list.remove(j - 1);
					}
				} else {
					nums.put(A[i], 1);
					list.add(j, A[i]);
				}
			}
		}

		int result = 0;
		for(Long key: nums.keySet()) {
			result += nums.get(key);
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 51144
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define PI 3.1415926535897932384626
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define forn(i,n) for(int i=0;i<n;i++)
int main()
{
       boost;
       int n,x,sum=0;
       cin>>n>>x;
       int arr[n];
       forn(i,n)
       {
             cin>>arr[i];
             sum+=arr[i];
       }
       sort(arr,arr+n);
       cout<<n+((x-sum)/arr[0])<<endl;
}    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int d = 0;
  rep(i,b){
    d += a;
    if(d%b==c){
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";

}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    string s;
    cin >> s;

    for(long long i = 0; i < s.size() - 1; i++){
      if(s[i] == s[i + 1]){
        cout << i + 1 << ' ' << i + 2 << endl;
        return 0;
      }
    }

    if(s.size() > 2){
      for(long long i = 0; i < s.size() - 2; i++){
        if(s[i] == s[i + 2]){
          cout << i + 1 << ' ' << i + 3 << endl;
          return 0;
        }
      }
    }

    cout << -1 << ' ' << -1 << endl;

}


Measured memory_bytes: 512
N = int(input())
S = [int(input()) for _ in range(N)]
s = list(filter(lambda x : x%10 > 0, S))

if len(s) == 0:
    print(0)
    exit()

sum_ = sum(S)
if sum_ % 10 > 0:
    print(sum_)
    exit()

print(sum_ - min(s))

Measured memory_bytes: 3060
w=input()
amida=[i+1 for i in xrange(w)]
n=input()
for i in xrange(n):
    a,b=map(int,raw_input().split(","))
    amida[a-1],amida[b-1]=amida[b-1],amida[a-1]
for i in xrange(w):
    print(amida[i])

Measured memory_bytes: 6308
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, M;
    cin >> N >> M;

    const int NMAX = 1000;
    const int MMAX = 2000;

    int a[MMAX], b[MMAX];
    ll c[MMAX];

    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    ll dist[NMAX];

    rep(i, N) {
        dist[i] = inf;
    }

    dist[0] = 0;

    rep(loop, N) rep(i, M) {
        if (dist[a[i]-1] == inf) continue;

        if (dist[b[i]-1] > dist[a[i]-1] + c[i]) dist[b[i]-1] = dist[a[i]-1] + c[i];
    }

    ll ans = dist[N-1];

    bool negative[NMAX];

    rep(i, N) {
        negative[i] = false;
    }

    rep(loop, N) rep(i, M) {
        if (dist[a[i]-1] == inf) continue;

        if (dist[b[i]-1] > dist[a[i]-1] + c[i]) {
            dist[b[i]-1] = dist[a[i]-1] + c[i];
            negative[b[i]-1] = true;
        }

        if (negative[a[i]-1] == true) negative[b[i]-1] = true;
    }

    if (negative[N-1]) cout << "inf" << endl;
    else cout << -ans << endl;
    return 0;
}

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

using namespace std;


int main(){
	int N;
	int buf;
	vector<int> A;
	int edge[2];
	long long res;

	cin >> N;

	for(int i=0;i<N;i++){
		cin >> buf;
		A.push_back(buf);
	}

	sort(A.begin(),A.end(),greater<int>());

	int j = 0;

	for(int i=0;i<N;i++){
		if(A[i]==A[i+1]){
			edge[j] = A[i];
			i++;
			j++;
		}

		if(j==2){
			break;
		}
	}

	if(j<2){
		edge[0] = 0;
		edge[1] = 0;
	}

	res = (long long)edge[0]*(long long)edge[1];

	cout << res << "\n";

	return 0;

}

Measured memory_bytes: 892
import Control.Applicative
import Data.List

main = do
  (n:k:_) <- (map (read::String->Int)) . words <$> getLine
  dat <-
    (sortBy (\a b -> compare (fst a) (fst b))) .
    (map ((\(a:b:_) -> (a,b)) . (map (read::String->Int)) . words)) . lines <$> getContents

  print $ f dat 0 k

  where
    f ((a,b):xs) s k = if k <= s+b then a else f xs (s+b) k


Measured memory_bytes: 80124
# import sys
# sys.setrecursionlimit(5000)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def sum_():
    sum_list = [0]
    i = 0
    x = 1
    while(sum_list[-1] <=1000000007):
        sum_list.append(x+sum_list[i])
        i +=1
        x +=1
    # print(sum_list)
    return sum_list
N = int(input())
if(N == 1):
    print(0)
else:
    ans = 0
    sum_list = sum_()
    f = factorization(N)
    for i in range(len(f)):
        count =0
        while(sum_list[count]<=f[i][1]):
            
            count += 1
        ans += count-1
    # print(f)
    print(ans)

Measured memory_bytes: 10944
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
//Factors of an num
/*
vector<ll> fact(ll n){
	vector<ll>v;
	for(int i=1;i*i<=n;i++){
		if(n%i ==0){
			v.push_back(i);
		
		if(i!=n/i)
			v.push_back(n/i);
	    }
	}

	return v;
}
*/


/*
Seive Of Eratos..
int N=1e5;
vector<bool> isprime(N+1,true);
void pri(int n){
	for(int i=2;i*i<=n;i++){
		if(isprime[i]){
			for(int j=i*i;j<=n;j+=i){
				isprime[j]=false;
			}
		}
	}
	return;
}
*/

/*
//Prime Factors
vector<bool> isprime(1e6+1,true);
 vector<int> primes;
 void sieve()
 {

    ll  i,j;
    isprime[0] = false;
    isprime[1] = false;

    for(i=2; i<=1e6 ;i++)
  {

    if(isprime[i])
    {

      primes.push_back(i);

      for(j=i*i; j<=1e6; j+=i)
      {
        isprime[j]=false;
      }

    }

  }
}

vector<int> primefactors(int  N)

 {

    vector<int> factors;
    ll pf_idx = 0, pf=primes[pf_idx];

    while(pf*pf<=N)
    {
        while(N % pf == 0)
        {
            N/=pf;
            factors.push_back(pf);
        }
        pf = primes[++pf_idx];
    }
    
    if(N != 1) factors.push_back(N);
    return factors;
}
 */   

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin.tie(NULL);
   int x;
   cin>>x;
   if(x==0)
   	cout<<"1"<<endl;
   else cout<<"0"<<endl;
}

Measured memory_bytes: 3624
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
//#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;

bitset<N> dp, dp1;
ll A, B, C, D, E, F;

ll who[N];

bool isval(ll x, ll y){
	if (x * 100 <= (y) * E){
		return 1;
	}
	return 0;
}


int main(){
	IOS;
	memset(who, -1, sizeof who);
	cin >> A >> B >> C >> D >> E >> F;
	A *= 100;
	B *= 100;
	for (int i = 0; i <= F; i++){
		for (int j = 0; j <= i; j+=A){
			if ((i - j) % B == 0) dp[i] = 1;
		}
	}
	
	for (int i = 0; i <= F; i++){
		for (int j = 0; j <= i; j+=C){
			if ((i - j) % D == 0) dp1[i] = 1;
		}
	}
	
	pair<ll, ll> Max = {-1, -1};
 	//cout << isval(900, 100) << '\n';
 	
	for (int i = 0; i <= F; i++){
		if (dp1[i] == 0) continue;
		for (int j = 1; j <= F; j++){
			if (dp[j] == 0) continue;
			if (isval(i, j) && (i + j <= F)){
				///cout << "YES\n";
				if (Max.S == -1){
					Max = {i, j};
				}
				else if (i * Max.S > j * Max.first){
					Max = {i, j};
				}
			}
		}
	}
	//cout << Max.first <<  ' ' << Max.S << '\n'; 
 	
	cout << Max.first + Max.S << ' ' << Max.first;
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




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

int main()
{
	double height,low;
	double input;
	vector<double> height_array;
	while (cin >> input) {
		height_array.push_back(input);
	}
	low = height = height_array[0];
	for (int i = 0;i < height_array.size();i++)
	{
		double temp;
		if (low >= height_array[i])
		{
			low = height_array[i];
		}
		if (height <= height_array[i]) {
			height = height_array[i];
		}

	}
	cout << height - low << endl;
	return 0;
}

Measured memory_bytes: 1300
import java.util.*;

public class Main{
    public static void main(String[] args){
	int i,j;
	Scanner scan = new Scanner(System.in);

	while(scan.hasNext()){
	    String tmp[] = (scan.nextLine()).split(",");
	    int card[] = new int[14];
	    int count[] = new int[5];
	    for(i=0;i<5;i++){
		int n = Integer.parseInt(tmp[i]) - 1;
		card[n]++;
		if(n == 0) card[13]++;
	    }
	    for(i=0;i<13;i++){
		if(card[i] < 4){
		    count[card[i]]++;
		}
		else{
		    count[4]++;
		}
	    }

	    if(count[4] == 1){
		System.out.println("four card");
	    }
	    else if(count[3] == 1){
		if(count[2] == 1){
		    System.out.println("full house");
		}
		else{
		    System.out.println("three card");
		}
	    }
	    else if(count[2] == 2){
		System.out.println("two pair");
	    }
	    else if(count[2] == 1){
		System.out.println("one pair");
	    }
	    else{
		boolean flg = false;

		for(i=0;card[i]==0;i++);
		for(j=i+1;j<14 && card[j]==1;j++);

		if(j - i == 5){
		    flg = true;
		}
		else{
		    for(i=1;card[i]==0;i++);
		    for(j=i+1;j<14 && card[j]==1;j++);

		    if(j - i == 5){
			flg = true;
		    }
		}
		if(flg){
		    System.out.println("straight");
		}
		else{
		    System.out.println("null");
		}
	    }
	}
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    double q, x;
    while (cin >> q, q != -1)
    {
        x = q / 2;
        while (abs(x * x * x - q) >= 0.00001 * q)
            x = x - (x * x * x - q) / (3 * x * x);
        printf("%.8f\n", x);
    }
    return 0;
}


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

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

int main() {
    int n, ans = 1, ans2 = 1;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        if(!(k&1)) ans *= 2;
        ans2 *= 3;
    }
    cout << ans2-ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007
#define INF 1e18 

typedef struct{
    int a;
    int b;
    long c;
}edge;

//a→bの順での昇順
int asc(const void* a, const void* b){
    edge p=*(edge*)a;
    edge q=*(edge*)b;
    if((p.a-q.a)>0) return 1;
    else if((p.a-q.a)<0) return -1;
    else{
        if((p.b-q.b)>0) return 1;
        else if((p.b-q.b)<0) return -1;
        else return 0;
    };
}

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    edge* E;
    NEW(E,M);
    for(int i=0;i<M;i++){
        scanf("%d%d%ld",&E[i].a,&E[i].b,&E[i].c);
        E[i].a--;
        E[i].b--;
        E[i].c=-E[i].c;
    }
    qsort(E,M,sizeof(edge),asc);

    long* d;
    NEW(d,N);
    for(int i=0;i<N;i++) d[i]=INF;
    d[0]=0;

    for(int i=1;i<N;i++){
        for(int j=0;j<M;j++){
            if(d[E[j].a]==INF) continue;

            if(d[E[j].a]+E[j].c<d[E[j].b]){
                d[E[j].b]=d[E[j].a]+E[j].c;
            }
        }
    }

    long ans=d[N-1];

    int* negative;
    NEW(negative,N);
    for(int i=0;i<N;i++) negative[i]=0;

    for(int i=1;i<N;i++){
        for(int j=0;j<M;j++){
            if(d[E[j].a]==INF) continue;

            if(d[E[j].a]+E[j].c<d[E[j].b]){
                d[E[j].b]=d[E[j].a]+E[j].c;
                negative[E[j].b]=1;
            }

            if(negative[E[j].a]) negative[E[j].b]=1;
        }
    }

    if(negative[N-1]) printf("inf\n");
    else printf("%ld\n",-ans);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b=0;
  scanf("%d",&a);
  if(a >= 100){
    b +=1;
  a -= 100;}
  if(a >= 10){
    b +=1;
    a -= 10;}
  if(a ==1){
    b +=1;}
  printf("%d\n",b);
  return 0;
}

Measured memory_bytes: 128
while num = STDIN.gets.to_i
  count = 0
  data = Array.new
  if num == 0 then break end
  if num < 5
    puts 0
  else
    i = 1
    while TRUE
      data[i] = Array.new
      if num/5**i == 0 then break end
      for j in 1.. num/5**i
        data[i].push(5**i * j)
      end
      i += 1
    end
    sum = 0
    for i in 1.. data.length-1
      sum+= data[i].length
    end
  puts sum
  end
end

Measured memory_bytes: 2400
def main():
    inf = float('inf')
    mod = 10**9+7
    from itertools import product, permutations, combinations, combinations_with_replacement
    import bisect

    N, H = map(int, input().split())

    katana = [list(map(int, input().split())) for i in range(N)]
    a = max([i[0] for i in katana])
    b = sorted([i[1] for i in katana if a<=i[1]], reverse=True)
    result = 0
    for i in b:
        H -= i
        result += 1
        if H <= 0:
            print(result)
            return

    if a == 1:
        result += H
    else:
        result += H//a + (1 if H%a>=1 else 0)
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 29256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;
ll dp[101][5][5][5];//現在の文字からさかのぼってj,kだった場合にi文字目に来れる文字の数
bool m[101][5][5][5];
//null...0 A...1 C...2 G...3 T...4
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	//fill(dp[0][0][0],dp[101][5][5],0);
	for(int i=0;i<101;i++)
	{
		for(int j=0;j<5;j++)
		{
			for(int k=0;k<5;k++)
			{
				for(int l=0;l<5;l++)
					m[i][j][k][l]=false;
			}
		}
	}	

	dp[1][1][0][0]=1;
	dp[1][2][0][0]=1;
	dp[1][3][0][0]=1;
	dp[1][4][0][0]=1;
	//ここからDP
	for(int i=2;i<n+1;i++)
	{
		for(int j=1;j<5;j++)
		{
			for(int k=0;k<5;k++)
			{
				for(int l=0;l<5;l++)
				{
					if(dp[i-1][j][k][l]>0)
					{
						for(int a=1;a<5;a++)
						{
							dp[i][a][j][k]+=dp[i-1][j][k][l];
							//dp[i][a][j][k]%=MOD;
						}
						
						//AG?Cの場合を取り除く
						if(k==3 && l==1 && !m[i-1][0][k][l])
						{
							m[i-1][0][k][l]=true;
							for(int a=1;a<5;a++)
								dp[i][2][a][k]-=dp[i-1][a][k][l];
						}
						//A?GC
						if(l==1 && j==3 && !m[i-1][j][0][l])
						{
							m[i-1][j][0][l]=true;
							for(int a=1;a<5;a++)
								dp[i][2][j][a]-=dp[i-1][j][a][l];
						}
						//AGGCの場合を足す
						if(l==1 && j==3 && k==3 && !m[i-1][j][k][l])
						{
							m[i-1][j][k][l]=true;
							dp[i][2][j][k]+=dp[i-1][j][k][l];
						}
						for(int a=1;a<5;a++)
							dp[i][a][j][k]%=MOD;
						
						dp[i][3][2][1]=0;
						dp[i][2][1][3]=0;
						dp[i][2][3][1]=0;
					}
				}
			}
		}
	}
	//ここまでDP
	for(int i=0;i<5;i++)
	{
		for(int j=0;j<5;j++)
		{
			for(int k=0;k<5;k++)
			{
				//cerr<<i<<" "<<j<<" "<<k<<" "<<dp[n][i][j][k]<<endl;
				ans+=dp[n][i][j][k];
				ans%=MOD;
			}
		}
	}
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

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

#define N 501

int asc(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main(void)
{
	int n, k, a[N], s[N];

	scanf("%d %d", &n, &k);

	int i, j, tmp, sum = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}

	int rem, count;
	for (i = sum; i > 0; i--)
	{
		if (sum % i == 0)
		{
			for (j = 0; j < n; j++)
				s[j] = a[j] % i;
			qsort(s, n, sizeof(int), asc);
			count = j = 0;
			tmp = n - 1;
			while (j < tmp)
			{
				if (s[j] > (rem = i - s[tmp]))
				{
					s[j] -= rem;
					count += rem;
					tmp--;
				}
				else if (s[j] < rem)
				{
					s[tmp] += s[j];
					count += s[j];
					j++;
				}
				else
				{
					count += s[j];
					j++;
					tmp--;
				}
			}
			if (count <= k)
				break;
		}
	}
	printf("%d\n", i);
	return 0;
}

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

int a[3][3];
int x[3];
int y[3];
int main(void) {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  x[0] = 0;
  for (int i = 0; i < 3; i++) {
    y[i] = a[0][i] - x[0];
  }
  for (int i = 0; i < 3; i++) {
    x[i] = a[i][0] - y[0];
  }

  bool good = true;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (x[i] + y[j] != a[i][j]) {
        good = false;
      }
    }
  }

  if (good) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static int[][] typeitem;
	public static int[] itemval;
	public static int[] val;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			if(n == 0) {
				break;
			}
			String[] AT = new String[n]; //アイテム名とIDの対応の格納
			val = new int[n]; //各IDの価格
			typeitem = new int[n][0];
			for(int i = 0; i < n; i++) {
				String tmp22 = stdIn.next();
				AT[i] = tmp22;
				val[search(AT,tmp22)] = stdIn.nextInt(); 
			}
			
			int suma = stdIn.nextInt();
			
			for(int i = 0; i < suma; i++) {
				int idx0 = search(AT,stdIn.next());
				int nums = stdIn.nextInt();
				typeitem[idx0] = new int[nums];
				for(int j = 0; j < nums; j++) {
					typeitem[idx0][j] = search(AT,stdIn.next());
				}
			}
			int seaID = search(AT,stdIn.next());
			
			int ans = dfs(seaID);
			
			System.out.println(ans);
		}
		
		
		
		
	}
	
	public static int search(String[] id, String tmp) {
		for(int i = 0; i < id.length; i++) {
			if(id[i].equals(tmp)) {
				return i;
			}
		}
		return 0;
	}
	
	public static int dfs(int id) {
		int ALc = 0;
		if(typeitem[id].length == 0) {
			return val[id]; 
		}
		for(int i = 0; i < typeitem[id].length; i++) {
			ALc += dfs(typeitem[id][i]);
		}
		
		if(val[id] > ALc) {
			return ALc;
		}
		return val[id];
	}
}

Measured memory_bytes: 24856
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    if(u == s) a -= 1;
    else b -= 1;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef  long long ll;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
int const N = 1000006;
ll const M = 1020;
long double const ep = .000000000000000001;
stack<int> q;
vector<pair < int , int > > ans;
int curr = 2, n ; 
void go(int node , int lol){
	if(q.size()!=0){
		int num = q.top();
		ans.pb(mp(node , curr));
		lol -= num;
		q.pop();
		go(curr++ , num - 1);
	}
	for(int i = 0 ; i < lol ; i++){
		ans.pb(mp(node,curr++));
	}
}
int main() {
 
	string s;cin >> s;
	n = s.length();
	if(s[0] == '0'){printf("-1\n");return 0;}
	if(s[s.length()-1] == '1'){printf("-1\n");return 0;}
	int to = ceil(s.length() / 2.0);
	for(int i = 0 ; i < to ; i++){
		if(s[i] != s[s.length() - 2 - i]){
			printf("-1\n");
			return 0;
		}
		if(s[i] == '1')q.push(i+1);
	}
	go(1 , n - 1);
	for(int i = 0  ; i < ans.size() ;i++)printf("%d %d\n", ans[i].first , ans[i].second);
	return 0;
}

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

int main(){
	string o,e;
	cin >> o >> e;
	string ans;
	rep(i,o.size()){
		ans.push_back(o[i]);
		if(i < e.size()){
			ans.push_back(e[i]);
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define if_range(x, w, h) if (w <= x && x <= h)
#define BitCheck(a,b)   (a >> b) & 1
#define BitSet(a,b)       a |= (1 << b)
#define BitunSet(a,b)    a &= ~(1 << b)

int compare_int(const void* a, const void* b) { return *(int*) a - *(int*) b; }

//int n, s[100], ans;
//long long int dp[100][21];
//
//long long int func(int a, int sum) {
//	if (a == n-1)
//		return sum == ans ? 1 : 0;
//	long long int cnt = 0;
//	if (sum - s[a + 1] >= 0) {
//		if (!dp[a + 1][sum - s[a + 1]]) {
//			dp[a + 1][sum - s[a + 1]] = func(a + 1, sum - s[a + 1]);
//		}
//		cnt += dp[a + 1][sum - s[a + 1]];
//	}
//	if (sum + s[a + 1] <= 20) {
//		if (!dp[a + 1][sum + s[a + 1]]) {
//			dp[a + 1][sum + s[a + 1]] = func(a + 1, sum + s[a + 1]);
//		}
//		cnt += dp[a + 1][sum + s[a + 1]];
//	}
//	return cnt;
//}
//
//int main() {
//	scanf("%d", &n);
//	n--;
//	for (int i = 0; n > i; i++) {
//		scanf("%d", &s[i]);
//	}
//	scanf("%d", &ans);
//	printf("%lld\n", func(0, s[0]));
//	return 0;
//}


int main() {
	int n, s[100], ans;
	long long int dp[100][21] = {};

	scanf("%d", &n);
	n--;
	for (int i = 0; n > i; i++) scanf("%d", &s[i]);
	scanf("%d", &ans);
	dp [n-1][ans] = 1;
	for (int i = n-2; 0 <= i; i--){
		for (int j = 0; 21 > j; j++){
			if (j + s[i + 1] <= 20)
				dp[i][j] += dp[i + 1][j + s[i + 1]];
			if(j - s[i + 1] >= 0)
				dp[i][j] += dp[i + 1][j - s[i + 1]];
		}
	}
	printf("%lld\n", dp[0][s[0]]);
	return 0;
}
/*

	dp[i][j] = { dp[i+1][j+s[i+1]] + dp[i+1][j-s[i+1]] 

*/

Measured memory_bytes: 1212
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256

int main(void) {
	
	int N, K, R, S, P;
	scanf("%d%d%d%d%d", &N, &K, &R, &S, &P);
	char T[100001];
	scanf("%s", T);
	
	char X[100001];
	long long int sum = 0;

	/*
	for (int i = 0; i < strlen(T); i++) {
		
		if (T[i] == 'r') {
			X[i] = 'p';
		}
		else if (T[i] == 's') {
			X[i] = 'r';
		}
		else {
			X[i] = 's';
		}
	}
	X[strlen(T) ] = '\0';
	printf("%s\n", X);
	*/

	for (int i = 0; i < strlen(T); i++) {
		if (T[i] == 'r') {
			sum += P;
		}
		else if (T[i] == 's') {
			sum += R;
		}
		else {
			sum += S;
		}

		if (i >=K ) {
			if (T[i - K] == T[i]) {
				
				if (T[i] == 'r') {
					sum -= P;
				}
				else if (T[i] == 's') {
					sum -= R;
				}
				else {
					sum -= S;
				}

				T[i] = ' ';
				//X[i] = ' ';
			}
		}

	}
//	printf("%s\n", X);

	printf("%lld", sum);


	return 0;
}

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

using namespace std;

bool ok[3005], ok2[3005];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	for (int i = 0; c * i <= f; i++) {
		for (int j = 0; j * d + c * i <= f; j++) {
			ok[j * d + c * i] = true;
		}
	}

	for (int i = 0; a * i <= f; i++) {
		for (int j = 0; j * b + a * i <= f; j++) {
			ok2[j * b + a * i] = true;
		}
	}

	int ans_a = 0, ans_b = 0;
	for (int i = f; i >= 0; i--) {
		if (!ok[i]) continue;
		int hoge = (i + e - 1) / e;
		for (int j = hoge; j <= f; j++) {
			if (!ok2[j]) continue;
			if (i + j * 100 > f) break;
			if ((ans_a == 0 && ans_b == 0) || j * 100 * ans_b < ans_a * i) {
				ans_a = j * 100;
				ans_b = i;
			}
		}
	}
	cout << ans_a + ans_b << " " << ans_b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main() {
    val scanner = FastScanner(System.`in`)
    val n: Int = scanner.nextInt()
    val list: List<Pair<Int, Int>> = (1..n).map { scanner.next() }
        .map { it.simplify() }
        .filterNot { it.first == 0 && it.second == 0 }
        .toList()

    val former: List<Pair<Int, Int>> = list.filter { it.first >= it.second }
        .sortedBy { it.second }
        .toList()

    val latter: List<Pair<Int, Int>> = list.filter { it.second > it.first }
        .sortedBy { it.first }
        .reversed()
        .toList()

    var left = 0
    var right = 0
    (former + latter)
        .forEach {
            if (it.second < left) {
                left -= it.second
            } else {
                right += it.second - left
                left = 0
            }
            left += it.first
        }

    if (left == 0 && right == 0) {
        println("Yes")
    } else {
        println("No")
    }
}

private fun String.simplify(): Pair<Int, Int> {
    var left = 0
    var right = 0

    this.toCharArray()
        .forEach {
            if (it == '(') {
                left++
            } else {
                if (left > 0) {
                    left--
                } else {
                    right++
                }
            }
        }

    return left to right
}

private class FastScanner(`in`: InputStream) {
    private val reader: BufferedReader = BufferedReader(InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null
    operator fun next(): String {
        if (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return next().toInt()
    }
}


Measured memory_bytes: 164932
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long X;
    cin >> X;
    long big = X / 500 * 1000;
    long small = X % 500 / 5 * 5;
    cout << big + small << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

const ll INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vint a(n);
    vp b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) b[i] = P(a[i], i);
    sort(b.rbegin(), b.rend());

    vvll dp(n + 1, vll(n + 1, -INF));
    dp[0][0] = 0;

    rep(i, n)
    {
        P now = b[i];
        rep(j, i + 1)
        {
            chmax(dp[i + 1][j + 1], dp[i][j] + now.first * abs(now.second - j));
            chmax(dp[i + 1][j], dp[i][j] + now.first * abs((n - i - 1 + j) - now.second));
        }
    }

    ll ans = 0;
    rep(i, n + 1)
    {
        chmax(ans, dp[n][i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 34676
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    int N;
    cin >> N;
    vi a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int on = 0;
    ll cnt = 0;
    while(1) {
        if(cnt >= N) {
            cout << -1 << endl;
            break;
        }
        else if(on == 1) {
            cout << cnt << endl;
            break;
        }
        else {
            cnt++;
            on = a[on] - 1;
        }
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long ll;
typedef tuple<ll,ll,ll> T;
const ll MOD = 1e9+7;


int main()
{
	int n;
	ll g;
	int ans=1e8-1;
	cin>>n>>g;
	vector<T> ques;
	for(int i=0;i<n;i++)
	{
		ll p,c;
		cin>>p>>c;
		ques.push_back(T((i+1)*100,p,c));
	}

	//permutation全探索
	do{
		ll sum=0;
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			T t=ques[i];
			//コンプリートしなくても終了できる場合
			if(g-sum<=get<0>(t)*get<1>(t))
			{
				cnt+=(g-sum)/get<0>(t)+((g-sum)%get<0>(t)!=0);
				ans=min(ans,cnt);
				break;
			}
			//終了できない
			cnt+=get<1>(t);
			sum+=get<0>(t)*get<1>(t)+get<2>(t);
			//コンプリートボーナスが加わることで終了
			if(sum>=g)
			{
				ans=min(ans,cnt);
				break;
			}
		}
	}while(next_permutation(ques.begin(),ques.end()));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b); 
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
	a=mult(a,b);
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
int ipow2[5555];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(5555);
	for(int i=0;i<5011;i++) ipow2[i]=inverse(pow2[i]);
	int n,m; cin>>n>>m;
	vi old(m+1,0);
	old[m]=1;
	for(int z=1;z<=n;z++)
	{
		vi nw(m+1,0);
		vi suf(m+2,0);
		for(int i=m;i>=1;i--)
		{
			suf[i]=add(suf[i+1],mult(pow2[i],old[i]));
		}
		for(int i=1;i<=m;i++)
		{
			nw[i]=add(nw[i],mult(old[i],i+1));
			nw[i]=add(nw[i],mult(mult(i,ipow2[i+1]),suf[i+1]));
		}
		old=nw;
	}
	int ans=0;
	for(int i=1;i<=m;i++) radd(ans,old[i]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 3796