akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define sp  set< pair<ll,ll> >
#define vp vector< pair<ll,ll> >
#define spp set< pair<pair<ll,ll>,ll> >
#define maxe 100000000
#define MOD 1000000007
#define ll long long int
#define pb push_back
#define mp  make_pair
#define sz(a) sizeof(a)
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef map<int,int> MPII;
typedef set<int> SETI;
#define ps(y,x) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define REP(i,n) FOR(i,0,(int)n-1)
#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACH_FN(v, fn) for_each(ALL(v), myobject);

#define SORT(a) sort(a.begin(),a.end())
#define RSORT(a) sort(a.rbegin(),a.rend())
#define REV(a) reverse(a.begin(),a.end())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MINIMUM(a)  *min_element(a.begin(), a.end())
#define MAXIMUM(a)  *max_element(a.begin(), a.end())
#define deb(x) cout << #x << "=" << x << endl;
#define ld long double
#define bigint int64_t
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define hurry ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define W(t)  while(t--)
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))

const int N =2e+5;


int main()
{
    hurry;


#ifndef ONLINE_JUDGE
 freopen("inputs.txt", "r",stdin);
 freopen("output.txt","w",stdout);
#endif

ll i,n,a,b,c; 
  cin>>n;
    int dp[n][3];
    cin>>a>>b>>c;
    dp[0][0]=a;
    dp[0][1]=b;
    dp[0][2]=c;

    for(i=1;i<n;i++)
    {
      cin>>a>>b>>c;
      dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
      dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));


 
}

Measured memory_bytes: 4784
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    RGB = {'R': R, 'G': G, 'B': B}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r, num_g, num_b = len(R), len(G), len(B)
    ans = num_r * num_g * num_b
    if ans == 0:
        print(0)
        return

    len_b = (B[-1] + 1)
    B1 = [0]*len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    for i in R:
        for j in G:
            if i < j:
                ans -= calc(i, j, B1, len_b)
            else:
                ans -= calc(j, i, B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9288
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>


using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair

lint mod = 1e9 + 7;
lint mypow(lint a, lint n){
  lint res = 1;
  lint base = a;
  while(n > 0){
    if (n%2) res = res*base%mod;
    base = base*base%mod;
    n = n/2;
  }
  return res;
}

lint rev(lint a){
  return mypow(a, mod-2);
}

struct ComBi {
  ComBi() = delete;
  explicit ComBi(int n){
    la.assign(n+1, 1);
    for (int i=1; i<=n; ++i) la[i] = la[i-1]*i%mod;

    rela.assign(n+1, 0);
    rela[n] = rev(la[n]);
    for (int i=n; i>=1; --i) rela[i-1] = rela[i] * i % mod;

  }

  lint comb(lint n, lint m){
    return (la[n] * rela[m] % mod) * rela[n-m] % mod;
  }

  vl la, rela;
};




int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    int k; cin>>k;
    string s; cin>>s;
    int n = s.size();

    ComBi cb(2e6 + 5);

    lint ans = 0;
    for (int l = n-1; l<= n + k-1; ++l){
        lint base =  cb.comb(l, n-1) * mypow(25, l - n +1) % mod;
        base = base * mypow(26, n + k - l-1) % mod;
        ans = (ans + base)%mod;
    }
    cout<<ans;


}



Measured memory_bytes: 35688
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int ans=0;
    for(int i=0; i<n; i++){
        ans=ans^a[i];
    }
    if(ans==0)cout << "Yes"<<endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<functional>

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

using namespace std;

bool dfs(int i);

int n,a[50];

bool fil[50];

bool dfs2(int i,int j,int rem){ // partition
	if(rem==0) return dfs(i+1);
	if(j==n) return false;

	if(!fil[j] && a[j]<=rem){
		fil[j]=true;
		if(dfs2(i,j+1,rem-a[j])) return true;
		fil[j]=false;
	}
	return dfs2(i,j+1,rem);
}

bool dfs(int i){
	if(i==n) return true;

	if(!fil[i]) return false;

	return dfs2(i,i+1,a[i]) || dfs(i+1);
}

int main(){
	for(;scanf("%d",&n),n;){
		rep(i,n){
			scanf("%d",a+i);
			fil[i]=false;
		}
		sort(a,a+n,greater<int>());
		fil[0]=true;
		puts(dfs(0)?"YES":"NO");
	}

	return 0;
}

Measured memory_bytes: 1028
s = list(input())[::-1] + [0,0]
N,i,ans = len(s),0,0

while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
            temp = 1
            i += 2
            while i < N:
                if s[i] == 'A':
                    ans += temp
                    i += 1
                elif s[i] == 'C' and s[i+1] == 'B':
                    temp += 1
                    i += 2
                else:
                    break
    else:   i += 1

print(ans)




Measured memory_bytes: 6308
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

int main() {
  ll n;
  cin >> n;

  bool fw = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a % 2 == 1) {
      fw = true;
      break;
    }
  }

  string ans = fw ? "first" : "second";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef struct {
	int id, score;
} team_t;

int cmp(const team_t *x, const team_t *y) {
	return y->score - x->score;
}
int main() {
	team_t team[9999];
	int n, id, i, rank, prevscore;
	for(n=0; scanf("%d,%d", &team[n].id, &team[n].score),team[n].id; n++)
		if(n==1000) return 0;
	qsort(team, n, sizeof(team_t), cmp);
	while(~scanf("%d",&id)) {
		rank=0;
		prevscore=-1;
		for(i=0;i<n;i++) {
			if(team[i].score != prevscore)
				rank++;
			prevscore = team[i].score;
			if(team[i].id == id) {
				printf("%d\n", rank);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
const int mod=1000000007;
long long x,s;

int main()
{
    int n,k,i;
    cin>>n>>k;n;
    for(i=k;i<=n+1;i++)
    {
        x=((long long)n*(n+1)/2-(long long)(n-i)*(n-i+1)/2-(long long)(i-1)*i/2+1)%mod;
        s=(s+x)%mod;
    }
    cout<<s%mod;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
using namespace std;


int main(){
	int n;
	cin >>n;
	int a[n];
	int i;
	rep(i,n){
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	rep(i,n){
		if(i == a[a[i]])
			ans++;
	}
	ans/=2;

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int a;
  int left  = 0,right = 0;
  rep(i,m){
    cin >> a;
    if(x > a) left++;
    else right ++;
  }
  cout << min(left,right) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
// N 为邻接矩阵的大小
#define N 10001
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1 << 21

using namespace std;

int color[N], d[N], p[N];
vector<pair<int, int> > adj[N];

void dijkstra (int s, int n) {
  priority_queue<pair<int, int> > PQ;

  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[s] = 0;
  p[s] = -1;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while (PQ.size()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;

    color[u] = BLACK;

    // 取出最小值，如果不是最短路径就忽略
    if (d[u] < f.first * (-1))
      continue;
    
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;

      if (color[v] != BLACK && d[u] + adj[u][j].second < d[v]) {
        d[v] = d[u] + adj[u][j].second;
        p[v] = u;
        // 优先队列默认优先较大值，因此要乘以 -1
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
}

int main () {
  int n, u, v, degree, cost;
  
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> u >> degree;
    
    for (int j = 0; j < degree; j++) {
      cin >> v >> cost;
      
      adj[i].push_back(make_pair(v, cost));
    }
  }

  dijkstra(0, n);

  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;

  return 0;
}


Measured memory_bytes: 8008
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    tmp = min(a[i], b[i])
    ans += tmp
    a[i] -= tmp
    b[i] -= tmp
    tmp = min(a[i+1], b[i])
    ans += tmp
    a[i+1] -= tmp
    b[i] -= tmp
print(ans)

Measured memory_bytes: 82148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		boolean dp[] = new boolean[100010];

		dp[0] = true;
		for (int i = 1; i < dp.length; i++) {
			if (i < 100) {
				dp[i] = false;
			} else if (dp[i - 100] || dp[i - 101] || dp[i - 102] || dp[i - 103] || dp[i - 104] || dp[i - 105]) {
				dp[i] = true;
			} else {
				dp[i] = false;
			}
		}

		if (dp[n]) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21460
//author : 'Amit Singh Sansoya @amit3200'
//it was all meant to happen as i was all talk!
#include<bits/stdc++.h>
using namespace std;
vector<int> dp,arr;
int n;
int main(){
	cin>>n;
	dp.resize(n+1,INT_MAX);
	for(int i=0;i<n;i++){
		int data;
		cin>>data;
		arr.push_back(data);
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		if(i+1<n) dp[i+1]=min(dp[i]+abs(arr[i+1]-arr[i]),dp[i+1]);
		if(i+2<n) dp[i+2]=min(dp[i]+abs(arr[i+2]-arr[i]),dp[i+2]);
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
      	if (k < n) {
        	System.out.println(x * k + y * Math.max(n - k, 0));  
        } else {
          	System.out.println(x * n);
        }
        
        
    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a,b;
    cin >> a>>b;

    int ret = a-2*b;
    if(ret<0) ret = 0;

    cout << ret << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount

const llong mxn = 1e6 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, a[mxn], k, dp[1001][1001], sum[mxn];
bool ok = 0;

int main (){
    cin >> n;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }for (int i = 1; i <= n; i ++){
        sum[i] = sum[i - 1] + a[i];
    }for (int l = 2; l <= n; l ++){
        for (int i = 1; i <= n - l + 1; i ++){
            llong j = i + l - 1;
            if(l == 2){
                dp[i][j] = sum[j] - sum[i - 1];
            }for (int x = i; x < j; x ++){
                if(dp[i][j]){
                    dp[i][j] = min(dp[i][j], dp[i][x] + dp[x + 1][j] + sum[j] - sum[i - 1]);
                }else{
                    dp[i][j] = dp[i][x] + dp[x + 1][j] + sum[j] - sum[i - 1];
                }
            }
        }
    }cout << dp[1][n] << endl;
    /*for (int i = 1; i <= n; i ++){
        for (int j = 1; j <= n; j ++){
            cout << dp[i][j] << ' ';
        }cout << endl;
    }*/
    return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
int main(void)
{
  int num,i, flag=0;
  scanf("%d", &num);
  for(i=0;i<3;i++) {
    if(num%10==7)
      flag=1;
    num=num/10;
  }
  if(flag==1)
    puts("Yes");
  else
    puts("No");
  return 0;
}

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

int main(){
	char s[2000001];
	gets(s);
//	printf("%s\n", s);
	int n=strlen(s), ans=0;
	char t[n];
	for(int i=0; i< n; i++){
		scanf("%c", &t[i]);
		if(s[i]!=t[i])ans++;
//		printf("%c\n", t[i]);
//		printf("%c\n", s[i]);
//		printf("%d\n", ans);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 2100
#include <iostream>

void countingSort(int* A, int* B, int n)
{
	int C[10001];
	for (int i=0; i<10001; i++) C[i] = 0;
	for (int j=0; j<n; j++) C[A[j]]++;
	for (int i=1; i<10001; i++) C[i] += C[i-1];
	for (int j=n-1; j>=0; j--) {
		B[C[A[j]]-1] = A[j];
		C[A[j]]--;
	}
}

int main()
{
	int n;
	std::cin >> n;
	
	int *A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	
	int *B = new int[n];
	countingSort(A, B, n);
	
	std::cout << B[0];
	for (int i=1; i<n; i++) std::cout << " " << B[i];
	std::cout << std::endl;
	
	delete[] A;
	delete[] B;
	
	return 0;
}




Measured memory_bytes: 18296
import math
N,M = map(int,input().split())
n = max(N,M)
m = min(N,M)
if abs(N-M) > 1:
  print(0)
  exit()

ncnt = math.factorial(n) % 1000000007

if abs(N-M) == 0:
  mcnt = 2 * ncnt
else:
  mcnt = math.factorial(m)
print(ncnt*mcnt % 1000000007)

Measured memory_bytes: 9940
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n, m, A[100][100] , b[100], c[100];
    
    cin >> n >> m;
    for (int i=0; i<n; i++)
        for(int j=0; j<m; j++) cin >> A[i][j];
    for(int i=0; i<m; i++) cin >> b[i];
    
    for( int i=0; i<n; i++){
        c[i] = 0;
        for(int j=0; j<m; j++){
            c[i] += A[i][j]*b[j];
        }
    }
    
    for(int i=0; i<n; i++)cout << c[i] << endl;
        return 0;
}



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

vector<P> prime_factor(ll n){
    vector<P> pf;
    for(ll i = 2; i*i <= n; i++){
        if(n%i == 0){
            int cnt = 0;
            while(n%i == 0){
                n /= i;
                cnt++;
            }
            pf.push_back(P(i, cnt));
        }
    }
    if(n != 1) pf.push_back(P(n, 1));
    return pf;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    int cnt_2 = 0, cnt_4 = 0;
    rep(i, 0, n){
        if(a[i]%4 == 0) cnt_4++;
        else if(a[i]%2 == 0) cnt_2++;
    }
    if(cnt_2 == 0 && cnt_4*2 + 1 >= n) cout << "Yes" << endl;
    else if(cnt_4*2 >= n - cnt_2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3984
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
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 long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int count=0;
    for(int i=100;i>=1;i--){
        if(a%i==0&&b%i==0){
            count++;
            if(count==k){
                cout<<i<<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
program abc9
 implicit none
 integer::N,i,x,y,z,s,t,sa=0,sb=0,sc=0
 read(*,*)N
 do i=1,N
  t=int(sqrt(dble(i))-1)+1
  s=0
  sa=0
  sb=0
  sc=0
  do x=1,t
   do y=x,t
    do z=y,t
     if(x**2+y**2+z**2+x*y+y*z+z*x==i)then
      if(x==y.and.y==z)then
       sb=sb+1
      else if(x==y.or.y==z.or.z==x)then
       sa=sa+1
      else
       sc=sc+1
      end if
     end if
    end do
   end do
  end do
 s=sc*6+sa*3+sb
  print'(i0)',s
 end do
end program abc9

Measured memory_bytes: 2804
let hd x i = String.sub x 0 i ;;
let md x i j = String.sub x i (j + 1 - i) ;;
let tl x i j = String.sub x (j+1) (String.length x - 1 - j);;

let replace x y i j = hd x i ^ y ^ tl x i j;;
let reverse x i j  =
  let rec rev s k res =
    if k = String.length s then List.fold_left (fun e x -> e ^ x) "" res
    else rev s (k+1) ((String.sub s k 1) :: res)
  in
  hd x i ^ rev (md x i j) 0 [] ^ tl x i j ;;
let print x i j = print_endline (md x i j) ;;

let () =
  let str = read_line() in
  let m = read_int() in
  let rec loop line n =
    if n = 0 then ()
    else
      let lst = Str.split (Str.regexp " ") (read_line()) in
      let i = int_of_string (List.nth lst 1) in
      let j = int_of_string (List.nth lst 2) in
      try
        (match List.hd lst with
          "replace" -> let r = List.nth lst 3 in loop (replace line r i j) (n-1)
        | "reverse" -> loop (reverse line i j) (n-1)
        | _ -> raise Not_found)
      with Not_found -> print line i j ; loop line (n-1) 
  in
  loop str m ;;


Measured memory_bytes: 4148
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    long long a,b,x;
    cin >> a >> b >> x;
    long long minimum,maximum;
    if(a%x==0) minimum = a;
    else minimum = (a/x+1) * x;
    if(b%x==0) maximum = b;
    else maximum = (b/x) * x;
    cout << (maximum-minimum)/x + 1 << endl;
    
    return 0;
}

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

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

using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;

int main(int, char**)
{
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    rep(_,k) {
        vector<int> d(n, 0);
        int endcntl = 0, endcntr = 0;
        rep(i,n) {
            int l = max(0, i-a[i]);
            int r = min(n-1, i+a[i]);
            d[l]++;
            if (r+1 < n) d[r+1]--;
            if (l==0) endcntl++;
            if (r+1 >= n) endcntr++;
        }
        rep(i,n) {
            if (!i) a[i] = d[i];
            else a[i] = a[i-1] + d[i];
        }
        if (endcntl == n && endcntr == n) break;
    }
    rep(i,n) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 4780
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
if N % 2 != 0:
    for i in range(N-1, -1, -2):
        print(A[i], end=" ")
    for i in range(1, N, 2):
        print(A[i], end=" ")
else:
    for i in range(N-1, 0, -2):
        print(A[i], end=" ")
    for i in range(0, N, 2):
        print(A[i], end=" ")

Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    reverse(all(a));

    multiset<int> st;
    rep(i, n) {
        auto id = st.upper_bound(a[i]);
        if(id != st.end()) st.erase(id);
        st.insert(a[i]);
    }

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

Measured memory_bytes: 5760
N = int(input())
A = list(map(int, input().split()))

if N == 2:
  A.sort()
  print(A[1] - A[0])
  print(A[1], A[0])
  exit()

p = []
m = []
for i in A:
  if i > 0:
    p.append(i)
  else:
    m.append(i)

p.sort()
m.sort()
ans = [[0, 0]] * (N - 1)
cnt = 0

if len(m) == 0:
  ans[0] = [p[0], p[1]]
  k = p[0] - p[1]
  for i in range(1, N - 2):
    ans[i] = [k, p[i + 1]]
    k -= p[i + 1]
  ans[-1] = [p[-1], k]
  k = p[-1] - k
elif len(p) == 0:
  ans[0] = [m[-1], m[0]]
  k = m[-1] - m[0]
  for i in range(1, N - 1):
    ans[i] = [k, m[i]]
    k -= m[i]
else:
  k = m[0]
  for i in range(len(p) - 1):
    ans[i] = [k, p[i]]
    k -= p[i]
  ans[len(p) - 1] = [p[-1], k]
  k = p[-1] - k
  for i in range(1, len(m)):
    ans[len(p) - 1 + i] = [k, m[i]]
    k -= m[i]

print(k)
for a, b in ans:
  print(a, b)

Measured memory_bytes: 23016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    double a, b, x; cin >> a >> b >> x;
    double lim = a * a * b;

    double ans = -1;
    if (x <= lim / 2) {
        double ok = 0, ng = a;
        FOR(i, 0,30) {
            double mid = (ok + ng) / 2;
            if (a * b * mid / 2 <= x)ok = mid;
            else ng = mid;
        }
        ans = pi / 2 - atan(ok / b);
    }
    else {
        double ok = 0, ng = b;
        FOR(i, 0, 30) {
            double mid = (ok + ng) / 2;
            if (a * a * mid / 2 <= lim - x)ok = mid;
            else ng = mid;
        }
        ans = atan(ok / a);
    }
    cout << ans / pi * 180 << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = (1 << 20);
const int K = 300000;
int dp[110][40000], s1[110][40000], s2[110][40000];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    int sr = 1;
    while((sr + 1) * (sr + 1) <= n){
        sr++;
    }
    dp[0][1] = 1;
    for (int j = 1; j <= sr; j++){
        s1[0][j] = (s1[0][j - 1] + dp[0][j]) % mod;
        s2[0][j] = (s2[0][j - 1] + dp[0][j] * (n / j)) % mod;
    }
    for (int i = 1; i <= k; i++){
        for (int j = 1; j <= sr; j++){
            dp[i][j] = s1[i - 1][sr];
            if (i != 1){
                dp[i][j] = (dp[i][j] + (n / j) * s1[i - 2][j] + (s2[i - 2][sr] - s2[i - 2][j] + mod) - sr * s1[i - 2][sr] % mod + mod) % mod;
            }
            s1[i][j] = (s1[i][j - 1] + dp[i][j]) % mod;
            s2[i][j] = (s2[i][j - 1] + (n / j) * dp[i][j]) % mod;
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }
    }
    int ans = 0;
    for (int j = 1; j <= sr; j++){
        ans = (ans + dp[k][j]) % mod;
        ans = (ans + ((n / j) - sr) * dp[k - 1][j]) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 100224
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll cnt(64,0) ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		for(int j=0;j<64;j++) if((a>>j)&1) cnt.at(j)++ ;
	}
	vll dp1(64,-1),dp2(64,0) ;
	dp2.at(63) = 0 ;
	for(int i=45;i>=0;i--){
		if((k>>i)&1){
			if(dp1.at(i+1)!=-1) dp1.at(i) = dp1.at(i+1)+max(cnt.at(i),n-cnt.at(i))*(1LL<<i) ;
			dp1.at(i) = max(dp1.at(i),dp2.at(i+1)+cnt.at(i)*(1LL<<i)) ;
			dp2.at(i) = dp2.at(i+1)+(n-cnt.at(i))*(1LL<<i) ;
		}else{
			if(dp1.at(i+1)!=-1) dp1.at(i) = dp1.at(i+1)+max(cnt.at(i),n-cnt.at(i))*(1LL<<i) ;
			dp2.at(i) = dp2.at(i+1)+cnt.at(i)*(1LL<<i) ;
		}
	}
//	for(int i=10;i>=0;i--) cout << dp1.at(i) << " " << dp2.at(i) << endl ;
//	for(int i=0;i<10;i++) cout << cnt.at(i) << endl ;
	cout << max(dp1.at(0),dp2.at(0)) << endl ;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{

  ll n;
  cin >> n;
  vector<ll> ls;
  for (auto i = 0; i < n; i++)
  {
    ll l;
    cin >> l;
    ls.push_back(l);
  }

  sort(ls.begin(), ls.end());
  ll ans = 0;
  for (ll i = n - 1; i >= 0; i--)
  {
    for (ll j = i - 1; j >= 0; j--)
    {
      ll min = ls[i] - ls[j] + 1; // 下限
      auto itr = lower_bound(ls.begin(), ls.end(), min);
      ll index = distance(ls.begin(), itr);
      if (index < j)
      {
        ans += j - index;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;


int main() {
    ll n;
    cin >> n;

    cout << (1000 - (n % 1000)) % 1000 << endl;
}


Measured memory_bytes: 3640
import math
a,b,h,m = map(int,input().split())
hthta = 30*h+0.5*m
mthta = 6*m

thta = abs(hthta-mthta)
if thta > 180:
    thta = 360-thta

rad = math.radians(thta)
print((a**2+b**2-2*a*b*math.cos(rad))**0.5)

Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int D,cnt[19],ans;ll b[20];
void dfs(int x,ll res,int L,int now)
{
    if(x>(L>>1)-1){if(res==D) ans+=now*(L&1?10:1);return;}
    ll i=-9ll;while(i<9ll&&res+(i+1ll)*(b[L-x-1]-b[x])<=D) ++i;
    dfs(x+1,res+i*(b[L-x-1]-b[x]),L,now*(x==0&&i>=0?cnt[i+9]-1:cnt[i+9]));
    if(++i<=9) dfs(x+1,res+i*(b[L-x-1]-b[x]),L,now*(x==0&&i>=0?cnt[i+9]-1:cnt[i+9]));
}
int main()
{
    scanf("%d",&D);
    b[0]=1ll;for(int i=1;i<19;++i) b[i]=b[i-1]*10ll;
    for(int i=0;i<=9;++i) for(int j=0;j<=9;++j) ++cnt[i-j+9];
    for(int i=1;i<=18;++i) dfs(0,0,i,1);
    printf("%d",ans);
}

Measured memory_bytes: 3828
#include <stdio.h>

int main() {
	int day_num[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int m, d;
	char name[7][16] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

	int day_count;
	int i;

	while(1) {
		day_count = 0;
		scanf("%d %d", &m, &d);
		if(m == 0) break;

		for(i = 0; i < m - 1; i++)
			day_count += day_num[i];

		day_count += d;

		printf("%s\n", name[day_count % 7]);
	}

	return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<queue>
#include<utility>
using namespace std;
void search(int, int);
int c[60][60] = {}, map[60][60] = {};
void mapDraw(int,int);
queue< pair<int, int> > q;
int w, h;

int main() {

	while (1) {
		
		//initialize
		int count = 0;
		for (int i = 0; i < 60; i++) {
			for (int j = 0; j < 60; j++) {
				c[i][j] = 0;
				map[i][j] = 0;
			}
		}


		cin >> w >> h;
		if (w == 0 && h == 0) break;
		//input
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> c[i][j];
			}
		}

		//search
		//unresearched:0, land:2, sea:1
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == 0) {
					map[i][j] = c[i][j] + 1;
					if (c[i][j] == 1) {
						q.push(make_pair(i, j));
						count++;
					}
				}

				pair<int, int> cur = make_pair(i, j);
				while (!q.empty()) {
					cur = q.front();
					int x = cur.second;
					int y = cur.first;
					q.pop();

					//cerr << "( " << y << ", " << x << " )now"<< endl;

					for (int a = -1; a <= 1; a++) {
						for (int b = -1; b <= 1; b++) search(y + a, x + b);
					}
				}
			}
		}

		cout << count << endl;
	}


	return 0;
}

void search(int i, int j) {
	if (i < h&&i >= 0 && j < w&&j >= 0) {
		if (map[i][j] == 0) {
			map[i][j] = c[i][j] + 1;
			if (c[i][j] == 1) q.push(make_pair(i, j));
		}
	}
	//mapDraw(w, h);
}

void mapDraw(int w, int h) {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cerr << map[i][j];
		}
		cerr << endl;
	}
	cerr << endl;
}

Measured memory_bytes: 1244
Var n,i,rem:Longint;
    S:Ansistring;
Begin
    Readln(n);
    Readln(S);
    For i:=1 to length(S) do begin
        rem:=ord(S[i])+n;
        If rem>90 then rem:=rem-26;
        S[i]:=chr(rem);
    End;
    Writeln(S);
End.

Measured memory_bytes: 128
# coding : utf-8 

N = int(input())
n = {}
for i in range(N):
    st = input()
    if st in n:
        n[st] += 1
    else:
        n[st] = 1
M = int(input())
m = {}
for i in range(M):
    st = input()
    if st in m:
        m[st] += 1
    else:
        m[st] = 1
maxl = 0
for st,i in n.items():
    if st not in m:
        maxl = max(i,maxl)
    else:
        maxl = max(i-m[st],maxl)

print(maxl)


Measured memory_bytes: 3064
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
// typedef vector<int> v;

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //




int main() {
  int a,b;
  cin >> a >> b;
  if (a >= b) {
    rep(i, a) cout << b;
    cout << endl;
  } else {
    rep(i, b) cout << a;
    cout << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

int main()
{
	int32_t N;
	scanf("%d", &N);

	int32_t t[101];
	int32_t T = 0;
	for (int32_t i = 0; i < N; i++) {
		scanf("%d", &t[i]);
		T += t[i];
	}

	double max_v[40001];
	int32_t max_v_index = 0;
	int32_t prev_v = 100000;
	for (int32_t i = 0; i < N; i++) {
		int32_t v;
		scanf("%d", &v);

		for (int32_t j = 0; j < 2 * t[i]; j++)
			max_v[max_v_index++] = (i > 0 && j == 0) ? min(prev_v, v) : v;
		prev_v = v;
	}

	max_v[0] = 0;
	max_v[2 * T] = 0;

	for (int32_t i = 1; i < 2 * T + 1; i++)
		max_v[i] = min(max_v[i], max_v[i - 1] + 0.5);
	for (int32_t i = 2 * T - 1; i >= 0 ; i--)
		max_v[i] = min(max_v[i], max_v[i + 1] + 0.5);

	double res = 0;
	for (int32_t i = 0; i < 2 * T; i++) {
		res += min(max_v[i], max_v[i + 1]) * 0.5;
		if (max_v[i] != max_v[i + 1])
			res += 0.5 * 0.5 / 2;
	}

	printf("%.17f\n", res);

	return 0;
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.util.Scanner;

public class Main {


	public static void main(String args[]) {
        InputStream inputStream = System.in;
        Scanner sc = new Scanner(inputStream);
        String out;
        int A = sc.nextInt();
        int B=sc.nextInt();
        if(B==100) {B+=1;}
        int C=(int)Math.pow(100,A)*B;
        System.out.print(C);
	}

}

Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h> 
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  if(s[n]=='1'){
    cout << -1 << endl;
    return 0;
  }
  int cnt=0;
  int posi=0;
  while(posi<=n){
    int subcnt=0;
    while(posi<=n && s[posi]=='1'){
      subcnt++;
      posi++;
    }
    cnt=max(cnt,subcnt);
    posi++;
  }
  if(cnt>=m){
    cout << -1 << endl;
    return 0;
  }
  reverse(s.begin(),s.end());
  vector<int> ans;
  vector<int> v;
  rep(i,n)if(s[i]=='0')v.push_back(i);
  int pos=0;
  while(pos<n){
    while(pos+m<n && s[pos+m]=='0'){
      pos+=m;
      ans.push_back(m);
    }
    if(pos+m>=n){
      ans.push_back(n-pos);
      break;
    }
    int x=upper_bound(v.begin(),v.end(),pos+m)-v.begin();
    ans.push_back(v[x-1]-pos);
    pos=v[x-1];
  }
  reverse(ans.begin(),ans.end());
  rep(i,ans.size())cout << ans[i] << ' ';
  cout << endl;
return 0;}

Measured memory_bytes: 1592
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 , INF = 1e9;
int dp[maxn],n,m;
vector<int> grafo[maxn];

int solve( int v )
{

	if( dp[v]  !=  -INF )
		return dp[v];

	for( int x = 0 ; x < grafo[v].size() ; x++ )
		dp[v] = max( solve( grafo[v][x] ) , dp[v] );

	if( dp[v]  ==  -INF )
		dp[v] = -1;

	dp[v]++;


	return dp[v];

}



int main(){


	for(int x = 0 ; x < maxn ; x++ )
		dp[x] = -INF;


	scanf("%d%d",&n,&m);
	for(int x=0;x<m;x++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		grafo[a].push_back(b);
	}


	int resp = -INF;
	for( int x = 1 ; x <= n ; x++ )
	{
		solve( x );
		resp = max( resp , dp[x] );

	}


	printf("%d\n",resp);

}

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

using namespace std;

using ll = long long;

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

    ll n, min_v = 100;
    cin >> n;

    for (ll x = 1; x * x <= n; ++x) {
        if (n % x != 0) continue;
        ll len = max(log10(x) + 1, log10(n / x) + 1);
        min_v = min(min_v, len);
    }

    cout << min_v << endl;

    return 0;
}


Measured memory_bytes: 640
// written by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

const int mod = 1e9 + 7;
int power(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = 1ll * ret * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return ret;
}

int c[503], fac[503], iFac[503], bin[103][503], dp[503][503][503];
void add(int &x, const int &y) {
  x += y - mod;
  x += (x >> 31) & mod;
}
void dec(int &x, const int &y) {
  x -= y;
  x += (x >> 31) & mod;
}

int main() {
  int n, X;
  scanf("%d%d", &n, &X);
  for (int i = 1; i <= n; ++i) {
    int l;
    scanf("%d", &l);
    ++c[l];
  }
  fac[0] = 1;
  for (int i = 1; i <= X + 1; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  iFac[X + 1] = power(fac[X + 1], mod - 2);
  for (int i = X + 1; i; --i)
    iFac[i - 1] = 1ll * iFac[i] * i % mod;
  for (int i = 0; i <= n; ++i) {
    bin[i][0] = 1;
    for (int j = 1; j <= X; ++j)
      bin[i][j] = 1ll * bin[i][j - 1] * i % mod;
  }
  
  dp[X + 1][0][0] = 1;
  for (int i = X; i; --i)
    for (int k = 0; k <= X; ++k)
      for (int j = 0; i * j <= k; ++j) {
        for (int l = 0; l <= j; ++l)
          add(dp[i][j][k], 1ll * dp[i + 1][j - l][k - i * l] * iFac[l] % mod);
        dp[i][j][k] = 1ll * dp[i][j][k] * power(k - (i - 1) * j, c[i]) % mod;
      }
  int ans = 0;
  for (int i = 0; i <= X; ++i)
    for (int j = 0; j <= X - i + 1; ++j) {
      int temp = 1ll * fac[X - j + 1] * iFac[X - j + 1 - i] % mod *
        dp[1][i][j] % mod;
      (X - j) & 1 ? dec(ans, temp) : add(ans, temp);
    }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 495232
#include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    int main(void){
        int i, m, l, p, h;
        char s[201], sc[201], sn[201], hp;
        while(1){
            scanf("%s", s);
            if(s[0] == '-') break;
            l = strlen(s);
            scanf("%d", &m);
            for(i = 0; i < m; ++i){
                scanf("%d", &h);
                if(i % 2 == 0){
                    for(int j = 0; j < h; ++j) sc[j] = s[j];
                    for(int k = h; k < l; ++k) sn[k - h] = s[k];
                    sc[h] = '\0';
                    sn[l - h] = '\0';
                    strcat(sn, sc);
                    p = 0;
                }else{
                    for(int j = 0; j < h; ++j) sc[j] = sn[j];
                    for(int k = h; k < l; ++k) s[k - h] = sn[k];
                    sc[h] = '\0';
                    s[l - h] = '\0';
                    strcat(s, sc);
                    p = 1;
                }
            }
            if(p) printf("%s\n", s);
            else printf("%s\n", sn);
        }
        return 0;
    }


Measured memory_bytes: 2148
//枝内における最大コストの求め方がよく理解できない。
#include<iostream>
#include<math.h>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int,int> P;

int N,M,K;		//町数、道の数、店舗数
struct NODE{
	vector<int> cost,list;
	int minest;	//頂点から店への最短距離
}MISE[3000];

void Ini(int *a,int index,int num){
	for(int i = 0;i < index;i++){
		a[i] = num;
	}
}
void Dijkstra(int left){
	priority_queue<P,vector<P>,greater<P> > que;
	int done[3000],DEFINEED = 0;
	int nowcost[3000];
	P edge;
	Ini(done,N,-1);
	Ini(nowcost,N,500000000);
	que.push(P(0,left));
	while(DEFINEED < N && !que.empty()){
		edge = que.top();
		que.pop();
		if(done[edge.second] >= 0)
			continue;
		DEFINEED++;
		done[edge.second] = edge.first;
		//確定した頂点から枝を出す
		int lsize;
		lsize = MISE[edge.second].list.size();
		for(int i = 0;i < lsize;i++){
			if(done[MISE[edge.second].list[i]] == -1 && nowcost[MISE[edge.second].list[i]] > edge.first+MISE[edge.second].cost[i]){
				nowcost[MISE[edge.second].list[i]] = edge.first+MISE[edge.second].cost[i];
				que.push(P(nowcost[MISE[edge.second].list[i]],MISE[edge.second].list[i]));
			}
		}
	}
	for(int  i = 0;i < N;i++){
		if(MISE[i].minest > done[i] && done[i] != -1)
			MISE[i].minest = done[i];
	}
}
int main(){
	int i,a,b,c;
	int Mplace;
	cin >> N >> M >> K;
	for(i = 0;i < N;i++){
		MISE[i].minest = 500000000;
	}
	for(i = 0;i < M;i++){
		cin >> a >> b >> c;
		a--;b--;
		//隣接リスト作成。道の生成による影響は2ノード間にのみ作用する。
		MISE[a].list.push_back(b);
		MISE[a].cost.push_back(c);
		MISE[b].list.push_back(a);
		MISE[b].cost.push_back(c);
	}
	for(i = 0;i < K;i++){
		cin >> Mplace;
		Mplace--;
		Dijkstra(Mplace);
	}
	double D_length;
	int I_length,I_Mlength = 0;
	for(i = 0;i < N;i++){
		//枝の間が一番距離が長くなりそう(嘘
		int lsize;
		lsize = MISE[i].list.size();
		for(int j = 0;j < lsize;j++){
			D_length = (double)MISE[i].cost[j]/2.0;
			D_length += (MISE[i].minest+MISE[MISE[i].list[j]].minest)/2.0;
			if(D_length - (int)D_length == 0)
				I_length = (int)D_length;
			else
				I_length = (int)D_length+1;
			if(I_Mlength < I_length)
				I_Mlength = I_length;
		}
	}
	cout << I_Mlength << endl;
	return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
using namespace std;
const int MOD=1000000007;
const ll MAX=9187201950435737471;
const int N=100005;
const ll INF=1e14;

ll a[N][4];
ll dp[N][4];
int m[]={0,1,2};

int main() {
    fastio

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<3;i++)dp[0][i]=a[0][i];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(k!=j){
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
            }
        }
    }
    ll ans=0;
    for(int i=0;i<3;i++)ans=max(ans,dp[n-1][i]);
    cout<<ans;
	return 0;
}



Measured memory_bytes: 6528
using System;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        long[] nk = Scan.LongArray(2);
        long n, k;
        n = nk[0]; k = nk[1];
        long[] a = Scan.LongArray((int)n);
        string[] a_bin = new string[n];
        string k_bin = Convert.ToString(k, 2);
        string d_bin = "";
        for (int i = 0; i < n; i++)
        {
            a_bin[i] = Convert.ToString(a[i], 2).PadLeft(k_bin.Length, '0');
        }
        for (int i = 0; i < k_bin.Length; i++)
        {
            int cnt = 0;
            for (int j = 0; j < n; j++)
            {
                if(a_bin[j][a_bin[j].Length-1-i] == '0')
                {
                    cnt++;
                }
            }
            if(cnt*2 > n)
            {
                d_bin = Str.Connect("1", d_bin);
            }
            else
            {
                d_bin = Str.Connect("0", d_bin);
            }
        }
        string blank = "";
        long ans = 0;
        Queue<string> q = new Queue<string>();
        q.Enqueue(blank);
        while(q.Count != 0)
        {
            string s = q.Dequeue();
            int len = s.Length;
            if(len == k_bin.Length)
            {
                ans = Math.Max(ans, F(s, a));
            }
            else
            {
                if(k_bin[k_bin.Length-d_bin.Length+len] == '0')
                {
                    q.Enqueue(Str.Connect(s,"0"));
                }
                else if(k_bin[k_bin.Length - d_bin.Length + len] == '1' && d_bin[len] == '0')
                {
                    s = Str.Connect(s, d_bin.Substring(s.Length));
                    q.Enqueue(s);
                }
                else
                {
                    string s0 = Str.Connect(s, "0");
                    s0 = Str.Connect(s0, d_bin.Substring(s0.Length));
                    q.Enqueue(s0);
                    q.Enqueue(Str.Connect(s,"1"));
                }
            }
        }
        Out.Num(ans);
    }

    public static long F(string s, long[] a)
    {
        long ans = 0;
        long sl = Convert.ToInt64(s, 2);
        for (int i = 0; i < a.Length; i++)
        {
            ans += sl ^ a[i];
        }
        return ans;
    }

}

public class Str
{
    public static string Connect(string a, string b)
    {
        StringBuilder sb = new StringBuilder(a);
        sb.Append(b);
        return sb.ToString();
    }
}
public class Scan
{
    public static long[] LongArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] ar = new long[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = long.Parse(str[i]);
        }
        return ar;
    }
}

public class Out
{
    public static void Num<T>(T a)
    {
        Console.WriteLine(a);
    }
}

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

const int N = 2 * 1000 * 100 + 100;
string s[N], t[N];
map<string, int> cnt;
int n, size;

int main() { 
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		if (cnt[t[i]] == 0)
			s[size++] = t[i];
		cnt[t[i]]++;
	}
	sort(s, s + size);
	int mx = 0;
	for (int i = 0; i < size; i++)
		mx = max(mx, cnt[s[i]]);
	for (int i = 0; i < size; i++)
		if (cnt[s[i]] == mx)
			cout << s[i] << endl;
	return 0;
}


Measured memory_bytes: 27008