akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    vector<string> v={"mon","tue","wed","thu","fri","sat","sun"};
    ll n;cin>>n;
    out(v[(n+3)%7]);
}


Measured memory_bytes: 3216
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

t=[]
n=int(input())
for i in range(n):
    t.append(int(input()))
l=[0]
r=[0]
for i in range(n):
    l+=[max(l[-1],t[i])]
    r+=[max(r[-1],t[n-1-i])]
for i in range(n):
    print(max(l[i],r[n-1-i]))

Measured memory_bytes: 15640
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      long[] h = new long[n];
      for(int i=0;i<n;i++){
        h[i] = Long.parseLong(sc.next());
      }

      long[] dp = new long[n];
      dp[0] = 0;
      dp[1] = Math.abs(h[1]-h[0]);
      for(int i=2;i<n;i++){
        long cost1 = Math.abs(h[i]-h[i-1]);
        long cost2 = Math.abs(h[i]-h[i-2]);
        dp[i] = Math.min(dp[i-1]+cost1,dp[i-2]+cost2);
      }

      System.out.println(dp[n-1]);

    }
}


Measured memory_bytes: 46472
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string s;
	cin >> s;
	string ans = "";
	int i = 0;
	while (i < s.size()) {
		ans += s[i];
		i += 2;
	}
	cout << ans << endl;
}

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

namespace Perfect_Number
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> inputs = new List<int>();

            while(true)
            {
                int input = int.Parse(Console.ReadLine());
                if (input == 0)
                {
                    break;
                }
                inputs.Add(input);
            }

            List<int> sums = new List<int>();

            foreach(int item in inputs)
            {
                int sum = 0;

                for (int i = 1; i <= item / 2; ++i)
                {
                    if (item % i == 0 && item != i)
                    {
                        sum += i;
                    }                    
                }
                sums.Add(sum);
            }

            for (int i = 0; i < inputs.Count; ++i)
            {
                if (inputs[i] == sums[i])
                {
                    Console.WriteLine("perfect number");
                }
                else if (inputs[i] > sums[i])
                {
                    Console.WriteLine("deficient number");
                }
                else 
                {
                    Console.WriteLine("abundant number");
                }
            }
        }
    }
}



Measured memory_bytes: 15916
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,arr[1000000],brr[1000000],count=0;
  cin >> n;
  for(long long i=0;i<=n;i++){
    cin >> arr[i];
  }
  for(long long i=0;i<n;i++){
    cin >> brr[i];
  }
  for(long long i=0;i<n;i++){
    if(brr[i]>arr[i]){
      count =count+arr[i];
      
      brr[i]=brr[i]-arr[i];
      arr[i]=0;
      if(brr[i]>=arr[i+1]){
        count=count+arr[i+1];
        arr[i+1]=0;
        
      }
      else {
        count=count+brr[i];
        arr[i+1]=arr[i+1]-brr[i];
      }
    }
    else{
      count=count+brr[i];
    }
  }
  cout << count;
}
 


Measured memory_bytes: 6784
#include <stdio.h>
int main (void){
    int a,c,i,j,n;
    for(;;){
        scanf("%d",&n);
        if(n==0)break;
        int b[101]={},ans=0;
        for(i=0;i<n;i++){
            scanf("%d",&a);
            b[i]=a;
        }
        for(i=1;i<n;i++){
            for(j=1;j<n;j++){
                if(b[j-1]>=b[j]){
                    if(b[j-1]>b[j]){
                        ans++;
                    }
                    c=b[j-1];
                    b[j-1]=b[j];
                    b[j]=c;
                }
            }
        }
        printf("%d\n",ans);
    }
return 0;
}

Measured memory_bytes: 1028
# D - Maze Master
from collections import deque

MOD = 10 ** 9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]


def bfs(sx: int, sy: int):
    queue = deque([(sx, sy)])
    dist = {sx * MOD + sy: 0}
    while queue:
        x, y = queue.popleft()
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if S[nx][ny] == ".":
                if nx * MOD + ny not in dist:
                    dist[nx * MOD + ny] = dist[x * MOD + y] + 1
                    queue.append((nx, ny))
    return max(dist.values())


def main():
    global S
    H, W, *S = open(0).read().split()
    H, W = int(H) + 2, int(W) + 2
    S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W]  # put sentinels
    ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
L, R = map(int, input().split())

ans = 2018
for i in range(L, R):
    for j in range(i+1, R+1):
        y = ( i * j ) % 2019
        #print(i, j, i*j, y)
        #print(i % 2019, j % 2019)
        #print((i % 2019), (j % 2019))
        if y < ans: ans = y
        if ans == 0:
            break
    if ans == 0:
        break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
void solve(); 
int main() 
{ 
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
			   
	#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin); 
	freopen("error.txt", "w", stderr); 
	freopen("output.txt", "w", stdout); 
	#endif 
			   
	int t=1; 
	while(t--) 
	{ 
	   solve(); 
	} 
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
	return 0; 
} 
void solve() 
{ 
	bool x;
	cin >> x;
	cout << !x << '\n';
}

Measured memory_bytes: 3796
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	x := scanInt(sc)
	max := 1
	for i := 2; i*i <= x; i++ {
		cur := i * i
		for cur <= x {
			if max < cur {
				max = cur
			}
			cur *= i
		}
	}
	fmt.Println(max)
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}
	

Measured memory_bytes: 1784
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[200100];
typedef long long LL;
int main()
{
    int n; scanf("%d",&n);
    int i;
    for (i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        a[i]=a[i]-i;
    }
    sort(a+1, a+n+1);
    
  /*  int tmp=1, ans=0, tag=0;
    for (i=1; i<=n-1; i++)
    {
        if (a[i]==a[i+1])
        {
            tmp++;
            if (tmp>tag)  tag=tmp, ans=a[i];
        }
        else
            tmp=1;
    }*/
    int ans=a[(1+n)/2];
    long long sum=0;
    for (i=1; i<=n; i++)
        sum+=(LL) abs(a[i]-ans);
    printf("%lld\n",sum);
    return 0;
}
    


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint a, b, x;
    cin >> a >> b >> x;

    lint res = b / x;

    if (a > 0) {
        res -= (a-1)/x;
    }
    else {
        res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>


using namespace std;

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

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

vector<ll> item[4];
ll w1;
int n[4];
ll memo[100][100][100][100];
int N,W;

ll dfs(int used[4], ll w, ll v){
    if(memo[used[0]][used[1]][used[2]][used[3]]>0){
        return memo[used[0]][used[1]][used[2]][used[3]];
    }
    ll ret=v;
    rep(i,4){
        ll nw = w+w1+i;
        if(nw>W){
            break;
        }
        if(used[i]>=n[i]){
            continue;
        }
        ll nv = v+item[i][used[i]];
        used[i]++;
        ret = max(dfs(used, nw, nv), ret);
        memo[used[0]][used[1]][used[2]][used[3]] = ret;
        used[i]--;
    }
    return ret;
}

int main(){
    cin >> N >> W;
    ll v;
    cin >> w1 >>v;
    item[0].push_back(v);

    rep(i,N-1){
        ll w;
        cin >> w >> v;
        item[w-w1].push_back(v);
    }
    rep(i,4){
        sort(item[i].begin(), item[i].end(), greater<ll>());
        n[i]=item[i].size();
    }

    int used[4] = {0};
    cout << dfs(used , 0, 0) << endl;;
}

Measured memory_bytes: 203008
#include<stdio.h>

int main()
{
  int i;
  char s[101];

  scanf("%s", s);
  for(i=0; i< (sizeof(s)/sizeof(char)); i++)
  {
    if((i+1)%2 == 0 && s[i] =='R'){
      printf("No");
      return 0;
    }else if((i+1)%2 != 0 && s[i] == 'L'){
      printf("No");
      return 0;
    }else{
      continue;
    }
  }

  printf("Yes");

  return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

    vector<vector<vector<int>>> groups(9, vector<vector<int>>(9, vector<int>()));
    for (int i = 1; i <= n; i++) {
        string sStr = to_string(i).substr(0,1);
        int s = stoi(sStr);
        string eStr = to_string(i).substr(to_string(i).length()-1);
        int e = stoi(eStr);
        if (s == 0 || e == 0) continue;
        groups[s-1][e-1].push_back(i);
    }

    int cnt = 0;
    rep(i,9) rep(j,9) {
        cnt += groups[i][j].size() * groups[j][i].size();
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1408
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

struct edge {
    int next,to;
};

const int maxn=(int)(2e5)+5;
int fr[maxn];
LL a[maxn];
int in[maxn];
edge e[maxn<<1];
int tote=0;

inline void addone(int u,int v) {
    ++tote;
    e[tote].next=fr[u];fr[u]=tote;e[tote].to=v;
}

inline void addedge(int u,int v) {
    addone(u,v);addone(v,u);
}

void dfs(int x,int f) {
    int cnt=0;LL tot=0,mx=0;
    RAL(i,x) if(e[i].to!=f) {
        ++cnt;
        dfs(e[i].to,x);
        tot+=a[e[i].to];mx=max(mx,a[e[i].to]);
    }
    if(!cnt) return;
    if(tot<a[x]) {
        printf("NO\n");exit(0);
    }
    LL w=mx;
    if(w>a[x]) {
        printf("NO\n");exit(0);
    } a[x]-=tot-a[x];
    if(a[x]<0) {
        printf("NO\n");exit(0);
    }
}

int main() {
    int n;
    read(n);
    REP(i,1,n) read(a[i]);
    if(n==2) {
        if(a[1]!=a[2]) {
            printf("NO\n");
        } else printf("YES\n");
        return 0;
    }
    memset(fr,-1,sizeof(fr));
    REP(i,1,n-1) {
        int u,v;
        read(u);read(v);
        addedge(u,v);++in[u];++in[v];
    }
    int rt=1;
    REP(i,1,n) if(in[i]>1) {
        rt=i;break;
    } dfs(rt,0);
    if(a[rt]==0) printf("YES\n"); else printf("NO\n");
    return 0;
}

Measured memory_bytes: 10496
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<unordered_map>
 
#include<unordered_map>
#include<algorithm>
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
 
#define ii pair<int,int>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
//~ #define mid l + ( (r-l)>>1)
 
using namespace std;
 
const int maxn = 1e5 + 10;
const int MAX = 5e3 + 10;
typedef long long ll;
typedef vector< int> vi;		
 
//~ https://codeforces.com/contest/645/problem/D


 

int n;
ii a[maxn];

int main (){
	//~ in
	
	cin >> n;
	for(int i = 0 ;i <n;i++)
		cin >> a[i].f , a[i].s = i+1;
	sort ( a, a + n);
	for(int i = 0 ;i < n;i++)
		cout << a[i].s << ' ';

}
 
		


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,L,T;
int pos[N],v[N];
int main(){
    scanf("%d%d%d",&n,&L,&T);
    for(int i=1;i<=n;i++) scanf("%d%d",&pos[i],&v[i]),v[i]=v[i]==1? 1:-1;
    vector<int> fin;
    for(int i=1;i<=n;i++)
        fin.push_back(((pos[i]+v[i]*T)%L+L)%L);
    int pos1=fin[0];
    sort(fin.begin(),fin.end());
    long long tot=0;
    for(int i=1;i<=n;i++)
        if(v[i]!=v[1])
            tot+=(2*1LL*T+(v[1]==1? (L-pos[i]+pos[1]):(pos[i]-pos[1])) )/L;
    tot=((v[1]*tot)%n+n)%n;
    int id1=0;
    for(int i=0;i<n;i++)
        if(fin[i]==pos1){
            id1=i;
            if(v[1]==-1) break;
        }
    id1=((id1-tot)%n+n)%n;
    for(int i=id1;i<n;i++)
        printf("%d\n",fin[i]);
    for(int i=0;i<id1;i++)
        printf("%d\n",fin[i]);
    return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll a,b,ans;
void solve(){
	ll c = gcd(a,b);
	for(ll i = 1;i*i<=c;i++){
		if(c % i == 0){
			if(isp(i) || i == 1) ans++;
			if(c/i!=i&&isp(c/i)) ans++;
		}
	}
	cout << ans << endl;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> a >> b;
	solve();
	return 0;
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        x: u64,
    }
    print!("Christmas ");
    for _ in 0..25-x {
        print!("Eve ");
    } 
    println!();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  string S;
  cin>>S;
  long long N=S.size();
  long long p=0;
  vector<int> R(N),T(2019); //累積和iの個数
  T[0]++;
  for(long long i=0;i<N;i++){
    R[i]=S[i]-'0';
    R[i]=p+R[i]*modpow(10,N-i-1,2019);
    R[i]=R[i]%2019ll;
    if(R[i]<0)
      R[i]=R[i]+2019;
    p=R[i];
    T[R[i]]++;
    //cout<<R[i]+0<<endl;
  }
  int answer=0;
  for(int i=0;i<2019;i++){
    //cout<<T[i]<<endl;
    answer+=(T[i]*(T[i]-1))/2;
  }
  cout<<answer;
    
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
int main (){
	ios::sync_with_stdio(0);cin.tie(0);
	char a, b;
	cin >> a >> b;
		if ((a=='2' && b=='3') || (b=='2' && a=='3'))
			cout << "1\n";
		if ((a=='1' && b=='3') || (b=='1' && a=='3'))
			cout << "2\n";
		if ((a=='1' && b=='2') || (b=='1' && a=='2'))
			cout << "3\n";
}


Measured memory_bytes: 256
import collections
n = int(input())
li = list(map(int,input().split()))

c = collections.Counter(li)
#print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})
#print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])
count_list = list(c.items())
count_list.sort()
keys = set(c.keys())
#print(keys,{i for i in range(n) if i%2 == 1})
#print(count_list)
flag = True
if n%2 == 1:
    if keys != {i for i in range(n) if i%2 == 0}:
        print(0)
        exit()
    for i,c in enumerate(count_list):
        #print(c[0],c[1])
        if c[0] == 0:
            if c[1]!=1:
                flag = False
        else:
            if c[1]!=2:
                flag = False
else:
    if keys != {i for i in range(n) if i%2 == 1}:
        print(0)
        exit()
    for i in count_list:
        if i[1] != 2:
            flag = False
if not flag:
    print(0)
    exit()

ans_tmp = 0
if n%2 == 1:
    ans_tmp = 2**((n-1)//2)
else:
    ans_tmp = 2**(n//2)
print(ans_tmp%(10**9+7))

Measured memory_bytes: 63724
// verified : https://atcoder.jp/contests/dp/tasks/dp_s
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 1e4+7 ;
//const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;

string a , b ; // range inclusive [a,b] && (a < b)
int len ;
int d ;
int dp[N][101][2][2] ;

void pre(){
	len = sz(b) ;
	reverse(all(a)) ;
	while(sz(a)<sz(b)) a.pb('0') ;
	reverse(all(a)) ;
	ms(dp,-1) ;
	// do other stuff if required 
}

int go(int idx, int val, int lo, int hi){
	if(idx == len){
		return val == 0 ;
	}
	int& ans = dp[idx][val][lo][hi] ;
	if(~ans) return ans ;
	ans = 0 ;
	int l = a[idx]-'0' ;
	int r = b[idx]-'0' ;
	if(lo == 0) l = 0 ;
	if(hi == 0) r = 9 ;
	for(int i = l ; i <= r ; i++){
		int newlo = lo , newhi = hi ;
		if(i != l) newlo = 0 ;
		if(i != r) newhi = 0 ;
		// do dp here 
		ans = ans+go(idx+1,(val+i)%d, newlo, newhi)%MOD ;
	}
	return ans%MOD ;
}

void solve(){
	cin >> b >> d ;
	a = "1" ;
	pre() ;
	cout << go(0,0,1,1) ;

}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 32896
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int main() {
	ll i, j, k, l;
	string s;
	cin >> s;
	int start = -2, end = -2;
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1]) {
			start = i; end = i + 1;
			break;
		}
		if (i < s.size() - 2) {
			if (s[i] == s[i + 2]) {
				start = i; end = i + 2;
				break;
			}
		}
	}
	cout << start+1 << " " << end+1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int cmp(const void* p, const void* q) {
	return *(int*)p - *(int*)q;
}

int main(void) {
	int n;
	int v_odd[100001] = { 0 }, v_even[100001] = { 0 };
	int cnt_odd = 1, cnt_even = 1, temp = 1;
	int cnt_odd2 = 1, cnt_even2 = 1;
	int a_odd=-1, a_even=-2, ans;

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		if (i % 2) scanf("%d", &v_odd[i / 2]);
		else scanf("%d", &v_even[i / 2 - 1]);
	}
	qsort(v_odd, n / 2, sizeof(int), cmp);
	for (int i = 0; i < n / 2 ; i++) {
		if (v_odd[i] == v_odd[i + 1])temp++;
		else {
			if (temp > cnt_odd)
				a_odd = v_odd[i], cnt_odd2 = cnt_odd, cnt_odd = temp;
			else if (cnt_odd2 <= temp && temp <= cnt_odd)
				cnt_odd2 = temp;
			temp = 1;
		}
	}
	temp = 1;
	qsort(v_even, n / 2, sizeof(int), cmp);
	for (int i = 0; i < n / 2 ; i++) {
		if (v_even[i] == v_even[i + 1])temp++;
		else {
			if (temp > cnt_even)
				a_even = v_even[i], cnt_even2 = cnt_even, cnt_even = temp;
			else if (cnt_even2 <= temp && temp <= cnt_even)
				cnt_even2 = temp;
			temp = 1;
		}
	}
	if (a_odd != a_even) printf("%d", n - cnt_odd - cnt_even);
	else {
		if (cnt_odd == n / 2 && cnt_even == n / 2) printf("%d", n / 2);
		else if (cnt_odd + cnt_even2 >= cnt_even + cnt_odd2) printf("%d", n - cnt_odd - cnt_even2);
		else printf("%d", n - cnt_odd2 - cnt_even);
	}	
	return 0;
}


Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;


int main(void){
	int n;
	cin>>n;
	ll ans=0;
	rep(i,n){
		int tmp=0;
		ll work;
		cin>>work;
		while(work%2 == 0){
			tmp++;
			work/=2;
		}
		ans+=tmp;
	}
	cout<<ans<<endl;
	return 0;

}


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

using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int mod = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;

struct mint {
  long long x;

  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }

  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

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

  combination comb(2000000);

  for (int i = 1; i <= k; i++) {
    mint ans = comb(n - k + 1, i) * comb(k - 1, i - 1);

    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

bool ok(vector<pair<int, int>> v){

  sort(v.rbegin(), v.rend());

  int now = 0;
  rep(i, v.size()){

    if(now + v[i].first < 0){
      return false;
    }

    now += v[i].second;
  }

  return true;

}

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

  int n;
  cin >> n;

  vector<pair<int, int>> L, R;

  int sum_h = 0;
  rep(i, n){
    string s;
    cin >> s;
    int h = 0;
    int b = 0;
    rep(j, s.length()){
      if(s[j] == '('){
        h++;
        chmin(b, h);
      }else{
        h--;
        chmin(b, h);
      }
    }
    if(h >= 0){
      L.emplace_back(b, h);
    }else{
      R.emplace_back(b-h, -h);
    }
    sum_h += h;
  }

  if(sum_h != 0){
    cout << "No" << endl;
    return 0;
  }

  if(ok(L) && ok(R)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


  return 0;
}


Measured memory_bytes: 18920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; a < b; i++);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << 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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) {
        cout << k << endl;
    } else if (k <= a + b) {
        cout << a << endl;
    } else {
        cout << a - (k - a - b) << endl;
    }
}

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



Measured memory_bytes: 3652
h, w = [int(x) for x in input().split()]
s = []
for i in range(h):
  s += [input()]

black = 0
for si in s:
  for sij in si:
    if sij == '#':
      black += 1

cnt = 0
d = []
for i in range(h):
  d.append([])
  for j in range(w):
    d[-1].append(10 ** 9)

d[0][0] = 1
q = [(0, 0)]
for k in range(h * w):
  p = q.pop(0)
  i = p[0]
  j = p[1]
  dis = d[i][j]

  if i + 1 < h:
    if s[i + 1][j] == '.':
      if dis + 1 < d[i + 1][j]:
        d[i + 1][j] = dis + 1
        q.append((i + 1, j))
  if j + 1 < w:
    if s[i][j + 1] == '.':
      if dis + 1 < d[i][j + 1]:
        d[i][j + 1] = dis + 1
        q.append((i, j + 1))
  if i - 1 >= 0:
    if s[i - 1][j] == '.':
      if dis + 1 < d[i - 1][j]:
        d[i - 1][j] = dis + 1
        q.append((i - 1, j))
  if j - 1 >= 0:
    if s[i][j - 1] == '.':
      if dis + 1 < d[i][j - 1]:
        d[i][j - 1] = dis + 1
        q.append((i, j - 1))

  if len(q) <= 0:
    break

cnt = d[h - 1][w - 1]
if cnt != 10 ** 9:
  res = h * w - black - cnt
  print(res)
else:
  print(-1)



Measured memory_bytes: 3188
#include <stdio.h>

typedef long long ll;
const ll mod = 1000003;

ll fact[mod] = { 1, };
ll fact_inv[mod] = { 1, };

inline ll get_pow(ll base, int pow)
{
	ll ret = 1;

	while (pow)
	{
		if (pow & 1) ret = (ret*base) % mod;
		base = (base*base)%mod;
		pow >>= 1;
	}

	return ret;
}

inline ll get_inv(ll num)
{
	return get_pow(num, mod - 2);
}

inline ll mod_mul(ll a, ll b)
{
	return (a*b) % mod;
}

void init()
{
	for (int i = 1; i < mod; ++i) fact[i] = (fact[i - 1] * i) % mod;
	fact_inv[mod - 1] = get_inv(fact[mod - 1]);
	for (int i = mod - 2; i >= 1; --i) fact_inv[i] = (fact_inv[i + 1] * (i + 1)) % mod;
}

int main()
{
	init();

	int Q;

	scanf("%d", &Q);

	for (int i = 0; i < Q; ++i)
	{
		ll x, d, n;

		scanf("%lld %lld %lld", &x, &d, &n);

		if (d == 0) printf("%lld\n", get_pow(x, n));
		else
		{
			if (n >= mod) printf("0\n");
			else
			{
				ll k = mod_mul(mod - x, get_inv(d));

				if (n-1 >= k) printf("0\n");
				else
				{
					ll temp = mod_mul(mod_mul(get_pow(d, n), fact[k]), fact_inv[k - n]);
					if (n & 1) temp = mod - temp;
					printf("%lld\n", temp);
				}
			}
		}
	}

	return 0;
}


Measured memory_bytes: 16384
#include<bits/stdtr1c++.h>

#include<list>
#include<algorithm>
using namespace std;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main(){
    int a;
    vector<int> penki(3);
    for (int i = 0;i < 3;i++){
        cin >> penki.at(i);
    }
    std::sort(penki.begin(), penki.end());
  penki.erase(std::unique(penki.begin(), penki.end()), penki.end());
    cout << penki.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  ll N, M, D;
  cin >> N >> M >> D;
  cout << setprecision(20) << (double)(N-D)*(D?2:1)*(M-1)/(N*N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
  ll A,B,C,X[107];
  ll N,M;
  string S;
  cin >> N;
  M=N;
  rRep(i,sqrt(N)+1,1){
    if(N%i==0){
      cout << (i-1)+(N/i)-1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
unsigned long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
unsigned long long int iremono[100001], koware[100001];
unsigned long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
vector<pair<long long int, long long int>>pairs;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool qw = false, er = false, ty = false,ui=false;
int main() {
	cin >> a>>b;

	iremono[0] = 1;
	iremono[1] = 1;
	for (int i = 2; i <= a; i++) {
		iremono[i] = (iremono[i - 1] + iremono[i-2]) % 1000000007;
	}
	if (b == 0) {
		cout << iremono[a] << endl;
		return 0;
	}
	rep(i, b) {
		cin >> koware[i];
		if (i != 0) {
			vec.push_back(koware[i] - koware[i - 1]-2);
			
		}
		else {
			vec.push_back(koware[i]-1);
		}
	
	}
	rep(i, b-1) {
		if (koware[i + 2] - koware[i+1] == 1) {
			cout << 0 << endl;
			return 0;
		}
	
	}
	vec.push_back(a - koware[b - 1]-1);
	ans = 1;
	rep(i, vec.size()) {
		
		ans = ans*iremono[vec[i]]%1000000007;
		
	}
	cout << ans%1000000007 << endl;
}


Measured memory_bytes: 3704
#include <stdio.h>

int main(){
    int a,b;
    char op;
    int result,flag=1;

    while(flag){
        scanf("%d %c %d",&a,&op,&b);
        switch (op){
            case '+':
                result = a+b;
                printf("%d\n",result);
                break;
            case '-':
                result = a-b;
                printf("%d\n",result);
                break;
            case '*':
                result = a*b;
                printf("%d\n",result);
                break;
            case '/':
                result = a/b;
                printf("%d\n",result);
                break;
            case '?':
                flag = 0;
                break;
        }
    }
        
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

vector<int> z(string s){
    int len = s.size();
    vector<int> res(len);
    res[0] = len;
    int i = 1, j = 0;
    while(i < len){
        while(i+j < len && s[j] == s[i+j]) ++j;
        res[i] = j;
        if(j == 0){ ++i; continue;}
        int k = 1;
        while(i+k < len && k+res[k] < j){
            res[i+k] = res[k], ++k;
        }
        i += k; j -= k;
    }
    rep(i,len){
        res[i] = min(res[i], i);
    }
    return res;
}

int main(){
    ll n; cin >> n;
    string s;cin >> s;
    ll ans = 0;
    rep(i,n){
        vector<int> vec = z(s.substr(i));
        // auto itr = vec.begin();itr++;
        ll temp = *max_element(vec.begin(), vec.end());
        ans = max(ans,temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long int ll;
void solve()
{
	int n;cin>>n;
	string s;cin>>s;
	if(s.size()<=n)cout << s;
	else{
		string s1;
		for(int i=0;i<n;i++){
			s1+=s[i];
		}
		s1=s1+"...";
		cout << s1;
	}
}
int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	solve();
	return 0;
}


Measured memory_bytes: 3604
import Data.List
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- replicateM n getLine
  let baseab = length . filter (=="AB") . concatMap pair $ ss
      lasta  = length . filter (not . isPrefixOf "B") . filter (isSuffixOf "A") $ ss
      firstb = length . filter (not . isSuffixOf "A") . filter (isPrefixOf "B") $ ss
      bothab = length . filter (      isSuffixOf "A") . filter (isPrefixOf "B") $ ss
  print $ baseab + solve lasta firstb bothab
  -- print $ baseab + if lasta == 0 && firstb == 0 && bothab > 0
  --                  then bothab - 1
  --                  else bothab + min lasta firstb

solve :: Int -> Int -> Int -> Int
solve x y z
  | z == 0 = min x y
  | z > 0 && x + y > 0 = z + min x y
  | z > 0 && x + y == 0 = z - 1

pair :: [a] -> [[a]]
pair [] = []
pair [x] = []
pair (x:y:xs) = [x,y] : pair (y:xs)


Measured memory_bytes: 5500
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX +1];

void maxHeapify(int i){
	int l,r,largest;
	int copy = 0;
	
	l = 2 * i;
	r = 2 * i + 1;
	
	if(l<=H && A[l]>A[i]){
		largest = l;
	}else {
		largest = i;
	}
	
	if(r <= H && A[r] > A[largest]){
		largest = r;
	}
	
	if(largest != i){
		copy = A[i];
		A[i] = A[largest];
		A[largest] = copy;
		maxHeapify(largest);
	}
}

int extract(){
	int maxv;
	if(H < 1) return  -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void swap(int x,int y){
		int copy;
		copy = A[x];
		A[x] = A[y];
		A[y] = copy;
}

void increaseKey(int i,int key){
	if(key < A[i])return;
	A[i] = key;
	while(i>1&&A[i / 2]<A[i]){
		swap(i,i/2);
		i = i/2;
	}
}

void insert(int key){
	H++;
	A[H] = -INFTY;
	increaseKey(H,key);
	
}
int main (){
	int Key;
	char com[10];
	
	while(1){
		scanf("%s",com);
		if(com[0] == 'e' && com[1] =='n')break;
		if(com[0] == 'i'){
			scanf("%d",&Key);
			insert(Key);
		}else{
			printf("%d\n",extract());
		}
		
	}
	return 0;
	
}



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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int n = Integer.parseInt(buffer.readLine());
        String [] inp = buffer.readLine().split(" ");
        int [] arr = new int[n];
        for (int pos = 0; pos < n; pos++) {
            arr[pos] = Integer.parseInt(inp[pos]);
        }
        int mod = (int) (1e9+7);
        long [] suffSum = new long[n];
        suffSum[n-1] = arr[n-1];
        for (int pos = n-2; pos >=0 ; pos--) {
            suffSum[pos] = arr[pos]+suffSum[pos+1]%mod;
            suffSum[pos]%=mod;
        }
        long sum = 0;
        for (int pos = 0; pos < n - 1; pos++) {
            sum+= (arr[pos]%mod*suffSum[pos+1]%mod)%mod;
            sum%=mod;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 61496
N,*as=$<.read.split.map(&:to_i)

ls = []
l = 0

h = Hash.new(0)
as.each do |a|
    l += a
    h[l] += 1
end

ret = h[0]
h.each do |k,v|
    ret += (v-1)*v / 2
end

puts ret

Measured memory_bytes: 38980
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

//区間[a,b]と区間[c,d]の関係
int intervalState(int a, int b, int c, int d){
    if(a < c && b < c) return 1; //定期区間と全く関係がない
    else if(a > d && b > d) return 0; //左
    else if(a <= c && d <= b) return 2; //定期区間が移動区間を内包する
    else if(c < a && b < d) return 3; //移動区間が定期区間を内包する
    else if(a <= c && b < d) return 4; //右にはみ出る
    else if(c < a && d <= b) return 5; //左にはみ出る
    return -1;
}

int main(){
    int w, a, b;
    cin >> w >> a >> b;

    int ans = 0;
    switch (intervalState(a,a + w, b, b + w)) {
        case 1:
            ans = b - (a + w);
            break;
        case 0:
            ans = a - (b + w);
            break;
        default:
            ans = 0;
            break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    while(N != 0){
        vector<int> A(K);
        for(int i=0; i<K; i++){
            cin >> A[i];
        }
        sort(A.begin(),A.end());
        bool can = false; 
        if(A[0] == 0) can = true;
        vector<pair<pair<int,int>,int>> vec;
        for(int i=0; i<K; i++){
            if(A[i] == 0) continue;
            if(!vec.size()){
                vec.push_back(make_pair(make_pair(A[i],A[i]),1));
            }else{
                if(vec.back().first.second+1 == A[i]){
                    vec.back().first.second++;
                    vec.back().second++;
                }else{
                    vec.push_back(make_pair(make_pair(A[i],A[i]),1));
                }
            }
        }
        int ans = 0;
        for(int i=0; i<vec.size(); i++){
            if(can and i < vec.size()-1){
                if(vec[i+1].first.first - vec[i].first.second == 2){
                    chmax(ans,vec[i].second + vec[i+1].second + 1);
                }
            }else{
                chmax(ans,vec[i].second);
            }
        }
        cout << ans << enld;
        cin >> N >> K;
    }
    return 0;
}



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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,a,b;
    cin >> n >> a >> b;
    
    ll ans = 0;
    
    if(n == 1 && a != b) ans = 0;
    else if(a > b) ans = 0;
    else {
        ll x = n - 2;
        ll minv = a * x;
        ll maxv = b * x;
        
        ans = maxv - minv + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let yps = Array.init m @@ fun i -> Scanf.scanf " %d %d" @@ fun a b -> b, a, i
let rs, ns = Array.(make (n + 1) 1, make m "")
let _ = Array.(sort compare yps; iter (fun (_, p, i) -> ns.(i) <- Printf.sprintf "%06d%06d" p rs.(p); rs.(p) <- rs.(p) + 1) yps; iter print_endline ns)

Measured memory_bytes: 12416
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long a,b;
    cin >> a >> b;

    if( (a - b) % 2 == 0 ){
        cout << (a + b) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}



Measured memory_bytes: 256