akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

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

    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    vector<vector<vector<ll>>> dp(
        n + 1, vector<vector<ll>>(n + 1, vector<ll>(2500 + 1)));

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

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= 2500; k++) {
                dp[i][j][k] = dp[i - 1][j][k];
                if (k - x[i - 1] >= 0) {
                    dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;

    return 0;
}


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

#define ll long long
//#define sz 1000

void solve()
{
    ll n, k;
    cin >> n >> k;

    ll arr[n+3];
    for(int i=1; i<=n; i++) cin >> arr[i];

    vector<ll> v;
    v.push_back(1);

    ll x = arr[1];
    map<int, int> mp;
    mp[1]++;
    while(1)
    {
        mp[x]++;
        if(mp[x] > 1) break;
        v.push_back(x);
        x = arr[x];
    }
    int rep = 0;
    for(int i=v.size()-1; v[i]!=x; i--)
    {
        rep++;
    }
    if(k <v.size())
        cout << v[k] << endl;
    else
    {
        rep++;
        int sz = v.size();
        x = sz - rep;
        ll idx = (k-x) % rep;
        cout << v[idx+x] << endl;
    }

}

int main()
{
    int tc = 1;
    //cin >> tc;
    while(tc--)
    {
        solve();
    }

    return 0;
}




Measured memory_bytes: 15536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define rep(i,N) for(int i=0;i<N;i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1e9+7;

int main() {
  ll X, A, B;
  cin >> X >> A >> B;
  ll answer = (X - A) % B;
  
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define TEST 0
int par[100001];
bool marked[100001];
int find_marked(int id)
{
    if(marked[id])return id;
    return find_marked(par[id]);
}
int main(void)
{
    int n,q;
    while(scanf("%d%d",&n,&q)==2 && (n!=0 || q != 0))
    {
        par[1]=0;
        marked[1]=true;
        long long int sum=0;
        for(int i=0;i<n-1;i++)
        {
            scanf("%d",par + i+2);
            marked[i+2]=false;
        }
        for(int j=0;j<q;j++)
        {
            char str[8];
            int num;
            scanf("\n%[QM]%d",str,&num);
#if TEST
            printf("%c:%d\n",str[0],num);
#endif
            switch(str[0])
            {
            case 'Q':
                    sum+=find_marked(num);
                    break;
            case 'M':
                    marked[num]=true;
                    break;
            }
        }
        printf("%lld\n",sum);
    }
    return 0;
}

Measured memory_bytes: 3052
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  int N;
  cin >> N;
  VI T(N + 1);
  int sum = 0;
  NREP(i, N) {
    cin >> T[i];
    sum += T[i];
  }

  int M;
  cin >> M;
  REP(i, M) {
    int P, X;
    cin >> P >> X;
    cout << sum - T[P] + X << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,m,tmp;
    scanf("%d %d",&n,&m);
    int** A = new int*[n];
    for(int i = 0; i < n; i++) A[i] = new int[m];
    int b[m];
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&tmp);
            A[i][j] = tmp;
        }
    }
    for(int i = 0; i < m; i++){
        scanf("%d",&tmp);
        b[i] = tmp;
    }
    long long int sum;
    for(int i = 0; i < n; i++){
        sum = 0;
        for(int j = 0; j < m; j++){
            sum += A[i][j] * b[j];
        }
        printf("%lld\n",sum);
    }
 
    for(int i = 0; i < n; i++){
        delete[] A[i];
    }
    delete A;
}


Measured memory_bytes: 2716
def calc(a_cur, a_prev, vec, ans):
    if a_cur == a_prev:
        pass
    elif a_cur > a_prev:
        if vec == -1:
            ans += 1
            vec = 0
        else:
            vec = 1

    elif a_cur < a_prev:
        if vec == 1:
            ans += 1
            vec = 0
        else:
            vec = -1

    return a_cur, vec, ans

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 0
    vec = 0
    a_prev = a[0]
    for i in range(1, n):
        a_cur = a[i]
        a_prev, vec, ans = calc(a_cur, a_prev, vec, ans)

    print(ans+1)

main()

Measured memory_bytes: 14252
from itertools import combinations_with_replacement
def f(N):
    global table
    for x, y, z in combinations_with_replacement(range(1, 100), 3):
        n = x**2+y**2+z**2+x*y+y*z+z*x
        if n>N:
            continue
        if x==y==z:
            table[n] += 1
        elif x==y or y==z or z==x:
            table[n] += 3
        else:
            table[n] += 6
N = int(input())
table = [0 for _ in range(N+1)]
f(N)
for n in range(1, N+1):
    print(table[n])

Measured memory_bytes: 9244
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        // 主処理
        int min = n / k;
        int max = (int) Math.ceil((double) n / k);
        int result = max - min;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ZERO(a) memset(a,0,sizeof(a))

int f[100][100];
int m,n;
int ans;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};

bool ng(int x, int y) {
    return x<0 or m<=x or y<0 or n<=y;
}

void dfs(int x, int y, int d) {
    ans = max(ans, d);
    rep(i,4) {
        int nx = x+dx[i], ny = y+dy[i];
        if(!ng(nx,ny) and f[ny][nx] == 1) {
            f[ny][nx] = 0;
            dfs(nx,ny,d+1);
            f[ny][nx] = 1;
        }
    }
    return ;
}

void solve() {
    ans = 0;
    rep(y,n) rep(x,m) {
        if(f[y][x] == 0) continue;
        f[y][x] = 0;
        dfs(x,y,1);
        f[y][x] = 1;
    }
    cout << ans << "\n";
    return ;
}

int main() {
    while(cin>>m>>n && m) {
        ZERO(f);
        rep(y,n) rep(x,m) cin >> f[y][x];
        solve();
    }

    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
//typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

ll kaizyo(int n,ll sum){
    if(n==0)return sum;
    return kaizyo(n-1,sum*2);
}

int main(){
    int n,p;
    cin>>n>>p;
    int odd=0;
    rep(i,0,n){
        int x; cin>>x;
        if(x%2==1)odd++;
    }
    
    if(odd==0){
        if(p==1)cout<<0<<endl;
        else cout<<kaizyo(n,1)<<endl;
    }else cout<<kaizyo(n-1,1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    long double ans=0;
    rep(0,i,n){
        long double x;
        string u;
        cin>>x>>u;
        if(u=="JPY"){
            ans+=x;
        }else{
            ans+=x*380000.;
        }
    }
    cout<<fixed<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://abc061.contest.atcoder.jp/tasks/abc061_b

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    N, M = map(int, input().split())

    roads = [0] * (N+1)
    for _ in range(M):
        f, t = map(int, input().split())
        roads[f] += 1
        roads[t] += 1

    print('\n'.join(map(str, roads[1:])))


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main() {
  int A;
  int ans=0;
  cin >> A;
  for(int i=1; i<=A; ++i){
      if((to_string(i).size())%2 == 1) ++ans;
  }
  cout << ans << endl;
}

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


int main(){
	int N;
	cin >> N;
	for(int i = 1; i < 10; i++)
		for(int j = 1; j < 10; j++)
			if(i*j == N){
				cout << "Yes" << endl;return 0;
			}

	cout << "No" << endl;

}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  rep(i, A, B + 1){
    if(i - A < K || B - i < K){
      cout << i << endl;
    }
  }
  return 0;
}


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

int main () {
  int64_t a, b, x; cin >> a >> b >> x;
  
  int64_t ans =0;
  if (a ==0) ans = b/x +1;
  else ans = b/x - (a-1)/x;
  cout << ans  << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAX 100000
#define NIL -1

struct Node {int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void Depth(int i, int m){
  if(i == NIL) return;
  D[i] = m;
  Depth(T[i].left, m + 1);
  Depth(T[i].right, m + 1);
}

int Height(int i){
  int h1 = 0, h2 = 0;
  if( T[i].left != NIL )
    h1 = Height(T[i].left) + 1;

  if( T[i].right != NIL)
    h2 = Height(T[i].right) + 1;

  return H[i]  = (h1 > h2 ? h1 : h2 );
}

int Sibling(int i){
  if( T[i].parent == NIL) return NIL;
  if(T[T[i].parent].left != i && T[T[i].parent].left != NIL)
    return T[T[i].parent].left;

   if(T[T[i].parent].right != i && T[T[i].parent].right != NIL)
    return T[T[i].parent].right;

   return NIL;
}

void print(int i){
  printf("node %d: ",i);
  printf("parent = %d, ",T[i].parent);
  printf("sibling = %d, ",Sibling(i));
  int deg = 0;
  if(T[i].left != NIL ) deg++;
  if(T[i].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[i]);
  printf("height = %d, ",H[i]);

  if( T[i].parent == NIL){
    printf("root\n");
  }else if (T[i].left == NIL && T[i].right == NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root = 0;
  scanf("%d",&n);

  for(int k =0; k < n; k++) T[k].parent = NIL;

  for(int k = 0; k < n; k++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if( l != NIL) T[l].parent = v;
    if( r != NIL) T[r].parent = v;
  }
  for(int k = 0; k < n; k++) if(T[k].parent == NIL) root = k;
  
  Depth(root, 0);
  Height(root);
  for( int k = 0; k < n; k++) print(k);
  
  

  return 0;
}
  



Measured memory_bytes: 2708
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>X(M),dif(M-1);
    for (int i = 0; i < M; i++) {
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    for (int i = 0; i < M-1; i++) {
        dif[i] = X[i + 1] - X[i];
    }
    sort(dif.rbegin(), dif.rend());

    int ans = X[M - 1] - X[0];
    for (int i = 0; i < min(N - 1, M - 1); i++) {
        ans -= dif[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

isOk :: Int -> Bool
isOk num 
        | num `mod` 2 == 1 = True
        | num `mod` 5 == 0 = True
        | num `mod` 3 == 0 = True
        | otherwise = False

main = do
    _ <- readInt
    ints <- readInts
    putStrLn $ if all isOk ints then "APPROVED" else "DENIED"


Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <array>
using namespace std;
typedef long long ll;

int uf[100000][2]={};

int main(int argc,char const* argv[])
{
  int n,k;
  cin >> n >> k;
  vector<int> c(k,0);
  int ans=0;
  for(int i=0;i<k;i++)
    {
      cin >> c[i];
    }
  bool clear=false;
  for(int i=n;i<10*n;i++)
    {
      clear=true;
      string s=to_string(i);
      for(int j=0;j<k;j++)
	{
	  for(int h=0;h<s.size();h++)
	    {
	      char judge='0'+c[j];
	      if(s[h]==judge) clear=false;
	    }
	}
      if(clear==true)
	{
	  ans=i;
	  break;
	}
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
long ans=0,m=1e9+7;
main()
{
    cin>>N;
    long long s=0;
    for(int i=0;i<N;++i){
        long a;
        cin>>a;
        ans=(ans+a*s)%m;
        s=(s+a)%m;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;

    int num_lr = 0;
    rep(i, n - 1) {
        if (s[i] == 'R' and s[i + 1] == 'L') num_lr++;
    }
    int x = num_lr;
    int y = num_lr - 1;
    y += (s[0] == 'R' ? 0 : 1);
    y += (s[n - 1] == 'L' ? 0 : 1);
    x -= k;
    y -= k;
    if (x <= 0 and y <= 0) {
        cout << n - 1 << endl;
    } else {
        cout << n - 1 - x - y << endl;
    }
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

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

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  string str = in<string>();
  int n = str.size();

  function<bool(int,int)> func =
    [&](int l,int r){
      if(l>=r)return true;
      static vvector<int> dp(n+1,vector<int>(n+1,0));
      int &res = dp[l][r];
      if(res)return res==2?true:false;
      if(str[l]!='m'){
        res = 1;
        return false;
      }
      if(str[r]!='w'){
        res = 1;
        return false;
      }
      for(int i=l+1;i<r;++i){
        if(str[i]!='e')continue;
        if(func(l+1,i-1) and func(i+1,r-1)){
          res = 2;
          return true;
        }
      }
      res = 1;
      return false;
    };

  cout << (func(0,n-1)?"Cat":"Rabbit") << endl;

  return 0;
}



Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	ll k , n ;
	cin>> k >> n ;
	ll arr[n];
	for(ll i=0;i< n ;i++)cin>>arr[i];
	vector<ll> vec(3*n);
	for(ll i=1 ;i< n ; i++){
		vec[i-1]=(arr[i]-arr[i-1]);
		vec[n+i-1]=arr[i]-arr[i-1];
		vec[2*n+i-1]=arr[i]-arr[i-1];
	}
	ll ps = k-arr[n-1]+arr[0];
	vec[n-1]=ps ;
	vec[2*n-1]=ps;
	vec[3*n-1]=ps;
	for(ll i=1 ;i<3*n ; i++){
		vec[i]=vec[i-1]+vec[i];
	}
	ll mn = inf;
	for(ll i=n ; i< 2*n ; i++){
		mn= min(vec[i+n-1]-vec[i],mn);
		mn = min(mn , vec[i]-vec[i-n+1]);
	}
	cout<<mn<<endl;
	
	// ll ans = 0 ;
	

	return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 26636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int n,k;
    cin >> n >>k;
    vector<int> l(n);
    rep(i,n) cin>>l.at(i);
    sort(l.begin(), l.end(), greater<int>());
    int sum=0;
    rep(i,k)sum+=l.at(i);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int keta(int n) {
  int ten = 1000000;
  int ans = 0;
  while(ten>0) {
    ans += n/ten;
    n %= ten;
    ten /= 10;
  }
  return ans;
}

int main() {
  int N;
  cin>>N;
  int ans1=1, ans2=N-1;
  int tmpans = keta(ans1)+keta(ans2);
  for(int i=1;i<N;++i) {
    if(tmpans>keta(i)+keta(N-i)) {
      ans1 = i;
      ans2 = N-i;
      tmpans = keta(i)+keta(N-i);
    }
  }
  cout<<keta(ans1)+keta(ans2)<<endl;
}



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

int main()
{ 
  int n ;
  cin >> n ;
  vector<int> a(n) ;
  vector<int> b(n) ;
  for(int i = 0 ; i < n ; i++)
  {
    cin >> a.at(i) ;
  } 
  for(int i = 0 ; i < n ; i++)
  {
    cin >> b.at(i) ;
  }
  reverse(b.begin(), b.end()) ;

  vector<int> da(n);
  vector<int> db(n);
  int calcu = 0 ;
  for(int i = 0 ; i < n ; i++)
  {
    calcu += a.at(i) ;
    da.at(i) = calcu ;
  }
  calcu = 0 ;
  for(int i = 0 ; i < n ; i++)
  {
    calcu += b.at(i) ;
    db.at(i) = calcu ;
  }
  reverse(db.begin(), db.end()) ;

  vector<int> answer(n) ;
  for(int i = 0 ; i < n ; i++)
  {
    answer.at(i) = da.at(i) + db.at(i) ;
  }
  sort(answer.begin(), answer.end()) ;
  reverse(answer.begin(), answer.end()) ;

  cout << answer.at(0) << endl ; 
}


Measured memory_bytes: 256
import * as fs from 'fs';

//in
// 6 4 3
//out
// 1
const main = (inp: string) => {
    const [a, b, c]: number[] = inp.split(' ').map(Number);
    let ans: number = c - (a - b);
    if (ans < 0) {
        ans = 0;
    }
    console.log(ans);
};


main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7500
import java.util.Scanner;
public class Main{
    private static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        String s = scanner.next();
        int charCount = 0, flag = 0;
        for(char c = 'a'; c<='z'; c++){
            for(int i=0; i<s.length(); i++){
                if(c == s.charAt(i))
                    charCount++;
            }
            if(charCount % 2 != 0){
                flag = 1;
                break;
            }
        }
        if(flag == 1)
            System.out.println("No");
        else
            System.out.println("Yes");
    }
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

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

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

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


int main() {
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind uf(N);
  for(int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
  }
  UnionFind uf2(N);
  for(int i = 0; i < L; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf2.unite(a, b);
  }
  vector< int > belong[200000];
  for(int i = 0; i < N; i++) {
    belong[uf.find(i)].emplace_back(i);
  }
  map< int, int > mp[200000];
  for(int i = 0; i < N; i++) {
    for(auto &p : belong[i]) mp[i][uf2.find(p)]++;
  }
  for(int i = 0; i < N; i++) {
    if(i) cout << " ";
    cout << mp[uf.find(i)][uf2.find(i)];
  }
  cout << endl;
}





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

int main(){
  double A,B;
  cin>>A>>B;
  for (int p=0;p<1300;p++){
    if((floor(p*0.08)==A)&&(floor(p*0.1)==B)){
      cout<<p<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

  
  


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const long long INF = LLONG_MAX / 2;

int n;
vector<long long> x, y;
vector<int> dx, dy;

double solve(double t)
{
    double xmin = DBL_MAX;
    double ymin = DBL_MAX;
    double xmax = -DBL_MAX;
    double ymax = -DBL_MAX;
    for(int i=0; i<n; ++i){
        double x2 = x[i] + dx[i] * t;
        double y2 = y[i] + dy[i] * t;
        xmin = min(xmin, x2);
        xmax = max(xmax, x2);
        ymin = min(ymin, y2);
        ymax = max(ymax, y2);
    }
    return (xmax - xmin) * (ymax - ymin);
}

int main()
{
    cin >> n;
    x.assign(n, 0);
    y.assign(n, 0);
    dx.assign(n, 0);
    dy.assign(n, 0);
    for(int i=0; i<n; ++i){
        char d;
        cin >> x[i] >> y[i] >> d;
        if(d == 'R')
            ++ dx[i];
        else if(d == 'L')
            -- dx[i];
        else if(d == 'U')
            ++ dy[i];
        else
            -- dy[i];
    }

    double left = 0.0;
    double right = 1.0e+10;
    for(int i=0; i<200; ++i){
        double mid1 = (left * 2.0 + right) / 3.0;
        double mid2 = (left + right * 2.0) / 3.0;
        if(solve(mid1) < solve(mid2))
            right = mid2;
        else
            left = mid1;
    }
    printf("%.10f\n", solve(left));

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
    vector<pair<int,int>> v1;
    int n,m;
    cin>>n>>m;
    for(int i =0;i<n;i++)
    {
        int h;
        cin>>h;
        v1.push_back(pair<int,int>(h,1));
    }
    for(int i =0 ; i<m;i++)
    {
        int h,j;
        cin>>h>>j;
        if(v1[h-1].first>v1[j-1].first)
        {
            v1[j-1].second=0;
        }
        else if(v1[h-1].first==v1[j-1].first)
        {
            v1[j-1].second=0;
            v1[h-1].second=0;
        }
        else
            {
                v1[h-1].second=0;
            }
    }
    int sum=0;
    for(auto &m:v1)
    {
        if(m.second==1)
            sum++;
    }
    cout<<sum;
}

Measured memory_bytes: 4328
using System;


public class hello
{
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // ??¶??°????????????????????????

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                return false;
            }
        }
        return true;
    }
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            var p = int.Parse(Console.ReadLine().Trim());
            if (IsPrime(p)) count += 1;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {

            int dif = i ^ j;
            for (int k = 0; ; ++k) {
                if ((dif >> k) & 1) {
                    cout << k + 1 << ' ';
                    break;
                }   
            }   

        }   
        cout << endl;
    }   

}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
using namespace std;
int b[136],a[136];
int main()
{
	int n,m,c,i,j,k;
	cin>>n>>m>>c;
	for(i=1;i<=m;i++)
	{
		cin>>b[i];
	}
	int ans=0;
	for(i=1;i<=n;i++)
	{
		int s=0;
		for(j=1;j<=m;j++)
		{
			cin>>a[j];
			s+=a[j]*b[j];
		}
		if(s+c>0) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner $ = new Scanner(System.in);
		int N = $.nextInt(), K = $.nextInt();
		String S = $.next();
		System.out.print(S.substring(0, K - 1));
		if (S.substring(K - 1, K).equals("A")) System.out.print("a");
		else if (S.substring(K - 1, K).equals("B")) System.out.print("b");
		else System.out.print("c");
		System.out.println(S.substring(K, N));
		/*
		3 1 ABC -> aBC
		4 3 CABA -> CAbA
		*/
	}
}


Measured memory_bytes: 21844
N,K=map(int, input().split())
ls=[]
for i in range(N):
    ls.append(int(input()))
ls2=sorted(ls)
min=float("inf")
for i in range(N-K+1):
    if min > ls2[i+K-1] - ls2[i]:
        min=ls2[i+K-1] - ls2[i]
print(min)


Measured memory_bytes: 8280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
vl v[10005];
vl vv;
ll deg[10005];
ll level[10005];
void dfs(ll curr , ll par)
{
    if(par == -1 ) level[curr] = 0 ;
    level[curr] = 1+level[par] ;
    for(auto &child : v[curr]){
        if(child == par) con ;
        dfs(child , curr) ;
    }

}
int main()
{
    ios;
    ll n ;
    cin >> n ;
    forn(i ,1 , n-1){
      ll x, y ;
      cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
      deg[x]++;
      deg[y]++;
    }
    forn(i , 1 , n ){
      ll x;
      cin >> x;
      vv.pb(x);
    }
    dfs(1 , -1 ) ;
    vector<pll > nodes ;
    forn(i ,1 , n){
       nodes.pb({level[i] , i}) ;
    }
    sort(all(nodes));
    vl newnode;
    for(auto &x : nodes){
        newnode.pb(x.se);
    }
    sort(vv.be , vv.en , greater<ll>());
    unordered_map<ll , ll > mpp ;
    mpp.cl ;
    forn( i , 0 , n-1){
       mpp[newnode[i]] = vv[i] ;
    }
    vl ans ;
    forn(i , 1 , n){
       ans.pb(mpp[i]);
    }
    ll sum = acc(ans) ;
    sum = sum - mpp[1] ;
    cout << sum << el ;
    forn(i , 0 , n-1){
       cout << ans[i] << " " ;
    }
    cout << el ;
    ro ;
}































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

template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}
typedef pair<long long, long long> P;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

void solve(int w, int h){
	vector<string> v;
	readVector(h, v);
	int x = 0, y = 0, ans = 0;
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j)
			if(v[i][j] == '@')
				x = i, y = j;
	queue<P> q;
	q.push(P(x, y));
	v[x][y] = ' ';
	++ans;
	while(!q.empty()){
		P p = q.front();
		q.pop();
		int nx = p.first;
		int ny = p.second;
		for(int i=0; i<4; ++i){
			int a = nx + dx[i];
			int b = ny + dy[i];
			if(0<=a && 0<=b && a<h && b<w && v[a][b] == '.'){
				q.push(P(a, b));
				v[a][b] = ' ';
				++ans;
			}
		}
	}
	cout << ans << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int w, h;
		cin >> w >> h;
		if(w == 0 && h == 0) return 0;
		solve(w, h);
	}
}


Measured memory_bytes: 3144
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static int[] nab;
    static int[] hs;
    static void Solve()
    {
        nab = Input.ar;
        hs = Input.ar1D(nab[0]);
        WriteLine(BinarySearch());
    }
    static long BinarySearch()
    {
        var ok = (long)int.MaxValue;
        var ng = 0L;
        while (Abs(ok - ng) > 1)
        {
            var mid = (ok + ng) / 2;
            if (isOk(mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    static bool isOk(long mid)
    {
        var ct = 0L;
        for (var i = 0; i < nab[0]; i++)
            ct += Max(0, (hs[i] - mid * nab[2] + nab[1] - nab[2] - 1) / (nab[1] - nab[2]));
        return ct <= mid;
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

int main() {
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for (int i=0; i<=K; ++i) {
        for (int j=0; j<=i; ++j) {
            int k = S - i - j;
            if ((k <= K) && (k >= 0) && (k <= j)) {
                if ((i==j) && (j==k)) ++ans;
                else if ((i==j) || (j==k)) ans += 3;
                else ans += 6;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
from fractions import gcd
def gen(x):
    i = 1
    while i * i <= x:
        yield i
        i += 1

def main():
    a,b = map(int,input().split())
    g = gcd(a,b)
    gl = []
    for i in gen(g):
        if (g % i) == 0:
            gl.append(i)
            gl.append(g // i)
    gl =set(gl)
    p = []
    for i in gl:
        b = True
        for j in gen(i):
            if j == 1:continue
            if (i % j) == 0:
                b = False
                break
        if b:
            p.append(i)
    ans = 0
    for i in p:
        if i in p:ans+=1

    
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 5944
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

state = 0
s = deque(input().rstrip())
q = int(input())
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        state ^= 1
    else:
        f = int(query[1]); c = query[2]
        if state == 0:
            if f == 1:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == 1:
                s.append(c)
            else:
                s.appendleft(c)

if state == 0:
    ans = "".join([item for item in s])
else:
    s.reverse()
    ans = "".join([item for item in s])

print(ans)

Measured memory_bytes: 8600
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n, m;
vector<int> g[maxn];
vector<int> path;
int used[maxn];

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
    used[i] = false;
  }
  path.clear();
  for (int i = 0; i < m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
    if (!i) {
      path.push_back(v);
      path.push_back(u);
      used[v] = true;
      used[u] = true;
    }
  }
  return true;
}

void solve() {
  for (int it = 0; it < 2; it++) {
    while (true) {
      int v = path.back();
      int nv = -1;
      for (int i = 0; i < sz(g[v]); i++) {
        int u = g[v][i];
        if (!used[u]) {
          nv = u;
          break;
        }
      }
      if (nv == -1) {
        break;
      }
      path.push_back(nv);
      used[nv] = true;
    }
    reverse(path.begin(), path.end());
  }
  printf("%d\n", sz(path));
  for (int i = 0; i < sz(path); i++) {
    printf("%d ", path[i] + 1);
  }
  printf("\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 7160
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
void chstrrev(char *p)
{
	int loop=strlen(p)/2;
	char *R=p+strlen(p)-1,ch;
	while(loop--)
	{
		ch=*p;
		*p=*R;
		*R=ch;
		p++;
		R--;
	}
}
int main()
{
	char s[22]={0};
	cin>>s;
	chstrrev(s);
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
  ll N,M;
  cin >> N >> M;
  UnionFind UF(N);
  vector<vector<int>> A(M,vector<int>(3));
  REP(i, M){
    REP(j, 3){
      cin >> A.at(i).at(j);
    }
    A[i][0]--;
    A[i][1]--;
    UF.merge(A[i][0],A[i][1]);
  }
  
  set<int> st;
  REP(i,N){
    if(!st.count(UF.root(i))){
      st.insert(UF.root(i));
    }
  }

  cout << st.size() << endl;
}

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

int main() {
    int d,t,s; cin >> d >> t >> s;
    if (d <= s*t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
import std.stdio;


void main(){
	int n, a;
	double h;
	string[7] freq = "";
	readf("%d\n", &n);
	for (int i = 0; i < n; i++) {
		readf("%s\n", &h);
		if (h < 165.0) a = 1;
		else if (h >= 185.0) a = 6;
		else a = cast(int)((h - 165.0) / 5) + 2;
		freq[a] ~= "*";
	}
	foreach (i; 1..7) writeln(i, ":", freq[i]);
}

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

int main(int argc, char **argv)
{
	ll n, m;
	cin >> n >> m;
	vector<ll> k(m), p(m);
	ll s[20][20];
	memset(s, 0, sizeof(s));
	for (int i = 0; i < m; ++i)
	{
		cin >> k[i];
		for (int j = 0; j < k[i]; ++j)
		{
			int a; cin >> a;
			s[i][j] = a-1;
		}
	}
	for (int i = 0; i < m; ++i)
		cin >> p[i];

	ll res{0};
	for (ll bits = 0; bits < (1<<n); ++bits)
	{
		bool flag{true};
		for (ll i = 0; i < m; ++i)
		{
			ll bit_c{0};
			for (ll j = 0; j < k[i]; ++j)
			{
				int nth = s[i][j];
				if (bits & (1<<nth)) ++bit_c;
			}

			if (bit_c % 2 != p[i])
				flag = false;
		}
		if (flag)
		{
			++res;
		}
	}
	std::cout << res << std::endl;
	
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int n = S.size();
  if (n % 2) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < n; i += 2) {
    if (S[i] == 'h' && S[i + 1] == 'i') {
      ;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256