akhauriyash/Code-Regression huggingface dataset:
// Submitted by Subhash Yadav
import java.io.*;
import java.util.*;



public class Main {
	

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
		
		int n=sc.nextInt(),k=sc.nextInt();
		int p[]=new int[n];
		for(int i=0;i<n;i++) p[i]=sc.nextInt()-1;
		
		int c[]=sc.readArray(n);
		
		ArrayList<Long>[] pre=new ArrayList[n];
		
		for(int i=0;i<n;i++) {
			pre[i]=new ArrayList<>();
			long sum=0;
			boolean visited[]=new boolean[n];
			int x=p[i];
			while(!visited[x]) {
				visited[x]=true;
				
				sum+=c[x];
				x=p[x];
				pre[i].add(sum);
			}
			
		}
		
		long ans=Long.MIN_VALUE;
		for(int i=0;i<n;i++) {
			if(k<=pre[i].size()) {
				for(int j=0;j<k;j++) ans=Math.max(ans, pre[i].get(j));
				
			}
			else {
				long tempmax=Long.MIN_VALUE;
				long last=pre[i].get(pre[i].size()-1);
				int k1=k%pre[i].size();
			
				long maxUptoK=Long.MIN_VALUE,wholeMax=Long.MIN_VALUE;
				for(int j=0;j<pre[i].size();j++) {
					if(j<k1) maxUptoK=Math.max(maxUptoK, pre[i].get(j));
					
					wholeMax=Math.max(wholeMax, pre[i].get(j));
				}
				int div=k/pre[i].size();
				
				if(last>0) {
					tempmax=Math.max(div*last+maxUptoK, (div-1)*last+wholeMax);
				}
				else {
					tempmax=Math.max(tempmax, wholeMax);
				}
				ans=Math.max(ans, tempmax);
				
			}
			
			
		}
		System.out.println(ans);
		
	
		
		

	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

Measured memory_bytes: 871080
const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val (N, M, C) = readLine()!!.split(" ").map{it.toInt()}
    val b = readLine()!!.split(" ").map{it.toInt()}

    var cnt = 0
    for (i in 1..N) {
        val a = readLine()!!.split(" ").map{it.toInt()}
        val x = a.mapIndexed{index, it ->
            it * b[index]
        }.sum()
        if (x + C > 0) {
            cnt++
        }
    }

    println(cnt)
}


Measured memory_bytes: 37864
n, m, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for i, a in enumerate(sa):
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+r)
      
  
    
print(best)

Measured memory_bytes: 47692
#include <stdio.h>
#include <iostream>
#include <cmath>
#include<vector>
#include<queue>
#include<string>
#include <ios>
#include <iomanip>
#include<algorithm>
using namespace std;

int main() {
	queue<pair<string, int> > que;
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		string name;
		int time;
		cin >> name >> time;
		que.push(make_pair(name, time));
	}
	int sumtime = 0;
	while (!que.empty()) {
		pair < string, int > tmp = que.front();
		que.pop();
		if (tmp.second - q <= 0) {
			sumtime += tmp.second;
			cout << tmp.first << " " << sumtime << endl;
			continue;
		}
		tmp.second -= q;
		que.push(tmp);
		sumtime += q;
	}
}


Measured memory_bytes: 6156
#include<stdio.h>

int main(void){

	int m, f, r, p;
	while (1) {
		scanf("%d %d %d", &m, &f, &r);
		p = m + f;
		if (m == -1 && f == -1 && r == -1) break;
		if (m == -1 || f == -1 || p < 30) printf("F\n");
		else if (p >= 80) printf("A\n");
		else if (65 <= p && p < 80) printf("B\n");
		else if (50 <= p && p < 65) printf("C\n");
		else if (30 <= p && p < 50 && r >= 50) printf("C\n");
		else printf("D\n");
	}
    return 0;
}


Measured memory_bytes: 2080
N,W=map(int,input().split())
w=[]
v=[]
maxV=0
for i in range(N):
    a,b=map(int,input().split())
    if maxV<b:
        maxV=b
    w.append(a)
    v.append(b)
#dp[n個目のアイテムまでで][V以上を達成する]=最小のw
#dp[0][v]=inf ゼロ個でｖは無理なので
#dp[0][0]=0と初期化する
#だからiの時dp[i][v]=min(dp[i-1][v],dp[i-1][V-v[i-1]]+w[i])である<-i-1なのはvとかにはゼロ個とかないので
#V-v[i]<0ならば、とれないので前者になるね！！
#これをi=0(は初期化でする)->nまでおこない、各iについてはとりうる最大のValueを考えるが
#これは最大で各アイテムについて最大のVがあってこれにアイテム数Nを掛けたものである
#つまりdpのサイズはdp[0->N][0->maxV*N]をとればよい

dp=[[float("inf") for i in range(maxV*(N+1))] for j in range(N+1)]
dp[0][0]=0

for i in range(1,N+1):
    for val in range(maxV*N+1):
        tmp1=dp[i-1][val]#とらない
        if val-v[i-1]<0:#この時、iこめの価値がおおきいので、これをとるだけで達成してしまう
            tmp2=w[i-1]#i=1の時、dp[0][val]=inf
        else:#i=1の時val-v[0]>0で無限になるので
            tmp2=dp[i-1][val-v[i-1]]+w[i-1]#
        res=min(tmp1,tmp2)
        dp[i][val]=res
#ここでW以下となるvalの最大値をたんさくする
max=0
for value in range(len(dp[N])):
    if dp[N][value]<=W:
        if value>max:
            max=value
print(max)


Measured memory_bytes: 322032
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int i, j, k, n, m;
  int *a, *b;
  fscanf(stdin, "%d\n", &n);
  a = (int*)malloc(sizeof(int)*n);
  for (i=0; i<n; i++)
    fscanf(stdin, "%d", &a[i]);

  fscanf(stdin, "%d\n", &m);
  b = (int*)malloc(sizeof(int)*m);
  for (i=0; i<m; i++)
    fscanf(stdin, "%d", &b[i]);
  j=0;
  for (i=0; i<m; i++) {
    for (; j<n && b[i]>=a[j]; j++) {
      if (b[i]==a[j]) goto next;
    }
    putc_unlocked('0', stdout);
    putc_unlocked('\n', stdout);
    break;
  next:
    ;
  }
  if (i==m) {
    putc_unlocked('1', stdout);
    putc_unlocked('\n', stdout);
  }
    
  return 0;
}



Measured memory_bytes: 3232
#include "bits/stdc++.h"
using namespace std;

int main(){
	double a;
	double ans=0;
	double ans2=51;
	while(cin>>a){
		ans=max(ans,a);
		ans2=min(ans2,a);
	}
	
	cout<<ans-ans2<<endl;
	return 0;
}

Measured memory_bytes: 3256
W,H,N = map(int,input().split(" "))
Lx = [1 for i in range(W)]
Ly = [1 for i in range(H)]
 
for i in range(N):
  xi,yi,ai = map(int,input().split(" "))
  if ai ==1:
    for j in range(xi):
      Lx[j] = 0
         
  if ai ==2:
    for j in range(xi,W):
      Lx[j] = 0
    
  if ai ==3:
    for j in range(yi):
      Ly[j] = 0
    
  if ai ==4:
    for j in range(yi,H):
      Ly[j] = 0
x = sum(Lx)
y = sum(Ly)
 
print(x*y)

Measured memory_bytes: 3064
extern crate core;

use std::collections::HashSet;
use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64 k:usize)(list:[i64]));
    let mut set = list
        .into_iter()
        .map(|x| x.to_string().chars().collect::<Vec<_>>()[0])
        .collect::<HashSet<_>>();
    for x in n.. {
        if x.to_string().chars().all(|c| !set.contains(&c)) {
            return x.to_string();
        }
    }
    panic!();
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "1000 8\n1 3 4 5 6 7 8 9" => "2000",
    test2: "9999 1\n0" => "9999",
}


Measured memory_bytes: 4352
#include<stdio.h>
main()
{
	int l,m,n;
	int a[200][200]={0},b[200][200]={0};
	long long int c[200][200]={0};
	scanf("%d %d %d",&n,&m,&l);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<l;j++)
		{
			scanf("%d",&b[i][j]);
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int k=0;k<m;k++)
		{
			for(int j=0;j<l;j++)
		   {
			c[i][j]=c[i][j]+a[i][k]*b[k][j];
		   }
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<l;j++)
		{
		    if(j!=0) printf(" ");
			printf("%lld",c[i][j]);
			
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * 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;
}
int main() {
    int N;
    cin >> N;
    set<string> se;
    rep(i, 0, N) {
        string s;
        cin >> s;
        se.insert(s);
    }
    cout << se.size() << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m), a(m);
    rep(i, m) cin >> b[i];

    int res = 0;
    rep(i, n)
    {
        rep(j, m) cin >> a[j];
        int tmp = c;
        rep(j, m) tmp += b[j] * a[j];
        if (tmp > 0)
            res++;
    }

    cout << res << '\n';
    return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int> A(N + 1), dp(N + 1);
  for(int i = 1; i <= N; i++){
    cin >> A[i];
  }
  int min = A[1];
  dp[1] = 1;
  for(int i = 2; i <= N; i++){
    if(A[i] >= min) dp[i] = dp[i - 1];
    else{
      dp[i] = dp[i - 1] + 1; min = A[i];
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
typedef long double ld;
using namespace std;
///////////////////////////
#define INF 10000000000000009
#define MAX_V 100001
typedef pair<ll, ll> p;
struct edge{ll to, cost;};
std::vector<vector<edge> > G(MAX_V);
std::vector<ll> pre(MAX_V,-1);
priority_queue<p, std::vector<p>, greater<p> > que; //class, inner, compair
std::vector<ll> d(MAX_V+1, INF);
std::vector<ll> ds(MAX_V, 0), dt(MAX_V, 0), DS(MAX_V, 0), DT(MAX_V, 0);
ll P = 1000000007;
void dijkstra(int start, int mode){
  d[start]=0;
  que.push(p(0, start));
  while(!que.empty()){
    p p_now=que.top(); que.pop();
    ll v = p_now.second;
    if(d[v]<p_now.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to]==d[v]+e.cost) (mode==1?ds[e.to]:dt[e.to]) = ((mode==1?ds[e.to]:dt[e.to]) +  (mode==1?ds[v]:dt[v]))%P;
      if(d[e.to]>d[v]+e.cost){
        (mode==1?ds[e.to]:dt[e.to]) = (mode==1?ds[v]:dt[v]);
        d[e.to]=d[v]+e.cost;
        pre[e.to] = v;
        que.push(p(d[e.to], e.to));
      }
    }
  }
}
ll pm(ll a, ll b){return (a - b + P)%P;}
ll pp(vector<ll> a){
  ll ret = 1;
  for(int i=0;i<a.size();i++) ret = (ret * a[i])%P;
  return ret;
}
/////////////////////////////////////////////
int main(int argc, char const *argv[]) {
  ll N, M, S, T, a, b, c, ans = 0;
  std::cin >> N >> M;
  std::cin >> S >> T;
  vvl eg = vv(0, 3, 0, ll);
  for(int i=0;i<M;i++){
    scanf("%lld %lld %lld", &a, &b, &c);
    eg.push_back(std::vector<ll> {a, b, c});
    eg.push_back(std::vector<ll> {b, a, c});
    G[a].push_back(edge{b, c});
    G[b].push_back(edge{a, c});
  }

  ds[S] = dt[T] = 1;
  dijkstra(S, 1);
  for(int i=1;i<=N;i++) DS[i] = d[i];
  for(int i=1;i<=N;i++) d[i] = INF;
  dijkstra(T, -1);
  for(int i=1;i<=N;i++) DT[i] = d[i];
  if(DS[T]==INF){
    std::cout << 0 << '\n';
    return 0;
  }
  ans = (ds[T]*ds[T])%P;
  for(int i=1;i<=N;i++){
    if(DS[T] == 2 * DS[i]){
      ans = pm(ans, pp(vector<ll> {ds[i], ds[i], dt[i], dt[i]}));
    }
  }
  for(int i=0;i<eg.size();i++){
    if(2*DS[eg[i][0]]<DS[T]&&2*DS[eg[i][1]]>DS[T]&&DS[eg[i][0]]+eg[i][2]+DT[eg[i][1]]==DS[T]){
      ans = pm(ans, pp(vector<ll> {ds[eg[i][0]], ds[eg[i][0]], dt[eg[i][1]], dt[eg[i][1]]}));
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 43432
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n+1];
        int ans = 0;
        for (int i = 1; i <= n; i++){
            int tmp = sc.nextInt();
            arr[i] = tmp;
            if (tmp < i && arr[tmp] == i)
                ans++;
        }
        System.out.println(ans);
    }
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll n,h,w;cin>>n>>h>>w;
  cout<<(n-h+1)*(n-w+1)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
LL dp[1000005];
int main(){
    int n;
    scanf("%d", &n);

    LL res1 = (n-1)*1ll*n%mod;
    LL res2 = 0;
    dp[1] = n;
    for(int i=2;i<=n;i++){
        if(i >= 4){
            res1 = (res1 - n + mod)%mod;
            res2 = (res2 + dp[i-3] + n-1)%mod;
        }
        dp[i] = (dp[i-1] + res1 + res2)%mod;
    }
    printf("%lld\n", dp[n]);
}

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

char S[100001];
char R[100001];
int res[100000];
int len;
int pos(int);

int main(int argc, char *argv[]) {
	int sr;
	int i, j;

	sr=scanf("%s", S);

	len = strlen(S);
	for (i=0; i<len; i++) {
//printf("R[%d] = S[%d](%c)\n", i, len-i-1, S[len-i-1]);
		R[i] = S[len-i-1];
	}
	R[len] = '\0';
//printf("R=%s\n", R);
	for (i=0; i<len; i++) {
//printf("pos(%d)=%d\n", i, pos(i));
		res[pos(i)]++;
	}

	printf("%d", res[0]);
	for (i=1; i<len; i++)
		printf(" %d", res[i]);
	printf("\n"); fflush(stdout);

	return 0;

}

int pos(int p) {
	int r;
	int strfchr(char *);
	int strbchr(char *);

	if (S[p] == 'R') {
		r = strfchr(S+p+1);
		if (r%2) {
			return p+r+1;
		} else {
			return p+r;
		}
	} else {
		r = strbchr(R+len-p);
		if (r%2) {
			return p-r-1;
		} else {
			return p-r;
		}
	}
}
int strfchr(char *str) {
	char *st;

	st = strchr(str, 'L');
	return st - str;
}
int strbchr(char *str) {
	char *st;

	st = strchr(str, 'R');
	return st - str;
}
/*
int strbchr(char *str) {
	char *st;

	st = str;
	while (*str != 'R') str--;
	return st - str;
}
*/


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*2
#define mod 1000000007
#define ll long long
int n;int m[nn];
int main()
{
	cin>>n;for(int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);
		m[i]=x;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		int t=m[i]/2;
		if(m[i]%2 and m[i+1])
			t++,m[i]--,m[i+1]--;
		ans+=t;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

#define LOCAL

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
#else
    #define dbg(x)
#endif

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    cout << "\n";
    return a;
}

const int INF = 1e18;
//const int mod = 2600000069;
//const int p = 179;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int kek = 1;
    int cur = a[0];
    for (int i = 1; i < n; i++) {
        if (cur > a[i]) {
            kek++;
            cur = a[i];
        }
    }
    cout << kek;
}
/*
*/


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int MAXN = 25;
const int inf = 0x3f3f3f3f;
typedef long long LL;
int vis[MAXN][MAXN];
char G[MAXN][MAXN];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int h, w;
typedef struct point{
     int x;
     int y;
     int step;
}P;
int bfs(int x, int y)
{
    queue<P>q;
    int ans=0;
    while(!q.empty())
        q.pop();
    vis[x][y]=1;
    q.push((P){x,y,0});
    while(!q.empty())
    {
        P tmp = q.front();
        ans=max(ans, tmp.step);
        q.pop();
        for(int i=0;i<4;++i)
        {
            int nx = dx[i] + tmp.x;
            int ny = dy[i] + tmp.y;
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&G[nx][ny]=='.'&&!vis[nx][ny])
            {
                vis[nx][ny]=1;
                q.push((P){nx, ny,tmp.step+1});
            }
        }
    }
    return ans;
}

int main()
{
    scanf("%d %d", &h, &w);
    for(int i=0;i<h;++i)
        scanf("%s", G[i]);
    int ans=0;
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            if(G[i][j]=='.')
            {
                memset(vis,0, sizeof(vis));
                ans=max(ans, bfs(i,j));
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
        public static void main(String[] args){
                try(Scanner sc = new Scanner(System.in)){
                        int A = sc.nextInt() % 3;
                        int B = sc.nextInt() % 3;
                        if(A == B && A != 0){
                                System.out.println("Impossible");
                        }else{
                                System.out.println("Possible");
                        }
                }
        }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(void){
  int N, M; cin >> N >> M;
  vector<int> X(M);
  vector<P> cost(M-1);  // cost[i].first = X[cost[i].second + 1] - X[cost[i].second]
  vector<int> graph(M-1, false); // graph[i] is true if X[i+1] and X[i] are connected
  for(int i = 0; i < M; i++){
    cin >> X[i];
  }
  sort(X.begin(), X.end());
  for(int i = 0; i < M-1; i++){
    cost[i].second = i;
    cost[i].first = X[i+1] - X[i];
  }

  sort(cost.begin(), cost.end());
  for(int i = 0; i < M-N; i++){
    int edge_idx = cost[i].second;
    graph[edge_idx] = true;
  }

  int ans = 0;
  for(int i = 0; i < (int)graph.size(); i++){
    if(graph[i] == true){
      ans += X[i+1] - X[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, p, q, m, s, e;
int t[100000];

int main(){
  while(scanf("%d%d%d", &n, &p, &q) && n+p+q){
    p = (p/100)*60 + (p%100);
    q = (q/100)*60 + (q%100);
    memset(t, 0, sizeof(t));
    rep(i, n){
      scanf("%d", &m);
      rep(j, m){
	scanf("%d%d", &s, &e);
	s = (s/100)*60 + (s%100);
	e = (e/100)*60 + (e%100);
	REP(k, s, e) t[k]++;
      }
    }

    //    REP(i, p, q) printf("%d ", t[i]); puts("");
    int res = 0, c = 0;
    REP(i, p, q){
      if(t[i] == n){
	c = 0;
      }else{
	c++;
	res = max(res, c);
      }
    }

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

Measured memory_bytes: 1584
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n,y;
	cin>>n>>y;
	
	for(int i=0;i<n+1;i++){
		for(int j=0;j<n-i+1;j++){
			int k=n-i-j;
			if(i*10000+j*5000+k*1000==y){
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
	}
	
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<chrono>
#include<random>
#include<cstdio>
#include<set>
#include<map>
#include<numeric>
#include<cfenv>
#include<cmath>
#define MAX_N pow(10,6)
#define MAX_M pow(10,6)
#define INF pow(10,6)
#define REP(i,n) for(long long i=0;i<n;i++)
typedef long long ll;
using namespace std;
//vector<vector<int>>dp(MAX_N,vector<int>(MAX_N));
//vector<pair<int,int>>item_retail(MAX_N);
int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    bool c=false;
    REP(i,1000){
        if(a<=k*i&&k*i<=b){
            c=true;
            break;
        }
    }
    if(c){
        cout<<"OK";
    }else{
        cout<<"NG";
    }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int A,B;cin >> A >> B;
  if(A>=13) cout << B << endl;
  else if(A>=6) cout << B/2 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    long term;
    cin >> term;

    vector<long> v(term*3);
    for (long i = 0; i < term*3; i++)
    {
        long a;
        cin >> a;
        v[i] = a;
    }

    std::sort(v.begin(), v.end());
    std::reverse(v.begin(), v.end());

    unsigned long sum = 0;
    for (long i = 0; i < term; i++)
    {
        sum += v[(i*2)+1];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2560
// 2020-09-16 23:25:16
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    chmax(v[b], a);
  }
  int c = 0, ans = 0;
  REPC(i, 2, n) {
    if (c < v[i]) {
      ans++;
      c = i - 1;
    }
  }
  cout << ans << '\n';
}

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

Measured memory_bytes: 3740
a,b = map(int, input().split())
c = list(map(int, input().split())) 
c.sort()
c.reverse() 
d = c[0]   
for i in range (1, a):
  while c[i] != 0:
    d , c[i] = c[i] , d % c[i]
if b > c[0]:
  print('IMPOSSIBLE')
else:
  print('POSSIBLE' if b%d == 0 else 'IMPOSSIBLE')

Measured memory_bytes: 19944
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
#define ulta(i,n,a) for(ll i=n;i>=a;i--)
#define pi acos(-1)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ve vector<ll>
#define se set<ll>
#define pll vector<pair<ll,ll>>
const string space=" ";
const ll maxx=200;
ll n,m,k,sum,faltu,t,p,i,j;
bool fg,a[maxx];
int main()
{
cin>>n>>m;
se s;
while(m--)
{
cin>>k;
while(k--)
{cin>>t;
s.insert(t);}}
cout<<n-s.size()<<endl;
    return 0;
}

Measured memory_bytes: 3632
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
ll dp[10005][2][2][3][8]={};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,a,b,ans=0;
  cin >> n >> m;
  vector<int> v[100005]={};
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  priority_queue<int> q;
  for(int i=1; i<=m; i++) {
    for(auto p:v[i]) {
      q.push(p);
    }
    if(q.size()) {
      ans+=q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include<algorithm>
using namespace std;
const int maxn=4005;
using ll = long long;
int dp[maxn][maxn];
int main()
{
       string a,b;
       cin>>a>>b;
       memset(dp,0,sizeof(dp));
       int la=a.size(),lb=b.size();
       for(int i=1;i<=la;++i){
           for(int j=1;j<=lb;++j){
               if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
               else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           }
       }
       if(dp[la][lb]==0) return 0;
       string ans="";
       int i=la,j=lb;
       while(i>=1&&j>=1){
            if(dp[i-1][j]==dp[i][j]) i--;
            else if(dp[i][j-1]==dp[i][j]) j--;
            else{
                ans+=a[i-1];
                i--;
                j--;
            }
       }
       reverse(ans.begin(),ans.end());
       cout<<ans<<endl;



   return 0;
}
//

Measured memory_bytes: 62976
#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MSIZE = 100200;

const long long mod = 1e9 + 7;

long long dp[101][MSIZE];
long long pref[MSIZE];

long long Get(int l, int r) {
    l = max(0, l);
    return (mod + pref[r] - (l ? pref[l - 1] : 0LL)) % mod;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, 0, sizeof dp);
    int n, k;
    cin >> n >> k;
    dp[0][0] = 1;
    long long answer = 1;
    
    int * arr = new int[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }

    for (int i = 1; i <= n; i++) {
        memcpy(pref, dp[i - 1], sizeof pref);
        for (int u = 1; u <= k; u++) {
            pref[u] += pref[u - 1];
            pref[u] %= mod;
        }
        for (int u = 0; u <= k; u++) {
            dp[i][u] = Get(u - arr[i], u);       
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 80128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int ufroot(int x){return unicnt[x]<=0?-(unicnt[x]=-ufroot(-unicnt[x])):x;}
int ufsame(int x,int y){return ufroot(x)==ufroot(y);}
void uni(int x,int y){if((x=ufroot(x))==(y=ufroot(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

int flag[100010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	ufinit(n+1);
	rep(i,0,m){
		int a,b;
		scanf("%d%d",&a,&b);
		uni(a,b);
	}
	
	int ans=0;
	rep(i,1,n+1){
		int r=ufroot(i);
		if(!flag[r]){
			flag[r]=1;
			ans++;
		}
	}
	printf("%d",ans-1);
}



Measured memory_bytes: 2512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>

const double eps = 1e-8;
const double INF = 1e50;

__inline int sgn(const double &x) {
	return x < -eps ? -1 : x > eps;
}

typedef std::pair<double, double> Interval;

int n;
double l, m, r;
std::vector<Interval> intervals[2];

void insert(const Interval &a, const Interval &b, int now) {
	Interval result = Interval(a.first + b.first, a.second + b.second);
	if (result.second < -m - eps || result.first > m + eps) {
		return;
	}
	result.first = std::max(result.first, -m);
	result.second = std::min(result.second, m);
	if (result.second - result.first > -eps) {
		intervals[now].push_back(result);
	}
}

int main(void) {
	int now = 0;
	intervals[0].push_back(Interval(0, 0));

	scanf("%d%lf%lf%lf", &n, &l, &m, &r);
	for (double w; n--; ) {
		scanf("%lf", &w);
		
		intervals[now ^ 1].clear();
		for (int sign = -1; sign <= 1; sign += 2) {
			Interval interval = Interval(sign * w * r, sign * w * l / 2);
			if (interval.first > interval.second) {
				std::swap(interval.first, interval.second);
			}
			for (int i = 0; i < (int)intervals[now].size(); ++i) {
				insert(interval, intervals[now][i], now ^ 1);
			}
		}
		
		now ^= 1;
		std::sort(intervals[now].begin(), intervals[now].end());
/*		
		for (int i = 0; i < (int)intervals[now].size(); ++i) {
			printf("%f %f\n", intervals[now][i].first, intervals[now][i].second);
		}
		puts("");
*/		
		std::vector<Interval> list;
		Interval interval = Interval(-INF, -INF);
		for (int i = 0; i < (int)intervals[now].size(); ++i) {
			if (interval.second > intervals[now][i].first - eps) {
				interval.second = std::max(interval.second, intervals[now][i].second);
			} else {
				if (interval.first + interval.second > -INF) {
					list.push_back(interval);
				}
				interval = intervals[now][i];
			}
		}
		if (interval.first + interval.second > -INF) {
			list.push_back(interval);
		}
		
		if (list.empty()) {
			puts("No");
			return 0;
		}
		
		intervals[now] = list;
/*
		for (int i = 0; i < (int)intervals[now].size(); ++i) {
			printf("%f %f\n", intervals[now][i].first, intervals[now][i].second);
		}
		puts("");
*/	}
	puts("Yes");
}

Measured memory_bytes: 1048
s = input()
t = input()
LENs = len(s)
LENt = len(t)
dp = [[0 for i in range(LENt+1)] for j in range(LENs+1)]
for i in range(LENs+1):
    for j in range(LENt+1):
        if i+1 <= LENs:
            dp[i+1][j] = max(dp[i+1][j],dp[i][j])
        if j+1 <= LENt:
            dp[i][j+1] = max(dp[i][j+1],dp[i][j])
        if i+1 <= LENs and j+1<=LENt:
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j]+1

ans = ''
x = LENs
y = LENt
while True:
    if len(ans)==dp[-1][-1]:
        break
    if dp[x-1][y] ==dp[x][y]:
        x = x-1
    elif dp[x][y] == dp[x][y-1]:
        y = y-1
    elif dp[x-1][y-1]+1== dp[x][y]:
        ans =s[x-1] + ans
        x = x-1
        y = y-1
        continue
#     elif dp[x-1][y] == dp[x][y-1]:
#         x = x-1

print(ans)

Measured memory_bytes: 122076
n = int(input())
num = [0]*(n+1)
ans = 1
for i in range(2,n+1):
    j=2
    while j<n+1 and i>1:
        if i%j==0:
            i=i//j
            num[j]+=1
        else:
            j+=1
for i in num:
    ans=ans*(i+1)%1000000007
print(ans)


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N)
{

    string s = to_string(N);

    string ans = NO;
    if (s.find("7") != string::npos)
    {
        ans = YES;
    }

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

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

    long long money;
    for(long long i = 1; i <= 10; i++){
        if(n <= 1000 * i){
            money = 1000*i;
            break;
        }
    }

    cout << money - n << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main () {
	int argN, argA, argB;
	cin >> argN >> argA >> argB;

	int ret = 0;
	for (int n = 0; n <= argN; ++n) {
		int target = n;
		int sum = 0;
		
		sum += target / 10000;
		target %= 10000;

		sum += target / 1000;
		target %= 1000;

		sum += target / 100;
		target %= 100;

		sum += target / 10;
		target %= 10;

		sum += target;

		if (sum >= argA && sum <= argB) {
			ret += n;
		}
	}

	cout << ret << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

int gcd(int a, int b);
int lcm(int a, int b);

void solve_A(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);

    if(a[0] == a[1] && a[1] != a[2]) cout << "Yes";
    else if(a[0] != a[1] && a[1] == a[2]) cout << "Yes";
    else cout << "No";
}

void solve_B(){
    int n;
    cin >> n;
    int a[n];
    REP(i,n) cin >> a[i];

    bool flag = true;
    REP(i,n){
        if(a[i] %2 == 0){
            if(a[i] % 3 != 0 && a[i] % 5 != 0) flag = false;
        }
    }

    if(flag) cout << "APPROVED";
    else cout << "DENIED";
}

struct sC{
    int number;
    string s;
};

int comp(const void *a, const void *b){
    return -((struct sC*)a) -> number + ((struct sC*)b) -> number;
}

void solve_C(){
    int n;
    cin >> n;
    string s[n];
    REP(i,n){
        cin >> s[i];
    }

    sort(s,s+n);

    vector<int> vec;
    vec.push_back(0);

    int ctr = 0;
    REP(i,n-1) if(s[i] != s[i+1]){
        vec.push_back(i+1);
    }
    
    int m = vec.size()+1;
    vec[m-1] = n;

    int size = m-1;
    struct sC ans[size];

    REP(i,m-1){
        ans[i].number = vec[i+1] - vec[i];
        ans[i].s = s[vec[i]];
    }
    
    int mm = sizeof(ans) / sizeof(struct sC);
    qsort(ans, mm, sizeof(struct sC), comp);

    REP(i,size){
        cout << ans[i].s << endl;
        if(i < size - 1 && ans[i].number > ans[i+1].number) break;
    }
}

int main(void){
    solve_C();
    
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

int lcm(int a, int b){
    return a * b / gcd(a, b);
}

Measured memory_bytes: 19572
N, *AB = map(int, open(0).read().split())
A = sorted(AB[::2])
B = sorted(AB[1::2])
if N % 2:
    print(B[N // 2] - A[N // 2] + 1)
else:
    print(B[N // 2 - 1] + B[N // 2] - A[N // 2 - 1] - A[N // 2] + 1)


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

using namespace std;

const int MX = 1000000;

char s[MX + 1];

int brute(int n) {
	vector<int> a(n);
	for (int i = 0; i < n; i++) a[i] = s[i] - '1';
	for (int k = n; k > 1; k--)
		for (int i = 1; i < k; i++)
			a[i - 1] = abs(a[i - 1] - a[i]);
	
	return a[0];
}

int calc(char* s, char v, int n) {
	int res = 0;
	for (int i = 0; i < n; i++)
		if (((n - 1) & i) == i)
			if (s[i] == v) res ^= 1;
	
	return res;
}

int main() {
//for (int it = 0; it < 100000; it++) {
	int n;
	ignore = scanf("%d %s", &n, s);
	
//	int n = 15;
//	for (int i = 0; i < n; i++) s[i] = '1' + rand() % 3;
	
	int one = calc(s, '2', n);
	int two = calc(s, '3', n);
	
	int ans;
	if (one == 1) ans = 1;
	else if (count(s, s + n, '2') > 0) ans = 0;
	else ans = 2 * two;
	
	printf("%d\n", ans);
//	int real = brute(n);
//	if (real != ans) {
//		s[n] = 0;
//		printf("Fail: %s\n", s);
//		return 0;
//	}
	
//	if (it % 10000 == 0) printf("%d ok\n", it + 1);
//}
	
	return 0;
}


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

using namespace std;

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> c(N), t(N);

    for(int i=0; i<N; i++){
        cin >> c.at(i) >> t.at(i);
    }

    int ans=1000;
    bool frag=false;

    for(int i=0; i<N; i++){
        if(t.at(i) <= T){
            ans = min(ans, c.at(i));
            frag =true;
        }
    }

    if(frag){
        cout << ans << endl;
    }
    else cout << "TLE" << endl;
}

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

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

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

    deque<int> dq;
    for(int i = 0; i < n; i++){
        int idx = lower_bound(dq.begin(), dq.end(), A[i]) - dq.begin();
        if(idx == 0){
            dq.push_front(A[i]);
        }else{
            dq[idx - 1] = A[i];
        }
    }

    cout << dq.size() << endl;

    return 0;
}

Measured memory_bytes: 1024
import scala.io.StdIn._
object Main extends App {

  val prime = primes(100000)
  val isM = Array.fill(100001){1}.also{a ⇒ a(0) = 0; a(1) = 0}
  for (i ← prime.indices) {
    for (j ← 0 until upperLimit(0, i + 1, prime, 100000 / prime(i))) {
      isM(prime(i) * prime(j)) = 0
    }
    isM(prime(i)) = 0
    if (prime(i).toLong * prime(i) * prime(i) <= 100000) isM(prime(i) * prime(i) * prime(i)) = 0
  }
  for (i ← isM.indices.tail) isM(i) += isM(i - 1)
  for (_ ← 0 until readInt()) {
    val n = readInt()
    println(isM(n))
  }

  def upperLimit(from: Int, until: Int, array: Array[Int], target: Int): Int = {
    var left = from
    var right = until
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) <= target) left = mid + 1
      else right = mid
    }
    right
  }
  def primes(upperLimit: Int): Array[Int] = {
    val isPrime = Array.fill(upperLimit + 1){true}
    for (i ← 2 to math.sqrt(upperLimit).ceil.toInt if isPrime(i)) {
      for (j ← i * i to upperLimit by i){
        isPrime(j) = false
      }
    }
    (2 to upperLimit).filter(isPrime).toArray
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    def let[A](@inline func: T ⇒ A): A = func(value)
    def also(@inline func: T ⇒ Unit): T = {func(value);value}
  }
}


Measured memory_bytes: 75408
n, m = map(int, input().split())
py_array = [[int(x) for x in input().split()] for y in range(m)]
py_dict = {x: y for x, y in enumerate(py_array, 1)}
py = sorted(py_dict.items(), key=lambda x: x[1][1])
ans = {}
now = min([x[0] for x in py_array])
index = 0
index_array = {x: 0 for x in [x[0] for x in py_array]}
for key, value in py:
    index_array[value[0]] += 1
    index = index_array[value[0]]
    ken = str(value[0])
    si = str(index)
    ans[key] = ken.zfill(6) + si.zfill(6)
    now = value[0]
for key, value in ans.items():
    print(value)


Measured memory_bytes: 109524
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)
	as := make([]int, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&as[i])
	}

	l, r := 0, int(1e18)
	for r-l > 1 {
		mid := (l + r) / 2
		res := calc(mid, as)
		if res < 2 {
			l = mid
		} else {
			r = mid
		}
	}
	mn := r

	l, r = 0, int(1e18)
	for r-l > 1 {
		mid := (l + r) / 2
		res := calc(mid, as)
		if res <= 2 {
			l = mid
		} else {
			r = mid
		}

	}
	mx := l

	if mn > mx {
		fmt.Println(-1)
		return
	}

	fmt.Println(mn, mx)
}

func calc(x int, as []int) int {
	for i := 0; i < len(as); i++ {
		x -= x % as[i]
	}
	return x
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int f(int n,int k){
	if(k>n) return 0;
	if(k==0) return 1;
	if(k==1) return n;
	if(k==2) return n*(n-1)/2;
	if(k==3) return n*(n-1)*(n-2)/6;
}
int tenth(int k){
	int ret = 1;
	for(int i=0; i<k; i++) ret*=9;
	return ret; 
}
int main(){
	string s;
	int k;
	cin>>s>>k;
	vector<int>arr(s.length()+1,0);
	int n = s.length();
	for(int i=0; s[i]; i++){
		arr[i+1] = (int)(s[i]-'0');
	}
	int ret = 0;
	
	for(int i=1; i<=n; i++){
		for(int j=0; j<arr[i]; j++){
			if(j==0) ret+=tenth(k)*f(n-i,k);
			else ret+=tenth(k-1)*f(n-i,k-1);
		}
		if(arr[i]) k--;
		if(k==0){
			ret++;
			break;
		}	
	}
	cout<<ret;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(i, v) for(auto i =  v.begin(); i !=  v.end(); ++i)
#define RFOR(i, v) for(auto i = v.rbegin(); i != v.rend(); ++i)

template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "[";
	FOR(it, v) {
		if(it != v.begin()) { os << ", "; }
		os << *it;
	}
	os << "]";
	return os;
}
template<typename F, typename S> ostream & operator<<(ostream & os, const pair<F, S> & p) {
	os << "<" << p.FI << ", " << p.SE << ">";
	return os;
}

// ---- ----

const LL MOD = 1000000007;
LL n;
bool p[1001];

// サンプル通らない

int main() {
	cin >> n;
	
	inc1(i, n) {
		int d = 0;
		inc1(j, i) { if(i % j == 0) { d++; } }
		if(d == 2) { p[i] = true; }
	}
	
	LL ans = 1;
	inc1(i, n) {
		if(p[i]) {
			LL x = i, e = 0;
			while(x <= n) {
				e += n / x;
				x *= i;
			}
			// cout << "i: " << i <<  ", e: " << e << endl;
			(ans *= e + 1) %= MOD;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

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

  if (a >= b)
    cout << "delicious" << endl;
  else if (n + a >= b)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}


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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int N,M;
int A[100000];

int num_two(int n) {
  int i = 0;
  while(n%2==0) {
    i++;
    n/=2;
  }
  return i;
}

signed main() {
  cin >> N >> M;
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) A[i] /= 2;

  int t = num_two(A[0]);
  for(int i=0; i<N; i++) {
    if(t!=num_two(A[i])) {
      puts("0");
      return 0;
    }
    A[i] >>= t;
  }

  M >>= t;

  int d = A[0];
  for(int i=1; i<N; i++) {
    d = lcm(d, A[i]);
    if (d > M) {
      puts("0");
      return 0;
    }
  }
  int ans = 0;
  int x = 1;
  while(d*x <= M) {
    ans++;
    x+=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())


def f(n):
    return (10 - (n % 10)) % 10


ans = a + b + c + d + e
ans += f(a) + f(b) + f(c) + f(d) + f(e)
ans -= max(f(a), f(b), f(c), f(d), f(e))

print(ans)

Measured memory_bytes: 3064
from math import log
n = int(input())
s = ""
if n != 0:
    for i in range(int(log(abs(n),2))+3):
        #print("i=",i)
        if n % 2**(i+1) == 2**i:
            s = "1" + s
            n -= (-2)**(i)
            #print(i,n)
        else:
            s = "0" + s
    for j in s[s.find("1"):]:
        print(j,end = "")
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int N; cin>>N;
  int odd=0;
  int even=0;
  for(int i=0; i<N; i++){
    int a; cin>>a;
    if(a%2==0) even++;
    if(a%2==1) odd++;;
  }
  cout<<pow(3, N)-pow(2, even)<<endl;
}

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

int main(){
    int x;
    cin >> x;
    if(x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3612