akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
  int n,i,j,x,y,z;
  int matrix[101][101];
 
  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
	{
	  matrix[i][j] = 0;
	}
    }

  for(i=1;i<=n;i++)
    {
      scanf("%d",&x);
      scanf("%d",&y);

      for(j=0;j<y;j++)
	{
	  scanf("%d",&z);
	  matrix[i][z]=1;
	}
    }
  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
	{
	  if(j>1) printf(" ");
	  printf("%d",matrix[i][j]);
	}
      printf("\n");
    }

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vi vector<int>
#define sl set<ll>
#define sc set<char>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mpi map<ll,ll>
#define mpc map<char,ll>
#define forn(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf        1000000000000

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	forn(i,n)
	cin>>a[i];
	int ans[k+1]={0};
	ans[0]=0;
	for(ll i=0;i<=k;i++){
		for(ll j=0;j<n;j++){
			if(i>=a[j] && ans[i-a[j]]==0){
				ans[i]=1;
			}
		}
	}
	if(ans[k]==1)
	cout<<"First";
	else
	cout<<"Second";
}

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
  
 int main(){ 

 int A, B;

 cin >> A >> B;

 int ans = 0;

 if (A >= B) {
  ans += A;
  A -= 1;
  }

 else {
  ans = B;
  B -= 1;
  }

 if (A >= B) ans += A;

 else ans += B;

  cout << ans << endl;


 return 0;
}


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

using namespace std;

int main()
{
    long long value;
    cin >> value;
    int ans, v, min_diff = 1000;
    while(1){
        v = value % 1000;
        if(v < 100) break;
        if(abs(v - 753) < min_diff){
            ans = v;
            min_diff = abs(v - 753);
        }
        value /= 10;
    }
    cout << min_diff << endl;
}

Measured memory_bytes: 256
#include <stdio.h> 

int main(void)
{
    // int x;
    // scanf("%d", &x);
    // printf("%d\n", x);

    // long x;
    // scanf("%ld", &x);
    // printf("%ld\n", x);

    // char array[x];
    int k, a, b, ret=0, cnt=1;
    scanf("%d", &k);
    scanf("%d", &a);
    scanf("%d", &b);
    
    while (ret < a) {
        ret = (cnt++) * k;
        //printf("%d\n", ret);
    }

    if (ret <= b)
        printf("OK");
    else 
        printf("NG");

    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>

using namespace std;

int main() {
	int h, n;

	cin >> h >> n;

	vector<int> a(n);
	vector<int> b(n);

	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];

	vector<int> dp(h + 1);

	for (int i = 1; i <= h; i++) {
		dp[i] = dp[i - 1] + b[0];
		for (int j = 0; j < n; j++) {
			int mp;
			if (i <= a[j]) {
				mp = b[j];
			}
			else {
				mp = b[j] + dp[i - a[j]];
			}
			if (mp < dp[i]) {
				dp[i] = mp;
			}
		}
	}

	cout << dp[h] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
  
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
 
template <class X> void print(X Target){ cout << Target << '\n'; }

const int MAXN = 100, MAXW = 10000;

signed main()
{
  ios::sync_with_stdio(false);
  int N, W;
  int dp[MAXN + 1][MAXW + 1];
  int v[MAXN + 1], w[MAXN + 1];

  cin >> N >> W;
  for (int i = 1; i <= N; i++) cin >> v[i] >> w[i];

  // init
  for (int i = 0; i < W; i++) dp[0][i] = 0;
  for (int i = 0; i < N; i++) dp[i][0] = 0;

  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= W; j++){
      if (w[i] > j){
        dp[i][j] = dp[i - 1][j];
      }
      else {
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
      }
    }
  }

  print(dp[N][W]);

  return (0);
}

Measured memory_bytes: 5136
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()

  l=[I() for _ in range(n)]

  l.sort()

  l2=[]
  for x in l:
    if len(l2)>0:
      if x==l2[-1]:
        l2.pop()
      else:
        l2.append(x)
    else:
      l2.append(x)

  return len(l2)

print(main())


Measured memory_bytes: 10432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,q;
  cin >> n >> k >> q;

  vector<int> point(n, k-q);

  for(int i=0;i<q;i++){
  	int a;
  	cin >> a;
  	point.at(a-1)++;
  }
  for(int i=0;i<n;i++){
  	if(point.at(i)>0) cout << "Yes" << endl;
  	else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b;
  cin>>a>>b;
  if(max(a,b)>9) cout<<-1<<endl;
  else cout<<a*b<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=0;i<=999;i++)
	{
		if((n+i)%1000==0)
		{
			sum=i;
			break;
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int ans = 0;
        int ind = 0;
        while(true){
            int tmp = s.indexOf("ABC",ind);
            if(tmp == -1){
                break;
            }else{
                ans++;
                ind = tmp+1;
            }
        }
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

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

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

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

void solve(long long N, long long K, long long Q, std::vector<long long> A) {
  vector<LL> S;
  for(int i=0; i< N; i++){
    S.PB(K-Q);
  }
  for(int i=0; i<Q; i++){
    S[A[i]-1]++;
  }
  for(int i=0; i<N; i++){
    if(S[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> A(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, Q, std::move(A));
  return 0;
}


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

long long N;
long long a[200005];
set<long long> ans;

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

	for(long long i = N; i >0; i--){
		long long base = i;
		long long sumi = 0;
		while(base <= N){
			if(ans.find(base) != ans.end()){
				sumi += 1;
			}
			base += i;
		}

		if(a[i] != sumi%2){
			ans.insert(i);
		} 
	}

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

	vector<long long>ansout;
	for(auto item: ans){
		ansout.push_back(item);
	}

	for(int i = 0; i < ans.size(); i++){
		cout << ansout[i];
		if(i == ans.size() - 1){
			cout << endl;
		} else {
			cout << " ";
		}
	}
}


Measured memory_bytes: 9588
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>

using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

void precalc() {}

//#define solvsh
//#define multi

#ifdef solvsh

void solve() {

}

#else
typedef vector<int> vi;
#define INF 0x3f3f3f3f
#define FOR(i, n) for(int i = 0; i < n; i++)
template<class T>
T rnd(T l,T r){	//[l,r)
    using D = uniform_int_distribution<T>;
    static random_device rd;
    static mt19937 gen(rd());
    return D(l,r-1)(gen);
}
const int MAXN = 90;

ll dt[9][9];

bool cool[8][8];

void solve() {

    for (int i = 0; i < 3; ++ i){
        for (int j = 0; j < 3; ++ j){
            cin >> dt[i][j];
        }
    }

    int n;
    cin >> n;

    for (int i = 0 ; i < n; ++ i){
        int curr;
        cin >> curr;

        for (int j = 0; j < 3; ++ j){
            for (int k = 0; k < 3; ++ k){
                if (dt[j][k] == curr)cool[j][k] = true;
            }
        }
    }


    for (int i = 0; i < 3; ++ i){

        if (cool[i][0] && cool[i][1] && cool[i][2]){
            cout << "Yes\n";
            return;
        }

        if (cool[0][i] && cool[1][i] && cool[2][i]){
            cout << "Yes\n";
            return;
        }
    }

    if (cool[0][0] && cool[1][1] && cool[2][2]){
        cout << "Yes\n";
        return;
    }

    if (cool[2][0] && cool[1][1] && cool[0][2]){
        cout << "Yes\n";
        return;
    }

    cout << "No\n";

}

#endif


void multisolve() {
    int t;
    cin >> t;

    while (t--)
        solve();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

    precalc();

#ifdef multi
    multisolve();
#else
    solve();
#endif

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  int anssw=100*A,answ=100*A,anss=0;
  set<int> W;
  set<int> S;
  for(int a=0;a<=30;a++){
    for(int b=0;b<=30;b++){
      if(a+b==0) continue;
      if((A*a+B*b)*100<=F) W.insert(A*a*100+B*b*100);
    }
  }
  for(int c=0;c<=3000;c++){
    for(int d=0;d<=3000;d++){
      if(C*c+D*d<=F) S.insert(C*c+D*d);
    }
  }
  for(auto w:W){
    for(auto s:S){
      if(w+s>F)continue;
      if(E*w/100<s) continue;
      if(100*s*(anssw) > 100*anss*(s+w)){
        anss = s;
        answ = w;
        anssw = anss + answ;
      }
    }
  }
  cout << anssw << " " << anss << endl;
  return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{


	public static void main(String[] args){

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		try{
		String str=reader.readLine();
		String[] spl =str.split(" ");
		int[] intArray=new int[3];
		intArray[0]=Integer.parseInt(spl[0]);
		intArray[1]=Integer.parseInt(spl[1]);
		intArray[2]=Integer.parseInt(spl[2]);


		Arrays.sort(intArray);
		System.out.println(intArray[0]+" "+intArray[1]+" "+intArray[2]);

		}catch(IOException e){
			System.out.println("??¨??????:"+e);
		}


	}


}

Measured memory_bytes: 24380
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String inputLine = sc.nextLine();
		String[] tokens = inputLine.split(" ");
		int N = Integer.parseInt(tokens[0]);
		int K = Integer.parseInt(tokens[1]);
		if(N <= K)System.out.println(1);
		else System.out.println((int)Math.ceil((N-K)/(double)(K-1))+1);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(){
    int N, C;
    int s [100000] , t [100000] , c [100000];
    int sm [200002];
    int tt [200002];

    scanf ("%d %d " ,&N ,&C );
    for ( int i =0; i < N ; i ++) scanf ("%d %d %d " ,&s[i] ,&t[i] ,&c[i]);
    for ( int i =1; i <= C ; i++)
    {
       for ( int j =0; j <200002; j ++) tt [ j ]=0;
        for ( int j =0; j < N ; j ++) if ( c[j]== i ) tt [ s[j]*2 -1]++, tt[t[j]*2]--;
        for ( int j =1; j <200002; j ++) tt [j]+= tt [j-1];
        for ( int j =0; j <200002; j ++) if ( tt [j] >0) sm [j]++;
    }
    int mx =0;
    for ( int j =0; j <200002; j ++) if ( mx < sm [j]) mx = sm [j];
    printf ("%d\n" , mx );
}

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

typedef pair<int, int> pii;

int main(void) {
    int N;

    while (cin >> N, N)  {
        vector<pii> D(N);
        D[0] = pii(0, 0);

        for (int i = 1; i < N; i++) {
            int n, d; cin >> n >> d;
            pii s = D[n];

            switch (d) {
            case 0:
                s.first--;
                break;
            case 1:
                s.second++;
                break;
            case 2:
                s.first++;
                break;
            case 3:
                s.second--;
                break;
            }

            D[i] = s;
        }

        int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
        for (int i = 1; i < N; i++) {
            xmin = min(xmin, D[i].first);
            xmax = max(xmax, D[i].first);
            ymin = min(ymin, D[i].second);
            ymax = max(ymax, D[i].second);
        }

        cout << xmax-xmin+1 << " " << ymax-ymin+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<vector>

int main(){
	int h,w,m;
	std::cin>>h>>w>>m;

	std::vector<int> yList(m);
	std::vector<int> xList(m);

	for(int i=0; i< m; i++)
		std::cin>>yList[i]>>xList[i];

	std::vector<long long> yCount(h, 0);
	std::vector<long long> xCount(w, 0);

	for(int i=0; i<m; i++){
		yCount[yList[i]-1]++;
		xCount[xList[i]-1]++;
	}

	long long maxX=0;
	long long maxY=0;
	for(int i=0; i<w; i++)
		if(maxX< xCount[i])
			maxX= xCount[i];

	for(int i=0; i<h; i++)
		if(maxY< yCount[i])
			maxY= yCount[i];

	std::vector<int> maxXIdx;
	std::vector<int> maxYIdx;

	for(int i=0; i< w; i++)
		if(xCount[i] == maxX)
			maxXIdx.push_back(i);

	for(int i=0; i< h; i++)
		if(yCount[i] == maxY)
			maxYIdx.push_back(i);

	long long duplicateCount= 0;
	long long duplicateMax= maxXIdx.size() * maxYIdx.size();

	for(int i=0; i<m; i++){
		bool isExistX= false;
		bool isExistY= false;

		auto itrX = std::lower_bound(maxXIdx.begin(), maxXIdx.end(), xList[i]-1);
		isExistX= (itrX!= maxXIdx.end() && *itrX == xList[i]-1);

		auto itrY = std::lower_bound(maxYIdx.begin(), maxYIdx.end(), yList[i]-1);
		isExistY= (itrY!= maxYIdx.end() && *itrY == yList[i]-1);

		if(isExistX && isExistY)
			duplicateCount++;
	}

	long long ans = maxX + maxY + ((duplicateCount< duplicateMax)? 0 : -1);

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    string s,p;
    cin>>s>>p;
    
    s += s;
    
    bool tf=false;
    for(int i=0;i<s.size();i++) tf |= p == s.substr(i,p.size());
    
    cout<<(tf?"Yes":"No")<<endl;
    return 0;
    
}


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

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

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

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll A, B;

int main(){
    cin >> A >> B;

    if (A > B) swap(A, B);
    vector<ll> nums;
    for (ll i = 1; i * i <= A; ++i) {
        if (A % i == 0) {
            if (B % i == 0) nums.push_back(i);
            if (i != A / i && B % (A / i) == 0) nums.push_back(A / i);
        }
    }

    sort(nums.begin(), nums.end());

    int ans = 0;
    rep(i, nums.size()){
        bool ok = true;
        for (ll j = 1; j < i; ++j) {
            if (nums[i] % nums[j] == 0) ok = false;
        }
        if (ok) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
#define PI 3.1415926535897932384626433832795
#define coutfix(i) cout << fixed << setprecision(i)
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	vector<int64> vv(nn);
	long double ans;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> vv[ii];
	}
	sort(vv.begin(), vv.end());
	ans = vv[0];
	for(int64 ii = 1;ii < nn;ii++)
	{
		ans += vv[ii];
		ans /= 2.0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3804
n = int(input())
a = list(map(int, input().split()))
b = []
su = 0

la = len(a)
ele = a[la - 1]

for i in range(1, len(a) - 1):
    ele = ele + a[la - i - 1]
    b.append(ele)

lb = len(b)

for j in range(len(a) - 2):
    su = su + a[j] * b[lb - j - 1]

su = su + a[len(a) - 1] * a[len(a) - 2]

print(su % (10**9 + 7))

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

int main(){
	int n;
	std::vector<int> aList;

	long long ans=0;

	std::cin>>n;
	aList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end(), [](int x, int y){return x<y;});

	for(int i=0; i< n-2; i++){
		for(int j=i+1; j<n-1; j++){
			int sum= aList[i]+ aList[j];

			int left= j+1;
			int right= n;
			while(right- left>1){
				int center= (left+right)/2;

				if(sum<= aList[center])
					right= center;
				else
					left= center;
			}
			if(sum<= aList[left])
				continue;

			ans+= (left-j);
		}
	}

	std::cout<<ans<<std::endl;

	return 0;
}

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

#include <cmath>
#include <cstdlib>
#include <climits>

//#include "show_vector.hh"
//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int N, H;
  cin >> N >> H;
  vector<pair<int, int>> ab(N);
  int a_max = INT_MIN, b_min = INT_MAX;
  int x, y;
  for(int i = 0; i < N; i++){
    cin >> ab[i].first >> ab[i].second;
    if(ab[i].first > a_max) a_max = ab[i].first;
    if(ab[i].second > b_min) b_min = ab[i].second;
  }

  int n = 0;
  for(int i = N-1; 0 <= i; i--){
    if(ab[i].second <= a_max){
      ab.erase(ab.begin()+i);
      n++;
    }
  }

  N -= n;
  int a[N] = {}, b[N] = {};
  for(int i = 0; i < N; i++){
    a[i] = ab[i].first;
    b[i] = ab[i].second;
  }
  sort(a, a+N);
  sort(b, b+N);
  int count = 0;
  int damage = 0;
  int tmp;
  for(int i = 0; i < N; i++){
    damage += b[N-1-i];
    count++;

    if(H <= damage){
      //printf("throw only\n");
      goto END;
    }
  }
  //printf("damage : %d\n", damage);
  //printf("count  : %d\n", count);

  /*
  // H > damage
  while(H > damage){
    damage += a_max;
    count++;
  }
  */

  tmp = (H-damage) / a_max;
  if((H-damage) % a_max != 0) tmp++;
  count += tmp;

  END:
    cout << count << endl;


  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using lint = long int;
#define MAX 1000000

int N, tmp, a, GCD;
vector<lint> A(1000010);
vector<lint> spf(1000010);
vector<lint> emerge(1000010, 0);
bool SC = true, PC = true;

int gcd(int x, int y){
    if(x % y == 0) return y;
    else return gcd(y, x % y);
}

int main(){
    cin >> N;
    for(int i = 0; i <= MAX; i++) spf[i] = i;
    for(int i = 2; i * i <= MAX; i++){
        if(spf[i] == i){
            for(int j = i * i; j <= MAX; j+= i){
                if(spf[j] == j) spf[j] = i;
            }
        }
    }

    for(int i = 0; i < N; i++) cin >> A[i];

    /*set coprimeの条件を計算*/
    GCD = A[0];
    for(int i = 1; i < N; i++) GCD = gcd(GCD, A[i]);
    if(GCD != 1) SC = false;

  	/*pair coprimeの条件を計算*/
    for(int i = N-1; i >= 0; i--){
        a = A[i];
        while(a != 1){
            tmp = spf[a];  //最小素因数取得
            if(emerge[tmp] > 0){ PC = false; break;}  //前の要素分解で出現済みはアウト
            else emerge[tmp] = 1;
            while(a != 1 && spf[a] == tmp) a /= spf[a];
        }
    }

    if(PC) cout << "pairwise coprime" << endl;
    else if(SC) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;

    return 0;

    

}

Measured memory_bytes: 26588
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

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

    int N, A, B;
    cin >> N >> A >> B;
    if(A*N < B){
        cout << A*N << endl;
    }else{
        cout << B << endl;
    }

    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  cin>>s;
  ll n=s.size();
  
  ll cnt=0;
  REP(i,n){
    if(s[i]=='x')
      cnt++;
  }
  
  if(cnt<=7)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
S = input()

n = len(S)
ans = [0 for _ in range(n)]

S += "$"

s = 0
for i in range(n):
    if S[i] != S[i+1]:
        l = i - s + 1
        if S[i] == "R":
            ans[i + 1] += l // 2
            ans[i] += (l + 1) // 2
        else:
            ans[s] += (l + 1) // 2
            ans[s - 1] += l // 2
        s = i + 1

print(" ".join(map(str, ans)))


Measured memory_bytes: 17144
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/

/*
int prime[1000000] = {0} ;
vector < vector < int >  > fact(1000001);
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*2 ; j <= 1000000 ; j += i )
            {
                fact[j].pb(i);
            }
        }
    }
}
*/

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
  ll a = 0, b = 1, c, i;
  if( n == 0)
    return a;
  for (i = 2; i <= n; i++)
  {
    c = (a + b);
    a = b;
    b = c;
  }
  return b;
}


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

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair<int,int> &a , const pair<int,int> &b){
    return a.first < b.first;
    if(a.first == b.first)  return a.second < b.second;
}

int arr[100005];

void solve(){
    int n;
    in(n);
    ll arr[n];
    f(i,n)  in(arr[i]);
    ll fin = arr[0];
    mfor(i,1,n,1){
        fin ^= arr[i];
    }
    f(i,n){
        cout<<(fin^(ll)arr[i])<<" ";
    }
}
int main() {
    fast();
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


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

using namespace std;

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

const long long INF = 1LL << 60;

long long dp[100010];//Table
long long N;
int main(){
    cin >> N;

    //init
    for(int i = 0; i < 100010; i++)dp[i] = INF;
    dp[0] = 0;

    vector<int> h(N);
    for(int i = 0; i < N; i++)cin >> h[i];

    for(int i =0; i < N; i++){
        chmin(dp[i+1],(dp[i]+abs(h[i+1]-h[i])) );
        chmin(dp[i+2],(dp[i]+abs(h[i+2]-h[i])) );
    }

    cout << dp[N-1] << endl;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  string s;
  cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 3572
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = stdIn.nextInt();
        }
         
        Arrays.sort(a);
         
        long s = 0;
         
        for(int i = 0; i < n; i++) {
            s += a[i];
        }
         
        System.out.println(a[0] + " " + a [n-1] + " " +  s );
    }
}


Measured memory_bytes: 42316
#!/usr/bin/env python3
import sys


def solve(W: int, a: int, b: int):
    if a <= b <= a+W or b <= a <= b+W:
        return 0
    return min(min(abs(aa-bb) for bb in [b, b+W]) for aa in [a, a+W])

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    print(solve(W, a, b))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

typedef long long ll;
#define PI 2 * acos (0.0)

ll MOD = 1e9 + 7 ;
ll arr[100005] ;

int main()
{
  ll a, b, ans ;
  cin >> a >> b ;

  ans = (a * b) / __gcd(a, b) ;
  cout << ans << endl ;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
int r,c,rs[101],cs;
cin >> r >> c;
int h[101][101];
for (int i = 0; i<r; i++) {
for (int j = 0; j<c; j++) {
cin >> h[i][j];
}
}
for (int i = 0; i < 101; i++) {
rs[i] = 0;
}
for (int i = 0; i <= r; i++) {
cs = 0;
for (int j = 0; j <= c; j++) {
if (i != r) {
if(j!=c)cs += h[i][j];
if (j != c)rs[j] += h[i][j];
if (j == c) cout << cs << endl;
else cout << h[i][j] << " ";
}
else {
if (j != c)cs += rs[j];
if (j == c) cout << cs << endl;
else cout << rs[j] << " ";
}
}
}
}

Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
#define USINT_MAX 4294967295

int main() {
	char a[16];
	int i = 0;
	cin >> a;
	if (a[0] != 'C')i++;
	if (a[1] != 'O')i++;
	if (a[2] != 'D')i++;
	if (a[3] != 'E')i++;
	if (a[4] != 'F')i++;
	if (a[5] != 'E')i++;
	if (a[6] != 'S')i++;
	if (a[7] != 'T')i++;
	if (a[8] != 'I')i++;
	if (a[9] != 'V')i++;
	if (a[10] != 'A')i++;
	if (a[11] != 'L')i++;
	if (a[12] != '2')i++;
	if (a[13] != '0')i++;
	if (a[14] != '1')i++;
	if (a[15] != '6')i++;
	cout << i;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    map<int, int> ma;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;

        ma[a]++;
    }

    int sum = 0;

    for (auto m : ma) {
        if (m.second > 1) {
            sum += m.second - 1;
        }
    }

    if (sum % 2 == 0) {
        cout << n - sum << endl;
    } else {
        cout << n - sum - 1 << endl;
    }
}

Measured memory_bytes: 4992
Bingo_list = [[int(_) for _ in input().split()] for i in range(3)]

cross_line = []
reverse_cross = []
for i in range(3):
    vertiual_line = []
    cross_line.append(Bingo_list[i][i])
    reverse_cross.append(Bingo_list[i][2-i])
    for j_line in Bingo_list[:3]:
        vertiual_line.append(j_line[i])
    Bingo_list.append(vertiual_line)

Bingo_list.append(cross_line)
Bingo_list.append(reverse_cross)

N = int(input())
SelectNum = [int(input()) for _ in range(N)]

for i_line in Bingo_list:
    for i_num in i_line:
        if not i_num in SelectNum:
            break
    else:
        ans = 'Yes'
        break
else:
    ans = 'No'

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 0;
const int OOO = 1;
using namespace std;

string k;
vector<int> a;
int d, n;
int dp[2][101];

void layer(int l) {
	for (int i = 0; i < d; i++) dp[l & 1][i] = 0;
	for (int i = 0; i < d; i++) {
		for (int put = 0; put < 10; put++) {
			dp[l & 1][(i + put) % d] += dp[l & 1 ^ 1][i];
			if (dp[l & 1][(i + put) % d] >= md)
				dp[l & 1][(i + put) % d] -= md;
		}
	}
	if (OO) {
		cout << "layer " << l << '\n';
		for (int i = 0; i < d; i++) {
			cout << "dsum " << i << ": " << dp[l & 1][i] << '\n';
		}
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> k >> d;
	n = k.size();
	a.resize(n);
	for (int i = 0; i < n; i++) {
		a[i] = k[i] - '0';
		if (i) a[i] += a[i - 1];
		a[i] %= d;
	}
	int ans = 0;
	for (int put = 0; put <= k.back() - '0'; put++)
		if (((n == 1 ? 0 : a[n - 2]) + put) % d == 0) ans++;
	dp[0][0] = 1;
	for (int i = 1; i < n; i++) {
		layer(i);
		for (int put = 0; put < k[n - 1 - i] - '0'; put++) {
			ans += dp[i & 1][((d - ((n - 2 - i < 0 ? 0 : a[n - 2 - i]) + put)) % d + d) % d];
			if (ans >= md)
				ans -= md;
		}
	}
	ans--; // counted 0
	if (ans < 0) ans += md;
	finish(ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

ll dp[100010][110] = {};

ll max(ll a, ll b)
{
        return (a>b)?a:b;
}

int main()
{
        ll N, W, i, j;
        scanf("%lld %lld", &N, &W);
        ll w[N+1], v[N+1];
        for(i = 0; i < N; i++)
        {
                scanf("%lld %lld", w+i+1, v+i+1);
        }
        for(i = 1; i <= W; i++)
        {
                for(j = 1; j <= N; j++)
                {
                        if(i-w[j] < 0)
                                dp[i][j] = dp[i][j-1];
                        else
                                dp[i][j] = max( dp[i][j-1], v[j] + dp[i-w[j]][j-1]);
                //      printf("%lld ", dp[i][j]);

                }
        //      printf("\n");
        }

        printf("%lld\n", dp[W][N]);
        return 0;

}

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

int h,w;
char field[105][105];
int main(){
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;++i) scanf("%s",field[i]);
	for(int i=0;i<h;++i){
		int lastPos=-1;
		for(int j=0;j<w;++j){
			if(field[i][j]=='c') lastPos=j;
			
			int res=-1;
			if(lastPos!=-1) res=j-lastPos;
			printf("%d%c",res,j==w-1?'\n':' ');
		}
	}

	return 0;
}

Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int64_t> s(n+1,0);
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    s.at(i+1)=s.at(i)+a;
  }
  vector<vector<int64_t>> dp(n,vector<int64_t>(n,0));
  for(int w=1;w<n;w++){
    for(int i=0;i+w<n;i++){
      dp[i][i+w]=dp[i+1][i+w];
      for(int x=i;x<i+w;x++)
        dp[i][i+w]=min(dp[i][i+w],dp[i][x]+dp[x+1][i+w]);
      dp[i][i+w]+=s.at(i+w+1)-s.at(i);
    }
  }
  cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 4880
n,x = map(int,input().split())
a = list(map(int,input().split()))

res = 0
for i in range(1,n):
    if a[i]+a[i-1]>= x:
        res += (a[i]+a[i-1]-x)
        if a[i-1]>= x:
            a[i]=0
        else:
            a[i] = x-a[i-1]
    
print(res)

Measured memory_bytes: 14540
#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
const int INF = 1<<30;

int n, ans=-INF, tot=1, front[N], bit[N], f[N];

struct tEdge{
    int v, next;
    inline void addEdge(int tmpu, int tmpv){
        v = tmpv;
        next = front[tmpu];
        front[tmpu] = tot;
    }
} e[N<<1];
inline void add(int u, int v){
    e[++tot].addEdge(u, v);
    e[++tot].addEdge(v, u);
}

void dfs(int u, int fa){
    bit[u] = f[u] = 0; int l = 0;
    for(int i=front[u]; i; i=e[i].next){
        int v = e[i].v;
        if(v == fa) continue;

		dfs(v, u);
        l |= (bit[u] & bit[v]);
        // 如果bit[u] 和 bit[v] 在 i 位上同时为1, l 在 i 位上也是1
        // 即如果两个超过两个儿子对于 i 都良好, 则该节点的编号必须超过 i
        bit[u] |= bit[v];
    }

    if(!bit[u]) bit[u] = 1;
    else{
        while((1<<f[u]) < l || (1<<f[u]) & bit[u]) f[u] ++;
        //如果2^f[u] < l 或者 bit[u]在f[u]上为1
        bit[u] = ((bit[u] >> f[u] << f[u]) | (1<<f[u]));
        //重置bit[u], 去掉f[u]后的位
    }

    ans = max(ans, f[u]);
}

int main(){
    scanf("%d", &n);
    for(int i=1,x,y; i< n; i++){
        scanf("%d%d", &x, &y);
        add(x, y);
    }
    
    dfs(1, 0);
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 12544
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

ll sq(ll x){
	return x*x;
}

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

bool isvowel(char c){
	int i;
	string v="aeiou";
	for(i = (v.size()-1); i>=0; --i){
		if(c == v[i]){
			return true;
		}
	}
	return false;
}

int main(void){
	int a,b;
	cin >> a >> b;
	a += 11;
	a %= 13;
	b += 11;
	b %= 13;
	cout << ((a==b)?"Draw":((a>b)?"Alice":"Bob")) << endl;
	return 0;
}

Measured memory_bytes: 256
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.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);
        DXorSum2 solver = new DXorSum2();
        solver.solve(1, in, out);
        out.close();
    }

    static class DXorSum2 {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints();
            int[] a = in.ints(n);

            int t = 0;
            int l = 0;
            long ans = 0;
            for (int r = 0; r < n; r++) {
                while ((t & a[r]) > 0) {
                    t &= ~a[l];
                    l++;
                }
                t |= a[r];
                ans += r - l + 1;
            }
            out.println(ans);
        }

    }

    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 int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}



Measured memory_bytes: 44728
def resolve():
    n = int(input())
    s = [",".join(sorted(input())) for i in range(n)]
    ans = {}
    count = 0
    for i in range(n):
        if s[i] in ans:
            count += ans[s[i]]
            ans[s[i]] += 1
        else:
            ans[s[i]] = 1
    print(count)
resolve()

Measured memory_bytes: 70744
#include <stdio.h>
int main(void){
    // Your code here!
    char moji[4];
    int flag = 0;
    for(int i=0;4>=i;i++){
        scanf("%c\n",&moji[i]);
    }
    if(moji[0]==moji[1]){
        if(moji[0]!=moji[2]&&moji[2]==moji[3]){
            printf("Yes\n");
            flag=1;
        }
    }
    else if(moji[0]==moji[2]){
        if(moji[0]!=moji[1]&&moji[1]==moji[3]){
            printf("Yes\n");
            flag=1;
        }
    }
    else if(moji[0]==moji[3]){
        if(moji[0]!=moji[1]&&moji[1]==moji[2]){
            printf("Yes\n");
            flag=1;
        }
    }
    
    if(flag==0){
        printf("No\n");
    }
}




Measured memory_bytes: 256
'''input
3 3
.#.
#..
.#.
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque


def mp(arr):
	arr = map(str, arr)
	return ' '.join(arr)


def bfs(source):
	myq = deque()
	myq.append(source)
	visited = dict()
	visited[mp(source)] = True
	dist = -1
	while len(myq) > 0:
		temp = deque()
		dist += 1
		while len(myq) > 0:
			x, y  = myq.popleft()
			if x - 1 >= 0 and maze[x - 1][y] != '#' and mp([x - 1, y]) not in visited:
					visited[mp([x -1, y])] = True
					temp.append([x - 1, y])
			if x + 1 < n and maze[x + 1][y] != '#' and mp([x + 1, y]) not in visited:
					visited[mp([x + 1, y])] = True
					temp.append([x + 1, y])
			if y - 1 >= 0 and maze[x][y - 1] != '#' and mp([x, y - 1]) not in visited:
					visited[mp([x, y - 1])] = True
					temp.append([x, y - 1])
			if y + 1 < m and maze[x][y + 1] != '#' and mp([x, y + 1]) not in visited:
					visited[mp([x, y + 1])] = True
					temp.append([x, y + 1])
		myq = temp
	return dist		


# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(n):
	state = list(input().strip())
	maze.append(state)

# from random import randint
# for _ in range(1000):
# maze = []
# n = randint(1, 20)
# m = randint(1, 20)
# for i in range(n):
# 	temp = []
# 	for j in range(m):
# 		k = randint(1, 2)
# 		if k == 1:
# 			temp.append('.')
# 		else:
# 			temp.append('#')
# 	maze.append(temp)

ans = 0
for i in range(n):
	for j in range(m):
		if maze[i][j] != '#':
			first = [i, j]
			ans = max(ans, bfs(first))
print(ans)

Measured memory_bytes: 46360
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  ll ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    ll T;
    cin >> T;
    ans = lcm(T, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
int insSort(int *A,int n,int g)
{
    int i,cnt=0;
    for(i=g;i<n;i++){
        int v=A[i];
        int j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j=j-g;
            cnt++;
        }
       A[j+g]=v;
    }
    return cnt;
}
int main()
{
    int n,i;
    scanf("%d",&n);
    int A[n];
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    int m=1, cnt=0;
    int G[13]={1};
    for(i=1;;i++){
        G[i]=G[i-1]*3+1;
        if(G[i]>n)break;
        m++;
    }
    printf("%d\n",m);
    for(i=m-1;i>=0;i--){
        if(i==0)printf("%d\n",G[i]);
        else printf("%d ",G[i]);
    }
    for(i=m;i>=0;i--){
        cnt += insSort(A,n,G[i]);
    }
    printf("%d\n",cnt);
    for(i=0;i<n;i++){
        printf("%d\n",A[i]);
    }
    return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = n; i > 0; i--)
#define rep3(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep4(i, s, e) for (int i = (e); i < (int)(s); i--)

int main() {
    int n, m;
    int a, b;
    cin >> n >> m;
    vector<int> road_num(n, 0);

    rep(i, m){
        cin >> a >> b;
        road_num.at(a - 1)++;
        road_num.at(b - 1)++;
    }

    rep(i, n){
        cout << road_num.at(i) << endl;
    }
}


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

int main()
{
    int a,b,c,d,e,k,check=0;
    scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
    if((b-a)>k || (c-a)>k || (d-a)>k || (e-a)>k || (c-b)>k || (d-b)>k || (e-b)>k || (d-c)>k || (e-c)>k || (e-d)>k){
        check=1;
    }
    if(check==0){
        printf("Yay!\n");
    }else{
        printf(":(\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>
#include <complex>
#include <cstdio>

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

// sizeof v must be 2 ^ n
template<class T>
void fft_core(vector<complex<T> > &v, bool rev = false){
  const int n = v.size();

  for(int i = 0; i < n; i++){
    int k = 0;
    int b = (n >> 1);
    int a = 1;

    while(b >= a){
      if(b & i) k |= a;
      if(a & i) k |= b;
      b >>= 1;
      a <<= 1;
    }

    if(i < k) swap(v[i], v[k]);
  }

  int m = 2;

  while(m <= n){
    double arg = -2.0 * M_PI / m;
    complex<T> w(cos(arg), sin(arg));
    if(rev) w = 1.0 / w;

    for(int i = 0; i < n; i += m){
      complex<T> ww(1.0);

      for(int j = 0; j < m / 2; j++){
	int a = i + j;
	int b = i + j + m / 2;
	complex<T> t = ww * v[b];

	v[b] = v[a] - t;
	v[a] = v[a] + t;

	ww *= w;
      }
    }
    m *= 2;
  }

  if(rev){
    double s = (double)n;
    for(int i = 0; i < n; i++)
      v[i] /= s;
  }
}

template<class T> inline void  fft(vector<T> &v){ fft_core(v); }
template<class T> inline void ifft(vector<T> &v){ fft_core(v, true); }

int next(int n){
  int i = 1;
  while(i < n) i *= 2;
  return i;
}


int main(){
  int n  = getInt();
  int m  = next(n + 1);
  int mm = m * 2;
  vector<complex<double> > p(mm, 0.0);
  double prev = 0.0;
  p[0] = 1.0;
  
  for(int i = 1; i <= n; i++){
    if(i < 80){
      fft(p);

      for(int j = mm - 1; j >= 0; j--){
	p[j] = p[j] * p[j];
      }
      
      ifft(p);

      for(int j = mm - 1; j >= 1; j--){
	p[j] = p[j - 1];
      }
      p[0] = 1.0;
      for(int j = 1; j < mm / 2; j++)
	p[j] /= j;
      for(int j = mm / 2; j < mm; j++)
	p[j] = 0.0;
      
      double ans = n >= p.size() ? 0.0 : p[n].real();
      double pans = (ans - prev);
      if(ans > 1e-10) pans += 0.000007;
      printf("%.7f\n", max(0.0, pans) + 1e-10);
      prev = ans;
    }else{
      printf("%.7f\n", 0.0 + 1e-10);
    }
  }

  return 0;
}

Measured memory_bytes: 0