akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int mod = 1000000007;
char s[200001];
long long dp[200001][2];
long long dp2[200001][2];

int main() {
    int n, m, c, i, j;
    long long ans = 0;
    vector <int> v, w;
    
    scanf("%d %d", &n, &m);
    scanf("%s", s);
    
    for (i = 0; i < m; ) {
        for (j = i; j < m; j++) {
            if (s[i] != s[j]) break;
        }
        
        v.push_back(j - i);
        i = j;
    }
    v.back() = 1e9;
    
    c = v[0] + 1;
    for (i = 0; i < v.size(); i += 2) {
        if (v[i] % 2 == 1) c = min(c, v[i]);
    }
    
    dp[0][1] = 1;
    dp[1][1] = mod - 1;
    dp2[0][1] = 1;
    dp2[1][1] = mod - 1;
    
    for (i = 0; i <= n; i++) {
        if (i > 0) {
            for (j = 0; j < 2; j++) {
                dp[i][j] += dp[i - 1][j];
                if (dp[i][j] >= mod) dp[i][j] -= mod;
                
                dp2[i][j] += dp2[i - 1][j];
                if (dp2[i][j] >= mod) dp2[i][j] -= mod;
            }
        }
        
        if (i == 0) {
            dp[1][0] = 2;
            for (j = 2; j <= c && j <= n; j++) dp[j][0] = 1;
            if (c + 1 <= n) dp[c + 1][0] = mod - (c + 1);
        } else if (i % 2 == 1) {
            if (i + 1 <= n) {
                dp[i + 1][1] += dp[i][0];
                if (dp[i + 1][1] >= mod) dp[i + 1][1] -= mod;
            }
            
            if (i + 2 <= n) {
                dp[i + 2][1] -= dp[i][0];
                if (dp[i + 2][1] < 0) dp[i + 2][1] += mod;
            }
        } else {
            if (i + 1 <= n) {
                dp[i + 1][0] += dp[i][1];
                if (dp[i + 1][0] >= mod) dp[i + 1][0] -= mod;
            }
            
            if (i + c + 1 <= n) {
                dp[i + c + 1][0] -= dp[i][1];
                if (dp[i + c + 1][0] < 0) dp[i + c + 1][0] += mod;
            }
        }
        
        if (i == 0) {
            dp2[1][0] = 2;
            for (j = 2; j <= c && j <= n; j++) dp2[j][0] = 1;
            if (c + 1 <= n) dp2[c + 1][0] = mod - (c + 1);
        } else {
            if (i + 1 <= n) {
                dp2[i + 1][1] += dp2[i][0];
                if (dp2[i + 1][1] >= mod) dp2[i + 1][1] -= mod;
            }
            
            if (i + 2 <= n) {
                dp2[i + 2][1] -= dp2[i][0];
                if (dp2[i + 2][1] < 0) dp2[i + 2][1] += mod;
            }
            
            if (i + 1 <= n) {
                dp2[i + 1][0] += dp2[i][1];
                if (dp2[i + 1][0] >= mod) dp2[i + 1][0] -= mod;
            }
            
            if (i + c + 1 <= n) {
                dp2[i + c + 1][0] -= dp2[i][1];
                if (dp2[i + c + 1][0] < 0) dp2[i + c + 1][0] += mod;
            }
        }
    }
        
    if (n % 2 == 0) ans = dp[n][1];
    if (v.size() == 1) ans = (dp2[n][1] + 1) % mod;
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 7032
l, k = gets.split.map(&:to_i)
t = [1, 0]
(2..l-1).each do |h|
    t[h] = t[h-2]
    t[h] += t[h-k-1] if h-k-1 >= 0
end
a = 0
(1..l).each do |h|
    a += t[h-1]
    a += t[h-k] if h-k >= 0
end
p a


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

int main(){
    int a,b,c,sam;
    sam = 0;
    cin>>a>>b>>c;
    for (int i = a;i <= b;i++) {
       if (c%i == 0) {
        sam = sam + 1;
       }
    }
    cout<<sam<<endl;
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[305];
ll A[305][305];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, K;
    cin >> H >> W >> K;
    REP(i, H) {
        cin >> S[i];
    }

    REP(w, W) {
        ll cnt = 0;
        REP(h, H) {
            if (S[h][w] == '#')
                cnt++;
        }
        if (cnt == 0) {
            if (w > 0) {
                REP(h, H) {
                    A[h][w] = A[h][w - 1];
                }
            }
            continue;
        }
        REP(h, H) {
            A[h][w] = K;
            if (S[h][w] == '#') {
                if (--cnt > 0)
                    K--;
            }
        }
        K--;
        REP(h, H) {
            for (ll j = w - 1; j >= 0; --j) {
                if (A[h][j] == 0)
                    A[h][j] = A[h][j + 1];
                else
                    break;
            }
        }
    }

    REP(h, H) {
        REP(w, W) {
            cout << A[h][w] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.List

-- space delimited integers
getVals::IO [Int]
getVals = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
 

-- space delimited strings
getStrings::IO [String]
getStrings = (map BS.unpack . BS.words) <$> BS.getLine

main::IO()
main = do 
    str<-getLine
    putStrLn $ if last str == 's' then str ++ "es" else str ++ "s"

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9+21;
const long long LINF = (long long) 1e18;
const long double PI = 2 * acos((long double)0);
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
#define Mahmud main()
#define endl "\n"
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define alla(arr,n) arr,arr+n
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define pb push_back
///Debug
#define dbg1(x) std::cerr<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<','<<#z<<"="<<(z)<<endl;
#define dbgArr(arr,n) cerr<<#arr<<"=["; printArray(arr,n,0,93); cerr<<endl;
///traversing
#define rep(n) for(int i=0;i<n;++i)
#define trv(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();++i)
///necessary functions
inline ll Int()
{
    ll _x=0,_tmp=1;
    char _tc=getchar();
    while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
    if( _tc == '-' ) _tc=getchar(), _tmp = -1;
    while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
    return _x*_tmp;
}
inline long double Double()
{
    long double d;
    scanf("%Lf",&d);
    return d;
}
ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}
int ton(string x)
{
    int y;
    std::istringstream ss(x);
    ss >> y;
    return y;
}
template<typename T>
string tostring(T x)
{
    ostringstream ss;
    ss << x ;
    return ss.str();
}

///Current Code vars
#define N 100010
long long n,k,c,d;
char arr[111][111];
///Current Code functions

string s;

void solve()
{
    n = Int();
    k = Int();
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<k;++j)
        {
            cin>>arr[i][j];
        }
    }
    for(int i=0;i<k+2;++i)
    {
        cout<<"#";
    }
    cout<<endl;
    for(int i=0;i<n;++i)
    {
        cout<<"#";
        for(int j=0;j<k;++j)
        {
            cout<<arr[i][j];
        }
        cout<<"#"<<endl;
    }
    for(int i=0;i<k+2;++i)
    {
        cout<<"#";
    }
    cout<<endl;
}

int Mahmud
{
    // ios_base::sync_with_stdio(0); //cin.tie(0);
  //#ifdef _LOCAL_
    //freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
  //while(1)
    solve();
  //#ifdef _LOCAL_
    //printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
  //#endif
    return 0;
}


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

ll cn[111];

int main(){
    ll n,k;cin>>n>>k;
    rep(i,0,k){
        ll d;cin>>d;
        rep(i,0,d){
            ll a;cin>>a;
            a--;
            cn[a]++;
        }
    }
    ll an=0;
    rep(i,0,n){
        if(cn[i]==0)an++;
    }
    cout<<an<<endl;
}
    









Measured memory_bytes: 3632
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;
const ll mod=1e9+7;
const double eps=0.000000001;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    if(a<=c && c<=b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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


template<Int MOD = 1000000007>
struct Mod{
  Int prev=0;
  vector<Int> fact,inv,finv;
  Mod(){}
  Mod(Int n){init(n);}
  
  Int pow(Int x,Int n){
    Int res=1;
    while(n){
      if(n&1) (res*=x)%=MOD;
      (x*=x)%=MOD;
      n>>=1;
    }
    return res;
  }
  
  Int inverse(Int a){
    return pow(a,MOD-2);
  }
  
  void init(Int n){
    if(prev>=n) return;
    prev=n;
    fact=inv=finv=vector<Int>(n);
    
    fact[0]=1;
    for(Int i=1;i<n;i++)
      fact[i]=(fact[i-1]*i)%MOD;
    
    inv[1]=1;
    for(Int i=2;i<n;i++)
      inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    
    finv[0]=1;
    for(Int i=1;i<n;i++)
      finv[i]=finv[i-1]*inv[i]%MOD;
  }
  
  Int comb(Int n,Int k){
    Int res=1;
    for(Int i=0;i<k;i++){
      res*=(n-i)%MOD;
      res%=MOD;
      res*=inverse(i+1);
      res%=MOD;
    }
    return res;
  }
  
  //only for prime MOD
  Int C(Int n,Int k){
    if(k<0||k>n) return 0;
    return fact[n]*finv[k]%MOD*finv[n-k]%MOD;
  }
  
  Int P(Int n,Int k){
    if(k<0||k>n) return 0;
    return fact[n]*finv[n-k]%MOD;    
  }

  Int H(Int n,Int k){
    return C(n+k-1,n);
  }
};


//INSERT ABOVE HERE
Int dp[2][5050][5050];
Int nxt[2][5050];

signed main(){
  Int n;
  cin>>n;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  const Int MOD = 1e9+7;
  Mod<MOD> mod(1e6);

  auto add=[&](Int &a,Int b){a+=b;a%=MOD;};

  vector<Int> g(n+1);
  g[0]=1;
  for(Int i=2;i<=n;i++) g[i]=g[i-2]*(i-1)%MOD;
  
  memset(dp,0,sizeof(dp));
  memset(nxt,0,sizeof(nxt));
  
  vector<Int> sz(n);
  function<void(Int, Int)> dfs=
    [&](Int v,Int p){
      sz[v]=1;
      for(Int u:G[v]){
	if(u==p) continue;
	dfs(u,v);
	sz[v]+=sz[u];
      }

      Int l=1;
      dp[0][v][1]=1;
      
      for(Int u:G[v]){
	if(u==p) continue;

	for(Int x=0;x<2;x++)
	  for(Int y=0;y<2;y++)
	    for(Int i=0;i<=l;i++)
	      for(Int j=0;j<=sz[u];j++){
		add(nxt[x^y][i+j],dp[x][v][i]*dp[y][u][j]%MOD);
		add(nxt[x^y^1][i],dp[x][v][i]*dp[y][u][j]%MOD*g[j]%MOD);
	      }
	
	l+=sz[u];
	for(Int k=0;k<2;k++){
	  for(Int i=0;i<=l;i++){
	    dp[k][v][i]=nxt[k][i];
	    nxt[k][i]=0;
	  }
	}
      }
    };
  
  dfs(0,-1);
  Int ans=0;
  for(Int i=0;i<=n;i++){
    add(ans,dp[0][0][i]*g[i]%MOD);
    add(ans,MOD-dp[1][0][i]*g[i]%MOD);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 423296
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int s;
    cin>>str;
    s=str.size();
    for(int i=0;i<s-1;i++)
    {
       if(str[i]==str[i+1])
       {
           cout<<i+1<<" "<<i+2;return 0;
       }
    }
    for(int i=0;i<s-2;i++)
    {
        if(str[i]==str[i+2])
        {
            cout<<i+1<<" "<<i+3;return 0;
        }
    }
    cout<<-1<<" "<<-1;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n;
    long k;
    std::cin >> n >> k;
    std::vector<int> a(n), b(n, -1);
    for(int i = 0; i < n; ++i) std::cin >> a[i];
    int now = 0, per;
    long count = 0;
    b[now] = 0;
    while(true){
        now = a[now] - 1;
        ++count;
        if(k == count){
            std::cout << now + 1 << std::endl;
            return 0;
        }
        if(-1 != b[now]){
            per = count - b[now];
            break;
        }else b[now] = count;
    }
    for(int i = 0; i < (k - count) % per; ++i){
        now = a[now] - 1;
    }
    std::cout << now + 1 << std::endl;

    return 0;
}

Measured memory_bytes: 4844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var hs = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();

            var max = 0;
            var from = 0;
            for (var i = 1; i < n; i++)
            {
                if (hs[i] > hs[i - 1])
                {
                    if (i - from > max) max = i - from - 1;
                    from = i;
                }
            }

            if (n - 1 - from > max) max = n - 1 - from;
            Console.WriteLine(max);
        }

    }
}

Measured memory_bytes: 39316
#include<stdio.h>
#include<string.h>

int main(){
    int N;
    char W[200][20];
    int i, j;
    int length;
    char ans = 0;

    scanf("%d", &N);

    for(i=0; i<N; i++){
        scanf("%s", &W[i]);
    }

    for(i=1; i<N; i++){
        length = strlen(W[i-1]);
        if(W[i-1][length-1] != W[i][0]){
            ans = 1;
        }
    }

    for(i=0; i<N-1; i++){
        for(j=i+1; j<N; j++){
            if(strcmp(W[i], W[j]) == 0){
                ans = 1;
            }
        }
    }

    if(ans == 0){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = mutableListOf<Pair<Int, Int>>()
    for (i in 0 until n) {
        list.add(readLine()!!.split(" ").map { it.toInt() }.let { Pair(it.first(), it.last()) })
    }
    var sum = 0.0
    for (i in 0 until n) {
        for (j in 0 until n) {
            sum += Math.sqrt(Math.pow(list[j].second.toDouble() - list[i].second.toDouble(), 2.0)
                    + Math.pow(list[j].first.toDouble() - list[i].first.toDouble(), 2.0))
        }
    }
    println(sum / n)
}


Measured memory_bytes: 36448
#include<stdio.h>
  
int search(int A[],int n,int key){
    int i=0;
    A[n]=key;
    while(A[i] != key)
        i++;
    return i != n;
}
  
int main()
{
    int i,n,A[10000+1],q,key,sum=0;
      
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&A[i]);
          
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&key);
        if(search(A,n,key))
            sum++;
    }
    printf("%d\n",sum);
      
    return 0;
}


Measured memory_bytes: 2112
import numpy as np

N, M = map(int, input().split())
bulb = np.zeros((M, N), dtype=bool)

for i in range(M):
    tmp = list(map(int, input().split()))

    for s in tmp[1:]:
        bulb[i][s - 1] = True

P = list(map(int, input().split()))

ret = 0
for k in range(2 ** N):
    count = np.zeros(M, dtype=int)
    for i in range(N):
        state = k & (1 << i) > 0
        for j in range(M):
            if state and bulb[j][i]:
                count[j] += 1

    f = True
    for c, p in zip(count, P):
        if c % 2 != p:
            f = False
            break

    if f:
        ret += 1

print(ret)


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll n;
  ll k;
  cin >> n >> k;
  if (n <= 2) {
    cout << 0 << endl;
    return;
  }
  ll a = (k + 5ll) * 5ll % 11ll;
  dmp(a);
  ll quo = (n - 2) / 11;
  ll rem = (n - 2) % 11;
  //   dmp(quo);
  //   dmp(rem);
  ll sum = 0ll, ans = 0ll;
  for (ll i = 1; i <= 11; i++) {
    for (ll j = 1; j <= 5; j++) {
      if ((7ll * i + j - 7ll) % 11 == a) sum++;
    }
    if (i == rem) ans += sum;
  }
  ans += quo * sum;
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long double INF = 1e18;

int res;
void dfs(int cnt,long nokori,int npos){
	if(cnt==0)return;
	for(int i=npos;i*i<=nokori;i++){
		if(i*i==nokori)res++;
		else dfs(cnt-1,nokori-i*i,i);
	}
}
int main(){
	int N;
	while(cin>>N&&N){
		res=0;
		dfs(4,N,1);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

template <typename T, typename E> struct SegmentTree {
  private:
    typedef function<T(T, T)> F;
    typedef function<T(T, E)> G;
    int n;
    T identity;
    F f;
    G g;
    vector<T> dat;
    void init(int n_) {
        n = 1;
        while(n < n_)
            n *= 2;
        dat.assign(2 * n - 1, identity);
    }
    void build(int n_, vector<T> v) {
        for(int i = 0; i < n_; i++)
            dat[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--)
            dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }

  public:
    SegmentTree(int n_, F f, G g, T id, vector<T> v = vector<T>())
        : identity(id), f(f), g(g) {
        init(n_);
        if(n_ == (int)v.size()) build(n_, v);
    }
    void update(int k, E a) {
        k += n - 1;
        dat[k] = g(dat[k], a);
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    T query(int a, int b) {
        T vl = identity, vr = identity;
        for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) vl = f(vl, dat[(l++) - 1]);
            if(r & 1) vr = f(dat[(--r) - 1], vr);
        }
        return f(vl, vr);
    }
};

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

    int n, q;
    cin >> n;
    vector<bitset<26>> vec(n, 0);
    string s;
    cin >> s;
    rep(i, n) vec[i].set(s[i] - 'a');
    SegmentTree<bitset<26>, char> segtree(
        n, [](bitset<26> a, bitset<26> b) { return a | b; },
        [](bitset<26> a, char b) { return bitset<26>(1 << b - 'a'); },
        bitset<26>(0), vec);

    cin >> q;
    while(q--) {
        int x;
        cin >> x;
        if(x == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            segtree.update(i, c);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << segtree.query(l, r).count() << endl;
        }
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  int pin[3];
  int ans=0;
  REP(i,1000){
    int p = i;
    REP(j,3){
      pin[j] = p%10;
      p /= 10;
    }

    int j=0;
    REP(k,s.size()){
      if(pin[j] == s[k] - '0')j++;
      if(j==3)break;
    }
    if(j==3)ans++;
  }
  cout << ans << endl;

}



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

int main(){
  double v1,v2;
  int l[10];
  while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2)){
  double sum = 0;
  rep(i,10){
    sum += l[i];
  }
  double sum2 = 0;
  v1=(v1/(v1+v2))*sum;
  rep(i,10){
    sum2+=l[i];
    if(v1 <= sum2){
      cout << i+1 << endl;
      break;
    }
  }
  }
  return 0;
}

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

const long long int INF = 1 << 17;
const long long int MAX = 2000010;
const long long int MOD = 1000000007;


int main() {
 long long int a ,b ;
  cin >> a >> b  ;
  
 
  
long long int ans = 0;
 
  for(int i=b;i<=a+1;i++){
   
    ans += ((a+1-i)*i+1)%MOD;
  }
   
 
  
  cout << ans%MOD << endl;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

n,k=I()
l=I()
lo=1;hi=max(l)
while lo<hi:
	md=(lo+hi)//2
	ct=0
	for i in range(n):
		ct+=l[i]//md-(l[i]%md==0)
	if ct<=k:
		hi=md
	else:
		lo=md+1
print(lo)

Measured memory_bytes: 30896
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int x=0,f=0;
	char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) f^=(ch=='-');
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return f ? -x : x;
}
const int maxn=1e5+10;
int n,m,head[maxn],cnt=0,col[maxn],ans,tot1=0,tot2=0;
bool flag=0;
struct node{
	int to,nxt;
}e[maxn<<1];
inline void add(int u,int v) {
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
} 
void dfs(int u,int COL) {
	if (flag) return;
	col[u]=COL;
	if (COL==1) ++tot1;
	else ++tot2;
	for (int i=head[u];i;i=e[i].nxt) {
		int v=e[i].to;
		if (!col[v]) dfs(v,3-COL);
		else if (col[v]==COL) {
			flag=1;
			return;
		}
 	}
}
signed main(){
	n=read(); m=read();
	for (int i=1,u,v;i<=m;++i) {	
		u=read(); v=read();
		add(u,v); add(v,u);
	}
	memset(col,0,sizeof(col));
	dfs(1,1);
	if (flag) ans=n*(n-1)/2;
	else ans=tot1*tot2;
	printf("%lld\n",ans-m);
	return 0;
}

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

using namespace std;

int main(){
    int ans;
    int n;
    while(true){
        cin >> n;
        if(n == 0) break;
        double tmpans = 1000000;
        for(int i = 0;i < n;i++){
            int p;
            double h,w;
            cin >> p >> h >> w;
            h /= 100.0;
            double tmpbmi =  w / ( h*h);
        //    cout <<  p << ":" << tmpbmi << endl;
            if(max(22.0-tmpbmi,tmpbmi-22.0) < tmpans){
                tmpans = max(22.0-tmpbmi,tmpbmi-22.0);
                ans = p;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3056
#include <iostream>

int main(int argc, char const *argv[]) {
	int x , y;
	std::string ans = "No";
	std::cin>>x>>y;
	if ( (y& 1) == 0 ) {
		for(int i = 1; i <=x;i++) {
			if ( i * 2 + (x - i) * 4 == y || 4 * i + (x - i) * 2 == y) {
				ans = "Yes";
				break;
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3620
N, A, B = map(int, input().split(' ')) 

diff = B-A
if diff%2 == 0:
    print(int(diff//2))
else:
    if((N-B) > (A-1)):
        path = A-1 + 1 + (B-A-1)//2
        print(int(path))
    else:
        path = N-B + 1 + (B-A-1)//2
        print(int(path))

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

const int N=200100;
multiset<int>s[N];
map<pair<int,int>,int>mp;
queue<pair<int,int> >q;
int n;

void add(int x,int y){
	if(x>y)swap(x,y);
	if(x==y)return;
	if(++mp[make_pair(x,y)]==2)q.emplace(x,y);
	s[x].insert(y);s[y].insert(x);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int x,y;cin>>x>>y;add(x,y));
	for(int i=1;i<n;++i)
		for(;;){
			if(q.empty()){cout<<"NO\n";exit(0);}
			auto x=q.front();q.pop();
			if(!mp[x])continue;
			int u=x.first,v=x.second;
			if(s[u].size()<s[v].size())swap(u,v);
			for(int i:s[v]){
				mp[make_pair(min(i,v),max(i,v))]=0;
				s[i].erase(s[i].find(v));add(i,u);
			}
			s[v].clear();
			break;
		}
	cout<<"YES\n";
	return 0;
}


Measured memory_bytes: 43648
#include<stdio.h>
int main()
{
          long long int i,num1,num2,result,temp,max;
          scanf("%lld%lld",&num1,&num2);
          i=1;
          if(num1 > num2)
          {
                    max = num1;
          }
          else
          {
                     max = num2;
          }
          while(1)
          {
              if((num2 * i) % num1 == 0)
              {
                        temp = i;
                        break;
              }
              i++;
          }
          result = num2 * temp;
          printf("%lld\n",result);
}


Measured memory_bytes: 128
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


int main() {
	int n, D, X;
	cin >> n >> D >> X;
	VI a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1;(j*a[i]+1)<=D; j++) {
			cnt++;
		}
	}
	cnt += (n+X);
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let s:String = read();
    let ans = format!("ABC{}",s);
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <cstring>

typedef struct _ORDER {
    char data[201]; // max of string.
    int effect_count;
    int shuffle_number[100]; // max of shuffle number is 100.
} ORDER;

class Shuffle {
    std::vector<ORDER> lst;
    std::list<char> shuffle_data;

public:
    bool run(void); // execute shuffle operation.

private:
    void read(void);
    void shuffle(void);
    void disp();
};

bool Shuffle::run()
{
    read();
    if (0 >= lst.size()) {
        return false;
    }
    shuffle();
    return true;
}

void Shuffle::read(void)
{
    ORDER tmp;
    std::string line;
    while (true) {
        std::memset(&tmp, 0, sizeof(tmp));
        std::cin >> line;
        if (0 == std::strcmp("-", line.c_str())) {
            break;
        }
        std::memcpy(tmp.data, line.c_str(), sizeof(tmp.data));
        std::cin >> tmp.effect_count;
        for (int i = 0; i < tmp.effect_count; i++) {
            std::cin >> tmp.shuffle_number[i];
        }
        lst.push_back(tmp);
    }
}

void Shuffle::shuffle()
{
    for (std::vector<ORDER>::const_iterator it = lst.begin(); it != lst.end(); it++) {
        int index = 0;
        shuffle_data.clear();
        while ('\0' != it->data[index]) {
            shuffle_data.push_back(it->data[index++]);
        }
        for (int i = 0; i < it->effect_count; i++) {
            for (int j = 0; j < it->shuffle_number[i]; j++) {
                char t = shuffle_data.front();
                shuffle_data.pop_front();
                shuffle_data.push_back(t);
            }
        }
        disp();
    }
}

void Shuffle::disp()
{
    for (std::list<char>::const_iterator it = shuffle_data.begin(); it != shuffle_data.end(); it++) {
        std::cout << *it;
    }
    std::cout << std::endl;
}

int main()
{
    Shuffle shuffle;
    (void) shuffle.run();
}

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

int main() {
	ll n;
	cin >> n;
	ll m = n/500;
	ll ans = m*1000;
	ll p = n%500;
	p = p/5;
	p = p*5;
	ans = p+ans;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=993244853;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=3e2+10;

    char str[N];int dp[N][N][N];
    void main()
	{
        scanf("%s",str+1);int K=qread(),n=strlen(str+1);
        fo(i,0,n) fd(j,n+1,i+1) fo(cnt,0,K)
        {
            chmax(dp[i+1][j][cnt],dp[i][j][cnt]);chmax(dp[i][j-1][cnt],dp[i][j][cnt]);
            chmax(dp[i+1][j-1][cnt+(str[i+1]!=str[j-1])],dp[i][j][cnt]+1);
        }
        int ans=0;fo(i,0,n) fo(cnt,0,K) chmax(ans,dp[i][i+1][cnt]*2),chmax(ans,dp[i][i+2][cnt]*2+1);write(ans);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 114560
import collections
import itertools
import operator


class UnionFind:
    def __init__(self,n):
        self.ps = [-1]*(n+1)
    def find(self,x):
        if self.ps[x]<0:
            return x
        else:
            self.ps[x]=self.find(self.ps[x])
            return self.ps[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return False
        if self.ps[x]>self.ps[y]:
            x,y = y,x
        self.ps[x] += self.ps[y]
        self.ps[y] = x
        return True
    def same(self,x,y):
        return self.find(x)==self.find(y)
    def size(self,x):
        x = self.find(x)
        return -self.ps[x]


N,M,K=map(int,input().split())
retu_n=[0]*N
block_n=[0]*N
uf = UnionFind(N)

for m in range(M):
  a,b=map(int,input().split())
  retu_n[a-1] +=1
  retu_n[b-1] +=1
  uf.unite(a,b)
  
  
for k in range(K):
  c,d=map(int,input().split())
  if uf.same(c, d):
    block_n[c-1] += 1
    block_n[d-1] += 1
    
  
for n in range(N):
  print(uf.size(n+1)-retu_n[n]-block_n[n]-1, end=" ")


Measured memory_bytes: 9748
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define MP(a, b) make_pair(a, b)
#define F first
#define S second

int main() {
	int M, T, P, R;
	while (cin >> M >> T >> P >> R, M || T || P || R) {
		vector<pair<int, pair<int, int>>> vp;

		int pena[51][11];

		REP(i, 0, T) vp.push_back(MP(0, MP(0, -i - 1)));
		REP(i, 0, 51) REP(j, 0, 11) pena[i][j] = 0;

		REP(i, 0, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;

			if (j == 0) {
				vp[t].F--;
				vp[t].S.F += (pena[t][p] + m);
			}
			else {
				pena[t][p] += 20;
			}
		}

		sort(vp.begin(), vp.end());

		cout << -vp[0].S.S;
		REP(i, 1, vp.size()) {
			if (vp[i - 1].F < vp[i].F) {
				cout << "," << -vp[i].S.S;
			}
			else if (vp[i - 1].S.F < vp[i].S.F) {
				cout << "," << -vp[i].S.S;
			}
			else {
				cout << "=" << -vp[i].S.S;
			}
		}

		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3044
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,m,i;
    cin>>n;
    long long int a[n],sum2=100000000,sum1=0,k,l,h,j;
   for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=a[0];i<=a[n-1];i++){
        for(j=0;j<n;j++){
            l=abs(i-a[j]);
           // cout<<"l="<<l<<endl;
            sum1=sum1+(l*l);
         //   cout<<sum1<<endl;
        }
      //  cout<<"sum1="<<sum1<<endl;
         sum2=min(sum2,sum1);
         sum1=0;
    }
  cout<<sum2<<endl;
}


Measured memory_bytes: 3624
def main():
    K = int(input())
    LL = set()

    def dfs(s):
        if 3234566667 < int(s):
            return
        c = int(s[-1])
        for p in range(-1, 2):
            if c+p < 0 or 9 < c+p:
                continue
            LL.add(int(s+str(c+p)))
            dfs(s+str(c+p))

    for s in "123456789":
        LL.add(int(s))
        dfs(s)

    ans = sorted(LL)
    print(ans[K-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 75368
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long n,m;
    cin>>n>>m;
    long long a[n],b[n];
    pair<long long,long long> c[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        c[i]=make_pair(a[i],b[i]);
    }
    sort(c,c+n);
    long long sum=0;
    for(int i=0;m!=0;i++){
        if(m>c[i].second){
            sum+=c[i].first*c[i].second;
            m-=c[i].second;
        }
        else{
            sum+=c[i].first*m;
            break;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p[1000005],hell=pow(10,9)+7;
ll exp(ll x,ll y){
    ll res=1;
    while(y>0){
        if(y&1)
        res=(res*x)%hell;
        y>>=1;
        x=(x*x)%hell;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    p[0]=1;
    for(ll i=1;i<1000005;i++)
    p[i]=(i*p[i-1])%hell;
    ll x,y;
    cin>>x>>y;
    ll x0=(2*x-y)/3,y0=(2*y-x)/3;
    if(((2*x-y)%3)||((2*y-x)%3)||x0<0||y0<0){
        cout<<0;
        exit(0);
    }
    ll res=p[x0+y0];
    res*=exp(p[x0],hell-2);
    res%=hell;
    res*=exp(p[y0],hell-2);
    res%=hell;
    cout<<res;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vb=vector<bool>;
ll n;
vi heads{3,5,7};

bool is_753(ll s) {
    vb a{false,false,false};
    while(s > 0) {
        int k = s%10;
        rep(i,3) if(k==heads[i]) a[i] = true;
        if(all_of(ALL(a),[](bool x) {return x;})) return true;
        s /= 10;
    }
    return false;
}

int dfs(ll s, int d) {
    if(s > n) return 0;
    int res = is_753(s)?1:0;
    for(auto h:heads) {
        ll t = h*pow(10,d) + s;
        res += dfs(t, d+1);
    }
    return res;
}

int main() {
    cin >> n;
    cout << dfs(0,0) << endl;
    return 0;
}


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


int main(){
  char c1, c2,c3;
  cin >> c1 >> c2 >> c3;
  
  int answer = 0;
  if(c1 == '1'){
    answer++;
  }
  if(c2 == '1'){
    answer++;
  }
  if(c3 == '1'){
    answer++;
  }
  
  cout << answer;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int i,a,b;
  cin >> a >> b;
  if (a+b==15) {
    cout << "+"<< endl;
  } else if (a*b==15) {
    cout << "*"<< endl;
  } else {
    cout << "x"<< endl;
  }
  return 0;
}


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

int main(){
  uint N;
  cin>>N;
  uint inc,myno,SYO=1000000007,sameflg;
  vector<uint> C(N,0);
  cin>>C[0];
  uint newN=1,jid;//newN
  for(uint i=1;i<N;i++){
    cin>>inc;
    if (C[newN-1]!=inc){
      C[newN]=inc;
      newN++;
    }
  }
  
  vector<uint> sumdp(200000,0);
  vector<uint> dp(newN,0);

  dp[0]=1;
  sumdp[C[0]]=1;
  for(uint i=1;i<newN;i++){
    myno=C[i];
    sameflg=sumdp[myno];
    dp[i]=(dp[i-1]+sameflg)%SYO;
    sumdp[myno]=(sumdp[myno]+dp[i-1])%SYO;
  }

  cout<<dp[newN-1]<<endl;
  return 0;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define N 1002
int main() {
	char s[N] = "", x[N]="", tmp[N], str[N] = "", *p1, *p2;
	int i= 0,j,k=1,cnt = 0,xLength, sLength;
	fgets(x, sizeof(x), stdin);
	x[strlen(x) - 1] = '\0';
	while (1) {
		tmp[0] = '\0';
		//fgets(str, sizeof(str), stdin);
		scanf("%s", str);
		if (strcmp(str, "END_OF_TEXT") == 0) break;
		if (strcmp(str, "END_OF_TEXT\n") == 0) break;
		xLength = strlen(x);
		sLength = strlen(str);
		for (i = 0; i < sLength; i++) str[i] = tolower(str[i]);
		for (i = 0; i < xLength; i++) x[i] = tolower(x[i]);
		if (strcmp(str, x) == 0)cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 568
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def order(l):
    flag = [True]*n
    ret = 0
    for i,item in enumerate(l):
        count = 0
        for j in range(n):
            if item-1==j:
                flag[j] = False
                break
            if not flag[j]:
                continue
            count += 1
        ret += fact[n-i-1]*count
    ret += 1
    return ret

def solve():
    a = order(p)
    b = order(q)
    print(abs(a-b))
    return

if __name__=='__main__':
    fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320]
    n = I()
    p = list(IL())
    q = list(IL())
    solve()

Measured memory_bytes: 9276
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

int arr[200010];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, i;
    scanf("%d", &n);
    for(i = 1; i <= n; i++)
        scanf("%d", &arr[i]);

    for(i = 1; i <= n; i++)
        arr[i] -= i;

    sort(arr + 1, arr + n + 1);

    int b = arr[n / 2 + 1];

    long long res = 0;
    for(i = 1; i <= n; i++)
        res += abs(arr[i] - b);

    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1024
// Distance.cc
// ２点 P1(x1, y1), P2(x2, y2) の距離を求めるプログラムを作成せよ。
// 【入力】
// x1, y1, x2, y2 （実数）が空白区切りで与えられます。
// 【出力】
// P1とP2の距離を実数で１行に出力して下さい。0.0001以下の誤差があってもよいものとします。
// 【例】
// 入力１：
// 0 0 1 1
// 出力１:
// 1.41421356
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main( void) {
  double x1, y1, x2, y2;

  cin >> x1 >> y1 >> x2 >> y2;

  printf( "%.8lf\n", sqrt( pow( fabs(x1-x2), 2) + pow( fabs(y1-y2),2)));

  return 0;
}



Measured memory_bytes: 3184
# 047_a
a, b, c = map(int, input().split())
if (1 <= a <= 100) & (1 <= b <= 100) & (1 <= c <= 100):
    if (a + b == c) | (a == b + c) | (a + c == b):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9040
n = int(input())
march = [0, 0, 0, 0, 0]
for i in range(n):
    s = list(input())
    if s[0] == "M":
        march[0] += 1
    elif s[0] == "A":
        march[1] += 1
    elif s[0] == "R":
        march[2] += 1
    elif s[0] == "C":
        march[3] += 1
    elif s[0] == "H":
        march[4] += 1
ans = 0
for i in range(3):
    for j in range(3 - i):
        for k in range(3-i-j):
            ans += march[i] * march[i + j + 1] * march[i + j + k + 2]
print(ans)


Measured memory_bytes: 3064
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!(n: usize, m: usize);
    let mut candidates = vec![];

    let mut p = 1;
    while p * p <= m {
        if m % p == 0 {
            candidates.push(p);
            candidates.push(m / p);
        }
        p += 1;
    }
    candidates.sort();
    candidates.reverse();

    for &candidate in candidates.iter() {
        if candidate * n <= m {
            println!("{}", candidate);
            return;
        }
    }

    unreachable!();
}


Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <vector>   // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
using namespace std;

int main(void)
{
  long long int a, b, c;
  cin >> a >> b >> c;
  vector<long long int> Z(3);
  Z[0] = a;
  Z[1] = b;
  Z[2] = c;
  sort(Z.begin(), Z.end());
  for(int i = 0;i < 3;i++)
  {
    if(i != 2) cout << Z[i] << " ";
    else cout << Z[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
const ll INF=1e18;
int x,d,n,tot;
ll ans;
struct node {
	int p;
	ll l,r;
} a[maxn];
bool cmp(node A,node B) {
	if (A.p!=B.p) return A.p<B.p;
	return A.l<B.l;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(x); read(d);
	if (d==0) {
		if (x==0) printf("1\n");
		else printf("%d\n",n+1);
		return 0;
	}
	if (d<0) x=-x,d=-d;
	int p; ll l,r;
	for (ll k=0;k<=n;k++) {
		l=k*(k-1)/2;
		r=k*(n*2-k-1)/2;
		p=k*x%d;
		l+=k*x/d;
		r+=k*x/d;
		a[++tot]=(node){p,l,r};
	}
	sort(a+1,a+tot+1,cmp);
	ll L=-INF+1,R=-INF;
	for (int i=1;i<=tot+1;i++) {
		if (a[i].p!=a[i-1].p||i>tot||i==1) {
			ans+=R-L+1;
			L=a[i].l,R=a[i].r;
			continue;
		}
		if (a[i].l>R) ans+=R-L+1,L=a[i].l,R=a[i].r;
		else R=max(R,a[i].r);
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 4992
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    n <- readLn
    ds <- r n
    putStrLn $ if U.all (\x -> x `mod` 3 == 0 || x `mod` 5 == 0) $ U.filter even ds
        then "APPROVED" else "DENIED"



Measured memory_bytes: 508
function main(input){

  input = input.split('\n');
  const [N, M, X] = input[0].split(' ').map(Number);
  const list = input.slice(1, N+1).map(x => {
    const row = x.split(' ').map(Number);
    return {
      c: row[0],
      a: row.slice(1, M+1)
    }
  });

  let min = -1;
  for(let n=1; n<=2**N; n++){
    let sum = 0;
    let a = [];
    for(let i=0; i<M; i++){
      a.push(0);
    }
    for(let i=0; i<N; i++){
      if((n>>i & 1) == 1){
        sum += list[i].c;
        for(let j=0; j<M;j++){
          a[j] += list[i].a[j];
        }
      }
    }
    if(!a.every(x=> x >= X)) continue;
    if ((sum < min) || (min==-1)){
      min = sum;
    }
  }

  console.log(min);

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


Measured memory_bytes: 33608