akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string s;
string m;

void C() {
    rotate(s.begin(), s.begin()+1, s.end());
}

void J() {
    rotate(s.begin(), s.end()-1, s.end());
}

void E() {
    string p, q;
    if (s.size() % 2 == 1) {
        char mid = s[s.size()/2];
        for (int i = 0; i < s.size()/2; i++) p.push_back(s[i]);
        for (int i = s.size()/2+1; i < s.size(); i++) q.push_back(s[i]);
        s = q + mid + p;
    } else {
        for (int i = 0; i < s.size()/2; i++) p.push_back(s[i]);
        for (int i = s.size()/2; i < s.size(); i++) q.push_back(s[i]);
        s = q + p;
    }
}

void A() {
    reverse(s.begin(), s.end());
}

void P() {
    for (int i = 0; i < s.size(); i++) {
        if (isdigit(s[i])) {
            if (s[i] == '0') {
                s[i] = '9';
            } else {
                s[i]--;
            }
        }
    }
}

void M() {
    for (int i = 0; i < s.size(); i++) {
        if (isdigit(s[i])) {
            if (s[i] == '9') {
                s[i] = '0';
            } else {
                s[i]++;
            }
        }
    }
}

void F() {
    for (int i = 0; i < m.size(); i++) {
        switch (m[i]) {
            case 'J':
                J();
                break;
            case 'C':
                C();
                break;
            case 'E':
                E();
                break;
            case 'A':
                A();
                break;
            case 'P':
                P();
                break;
            case 'M':
                M();
                break;
            default:
                cerr << "ERROR" << endl;
        }
    }
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> m;
        reverse(m.begin(), m.end());
        cin >> s;
        F();
        cout << s << endl;
    }
    return 0;
}

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

using namespace std;

int N,K;

int dfs(int X){
  if( X == 0){ return 1;}
    return   min(2 * dfs(X - 1), dfs( X - 1) + K);}
    

int main(){
  cin >> N >> K;
  cout << dfs(N) << endl;
  
  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

ll mod(ll a)
{
	if(a<inf)return a;
	else 
	return a%inf;
}
 void test_cases()
{

ll s,c;
cin>>s>>c;

	
if(c>=2*s)
{
	c-=2*s;
	
	if(c)
	{
		c=c/4;
	}
	cout<<s+c;
	}
	else
	{
		c=c/2;
		s=min(s,c);
		cout<<s;
		}	





}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


Measured memory_bytes: 3556
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n, q; cin >> n >> q;
    vector<vector<int>> ab(n);
    for (int i = 0; i < n-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }
    vector<int> cnt(n);
    for (int i = 0; i < q; i++)
    {
        int p, x; cin >> p >> x;
        p--;
        cnt[p] += x;
    }
    
    // cout << 1 << endl;
    queue<int> que;
    que.push(0);
    vector<bool> ok(n, false);
    ok[0] = true;

    while (!que.empty()) {
        int now = que.front();
        que.pop();
        for (int i = 0; i < ab[now].size(); i++)
        {
            int next = ab[now][i];
            if (ok[next]) continue;
            ok[next] = true;
            que.push(next);
            cnt[next] += cnt[now];
        }
        
    }
    
    for (int i = 0; i < n; i++)
    {
        printf("%d%c", cnt[i], (i==n-1)? '\n' : ' ');
    }
    
    return 0;
}

Measured memory_bytes: 15604
N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
ListN=[A,B,C,D,E]
ListN.sort()
q=ListN[0]
if N%q!=0:
  w=(N//q)+1 #律速段階の輸送回数
elif N%q==0:
  w=N//q
if q==A:
  print(w+4)
elif q==B:
  print(w+4)
elif q==C:
  print(w+4)
elif q==D:
  print(w+4)
elif q==E:
  print(w+4)


Measured memory_bytes: 3064
#include <stdio.h>

main(){
    int N;
    int a=0,b;
    int i;
    int t;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&t);
        if(t>a){
            a=t;
            scanf("%d",&b);
        }else
            scanf("%d",&t);
    }
    printf("%d\n",a+b);

    return 0;
}

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

typedef long long ll;

int main(void) {
    int n; scanf("%d", &n);
    ll ans = 0;
    for (int i = 1; i <= n; ++i)
        ans += 1ll * i * (n - i + 1);
    for (int i = 1; i <= n - 1; ++i) {
        int u, v; scanf("%d %d", &u, &v);
        if (u > v) swap(u, v);
        ans -= 1ll * (n - v + 1) * u;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3764
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 26 14:22:54 2020

@author: Maruthi Srinivas
"""
import sys
sys.setrecursionlimit(1000000)
def dfs(node,graph,dp):
    temp=0
    if dp[node]!=-1:
        return dp[node]
    for i in graph[node]:
        temp=max(temp,dfs(i,graph,dp)+1)
    dp[node]=temp
    return temp
            
v,e=map(int,input().split())
adj={x:[] for x in range(v+1)}
for i in range(e):
    x,y=map(int,input().split())
    adj[x].append(y)
m=-1
dp=[-1]*(v+1)
for i in range(1,v+1):
    x=dfs(i,adj,dp)
    m=max(m,x)
print(m)



Measured memory_bytes: 192252
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;



int main()
{
	int K;    cin >> K;
	string S; cin >> S;
	
	if (S.length() > K)
	{
		cout << S.substr(0, K) << "..." << endl;
	}
	else
	{
		cout << S << endl;
	}

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100000
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt;

int main(){
    cin >> n;
    rep(i,n){
        int a; cin >> a;
        if(a&1) cnt++;
    }
    if(cnt%2) cout << "NO" << endl;
    else cout << "YES" << endl;
}


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

using namespace std;

int n,x[300000];
pair<int,int> p[300000];
int sol[300000];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        p[i]={x,i};
    }
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++){
        int x = p[i].second ;
        if(i>n/2)sol[x]=p[n/2].first;
        else sol[x]=p[n/2+1].first;

    }
    for(int i=1;i<=n;i++){
        printf("%d\n",sol[i]);
    }

}


Measured memory_bytes: 5888
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

int main () {
  int n = in();
  vi p(n);
  rep(i,n) cin >> p[i];
  
  int ans = 0;
  for (int i = 1; i <= n-2; ++i) {
    if (p[i-1]<p[i] && p[i]<p[i+1]) ans++;
    else if (p[i-1]>p[i] && p[i]>p[i+1]) ans++;
  }

  cout << ans << endl;
  return 0;
}

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



int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    
   ll arr[n];
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	sort(arr,arr+n);
	
	ll sum=0;
	for(int i=0;i<n-k;i++)
	{
		sum+=arr[i];
	}
	cout<<sum<<endl;
	
	
	
    
	return 0;
	
	
}

Measured memory_bytes: 1792
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()

        if S == 'SUN':
            print(7)
        elif S == 'MON':
            print(6)
        elif S == 'TUE':
            print(5)
        elif S == 'WED':
            print(4)
        elif S == 'THU':
            print(3)
        elif S == 'FRI':
            print(2)
        elif S == 'SAT':
            print(1)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ll a,b,c,d,e,f;

int main(){
    cin >> a >> b >> c >> d >> e >> f;

    set<ll> w,s;
    for(int i=0;i*a<=30;i++){
        for(int j=0;j*b<=30;j++){
            if(i*a+j*b<=30) w.insert(i*a+j*b);
        }
    }
    for(int i=0;i*c<=1500;i++){
        for(int j=0;j*d<=1500;j++){
            if(i*c+j*d<=1500) s.insert(i*c+j*d);
        }
    }

    ll ws=w.size();
    ll ss=s.size();

    pair<ll,ll> ans(make_pair(0,0));
    ld mxmnoudo = 0.0;

    for(auto i:w){
        for(auto j:s){
            //cout << i << " " << j << endl;
            ll wt = i * 100;
            ll sg = j;
            ll sgwt = wt+sg;
            if(e*wt<100*sg) continue;
            if(sgwt>f) continue;
            if(1.0*(ld)(sg)/(ld)(sgwt)>=mxmnoudo){
                mxmnoudo = 1.0*(ld)(sg)/(ld)(sgwt);
                ans = make_pair(sgwt,sg);
            }

        }
    }
    cout << ans.first << " " << ans.second << endl;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int gcd(int a, int b) {
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

signed main(void) {
	int n,m;
	cin >> n >> m;
	vector<int>x(m);
	rep(i, m) {
		cin >> x[i];
	}
	int ans = 0;
	if (n >= m) {
		print(0);
		return 0;
	}
	sort(x.begin(), x.end());
	vector<int>l(m - 1);
	rep(i, m - 1) {
		l[i] = x[i + 1] - x[i];
	}
	sort(l.begin(), l.end());
	rep(i, m-n) {
		ans += l[i];
	}
	print(ans);

}


Measured memory_bytes: 1792
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Integer> a = new ArrayList<Integer>();
		for(int i=0; i<M; i++) {
			a.add(sc.nextInt());
		}

		int MOD = 1000000007;
		long dp[] = new long[N+1];
		dp[0] = 1;
		int j=0;
		for(int i=1; i<=N; i++) {
			if(j<M && a.get(j) == i) {
				j++;
				continue;
			}
			dp[i] += dp[i-1];
			dp[i] %= MOD;
			if(i-2>=0) {
				dp[i] += dp[i-2];
				dp[i] %= MOD;
			}
		}
		System.out.println(dp[N]);
		sc.close();
	}
}


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

int main()
{
    int n,i,j;
    cin >> n;
    vector<int> c(n-1);
    vector<int> s(n-1);
    vector<int> f(n-1);
    for(i = 0;i < n-1;++i){
        cin >> c.at(i) >> s.at(i) >> f.at(i);
    }
    
    for(i = 0;i < n-1;++i){
        int temp = 0;
        for(j = i;j < n-1;++j){
            if(temp < s.at(j)){
                temp = s.at(j)+c.at(j);
            }else{
                if((temp-s.at(j))%f.at(j)){
                    temp = temp-(temp-s.at(j))%f.at(j)+f.at(j)+c.at(j);
                }else{
                    temp += c.at(j);
                }
            }
        }
        cout << temp << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        count=0
        #range(1,n)は、1からn-1までを意味する（eg.range(2,n)=2,3,4...n-1)
        for i in range(1,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        count=count+1
        print(count)


Measured memory_bytes: 5592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Discount_Fare
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = Console.ReadLine().Split(' ').ToArray();
            var num_X = int.Parse(num[0]);
            var num_Y = int.Parse(num[1]);

            var sum = num_X + num_Y / 2;

            Console.WriteLine(sum);
            
        }
    }
}

Measured memory_bytes: 13268
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

s = arr_data[0][0]


print(s.count("o")*100+700)

Measured memory_bytes: 3060
R, G, B, N = map(int, input().split())
ans = 0
for i in range(int(N/R) + 1):
    for j in range(int(N/G) + 1):
        tmp = int((R * i) + (G * j))
        if N >= tmp and (N - tmp) % B == 0:
            ans += 1
print(ans)


Measured memory_bytes: 40940
module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_str () = sf "%s " (fun x -> x)
let read_array n read () = A.init n (fun _ -> read ())
let err s = raise (Failure s)

let range s t = A.init (t - s) @@ (+) s
let foreach fold_f init s t map_f =
  range s t |> A.map map_f |> A.fold_left fold_f init

let inf = int_of_float 1e18
let eps = 1e-11

module S = struct
  include String
  let of_array a = String.init (A.length a) (A.get a)
  let to_array s = A.init (String.length s) (String.get s)
end;;

let rec sum_of_digit n =
  if n = 0
  then 0
  else sum_of_digit (n / 10) + n mod 10

let () =
  let n = read_int () in
  let c = read_int () in
  let d =
    let read () =
      let s = read_int () in
      let t = read_int () in
      let c = read_int () in
      (s, t, c - 1) in
    read_array n read () in
  let mat = A.make_matrix c 100100 0 in
  let update (s, t, c) =
    mat.(c).(s - 1) <- mat.(c).(s - 1) + 1;
    mat.(c).(t) <- mat.(c).(t) - 1 in
  Array.iter update d;
  let accu ary =
    for i = 0 to 100050 do
      ary.(i + 1) <- ary.(i + 1) + ary.(i)
    done in
  Array.iter accu mat;
  let cnt i = foreach (+) 0 0 c (fun j -> if mat.(j).(i) > 0 then 1 else 0) in
  let res = foreach max 0 0 100010 cnt in
  pf "%d\n" res


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  bool x = true;
  rep(i,n/2){
    if(s[i] != s[n/2+i]) x = false;
  }
  if(n%2 != 0) x = false;
  cout << (x ? "Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  int cnt = 0;
  for (auto &i : a)
  for (auto &j : i) {
    cin >> j;
    if (j == '#') cnt++;
  }
  if (cnt == h + w - 1) cout << "Possible" << '\n';
  else cout << "Impossible" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3604
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def g(i, N):
    tmp = N // i
    return int(i*tmp*(tmp+1)/2)


def main():
    N = II()
    ans = 0
    for i in range(1, N+1):
        ans += g(i, N)
    print(ans)


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()


Measured memory_bytes: 64352
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s; i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n, k, q; cin >> n >> k >> q;
    vector<int> score(n, k-q);
    REP(i, q){
        int a; cin >> a;
        ++score[a-1];
    }
    REP(i, n) cout << (score[i]>0 ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

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

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

    cout << a + pow(a,2) + pow(a,3) << endl;

    return 0;
}

Measured memory_bytes: 3556
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;

signed main() {
	int s; cin >> s;
	if (s == 1000000000000000000) {
		cout << "0 0 0 1000000000 1000000000 0" << endl;
		return 0;
	}
	int A = 1000000000;
	int D = s / A + 1;
	int B = 1;
	int C = A*D - s;
	cout << "0 0 " << A << ' ' << B << ' ' << C << ' ' << D << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int A, B;
	cin >> A >> B;
	if (A <= 5) {
		cout << 0 << "\n";
	} else if (6 <= A && A <= 12) {
		cout << B / 2 << "\n";
	} else {
		cout << B << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[101010];
bool on_cyc[101010];
int vis[101010];
vector<int> rev[101010];

void fuee()
{
	puts("0");
	exit(0);
}

int odds[101010];
i64 fact[101010], facti[101010];

i64 modpow(i64 a, int p = MOD - 2)
{
	if (p == 0) return 1;
	i64 tmp = modpow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2) tmp = tmp * a % MOD;
	return tmp;
}

i64 C(int a, int b)
{
	if (a < b) return 0;
	return fact[a] * facti[b] % MOD * facti[a - b] % MOD;
}

void naive()
{
	int p[20];
	for (int i = 0; i < N; ++i) {
		p[i] = i;
	}
	int ret = 0;
	do {
		bool ok = true;
		for (int i = 0; i < N; ++i) {
			if (A[i] == p[i] || A[i] == p[p[i]]) {
			} else ok = false;
		}
		if (ok) ++ret;
	} while (next_permutation(p, p + N));
	printf("%d\n", ret);
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", A + i);
		--A[i];
		rev[A[i]].push_back(i);
		vis[i] = -1;
	}
//	naive();
	for (int i = 0; i <= N; ++i) odds[i] = 0;
	fact[0] = 1;
	for (int i = 1; i <= N; ++i) fact[i] = fact[i - 1] * i % MOD;
	for (int i = 0; i <= N; ++i) facti[i] = modpow(fact[i]);

	for (int i = 0; i < N; ++i) if (vis[i] == -1) {
		int p = i;
		for (;;) {
			if (vis[p] == i) {
				on_cyc[p] = true;
				break;
			}
			if (vis[p] != -1) break;
			vis[p] = i;
			p = A[p];
		}
	}

	i64 ans = 1;
	for (int i = 0; i < N; ++i) if (on_cyc[i]) {
		vector<int> cyc;
		int p = i;
		do {
			cyc.push_back(p);
			p = A[p];
		} while (p != i);

		vector<int> branch(cyc.size(), 0);
		for (int j = 0; j < cyc.size(); ++j) {
			if (rev[cyc[j]].size() >= 3) fuee();
			if (rev[cyc[j]].size() == 2) {
				int q = rev[cyc[j]][0] + rev[cyc[j]][1] - cyc[(j + cyc.size() - 1) % cyc.size()];
				int len = 1;
				for (;;) {
					if (rev[q].size() >= 2) fuee();
					if (rev[q].size() == 1) {
						q = rev[q][0];
						++len;
						continue;
					}
					break;
				}
				branch[j] = len;
			}
		}
		for (int j = 0; j < cyc.size(); ++j) branch.push_back(branch[j]);
		int last_branch = -1;
		for (int j = 0; j < cyc.size() * 2; ++j) {
		//	printf("%d: %d\n", j, branch[j]);
			if (branch[j] > 0) {
				if (j >= cyc.size()) {
					int gap = j - last_branch;
		//			printf("%d %d\n", gap, branch[j]);
					if (gap < branch[j]) fuee();
					if (gap == branch[j]) {
					} else ans = ans * 2 % MOD;
				}
				last_branch = j;
			}
		}

		if (last_branch == -1) {
			odds[cyc.size()] += 1;
		}
	}
	for (int i = 1; i <= N; ++i) {
		int cnt = odds[i];
		if (cnt == 0) continue;

		i64 pat = 0, cur = 1;
		int w = (i == 1 || i % 2 == 0) ? 1 : 2;
		for (int j = 0; j <= cnt / 2; ++j) {
		//	printf("%d %lld\n", j, cur);
			ADD(pat, cur * modpow(w, cnt - 2 * j) % MOD * facti[j] % MOD * modpow(i, j));
			cur = cur * C(cnt - 2 * j, 2) % MOD;
		}
		ans = ans * pat % MOD;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 9848
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
char s[N];

int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	For(i,1,len) printf("%c",s[i]=='?'?'D':s[i]); 
}

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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 1000


int main()
{
    int n;
//    while(1)
//    {

    cin>>n;
    if(n%1000==0) cout<<"0\n";
    else
    cout<<1000-(n%1000)<<"\n";
//    }

    return 0;
}




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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, count=0, answer=0;
  cin >> N;
  for(int i=1; i<=N; i++) {
    if(i%2==1) {
      count=0;
      for(int j=1; j<=i; j++) {
        if(i%j==0) count++;
      }
      if(count==8) answer++;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, k, s = geta(int)

    r = s + 1 if s < 10**9 else 1

    ans = [s] * k + [r] * (n - k)
    print(*ans, sep=" ")


if __name__ == "__main__":
    main()

Measured memory_bytes: 6876
#include <stdio.h>
typedef long long ll;

ll n, m, q, ans = 0, a[50], b[50], c[50], d[50], now[10];

void dfs(ll p) {
  ll i, sum = 0;
  if(p == n) {
    for(i = 0; i < q; ++i) if(now[b[i]] - now[a[i]] == c[i]) sum += d[i];
    if(ans < sum) ans = sum;
    return;
  }
  for(i = now[p - 1]; i < m; ++i) {
    now[p] = i;
    dfs(p + 1);
  }
}

int main(void) {
  ll i;
  scanf("%lld%lld%lld", &n, &m, &q);
  for(i = 0; i < q; ++i) scanf("%lld%lld%lld%lld", &a[i], &b[i], &c[i], &d[i]), a[i]--, b[i]--;
  for(i = 0; i < m; ++i) {
    now[0] = i;
    dfs(1);
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val M = sc.nextInt
    val X = Array.fill(M)(sc.nextInt).sorted
    val d = (for (i <- 1 until X.length) yield X(i) - X(i - 1)).sorted

    d.take(M - N).sum.toString
  }
}


Measured memory_bytes: 57156
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long gcd(long long a, long long b){ // 最大公約数
    if(a == 0 || b == 0)
        return 0;
    if(b > a)
        swap(a, b);
    long long tmp;
    while((tmp = a % b) != 0){
        a = b;
        b = tmp;
    }
    return b;
}

long long lcm(long long a, long long b){ // 最小公倍数
    return a / gcd(a, b) * b;
}

long long solve(vector<vector<int> >& stick, int i)
{
    if(i == 0)
        return 1;

    long long p = stick[i][0];
    long long q = stick[i][1];

    long long a = solve(stick, stick[i][2]);
    long long b = solve(stick, stick[i][3]);
    long long tmp = lcm(p*a, q*b);
    a = tmp / p;
    b = tmp / q;

    return a + b;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > stick(n+1, vector<int>(4));
        vector<bool> check(n+1, false);
        for(int i=1; i<=n; ++i){
            for(int j=0; j<4; ++j){
                cin >> stick[i][j];
            }
            check[stick[i][2]] = check[stick[i][3]] = true;
        }

        long long ret = 0;
        for(int i=1; i<=n; ++i){
            if(!check[i])
                ret += solve(stick, i);
        }
        cout << ret << endl;
    }
}

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

int main() {
	int X,A,B;
	bool delicious,safe;
	delicious=true;
	safe=true;
	cin >> X >> A >> B;
	if(A<B){
		delicious=false;
	}
	if(X<B-A){
		safe=false;
	}
	
	if(safe&&delicious){
		cout << "delicious"<< endl;
	}
	if(safe&&!delicious){
		cout << "safe" << endl;
	}
	if(!safe&&!delicious){
		cout << "dangerous" << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        long a = long.Parse(input[0]);
        long b = long.Parse(input[1]);
        long c = long.Parse(input[2]);
        long d = long.Parse(input[3]);*/
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
//        int b = int.Parse(ReadLine());
//        int c = int.Parse(ReadLine());
//        int d = int.Parse(ReadLine());
//        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
//        string[] input = ReadLine().Split(' ');
//        string ko = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string[] a = ReadLine().Split(' ');
        string b = a[0] + a[1];
        int c = int.Parse(b);
        int d = (int)Sqrt(c);
        if(d*d == c){
            WriteLine("Yes");
        }else{
            WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
int main(void) {
	int A,B,C,D;
  	scanf("%d %d %d",&A,&B,&C);
  	D = C-(A-B);
  	if (D>0) {
		printf("%d\n",D);
    } else {
		printf("0\n");
    }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

LL n;
LL m;
LL x;
vector<LL> c(15);
vector<vector<LL>> a(15, vector<LL>(15));

LL dfs(LL sum, vector<LL> a_sum, int point){
    if(point==n){
        for(int i=0; i<m; i++){
            //cout << a_sum[i] << " ";
        }
        //cout << sum << endl;
        for(int i=0; i<m; i++){
            if(a_sum[i]<x){
                return -1;
            }
        }

        return sum;
    }

    LL tmp0=dfs(sum, a_sum, point+1);
    sum+=c[point];
    for(int j=0; j<m; j++){
        a_sum[j]+=a[point][j];
        //cout << j << " " << a_sum[j] << endl;
    }
    LL tmp1=dfs(sum, a_sum, point+1);
    //cout << point << " " << tmp0 << " " << tmp1 << endl;
    if(tmp0==-1 && tmp1==-1){
        return -1;
    }else if(tmp0==-1){
        return tmp1;
    }else if(tmp1==-1){
        return tmp0;
    }else{
        return (LL)min(tmp0, tmp1);
    }
}

int main() {
    LL ans;
    cin >> n >> m >> x;
    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }

    vector<LL> a_sum(15, 0);

    ans = dfs(0, a_sum, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import sys

n, h = [int(e) for e in raw_input().split()]

kl = []
for i in range(0, n):
    a, b = [int(e) for e in raw_input().split()]
    kl.append((b, 0))
    kl.append((a, 1))

kl.sort(reverse=True)
# print kl

n = 0
i = 0
while h > 0:
    k = kl[i]
    if k[1] == 0:
        h -= k[0]
        i += 1
        n += 1
    else:
        n = n + ((h + k[0] - 1) / k[0])
        break

sys.stdout.write('%d\n' % (n))
sys.stdout.flush()


Measured memory_bytes: 26372
#include<bits/stdc++.h>
using namespace std;
//from https://atcoder.jp/contests/abc142/submissions/7731316
 
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
 
template<class T>
inline bool chmax(T &a,T b) {
    if (a<b) {
        a=b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a,T b) {
    if (a>b) {
        a=b;
        return true;
    }
    return false;
}
 
int n,m;
int a[1050], b[1050], c[1050][20];
 
void input() {
    cin >>n >>m;
    for (int i=1;i<=m;i++) {
        cin >>a[i]>> b[i];
        for (int j=1;j<=b[i];j++) cin >>c[i][j];
    }
}
 
void solve() {
    input();
    const int inf=1e9;
    vector<int> dp(5000,inf);
    dp[0]=0;
    for (int item=1;item<=m;item++) {
        int now=0;
        for (int j=1;j<=b[item];j++) {
            now|= (1<<(c[item][j]-1));
        }
        for (int bits=0;bits<(1<<n);bits++) {
            chmin(dp[bits|now],dp[bits]+a[item]);
        }
    }
    if (dp[(1<<n)-1]==inf) dp[(1<<n)-1]=-1;
    cout << dp[(1<<n)-1] <<endl;
}
 
 
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 384
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
l = 1
for i in a:
    l = lcm(l, i)
l %= mod
ans = 0
for i in a:
    ans += l * pow(i, mod - 2, mod)
print(ans % mod)

Measured memory_bytes: 6136
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: a,b,c,d,turn

    read*, a,b,c,d
    turn=1
    do while(a > 0 .and. c>0)
        if (turn==1) then
            c=c-b
        else
            a=a-d
        end if
        turn=turn*(-1)
    end do

    if (a>0) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if
end program 

Measured memory_bytes: 2868
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    int ln = 0;
    int hn = N;
    REP(i, M){
        int l, r;
        cin >> l >> r;
        ln = max(ln, l);
        hn = min(r, hn);
    }
    cout << max(0, hn - ln + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

bool f[d5],s[d5];
int df[d5],ds[d5];
vector<int> edge[d5];

void f_dfs(int i){
    for(auto u:edge[i]){
        if(f[u])continue;
        f[u]=true;
        df[u]=df[i]+1;
        f_dfs(u);
    }
}
void s_dfs(int i){
    for(auto u:edge[i]){
        if(s[u])continue;
        s[u]=true;
        ds[u]=ds[i]+1;
        s_dfs(u);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    df[0]=0;
    f[0]=true;
    f_dfs(0);
    ds[n-1]=0;
    s[n-1]=true;
    s_dfs(n-1);
    int fcnt=0,scnt=0;
    for(int i=0;i<n;i++){
        if(df[i]<=ds[i])fcnt++;
        else scnt++;
    }
    if(fcnt>scnt)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
}


Measured memory_bytes: 10624
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
hist = [""] * N
hands = {"r": 1, "s": 2, "p": 3}

total = 0
for i in range(N):
  t = T[i]
  if t == "r":
    h = "p"
    points = P
  elif t == "s":
    h = "r"
    points = R
  elif t == "p":
    h = "s"
    points = S

  if i >= K and hist[i-K] == h:
    continue
  else:
    hist[i] = h
    total += points

print(total)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int ans[5];
int main(int argc, char** argv) {
	int n;
	cin>>n;
	string ss[5]={"AC","WA","TLE","RE"};
	string a;
	for(int i=0;i<n;i++){
		cin>>a;
		for(int j=0;j<4;j++){
			if(a==ss[j]){
				ans[j]++;
			}
		}
	}
	for(int i=0;i<4;i++){
		cout<<ss[i]<<" x "<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pb push_back
vector<int> adj[100005];
bool vis[100005]={0};
ll dp[100005];
void dfs(int v){
    vis[v]=1;
    for(auto i:adj[v]){
        if(!vis[i]){
          dfs(i);
        }
    }
    if(adj[v].size()!=0){
    ll m=-999999;
    for(auto i:adj[v]){
        if(dp[i]>m) m=dp[i];
    }
    dp[v]+=m;
    }
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
	    int x,y;
	    cin>>x>>y;
	    adj[x].pb(y);
	}
	fill(dp,n+1,1);
	for(int i=1;i<=n;i++){
	    if(!vis[i]){
	        dfs(i);
	    }
	}
	ll ma=-1209999;
	for(int i=1;i<=n;i++){
	    if(dp[i]>ma){
	        ma=dp[i];
	    }
	}
	cout<<ma-1<<'\n';
	
	return 0;
}


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

int LCS(const string &a, const string &b) {
	vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, 0));
	for (int i = 0; i <= a.size(); i++) {
		for (int j = 0; j <= b.size(); j++) {
			if (i > 0 && j > 0) {
				if (a[i - 1] == b[j - 1]) {
					dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
				}
				else {
					dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
				}
				dp[i][j] = max(dp[i][j], dp[i][j - 1]);
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			}
			else if (i > 0) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			}
			else if (j > 0) {
				dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			}
		}
	}
	return dp[a.size()][b.size()];
}

int main()
{
	int n;
	string X, Y;
	cin >> n;
	while (n--) {
		cin >> X >> Y;
		cout << LCS(X, Y) << endl;
	}
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int ac,tle;
    ac=n-m;
    tle=m;
    cout << pow(2,tle)*(100*ac+1900*tle) << endl;
}

Measured memory_bytes: 4156
#include <iostream>

using namespace std;

int main() {
    int K;
    string S;
    cin >> K;
    cin >> S;
    if(S.length() > K){
        cout << S.substr(0,K) << "..." << endl;
    }else{
        cout << S << endl;
    }
    
        return 0;
}

Measured memory_bytes: 3536
from numpy import*
(_,k),*t=[int64(t.split())for t in open(0)]
A,F=map(sort,t)
l=-1
r=10**12
while r-l>1:
 m=l+r>>1
 if sum(A)-sum(minimum(A,m//F[::-1]))>k:l=m
 else:r=m
print(r)

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

int main(){
  int k, s; cin >> k >> s;
  int ans = 0;
  for(int x=0; x<=k; x++){
    for(int y=0; y<=k; y++){
      int z=s-x-y;
      if((0<=z) && (z<=k)){
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    int ans;
    ans = 0;
    for(int i=0; i<s.size()/2; ++i){
        if(s[i]==s[s.size()-i-1]){}
        else{
            ans +=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 20001
struct faner {
    int w, s, v;
} a[1010];
ll f[N], ans;
bool cmp(faner a, faner b) { return a.s + a.w < b.s + b.w; }
int n;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d%d", &a[i].w, &a[i].s, &a[i].v);
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; i++)
        for (int j = N - 1; j >= a[i].w; j--)
            if (a[i].s + a[i].w >= j) f[j] = max(f[j], f[j - a[i].w] + a[i].v);
    for (int i = 1; i < N; i++) ans = max(ans, f[i]);
    printf("%lld\n", ans);
    return 0;
}

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

typedef string s;
typedef vector
 vs;

void p(vs &v)
{
	for (s &x: v)
		cout << (&x == &v[0] ? "" : " ") << x;
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	vs bs(n), ss(n);
	for (s &x: bs)
		cin >> x;
	ss = bs;

	auto cmp = [](s a, s b){return a[1] < b[1];};
	stable_sort(bs.begin(), bs.end(), cmp);
	p(bs);
	cout << "Stable" << endl;

	for (auto i = ss.begin(), e = ss.end(); i != e - 1; i++) {
		auto min = i, j = i;
		for (; j != e; j++)
			if (cmp(*j, *min))
				min = j;
		if (i != min)
			swap(*i, *min);
	}
	p(ss);
	cout << (bs == ss ? "Stable" : "Not stable") << endl;
}


Measured memory_bytes: 3212
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    ll a, b, k;
    cin >> a >> b >> k;
    if(k<=a)
        cout <<a-k<<' '<<b, exit(0);

    k -= a;
    cout <<0<<' '<< max(b - k, 0LL);
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 500;
const int inf = (1<<21);
int edge[N][N];
bool visited[N];



main(){
  int n,m;
  while(cin>>n>>m && n ){
    
    rep(i,n){
      rep(j,n)edge[i][j]=inf;
      edge[i][i]=0;
    }
    rep(i,m){
      int f,t;
      cin>>f>>t;
      f--;t--;
      edge[f][t]=edge[t][f]=1;
    }
    rep(k,n)rep(i,n)rep(j,n)edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
    int cnt=0;
    REP(i,1,n)if(edge[0][i] <=2)cnt++;
    cout << cnt << endl;
    
  }
}

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

using namespace std;
using ll = long long;
const int INF = 1e9 + 5;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int& i : h) 
    	cin >> i;
  vector<int> dp(n, INF);
  dp[0] = 0;
  for(int i=0; i<n; i++) {
    for(int j = i+1; j<=i+k; j++) {
      if(j < n)
        	dp[j] = min(dp[j] , dp[i] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n-1];
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Stack;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int sum = 0;
        boolean[] passed = new boolean[N];
        for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 50680
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] like = new int[31];
        int ans = 0;
        for(int i = 0;i < n;i++){
            int kind = sc.nextInt();
            for(int j = 0;j < kind;j++){
                like[sc.nextInt()]++;
            }
        }

        for(int i : like){
            if(i == n)
            ans++;
        }

        System.out.println(ans);
    }
}

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

int main(){

    int A,B,C;
    cin >> A >> B >> C;

    int K;
    cin >> K;

    while(K > 0 && B <= A){
        B *= 2;
        K--;
    }

    while(K > 0 && C <= B){
        C *= 2;
        K--;
    }

    if(B > A && C > B) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<functional>

#define LLI long long int

using namespace std;

int main(){
	int N,K;
	cin>>N>>K;
	int C=(N-1)*(N-2)/2;
	if(K>C){
			cout<<-1<<endl;
			return 0;
	}
	int sa=C-K;
	int M=N-1+sa;
	cout<<M<<endl;
	for(int i=1;i<N;i++){
			cout<<i<<" "<<N<<endl;
	}
	for(int v=2;v<N;v++)for(int u=1;u<v;u++){
		if(sa==0)break;
		cout<<u<<" "<<v<<endl;



		sa--;
	}

	return 0;
}



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

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}
int main(void){
  char s[2000],t[2000];
  cin >> s >> t;
  ll ss=strlen(s),tt=strlen(t);
  ll k=3000,l;
  rep(i,ss-tt+1){
    l=0;
    for(ll j=i;j<i+tt;j++){
      if(s[j]!=t[j-i])l++;
    }
    if(k>l)k=l;
  }
  cout << k;
}

Measured memory_bytes: 3600