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

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

  list<int> l;
  queue<unique_ptr<set<int>>> q;
  for(auto i = 0; i < N; ++i) {
    int a;
    cin >> a;
    l.emplace_back(a);
    q.emplace(make_unique<set<int>>());
    q.back()->emplace(a);
  }

  auto merge = [](auto& base, auto& add) {
    if(base->size() < add->size()) swap(base, add);
    base->insert(begin(*add), end(*add));
  };

  long long ans = 0;

  l.sort();

  while(!l.empty()) {
    auto nex = make_unique<set<int>>();
    while(l.front() != *begin(*q.front())) {
      merge(nex, q.front());
      q.pop();
    }
    merge(nex, q.front());
    q.pop();
    nex->erase(l.front());
    l.pop_front();
    ans += nex->size();
    if(!nex->empty()) q.emplace(move(nex));
  }

  cout << ans << endl;
}

Measured memory_bytes: 32964
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

typedef long long ll;

const int kMaxN = 10000;

int N;
int a[kMaxN], b[kMaxN];
string ans;

ll c = 0;

int main() {
  cin >> N;
  REP(i, N) { cin >> a[i]; }
  REP(i, N) { cin >> b[i]; }

  REP(i, N) {
    if (b[i]-a[i] > 0) {
      c += (b[i]-a[i])/2;
    } else if (b[i]-a[i] < 0) {
      c += b[i]-a[i];
    }
  }
  if (c >= 0) {
    ans = "Yes";
  } else {
    ans = "No";
  }

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


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

int main(){
	int n;
    cin >> n;
    vector<int> ta(n);
    int ans = 0;
    rep(i, n) cin >> ta.at(i);
    rep(i, n-1) for(int j=i+1; j<n; j++) ans += ta.at(i)*ta.at(j);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  
  int h,w,i,j;
 
  while(1){
   
	scanf("%d %d",&h,&w);
    if(h==0&&w==0) break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
		if(i==0||i==h-1||j==0||j==w-1) printf("#");
		else printf(".");
      }
      puts("");
    }
    puts("");
  }
 
  return 0;
}

Measured memory_bytes: 588
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

N =        int( stdin.readline().strip() )
ps = map(int, stdin.readline().strip().split())

heights = [0] * N
for i, p in enumerate(ps):
    heights[p-1] = i

aa = [1 + 21000*i for i in range(N)]
bb = [heights[i] - aa[i] for i in range(N)]
base = min(bb)
bb = [b + abs(base)+1 for b in bb]

print ' '.join(map(str, aa))
print ' '.join(map(str, bb))


Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
  cout << N*N*N << endl;
  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
using namespace std;
int main(int,char**){
    long a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    sum+=min(a,k);
  	k-= a;
  	if(k<=0) goto last;
  	k-=b;
    if(k<=0) goto last;
  	sum-=k;
  last:
  	cout<<sum<<endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int s = sc.nextInt();
        // スペース区切りの整数の入力
        int w = sc.nextInt();

        if (s <= w) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }



    }
}


Measured memory_bytes: 35648
#include <stdio.h>
#include <stdlib.h>
int h(int i);
int main()
{
	int i,N,A,B,sum=0;
	scanf("%d %d %d",&N,&A,&B);
	for(i=1;i<=N;i++) {
		if((A<=h(i))&&(B>=h(i))) sum+=i;
	}
	printf("%d\n",sum);
	return 0;
}

int h(int i)
{
	int sum=0,d=i;
	while((i%10!=0)||(i/10!=0)) {
		sum+=i%10;
		i/=10;
	}
	return sum;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d",&a,&b);
if(a<b){
c=a;
a=b;
b=c;
}
while(b!=0){
a=a%b;
c=a;
a=b;
b=c;
}
printf("%d\n",a);
return 0;
}


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

int main() {
  string str;
  cin >> str;
  
  if((str.at(2) == str.at(3)) && (str.at(4) == str.at(5)))
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
      
}


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

ans = 0
if (b-a)%2 == 0:
    print((b-a)//2)
else:
    ans = 0
    if (b-1) < (n-a):
        ans += a-1
        b -= a-1
        a = 1
        if (b-a)%2 != 0:
            ans += 1
            b -= 1
        ans += (b-a)//2
        print(ans)
    else:
        ans += n-b
        a += n-b
        b = n
        if (b-a)%2 != 0:
            ans += 1
            a += 1
        ans += (b-a)//2
        print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
// order_of_key and *find_by_order
int32_t main()
{
	fast;
	int k;
	cin >> k;
	int a, b;
	cin >> a >> b;
	if (b / k * k < a) {
		cout << "NG";
	}
	else {
		cout << "OK";
	}



}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int ans = 1e8;

void dfs(int a, int b, int c, int turn) {
   if (a == b && b == c && a == c) {
      ans = min(ans, turn);
      return;
   }

   dfs(a+1, b+1, c, turn+1);
   dfs(a+1, b, c+1, turn+1);
   dfs(a, b+1, c+1, turn+1);

   dfs(a+2, b, c, turn+1);
   dfs(a, b+2, c, turn+1);
   dfs(a, b, c+2, turn+1);
}

int main() {
   int A[3];
   rep (i, 3) cin >> A[i];

   sort(A, A + 3);
   int cnt = 0;
   // cnt += A[2] - A[1];
   // A[0] += cnt;
   // A[1] += cnt;
   // debug3(A[0], A[1], A[2])
   while (1) {
      if (A[0] + 2 > A[2]) break;
      A[0] += 2;
      cnt++;
   }
   while (1) {
      if (A[1] + 2 > A[2]) break;
      A[1] += 2;
      cnt++;
   }
   // debug3(A[0], A[1], A[2])
   sort(A, A+3);


   if (A[0] == A[1] && A[1] +1 == A[2]) {
      cout << cnt + 1 << endl;
   } else if (A[0]+1 == A[1] && A[1] == A[2]) {
      cout << cnt + 2 << endl;
   } else {
      cout << cnt << endl;
   }

   return 0;
}

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

using namespace std;
const long long INF = (long long) (1e18)+1;

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

  cout << s[0] << s[1] << s[2] << endl;
  return 0;
}

Measured memory_bytes: 3624
class Combinatorics
  def initialize(n, mod)
    @mod = mod
    @fact, @inv, @finv = Array.new(3){[1, 1]}
    2.upto(n) do |i|
      @fact[i] = (@fact[i-1] * i) % @mod
      @inv[i]  = (@inv[@mod % i] * (@mod - @mod / i) ) % @mod
      @finv[i] = (@finv[i-1] * @inv[i] ) % @mod
    end
  end
  def combination(n, r)
    return 0 if (n < r) || (n < 0) || (r < 0)
    (@fact[n] * @finv[n-r] % @mod) * @finv[r] % @mod
  end
  def permutation(n, r)
    return @fact[n] * @finv[n-r] % @mod
  end
end

MOD=10**9+7
N,M=gets.split.map(&:to_i)
C=Combinatorics.new(M,MOD)
ans=C.permutation(M,N)
sign=1
1.upto(N) do |i|
  d=C.combination(N,i)*C.permutation(M-i,N-i)%MOD
  ans-=sign*d
  ans+=MOD
  ans%=MOD
  sign*=-1
end
p ans*C.permutation(M,N)%MOD

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int main() {
	int n;
	string s;
	cin >>n>>s;
	int cnt = 0;
	for (int i=0 ; i<n-2 ; i++) {
		if (s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C') cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 256
# A - 居合を終え、青い絵を覆う
# https://atcoder.jp/contests/abc049/tasks/abc049_a

c = input()

vowel = ['a', 'e', 'i', 'o', 'u']

if c in vowel:
    print('vowel')
else:
    print('consonant')


Measured memory_bytes: 8968
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
#define all(x) x.begin(),x.end()
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
const int N=2e5+9;
const ll mod=998244353;
pair<double,int> g[N];
ll dp[N][40];
int a[N],b[N],p[N];
int cnt,cnt2;
void upd(ll &a,ll b){
	if(a>b)a=b;
}
int main(){
//	freopen("text.in","r",stdin);
	int n,t;
	scanf("%d%d",&n,&t);
	++t;
	rep(i,1,n+1){
		scanf("%d%d",&a[i],&b[i]);
		++a[i],++b[i];
		if(a[i]>1)g[++cnt]={1.0*(1-a[i])/b[i],i};
		else p[cnt2++]=b[i];
	}
	sort(g+1,g+1+cnt);
	sort(p,p+cnt2);
	rep(i,0,N)rep(j,0,40)dp[i][j]=1e12;
	dp[0][0]=1;
	rep(i,1,cnt+1){
		rep(j,0,40){
			int k=g[i].se;
			if(dp[i-1][j]<=t)upd(dp[i][j],dp[i-1][j]);
			if(j&&dp[i-1][j-1]<=t&&dp[i-1][j-1]*a[k]+b[k]<=t)upd(dp[i][j],dp[i-1][j-1]*a[k]+b[k]);
		}
	}
	ll sum=0;
	int pos=0,ans=0;
	per(j,0,40){
		if(dp[cnt][j]>t)continue;
	//	cout<<cnt<<' '<<j<<' '<<dp[cnt][j]<<"dp\n";
		while(pos<cnt2&&dp[cnt][j]+sum+p[pos]<=t)sum+=p[pos++];
	//	cout<<cnt2<<' '<<pos<<"pos\n";
		ans=max(ans,pos+j); 
	}
	cout<<ans;
} 


Measured memory_bytes: 67456
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n;

int main(){
  ios_base::sync_with_stdio(false);
  
  int f = 0;

  cin >> n;
  
  for(int i=0;f == 0 && i*11<=n;i++){
    int now = i*11;
    for(int j=0;now+j*4<=n;j++){
      if(now+j*4 == n){
        f = 1;
        break;
      }
    }
    for(int j=0;now+j*7<=n;j++){
      if(now+j*7 == n){
        f = 1;
        break;
      }
    }
  }

  if(f){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto col = new int[](N);
    auto cnt = new int[](3);
    col[] = -1;

    void nibu(int v, int c) {
        col[v] = c;
        cnt[c]++;
        foreach (u ; adj[v]) if (col[u] == -1) {
            nibu(u, c == 1 ? 2 : 1);
        }
    }

    nibu(0, 1);

    int les = 1, many = 2;
    if (cnt[les] > cnt[many]) {
        swap(les, many);
    }

    auto rem = new int[][](3, 0);
    foreach (i ; 1 .. N + 1) {
        rem[i % 3] ~= i;
    }

    auto p = new int[](N);
    p[] = -1;

    if (rem[les].length.to!int <= cnt[les]) {
        foreach (i ; 0 .. N) {
            if (col[i] == les) {
                if (rem[les].empty) {
                    p[i] = rem[0].front;
                    rem[0].popFront();
                }
                else {
                    p[i] = rem[les].front;
                    rem[les].popFront();
                }
            }
        }
    }
    else {
        assert(rem[0].length >= cnt[les]);
        foreach (i ; 0 .. N) {
            if (col[i] == les) {
                assert(!rem[0].empty);
                p[i] = rem[0].front;
                rem[0].popFront;
            }
        }
    }

    foreach (i ; 0 .. N) {
        if (p[i] == -1) {
            foreach (j ; 0 .. 3) {
                if (!rem[j].empty) {
                    p[i] = rem[j].front;
                    rem[j].popFront;
                    break;
                }
            }
        }
    }

    assert(p.all!"a >= 0");

    writefln("%(%s %)", p);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 28924
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const LL N=100005;
LL n,X;
struct qq
{
	LL b,l,r,c;
}a[N];
bool cmp (qq x,qq y)	{return x.c>y.c;}
bool cmp1 (qq x,qq y)	{return x.r>y.r;}
LL pre[N];
LL suf[N];
LL sum=0,now,pos;
LL calc (LL x,LL k)
{
	if (k>a[x].b) return a[x].r*k-(a[x].r-a[x].l)*a[x].b;
	return a[x].l*k;
}
bool check (LL x)
{
	for (LL u=1;u<=pos;u++)//更改这里的人
	if (now-a[u].c+calc(u,x)>=sum) return true;
	for (LL u=pos+1;u<=n;u++)//更改这里的人
	if (now-a[pos].c+calc(u,x)>=sum) return true;
	return false;
}
int main()
{
	scanf("%lld%lld",&n,&X);
	for (LL u=1;u<=n;u++)	
	{
		scanf("%lld%lld%lld",&a[u].b,&a[u].l,&a[u].r);
		sum=sum+a[u].l*a[u].b;
		a[u].c=a[u].l*a[u].b+(X-a[u].b)*a[u].r;
	}
	sort(a+1,a+1+n,cmp);
	pos=0;now=0;
	for (LL u=1;u<=n;u++)
	{
		now=now+a[u].c;
		if (now>=sum)	{pos=u;break;}
	}
	LL l=0,r=X,ans;
	while (l<=r)
	{
		LL mid=(l+r)>>1;
		if (check(mid))	{ans=mid;r=mid-1;}
		else l=mid+1;
	}
	printf("%lld\n",ans+(pos-1)*X);
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    char s[201];
    cin>>s;
    int l=strlen(s),c;
    int low=0,mid=l/2;
    while(1)
    {
        int flag=1;
        l=l-2;
        mid=mid-1;
        c=0;
        for(int i=0;i<mid;i++)
        {
            if(s[i]==s[mid+i])
             c++;
             else
             {
                 flag=0;
                 break;
             }
        }
        if(c==mid)
        {
            cout<<l;
            break;
        }
    }return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		String[] w = new String[n];
		Arrays.setAll(w, i -> sc.next());
		List<String> list = new ArrayList<>(Arrays.asList(w));
		String result = "Yes";
		if(list.size() != list.stream().distinct().collect(Collectors.toList()).size()){
			result = "No";
		}else{
			for(int i=0; i<n-1; i++){
				if(list.get(i).charAt(list.get(i).length()-1) != list.get(i+1).charAt(0)){
					result = "No";
				}
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 36156
#include<stdio.h>
int main()
{
	int n=0;
	scanf("%d",&n);
	int d[n];
	int i=0;
	int j=0;
    char y;
    int sum1=0;
    int sum=0;
    int temp=0;
	if(n>=2&&n<=50){
    	do{
		    scanf("%d",&d[i]);
		    i++;
    	}while(y=getchar()!='\n');
    	temp=n;
    	for(i=0;i<n;i++){
	    	for(j=i;j<(temp-1);j++){
	    		sum1+=d[i]*d[j+1];
			}
			sum+=sum1;
			sum1=0;
			
	}
	printf("%d",sum);
	}

}

Measured memory_bytes: 128
local a = io.read("*n")
local s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
print(s[a])


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string grd[1005];
int M=(int)1e9+7, dp[1005][1005];
int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++) cin>>grd[i];
	int i=h-1;
	while(i!=-1&&grd[i][w-1]!='#') dp[i--][w-1]=1;
	i=w-1;
	while(i!=-1&&grd[h-1][i]!='#') dp[h-1][i--]=1;
	for(int i=h-2;i>=0;i--)
		for(int j=w-2;j>=0;j--)
			if(grd[i][j]=='#')
				continue;
			else
				dp[i][j]=(dp[i+1][j]+dp[i][j+1])%M;
	cout<<dp[0][0];
	return 0;
}

Measured memory_bytes: 5248
from queue import Queue

def bfs(HW, q, x, y):
    num = 0
    mem = [[-1]*(W+1) for i in range(H+1)]
    max_dist = 0
    mem[x][y] = 0
    while not q.empty():
        current = q.get()
        if current[0] >= H or current[0] < 0 or current[1] >= W or current[1] < 0:
            continue
        if HW[current[0]][current[1]] == '#':
            continue
        dist = mem[current[0]][current[1]]
        max_dist = max(max_dist, dist)
        if mem[current[0]+1][current[1]] == -1:
            mem[current[0]+1][current[1]] = dist+1
            q.put([current[0]+1,current[1]])
        if mem[current[0]][current[1]+1] == -1:
            mem[current[0]][current[1]+1] = dist+1
            q.put([current[0],current[1]+1])
        if mem[current[0]-1][current[1]] == -1:
            mem[current[0]-1][current[1]] = dist+1
            q.put([current[0]-1,current[1]])
        if mem[current[0]][current[1]-1] == -1:
            mem[current[0]][current[1]-1] = dist+1
            q.put([current[0],current[1]-1])
    return max_dist


H,W = map(int, input().split())

HW = [[''] * W for i in range(H)]
for i in range(H):
    h = str(input())
    HW[i] = h

ans = 0
for si in range(H):
    for sj in range(W):
        if HW[si][sj] == '#':
            continue
        q = Queue()
        q.put([si,sj,0])
        ans = max(ans, bfs(HW, q, si, sj))
print(ans)

Measured memory_bytes: 102612
package main

import (
	"bufio"
	. "fmt"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	type pair struct{ x, y int }
	var n, d int
	var s []byte
	var ls, rs []pair
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &s)
		l, r := 0, 0
		for _, b := range s {
			if b == '(' {
				l++
			} else if l > 0 {
				l--
			} else {
				r++
			}
		}
		if r < l {
			ls = append(ls, pair{r, l})
		} else {
			rs = append(rs, pair{l, r})
		}
		d += l - r
	}
	sort.Slice(ls, func(i, j int) bool { return ls[i].x < ls[j].x })
	sort.Slice(rs, func(i, j int) bool { return rs[i].x < rs[j].x })
	f := func(ps []pair) bool {
		s := 0
		for _, p := range ps {
			if s < p.x {
				return false
			}
			s += p.y - p.x
		}
		return true
	}
	if d == 0 && f(ls) && f(rs) {
		Print("Yes")
	} else {
		Print("No")
	}
}


Measured memory_bytes: 40424
#include<iostream>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
#include<stdio.h>
typedef long long ll;
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, pair<int, int>>> p(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i].first >> p[i].second.first;
		p[i].second.second = i + 1;
	}
	sort(p.begin(), p.end());
	int cnt = 1;
	p[0].second.first = p[0].first;
	p[0].first = p[0].second.second;
	p[0].second.second = cnt;
	for (int i = 1; i < m; i++) {
		if (p[i - 1].second.first != p[i].first)cnt = 1;
		else cnt++;
		p[i].second.first = p[i].first;
		p[i].first = p[i].second.second;
		p[i].second.second = cnt;
	}
	sort(p.begin(), p.end());
	for (int i = 0; i < m; i++) {
		printf("%06d%06d\n", p[i].second.first, p[i].second.second);
	}
	
}

Measured memory_bytes: 2688
#include <stdio.h>

int pertition(int a[],int left,int right){
    int i,j,k,l;
    k=left-1;
    for(i=left;i<right-1;i++){
        if(a[i]<=a[right-1]){
            k++;
            l=a[i]; a[i]=a[k]; a[k]=l;
        }
    }
    l=a[k+1]; a[k+1]=a[right-1]; a[right-1]=l;
    return k+1;
}

void quicksort(int a[],int left,int right){
    int mid;
    if(left+1<right){
        mid = pertition(a,left,right);
        quicksort(a,left,mid);
        quicksort(a,mid+1,right);
    }
}

int minn(int a,int b){
    if(a<b){return a;}
    return b;
}

int solve(int a[1000],int b[1000],int min,int n){
    int v[1000];
    int t[10001];
    int i,cur,s,lmin,an,ans;
    ans=0;
    for(i=0;i<n;i++){v[i]=0;}
    quicksort(b,0,n);
    for(i=0;i<n;i++){t[b[i]]=i;}
    for(i=0;i<n;i++){
        if(v[i]==1){continue;}
        cur=i; s=0; lmin=10001; an=0;
        while(1){
            v[cur]=1; an++;
            if(lmin>a[cur]){lmin=a[cur];}
            s+=a[cur];
            cur=t[a[cur]];
            if(v[cur]==1){break;}
        }
        ans += minn(s+(an-2)*lmin,lmin+s+(an+1)*min);
    }
    return ans;
}

int main(void){
    int n,i,min;
    int a[1000];
    int b[1000];
    scanf("%d",&n);
    min=100000;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
        if(min>a[i]){min=a[i];}
    }
    printf("%d\n",solve(a,b,min,n));
    
}


Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 998244353;

int main()
{
	ll L, R, d;
	cin >> L >> R >> d;
	ll ans = 0;
	for (ll i = L; i <= R; i++)
	{
		if (i % d == 0) {
			ans++;
		}

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mp make_pair 
#define pb push_back 
#define fi first
#define se second

#define DOMOD(d) if ((d) >= MOD) d %= MOD;
#define DONEGMOD(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;

#define inp(a) scanf("%d", &a)
#define inp2(a,b) scanf("%d %d", &a, &b)
#define inp3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define inp4(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define inpl(a) scanf("%lld", &a)
#define inpl2(a,b) scanf("%lld %lld", &a, &b)
#define inpl3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define inpl4(a,b,c,d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i=a;i<b;i++)
#define mset(a,val) memset(a,val,sizeof(a))
#define printv(v) for (int i=0;i<(int) v.size(); i++) cout<<v[i]<<" " 
#define MAX 100005
using namespace std ;
typedef long long int ll ;
typedef pair<int,int> pii ;
typedef pair<long long , long long > pll ;
typedef pair<int,pii> pipi ;
typedef pair<int,pair<int,string>> piis ;
typedef pair<ll,string> pls ;



int main()
{
	 #ifdef DHEER
  freopen("inp.txt","r",stdin) ;
  freopen("out.txt","w",stdout) ;
  #endif
   
   int n , c, k  ; inp3(n,c,k) ;
   int ans = 1 ;
   int a[n] ;
   for (int i=1;i<=n;i++) inp(a[i]) ;
   sort(a+1,a+(n+1)) ;
   int start = a[1] ;
   int pass = 1;
   for (int i=2;i<=n;i++)
   {
	   if (a[i] - start > k || pass == c) {
		   ans++ ;
		   start = a[i] ;
		   pass = 1 ;
	   }else pass++ ;
   }
	cout<<ans<<endl ;
  return 0 ;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int H,W,N;
int si,sj;
string S,T;

int di[]={0,-1,0,+1};
int dj[]={+1,0,-1,0};
string ds="RULD";

int getdir(char c){
  rep(i,4)if(ds[i]==c)return i;
}

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

  cin>>H>>W>>N>>si>>sj; si--; sj--;
  cin>>S>>T;

  rep(dir,4){
    int ni=si,nj=sj;
    rep(i,N){
      if(getdir(S[i])==dir){
        ni+=di[dir]; nj+=dj[dir];
      }
      if(ni<0||ni>=H||nj<0||nj>=W){
        cout<<"NO"<<endl;
        return 0;
      }
      int anti=(dir+2)%4;
      if(getdir(T[i])==anti){
        ni+=di[anti]; nj+=dj[anti];
        if(ni<0||ni>=H||nj<0||nj>=W){
          ni-=di[anti]; nj-=dj[anti];
        }
      }
    }
  }

  cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 920
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    string s;
    cin  >> s;
    ll co = 0;

    rep(i, (s.size() + 1) / 2){
        if(s[i] != s[s.size() - 1 - i]) co++;

    }
    cout << co << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    n,m = map(int, input().split())
    A = []
    B = []
    for _ in range(m):
        a,b = map(int, input().split())
        A.append(a)
        B.append(b)
    AB = []
    AB.extend(A)
    AB.extend(B)
    for i in range(n):
        count = 0
        for j in range(len(AB)):
            if i+1 == AB[j]:
                count += 1
        print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67740
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	int k;
	cin >> s >> k;
	auto u = set<string>();
	char t = 'a';
	while((int)u.size() < k && t <= 'z'){
		for(auto i = 0; i < (int)s.size(); ++i){
			if(s[i] != t) continue;
			for(auto j = i; j < (int)s.size(); ++j){
				auto o = s.substr(i, j - i + 1);
				u.insert(o);
				if((int)u.size() >= k){
					auto it = u.begin();
					advance(it, k - 1);
					if(*it < o) break;
				}
			}
		}
		++t;
	}
	auto ans = u.begin();
	advance(ans, k - 1);
	cout << *ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    double n, k;
    cin >>n>>k;
    vector<double> p(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
        p.at(i) = (p.at(i)+1)/2;
    }
    
    vector<double> ru(n+1);
    for(int i=0; i<n; i++){
        ru.at(i+1) = ru.at(i)+p.at(i);
    }
    
    double ans=0;
    for(int i=0; i<n+1; i++){
        if(i+k>=n+1) break;
        ans = max(ans, ru.at(k+i)-ru.at(i));
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3328
/*
* Problem link
* 
*/

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

struct INIT{INIT(){cin.tie(0);ios_base::sync_with_stdio(false);} }init;

typedef long long LL;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<double> Vd;
typedef vector<Vd> VVd;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename T>
inline bool chmax(T &a, T b) {
	bool res = a < b;
	if (res)a = b;
	return res;
}
const double EPS = 1e-8;
typedef complex<double> P;
typedef pair<P, P> LS;
#define X real()
#define Y imag()
double dot(P a, P b) { return a.X*b.X + a.Y*b.Y; }
double cross(P a, P b) { return a.X*b.Y - a.Y*b.X; }
double distance_P_LS(P p, LS ls) {
	P a, b, c = p;
	tie(a, b) = ls;
	if (dot(b - a, c - a) < EPS)return abs(c - a);
	if (dot(a - b, c - b) < EPS)return abs(c - b);
	return abs(cross(b-a,c-a))/abs(b-a);
}
vector<string> wrap(vector<string> s,char c) {
	int R = s.size();
	int C = s[0].size();
	vector<string> res(R + 2, string(C + 2, c));
	REP(i, R)REP(j, C)res[i + 1][j + 1] = s[i][j];
	return res;
}
const int dr[] = { 0,0,-1,1 };
const int dc[] = { 1,-1,0,0 };

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	int C, R;
	while (cin >> C >> R, C + R) {
		vector<string> s(R);
		REP(i, R)cin >> s[i];
		s = wrap(s,'x');
		int r = 0;
		int c = 0;
		R+=2; C+=2;
		int K = 0;
		REP(i, R)REP(j, C) {
			if (s[i][j] == 'o')r = i, c = j;
			if (s[i][j] == '*') {
				s[i][j] = 'a' + K++;
			}
		}
		using T = tuple<int, int, int>;
		vector<VV> dist(1 << K, VV(R, V(C, -1)));
		dist[0][r][c] = 0;
		queue<T> que;
		que.push(T(0, r, c));
		const int inf = 1e7;
		int res = inf;
		while (que.size()) {
			int bit;
			tie(bit, r, c) = que.front(); que.pop();
			if (bit == (1 << K) - 1) {
				res = dist[bit][r][c];
				break;
			}
			REP(i, 4) {
				int nr = r + dr[i];
				int nc = c + dc[i];
				int nxtbit = bit;
				int kk = s[nr][nc] - 'a';
				if (isalpha(s[nr][nc]) && kk < K)nxtbit |= (1 << kk);
				if (s[nr][nc] == 'x')continue;
				if (dist[nxtbit][nr][nc] !=-1)continue;
				dist[nxtbit][nr][nc] = dist[bit][r][c] + 1;
				que.push(T(nxtbit, nr, nc));
			}
		}
		if (res == inf)cout << -1 << endl;
		else cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 4332
import sys


def input():
    return sys.stdin.readline().strip()


class DisjointSet:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]


N, M = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
ds = DisjointSet(N)
for _ in range(M):
    x, y = map(lambda x: int(x) - 1, input().split())
    ds.union(x, y)
print(sum(ds.same(P[i], i) for i in range(N)))


Measured memory_bytes: 20364
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef unordered_set<string> Set;
typedef unordered_map<string, Set> Map;

Set expand(Map& members, const string& group, Map& memo) {
    if (memo.count(group))
        return memo[group];
    Set r;
    for (auto& name : members[group]) {
        if (members.count(name)) {
            Set s = expand(members, name, memo);
            r.insert(s.begin(), s.end());
        } else {
            r.insert(name);
        }
    }
    memo[group] = r;
    return r;
}

int main() {
    int n;
    while (cin >> n, n) {
        string line;
        getline(cin, line);     // skip LR
        string first_group;
        Map members;
        for (int i = 0; i < n; ++i) {
            getline(cin, line);
            size_t colon = line.find(':');
            string group_name = line.substr(0, colon);
            Set member;
            for (size_t idx = colon+1; ; ) {
                size_t next = line.find(',', idx);
                if (next == string::npos)
                    next = line.find('.', idx);
                member.insert(line.substr(idx, next-idx));
                if (line[next] == '.')
                    break;
                idx = next+1;
            }
            members[group_name] = member;
            if (i == 0)
                first_group = group_name;
        }

        Map memo;
        Set ret = expand(members, first_group, memo);
        cout << ret.size() << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m;
  cin >> n >> m;
  int ans = n * (n - 1) + m * (m - 1);
  ans >>= 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>

int main() {
  long long N,M;
  std::cin >> N >> M;
  if (N >= M) {
    std::cout << 0 << std::endl;
    return 0;
  }
  std::vector<long long> X(M);
  for (auto &x:X)
    std::cin >> x;
  std::sort(X.begin(),X.end());
  std::vector<long long> D(M-1);
  for(int i=0;i<M-1;i++)
    D[i] = X[i+1] - X[i];
  std::sort(D.begin(), D.end(), std::greater<long long>());
  int start = std::max<long long>(0, N-1);
  long long sum = std::accumulate(D.begin() + start,
    D.end(),0);
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  ll n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  vll s(n+1);
  s[0] = 0;
  rep(i,n) s[i+1] = s[i] + a[i];
  ll ans = inf*n;
  rep2(i,1,n){
    ans = min(abs(s[n]-s[i]-s[i]),ans);
  }
  cout << ans << endl;
    
}




Measured memory_bytes: 2560
#include <stdio.h>

int main(){
     int S,h,m,s;

    scanf("%d", &S);
    
    h = S/3600;
    m = (S-(h*3600))/60;
    s = S-(h*3600)-(m*60);

    printf("%d:%d:%d\n" ,h,m,s);
    return 0;

}


Measured memory_bytes: 2076
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
C = input()

W_cnt = C.count('W')
R_cnt = C.count('R')
difc = ['R']*R_cnt + ['W']*W_cnt
cnt = 0
for i, j in zip(difc, C):
    if i != j:
        cnt += 1

print(min(W_cnt, R_cnt, cnt//2))

Measured memory_bytes: 78608
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0 && i%15!=0)
        {
            sum=sum+i;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstring>
using namespace std;
int x[1180][118][118], n, m, p, a, b, c;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n >> m >> p; if (!n) { break; }
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c;
			x[a][b][c] = 1; x[a][c][b] = 1;
		}
		for (int i = 1000; i > 0; i--) {
			for (int j = 1; j <= n; j++) {
				if (x[i][p][j] == 1) {
					p = j;
					break;
				}
			}
		}
		cout << p << endl;
	}
}

Measured memory_bytes: 65348
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
                Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
         int R = sc.nextInt();
         int d = sc.nextInt();
        int count = 0;
        for (int i = L; i <= R; i++) {
            if (i % d == 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}


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

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

    int res = 0;

    vector<int> d[33];
    vector<bool> s(33,false);
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        d[x].push_back(y);
        for (int  j = x; j <= y; j++) s[j] = true;
    }

    for (int i = 1; i < 32; i++) {
        if (d[i].size() > 0) {
            res += 100;
            sort(d[i].begin(), d[i].end());
            for (int j = 1; j < d[i].size(); j++) {
                if (d[i][j] > i) {
                    d[i+1].push_back(d[i][j]);
                }
            }
        } else if (s[i] > 0) res += 50;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;

int main()
{
    int N;
    while (true) {
        cin >> N;
        if (N == 0) break;

        int cnt = 0, k;
        bool ok = false;
        for (int i = 0; i < N; i++) {
            cin >> k;
            if (k > 0) {
                cnt++;
                if (k > 1) ok = true;
            }
        }

        if (ok) 
            cout << cnt + 1 << endl;
        else
            cout << "NA" << endl;
    }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
  long double n,k;
  cin >> n >> k;
  long double ans=0;
  long double num,cnt;
  for(int i=1;i<n+1;i++){
    if(i>=k){
      ans+=1/n;
    }else{
      num=i;
      cnt=0;
      while(k>num){
        num*=2;
        cnt++;
      }
      ans+=1/(pow(2,cnt)*n);
    }
  }
  cout << fixed;
  cout << setprecision(12) << ans << endl;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int k;
  cin >> k;
  vector<int> dp(k);
  int64 x = 0;
  for (int i = 1; i <= 2 * k; i++) {
    x = x * 10 + 7;
    x %= k;
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    if (dp[x]) {
      cout << -1 << endl;
      return 0;
    }
    dp[x] = 1;
  }
}

Measured memory_bytes: 7120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll N = 1e2+5;

int ans[N];
int main(){
    int a,b,k,u=1;
    scanf("%d%d%d",&a,&b,&k);
    for(int i=min(a,b);i>=1;i--){
        if(a%i==0&&b%i==0){
            //cout<<i<<" "<<u<<endl;
            ans[u++]=i;
        }
    }
    printf("%d\n",ans[k]);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
int main()
{
	checkpoint1();
	ll n,d;
	cin>>n>>d;
	ll ans=0;
	while(n--)
	{
		ll a,b;
		cin>>a>>b;
		a*=a;
		b*=b;
		a+=b;
		ld ok=d;
		ld op=(ld)sqrt(a);
		if(op<=ok)
			ans++;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#define ll long long

template< typename Monoid >
struct SegmentTree {
	using F = function< Monoid(Monoid, Monoid) >;

	int sz;
	vector< Monoid > seg;

	const F f;
	const Monoid M1;

	SegmentTree(int n, const F f, const Monoid& M1) : f(f), M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid& x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid& x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid operator[](const int& k) const {
		return seg[k + sz];
	}

	template< typename C >
	int find_subtree(int a, const C& check, Monoid& M, bool type) {
		while (a < sz) {
			Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
			if (check(nxt)) a = 2 * a + type;
			else M = nxt, a = 2 * a + 1 - type;
		}
		return a - sz;
	}


	template< typename C >
	int find_first(int a, const C& check) {
		Monoid L = M1;
		if (a <= 0) {
			if (check(f(L, seg[1]))) return find_subtree(1, check, L, false);
			return -1;
		}
		int b = sz;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) {
				Monoid nxt = f(L, seg[a]);
				if (check(nxt)) return find_subtree(a, check, L, false);
				L = nxt;
				++a;
			}
		}
		return -1;
	}

	template< typename C >
	int find_last(int b, const C& check) {
		Monoid R = M1;
		if (b >= sz) {
			if (check(f(seg[1], R))) return find_subtree(1, check, R, true);
			return -1;
		}
		int a = sz;
		for (b += sz; a < b; a >>= 1, b >>= 1) {
			if (b & 1) {
				Monoid nxt = f(seg[--b], R);
				if (check(nxt)) return find_subtree(b, check, R, true);
				R = nxt;
			}
		}
		return -1;
	}
};


signed main() {
	int n; cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; ++i)
		cin >> h[i];
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	if (n == 1) {
		cout << a[0] << endl;
		return 0;
	}

	SegmentTree<ll> dp(
		n + 1,
		[](ll a, ll b) {return max(a, b); },
		-(ll)1e18
	);
	dp.update(0, 0);
	for (int i = 0; i < n; ++i) {
		ll tmp = dp.query(0, h[i]) + a[i];
		dp.update(h[i], tmp);
	}

	cout << (dp.query(1, n + 2)) << endl;

	return 0;
}

Measured memory_bytes: 6656
#include<iostream>
using namespace std;
//Strongly Connected Components
#include<vector>
struct SCC{
	int n;
	vector<int>comp,order;
	vector<bool>used;
	vector<vector<int> >G,RG;
	SCC(int _n=0):n(_n),comp(_n,-1),used(_n,false),G(_n),RG(_n){}
	void add_edge(int from,int to)
	{
		G[from].push_back(to);
		RG[to].push_back(from);
	}
	void copy(const vector<vector<int> >&H)
	{
		for(int i=0;i<H.size();i++)
		{
			for(int j=0;j<H[i].size();j++)
			{
				G[i].push_back(H[i][j]);
				RG[H[i][j]].push_back(i);
			}
		}
	}
	int operator[](int u){return comp[u];}
	void dfs(int u)
	{
		used[u]=true;
		for(int i=0;i<G[u].size();i++)if(!used[G[u][i]])dfs(G[u][i]);
		order.push_back(u);
	}
	void rdfs(int u,int cnt)
	{
		comp[u]=cnt;
		for(int i=0;i<RG[u].size();i++)if(comp[RG[u][i]]==-1)rdfs(RG[u][i],cnt);
	}
	int build()
	{
		for(int i=0;i<n;i++)if(!used[i])dfs(i);
		int cnt=0;
		for(int i=n-1;i>=0;i--)if(comp[order[i]]==-1)rdfs(order[i],cnt++);
		return cnt;
	}
	int build(vector<vector<int> >&H)
	{
		int ret=build();
		H.assign(ret,vector<int>());
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<G[i].size();j++)
			{
				if(comp[i]!=comp[G[i][j]])
					H[comp[i]].push_back(comp[G[i][j]]);
			}
		}
		return ret;
	}
};
int main()
{
	int N,M;
	cin>>N>>M;
	SCC P(N);
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		P.add_edge(a,b);
	}
	P.build();
	for(int i=0;i<N;i++)
	{
		vector<int>a;
		for(int j=0;j<N;j++)if(P[i]==P[j])a.push_back(j);
		for(int i=0;i<a.size();i++)cout<<a[i]+1<<(i+1==a.size()?"\n":" ");
	}
}



Measured memory_bytes: 4188