akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

double tl[110] = {},v[110] = {},tr[110] = {},t[110] = {};

int main(void){
   
   int n,sum = 0;
   cin >> n;
   
   for(int i = 1; i <= n; i++){
       cin >> t[i];
       tl[i] = sum;
       sum += t[i];
       tr[i] = sum;
   }
   
   for(int i = 1; i <= n; i++){
       cin >> v[i];
   }
   
   tr[n+1] = tl[n+1] = sum;
   
   double before = 0,now,answer = 0;
   
   for(double i = 0; i <= sum; i+=0.5){
       
       now = before + 0.5;
       
       for(int j = 0; j <= n+1; j++){
           if(tl[j] <= i && i  <= tr[j] ){
               //cout << tl[j] << " " << tr[j] << " " << j << ":" << now << endl;
               now = min(now,v[j]);
           }
           if(tl[j] > i){
               //cout << tl[j] << " " << i << " " << j << endl;
               now = min(now,v[j] + (tl[j]-i));
           }
           
       }
       
       //cout << now << endl;
       
       answer += ((before + now) * 0.5)/2;
       
       before = now;
       
   }
   
   printf("%.5lf\n",answer);
}

Measured memory_bytes: 256
# coding:utf-8

N, T = [int(i) for i in input().split()]
keiros = []
for i in range(N):
	c, t = [int(j) for j in input().split()]
	if t <= T:
		keiros.append(c)
if not keiros:
	print("TLE")
else:
	print(min(keiros))


Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTemplateMatching solver = new BTemplateMatching();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTemplateMatching {
        private static final String YES = "Yes";
        private static final String NO = "No";

        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints(), m = in.ints();
            String[] a = in.string(n), b = in.string(m);
            for (int i = 0; i <= n - m; i++) {
                outer:
                for (int j = 0; j <= n - m; j++) {
                    for (int y = 0; y < m; y++) {
                        for (int x = 0; x < m; x++) {
                            if (b[y].charAt(x) != a[i + y].charAt(j + x)) {
                                continue outer;
                            }
                        }
                    }
                    out.println(YES);
                    return;
                }
            }
            out.println(NO);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String[] string(int length) {
            return IntStream.range(0, length).mapToObj(x -> string()).toArray(String[]::new);
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 26068
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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(){
    ll x, k, d; cin >> x >> k >> d;
    ll X = abs(x), res;
    ll num = X / (double)d;
    if(num > k){
        res = X - k * d;
    }else{
        ll tmp = X / d;
        ll a = X - d * tmp, b = a - d;
        if(k%2==tmp%2)res = a;
        else res = abs(b);
    }
    cout << res << ln;
}
    


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)

const long long MOD = 2;
using lli = long long int;

void solve(long long k, long long q, std::vector<long long> d,
           std::vector<long long> n, std::vector<long long> x,
           std::vector<long long> m)
{
  rep(i, q)
  {
    lli tmp = 0;
    lli ans = 0;
    if (n[i] <= k)
    {
      lli cur = 0;
      vector<int> a(n[i]);

      rep(j, n[i])
      {
        if (j == 0)
          a[j] = x[i];
        else
          a[j] = a[j - 1] + d[(j - 1) % k];
        a[j] %= m[i];
      }
      rep(j, n[i] - 1)
      {
        if (a[j] < a[j + 1])
          ans++;
      }
      cout << ans << endl;
    }
    else
    {
      lli neko = 0;
      rep(j, k)
      {
        tmp += d[j] % m[i];
        if ((d[j] % m[i]) == 0)
          neko++;
      }
      lli hoge = tmp * ((n[i] - 1) / k);
      neko = neko * ((n[i] - 1) / k);
      lli fuga = hoge;
      rep(j, (n[i] - 1) % k)
      {
        fuga += d[j] % m[i];
        if ((d[j] % m[i]) == 0)
          neko++;
      }
      //fuga -= d[0] % m[i];
      fuga += x[i] % m[i];
      cout << n[i] - 1 - (fuga / m[i]) - neko << endl;
    }
  }
}

int main()
{
  long long k;
  scanf("%lld", &k);
  long long q;
  scanf("%lld", &q);
  std::vector<long long> d(k - 1 - 0 + 1);
  for (int i = 0; i < k - 1 - 0 + 1; i++)
  {
    scanf("%lld", &d[i]);
  }
  std::vector<long long> n(q);
  std::vector<long long> x(q);
  std::vector<long long> m(q);
  for (int i = 0; i < q; i++)
  {
    scanf("%lld", &n[i]);
    scanf("%lld", &x[i]);
    scanf("%lld", &m[i]);
  }
  solve(k, q, std::move(d), std::move(n), std::move(x), std::move(m));
  return 0;
}


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

int n;
char t[300][300];

int mem[300][300];

int calc(int y,int x){
  if(mem[y][x]!=-1)return mem[y][x];
  int ay=y;
  int ax=x;
  int by=y;
  int bx=x;
  int res=0;
  for(int i=0;i<n;i++){
    if(t[ay][ax]!=t[by][bx])break;
    res++;
    ay=(ay-1+n)%n;
    ax=(ax+1)%n;
    by=(by+1)%n;
    bx=(bx-1+n)%n;
  }
  return mem[y][x]=res;
}

int mem2[300][300];

int calc2(int y,int x){
  if(mem2[y][x]!=-1)return mem2[y][x];
  int ay=y;
  int ax=(x+1)%n;;

  int by=(y+1)%n;
  int bx=x;
  
  int res=0;
  for(int i=0;i<n;i++){
    if(t[ay][ax]!=t[by][bx])break;
    res++;
    ay=(ay-1+n)%n;
    ax=(ax+1)%n;
    by=(by+1)%n;
    bx=(bx-1+n)%n;
  }
  
  return mem2[y][x]=res;
}

int main(){
  memset(mem,-1,sizeof(mem));
  memset(mem2,-1,sizeof(mem2));
  
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>t[i][j];
    }
  }
  int tab[300];
  int cc=0;
  
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){

      cc=0;    
      for(int k=0;k<n;k++){
        tab[cc++]=calc( (i+k)%n , (j+k)%n );
      }
      
      bool flag=true;
      for(int k=0;k<n/2;k++){
        if(tab[k]<=k)flag=false;
        if(tab[cc-1-k]<=k)flag=false;
      }
      if(n%2==1 && tab[n/2]<=n/2)flag=false;

      cc=0;
      for(int k=0;k<n-1;k++){
        tab[cc++]=calc2( (i+k)%n , (j+k)%n );
      }
      
      for(int k=0;k<cc/2;k++){
        if(tab[k]<=k)flag=false;
        if(tab[cc-1-k]<=k)flag=false;
      }
      if(cc%2==1 && tab[cc/2]<=cc/2)flag=false;
      
      if(flag)ans++;

        
    }


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


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

#define N 100000000000

int z[1000000];

int main(){

  int n,k,i,v=0,w=N,ans=N;

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

  while(v+1<w) {

    int cnt=0,max=0,sum=0;
    int mid=(v+w)/2;
    for(i=0; i<n; i++) {
      if(sum+z[i]>mid) {
	    if(cnt<k-1) {
	     cnt++;
	     sum=0;
     	}
    }
    sum+=z[i];
    if(max<sum) {
      max=sum;
    }
  }
    if(ans>max) {
      ans=max;
    }
    if(max<=mid){
       w=mid;
     }
    else v=mid;
  }

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



Measured memory_bytes: 2232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    cout << n * n * n << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long  i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}


int main()
{
	long long a, b, k, cnt = 0;

	cin >> a >> b >> k;

	if (a >= k)
		a -= k;
	else if (a + b >= k) {
      	b -= (k - a);
		a = 0;
	}	
	else {
		a = 0;
		b = 0;
	}

	cout << a << " " << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int k, s, cnt = 0;
	cin >> k >> s;

	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (s - i - j >= 0 && s - i - j <= k)cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;
public class Main{
public static void main( String [] args){
Scanner in= new Scanner( System.in);
int c,t,X,Y,e,f,m,n,i,j,k;
c= 2;
t= 4;
m= 0;
X= in.nextInt();
Y= in.nextInt();
for (i=0;i<=X; i++){
e= c*i;
for (j= 0;  j <= X; j++){
f= t*j;
n= e+f;
k= i+j;
if (n==Y && k==X){
m++;
}
}
} if (m==0){
System.out.println ("No");
}else {
 System.out.println ("Yes");
  }
}
}

Measured memory_bytes: 35832
#include <iostream>
using namespace std;
int main(void){
    long long n;
    cin>>n;
    long long verybig=1000000;
    long long verymini=-1000000;
    long long a;
    long long sum = 0;
    for(int i=1;i<=n;i++){
        cin>>a;
        if(a<verybig){
            verybig=a;
        }
        if(a>verymini){
            verymini=a;
        }sum+=a;
    }
    cout<<verybig<<" "<<verymini <<" "<<sum<<endl;
}


Measured memory_bytes: 3112
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(;N-->0;)
		{
			int[] l = new int[3];
			for (int i = 0; i < 3; i++) l[i] = sc.nextInt();
			Arrays.sort(l);
			System.out.println(lensq(l[0], l[1]) == sq(l[2]) ? "YES" : "NO");
		}
	}
	
	private static int lensq(int x, int y) { return sq(x) + sq(y); }
	private static int sq(int n) { return n * n; }
}

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

int main(){
  long N,D,Ds,i;
  long x,y;
  long ct;
  
  cin >> N >> D;
  Ds = D*D;
  ct = 0;
  for(i=0;i<N;i++){
    cin >> x >> y;
    if (x*x + y*y <= Ds)
      ct++;
  }
  cout << ct << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#define M 110
using namespace std;
int n,a[M],b[M],m;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]+=a[i-1];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		b[i]+=b[i-1];
	}
	for(int i=1;i<=n;i++)
		m=max(m,a[i]+b[n]-b[i-1]);
	return!(cout<<m<<'\n');
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;

    int n,m;
    cin>>n>>m;

    vector<P> st(n);
    vector<int> ans(n,0);
    vector<P> cp(m);

    rep(i,n){
        int a,b;
        cin>>a>>b;
        st[i] = P(a,b);
    }

    rep(i,m){
        int a,b;
        cin>>a>>b;
        cp[i] = P(a,b);
    }


    rep(i,n){

        int mnd = INF;

        int a = st[i].fi;
        int b = st[i].se;

        rep(j,m){
            int c = cp[j].fi;
            int d = cp[j].se;

            int dist  = abs(a-c)+abs(b-d);
            if(chmin(mnd,dist))ans[i]=j+1;
        }
    }

    for(int ai:ans)cout<<ai<<endl;

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

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


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

X_sort = sorted(X)

tmp_m = X_sort[N // 2 - 1]
tmp_p = X_sort[N // 2]

for x in X:
    if x <=tmp_m:
        print (tmp_p)
    else:
        print (tmp_m)

Measured memory_bytes: 26016
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;

int main(){
  int m1,d1,m2,d2; cin >> m1 >> d1 >> m2 >> d2;
  
  if(m2-m1 == 1 && d2 == 1) cout << 1 << endl;
  else cout << 0 << endl;
  
  return 0;
}

Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val m = readLine.trim.toInt
    if (m != 0) {
      val cards = List.tabulate(m) { _ ⇒
        val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
        a → b
      }
      val pat = calPattern(cards)
      val g = readLine.trim.toInt
      for (_ ← 0 until g) {
        println(pat(readLine.trim.toInt))
      }
      solve
    }
  }
  def calPattern(cards: List[(Int, Int)]): Array[Int] = {
    def calSub(c: List[(Int, Int)], pattern: Array[Int]): Unit = {
      c match {
        case (a, b)::t ⇒ {
          for (i ← (0 to 1000).reverse) {
            if (pattern(i) > 0) {
              for (j <- 1 to b) {
                if (i + a * j <= 1000) pattern(i + a * j) += pattern(i)
              }
            }
          }
          calSub(t, pattern)
        }
        case Nil ⇒
      }
    }
    val res = Array.tabulate(1001){_ ⇒ 0}
    res(0) = 1
    calSub(cards, res)
    res
  }

}


Measured memory_bytes: 45680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        string S;cin>>S;
        if(S=="0") break;
        int N=S.size();
        vector<int> cnt(11);
        
        int now=0;
        cnt[0]=1;
        
        for(int i=1;i<=N;i++){
            if(i%2) now+=S[i-1]-'0';
            else now-=S[i-1]-'0';
            
            if(now>=11) now-=11;
            else if(now<0) now+=11;
            
            cnt[now]++;
        }
        
        ll ans=0;
        
        now=0;
        
        for(int i=0;i<N;i++){
            cnt[now]--;
            if(S[i]!='0'){
                ans+=cnt[now];
            }
            
            if(i%2) now-=S[i]-'0';
            else now+=S[i]-'0';
            
            if(now>=11) now-=11;
            else if(now<0) now+=11;
            
        }
        
        cout<<ans<<endl;
    }
}





Measured memory_bytes: 3320
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - +-x
            var line = ReadLine();
            int a = line[0];
            int b = line[1];
            var ans = new int[3];

            ans[0] = a + b;
            ans[1] = a - b;
            ans[2] = a * b;

            Console.WriteLine(ans.Max());
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13396
num = gets.chomp!.split("")

arr = ["#{num.shift}"]
3.times do |i|
    x = []
    while y = arr.shift do
        x << y + "+" + num[i]
        x << y + "-" + num[i]
    end
    arr = x
end

arr.each do |e|
    if eval(e) == 7
        puts e + "=7"
        break
    end
end

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

char getNext(char original)
{
    if (original == 'Z')
    {
        return 'A';
    }
    else
    {
        return original + 1;
    }
}

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

    string result = "";

    for (int i = 0; i < s.length(); ++i)
    {
        char single = s.at(i);
        for (int x = 0; x < n; ++x)
        {
            single = getNext(single);
        }
        result += single;
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    int flag1=0,flag2=0;
    int a[4] = {4,6,9,11};
    if(x==y) printf("Yes\n");
    else{
        rep(i,0,3){
            if(x==a[i]) flag1 = 1;
            if(y==a[i]) flag2 = 1;
            if(x==2) flag1 = 2;
            if(y==2) flag2 = 2;
        }
        if(flag1==flag2) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
  int a,b,state,n;
  cin>>n;
  string data;
  cin>>data;
  b=0;
  a=0;
  state=0;
  for(int i=0;i<n;i++){
    if(data[i]=='I')a+=1;
    else if(data[i]=='D')a-=1;
    if(a>b){
      b=a;
      state=i+1;
    }
  }
  cout<<b;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long STATES;

STATES free_days[31], dp[51], goal_state, next;
STATES* p;
int i, j, n, free_day, k;
short answer;

int main( void )
{

	while ( scanf( "%d", &n ) == 1 && n )
	{
		memset( free_days, 0, sizeof(free_days) );
		memset( dp, 0, sizeof(dp) );

		goal_state = 0;
		for ( i = 0; i < n; i++ ) goal_state |= 1LL << i;

		for ( i = 0; i < n; i++ )
		{
			scanf( "%d", &k );
			for ( j = 0; j < k; j++ )
			{
				scanf( "%d", &free_day );
				free_days[free_day] |= 1LL << i;
			}
		}

		answer = -1;
		for ( i = 0; i < n; i++ ) dp[i] = 1LL << i;
		p = free_days + 1;
		for ( i = 30; i != 0; i--, p++ )
		{
			next = 0;
			for ( j = 0; j < n; j++ ) if ( *p & 1LL << j ) next |= dp[j];
			if ( next == goal_state )
			{
				answer = 31 - i;
				break;
			}
			for ( j = 0; j < n; j++ ) if ( *p & 1LL << j ) dp[j] |= next;
		}

		printf( "%d\n", answer );
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;


string S;

int main(){
    cin >> S;
    int cnt[3] = {};
    for(int i = 0; i < S.length(); i++){
        cnt[S[i]-'a']++;
    }
    sort(cnt, cnt+3);
    if(cnt[2]-cnt[0] <= 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
from collections import defaultdict

n, k = map(int, input().split())
hhh = list(map(int, input().split()))
INF = 10 ** 18
dp = defaultdict(lambda: INF)
dp[0] = 0
mask1 = (1 << 10) - 1
mask2 = ((1 << 63) - 1) ^ mask1

for h in hhh:
    ndp = defaultdict(lambda: INF)
    h_key = h << 10
    for changed_prev_h, operate in dp.items():
        changed = changed_prev_h & mask1
        prev_h = changed_prev_h >> 10
        if h == prev_h:
            key = h_key + changed
            ndp[key] = min(ndp[key], operate)
        elif h > prev_h:
            key = h_key + changed
            ndp[key] = min(ndp[key], operate + h - prev_h)
            if changed < k:
                key = changed_prev_h + 1
                ndp[key] = min(ndp[key], operate)
        else:
            key = h_key + changed
            ndp[key] = min(ndp[key], operate)
            if changed < k:
                key = changed_prev_h + 1
                ndp[key] = min(ndp[key], operate)
    # print(h)
    # print(dict(dp))
    # print(dict(ndp))
    dp = ndp
print(min(dp.values()))


Measured memory_bytes: 135932
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    map<int,int> mp;
    for(int i = 0; i < n; ++i){
        int a; cin >> a;
        mp[a]++;
    }
    if(mp.size() <= k){
        cout << 0 << endl;
        return 0;
    }
    vector<int> vec;
    for(auto it = mp.begin(); it != mp.end(); ++it){
        vec.push_back(it->second);
    }
    sort(vec.begin(), vec.end());
    int ans = 0;
    for(int i = 0; i < mp.size()-k; ++i){
        ans += vec[i];
    }
    cout << ans << endl;
    return 0;
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
pair<ll,ll> par[150010];
ll rk[150010];
ll n, m;

void init (ll n) {
  for (int i = 0; i < n; i++) {
    par[i] = {i,1LL};
    rk[i] = 0LL;
  }
}

pair<ll,ll> fd(ll x) {
  if (par[x].fi == x) {
    return par[x];
  } else {
    return par[x] = fd(par[x].fi);
  }
}

ll unite (ll x, ll y) {
  x = fd(x).fi;
  y = fd(y).fi;
  ll xx = fd(x).se;
  ll yy = fd(y).se;
  //cout << x << " " << y << " " << xx << " " << yy << endl;
  if (x == y) return 0;

  if (rk[x] < rk[y]) {
    par[y].se += fd(x).se;
    par[x] = par[y];
  } else {
    par[x].se += fd(y).se;
    par[y] = par[x];
    if (rk[x] == rk[y]) rk[x]++;
  }
  return (ll)xx*(ll)yy;
}

void print() {
  cout << "-------------------------" << endl;
  for (int i = 0; i < n; i++) {
    cout << par[i].fi << " " << par[i].se << endl;
  }
  cout << "-------------------------" << endl;
}

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

  cin >> n >> m;
  init(n);
  vector<pair<ll,ll>> v;
  for (int i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    --a;--b;
    v.pb({a,b});
  }

  vector<ll> out;
  ll ans = n*(n-1)/2;
  for (int i = sz(v)-1; i >= 0; i--) {
    out.pb(ans);
    ans -= unite(v[i].fi, v[i].se);
    //print();
  }

//  for (int i = 0; i < n; i++) {
//    cout << i+1 << " " << fd(i).fi+1 << " " << fd(i).se << endl;
//  }

  for(int i = sz(out)-1; i>=0; i--) cout << out[i] << endl;
  return 0;
}


Measured memory_bytes: 7024
import collections

N = int(input())
a_list =  list(map(int, input().split()))

v_list = []

for i in a_list:
    v_list.append(i - 1)
    v_list.append(i)
    v_list.append(i + 1)

count_dict = collections.Counter(v_list)
print(count_dict.most_common(1)[0][1])


Measured memory_bytes: 27360
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int A, B;
    cin >> A >> B;
    if (A == 1) {
        A = 14;
    }
    if (B == 1) {
        B = 14;
    }
    if (A > B) {
        cout << "Alice";
    } else if (A == B) {
        cout << "Draw";
    } else {
        cout << "Bob";
    }
    return 0;
}

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


void solve(long long N, long long A, long long B){
    cout<<min(B,A*N)<<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);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi; 
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=(a);i>=(int)(b);i--)
const int mod = 1e9+7;
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
int fa[maxn],siz[maxn];
int Find(int x) {
    if(x==fa[x]) return x;
    else return fa[x]=Find(fa[x]);
}
void Union(int a,int b) {
    int f1=Find(a),f2=Find(b);
    siz[f1]+=siz[f2];
    fa[f2]=f1;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    rep(i,1,n) {
        fa[i]=i;
        siz[i]=1;
    }
    while(m--) {
        int a,b;
        cin>>a>>b;
        if(Find(a)!=Find(b)) Union(a,b);
    }
    int ans=0;
    rep(i,1,n) {
        if(i==fa[i]) ans=max(ans,siz[i]);
    }
    cout<<ans<<'\n';
    return 0;
}


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


int main(){
	int n,m;
	std::cin >> n >> m;
	int arr[m+1];
	int sum = 0;
	for(int i = 1;i <= m;i++){
		std::cin >> arr[i];
		sum += arr[i];
	}

	std::cout << (std::max(n-sum ,-1));

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;

const int maxn = 2e5 + 1;

vector<int> g[maxn], v[maxn];
int c[maxn], p[maxn], cp[maxn], d[maxn], sz[maxn], cs[maxn], nx[maxn], n;
long long ans[maxn];

void dfs(int x, int pr = -1) {
    p[x] = pr; sz[x] = 1; d[x] = (pr == -1 ? 0 : d[pr] + 1);
    cp[x] = (v[c[x]].empty() ? -1 : v[c[x]].back());
    if (pr != -1) v[c[pr]].push_back(x);
    if (pr != -1 && c[pr] == c[x]) cp[x] = -2;
    for (auto to : g[x]) {
        if (to == pr) continue;
        dfs(to, x); sz[x] += sz[to];
    }
    if (pr != -1) v[c[pr]].pop_back();
}

bool cmp(int x, int y) {
    return d[x] > d[y];
}

signed main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0); vector<int> q(n);
    for (int i = 0; i < n; i++) {
        q[i] = i; cs[i] = sz[i];
        ans[i + 1] = n * 1ll * (n + 1) / 2;
        nx[i + 1] = n;
    }
#ifdef DEBUG
    cout << "Sizes: ";
    for (int i = 0; i < n; i++)
        cout << sz[i] << ' ';
    cout << "\nDepths: ";
    for (int i = 0; i < n; i++)
        cout << d[i] << ' ';
    cout << "\nParents: ";
    for (int i = 0; i < n; i++)
        cout << p[i] << ' ';
    cout << "\nCParents: ";
    for (int i = 0; i < n; i++)
        cout << cp[i] << ' ';
    cout << '\n';
#endif // DEBUG
    sort(q.begin(), q.end(), cmp);
  	for (int x = 0; x < n; x++) {
        int i = q[x];
        for (auto to : g[i])
            if (to != p[i])
                ans[c[i]] -= cs[to] * 1ll * (cs[to] + 1) / 2;
        if (cp[i] == -1) nx[c[i]] -= sz[i];
        else if (cp[i] != -2) cs[cp[i]] -= sz[i];
        else cs[i] = 0;
  	}
  	for (int i = 1; i <= n; i++)
        ans[i] -= nx[i] * 1ll * (nx[i] + 1) / 2;
    for (int i = 1; i <= n; i++)
        cout << ans[i] << '\n';
  	return 0;
}


Measured memory_bytes: 46232
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define getMat(x, n, m, val) vector<vector<ll>> x(n, vector<ll> (m, val))
#define setp fixed<<setprecision
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll M=1000000000+7;
 
ll power(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

int main(){
    fastio;
    double d,t,s;
    cin>>d>>t>>s;
    if(d/s>t)cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 3728
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

ans=-1
for i in range(n):
    cnt=0
    for j in range(n):
        if j>i:
            cnt+=a2[j]
        elif j==i:
            cnt+=a1[j]+a2[j]
        else :
            cnt+=a1[j]
    if cnt > ans:
        ans=cnt
print(ans)

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    int n,m,Q;
    cin >> n >> m >> Q;

    vector<vector<int>> G(n+1);
    for(int i = 0; i < m; i++){
        int l,r;
        cin >> l >> r;
        G[l].push_back(r);
    }
    for(int i = 0; i < n + 1; i++){
        sort(G[i].begin(),G[i].end());
    }

    for(int i = 0; i < Q; i++){
        int p,q;
        cin >> p >> q;
        int ans = 0;
        for(int j = p; j <= q; j++){
            ans += upper_bound(G[j].begin(),G[j].end(), q) - G[j].begin();
        }
        cout << ans << endl;
    }
}


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

int main() {
	int N;
	int a,a1,b,b1,c,c1,d;
	
	cin >> N;
	
	if (N >= 1000 && N <= 9999) {
		a = N % 1000;
		a1 = N / 1000;
		b = (N - (a1 * 1000)) % 100;
		b1 = (N - (a1 * 1000)) / 100;
		c = (N - (a1 * 1000 + b1 * 100 )) % 10;
		c1 = (N - (a1 * 1000 + b1 * 100 )) / 10;
		d = (N - (a1 * 1000 + b1 * 100 + c1 * 10 ));

		
		if ((a1 == b1 && b1 == c1) || (b1 == c1 && c1 == d)) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int main(){
        int n,m,i,j,k,s,cnt,ans=0;
        bool ok;
        cin >> n >> m;
        vector<vector<int>> sw(m);
        vector<int> p(m);
        for(i=0;i<m;++i){
                cin >> k;
                for(j=0;j<k;++j){
                        cin >> s; --s;
                        sw.at(i).push_back(s);
                }
        }
        for(i=0;i<m;++i) cin >> p.at(i);
        for(i=0;i<(1<<n);++i){
                ok = true;
                for(j=0;j<m;++j){
                        cnt = 0;
                        for(auto e : sw.at(j)) if((i>>e)&1) ++cnt;
                        if(cnt%2!=p.at(j)){
                                ok = false;
                                break;
                        }
                }
                if(ok) ++ans;
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

#include <cmath>
typedef long long ll;
const double eps = 1e-6;
int main() {
    int n, d;
    scanf("%d%d", &n, &d);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        double D = sqrt(1ll * x * x + 1ll * y * y);
        if (D < d + eps) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  vector<int> d, c, neighbor;
  vector<map<int, pair<int, int>>> t;
  Solver2(LL n, LL m) : n(n), m(m), d(n), c(n, -1), neighbor(n, -1), t(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> d[i];
    }
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      t[--u][--v] = {1e9, i};
      t[v][u] = {1e9, i};
    }
    vector<int> local_min;
    for (int i = 0; i < n; ++i) {
      bool found = false;
      for (auto v : t[i]) {
        if (d[i] >= d[v.first]) {
          found = true;
          neighbor[i] = v.first;
          break;
        }
      }
      if (!found) {
        cout << -1 << endl;
        return;
      }
    }
    vector<int> perm(n);
    for (int i = 0; i < n; ++i) {
      perm[i] = i;
    }
    sort(perm.begin(), perm.end(), [&](int x, int y) -> bool { return d[x] < d[y] || (x < y && d[x] == d[y]); });

    for (int i = 0; i < n; ++i) {
      int v = perm[i];
      if (c[v] >= 0) continue;
      int tmpc = c[neighbor[v]];
      if (tmpc < 0) {
        c[v] = 0;
        c[neighbor[v]] = 1;
      } else if (tmpc == 0) {
        c[v] = 1;
      } else {
        c[v] = 0;
      }
      t[v][neighbor[v]].first = t[neighbor[v]][v].first = d[v];
    }

    vector<int> ans(m);
    for (int i = 0; i < n; ++i) {
      for (auto v : t[i]) {
        ans[v.second.second] = v.second.first;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << ("BW"[c[i]]);
    }
    cout << endl;
    for (int i = 0; i < m; ++i) {
      cout << ans[i] << endl;
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 34432
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
struct Span{
	int d;
	int p;
	Span():d(0),p(0){}
	Span(int d, int p):d(d),p(p){}
	bool operator>(const Span &t)const{ return p>t.p; }
};
int main(){
	while(true){
		int ans = 0;
		int n,m;
		vector<Span> vspan;
		scanf("%d%d", &n, &m);
		if(n==0&&m==0)break;
		for(int i = 0; i < n; ++i){
			int d,p;scanf("%d%d", &d, &p);
			vspan.push_back( Span(d,p) );
			ans += d * p;
		}
		sort(vspan.begin(), vspan.end(), greater<Span>());
		for(unsigned int i = 0; i < vspan.size(); ++i){
			if( m >= vspan[i].d ){
				m -= vspan[i].d;
				ans -= vspan[i].d * vspan[i].p;
			}else if( m > 0 ){
				ans -= m * vspan[i].p;
				m -= m;
			}
			//cout << ans << endl;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1052
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  string s,t;
  cin >> s >> t;
  s=s+s;
  if(s.find(t)!=-1) {
      cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a+b)%2==0) {
			System.out.println((a+b)/2);	
		} else {
			System.out.println((a+b+1)/2);
		}
	}
	
	static int binarySearch(int[] A, int x) {
		int l = 0;
		int r = A.length;
		while(l<r) {
			int mid = (l+r)/2;
			if(A[mid] == x) return mid;
			else if(x<A[mid]) r = mid;
			else l = mid+1;
		}
		return -1;
	}
	
	static long upper_bound(int[] A, int b) {
		// bよりおおきい値がはじめて出てくるindexを返す
		return lower_bound(A, b+1);
	}

	static long lower_bound(int[] A, int b) {
		// b以上の値がはじめて出てくるindexを返す
		int lb=0;
		int ub=A.length;
		while(ub>lb) {
			int mid = (lb+ub)/2;
			if(A[mid]>=b) ub = mid;
			else lb = mid+1;
		}
		return lb;
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

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

#define MAX 1000

int c[MAX + 1][MAX + 1];

int lcs(char *x, char *y) {
    int m = strlen(x);
    int n = strlen(y);
    int maxl = 0;

    char _s1[MAX + 1] = " ";
    char _s2[MAX + 1] = " ";

    x = strcat(_s1, x);
    y = strcat(_s2, y);

    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 1; j <= n; j++) c[0][j] = 0;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++){
            if (x[i] == y[j]) c[i][j] = c[i - 1][j - 1] + 1;
            else c[i][j] = c[i - 1][j] >= c[i][j - 1] ? c[i - 1][j] : c[i][j - 1];
            maxl = maxl >= c[i][j] ? maxl : c[i][j];
        }
    }

    return maxl;
}

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

    char s1[MAX + 1];
    char s2[MAX + 1];

    for (int i = 0; i < n; i++) {
        scanf("%s", s1);
        scanf("%s", s2);
        printf("%d\n", lcs(s1, s2));
    }
}



Measured memory_bytes: 5692
#include<stdio.h>
int main(){
    double W;
    double H;
    scanf("%lf %lf",&W,&H);
    int x,y;
    scanf("%d %d",&x,&y);
    double S;
    int D;
    S = W*H/2.0;
    printf("%lf ",S);
    if(x==W || y==H ||x==0||y==0){
        D=0;
    }
    else if(x==W/2 && y ==H/2){
        D=1;
    }
    else{
        D=0;
    }
    printf("%d\n",D);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int lgN = 21;
const int N = 3e5 + 233;
int n, ban[lgN + 2], col[N], ans = 0;
vector<int> g[N];
inline int dfs(int u, int fat) {
  vector<int> vec;
  int has = 0;
  for (int v : g[u]) if (v != fat) {
      int p = dfs(v, u);
      vec.push_back(p);
      has |= p;
    }
  int mx = 0;
  memset(ban, 0, sizeof ban);
  for (int k = 0; k < lgN; k ++) {
    int cnt = 0;
    for (int i : vec)
      cnt += i >> k & 1;
    if (cnt >= 1) ban[k] = true;
    if (cnt >= 2) mx = max(mx, k + 1);
  }
  while (ban[mx]) ++ mx;
  col[u] = mx;
  ans = max(ans, mx);
  for (int k = 0; k < col[u]; k ++)
    if (has >> k & 1)
      has ^= 1 << k;
  has |= 1 << col[u];
  return has;
}

main(void) {
  read(n);
  for (int i = 2; i <= n; i ++) {
    int x, y; read(x); read(y);
    g[x].push_back(y); g[y].push_back(x);
  }
  dfs(1, 0);
  // for (int i = 1; i <= n; i ++)
  //   cout << col[i] << " "; puts("");
  cout << ans << "\n";
}


Measured memory_bytes: 17024
// ABC168A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	if (N%10==3)
	{
		cout << "bon" << endl;
	}
	else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
	{
		cout << "pon" << endl;
	}
	else {
		cout << "hon" << endl;
	}
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    ll ans = 0;
    while (*max_element(all(a)) >= n) {
        ll sum = 0;
        each(i, a)sum += i / n;
        each(i, a)i = i % n + sum - i / n;
        ans += sum;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int N,K;
vi h;
vi dp;

signed main(){

    in(N,K);
    resz(N,h);
    in(h);

    resize(dp,N);
    fill(all(dp),INF);
    dp[0]=0;
    rep(i,N){
        REP(j,1,K+1){
            if(i+j<N) dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    out(dp[N-1]);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5,mod=1e9+7;
ll power(ll n,ll p){
    ll ans=1;
    while(p){
        if(p&1)ans*=n,ans%=mod;
        p>>=1;
        n*=n;
        n%=mod;
    }
    return ans;
}
ll sum[N],ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;cin>>n>>k;
    for(ll i=k;i>=1;i--){
        ll cnt=k/i;
        sum[i] = power(cnt,n);
        for(ll j=2*i;j<=k;j+=i)sum[i]=sum[i]-sum[j]+mod,sum[i]%=mod;
        ans+=(sum[i]*i)%mod;
        ans%=mod;
    }
    cout<<ans;
}

Measured memory_bytes: 4376