akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define out(x) rep(i, 0, (x).size()) cout << (x)[i] << ((i != (x).size() - 1) ? " " : "\n")
const double PI = 3.14159265;
const int MAXN = 1 << 15;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
#define Pr(a) (#a) << "=" << (a) << " "
#define pr(a) cout << Pr(a) << '\n'
///////////////////////////////////////////////////////
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> V(n);
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    V[i] = make_pair(x, y);
  }
  sort(all(V));
  for (auto v : V) {
    cout << v.first << " " << v.second << '\n';
  }
  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  double N,ans=0;double x;string v;cin>>N;
  for(int i=0;i<N;i++){
    cin>>x>>v;
    if(v=="BTC")x*=380000;
    ans+=x;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        String S = stdIn.next();
        String T = stdIn.next();

        String B = "";
        String S_I;
        String T_I;
        for(int i=0; i<N; i++){
            S_I = String.valueOf(S.charAt(i));
            B=B.concat(S_I);
            T_I = String.valueOf(T.charAt(i));
            B=B.concat(T_I);
        }
        System.out.print(B);
        //List<String> A = new ArrayList<>();

        


    }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<ll>> p(3);
  vector<map<ll, ll>> num(3);
  REP(i, n) {
    if (s[i] == 'R') {
      p[0].push_back(i);
      num[0][i]++;
    } else if (s[i] == 'G') {
      p[1].push_back(i);
      num[1][i]++;
    } else {
      p[2].push_back(i);
      num[2][i]++;
    }
  }

  vector<char> c{'R', 'G', 'B'};
  map<char, ll> mp;
  REP(i, 3) { mp[c[i]] = i; }

  ll ans = 0;
  REP(i, n) {
    FOR(j, i + 1, n) {
      if (s[i] != s[j]) {
        ll m;
        REP(k, 3) {
          if (c[k] != s[i] && c[k] != s[j]) m = mp[c[k]];
        }
        ll d = j - i;
        auto it = upper_bound(ALL(p[m]), j);
        ans += p[m].end() - it - num[m][j + d];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
int main(){
    int a,b;
    while(cin>>a>>b){
        if(a<b)swap(a,b);
        for(int i=a;i>0;i--){
            if(b%i==0&&a%i==0){
                cout<<i<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
 
using namespace std;
 
long long MAX = 1e18 + 9 ;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vso(x) sort( x.begin() , x.end() )
#define aso(x) sort( x , x + x.size() )
#define print(x) cout << x << endl 
#define no cout << "NO\n" 
#define yes cout << "YES\n"
typedef long long ll ; 
typedef unsigned long long ull ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;

ll a[500] , prefix[500] , x[500][500] ;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("problem_name.out", "w", stdout) ;
    //freopen("problem_name.in", "r", stdin) ;
    //ull h ; cin >> h ; srand(h) ;
    //int t ; cin >> t ; while(t--){}
    ll n ; cin >> n ;
    ll sum = 0 ;
    for ( ll i = 1 ; i <= n ; i++ )
    {
        cin >> a[i] ;
        sum += a[i] ;
        prefix[i] = sum ;
    }

    for ( ll i = 1 ; i <= n ; i++ )
    {
        for ( ll j = 1 ; (j+i) <= n ; j++  )
        {
            ll mini = MAX ;
            for ( ll k = j  ; k < (i+j) ; k++ )
            {
                mini = min( mini , x[j][k] + x[k+1][(i+j)] ) ;
            }
            x[j][(i+j)] = mini + ( prefix[(i+j)] - prefix[j-1] ) ;
            //cout <<  i << "  " << j << "  " << x[j][(i+j)] << "\n" ;
        }
    }
    print(x[1][n]) ;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long[] x = new long[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextLong();
        }
        long sum = 0;
        for (int i = 1; i < n; i++) {
            sum += Math.min(a * (x[i] - x[i - 1]), b);
        }
        System.out.println(sum);
    }

}


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

std::vector<int> calc(long long n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            ret.push_back(n / i);
        }
    }
    return ret;
}

int main() {
    long long n, m;
    std::cin >> n >> m;
    auto v = calc(m);
    std::sort(v.begin(), v.end());
    auto it = std::lower_bound(v.begin(), v.end(), n);
    std::cout << m / *it << std::endl;

    return 0;
}

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

using namespace std;

int n,m;
bool red[100001];
int box[100001];
int main() {
  cin >> n >> m;

  red[1] = true;

  int ans = 0;

  fill(box,box+n+1,1);
  
  for(int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    box[x]--;
    box[y]++;
    if(red[x]) red[y] = true;
    if(red[x] && box[x] == 0) red[x] = false;

    
  }
  for(int i = 1; i <= n; i++) if(red[i]) ans++;

  cout << ans << endl;
}


Measured memory_bytes: 768
import Control.Applicative
import Data.Int

main = do
  [n,a,b,c,d] <- map read . words <$> getLine :: IO [Int64]

  putStrLn $ if (or [a + c*i - d*(n-1-i) <= b && b <= a + d*i - c*(n-1-i) | i <- [0..n-1]]) then "YES" else "NO"


Measured memory_bytes: 1020
<?php
fscanf(STDIN, "%d %d %d %d", $A,$B,$C,$K);

if($K >= $A){
    $ans = $A * 1;
}else{
    $ans = $K * 1;
}

$K = $K - $A;
if($K > 0){
    $K = $K - $B;
    if($K > 0){
        $ans += $K * (-1);
    }    
}

echo $ans;

?>

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int d;
  cin >> d;
  vector<int> c(26);
  int i,j,k;
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(d,vector<int>(26));
  rep(i,d)rep(j,26) cin >> s[i][j]; 
  vector<int> t(d);
  rep(i,d)
  {
    t[i] = i%26;
  }
  vector<int> las(26,0);
  vector<int> rowans(26,0);
  int sums = 0;
  int kans = 0;
  rep(i,d)
  {
    las[t[i]] = i+1;
    sums += s[i][t[i]];
    kans += s[i][t[i]];
    rep(j,26)
    {
      kans -= c[j]*(i+1-las[j]);
      rowans[j] += c[j]*(i+1-las[j]);
    }
  }
  int m = 10000;
  int mwid = 20;
  for(mwid=20;mwid>=1;mwid--)
  {
    rep(i,m)
    {
      int wid = rand()%mwid;
      wid++;
      int tans = 0;
      int tod,q;
      tod = rand()%(d-wid);
      int d1q = t[tod];
      int d2q = t[tod+wid];
      t[tod] = d2q;
      t[tod+wid] = d1q;
      sums -= s[tod][d1q];
      sums -= s[tod+wid][d2q];
      sums += s[tod][d2q];
      sums += s[tod+wid][d1q];
      int rowd1q = rowans[d1q];
      int rowd2q = rowans[d2q];
      rowans[d1q] = 0;
      rowans[d2q] = 0;
      vector<int> klas(26,0);
      rep(j,d)
      {
        klas[t[j]] = j+1;
        rowans[d1q] += c[d1q]*(j+1-klas[d1q]);
        rowans[d2q] += c[d2q]*(j+1-klas[d2q]);
      }
      tans = sums;
      rep(j,26) tans -= rowans[j];
      if(tans >= kans)
      {
        kans = tans;
        las = klas;
      }
      else
      {
        t[tod] = d1q;
        t[tod+wid] = d2q;
        sums += s[tod][d1q];
        sums += s[tod+wid][d2q];
        sums -= s[tod][d2q];
        sums -= s[tod+wid][d1q];
        rowans[d1q] = rowd1q;
        rowans[d2q] = rowd2q;
      }
    } 
  }
  //double tmp = 100.0;
  //double alpha = 0.9999;
  //int inds = 0;
  /*
  rep(i,m)
  {
    int tans = 0;
    int tod,q;
    tod = rand()%d;
    q = rand()%26;
    int bq = t[tod];
    sums -= s[tod][bq];
    sums += s[tod][q];
    int browq = rowans[bq];
    int rowq = rowans[q];
    t[tod] = q; //change
    rowans[q] = 0;
    rowans[bq] = 0;
    rep(j,26)
    {
      las[j] = 0;
    }
    rep(j,d)
    {
      las[t[j]] = j+1;
      rowans[bq] += c[bq]*(j+1-las[bq]);
      rowans[q] += c[q]*(j+1-las[q]);
    }
    tans = sums;
    rep(j,26) tans -= rowans[j];
    //double prob = ((double)rand())/32767.0;
    int dis = kans-tans;
    if(tans >= kans)
    {
      kans = tans;
    }
    else
    {
      rowans[bq] = browq;
      rowans[q] = rowq;
      t[tod] = bq;
    }
    else if(prob <= exp(-(double)dis/(double)tmp))
    {
      kans = tans;
    }
    
    //tmp *= alpha;
    //cout << tmp << endl;
    //if(i%1000 == 0)cout << kans << endl;
  }*/
  rep(i,d)
  {
    cout << t[i]+1 << "\n";
  }
}


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

int main()
{
	int n,t,i,j,k;
	long int a[100001], d[100001];
	cin>>n>>k;

	for(i=0;i<n;i++)
	{
		scanf("%ld", &a[i]);
	}

	long ans = 0;
	d[0] = 0;
	d[1] = abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
		d[i] = INT_MAX;
		for(j=1;j<=k && (i-j)>=0;j++)
		{
			d[i] = min(d[i], d[i-j] + abs(a[i] - a[i-j]));
		}
		
	}
	cout<<d[n-1]<<endl;

	return 0;

}

Measured memory_bytes: 1792
n = int(input())

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(cnt)

    if temp!=1:
        arr.append(1)

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

    return arr

A = []
t = 0
for i in range(50):
    t += i
    A.append(t)
import bisect

B = factorization(n)
total = 0

for i in B:
    if i == A[bisect.bisect(A, i)]:
        total += bisect.bisect(A, i)
    else:
        total += bisect.bisect(A, i)-1
if n == 1:
    print(0)
else:
    print(total)

Measured memory_bytes: 63432
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 9e18
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


int main(void) {
	int a, b;
	cin >> a >> b;
	cout << (b - a) + b << endl;

	return 0;
}

Measured memory_bytes: 384
s=int(input())
s_set = {s}

cnt = 1
while(True):
  cnt += 1
  if s%2 == 0:
    s = s//2
  else:
    s = 3*s+1
    
  if s in s_set:
    break
  else:
    s_set.add(s)
    
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  ll h, w;
  cin >> h >> w;
  if(min(h,w) == 1){
    cout << 1 << endl;
    return 0;
  }
  if(h*w %2 ==0){
    cout << h*w/2 << endl;
  }else{
    cout << (h*w + 1)/2 << endl;
  }
}


Measured memory_bytes: 256
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
# ... 最小側の制約も確認した？
# ... オーバーフローしない？
a, b, c = map(int, input().split())
i = 1
ok = False
while i<=b-1:
    if (a*i-c)%b != 0: i+=1
    else:
        ok = True
        break
if ok: print("YES")
else: print("NO")

Measured memory_bytes: 9324
def print_row(iterable):
    print(''.join(map(lambda x: str(x).rjust(5), iterable)),
          str(sum(iterable)).rjust(5), sep='')


while True:
    n = int(input())
    if n == 0:
        break

    m = []
    for i in range(n):
        m.append(list(map(int, input().split())))

    last = [0 for i in range(n)]
    for row in m:
        print_row(row)
        for (i, e) in enumerate(row):
            last[i] += e

    print_row(last)

Measured memory_bytes: 6724
#include <iostream>
#include<string>
#include<cstdio>
#include<string.h>
#include<vector>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=11000;
//vector <vector<int> > a(1,vector<int >(1));

int main ()
{
    //std::ios::sync_with_stdio(false);
    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0){
        x=-x;
    }
    ll t=x/d;
    if(t>=k){
        cout<<x-k*d<<endl;
    }
    else{
        x-=t*d;
        k-=t;
        if(k%2==0){
            cout<<x<<endl;
        }
        else{
            cout<<d-x<<endl;
        }
    }
    return 0;
}

/*

*/


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


int dp[100010];
int main(){
    int n, k;
    cin >>n >> k;
    vector<int> a(n);
    for(auto &x : a){ cin >> x;}

    for(int i = 0; i <= n; i++) dp[i] = 1000000000;
    dp[1] = 0;


    for(int i = 2; i <= n; i++){
        for(int j = 1; j <= k && i-j >= 1; j++){
            dp[i] = min(dp[i], dp[i-j] + abs(a[i-1] - a[i-j-1]));
        }
    }

    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  rep(i,n){
    cin>>h[i];
  }
  sort(all(h));
  reverse(all(h));
  ll t=0;
  if(k<n){
    REP(i,k,n){
    t+=h[i];
    }
  }
  cout<<t<<endl;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
        k: i64
    }
    let mut ans = min(a, k);
    if k > a + b {
        ans -= k - a - b;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2112
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int ans;
	int n;
	
	while (scanf("%d", &n) == 1){
		ans = 0;
		for (a = 0; a < 10; a++){
			for (b = 0; b < 10; b++){
				for (c = 0; c < 10; c++){
					for (d = 0; d < 10; d++){
						if ( a + b + c + d == n){
							ans++;
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	
	return (0);
}
				
	

Measured memory_bytes: 596
/* Author:bhagatsunny96
         JGEC
	   template__
	lets_code_it_ */
#include <iostream>
using namespace std;
#define ll long long int
int main() 
{
    ll n,m;
    cin>>n;
    ll a[n]={0};
    for(ll i=1;i<n;i++)
    {
        cin>>m;
        a[m-1]++;
    }
    for(ll i=0;i<n;i++)
    cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 5180
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
  ans+=a[0]-x
  a[0]=x
for i in range(n-1):
  if a[i]+a[i+1]>x:
    ans+=(a[i+1]-(x-a[i]))
    a[i+1]=(x-a[i])
print(ans)

Measured memory_bytes: 19992
N = int(input())
S = input()
H = ""
A = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

if(N==0):
  print(S)
else:
  for i in range(len(S)):
    for j in range(26):
      if(S[i]==A[j]):
        H += A[j+N]
  print(H)

Measured memory_bytes: 3060
# coding: utf-8
import itertools
import sys
sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
d=[0]+list(itertools.accumulate(map(int,input().split())))
memo=[[-1 for i in range(401)]for i in range(401)]
def split_slime(l,r):
    if l+1==r:
        return 0
    if memo[l][r]!=-1:
        return memo[l][r]
    mn=10**18
    for i in range(l+1,r):
        cost=(d[i]-d[l])+(d[r]-d[i])+split_slime(l,i)+split_slime(i,r)
        if mn>cost:
            mn=cost
    memo[l][r]=mn
    return memo[l][r]
print(split_slime(0,n))

Measured memory_bytes: 44508
#include<iostream>

using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define NMAX 200
#define MMAX 100
#define INFTY (1<<21)
int n, m, T[NMAX][NMAX], P[MMAX][MMAX];

void valid(int sx, int sy, int &lx, int &ly ){
    int ax = -1, ay;
    rep(y, m) rep(x, m){
	if ( P[x][y] == -1 ) continue;
	if ( P[x][y] != T[sx+x][sy+y] ) return;
	if ( ax == -1 ) {ay = y; ax = x;}
    }
    if ( ay < ly || (ay == ly && ax < lx) ) {ly = sy+ay; lx = sx+ax; }
}

bool rotate(int sx, int sy){
    int tmp[MMAX][MMAX];
    int ly = INFTY, lx;
    rep(r, 4){
	valid(sx, sy, lx, ly);
	rep(y, m) rep(x, m) tmp[x][y] = P[x][y];
	rep(y, m) rep(x, m) P[y][m-x-1] = tmp[x][y];
    }
    if ( ly == INFTY ) return false;
    cout << lx+1 << " " << ly+1 << endl;
    return true;
}

void compute(){
    rep(y, n-m+1) rep(x, n-m+1) if ( rotate(x, y) ) return;
    cout << "NA" << endl;
}

main(){
    while( cin >> n >> m && n ){
	rep(y, n) rep(x, n) cin >> T[x][y];
	rep(y, m) rep(x, m) cin >> P[x][y];
	compute();
    }
}

Measured memory_bytes: 1004
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int UINT;
using namespace std;
//が YAKI から始まるなら Yes を、そうでないなら No を出力せよ。



int main(void) {
    string S;
    cin >> S;
    string chack = S.substr(0, 4);
    if (chack.compare("YAKI") == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
int main(void){
    long long K;
    long long A;
    long long B;
    cin >> K >> A >> B;
    for(int i=1; i<1000; i++){
        int out = K * i;
        if(out < A){
            continue;
        }
        if(B < out){
            cout << "NG" << endl;
            break;
        }
        if(A <= out && out <= B){
            cout << "OK" << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

const int MX = 500000;

char s[MX + 1];
int a[MX];

int main() {
	ignore = scanf("%s", s);
	int n = strlen(s);
	
	for (int cnt = 0, i = 0; i <= n; i++) {
		a[i] = cnt;
		if (s[i] == '<') cnt++;
		else cnt = 0;
	}
	
	for (int cnt = 0, i = n; i >= 0; i--) {
		a[i] = max(a[i], cnt);
		if (i > 0) {
			if (s[i - 1] == '>') cnt++;
			else cnt = 0;
		}
	}
	
	long long ans = accumulate(a, a + n + 1, 0LL);
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 2688
A,B,C,D,E,F=map(int,input().split())

A*=100
B*=100

dp=[-1 for i in range(F+1)]
dp2=[-1 for i in range(F+1)]
dp[0]=0
dp2[0]=0


for i in range(1,len(dp)):
    if i>=C and dp[i-C]>=0 or i>=D and dp[i-D]>=0:
        dp[i]=i
for i in range(1,len(dp)):
    if i>=A and dp2[i-A]>=0 or i>=B and dp2[i-B]>=0:
        dp2[i]=i
#print(dp)
#print(dp2)

noud=0
rep1=0
redp2=0
saidainoudo=E/(E+100)
for p1 in dp:
    if p1!=-1:
        for p2 in dp2:
            if p2>=0:

                satousui=p1+p2
                if 0<satousui<=F:
                    tempnoud=p1/(satousui)

                    if noud<tempnoud<=saidainoudo:
                        #print(p1,p2)
                        noud=tempnoud
                        rep1=p1
                        redp2=satousui
if rep1>0:
    print(redp2,rep1)
else:
    print(A,0)


Measured memory_bytes: 42988
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#define MN 40
#define ll long long
#define INF 2000000000000LL
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Way{int a,b,c,d,tot;ll x;}s[100005];
int col=0,num=0;vector<int> ans;
ll f[MN+5],C[MN+5][MN+5],S[MN+5][MN+5];
ll M(ll a,ll b){return a>INF/b?INF:a*b;}
ll A(ll a,ll b){return min(a+b,INF);}
bool cmp(const Way&A,const Way&B){return A.x*B.tot>B.x*A.tot;} 
void Print(Way x)
{
	for(int i=1;i<=x.a;++i) ans.push_back(col+1);
	for(int i=1;i<=x.b;++i) ans.push_back(col+2);
	for(int i=1;i<=x.c;++i) ans.push_back(col+1);
	for(int i=1;i<=x.d;++i) ans.push_back(col+2);
	col+=2;
}
int main()
{
	for(int i=0;i<=MN;++i) C[i][0]=1;
	for(int i=1;i<=MN;++i)
		for(int j=1;j<=i;++j)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	for(int i=2;i<=MN;++i)
	{
		for(int j=2;j<=i;j+=2) f[i]+=C[i][j];
		s[++num]=(Way){i,0,0,0,i,f[i]};
	}
	for(int i=1;i<=MN;++i) for(int j=1;j<=MN;++j)
		for(int k=1;k<=i&&k<=j;++k) S[i][j]=A(S[i][j],M(C[i][k],C[j][k])); 
	for(int i=1;i<=MN;++i) for(int j=1;j<=MN;++j) for(int k=i;k<=MN;++k) for(int l=j;l<=MN;++l)
		if(i+k<=MN&&j+l<=MN)
		{
			ll res=min(INF,f[i+k]+f[j+l]);res=A(res,M(S[i][k],S[j][l]));
			if(res<=1e12&&res) s[++num]=(Way){i,j,k,l,i+j+k+l,res};
		}
	sort(s+1,s+num+1,cmp);ll n;cin>>n;
	for(int i=1;i<=num;++i) while(n>=s[i].x) n-=s[i].x,Print(s[i]);
	printf("%d\n",ans.size());
	for(int i=0;i<ans.size();++i) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1000000007;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
int main(){
    int a,b;
    cin>>a>>b;
    cout << max({a+b,a-b,a*b}) << endl;
    return 0;
}



Measured memory_bytes: 256
import re
n, a, b, c, d = map(int, input().split())
road = input()
if c < d:
    if re.search('##', road[a:d]) is None:
        print('Yes')
    else:
        print('No')

elif c > d:
    if re.search('##', road[a:]) is None and re.search('\.\.\.', road[b-2:d+1]) is not None:
        print('Yes')
    else:
        print('No')
    


Measured memory_bytes: 3764
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}
class Array
  define_method(:sum){self.inject(:+).to_i} unless method_defined?(:sum)
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
N, M = gets_i_list

k_list = []
M.times do
  l = gets_i_list
  l.shift
  k_list.push l
end
dpp k_list
p_list = gets_i_list
total = 0
[0,1].repeated_permutation(N) do |pattern|
  dpp pattern
  ret = true
  M.times do |i|
    p = p_list[i]
    switches = k_list[i]
    dpp switches
    count = switches.map do |k|
      pattern[k-1]
    end.sum
    dpp count
    unless count % 2 == p
      ret = false
      break
    end
  end
  total += 1 if ret
end

puts total

Measured memory_bytes: 2556
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();

    let mut map = BTreeMap::new();
    let mut sum = 0;
    map.insert(0, 1);

    for a_i in a {
        sum += a_i;
        *map.entry(sum).or_insert(0i64) += 1;
    }

    let ans: i64 = map.iter().map(|(_, v)| (v * (v - 1) / 2)).sum();

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 10492
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    N_MAX = 10000

    bucket = [0]*N_MAX
    for x in range(1, 100):
        for y in range(1, x+1):
            for z in range(1, y+1):
                n = x*x+y*y+z*z+x*y+y*z+z*x
                if n <= N_MAX:
                    if x==y and y==z:
                        bucket[n-1] += 1
                    elif x==y or y==z:
                        bucket[n-1] += 3
                    else:
                        bucket[n-1] += 6
    for f_n in bucket[:N]:
        print(f_n)

if __name__ == "__main__":
    main()



Measured memory_bytes: 9148
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = 0;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return l+r;
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};
int main()
{
	int N,M,T;cin>>N>>M>>T;
	vector<vector<long long int>>dp(20,vector<long long int>(T,-1e9));

	dp[0][0]=0;
	for (int i = 0; i < N; ++i) {
		int a;cin>>a;
		dp[0][a%T]=max(a/T,int(dp[0][a%T]));
	}

	for (int i = 0; i < 19; ++i) {
		for (int x = 0; x < T; ++x) {
			for (int y = 0; y < T; ++y) {
				if (dp[i][x] >= 0 && dp[i][y] >= 0) {
					dp[i+1][(x+y)%T]=max(dp[i+1][(x+y)%T],dp[i][x]+dp[i][y]+(x+y>=T));
				}
			}
		}
	}
	bitset<20>bs(M);
	vector<long long int>ndp(T, -1e9);
	{
		ndp[0]=0;
		for (int i = 0; i < 20; ++i) {
			if (bs[i]) {
				auto next_dp(ndp);
				for (int x = 0; x < T; ++x) {
					for (int y = 0; y < T; ++y) {
						if (ndp[x] >= 0 && dp[i][y] >= 0) {
							next_dp[(x + y) % T] = max(next_dp[(x + y) % T], ndp[x]+ dp[i][y] + (x + y >= T));
						}
					}
				}
				ndp=next_dp;
			}
		}
	}
	for (int i = 0; i < T - 1; ++i) {
		ndp[T-i-2]=max(ndp[T-i-2],ndp[T-i-1]);
	}
	int Q;cin>>Q;
	while (Q--) {
		int A,B;cin>>A>>B;
		bool ok=ndp[A]>=B;
		if(ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3244
using System;

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != null;) {
            var l = line.Split(' ');
            var t500 = double.Parse(l[0]);
            var t1000 = double.Parse(l[1]);

            Console.WriteLine(GetRank(t500, t1000));
        }
    }

    static string GetRank(double t500, double t1000) {
        if (t500 < 35.50 && t1000 < 71.00)
            return "AAA";
        if (t500 < 37.50 && t1000 < 77.00)
            return "AA";
        if (t500 < 40.00 && t1000 < 83.00)
            return "A";
        if (t500 < 43.00 && t1000 < 89.00)
            return "B";
        if (t500 < 50.00 && t1000 < 105.00)
            return "C";
        if (t500 < 55.00 && t1000 < 116.00)
            return "D";
        if (t500 < 70.00 && t1000 < 148.00)
            return "E";
        return "NA";
    }
}

Measured memory_bytes: 9140
using System;
using System.Collections.Generic;

public class Program
{
    static void Main()
    {
        var str = Console.ReadLine();
        var stack = new Stack<char>();
        var count = 0;
        for (int i = 0; i < str.Length; i++)
        {
            stack.Push(str[i]);
            if (stack.Count > 1)
            {
                var a = stack.Pop();
                var b = stack.Pop();
                if (a != b)
                {
                    count += 2;
                }
                else
                {
                    stack.Push(b);
                    stack.Push(a);
                }
            }
        }

        Console.WriteLine(count);
    }
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int H, W, N; cin >> H >> W >> N;
    vector<string> town(H);
    vector<pair<int, int>> path(N+1);
    rep(i, H) {
        cin >> town[i];
        rep(j, W) {
            char c = town[i][j];
            if (c == 'S') {
                path[0] = make_pair(i, j);
            } else if ('1' <= c && c <= '9') {
                path[c-'0'] = make_pair(i, j);
            }
        }
    }

    int ans = 0;

    int dw[4] = { 0, 0,-1, 1 };
    int dh[4] = {-1, 1, 0, 0 };

    rep(i, N) {
        pair<int, int>& s = path[i];    // start
        pair<int, int>& e = path[i+1];  // end
    
        vector<vector<int>> d(H, vector<int>(W, -1));
        queue<pair<int, int>> q;
    
        d[s.first][s.second] = 0;
        q.push(make_pair(s.first, s.second));
        
        while (!q.empty()) {
            pair<int, int> hw = q.front(); q.pop();
            rep(j, 4) {
                int h = hw.first + dh[j];
                int w = hw.second + dw[j];
                if (0 <= h && h < H && 0 <= w && w < W && town[h][w] != 'X' && d[h][w] == -1) {
                    d[h][w] = d[hw.first][hw.second]+1;
                    if (h == e.first && w == e.second) {
                        while (!q.empty()) q.pop();
                        break;
                    }
                    q.push(make_pair(h, w));
                }
            }
        }
        ans += d[e.first][e.second];
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 7840
H,W=map(int,input().split())
grid=[None]*H
skip_i=set()
skip_j=set()
for i in range(H):
  grid[i]=input()
  if grid[i].count(".")==W:
    skip_i.add(i)

for j in range(W):
  count=0
  for i in range(H):
    if grid[i][j]==".":
      count+=1
  if count==H:
    skip_j.add(j)
    
ans=["" for i in range(H-len(skip_i))]

for i in range(len(grid)):
  if i in skip_i:
    continue
  line=""
  for j in range(len(grid[i])):
    if j in skip_j:
      continue
    line+=(grid[i][j])
  print(line)


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    ll X, A, B;
    cin >> X >> A >> B;

    if(A >= B){
        cout << "delicious" << endl;
        return 0;
    }
    if(B-A <= X){
        cout << "safe" << endl;
        return 0;
    }
    cout << "dangerous" << endl;
    return 0;
}

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

string s;
int k;

int main() {
    cin >> s >> k;
    if (s == string(s.length(), s[0])) {
        cout << ((1LL * k * s.length()) >> 1) << endl;
        exit(0);
    }
    long long ans1 = 0, ans2 = 0, ans3 = 0;
    int t1 = 0, t2 = 0;
    for (int i = 0; i < s.length(); i++) {
        int j;
        for (j = i; s[i] == s[j] && j < s.length(); j++);
        j--;
        if (i && j < s.length() - 1) ans1 += ((j - i + 1) >> 1);
        else if (!i) ans2 += ((j - i + 1) >> 1), t1 += j - i + 1;
        else ans3 += ((j - i + 1) >> 1), t2 += j - i + 1;
        i = j;
    }
    if (s[0] ^ s[s.length() - 1]) {
        cout << 1LL * k * (ans1 + ans2 + ans3) << endl;
    } else {
        cout << 1LL * k * ans1 + ans2 + ans3 + 1LL * (k - 1) * ((t1 + t2) >> 1) << endl;
    }
    return 0;
}

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

typedef long long LL;
#define rep(i ,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define arycpy(ary1,ary2,N) memcpy(ary2,ary1,sizeof(int)*N) //ary1:???????????? ary2:????????????
typedef vector<int> vi;


int main(){
	while (1){
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int *num = new int[n];
		for (int i = 0; i < n; i++){
			num[i] = n-i;
		}
		for (int i = 0; i < r; i++){
			int p, c; cin >> p >> c;
			int *ary = new int[n];
			rep(j, n) ary[j] = 0;

			//????????\????????????(c???)?????£??\
			for (int j = 0; j < c; j++){
				ary[j] = num[p - 1 + j];
			}
			
			//??????????????????????????????(p-1???)?????£??\
			for (int j = c; j <c+p-1; j++){
				ary[j] = num[j - c];
			} 

			//rep(j, n) cout << ary[j] << " ";
			//cout << endl;

			for (int j = p+c-1; j < n; j++){
				ary[j] = num[j];
			}
			arycpy(ary, num, n);
			//rep(j, n) cout << num[j] << " ";
			//cout << endl;
		}
		cout << num[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1628
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))


ll f(ll k){
	int ans=0;
	while(k){
		ans++;
		k/=10;
	}
	return ans;
}

ll n;
int main(){
	scanf("%lld",&n);
	ll k=sqrt(n);
	while(1){
		if(n%k==0){
			printf("%lld\n",f(n/k));
			return 0;
		}
		k--;
	}
}

Measured memory_bytes: 128
input()
super_coders_cnt = 0
coders = set()
for r in map(int, input().split()):
    if r >= 3200:
        super_coders_cnt += 1
    else:
        coders.add(r // 400)
print(max(1, len(coders)), len(coders) + super_coders_cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

void kisuu(ll);
void gusuu(ll);

int main(int argc, char const *argv[]) {
  bool flag=0;ll temp=0;
  scanf("%lld",&temp);
  flag=temp%2==0; //偶数なら1,奇数なら0;
  if(flag){
    gusuu(temp);
  }else{
    kisuu(temp);
  }
  return 0;
}

void kisuu(ll leng){
  stack<ll> A;
  queue<ll> B;
  ll temp=0;
  for (ll i = 1; i <= leng; i++) {
    if(i%2!=0){
      scanf("%d",&temp);
      A.push(temp);
    }else{
      scanf("%d",&temp);
      B.push(temp);
    }
  }
  printf("%lld",A.top());
  A.pop();
  while (!A.empty()) {
    printf(" %lld",A.top());
    A.pop();
  }
  while (!B.empty()) {
    printf(" %lld",B.front());
    B.pop();
  }
  printf("\n");
}

void gusuu(ll leng){
  queue<ll> A;stack<ll> B;ll temp=0;
  for (size_t i = 1; i <= leng; i++) {
    if(i%2!=0){
      scanf("%d",&temp);
      A.push(temp);
    }else{
      scanf("%d",&temp);
      B.push(temp);
    }
  }
  printf("%lld",B.top());
  B.pop();
  while (!B.empty()) {
    printf(" %lld",B.top());
    B.pop();
  }
  while (!A.empty()) {
    printf(" %lld",A.front());
    A.pop();
  }
  printf("\n");
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int N;
int K;
vector<int> stones;
vector<int> dp;

inline int calcCost(int i, int j) {
    return abs(stones[i] - stones[j]);
}

int solve(int currStone) {
    if (dp[currStone] != -1) {
        return dp[currStone];
    }

    if (currStone == N) {
        return 0;
    }

    int prev_min = 0x3f3f3f3f;
    for (int i = 1; i <= K; i++) {
        if (currStone <= N-i) {
            prev_min = min(
                prev_min,
                solve(currStone + i) + calcCost(currStone, currStone + i)
            );
        } else {
            break;
        }
    }

    return dp[currStone] = prev_min;
}

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

    stones = vector<int>(N+1);
    dp = vector<int>(N+1, -1);
    for (int i = 1; i <= N; i++) {
        cin >> stones[i];
    }

    cout << solve(1) << endl;

    return 0;
}


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

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

    vector<int> b(N, 0);

    for(int i = 0; i < N; i++) cin >> b[i];

    for(int i = 0; i < N; i++)
    {
        if(b[i] > i+1)
        {
            cout << "-1" << endl;
            return 0;
        }
    }

    vector<int> bb;
    for(int j = 0; j < N; j++)
    {
        bool flag = true;
        for(int i = b.size(); flag and i > 0; i--)
        {
            if(i == b[i-1])
            {
                bb.push_back(b[i-1]);
                b.erase(b.begin()+(i-1));
                flag = false;
            }
        }
    }

    for(int i = N-1; i >= 0; i--)
    {
        cout << bb[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []

for i in range(n):
    x,l = map(int,input().split())
    a.append([x+l, x-l])

a.sort()

ans = 1
hold = a[0]

for i in range(1,n):
    temp = a[i]
    if(hold[0] <= temp[1]):
        hold = temp
        ans += 1
        
    
print(ans)    

Measured memory_bytes: 20104
#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 all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N,Y;
cin >> N >> Y;

for( int x = 0 ; x <= N ; x++) {
    for(int y = 0; x+y <= N;y++) {
        int remain = Y - 10000*x - 5000*y;
        if( remain == 1000*(N-x-y) ) {
            cout << x << " " << y << " " << N-x-y << endl;
            return 0;
        }
    }
}

cout << "-1 -1 -1" << endl;
return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  a=LI()
  b=LI()

  l1=[a[0]]
  for i in range(1,len(a)):
    l1.append(l1[i-1]+a[i])

  b.reverse()
  l2=[b[0]]
  for i in range(1,len(b)):
    l2.append(l2[i-1]+b[i])
  l2.reverse()

  # print(l1)
  # print(l2)

  mx=0
  for i in range(n):
    mx=max(mx,l1[i]+l2[i])

  return mx

print(main())


Measured memory_bytes: 7196
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int int64_t
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define s second
#define f first
#define mp make_pair
typedef std::pair<int,int> pii ;

using namespace std;

const int N=3500;
int n;
double dp[N][N],p[N],ans;

double solve (int a, int b){
    if(dp[a][b]!=-1){
        return dp[a][b];
    }
    if(a==0 && b==0){
        dp[a][b]=1;
        return 1;
    }
    if(b>a){
        dp[a][b]=0;
        return 0;
    }
    dp[a][b]=solve(a-1,b-1)*p[a]+solve(a-1,b)*(double(1)-p[a]);
    return dp[a][b];
}

int32_t main(){
	ibsws(true==false);
	cin>>n;
	for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=-1;
        }
	}
	for(int i=1;i<=n;i++){
        cin>>p[i];
	}
	for(int i=(n+1)/2;i<=n;i++){
        ans+=solve(n,i);
	}
	cout<< setprecision(12) <<ans;
}


Measured memory_bytes: 84352
from collections import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def red(a, b, c):
    if a == 0 and b < 0: b, c = -b, -c
    if a < 0: a, b, c = -a, -b, -c
    g = gcd(a, gcd(abs(b), abs(c)))
    return a // g, b // g, c // g

def main():
    md = 998244353
    n = int(input())
    xy = LLI(n)
    cnt_online = {}
    # 各２点を結ぶ直線をax+by+c=0の(a,b,c)で表し
    # 各直線上にいくつの点があるかカウントする
    for i in range(n):
        x0, y0 = xy[i]
        counted = set()
        for j in range(i):
            x1, y1 = xy[j]
            a = y0 - y1
            b = x1 - x0
            c = -a * x0 - b * y0
            a, b, c = red(a, b, c)
            if (a, b, c) in counted: continue
            counted.add((a, b, c))
            cnt_online.setdefault((a, b, c), 1)
            cnt_online[(a, b, c)] += 1
    # print(cnt_online)
    # 各直線上で、2点以上で多角形ができない点の選び方を数える
    sum_online = 0
    for plot_n in cnt_online.values():
        sum_online += pow(2, plot_n, md) - 1 - plot_n
        sum_online %= md
    # すべての2点以上の選び方から、多角形ができないものを引く
    ans = pow(2, n, md) - 1 - n - sum_online
    print(ans % md)

main()


Measured memory_bytes: 7488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n,m,i;
    string s;
    cin>>n>>s>>m;
    for(i=0;i<n;i++){
        if(s[i]==s[m-1])
            cout<<s[i];
        else cout<<"*";
    }
    cout<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  ff     first
#define  ss     second
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  ps(x,y) fixed<<setprecision(y)<<x
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000000;
const ll MAX_N = 1e6 + 2;

int main() {
    IOS;
    int n,zero_cnt=0; cin>>n;
    vi v(n);
    map<int,int>mp;
    rep(i,0,n){
        cin>>v[i];
        if(v[i]==1) zero_cnt++;
        mp[v[i]]++;
    }
    int cnt=0;
    rep(i,0,n){
        int num = v[i],flag =1;
        for(int j=2;j*j<=num;j++){
            if(num % j==0){
                if(mp[j]){
                    flag=0;
                    break;
                }
                if(num/j != j){
                    if(mp[num / j]){
                        flag=0;
                        break;
                    }
                }
            }
        }
        if(flag && mp[v[i]]==1) cnt++;
    }
    
    if(zero_cnt==1) cout << "1";
    else if(zero_cnt>1) cout << "0";
    else cout << cnt;
    
    return 0;
}

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

ll gcd(ll x, ll y)
{
    return y ? gcd(y, x % y) : x;
}

vector<pair<ll, int>> factorize(ll n)
{
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i)
    {
        //割り切れない時は次のループ
        if (n % i)
            continue;
        //resの初期化？
        res.emplace_back(i, 0);
        while (n % i == 0)
        {
            //割り切れる場合は n = n/i
            //back().second++ はresの第2変数をインクリメント?
            n /= i;
            res.back().second++;
        }
    }
    //nか素数の場合素因数の数は1
    if (n != 1)
        res.emplace_back(n, 1);
    return res;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a=int(input())
if a==2:
  print(a)
else:
  sosuu=1
  a=a-1
  while sosuu==1:
    a+=1
    b=2
    while a!=b:
      if a%b==0:
        sosuu=1
        break
      else:
        b+=1
        sosuu=0
  print(a)

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


int main(){
  int  K, count;
  cin >> K;
  int a = 7;
  count = 1;
  for(int i =0; i < 1000000; i++){
    if (i == 999999){
      cout << -1 << endl;
    }
    else if(a%K ==0){
      cout << count <<endl; 
      break;
    }
    else{
      a = ( (a%K)*10 ) + 7;
      count++;
    }
    
  }
  
  

   
}

Measured memory_bytes: 3616
n=int(input())
s=input()
p=s.count('R')*s.count('G')*s.count('B')

for i in range(0,n-2):
    for j in range(1,int((n-i)/2)+1):
        if i+j*2>=n:
            break
        if s[i]!=s[i+j] and s[i]!=s[i+j*2] and s[i+j*2]!=s[i+j]:
            p-=1
print(p)
        

Measured memory_bytes: 9192