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


int main() {
  int x; cin >> x;
  if(x < 600) cout << 8 << endl;
  else if(x < 800) cout << 7 << endl;
  else if(x < 1000) cout << 6 << endl;
  else if(x < 1200) cout << 5 << endl;
  else if(x < 1400) cout << 4 << endl;
  else if(x < 1600) cout << 3 << endl;
  else if(x < 1800) cout << 2 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    string ans = "Impossible";
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
        ans = "Possible";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


int main(){
	init();
	ll N,K;cin>>N>>K;
	vector<ll>v(N);
	for(int i=0;i<N;i++){
		cin>>v[i];
	}
	ll ans=0;
	for(int i=0;i<=N;i++){
		if(i>K)continue;
		for(int j=0;j<=i;j++){
			//from left
			vector<ll>mine;
			for(int k=0;k<j;k++){
				mine.push_back(v[k]);
			}
			for(int k=0;k<i-j;k++){
				mine.push_back(v[N-k-1]);
			}
			/*cout<<"i="<<i<<" j="<<j<<endl;
			for(auto k : mine)cout<<k<<" ";
			cout<<endl;*/
			sort(mine.begin(),mine.end());
			ll index=0;
			for(;index<K-i;index++){
				if(index>=mine.size())break;
				if(mine[index]>0)break;
			}
			ll num=0;
			for(;index<mine.size();index++){
				num+=mine[index];
			}
			//cout<<"num="<<num<<endl;
			ans=max(num,ans);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    V<int> c(n),s(n),f(n);
    rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
    rep(i,n){
        if(i==n-1){
            out(0);
            break;
        }
        int time=s[i];
        for(int j=i;j<n-1;j++){
            time+=c[j];
            if(j==n-2) break;
            int tmp=time%f[j+1];
            if(tmp!=0) tmp=f[j+1]-tmp;
            if(time+tmp<s[j+1]) time=s[j+1];
            else time+=tmp;
        }
        out(time);
    }
}

Measured memory_bytes: 3668
import itertools

INF = float("inf")


def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    path = [[INF]*(N+1) for _ in range(N+1)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        path[A][B] = C
        path[B][A] = C
    for i in range(1, N+1):
        path[i][i] = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            for k in range(1, N+1):
                path[j][k] = min(path[j][k], path[j][i] + path[i][k])
    ans = INF
    for p in itertools.permutations(r):
        cost = 0
        for i in range(R-1):
            cost += path[p[i]][p[i+1]]
        ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61016
#include<stdio.h>
#define min(a,b) a<b?a:b
int main()
{
    long long a,b,t;
    scanf("%lld%lld",&a,&b);
    t=b+a;
    if(t&1)
        printf("IMPOSSIBLE\n");
    else
        printf("%d\n",t/2);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=0;
  rep(i,n){
    if(i%2==0&&s[i]=='L'){
      ans=1;
      break;
    }
    if(i%2==1&&s[i]=='R'){
      ans=1;
      break;
    }
  }
  if(ans)cout <<"No" << endl;
  else cout << "Yes" << endl;
}  


Measured memory_bytes: 256
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        a = a.OrderBy(f => f).ToArray();
        if (nk[0] > 1)
        {
            int gcdAll = Gcd(a[0], a[1]);
            for (int i = 2; i < a.Length; i++)
            {
                gcdAll = Gcd(gcdAll, a[i]);
            }
            Console.WriteLine((nk[1] % gcdAll == 0) && (nk[1] <= a.Last()) ? "POSSIBLE" : "IMPOSSIBLE");
        }
        else
        {
            Console.WriteLine(nk[1] == a[0] ? "POSSIBLE" : "IMPOSSIBLE");
        }
    }
    public static int Gcd(int x, int y)
    {
        if (x < y) return Gcd(y, x);
        while (y != 0)
        {
            var temp = x % y;
            x = y;
            y = temp;
        }
        return x;
    }
}

Measured memory_bytes: 23136
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
 
int main(){
#include<iostream>

using namespace std;
  string a;
  cin >> a;
  cout << a[0] << a.size()-2 << a[a.size()-1] << endl;
}


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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

bool solve(string s) {
    stack<char> stk;

    for (auto c : s) {
        if (c == '[' || c == '(') {
            stk.push(c);
        } else if (c == ']' || c == ')') {
            if (!stk.size()) return false;

            string t = string() + stk.top() + c;
            stk.pop();

            if (t != "()" && t != "[]") {
                return false;
            }
        }
    }

    return stk.size() == 0;
}

int main(void) {
    string s;
    while (getline(cin, s), s != ".") {
        cout << (solve(s) ? "yes" : "no") << endl;
    }

    return 0;
}

Measured memory_bytes: 3124
N = int(input())

fase = 0
idx = 0
for i in range(1, 20):
  N -= 26**i
  if N <= 0:
    fase = i
    idx = 26**i - abs(N)
    break

ans = ''
for i in range(1, fase+1):
  q = idx / (26**(fase-i))
  mod = idx % (26**(fase-i))
  if mod == 0:
    mod = 26**(fase-i)
  if q <= 1:
    ans += 'a'
  elif q <= 2:
    ans += 'b'
  elif q <= 3:
    ans += 'c'
  elif q <= 4:
    ans += 'd'
  elif q <= 5:
    ans += 'e'
  elif q <= 6:
    ans += 'f'
  elif q <= 7:
    ans += 'g'
  elif q <= 8:
    ans += 'h'
  elif q <= 9:
    ans += 'i'
  elif q <= 10:
    ans += 'j'
  elif q <= 11:
    ans += 'k'
  elif q <= 12:
    ans += 'l'
  elif q <= 13:
    ans += 'm'
  elif q <= 14:
    ans += 'n'
  elif q <= 15:
    ans += 'o'
  elif q <= 16:
    ans += 'p'
  elif q <= 17:
    ans += 'q'
  elif q <= 18:
    ans += 'r'
  elif q <= 19:
    ans += 's'
  elif q <= 20:
    ans += 't'
  elif q <= 21:
    ans += 'u'
  elif q <= 22:
    ans += 'v'
  elif q <= 23:
    ans += 'w'
  elif q <= 24:
    ans += 'x'
  elif q <= 25:
    ans += 'y'
  elif q <= 26:
    ans += 'z'
  idx = mod

print(ans)

    

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string S, T = "", words[4] = {"dream", "dreamer", "erase", "eraser"};
  cin >> S;
  int N = S.size(), w[4] = {5, 7, 5, 6};
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      if (i + w[j] == N && S.substr(i, w[j]) == words[j]) {
        cout << "YES" << endl;
        return 0;
      }
    }
    if (S[i] == 'd' && i + w[0] <= N - 1 && S.substr(i, w[0]) == words[0]) {
      if (i + w[0] <= N - 1 && S[i + w[0]] == 'd')
        T += words[0];
      else if (i + w[0] + 2 <= N - 1 && S[i + w[0] + 2] == 'a')
        T += words[0];
      else if (i + w[0] + 1 <= N - 1 && S[i + w[0] + 0] == 'e' &&
               S[i + w[0] + 1] == 'r')
        T += words[1];
      else {
        break;
      }
    } else if (S[i] == 'e' && i + w[2] <= N - 1 &&
               S.substr(i, w[2]) == words[2]) {
      if (i + w[2] <= N - 1 && S[i + w[2]] == 'r') {
        T += words[3];
      } else {
        T += words[2];
      }
    } else {
      break;
    }
    i = T.size() - 1;
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 640
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,p,x,y,z,num[2510],canrn[2510];
pii dp[2510],res[2510];
vector <pii> g[2510];
vector <LL> topo;
bool vis[2510],ok=true;

int dfs(int pos)
{
	vis[pos]=true;
	int ret=0;
	rep(i,g[pos].size())
	{
		if(vis[g[pos][i].fi]) continue;
		ret|=dfs(g[pos][i].fi);
	}
	topo.pb(pos);
	return canrn[pos]=ret|(pos==n ? 1:0);
}

int main()
{
	for(int i=2;i<=2503;i++) dp[i].se=1e9;
	cin>>n>>m>>p;
	rep(i,m)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		g[x].pb({y,z});
	}
	dfs(1);
	reverse(topo.begin(),topo.end());
	rep(i,topo.size()) num[topo[i]]=i;
	rep(i,topo.size())
	{
		for(int j=0;j<topo.size();j++)
		{
			rep(k,g[topo[j]].size())
			{
				if(dp[topo[j]].fi+g[topo[j]][k].se-(dp[topo[j]].se+1)*p>
				dp[g[topo[j]][k].fi].fi-dp[g[topo[j]][k].fi].se*p) 
				dp[g[topo[j]][k].fi]={dp[topo[j]].fi+g[topo[j]][k].se,
				dp[topo[j]].se+1};
			}
		}
	}
	rep(i,topo.size()) res[topo[i]]=dp[topo[i]];
	rep(i,topo.size())
	{
		for(int j=0;j<topo.size();j++)
		{
			rep(k,g[topo[j]].size())
			{
				if(dp[topo[j]].fi+g[topo[j]][k].se-(dp[topo[j]].se+1)*p>
				dp[g[topo[j]][k].fi].fi-dp[g[topo[j]][k].fi].se*p) 
				dp[g[topo[j]][k].fi]={dp[topo[j]].fi+g[topo[j]][k].se,
				dp[topo[j]].se+1};
			}
		}
	}
	rep(i,topo.size()) if(res[topo[i]]!=dp[topo[i]]&&canrn[topo[i]]) ok=false;
	if(!ok) puts("-1");
	else cout<<max(0LL,dp[n].fi-dp[n].se*p)<<endl;
	return 0;
}

Measured memory_bytes: 768
while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N;
  cin >> N;
  int F[100][5][2];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> F[i][j][k];
      }
    }
  }
  int P[100][11];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }

  int ans = INT_MIN;
  for (int x = 1; x < (1 << 10); x++) {
    int tmp = 0;
    for (int i = 0; i < N; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if ((x >> j & 1) && F[i][j % 5][j % 2]) {
          cnt++;
        }
      }
      tmp += P[i][cnt];
    }
    if (ans < tmp)
      ans = tmp;
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector <int> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  cout << v.at(n/2) - v.at((n/2)-1) << endl;
}

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

int main() {
	int N,M,X,Y;
	cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  rep(i,N) cin >> x[i];
  rep(i,M) cin >> y[i];

  int xmax = *max_element(all(x));
  int ymin = *min_element(all(y));

  if(xmax < Y && ymin >X && xmax<ymin){
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
char S[8];
int main(){
  rd(S);
  if(S[2]==S[3] && S[4]==S[5]){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200322-1 [beta]

// --- original code ---
// char S[8];
// {
//   rd(S);
//   wt(if[S[2]==S[3] && S[4]==S[5], "Yes", "No"]);
// }


Measured memory_bytes: 256
a, b = input().split()
keta = len(b) - b.find(".") - 1
a_n = int(a)
b_n = int(b.replace(".", ""))
ans = a_n * b_n
ans_s = str(ans)
if len(ans_s) < keta + 1:
    print(0)
else:
    print(ans_s[:-keta])

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

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
ios_base::sync_with_stdio(false); \
cin.tie(0);                       \
cout.tie(0);
#define test  \
int t;    \
cin >> t; \
while (t--)
#define debug(a)          \
	cerr << #a << ": ";   \
for (auto i : a)      \
	cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
for (int u = 0; u < n; u++) \
	{                           \
		cout << ar[u] << " ";   \
	}                           \
	cout << endl;
#define int long long
#define M 1000000007
	signed main()
	{
		rootdada;
// #ifndef ONLINE_JUDGE
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 		freopen("error.txt", "w", stderr);
// #endif
		int n,k;
		cin>>n>>k;
		int a[n+1]={0};
		rep(i,0,k)
		{
			int z;
			cin>>z;
			rep(i,0,z)
			{
				int x;
				cin>>x;
				a[x]=z;
			}
		}
		int ans=0;
		rep(i,1,n+1)
		{
			// cout<<i<<" "<<a[i]<<endl;
			if(a[i]==0)
				ans++;
		}
		cout<<ans<<endl;
	}

Measured memory_bytes: 3652
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
#define INF 1000000000
int main(){
	long long int i, j, H, N, A[10000], B[10000], **dp, count = INF, Amax=0;

	scanf("%lld %lld", &H, &N);

	for (i = 0; i < N; i++){
		scanf("%lld %lld", &A[i], &B[i]);
		Amax = max(Amax, A[i]);
	}

	dp = (long long int  **)malloc(sizeof(long long int *)* (N + 1));



	for (i = 0; i<N + 1; i++) {
		dp[i] = (long long int *)malloc(sizeof(long long int)* (H+Amax));
	}

	for (i = 0; i < N+1; i++){
		for (j = 0; j < H+Amax; j++){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;

	for (i = 0; i < N; i++){
		for (j = 0; j < H + Amax; j++){
			if (j < A[i]){
				dp[i + 1][j] = dp[i][j];
			}
			else{
				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i]);
			}

		}

	}

	for (i = H; i < H + Amax; i++){
		count = min(count, dp[N][i]);
	}



	printf("%lld\n", count);

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int str = 0;
    int Acount = 0;
    int Bcount = 0;
    for(int i=0;i<N;i++){
        str = a.at(i);
        if(i%2 == 0){
            Acount += str;
        }
        else{
            Bcount += str;
        }
    }

    cout << Acount - Bcount << endl;
}

Measured memory_bytes: 3592
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()

x1 = x2 = A[0]

i = 1
j = len(A) - 1

result = 0

while i <= j:
    a1 = A[i]
    a2 = A[j]
    d1 = abs(x1 - a1)
    d2 = abs(x1 - a2)
    d3 = abs(x2 - a1)
    d4 = abs(x2 - a2)
    ds = [d1, d2, d3, d4]
    dmax = max(ds)
    if dmax == d1:
        i += 1
        x1 = a1
        result += d1
    elif dmax == d2:
        j -= 1
        x1 = a2
        result += d2
    elif dmax == d3:
        i += 1
        x2 = a1
        result += d3
    else:
        j -= 1
        x2 = a2
        result += d4

print(result)


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

int main() {
    int n;
    cin>>n;
    int mao[n];
    for(int i=0; i<n; i++) cin>>mao[i];

    int ans = 1;
    int min = mao[0];

    for(int i=1; i<n; i++) {
        if(mao[i]<=min) {
            ans++;
            min=mao[i];
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e6+5;
int a[maxn],b[maxn];
void down(int all,int times)
{
    if(times==0)
    {
        for(int i=1;i<all;i++)
            a[i]=abs(a[i]-a[i+1]);
        return;
    }
    int val=(1<<times);
    int one=0;
    for(int i=0;i<=val;i++)
        one+=(a[i]==1);
    for(int i=1;i+val<=all;i++)
    {
        int x=a[i],z=a[i+val];
        one-=(a[i-1]==1);
        one+=(a[i+val]==1);
        if(abs(x-z)!=2)
            b[i]=abs(x-z);
        else
            b[i]=(one?0:2);
    }
    for(int i=1;i<=all-val;i++)
        a[i]=b[i];
    return;
}
int main()
{
    int n;
    scanf("%d",&n);
    char c;
    scanf("%c",&c);
    for(int i=1;i<=n;i++)
    {
        scanf("%c",&c);
        a[i]=c-'0';
    }
    for(int i=1;i<=n-1;i++)
        a[i]=abs(a[i]-a[i+1]);
    n--;
    int tot=n,times=n-1;
    for(int lg=0;lg<=log2(times);lg++)
        if(times&(1<<lg))
        {
            down(tot,lg);
            tot-=(1<<lg);
        }
    int ans=a[1];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const ll INF = 1LL << 60;
#define mst(x) memset(x, 0, sizeof(x))
ll n, p;
ll pr[maxx]; //p的所有因子
map <ll, bool> vis;
ll ans;

int main() {
	vis.clear();
	cin >> n >> p;
	if(n == 1) {
		cout << p << endl;
		return 0;
	}
	int tot = 0;
	for(int i = 1; i <= sqrt(p); i++) {
		if(p % i == 0) pr[++tot] = i;
	}
	int dd;
	double tmp = sqrt(p);
	if(tmp == (int)tmp) dd = tot - 1;
	else dd = tot;
	for(int i = 1; i <= dd; i++) pr[++tot] = p / pr[i];
	sort(pr + 1, pr + tot + 1);

	/* 如果除1以外的最小因子的n次幂都比p大, 那gcd必为1 */
	if(tot > 1) {
		ll f = pr[2]; //除1以外的最小因子
		ll m = 1;
		while(f * pr[2] <= p) {
			f *= pr[2];
			m++;
		}
		if(m < n) {
			puts("1");
			return 0;
		}
	}

	for(int i = 1; i <= tot; i++) vis[pr[i]] = 1;
	bool chk = 0;
	for(int i = tot; i >= 2; i--) {
		ll pp = pr[i];
		ll cnt = 1;
		bool flg = 0;
		while(pp * pr[i] <= p) {
			pp *= pr[i];
			cnt++;
			if(cnt == n) {
				flg = 1;
				break;
			}
		}
		if(flg && vis[pp]) {
			chk = 1;
			ans = pr[i];
			break;
		}
	}
	if(!chk) puts("1");
	else cout << ans << endl;
}

Measured memory_bytes: 256
main=do
 n<-readLn
 a<-map read.words<$>getLine
 print(g (n-1) 1 (abs((sum (tail a))-(head a))) (head a) (sum(tail a)) (tail a))
  where g n i f s b a | n==i      = f
                      | otherwise = g n (i+1) (min f (abs ((s+(head a))-(b-(head a))))) (s+(head a)) (b-(head a)) (tail a)

Measured memory_bytes: 65916
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
mod = 10**9+7
import math
s = I()
t = 0
ans = 0
for i in range(1,s+1):##iは数列の項の数
  if s - 3*i <0:
    continue
  else:
    t = s-3*i
    #玉の数がt個、仕切りの数がi-1個
    ans += math.factorial(i+t-1)//(math.factorial(t)*math.factorial(i-1))
    ans = ans%mod
print(ans)

Measured memory_bytes: 9120
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;


int main() {
	int ans=1000,k;
	string s;
	cin >> s;

	for (int i = 0; i < s.size() - 2;i++) {
		k = (s[i]-'0') * 100 + (s[i + 1]-'0') * 10 + (s[i+2]-'0');
		if (abs(k-753)<ans) {
			ans = abs(k - 753);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#define ll long long
         
using namespace std;
     
long long gcd(int x, int y){
     if ( x == 0 ) return y;
     
     return gcd(y%x, x);
}
     
long long lcm(int x, int y){
     if ( y == 0 ){
          return x;
     }
     
     return x*y/gcd(x, y);
}
     
ll min(ll a, ll b){
     return a > b ? b : a;
}
     
ll max(ll a, ll b){
     return a > b ? a : b;
}

int main()
{
     cin.sync_with_stdio( false );
     
     int n,m;
     cin>>n>>m;
     
     priority_queue <ll, vector <ll>, greater<ll> > q;
     map <ll, ll> rep;
     vector <pair<ll ,ll> > arr(m);
     
     for (int i=0;i<n;i++){
         ll qq;
         cin>>qq;
         
         q.push(qq);
         rep[qq]++;
     }
     
     for (int i=0;i<m;i++){
         //ll a,b;
         //cin>>a>>b;
         cin>>arr[i].second>>arr[i].first;
         
         //arr.push_back({b, a});
     }
     
     sort(arr.begin(), arr.end());
     reverse(arr.begin(), arr.end());
     
     for (int i=0;i<m;i++){
         ll a = arr[i].second;
         ll b = arr[i].first;
         while ( a > 0 ){
             ll qq = q.top();
             //q.pop();
             if ( qq >= b ){
                 break;
             }else{
                 ll smanji = min(rep[qq], a);
                 rep[qq]-=smanji;
                 rep[b]+=smanji;
                 a-=smanji;
                 q.push(b);
                 
                 if ( rep[qq] == 0 ){
                     q.pop();
                     rep.erase(qq);
                 }
             }
         }
     }
     
     ll res = 0;
     for (auto i:rep){
         res+=i.first*i.second;
     }
     
     cout<<res<<endl;
}

Measured memory_bytes: 11892
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  double y=sqrt(N);
  int z=floor(y);
  cout<<z*z<<endl;
}
  


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

using namespace std;

int main(){
  int A,B,C,count=0;
  cin >> A >> B >> C;
  
  if(A*C<B)
    cout << C;
  
  else{
    while(B>=A){
      B=B-A;
      count++;
    }
    cout << count;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char A[11],B[11],C[11];
    int i,a=-1,b=-1;
    
    scanf("%s %s %s", A,B,C);
    
    for(i=0;i<12;i++){
        if(A[i]=='\0' && a==-1) a=i-1;
        if(B[i]=='\0' && b==-1) b=i-1;
    }
    
    
    if(A[a]==B[0] && B[b]==C[0]){
        printf("YES\n");
    }
    else printf("NO\n");
    
    return 0;
}

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

#define int long long

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

signed main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for (int i = K + 1; i <= N; i++) {
        ans += N / i * (i - K);
        ans += max(0LL, N % i - K + 1);
    }
    if (K == 0) {
        ans -= N;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

void b_abc111(void) {
	int n;
	cin >> n;

	int sho = n / 111;
	int amari = n % 111;

	if(amari!=0){
		sho++;
	}

	cout << 111 * sho << endl;
}

int main()
{
    b_abc111();
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
using namespace std;
int n;
int a[3][100010];
int mem[100010];
vector<int> v;
int main()
{
    int i,a,rez=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    //memset(mem,-1,100010);
    mem[n - 1] = 0;
    for(i=n-2;i>=0;i--) {
        mem[i] =numeric_limits<int>::max();
        for(int j = 1; j <= 2; j ++)
            if (i + j < n)
                mem[i] = min(mem[i], mem[i + j] + abs(v[i] - v[i + j]));
    }
    int n_rez=0;

    cout<<mem[0];
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	unordered_map <string , int> mp;
	for(int i = 0 ; i < n ; i++){
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << "AC" << " x " << mp["AC"] << endl;
	cout << "WA" << " x " << mp["WA"] << endl;
	cout << "TLE" << " x " << mp["TLE"] << endl;
	cout << "RE" << " x " << mp["RE"] << endl;
	return 0;
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    int c = 0;
    for(auto moji : s)
    {
        if(moji == 'a') a++;
        if(moji == 'b') b++;
        if(moji == 'c') c++;
    }
    if(abs(a-b) < 2 && abs(b-c) < 2 && abs(c-a) < 2) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 3776
#include <iostream>
using namespace std;
int main(){
   string s;
   cin>>s;
    while(s[0]!='0'){
        int sum=0;
        for(int i=0; i<s.size(); i++){
            sum += s[i]-'0';
        }
        cout<<sum<<endl;
        cin>>s;
    }
    
}


Measured memory_bytes: 3208
#include <stdio.h>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, i, j;
    cin >> n;
    
    vvi a(n, vi(n-1));
    vi b(n);
    
    for (i=0;i<n;i++) for (j=0;j<n-1;j++){
        cin >> a[i][j];
        a[i][j]--;
    }
    
    set<int> st;
    
    for (i=0;i<n;i++){
        if (i == a[a[i][0]][0] && i < a[i][0]){
            st.insert(i);
        }
    }
    int res = 0;
    while (b!=vi(n, n-1)){
        if (st.empty()){
            res = -1;
            break;
        }
        set <int> _st = st;
        for (auto i: st){
            _st.insert(a[i][b[i]]);
            b[a[i][b[i]]]++;
            b[i]++;
        }
        st = _st;
        _st.clear();
        for (auto i:st){
            if (b[i] < n-1){
                int j = a[i][b[i]];
                if(b[j]<n-1 && a[j][b[j]]==i){
                    _st.insert(min(i, j));
                }
            }
        }
        st = _st;
        res++;
        
    }
    
    cout << res << endl;
    
}




Measured memory_bytes: 4352
def combination(n, r, mod):
    numerator, denominator = 1, 1
    for _ in range(r):
        numerator = numerator * n % mod
        denominator = denominator * r % mod
        n -= 1
        r -= 1
    return numerator * pow(denominator, mod - 2, mod) % mod


x, y = map(int, input().split())
if (x + y) % 3 != 0:
    answer = 0
    print(answer)
    exit()

m, n = (2 * x - y) // 3, (2 * y - x) // 3
if m < 0 or n < 0:
    answer = 0
    print(answer)
    exit()

mod = 10**9 + 7
answer = combination(m + n, m, mod)
print(answer)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main(void)
{
	int i, j;
	//  dic_t dic[200000];
	int ii[100];
	int ilen[100];
	int min, max;
	int len, flg;
	int cnt, maxcnt;
char aa[6+2];
  scanf("%s", aa);
	if(aa[2] ==aa[3] && aa[4]==aa[5]){
	printf("Yes\n");
	return 0;
    }
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int X=in(),A=in();
	cout << (X<A ? 0 : 10) << endl;
	return 0;
}


Measured memory_bytes: 256
S = input()
num = list(S)

for i in range(2**3) :
    pat = str(format(i, '03b'))
    ans = int(num[0])
    op = ["0", "0", "0"]
    for j in range(3) :
        if pat[j] == "1" :
            ans += int(num[j+1])
            op[j] = "+"
        else :
            ans -= int(num[j+1])
            op[j] = "-"
    if ans == 7 :
        print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3]))
        exit()


Measured memory_bytes: 3064
from collections import deque

N = int(input())

Graph = {}
Node = []
visited = [-1]*(N)

for i in range(N):
    tmp = input().split()
    if int(tmp[1]) != 0:
        Graph[i] = [int(x)-1 for x in tmp[2:]]
    else:
        Graph[i] = []

queue = deque([0])
visited[0] = 0
while queue:
    x = queue.popleft()
    for i in Graph[x]:
        if visited[i] == -1:
            visited[i] = visited[x] + 1
            queue.append(i)

for i,j in enumerate(visited, 1):
    print(i, j)


Measured memory_bytes: 6032
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,d,res=0;
    cin>>n>>d;
    ll arr[n][d];
    for(ll i=0;i<n;i++)
    for(ll j=0;j<d;j++)
    cin>>arr[i][j];
    for(ll i=0;i<n;i++)
    for(ll j=i+1;j<n;j++){
        ld sum=0;
        for(ll k=0;k<d;k++)
        sum+=pow(arr[i][k]-arr[j][k],2);
        sum=sqrt(sum);
        if(sum==ll(sum))
        res++;
    }
    cout<<res;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000*1000*1000+7
#define mem(dp,a) memset(dp,a,sizeof dp)
int h,n;
int ar[1010][2];
int rval=0;
int dp[110100];
int32_t main()
{
    cin>>h>>n;
    int maxi=0;
    for(int i=0;i<n;i++)
    {
        cin>>ar[i][0]>>ar[i][1];
        maxi=max(maxi,ar[i][0]);
    }
    for(int i=0;i<=1e5+10000;i++)
        dp[i]=1e15;
    dp[0]=0;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<n;j++)
        {
            dp[i+ar[j][0]]=min(dp[i+ar[j][0]],dp[i]+ar[j][1]);
        }
    }
    int ans=1e15;
    for(int i=h;i<=h+maxi;i++)
        ans=min(ans,dp[i]);
    cout<<ans<<"\n";
    return 0;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int>num(n);
  for(int i=0;i<n;i++) num[i]=0;
  for(int i=0;i<n;i++) num[a[i]-1]++;
  sort(num.begin(),num.end());
  int ans=n;
  for(int i=0;i<k;i++) ans-=num[n-1-i];
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rank=[0]*(n+1)
  def FindRoot(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.FindRoot(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.FindRoot(x)
    y=self.FindRoot(y)
    if x==y:
      return
    else:
      if self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      elif self.rank[x]<=self.rank[y]:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
  def isSameGroup(self,x,y):
    return self.FindRoot(x)==self.FindRoot(y)
  def Count(self,x):
    return -self.root[self.FindRoot(x)]

n,m=map(int,input().split())
arr=list(map(int,input().split()))
t=UnionFind(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  t.Unite(a,b)
ans=0
for i in range(n):
  if arr[i]==(i+1):
    ans+=1
  else:
    if t.isSameGroup((i+1),arr[i]):
      ans+=1
print(ans)

Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;

#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 55 + 10;
const ll LINF = LLONG_MAX;
int n,m;
char ch[N][N];
int visit[N][N],dist[N][N];
int dx[4]={-1,+1,0,0};
int dy[4]={0,0,+1,-1};
int bfs(int x,int y){
    memset(visit,0,sizeof(visit));
    queue<pa>q;
    q.push({x,y});
    visit[x][y]=1;
    dist[x][y]=0;
    int mx=0;
    while(!q.empty()){
        int x=q.front().F;
        int y=q.front().S;
        q.pop();
        f(i,0,4){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<1 or ny<1 or nx>n or ny>m or ch[nx][ny]=='#')
                continue;
            if(!visit[nx][ny]){
                dist[nx][ny]=dist[x][y]+1;
                mx=max(mx,dist[nx][ny]);
                visit[nx][ny]=1;
                q.push({nx,ny});
            }
        }

    }
    return mx;
}
int32_t main() {
    fast();
    cin >> n >> m;
    f(i,1,n+1){
        f(j,1,m+1){
            cin >> ch[i][j];
        }
    }
    int ans=0;
    f(i,1,n+1){
        f(j,1,m+1){
            if(ch[i][j]=='.'){
                ans=max(ans,bfs(i,j));
            }
        }
    }
    cout<<ans;
   
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;

vi v;
int root(int n)
{
    if(v[n] == n) return n;
    return v[n] = root(v[n]);
}

void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    v[rx] = ry;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, M; cin >> N >> M;
    v.resize(N); REP(i, N) v[i] = i;
    vi X(M), Y(M), Z(M);
    REP(i, M)
    {
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--; Y[i]--;
        unite(X[i], Y[i]);
    }
    vb t(N, false);
    REP(i, N) t[root(v[i])] = true;
    int ans = 0;
    REP(i, N) if(t[i]) ans++;
    cout << ans << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int dist = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x < K / 2.0) {
      dist += 2 * x;
    }
    else {
      dist += 2 * (K - x);
    }
  }
  cout << dist << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    int A, B, C, D, E, F;
    std::cin >> A >> B >> C >> D >> E >> F;

    double percent = double(E) / double(100 + E); 
    int water, sugar;
    int ans1, ans2;
    double max = 0.0;
    for (int i = 0; i <= F; i += 100*A) {
        for (int j = 0; j <= F; j += 100*B) {
            for (int k = 0; k <= F - (i+j); k += C) {
                for (int l = 0; l <= F - (i+j+k); l += D) {
                    if (i == 0 && j == 0) {
                        break;
                    }
                    water = i+j+k+l;
                    sugar = k+l;
                    double conc = double(sugar) / double(water);
                    if (conc <= percent) {
                        if (max <= conc) {
                            max = conc;
                            ans1 = water;
                            ans2 = sugar;
                        }
                    }
                }
            }
        }
    }

    std::cout << ans1 << " " << ans2 << std::endl;

    return 0;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 500005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long

#define mod  1000000007



int main()
{
	FAST;
	int d, t, s;
	cin >> d >> t >> s;
	int x = d /s;
	if(d % s){
		x ++;
	}
	
	if(x <= t){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3688
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            HashSet<Integer> set = new HashSet<Integer>();
            for (int i = 0; i < K; i++) {
                int d = sc.nextInt();
                for (int j = 0; j < d; j++) {
                    set.add(sc.nextInt());
                }
            }
            System.out.println(N - set.size());
        }
    }
}


Measured memory_bytes: 37664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	ll x; cin >> x;
	ll ans = x / 11 * 2; x %= 11;
	if(x) ans += x <= 6 ? 1 : 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

def check(s):
    if len(s)%2==1:
        return False
    else:
        l = len(s)//2
        if s[:l]==s[l:]:
            return True
        else:
            return False


s = str(input())

for i in reversed(range(1,len(s))):
    # print(s[:i])
    if check(s[:i]):
        print(len(s[:i]))
        exit()


Measured memory_bytes: 6352
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[50000];
int dp[50000][3];
int main(){
	int a;scanf("%d",&a);
	while(a--){
		int n;scanf("%d",&n);scanf("%s",str);
		for(int i=0;i<50000;i++)for(int j=0;j<3;j++)dp[i][j]=999999999;
		dp[0][0]=0;
		for(int i=0;i<=n;i++){
			bool L=(i<n&&str[i*2]=='Y')||(i&&str[i*2-1]=='Y');
			bool R=(i<n&&str[2*n+i*2]=='Y')||(i&&str[2*n+i*2-1]=='Y');
	//		printf("%d %d\n",L,R);
			dp[i+1][0]=min(dp[i+1][0],1+dp[i][0]+(R?3:(L?1:0)));
			dp[i+1][1]=min(dp[i+1][1],1+dp[i][0]+1+(R?1:0));
			dp[i+1][2]=min(dp[i+1][2],1+dp[i][0]+2);
			dp[i+1][0]=min(dp[i+1][0],1+dp[i][1]+1+(R?1:0));
			dp[i+1][1]=min(dp[i+1][1],1+dp[i][1]+(R?1:0)+(L?1:0));
			dp[i+1][2]=min(dp[i+1][2],1+dp[i][1]+1+(L?1:0));
			dp[i+1][0]=min(dp[i+1][0],1+dp[i][2]+2);
			dp[i+1][1]=min(dp[i+1][1],1+dp[i][2]+1+(L?1:0));
			dp[i+1][2]=min(dp[i+1][2],1+dp[i][2]+(L?3:(R?1:0)));
		}
		
		printf("%d\n",dp[n+1][0]-1);
	}
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
uli a[mx],b[mx],r[mx];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lld %lld",a+i,b+i);
    r[i]=b[i]*((a[i]+b[i]-1)/b[i])-a[i];
  }
  uli suf=r[n-1];
  for(int i=n-2;i>=0;i--){
    //    r[i]-suf+k*b[i]>=0
    uli k=0;
    if(r[i]-suf<0){
      k=((suf-r[i])+b[i]-1)/b[i];
    }
    suf=r[i]+k*b[i];
  }
  printf("%lld\n",suf);
  return 0;
}


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


int main() {
  int a,b,c;
  cin >> a >> b >>c;
  int d = (a + (b-1)) / b;
  cout << d*c;
}

Measured memory_bytes: 3616