akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int MAXN = 3e5;
int N;

int A[MAXN];

pair<ll, ll> sums[2][MAXN];

void go(int z) {
	ll totsum = 0;
	ll jsum = 0;
	for (int i = 0, j = 0; i < N; i++) {
		totsum += A[i];
		for (; jsum < totsum - jsum; j++) {
			jsum += A[j];
		}
		assert(j > 0);
		if (abs(jsum - (totsum - jsum)) < abs(jsum - A[j-1] - (totsum - (jsum - A[j-1])))) {
			sums[z][i+1] = {jsum, totsum - jsum};
		} else {
			sums[z][i+1] = {jsum - A[j-1], totsum - (jsum - A[j-1])};
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int z = 0; z < 2; z++) {
		go(z);
		reverse(A, A + N);
	}

	reverse(sums[1], sums[1] + N + 1);
	ll ans = 1e18;
	for (int i = 2; i+1 < N; i++) {
		vector<ll> buf;
		for (int z = 0; z < 2; z++) {
			buf.push_back(sums[z][i].first);
			buf.push_back(sums[z][i].second);
		}
		ans = min(ans, *max_element(buf.begin(), buf.end()) - *min_element(buf.begin(), buf.end()));
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 10496
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    final int MOD = 1000000007;
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    List<Integer> factorials = new ArrayList<>();
    int k = M;
    for (int i = 2; i <= M && k > 1; i++) {
      int count = 0;
      while (k % i == 0) {
        count++;
        k /= i;
      }
      if (count > 0) factorials.add(count);
    }

    long count = 1;
    for(int f : factorials) {
      count = (count * choose(f + N - 1, f, MOD)) % MOD;
    }
    System.out.println(count);
  }

  public static long choose(long n, long k, long mod) {
    if (k > n - k) return choose(n, n - k, mod);
    long res = 1;
    for (int i = 0; i < k; i++) {
      res = (res * (n - i)) % mod;
    }
    for (int i = 1; i <= k; i++) {
      res = (res * inverse(i, mod)) % mod;
    }
    return res % mod;
  }

  public static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  public static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 23892
// Problem : D - Partition
// Contest : AtCoder - AtCoder Beginner Contest 112
// URL : https://atcoder.jp/contests/abc112/tasks/abc112_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int n,m;
    cin>>n>>m;int ans=1;
    for(int i=1;i<=sqrt(m);i++)
    {
    	   if(m%i==0){
    	  if(m/i>=((n)))ans=max(ans,i);
    	  int x=m/i;
    	  if(m/x>=((n)))ans=max(ans,x);
    	  }
    	  
    	  
    }
    cout<<ans<<endl;
}


return 0;
}





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

using namespace std;

#define INF 1001001001  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=true;
    ll ans=0,sum=0;

    int n;
    string s;
    cin >>n>>s;

    if(n%2 == 1){
        flag = false;
    }else{
        for (int i = 0; i < n/2; i++)
        {
            if(s[i] != s[i + (n/2)]){
                flag = false;
                break;
            }
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    if(flag)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    int x = n%10;

    if (x == 3) {
        cout << "bon" << '\n';
    }
    else if (x == 0 || x==1 || x==6||x==8) {
        cout << "pon" << '\n';
    }
    else {
        cout << "hon" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    a = a%3; b = b%3;
    if(a==0||b==0||a+b==3) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  int N,a[120];
  cin>>N;

  for(int i=0;i<N;i++){
    cin>>a[i];
  }

  ll ans=40000000,sum=0,A=0;

  for(int i=-100;i<=100;i++,sum=0){
    for(int j=0;j<N;j++){
      sum+=(i-a[j])*(i-a[j]);
    }
    if(ans>sum){
      A=i;
      ans=sum;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main(){
	int n,l;
	std::cin >>n>>l ;
	std::vector<string> s(n);
	rep(i,n)std::cin >> s[i];
	sort(all(s));
	rep(i,n)std::cout << s[i];
	std::cout << std::endl;
	
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
ll a,b;
ll dpi(vl &vec,vl &dp,ll n){
	rep(i,1,n){
		ll dist=vec[i]-vec[i-1];
		dp[i]=min(dp[i-1]+dist*a,dp[i-1]+b);
	}
	return dp[n-1];
}

signed main(){
	ll n; cin>>n>>a>>b;
	vl vec(n);
	rep(i,0,n) cin>>vec[i];
	vl dp(n+10);
	dp[0]=0;
	ll ans=dpi(vec,dp,n);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp111 {
    class Program {
        static void Main(string[] args) {
            ulong N = ulong.Parse(Console.ReadLine());
            var T = new ulong[N];
            var A = new ulong[N];

            for (ulong i = 0; i < N; i++) {
                var st = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
                T[i] = st[0];
                A[i] = st[1];
            }

            //これまでのT, Aの合計
            ulong cur_T = T[0];
            ulong cur_A = A[0];

            ulong ans = T[0] + A[0];

            for (ulong i = 1; i < N; i++) {
                //次のセットを何セット作るか
                ulong T_cand = (ulong)Math.Ceiling((decimal)cur_T / T[i]);
                ulong A_cand = (ulong)Math.Ceiling((decimal)cur_A / A[i]);
                ulong pair_cand = (ulong)Math.Ceiling((decimal)ans / (T[i] + A[i]));

                ulong next_pair = Math.Max(T_cand, Math.Max(A_cand, pair_cand));

                ans = next_pair * (T[i] + A[i]);

                cur_T = T[i] * next_pair;
                cur_A = A[i] * next_pair;
            }

            Console.WriteLine(ans);
        }
    }
}


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

Measured memory_bytes: 3064
r, c = map(int, input().split())
l = [[] * c for i in range(r)]  # [[0, 0, 0], [0, 0, 0]]
cl = []

for i in range(r):
    l[i] = list(map(int, input().split()))
    l[i].append(sum(l[i]))
    print(*l[i], sep=" ")

for j in range(c + 1):
    sum = 0
    for i in range(r):
        sum += l[i][j]
    cl.append(sum)

print(*cl, sep=" ")


Measured memory_bytes: 5708
package main

import "fmt"

func main() {
	var n int

	fmt.Scan(&n)
	cards := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}
	sorted := bSort(cards)

	var alice int
	var bob int

	for k, v := range sorted {
		if k%2 == 0 {
			alice = alice + v
			continue
		}
		bob = bob + v
	}
	fmt.Println(alice - bob)
}

func bSort(n []int) []int {
	for i := 0; i < len(n); i++ {
		for j := len(n) - 1; i < j; j-- {
			if n[j] > n[j-1] {
				tmp := n[j]
				n[j] = n[j-1]
				n[j-1] = tmp
			}
		}
	}
	return n
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N = 705;
int n, m, col[N], cnt[2], dp[N][N];
bool con[N][N];
bool dfs(int u, bool futymygay) {
	cnt[futymygay]++, col[u] = futymygay;
	//cout << "u = " << u <<", futymygay = " << futymygay << "\n";
	fw (i, 0, n) if (con[u][i] && u != i) {
		if (col[u] == col[i]) return false;
		else if (col[i] == -1 && !dfs(i, futymygay ^ 1)) return false;
	}
	return true;
}
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	fw (i, 0, n) fw (j, 0, n) con[i][j] = 1;
	while (m--) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		con[u][v] = con[v][u] = 0;
	}
	memset(dp, 0, sizeof dp);
	memset(col, -1, sizeof col);
	dp[0][0] = 1;
	fw (i, 0, n) {
		memset(cnt, 0, sizeof cnt);
		if (col[i] == -1 && !dfs(i, 1)) {
			cout << "-1";
			return 0;
		}
		//cout << "cnt0 = " << cnt[0] << ", cnt1 = " << cnt[1] << "\n";
		fw (j, 0, n + 1) {
			if (j + cnt[0] <= n) dp[i + 1][j + cnt[0]] |= dp[i][j];
			if (j + cnt[1] <= n) dp[i + 1][j + cnt[1]] |= dp[i][j];
		}
	}
	int ans = INF;
	fw (i, 0, n + 1) if (dp[n][i]) {
		//cout << "i = " << i << "\n";
		ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2688
//Author: rishab_1128

#include<bits/stdc++.h>
using namespace std;
#define int long long int

//Using Bottom-Up Approach
int dp[10000][10000];
int knapsack(int* weights, int* values, int n, int maxWeight)
{

	if(n==0||maxWeight==0)
		return 0;

	if(dp[n][maxWeight]!=0)
		return dp[n][maxWeight];

	if(weights[n-1]<=maxWeight)
	{
		dp[n][maxWeight]=max(knapsack(weights,values,n-1,maxWeight-weights[n-1])+values[n-1],knapsack(weights,values,n-1,maxWeight));
	}
	else
	{
		dp[n][maxWeight]=knapsack(weights,values,n-1,maxWeight);
	}
	return dp[n][maxWeight];
}

//Using Top-Down Approach
int knapsack2(int* weights, int* values, int n, int maxWeight)
{
	int DP[n+1][maxWeight+1];

	//Filling 0th row and 0th col
	for(int w=0; w<=maxWeight; w++)
	{
		DP[0][w]=0;
	}
	for(int i=0; i<=n; i++)
	{
		DP[i][0]=0;
	}

	int Weights[n+1],Values[n+1],j=1,k=1;
	for(int i=0; i<n; i++)
	{
		Weights[j]=weights[i];
		j++;
	}

	for(int i=0; i<n; i++)
	{
		Values[k]=values[i];
		k++;
	}

	for(int i=1; i<=n; i++)
	{
		for(int w=1; w<=maxWeight; w++)
		{
			if(Weights[i]<=w)
				DP[i][w]=max(DP[i-1][w],DP[i-1][w-Weights[i]]+Values[i]);
			else
				DP[i][w]=DP[i-1][w];

		}
	}

	return DP[n][maxWeight];
}

//This function also returns the sum of the weights of the item chosen along with the max value(i.e. DP + a bit of Backtracking)
pair<int,int> knapsack3(int* weights, int* values, int n, int maxWeight)
{
	int DP[n+1][maxWeight+1];

	//Filling 0th row and 0th col
	for(int w=0; w<=maxWeight; w++)
	{
		DP[0][w]=0;
	}
	for(int i=0; i<=n; i++)
	{
		DP[i][0]=0;
	}

	int Weights[n+1],Values[n+1],j=1,k=1;
	for(int i=0; i<n; i++)
	{
		Weights[j]=weights[i];
		j++;
	}

	for(int i=0; i<n; i++)
	{
		Values[k]=values[i];
		k++;
	}

	for(int i=1; i<=n; i++)
	{
		for(int w=1; w<=maxWeight; w++)
		{
			if(Weights[i]<=w)			
				DP[i][w]=max(DP[i-1][w],DP[i-1][w-Weights[i]]+Values[i]);			
			else
				DP[i][w]=DP[i-1][w];
		}
	}

	int maxvalue=DP[n][maxWeight];
	int minweight=0;
	for(int i=0;i<=maxWeight;i++)
	{
		if(DP[n][i]==maxvalue)
		{
			minweight=i;
			break;
		}
	}

	return {minweight,maxvalue};
}

void solve()
{

	int n; 
	cin >> n;

	int maxWeight;
	cin >> maxWeight;

	int* weights = new int[n];
	int* values = new int[n];

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

	cout << knapsack2(weights, values, n, maxWeight);

}

int32_t main()
{
	std::ios::sync_with_stdio(false);

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

	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
    return 0;
}

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

class main{
    public static void Main(String[] args){
        int n = int.Parse(Console.ReadLine());
        int[] ans = new int[n];

        for(int i = 0;i < n;i++){
            String x = Console.ReadLine();
            List<String> lst = new List<String>();
            
            foreach(char val in x){
                lst.Add(val.ToString());
            }

            lst.Sort();
            List<String> lstReverse = new List<String>(lst);
            lstReverse.Reverse();

            int large;
            int small;
            String str = null;
            String str2 = null;
            foreach(String val in lst){
                str = str + val;
            }
            small = int.Parse(str);

            foreach(String val in lstReverse){
                str2 = str2 + val;
            }
            large = int.Parse(str2);

            ans[i] = large - small;
        }

        foreach(int val in ans){
            Console.WriteLine(val);
        }

    }
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int a[n];
    int b[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    int med1,med2;
    if(n%2==1){
    med1=2*a[(n-1)/2];
    med2=2*b[(n-1)/2];
    }
    else
    {
        med1=(a[(n-1)/2]+a[n/2]);
        med2=(b[(n-1)/2]+b[n/2]);
    }
    if(n%2==0)
    cout<<(med2-med1+1);
    else
    cout<<(med2/2-med1/2+1);
    return 0;
}


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

queue<int>q[100];

int main(){
    int n,x;
    cin>>n>>x;
    priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>>a;
    rep(i,n){
        int s,t,c;
        cin>>s>>t>>c;
        s--;
        a.emplace(make_tuple(s,t,c));
    }
    int ans=0;
    rep(i,100010){
        rep(j,100){
            if(!q[j].empty()){
                if(q[j].front()==i){
                    q[j].pop();
                }
            }
        }
        rep(j,100){
            if(!a.empty()){
                if(get<0>(a.top())==i){
                    if(!q[get<2>(a.top())].empty()){
                        if(q[get<2>(a.top())].front()-1==get<0>(a.top())){
                            q[get<2>(a.top())].pop();
                            q[get<2>(a.top())].emplace(get<1>(a.top()));
                            a.pop();
                        }
                        else{
                            q[get<2>(a.top())+50].emplace(get<1>(a.top()));
                            a.pop();
                        }
                    }
                    else{
                        q[get<2>(a.top())].emplace(get<1>(a.top()));
                        a.pop();
                    }
                }
            }
        }
        int cnt=0;
        rep(j,100)if(!q[j].empty())cnt++;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main(){
  ll N,K,Q;
  cin >> N >> K;
  matp A(N,vecp(20,P(0,0))),C(N,vecp(20,P(N,0)));
  vec B(N);
  rep(i,N){
    cin >> B.at(i);
  }
  rep(i,N){
    auto a=lower_bound(all(B),B.at(i)+K);
    if(a!=B.end()){
      A.at(i).at(0)=P((ll)(a-B.begin()),(ll)(a-B.begin()));
    }
    auto b=upper_bound(all(B),B.at(N-1-i)-K);
    if(b!=B.begin()){
      C.at(N-1-i).at(0)=P((ll)(b-B.begin())-1,(ll)(b-B.begin())-1);
    }
  }
  rep(i,19){
    rep(j,N){
      if(A.at(j).at(i).first!=0){
        A.at(j).at(i+1).first=A.at(A.at(j).at(i).first).at(i).first;
        A.at(j).at(i+1).second=A.at(A.at(j).at(i).first).at(i).second+A.at(j).at(i).second;
      }
      if(C.at(j).at(i).first!=N){
        C.at(j).at(i+1).first=C.at(C.at(j).at(i).first).at(i).first;
        C.at(j).at(i+1).second=C.at(C.at(j).at(i).first).at(i).second+C.at(j).at(i).second;
      }
    }
  }
  cin >> Q;
  rep(i,Q){
    ll l,r,ans=0,L=0,R=0,a;
    cin >> l >> r;
    l--;
    r--;
    a=l;
    L+=l;
    R+=r;
    rep(j,20){
      if(A.at(l).at(19-j).first!=0&&A.at(l).at(19-j).first<=r){
        if(A.at(l).at(19-j).first==r){
          L+=A.at(l).at(19-j).second;
          ans+=(ll)pow(2,19-j);
          break;
        }else{
          L+=A.at(l).at(19-j).second;
          ans+=(ll)pow(2,19-j);
          l=A.at(l).at(19-j).first;
        }
      }
    }
    l=a;
    rep(j,20){
      if(C.at(r).at(19-j).first!=N&&C.at(r).at(19-j).first>=l){
        if(C.at(r).at(19-j).first==l){
          R+=C.at(r).at(19-j).second;
          break;
        }else{
          R+=C.at(r).at(19-j).second;
          r=C.at(r).at(19-j).first;
        }
      }
    }
    cout << ans+R-L+1 << endl;
  }
  
    
    
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	string s;
	cin >> s;

	VB alpha(26, false);
	for(char c : s)
	{
		int nc = c - 'a';
		if(alpha[nc] == true) {
			cout << "no" << endl;
			return 0;
		}
		alpha[nc] = true;
	}
	cout << "yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 文字列の入力
    s <- getLine
    -- 出力
    putStrLn $ if s!!0 == '9' || s!!1 == '9' then "Yes" else "No"


Measured memory_bytes: 380
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int a[n];
    int ans = 1e9;
    REP(i, n)
    {
        int tmp = 0;
        cin >> a[i];
        while (not(a[i] & 1))
        {
            tmp++;
            a[i] = a[i] >> 1;
        }
        ans = min(tmp, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
	string S;
	int A[100000];
	cin >> S;
	
	int N = S.length();
	
	REP(i, N){
		A[i] = 0;
	}
	
	int i=0;
	int m = 0;
	int R = 0;
	int L = 0;
	int idx = 0;
	while(i<N){
		if(m == 0){
			if(S[i] == 'R'){
				R++;
			}else{
				L++;
				idx = i;
				m = 1;
			}
		}else{
			if(S[i] == 'L'){
				L++;
			}else{
				A[idx-1] += (R+1) / 2;
				A[idx-1] += L / 2;
				A[idx] += R / 2;
				A[idx] += (L+1) / 2;
				R = 1;
				L = 0;
				idx = 0;
				m = 0;
			}
		}
		i++;
	}
	if(m == 1){
		A[idx-1] += (R+1) / 2;
		A[idx-1] += L / 2;
		A[idx] += R / 2;
		A[idx] += (L+1) / 2;
	}
	
	REP(i, N){
		cout << A[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int h,n;
int a[maxn];
int main()
{
	cin>>h>>n;
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<h)
	{
		puts("No");
	}
	else
	{
		puts("Yes");
	}
	return 0;
} 

Measured memory_bytes: 640
n = int(input())
h = list(map(int,input().split()))
ans = 0
ans1 = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        ans += 1
    else:
        ans1 = max(ans1,ans)
        ans = 0
ans1 = max(ans1,ans)
print(ans1)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
map<pair<int, int>, int> gmemo;
int gcd(int a, int b) {
	if (gmemo[{a, b}] != 0) return gmemo[{a, b}];
	if (gmemo[{b, a}] != 0) return gmemo[{b, a}];
	if (a % b == 0)
		return gmemo[{a, b}] = b;
	else
		return gmemo[{a, b}] = gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
signed main() {
	int n,ans=0;
	cin>>n;
	int cnt=n;
	REP(i,1,n){
		int memo=cnt/i-1;
		if(n/memo>=memo)break;
		if(n%memo==n/memo)ans+=memo;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[2005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	    cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n-1;j++){
			int s=a[i]+a[j],x;
			if(a[j+1]>=s) continue;
			x=lower_bound(a+j+2,a+n,s)-a;
			ans+=x-j-1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N, X, M = map(int, input().split())

candicate = [pow(i, 2, M) for i in range(M)]
ans = 0
now = X
A = [0]
X2 = pow(X, 2, M)

d = dict()

flag = True
for i in range(1, N+1):
    if i == 1:
        A.append(X)
    
    else:
        nxt = candicate[A[i-1]]

        if d.get(nxt) == None:
            if nxt == 0:
                A.append(nxt)
                break
            else:
                A.append(nxt)
                d[nxt] = i

        else:
            flag = False
            break


if flag:
    print(sum(A))
else:
    l = d[nxt]
    r = i - 1
    circle_total = 0
    for j in range(l, r+1):
        circle_total += A[j]
    
    for j in range(1, l):
        ans += A[j]

    width = r - l + 1
    N -= (l - 1)
    ans += circle_total * (N // width)

    for j in range(l, l + N % width):
        ans += A[j]

    print(ans)


Measured memory_bytes: 18308
class Main{
    public static void main(String[] args){
        String s = "CODEFESTIVAL2016";
        String input = new java.util.Scanner(System.in).next();
        int i=0;
        int ans = 0;
        while(i<s.length()){
            if(s.charAt(i) != input.charAt(i)){
                ans++;
            }
            i++;
        }
        System.out.printf("%d\n", ans);
    }
}

Measured memory_bytes: 9808
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch; i++){
        if (ch == '\\') S1.push(i);
        else if (ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while (S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
char s[110],a[110];
int main(){
	int n,ans=1000;
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<26;++i){
		for(int j=0;j<n;++j)a[j]=(s[j]==i+'a');
		for(int k=0;k<n;++k){
			for(int l=0;l<n-k;++l)if(!a[l])goto nxt;
			ans=min(ans,k);break;
			nxt:for(int l=0;l<n-k;++l)a[l]=(a[l]|a[l+1]);
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c,i,k=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i+=1){
        if(c%i==0){
            k+=1;
        }
    }
    printf("%d\n",k);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll x, k, d;
    cin >> x >> k >> d;
    // 極限まで0に近づく手数
    ll p = abs(x)/d;
    // そのときの距離
    ll q = abs(x)%d;

    ll ans;
    // 必要な手数と同じか少ない
    if(p >= k) ans = abs(x)-(k*d);
    // そうじゃない場合
    else{
        ans = q;
        k -= p;
        // 0を左右にいったり来たり
        if(k%2 == 1) ans -= d;
    }
    cout << abs(ans) << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
ll fastexpo(ll x,ll y,ll m)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
void fff()
{
	ld x, k, d, a, b, c;
	cin >> x >> k >> d;
	x = abs(x);
		a = floor(x/d);
		if(a>k)
		{
			printf("%.0Lf\n",x-k*d);
			return;
		}
		k -= a;
		x -= (a*d);
		if(ll(k)&1)
		{
			printf("%.0Lf\n",abs(x-d));
		}
		else 
		{
			printf("%.0Lf\n",x);
		}

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 3804
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        int[] arr = new int[n];
        ntok();
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        int prev = arr[0];
        int count = 1;
        int best = 1;
        for (int i = 1; i < n; i++)
        {
            if (arr[i] > prev)
            {
                count = 1;
            }
            else
            {
                count++;
            }
            best = Math.max(count, best);
            prev = arr[i];
        }
        out.println(best-1);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


Measured memory_bytes: 39476
h,w=map(int,input().split())

field=[list(input())for i in range(h)]
cnt=0
for i in field:
    for j in i:
        if j=='#':
            cnt+=1
dp=[[0 for i in range(w)]for i in range(h)]

dydx=[[-1,0],[1,0],[0,-1],[0,1]]

queue=[]
queue.append([0,0])

while queue:
    ny,nx=queue.pop(0)
    for dy,dx in dydx:
        nny,nnx=ny+dy,nx+dx
        if 0<=nny<=h-1 and 0<=nnx<=w-1 and field[nny][nnx]!="#" and dp[nny][nnx]==0:
            dp[nny][nnx]=dp[ny][nx]+1
            queue.append([nny,nnx])
            if nny==h-1 and nnx==w-1:
                print(h*w-cnt-dp[h-1][w-1]-1)
                exit()
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>  // setw
#include <algorithm> // sort next_permutation count __gcd reverse etc.
#include <set>
#include <list>
#include <map>
#include <memory>
#include <numeric> // accumulate
#include <complex>
#include <functional>
#include <utility>
#include <iterator>
#include <vector>
#include <limits>
#include <stack>
#include <queue>
#include <deque>
#include <typeinfo>
#include <fstream> // freopen
#include <cstdio> // scanf printf
#include <cstdlib> // abs exit atof atoi
#include <string> // memset
#include <cstring>
#include <cfloat>
#include <cassert>
#include <cmath> // fabs
#include <cctype> // tolower toupper
#include <ctime> // srand
#include <sstream> // stringstream
#include <bitset>

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
/* -------------------------------------------------------------------------- */

int main(int argc, char *argv[])
{
    ld a, b, c;
    cin >> a >> b >> c;

    if (a + 2 * sqrt(a * b)  + b - c < 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int alf[26] = {0};
  char w[110];
  int i;
  
  scanf("%s", w);
  for(i = 0; w[i] != '\0'; i++) {
    alf[w[i] - 'a']++;
  }
  for(i = 0; i < 26; i++) {
    if(alf[i] % 2 == 1) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    ll n;
    cin>>n;
        ll k=26;
    vector<pair<ll,ll> > v;
    string ar={"aabcdefghijklmnopqrstuvwxyz"};
    v.push_back({1,k});
    for(int i=1;i<=12;i++){
        ll f=k+1;
        k=k*26+26;
        v.push_back({f,k});
        //cout<<k<<endl;
    }
    for(int i=0;i<v.size();i++){
        //cout<<v[i].F<<" "<<v[i].S<<endl;
        if(n>=v[i].F&&n<=v[i].S){
            vector<ll> vv;

            while(n){
            n--;
                ll x=(n%26LL);
                x++;
               // cout<<x<<" ";
                vv.push_back(x);
                n/=26LL;
            }

            string st="";
            for(int j=vv.size()-1;j>=0;j--){
               // cout<<vv[j]<<" ";
                st+=ar[vv[j]];
            }
            cout<<st;

        }
    }








    return 0;
}


Measured memory_bytes: 3600
import  heapq
n=int(input())
aa=list(map(int,input().split()))
count=1
have=1000
l=[aa[0]]
ll=[-aa[0]]
heapq.heapify(l)
heapq.heapify(ll)
while count<n:
  mx=-heapq.heappop(ll)
  mn=heapq.heappop(l)
  if mx<=aa[count]:
    heapq.heappush(ll,-aa[count])
    heapq.heappush(l,aa[count])
    heapq.heappush(ll,-mn)
    heapq.heappush(l,mn)
    heapq.heappush(ll,-mx)
    heapq.heappush(l,mx)
    #print(l,ll)
  else:
    have+=(mx-mn)*int(have/mn)
    #print(mx,mn,l,ll)
    if count<=n-1:
      l=[aa[count]]
      ll=[-aa[count]]
      heapq.heapify(l)
      heapq.heapify(ll)
  count+=1
if len(l)!=0:
  mx=-heapq.heappop(ll)
  mn=heapq.heappop(l)
  have+=(mx-mn)*int(have/mn)
  
  
print(have)

    
    

  
    
  


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

// Time: 03:56:84

// 全探索の探索方針を迷いながら書くことは愚の骨頂
// 今回は左端さえ決めれば貪欲に見ていけばよいことがわかる

// Tips: 端に番兵を置いてACGT以外のindexをメモすれば，線形でいける

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int N=S.size();
    int ans=0;
    vi idx;
    idx.pb(-1);
    rep(i,N)if(!(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T')) idx.pb(i);
    idx.pb(N);
    int M = idx.size();
    rep(i,M-1){
        chmax(ans,idx[i+1]-idx[i]-1);
    }

    // rep(i,N){
    //     int cand=0;
    //     FOR(j,i,N-1){
    //         if (!(S[j]=='A'||S[j]=='C'||S[j]=='G'||S[j]=='T')) break;
    //         cand++;
    //     }
    //     chmax(ans,cand);
    // }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
vector<int> graph[10003];
int vis[10003], ans[10003];
int dist[10003][10003];
void bfs(int src)
{
    
    int i;
    deque<int> q;
    q.eb(src);
    vis[src] = 1;
    dist[src][src] = 0;
    while (!q.empty())
    {
        int ma_src = q.front();
        q.pop_front();
        for (i = 0; i < graph[ma_src].size(); i++){
            int adj = graph[ma_src][i];
            //cout << ma_src << " " << adj << nl;
            if(!vis[adj]){
                dist[src][adj] = min(dist[src][adj], 1 + dist[src][ma_src]);
                //dist[adj][src] = min(dist[adj][src], 1 + dist[ma_src][src]);
                //cout << dist[src][adj] << " " << dist[adj][src] << nl;
                vis[adj] = 1;
                q.eb(adj);
            }
        }
    }
}
int main()
{
    int n, x, y, i, j;
    cin >> n >> x >> y;
    for (i = 1; i < n; i++)
    {
        graph[i].eb(i + 1);
        graph[i + 1].eb(i);
    }
    graph[x].eb(y);
    graph[y].eb(x);
    for (i = 0; i <= n; i++){
        for (j = 0; j <= n; j++){
            dist[i][j] = 9999999;
        }
    }
    for (i = 1; i <= n; i++)
    {
        bfs(i);
        memset(vis, 0, sizeof(vis));
    }
        //cout << "HEint" << nl;
    for (i = 0; i <= n; i++){
        for (j = i + 1; j <= n; j++){
            if(dist[i][j] != 9999999){
                ans[dist[i][j]]++;
            }
        }
    }
    for (int k = 1; k < n; k++){
        cout << ans[k] << nl;
    }
}

Measured memory_bytes: 80768
s = list(input())

ans = 0
while ans == 0:
    cnt = 0
    del s[-1], s[-1]
    for i in range(len(s)//2):
        if s[i] != s[i + len(s)//2]:
            break
        cnt += 1
    if cnt == len(s)//2:
        ans = len(s)

print(ans)

Measured memory_bytes: 8868
#include <stdio.h>
#define MAXNUM 100

int main(void){
    int n;
    scanf("%d", &n);
    
    int i;
    int rate[MAXNUM], exist[8] = {}, num_highrate = 0;
    for(i = 0; i < n; i++){
        scanf("%d", &rate[i]);

        if(rate[i] / 400 >= 8){
            num_highrate++;
        }else{
            exist[rate[i] / 400] = 1;
        }

        //printf("current num_highrate = %d\n", num_highrate);
    }

    int ans = 0;
    for(i = 0; i < 8; i++){
        ans += exist[i];
        //printf("exist[%d] = %d, current ans = %d\n", i, exist[i], ans);
    }

    printf("%d %d\n", (ans == 0)? 1 : ans, ans + num_highrate);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950D
#define modd 1000000007

ll sum(ll l,ll r)
{
        return (l+r)*(r-l+1)/2;
}
int main()
{
        fast;
        int t=1;
     //   cin>>t;
        while(t--)
        {
                ll n,k,ans=0;
                cin>>n>>k;

                for(int i=k;i<=(n+1);i++)
                {
                       ll mini=sum(0,i-1);
                       ll maxi=sum(n-i+1,n);
                       ans=(ans+(maxi-mini+1))%modd;
                }
                cout<<ans%modd<<endl;
        }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;










int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin >> n;
        double p[n+1];
        int i,j;
        for(i=1; i<=n; i++) cin >> p[i];
        double dp[n+1][n+1];
        // dp[i][j] probability of getting j head till i length
        
        dp[1][1]=p[1];
        dp[1][0]=(1-p[1]);
        for(i=2; i<=n; i++){
            for(j=0; j<=i; j++){
                if(j==0) dp[i][j]=dp[i-1][j]*(1-p[i]);
                else if(j==i) dp[i][j]=dp[i-1][j-1]*p[i];
                else
                dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*(p[i]);
            }
        }
      //  trace(dp[2][3]);
        double ans=0;
        if(n%2){
        for(i=n/2+1; i<=n; i++)
        ans+=dp[n][i];
        }
        else{
        for(i=n/2; i<=n; i++)
        ans+=dp[n][i];
        }
        cout << setprecision(16) << fixed << ans << '\n';

}

Measured memory_bytes: 70400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,z;
	scanf("%d%d%d",&x,&y,&z);
	for(int i=0;i<=1000;i++)
		if(i*x%y==z)
		{
		    printf("YES");
		    return 0;
		}
	printf("NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main() {
  char s[11]; cin >> s;
  int tmp = 0, ans = 1000;
  for(int i = 0; i < strlen(s) - 2; ++i) {
    tmp = ((int)s[i] - '0') * 100
      + ((int)s[i + 1] - '0') * 10
      + ((int)s[i + 2] - '0');
    if(ans > abs(tmp - 753))
      ans = abs(tmp - 753);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
	#include <set>
	#include <map>
	#include <cmath>
	#include <vector>
	#include <string>
	#include <algorithm>
	#include <iomanip>
	#include <queue>
	#include <deque>
	#include <stack>
	#include <climits>
	#include <math.h>
	using namespace std;
	#pragma warning(disable : 4996)
	typedef long long ll;
	typedef unsigned long long ull;




int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int q;
	cin >> q;
	int p = 0;
	deque<char> d;
	for (int i = 0; i < s.size(); i++)d.push_back(s[i]);
	while (q--) {
		int type;
		cin >> type;
		if (type == 1)p ^= 1;
		else {
			int x;
			char c;
			cin >> x >> c;
			if (x == 1) {
				if (p == 0) {
					d.push_front(c);
				}
				else d.push_back(c);
			}
			else {
				if (p == 1) {
					d.push_front(c);
				}
				else d.push_back(c);
			}
		}
	}
	s = "";
	for (auto i : d)s += i;
	if (p)reverse(s.begin(), s.end());
	cout << s;
}

Measured memory_bytes: 1168
S = gets.chomp

ans, wk = [0, 0]
(0...S.size).each{|i|
  if ['A', 'C', 'G', 'T'].include?(S[i]) then
    wk += 1
  else
    ans = wk if ans < wk
    wk = 0
  end
}
ans = wk if ans < wk

puts ans


Measured memory_bytes: 1916