akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
long long m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()
//nCk(comuseを使え)
long long combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//pCk(comuseを使え)
long long perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a,long long b){
  long long n;
  n=a/__gcd(a,b)*b;
  return n;
}

//auto A = div(n)
vector<long long> div(long long n){
  vector<long long> ret;
  for(long long i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a,long long n,long long mod){
  long long ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}

///////////////////////////////////////////////////////////



void Solve(){
  long long a , b;
  cin >> a >> b;
  cout << lcm(a,b) <<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)

def my_ed(s,t):
    #print('call',s,t)
    mem = {}
    def dp(i,j):
        nonlocal mem,s,t
        if (i,j) in mem.keys():
            return mem[(i,j)]
        if i<0:
            res = j+1
        elif j<0:
            res = i+1
        else:
            res = min(dp(i-1,j)+1,dp(i,j-1)+1,dp(i-1,j-1) + (0 if s[i]==t[j] else 1))
        mem[(i,j)] = res
        #print(i,j,s[:i+1],t[:j+1],res)
        return res
     
    return dp(len(s)-1,len(t)-1)
 
 
print(my_ed(input(),input()))



Measured memory_bytes: 165652
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef unsigned long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, m, l, len[12], s;
char a[12][30], in[5010];
ll pw[5010], h[5010], ha[12][30];
bool v[1 << 12];

bool rec(int pos, int bit, ll ch, int cl){
	if(v[bit]) return 0;
	v[bit] = 1;
	if(bit == (1 << n) - 1) return 1;
	rep(i, n) if(!(bit & 1 << i)){
		ll nh = ch + pw[cl] * ha[i][len[i]];
		int nl = cl + len[i];
		if(h[pos + nl] - h[pos] != nh * pw[pos]) continue;
		if(rec(pos, bit | 1 << i, nh, nl)) return 1;
	}
	return 0;
}

int main(){
	pw[0] = 1;
	rep(i, 5009) pw[i + 1] = pw[i] * 29;
	
	while(scanf("%d%d", &n, &m), n){
		s = 0;
		rep(i, n){
			scanf("%s", a + i);
			s += (len[i] = strlen(a[i]));
			rep(j, len[i]) ha[i][j + 1] = ha[i][j] + (a[i][j] - 'a' + 1) * pw[j];
		}
		l = 0;
		rep(i, m){
			scanf("%s", in + l);
			l += strlen(in + l);
		}
		rep(i, l) h[i + 1] = h[i] + (in[i] - 'a' + 1) * pw[i];
		
		int ans = 0;
		rep(i, l - s + 1){
			memset(v, 0, sizeof(v));
			if(rec(i, 0, 0, 0)) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i;
  char s[10];
  while(cin>>i,i){
    sprintf(s,"%o",i);
    for(i=0;s[i]!='\0';i++){
      if(s[i]>='4')s[i]++;
      if(s[i]>='6')s[i]++;
}
    printf("%s\n",s);
}
}

Measured memory_bytes: 3116
#include "bits/stdc++.h"

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll ans = n - 1;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      chmin(ans, i + n / i - 2);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    ll x, k, d;

    cin >> x >> k >> d; 

    bool flag = true;
    ll min1, min2, res, pos;

    if (x > 0){
        if (x/d + 1 <= k) {
            flag = true;
            min1 = x%d;
            min2 = abs(min1 - d);
            
            res = k - x/d;
            if(res%2 == 0) cout << min1 << endl;
            else cout << min2 << endl;
        }
        else {
            flag = false;
            min1 = x - d*k;
            cout << min1 << endl;
        }    
    }

    else if(x < 0){
        if (-x/d + 1 <= k) {
            flag = true;
            min1 = abs(x%d);
            min2 = x%d + d;
            res = k + (-x)/d;
            if(res%2 == 0) cout << min1 << endl;
            else cout << min2 << endl;
        }
        else {
            min1 = abs(x + d*k);
            cout << min1 << endl; 
        }
    }

    else{
        if(k%2 == 0){
            cout << 0 << endl;
        }
        else{
            cout << d << endl;
        }
    }
}

Measured memory_bytes: 3616
#pragma GCC optimize("O3")
                #pragma comment(linker, "/stack:200000000")
                #pragma GCC optimize("unroll-loops")
                 
                #include <algorithm>
                #include <bitset>
                #include <cassert>
                #include <chrono>
                #include <cmath>
                #include <complex>
                #include <cstdio>
                #include <cstdlib>
                #include <cstring>
                #include <ctime>
                #include <deque>
                #include <functional>
                #include <iomanip>
                #include <iostream>
                #include <iterator>
                #include <limits>
                #include <climits>
                #include <list>
                #include <map>
                #include <numeric>
                #include <queue>
                #include <random>
                #include <ratio>
                #include <set>
                #include <sstream>
                #include <stack>
                #include <string>
                #include <unordered_map>
                #include <unordered_set>
                #include <utility>
                #include <vector>
                using namespace std;
                 
                typedef long long ll;
                typedef long double LD;
                #define int ll
                #define double LD
                #define pb push_back
                #define mp make_pair
                #define REP(i,n) for (int i = 0; i < n; i++)
                #define loop(i,n) for (int i = 0; i < n; i++)
                #define FOR(i,a,b) for (int i = a; i < b; i++)
                #define REPD(i,n) for (int i = n-1; i >= 0; i--)
                #define FORD(i,a,b) for (int i = a; i >= b; i--)
                #define remax(a,b) a = max(a,b)
                #define remin(a,b) a = min(a,b)
                #define mem(a, b) memset(a, b, sizeof a)
                #define append push_back
                #define all(v) v.begin(),v.end()
                #define F first
                #define S second
                #define print(x) cout << (x) << endl
                #define PRECISION(x) cout << fixed << setprecision(x)
                #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
                #define N 505
                #define pb push_back
                const double PI=acos(-1);
                const int MOD = 1000000007;
                const int FMOD = 998244353;
                const double eps = 1e-9;
                 
                mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
                
             
               signed main()
               {
               		double r;
               		cin>>r;
               		double ans=2*3.14*r;
               		cout<<fixed<<setprecision(6)<<ans;
    		   }

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

int main(){

  int H,R;

  cin >>H>>R;
  
  if ( H+R > 0 ) cout <<1<<endl;

  else if ( H+R < 0 ) cout << -1<<endl;

  else cout <<0<<endl;

  return 0;
}




Measured memory_bytes: 3104
#include <stdio.h>
#define W 0
#define G 1
#define B 2

int n,M[100][100];
int color[100],d[100],f[100],count=0;

void serch(int u){
  int v;
  color[u] = G;
  d[u] = ++count;

  for(v=0;v<n;v++){
    if(M[u][v] == 0){
      continue;
    }
    if(color[v] == W){
      serch(v);
    }
  }
  color[u] = B;
  f[u] = ++count;
}

void dfs(){
  int u;

  for(u=0;u<n;u++){
    color[u] = W;
  }
  count = 0;
  
  for(u=0;u<n;u++){
    if(color[u] == W){
      serch(u);
    }
  }

  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;

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

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
} 

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;


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

	string S; cin >> S;
	
	int score = 0;
	int P = 0;
	int R = 0;
	F0R(i, S.size()) {
		if (S[i] == 'g') {
			// Rock
			if (P < R) {
				++P; ++score;
			} else {
				++R;
			}
		} else {
			// Paper
			if (P < R) {
				++P;
			} else {
				++R; --score;
			}
		}
	}

	print(score);
}

Measured memory_bytes: 512
def comb(a, b, mod):
    if a < b :
        return 0
    if (a // 2) < b:
        x = a - b
        # print(f'{b}　→ {x}')
        b = x
    t = 1
    for i in range(b):
        t *= (a - i) % mod
    s = 1
    for i in range(1, b + 1):
        s *= i % mod
    return (t // s) % mod

N, K = map(int, input().split())
r = N - K
mod = 1000000007

for i in range(1, K + 1):
        first = comb(r + 1, i, mod)
        if first == 0:
            second = 0
        else:
            second = comb(K - 1, i - 1, mod)
        print(first * second % mod)




Measured memory_bytes: 46172
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define M_N 1000
#define M_W 1000

typedef pair<int, int> ii; //?????????, ?????????

int W, N;
int v[M_N], w[M_N];
int dp[M_N + 1][M_W + 1][2];

//?????????j??\?????¶??????i????????\????????????????????????
ii dfs(int i, int j) {
	if (dp[i][j][0] != -1)
		return ii(
			dp[i][j][0],
			dp[i][j][1]
		);

	if (i == N) {
		//?????°??¶?????????????????¨???
		return ii(
			dp[i][j][0] = 0,
			dp[i][j][1] = 0
		);
	}
	else if (j < w[i]) {
		//i??????????????????????????¶?????§??\??????????????¨???
		return ii(
			dp[i][j][0] = dfs(i + 1, j).first,
			dp[i][j][1] = dfs(i + 1, j).second
		);
	}
	else {
		//???????????\???????????\??????????????§?????????????????????????????§??¨?????????
		int a = dfs(i + 1, j).first,
			b = dfs(i + 1, j - w[i]).first + v[i];
		if (a >= b) //??\?????????
			return ii(
				dp[i][j][0] = a,
				dp[i][j][1] = dfs(i + 1, j).second
			);
		else //??\?????? ??\????????????????????¶??????w[i]?????????
			return ii(
				dp[i][j][0] = b,
				dp[i][j][1] = dfs(i + 1, j - w[i]).second + w[i]
			);

	}
}

int main() {
	for (int h = 1; cin >> W, W; h++) {
		cin >> N;
		memset(dp, -1, sizeof(dp));
		for (int i = 0; i < N; i++) {
			char c;
			cin >> v[i] >> c >> w[i];
		}
		cout << "Case " << h << ":" << endl;
		cout << dfs(0, W).first << endl;
		cout << dfs(0, W).second << endl;
	}
	return 0;
}

Measured memory_bytes: 9076
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, l;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> l;

  int sum = 0, mii = INF;
  FOR(i, l, n + l) {
    sum += i;
    mii = min(mii, abs(i));
  }

  if(l < 0 && l + n - 1 < 0) {
    sum += mii;
  } else {
    sum -= mii;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


void solve(){
    int X,Y,Z; cin>>X>>Y>>Z;
    swap(X,Y); swap(X,Z);

    cout<<X<<" "<<Y<<" "<<Z<<endl;
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



Measured memory_bytes: 764
#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 2e18
#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;
}

int main()
{
  INT(A);
  INT(B);
  INT(Q);
  VEC(ll,s,A);
  VEC(ll,t,B);
  VEC(ll,x,Q);

  vector<ll> S(A);
  vector<ll> T(B);
  REP(i,A){
    auto itr=upper_bound(ALL(t),s[i]);
    int j=distance(t.begin(),itr);
    if(j==B){
      S[i]=abs(s[i]-t[j-1]);
    }else if(j-1<0){
      S[i]=abs(s[i]-t[j]);
    }else{
      S[i]=min(abs(s[i]-t[j]),abs(s[i]-t[j-1]));
    }
  }
  REP(i,B){
    auto itr=upper_bound(ALL(s),t[i]);
    int j=distance(s.begin(),itr);
    if(j==A){
      T[i]=abs(t[i]-s[j-1]);
    }else if(j-1<0){
      T[i]=abs(t[i]-s[j]);
    }else{
      T[i]=min(abs(t[i]-s[j]),abs(t[i]-s[j-1]));
    }
  }

  REP(i,Q){
    ll MIN = INF;
    auto itr=upper_bound(ALL(s),x[i]);
    int j=distance(s.begin(),itr);
    if(j==A){
      MIN=min(MIN,abs(x[i]-s[j-1])+S[j-1]);
    }else if(j-1<0){
      MIN=min(MIN,abs(x[i]-s[j])+S[j]);
    }else{
      MIN=min(MIN,abs(x[i]-s[j])+S[j]);
      MIN=min(MIN,abs(x[i]-s[j-1])+S[j-1]);
    }
    
    auto itr2=upper_bound(ALL(t),x[i]);
    int k=distance(t.begin(),itr2);
    if(k==B){
      MIN=min(MIN,abs(x[i]-t[k-1])+T[k-1]);
    }else if(k-1<0){
      MIN=min(MIN,abs(x[i]-t[k])+T[k]);
    }else{
      MIN=min(MIN,abs(x[i]-t[k])+T[k]);
      MIN=min(MIN,abs(x[i]-t[k-1])+T[k-1]);
    }
    
    cout << MIN << endl;
  }
}

Measured memory_bytes: 7216
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 110
#define ll long long
#define mo 998244353
int n;
char str[N];
int _s[10][N];
int _f[10][N][N];
int p;
int dp(int s[],int n,int f[][N]){
	for (int i=n;i>=1;--i){
		f[i][i]=s[i]+1;
		for (int j=i+1;j<=n;++j){
			f[i][j]=0;
			for (int d=1;d<j-i+1;++d)
				if ((j-i+1)%d==0){
					int *t=_s[++p];
					for (int k=0;k<d;++k)
						t[k+1]=s[i+k];
					for (int l=1;d*l<j-i+1;++l)
						for (int k=0;k<d;++k)
							t[k+1]&=s[i+d*l+k];
					f[i][j]=(f[i][j]+dp(t,d,_f[p]))%mo;
					--p;
				}
		}
	}
	static int g[N];
	g[0]=1;
	for (int i=1;i<=n;++i){
		g[i]=0;
		for (int j=0;j<i;++j)
			g[i]=(g[i]+(ll)g[j]*f[j+1][i])%mo;
	}
	return g[n];
}
int main(){
	scanf("%s",str+1);
	n=strlen(str+1);
	for (int i=1;i<=n;++i)
		_s[0][i]=str[i]-'0';
	p=0;
	printf("%d\n",dp(_s[0],n,_f[0]));
	return 0;
}











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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const int mx = 710000;


ll gcd(ll x, ll y){
	if(x%y == 0)return y;
	else return gcd(y, x%y);
}

ll a,b;
int main(){
	cin >> a >> b;
	ll g = gcd(a,b);
	// ll ans = 1;
	set<ll> ans = {1};
	for(int i = 2; i <= sqrt(g) + 1; i++){
		// if(g%i == 0)ans.insert(i);
		// if(g%i == 0)ans++;
		while(g%i == 0){
			ans.insert(i);
			g /= i;
		}
	}
	if(g > 1)ans.insert(g);
	// cout << g << endl;
	// set<ll> ans = {1};
	// for(int i = 2; i< max_divisor + 1; i++){
	// 	while(max_divisor % i == 0){
	// 		ans.insert(i);
	// 		cout << i << endl;
	// 		max_divisor /= i;
	// 	}
	// 	cout <<  max_divisor << endl;
	// }
	cout << ans.size() << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x));
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 18, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
ll n,m,ans[1005][1005];
char arr[1005][1005];
int main()
{
	MuhammedAly
	cin >> n >> m;
	for(int i =0;i<n;i++)
		for(int j =0;j<m;cin >> arr[i][j++]);
	ans[0][0] = 1;
	for(int i =0;i<n;i++)
	{
		for(int j = 0;j<m;j++)
		{
			if(arr[i][j] == '#')
				continue;
			if(i)
				ans[i][j]+=ans[i-1][j];
			if(j)
				ans[i][j]+=ans[i][j-1];
			ans[i][j]%=mod;
		}
	}
	cout << ans[n-1][m-1];
	return 0;
}


Measured memory_bytes: 9088
def main():
    H, W, D = list(map(int, input().split()))
    b = [None] * (H * W)
    for h in range(H):
        for w, a in enumerate(map(int, input().split())):
            b[a - 1] = (h, w)
    C = [0] * (H * W)
    for i in range(H * W - D):
        hi, wi = b[i]
        hn, wn = b[i + D]
        C[i] = abs(hi - hn) + abs(wi - wn)
    E = [0] * (H * W)
    for i in reversed(range(H * W - D)):
            E[i] = E[i + D] + C[i]
    Q = int(input())
    for _ in range(Q):
        l, r = map(int, input().split())
        print(E[l - 1] - E[r - 1])
        
main()


Measured memory_bytes: 15836
//2/05/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
vector<ll>v;
deque<ll>dq;
stack<ll>stk;
map<ll,ll>mp;
unordered_map<ll,ll>ump;
set<ll>st;
multiset<ll>mst;
unordered_set<ll>ust;
unordered_multiset<ll>umst;
priority_queue<ll,deque<ll>,greater<ll>>pq;
Pbds<ll>ost;

ll Get(ll n){
    return n/100;
}

int main(){
    _fastio
    ll x;
    cin>>x;

    ll tot=100;
    ll ans=0;
    while(tot<x){
        ans++;
        tot+=Get(tot);
    }
    cout<<ans<<en;



    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	string s;
	string t;
	cin>>s>>t;
	int ans=0;
	rep(i,s.size())
		if(s[i]!=t[i])ans++;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3956
#include <iostream>
#include <string>

using namespace std;

int main(){
    string a,b,ans;
    cin >> a >> b;

    if(a == "D"){
        if(b == "D"){
            ans = "H";
        }else{
            ans = "D";
        }
    }else{
        ans = b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();

		int attackNumA = (int) Math.ceil((double)A/D);
		//System.out.println(attackNumA);
		int attackNumT = (int) Math.ceil((double)C/B);
		//System.out.println(attackNumT);
		if(attackNumA >= attackNumT) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		scan.close();
	}
}


Measured memory_bytes: 35736
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  year, month, _ = map(int, input().split('/'))
  ans = 'TBD'

  if year < 2019 or (year == 2019 and month <= 4):
    ans = 'Heisei'

  print(ans, flush=True)


if __name__ == '__main__':
  main()



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  reverse(s.begin(), s.end());
  vector<string> T = { "dream", "dreamer", "erase", "eraser" };
  for_each(T.begin(), T.end(), [](string& t) { reverse(t.begin(), t.end()); });

  int i = 0, N = s.size();
  bool ok = true;
  while (i + 3 <= N) {
    string pre = s.substr(i, 3);
    string u;
    for (int i = 0; i < 4; ++i) {
      if (pre == T[i].substr(0, 3)) {
        u = T[i];
        break;
      }
    }
    if (u.empty() or i + u.size() > N) {
      ok = false;
      break;
    }
    if (s.substr(i, u.size()) != u) {
      ok = false;
      break;
    }
    i += u.size();
  }
  printf("%s\n", ok ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 512
n[10],k,t,i=9,h;main(j){for(;~scanf("%x",n+i);k=i--?0:printf("%x\n",k,i=8))for(h=1;h;k|=t&h,h*=2)for(j=9,t=*n^k;--j;)t-=n[j]^k;exit(0);}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define mi map<int,int>
#define mc map<char,int>

//ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
    int r;
    cin>>r;
    cout<<pow(r,2) <<"\n";
}

Measured memory_bytes: 3804
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 多次元配列を作る
// vector<vector<int>> vn(n, vector<int>(3, 0));

// 多次元配列の dump
// for (vector<int> v : vn) {
//     cout << v;
// }

// printf("%d\n", n);
// printf("%lld\n", n);

int main(void){
    int n;
    scanf("%d", &n);
    // printf("%d\n", n);
    int c = 3;
    vector<vi> funs(n, vi(c, 0));
    vector<vi> dp(n + 1, vi(c, 0));

    REP(i, n) {
        REP(j, c) {
            int fun;
            scanf("%d", &fun);
            funs[i][j] = fun;
        }
        // cout << funs[i];
    }
    // cout << endl;
    RREP(i, n) {
        // cout << "=====" << endl;
        // cout << i << endl;
        REP(j, c) {
            vi next_funs(c - 1, 0);
            REP(k, c) {
                if (j != k) {
                    next_funs.push_back(dp[i + 1][k]);
                }
            }
            // cout << "next_fun is :" << next_funs << endl;
            int next_max_fun = *max_element(next_funs.begin(), next_funs.end());
            // cout << "max is :" << next_max_fun << endl;
            dp[i][j] = funs[i][j] + next_max_fun;
        }
        // cout << dp[i] << endl;
    }
    // cout << dp[0];
    int max_fun = *max_element(dp[0].begin(), dp[0].end());
    printf("%d", max_fun);
    return 0;
}


Measured memory_bytes: 11136
S=str(input())
N=len(S)
M=int((N-1)/2)
f=True
L=""
for i in range(M):
	if S[i]!=S[-i-1]:
		f=False
	else:
		L+=S[i]	
for i in range(int(len(L)//2)):
	if L[i]!=L[-i-1]:
		f=False
if f==False:print("No")
else:print("Yes")

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

int main()
{
    ll X, N;
    cin >> X >> N;
    // vector<ll> p(N);
    // rep(i, N) cin >> p[i];
    unordered_set<ll> p;
    ll tmp;
    rep(i, N)
    {
        cin >> tmp;
        p.insert(tmp);
    };

    ll i = 0, ans;
    while (true)
    {
        if (p.count(X - i) == 0)
        {
            ans = X - i;
            break;
        }
        if (p.count(X + i) == 0)
        {
            ans = X + i;
            break;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    long long N, Y;
    cin >> N >> Y;

    for(int i = 0; i <= N; ++i) {
        for (int j = 0; j+i <= N; ++j) {
            int k = N - i - j;
                if( Y == i * 10000 + j * 5000 + k * 1000 ) {
                    cout << i << " " << j << " " << k << " " << endl;
                    return 0;
                
            }
        }
    }

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

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

int main(void){
  int N, i;
  float x[100];
  //char *u, c;
  char u[100], c;
  //char *JPY = "JPY", *BTC = "BTC";
  float sum=0.0;
  
  scanf("%d", &N);
  
  for(i=0; i<N; i++){
    scanf("%f %s", &x[i], u);
    //printf("%s\n", u);
    c = u[0];
    //printf("%c\n", c);
    if(c-'J'==0){
      sum=sum+x[i];
      //printf("J\n");
    } else if(c-'B'==0){
      sum=sum+x[i]*380000.0;
      //printf("B\n");
    }
  }
  
  printf("%f\n", sum);
  return 0;
}

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

const ll INF = 1LL << 60;

int main(void) {
  string S, T;
  cin >> S >> T;
  ll N = S.length(), M = T.length();

  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, -INF));
  REP(i, 0, N + 1) dp[i][0] = 0;
  REP(i, 0, M + 1) dp[0][i] = 0;

  REP(i, 0, N) REP(j, 0, M) {
    dp[i + 1][j + 1] = max({
      dp[i][j] + (S[i] == T[j] ? 1 : 0),
      dp[i][j + 1],
      dp[i + 1][j]
    });
  }

  string ans = "";
  for (ll i = N, j = M;;) {
    if (i - 1 >= 0 && j - 1 >= 0 && dp[i - 1][j - 1] + (S[i - 1] == T[j - 1] ? 1 : 0) == dp[i][j]) {
      if (dp[i - 1][j - 1] + 1 == dp[i][j]) {
        ans = S[i - 1] + ans;
      }
      i--;
      j--;
    } else if (i - 1 >= 0 && dp[i - 1][j] == dp[i][j]) {
      i--;
    } else if (j - 1 >= 0 && dp[i][j - 1] == dp[i][j]) {
      j--;
    }
    if (i == 0 && j == 0) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <tuple>
#include <ctime>
#include <cmath>
#include <fstream>
#include <sstream>
using namespace std;
#define INF 1000000007
#define PB push_back
#define MP make_pair
#define X first
#define Y second

typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef queue<int> QI;
typedef queue<PII> QII;
typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef set<int> SI;
typedef set<PII> SII;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(0);
	string S;
	cin >> S;
	int a=0;
	for(int i=0;i<4;i++)
	{
		if(S[i]=='-')
			a--;
		else
			a++;
	}
	cout << a << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
char c1[100],c2[100];
int f[100][30];
const int mod=1e9+7;
int main()
{	int n; cin>>n; bool b;
	scanf("%s",c1+1); scanf("%s",c2+1);
	c1[0]='#'; c2[0]='^';
	if(c1[1]==c2[1]) for(rint j=0;j<=2;j++) f[1][j*10+j]=1;
	else
	for(rint j=0;j<=2;j++)
	for(rint k=0;k<=2;k++) if(j!=k) f[1][j*10+k]=1;
	for(rint i=2;i<=n;i++)
	{	if(c1[i]==c2[i]) b=true;
		else b=false;
		if(!b&&c1[i-1]==c1[i])
		{	for(rint j=0;j<=2;j++)
			for(rint k=0;k<=2;k++)
			f[i][j*10+k]=f[i-1][j*10+k];
			continue;
		}
		for(rint j=0;j<=2;j++)
		for(rint k=0;k<=2;k++)
		{	if(j==k&&!b) continue;
			if(j!=k&&b) continue;
			for(rint l1=0;l1<=2;l1++)
			for(rint l2=0;l2<=2;l2++)
			if(l1!=j&&l2!=k) f[i][j*10+k]=(f[i][j*10+k]+f[i-1][l1*10+l2])%mod;
		}
	}
	int ans=0;
	for(rint i=0;i<=2;i++)
	for(rint j=0;j<=2;j++)
	ans=(ans+f[n][i*10+j])%mod;
	cout<<ans<<endl;
 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf 1000000000000000000
const int sz = 200006;
ll n,k;
vector<ll>h, dp;
int main() {
	io
	cin>>n;
	vector<vector<int>>ar(n, vector<int>(3));
	for(int i = 0; i<n; i++) {
		cin>>ar[i][0]>>ar[i][1]>>ar[i][2];
	}
	vector<vector<int>>dp(n, vector<int>(3));
	dp[0][0] = ar[0][0];
	dp[0][1] = ar[0][1];
	dp[0][2] = ar[0][2];
	for(int i = 1; i<n; i++) {
		dp[i][0] = max(dp[i-1][1] + ar[i][0], dp[i-1][2]+ar[i][0]);
		dp[i][1] = max(dp[i-1][2] + ar[i][1], dp[i-1][0]+ar[i][1]);
		dp[i][2] = max(dp[i-1][0]+ar[i][2], dp[i-1][1]+ar[i][2]);
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
}




Measured memory_bytes: 11264
n, m = gets.split.map(&:to_i)
$graph = Array.new(n) { Array.new(n) }
$visited = Array.new(n)
a = Array.new(m)
b = Array.new(m)

# 深さ優先探索(DFS: depth-first search)
def dfs(v, n)
  $visited[v] = true
  (0...n).each do |v2|
    next unless $graph[v][v2]
    next if $visited[v2] == true
    dfs(v2, n)
  end
end

# 隣接行列の作成
(0...m).each do |i|
  a[i], b[i] = gets.split.map(&:to_i).map {|i| i - 1}
  $graph[a[i]][b[i]] = $graph[b[i]][a[i]] = true
end

ans = 0

(0...m).each do |i|
  $graph[a[i]][b[i]] = $graph[b[i]][a[i]] = false # m番目の辺を除く(=falseにする)
  (0...n).each { |j| $visited[j] = false } # 深さ優先探索の初期化
  dfs(0, n)
  bridge = $visited.any? { |node| node == false } ? true : false # 1つでもfalseがあればtrue
  ans = ans.succ if bridge

  $graph[a[i]][b[i]] = $graph[b[i]][a[i]] = true
end
puts ans

Measured memory_bytes: 14324
hash = Array.new
ps = Array.new
loop{
  n,p = gets.split(",").map(&:to_i)
  break if(n|p)==0
  hash[n]=p
  ps<<p unless ps.include?(p)
}
ps.sort!{|a,b| b<=>a}
while n = gets do
  puts ps.index(hash[n.to_i])+1 if hash[n.to_i]
end

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    int remain = n % 1000;
    if (remain == 0)
        std::cout << 0 << "\n";
    else
        std::cout << 1000 - remain << "\n";
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int curT = 0, curX = 0, curY = 0;
    bool ok = true;
    rep(i,n){
        int t, x, y;
        cin >> t >> x >> y;
        if(t - curT < abs(curX - x) + abs(curY - y)) ok = false;
        if(abs((t - curT) - (abs(curX - x) + abs(curY - y))) % 2 == 1) ok = false;
        curT = t;
        curX = x;
        curY = y;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007
 
void solve()
{
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

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

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef pair< string, int > iP;
typedef pair< iP, int > iiP;

struct edge {
  int to;
  string spl;
};

int N, A, S, G;
vector< vector< edge > > graph;

string Dijkstra() {
  vector< vector< string > > minCost(N, vector< string >(500, "~"));
  priority_queue< iP, vector< iP >, greater< iP > > que;
  minCost[S][0] = "";
  for(int i = 0; i < graph[S].size(); i++) {
    que.push(iP(graph[S][i].spl, graph[S][i].to));
    minCost[graph[S][i].to][graph[S][i].spl.size()] = graph[S][i].spl;
  }
  
  while(!que.empty()) {
    iP p = que.top(); que.pop();
    int now = p.sc;
    string spell = p.fr;

    if(now == G){
      if(spell.size() > 240) return "NO";
      else return spell;
    }
   
    for(int i = 0; i < graph[now].size(); i++) {
      edge &e = graph[now][i];
      string next = spell + e.spl;
      if(next.size() >= 500) continue;
      if(next < minCost[e.to][next.size()]) {
        que.push(iP(next, e.to));
        minCost[e.to][next.size()] = next;
      }
    }
  }
  return "NO";
}

int main(){
  
  while(cin >> N >> A >> S >> G, N) {
    graph.resize(N);
    for(int i = 0; i < A; i++) {
      int to, from;
      string spell;
      cin >> from >> to >> spell;
      graph[from].push_back((edge){to, spell});
    }
    cout << Dijkstra() << endl;
    for(int i = 0; i < N; i++) {
      graph[i].clear();
    }
  }
}

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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n,m;
  cin>>n>>m;
  vector<int> l(m, 0);
  vector<int> r(m, 0);
  for (int i=0; i<m; i++) {
    cin>>l[i]>>r[i];
  }
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  int ans=0;
  for (int i=1; i<=n; i++) {
    if (l[m-1]<=i&&i<=r[0]) ans++;
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 1152
n, m = map(int,input().split())
x = list(map(int, input().split()))
x.sort()
r = [abs(x[i+1]-x[i]) for i in range(m-1)]
r.sort()
result = 0
for i in range(max(-1, m-n)):
    result += r[i]
print(result)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;
int dep[500001];
int deg[500001];
bool ut[500001];

int main(void){
	cin >> s;
	memset(dep,-1,sizeof(dep));
	queue<int> que;
	for(int i=0;i<s.size()+1;i++){
		if(i==0){
			if(s[i]=='<'){
				que.push(i);
				dep[i]=0;
			}else{
				deg[i]++;
			}
		}else if(i==s.size()){
			if(s[i-1]=='>'){
				que.push(i);
				dep[i]=0;
			}else{
				deg[i]++;
			}
		}else{
			if(s[i-1]=='>' && s[i]=='<'){
				que.push(i);
				dep[i]=0;
			}else{
				deg[i]=2;
				if(s[i-1]=='>'){
					deg[i]--;
				}
				if(s[i]=='<'){
					deg[i]--;
				}
			}
		}
	}
	ll ans=0;
	while(que.size()){
		int v=que.front();
		que.pop();
		//printf("%d %d\n",v,dep[v]);
		ans+=dep[v];
		ut[v]=true;
		if(v>0 && !ut[v-1]){
			deg[v-1]--;
			dep[v-1]=max(dep[v]+1,dep[v-1]);
			if(deg[v-1]==0)que.push(v-1);
		}
		if(v+1<=s.size() && !ut[v+1]){
			dep[v+1]=max(dep[v]+1,dep[v+1]);
			deg[v+1]--;
			if(deg[v+1]==0)que.push(v+1);
		}
	}
	/*
	for(int i=0;i<=s.size();i++){
		printf("%d ",dep[i]);
	}
	printf("\n");
	*/
	printf("%lld\n",ans);
	return 0;
}


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

int main()
{
    int x,i,j,k,p;

    cin>>x;

    int n[x];

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

    sort(n,n+x);

    int s=0;
    for(i=0;i<x;i++)
    {
        for(j=i+1;j<x;j++)
        {
            if(n[i]==n[j]) continue;
            p=n[i]+n[j];
            for(k=j+1;k<x;k++)
            {
                if(n[i]==n[k]||n[j]==n[k]) continue;
                if(p>n[k]) s++;
            }
        }
    }

    cout<<s<<endl;
}


Measured memory_bytes: 3620