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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define f first
#define s second

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll N, C; 

ll solve(vector<pair<ll, ll>> arr) {
	stack<pair<ll, ll>> mem;
	ll total = 0;
	ll dist = 0;
	mem.push({-1, 0});

	F0R(i, N) {
		total += arr[i].f - (arr[i].s - dist);
		dist = arr[i].s;
		if (total > mem.top().s) {
			mem.push({i, total});
		}
	}

	ll best = mem.top().s;

	total = 0;
	dist = 0;
	R0F(i, N) {
		total += arr[i].f - ((C - arr[i].s) - dist);
		dist = (C - arr[i].s);
		while (!mem.empty() && mem.top().f >= i) mem.pop();

		if (!mem.empty()) {
			// print(i, arr[i].s, total, mem.top(), dist, total + max(mem.top().s - dist, 0LL));
			best = max(best, total + max(mem.top().s - dist, 0LL));
		} else {
			// print(i, arr[i].s, total, "N");
			best = max(best, total);
		}
	}
	return best;
}

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

	cin >> N >> C;
	vector<pair<ll, ll>> arr;
	F0R(i, N) {
		ll a, b; cin >> a >> b;
		arr.push_back(make_pair(b, a));
	}

	ll best = solve(arr);	

	F0R(i, N) arr[i].s = C - arr[i].s;

	reverse(arr.begin(), arr.end());

	best = max(best, solve(arr));
	print(best);
}

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

using namespace std;
typedef long long int lli;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

void dfs(int v, vector<bool> &used, vector<vector<int>> &g, int &sz)
{	
    if(!used[v]) sz++;
    used[v] = true;
    
    for (size_t i = 0; i < g[v].size(); ++i)
    {
        int to = g[v][i];
        if (!used[to])
            dfs(to, used, g, sz);
    }
}

int main()
{
    fast;
    int t = 1;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        vector<vector<int>> adj(n);
        for (int i = 0; i < m; i++)
        {
            lli x, y;
            cin >> x >> y;
            adj[x - 1].push_back(y - 1);
            adj[y - 1].push_back(x - 1);
            
        }
        vector<bool> vis(n);
        int ans = 1;
        for (int i = 0; i < n; i++)
        {
            if (!vis[i])
            {
                int sz = 0;
                dfs(i, vis, adj, sz);
                ans = max(sz, ans);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 26636
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) throws Exception{
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    new Solution(n);
  }
}

class Solution {
  public Solution(int n) {
    long res = 0;
    for(int i = 1; i <= n; ++i) {
      if(i % 3 != 0 && i % 5 != 0) {
        res += i;
      }
    }
    System.out.println(res);
  }
}

class FastScanner {
  private final InputStream in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  public FastScanner(InputStream source) {
    in = source;
  }

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) return buffer[ptr++];
    else return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext()) throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 25748
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,k;
double a[N],ans,sum;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]=(a[i]+1)/2.0;
		if(i<=k)
			sum+=a[i];
	}
	ans=sum;
	for(int i=k+1;i<=n;i++)
	{
		sum=sum+a[i]-a[i-k];
		ans=max(ans,sum);
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int getint()
{
	int i=0,f=1;char c;
	for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar());
	if(c=='-')f=-1,c=getchar();
	for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
	return i*f;
}
const int N=2005,mod=1e9+7;
int n,k,m;
ll f[N][N],fac[N*N],invfac[N*N];
ll Pow(ll x,int y)
{
	ll res=1;
	for(;y;y>>=1,x=x*x%mod)
		if(y&1)res=res*x%mod;
	return res;
}
ll C(int x,int y)
{
	if(x<y||x<0||y<0)return 0;
	return fac[x]*invfac[y]%mod*invfac[x-y]%mod;
}
int main()
{
	//freopen("lx.in","r",stdin);
	n=getint(),k=getint(),m=n*k;
	if(k==1){puts("1");return 0;}
	fac[0]=1;for(int i=1;i<=m;i++)fac[i]=fac[i-1]*i%mod;
	invfac[m]=Pow(fac[m],mod-2);
	for(int i=m-1;i>=0;i--)invfac[i]=invfac[i+1]*(i+1)%mod;
	f[0][0]=1;--k;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++)if(f[i][j])
		{
			f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
			f[i][j+1]=(f[i][j+1]+f[i][j]*C(i+j*k+k-1,k-1))%mod;
		}
	cout<<f[n][n]*fac[n]%mod<<'\n';
	return 0;
}

Measured memory_bytes: 94464
read;tr \  \\n|nl|awk 1,\$1%=2|sort|uniq -c|sort -nr|awk 's+=$1{$2?a?b||b=$1:(a=$1)>c=$3:d?e||e=$1:(d=$1)>f=$3}END{print s-(c~f?a+e<b+d?b+d:a+e:a+d)}'

Measured memory_bytes: 11844
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String l = br.readLine();
		int c = 0;
		for(int i = 0; i < 6; i++) {
			if(l.charAt(i) == '1') {
				c++;
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 20692
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<long long >A(N);
  int zerocount=0;
  for (int i=0; i<N; i++){
    scanf("%lld", &A[i]);
    if (A[i]==0) zerocount++;
  }
  if (zerocount>0){
    printf("0\n");
  } else {
    long long ans=1;
    for (int i=0; i<N; i++){
      if (A[i]>(long long)1e18/ans){
	printf("-1\n");
	return 0;
      }
      ans *= A[i];
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3668
d[150][120];j,s,t,m,n,*p;main(i){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",s)){for(memset(d,9,7e4);t=m--;d[i][j]=d[j][i]=s/100)scanf("%d,%d,%d",&i,&j,&s);for(s=i=1-n;i++;s+=d[t=m][n])for(d[t][j=m=n]=0;j--;*p&&d[m][n]>*p?m=j:0)p=d[j]+n,*p=fmin(*p,p[t-n]);}}

Measured memory_bytes: 0
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    if(X>=30)prt("Yes");
    else prt("No");

    return 0;
}



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

int main() {
    init();

    int n; cin >> n;
    string s; cin >> s;
    int ans = 0, now = 0;
    each(c, s) {
        if (c == 'I')++now;
        else --now;
        chmax(ans, now);
    }
    cout << ans << "\n";
}

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

using namespace std;

int main(){
    int N; 
    cin >> N;
    vector<int> L(N);
    for(int i=0; i<N; i++){
        cin >> L[i];
    }

    sort(L.rbegin(),L.rend());
    int sum=0;
    for(int i=1; i<N; i++){
        sum += L[i];
    }

    if(L[0]<sum) cout <<"Yes" << endl;
    else cout <<"No" <<endl;
    
}

Measured memory_bytes: 3580
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct Node{
  int p;
  int l;
  int r;
}Node;

Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  c=T[u].l;
 
  for(i=0;c!=NIL;i++){

    if(i>0)printf(", ");
    printf("%d",c);
     c=T[c].r;
 }
  printf("]\n");
  
}

int depth(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL)depth(T[u].r,p);
  if(T[u].l!=NIL)depth(T[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }

  depth(r,0);

  for(i=0;i<n;i++)print(i);

  return 0;
}



Measured memory_bytes: 6392
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int V, E, S, G1, G2, B1, B2, C;

vector<vector<int> > G;

vector<vector<int> > R;

inline void Shortest(int s, int mode, int rev)
{
	vector<bool> u(V, false);
	
	R[mode][s] = 0;

	while (true)
	{
		int v = -1, c = 99999999;

		for (int i = 0; i < V; i++)
		{
			if (!u[i] && R[mode][i] < c)
			{
				c = R[mode][i]; v = i;
			}
		}

		if (c == 99999999) { break; }

		u[v] = true;

		for (int i = 0; i < V; i++)
		{
			if (!u[i])
			{
				if (R[mode][i] > R[mode][v] + (rev ? G[i][v] : G[v][i]))
				{
					R[mode][i] = R[mode][v] + (rev ? G[i][v] : G[v][i]);
				}
			}
		}
	}
}

int main()
{
	while (true)
	{
		scanf("%d", &V);
		scanf("%d", &E);
		scanf("%d", &S);
		scanf("%d", &G1);
		scanf("%d", &G2);

		if (V == 0) { break; }

		G = vector<vector<int> >(V, vector<int>(V, 99999999));

		for (int i = 0; i < E; i++)
		{
			scanf("%d", &B1);
			scanf("%d", &B2);
			scanf("%d", &C);

			G[B1 - 1][B2 - 1] = C;
		}
		
		R = vector<vector<int> >(3, vector<int>(V, 99999999));

		Shortest(S - 1, 0, 0);
		Shortest(G1 - 1, 1, 1);
		Shortest(G2 - 1, 2, 1);

		int ret = 299999997;

		for (int i = 0; i < V; i++)
		{
			ret = min(ret, R[0][i] + R[1][i] + R[2][i]);
		}

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

	return 0;
}

Measured memory_bytes: 3268
n=int(input())
if n==0:
    print(0)
    exit()
ans=''
i=1
k=n
while k!=0:
    if k%(2**i)!=0:
        ans='1'+ans
        k-=(-2)**(i-1)
    else:
        ans='0'+ans
    i+=1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N, M;
  while(cin >> N >> M, N) {
    vector<vector<pll>> E(N);
    REP(i, 0, M) {
      ll t, s, d;
      cin >> t >> s >> d;
      s--;
      d--;
      E[s].push_back(pll(t, d));
    }

    vector<bool> used(N, false);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push(pll(0, 0));
    while(q.size()) {
      ll v = q.top().second, t = q.top().first;
      q.pop();

      if(used[v]) continue;
      used[v] = true;

      for(pll p : E[v]) {
        ll nv = p.second, nt = p.first;
        if(nt >= t) {
          q.push(pll(nt, nv));
        }
      }
    }

    ll ans = 0;
    REP(i, 0, N) if(used[i]) ans++;
    cout << ans << endl;
  }
}



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

struct DICE {
	int top;
	int N;
	int S;
	int E;
	int W;
	int bottom;
};

struct DICE d = { 1,5,2,3,4,6 };

void North() {
	int buf;
	buf = d.top;
	d.top = d.S;
	d.S = d.bottom;
	d.bottom = d.N;
	d.N = buf;
}

void East() {
	int buf;
	buf = d.top;
	d.top = d.W;
	d.W = d.bottom;
	d.bottom = d.E;
	d.E = buf;
}

void West() {
	int buf;
	buf = d.top;
	d.top = d.E;
	d.E = d.bottom;
	d.bottom = d.W;
	d.W = buf;
}

void South() {
	int buf = d.top;
	d.top = d.N;
	d.N = d.bottom;
	d.bottom = d.S;
	d.S = buf;
}

void Right() {
	int buf = d.S;
	d.S = d.E;
	d.E = d.N;
	d.N = d.W;
	d.W = buf;
}

void Left() {
	int buf = d.S;
	d.S = d.W;
	d.W = d.N;
	d.N = d.E;
	d.E = buf;
}


int main() {
	int N, ans;
	char inpStr[30];
	
	while (1) {
		fgets(inpStr, 10, stdin);
		N = atoi(inpStr);
		if (!N)break;
		ans = 1;
		d.top = 1; d.N = 5; d.S = 2; d.E = 3; d.W = 4; d.bottom = 6;
		for (int i = 0; i < N; i++) {
			fgets(inpStr, 10, stdin);
			if (inpStr[0] == 'N')North();
			else if (inpStr[0] == 'E')East();
			else if (inpStr[0] == 'W')West();
			else if (inpStr[0] == 'S')South();
			else if (inpStr[0] == 'R')Right();
			else if (inpStr[0] == 'L')Left();
			ans += d.top;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2032
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def solve(input: String): String = {
    val s: Scanner = new Scanner(input)
    val n = s.nextInt
    val a1 = List.fill(n)(s.nextInt)
    val a2 = List.fill(n)(s.nextInt)
    (1 to n).toList.map(i => a1.take(i).sum + a2.drop(i - 1).sum).max.toString
  }

  val tests = List(
    """5
      |3 2 2 4 1
      |1 2 2 2 1""".stripMargin -> """14""",
    """4
      |1 1 1 1
      |1 1 1 1""".stripMargin -> """5""",
    """7
      |3 3 4 5 4 5 3
      |5 3 4 4 2 3 2""".stripMargin -> """29""",
    """1
      |2
      |3""".stripMargin-> """5"""
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}

Measured memory_bytes: 27320
from collections import deque
def main():
    n = int(input())
    a = []
    b = []
    c = []
    lst = [[] for _ in range(n)]

    for i in range(n - 1):
        aa, bb, cc = map(int,input().split())
        lst[aa - 1].append((bb - 1, cc))
        lst[bb - 1].append((aa - 1, cc))

    q, k = map(int,input().split())
    x = []
    y = []
    for i in range(q):
        xx, yy = map(int,input().split())
        x.append(xx - 1)
        y.append(yy - 1)
    qq = deque()
    qq.append(k - 1)
    dist = [0] * n
    while len(qq) != 0:
        now = qq.popleft()
        for to, w in lst[now]:
            if dist[to] != 0:
                continue
            dist[to] = dist[now] + w
            qq.append(to)

    for i in range(q):
        print(dist[x[i]] + dist[y[i]])





if __name__ == '__main__':
    main()


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

int main()
{
	vector<int> N(3);
	for(int i(0);i<3;++i) cin >> N[i];
	sort(N.begin(), N.end());
	cout << N[2] * 10 + N[1] + N[0] << endl;
	return 0;
}

Measured memory_bytes: 256
/*Author : Krishna*/
#include<iostream>
#include<unordered_map>
#include<queue>
#include<vector>
#include <cmath>
#include <stack>
#include<string>
#include<sstream>
#include <unordered_set>
#include <algorithm>
#define ll long long
#define MOD 1000000007
using namespace std;

void solve()
{
   
    
}

int main()
{
    int n;
       cin>>n;
       for(int i=0;i<n;i++)
       {
           cout<<"ACL";
       }
}


/*
*Check for the edge cases(n=1)?
*Is there any another approach?
*check for data types
*Keep on thinking
*/


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

int main() {
  string S;
  cin >> S;
  int lose = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'x') lose++;
  }
  if (lose > 7) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
};


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int n,m,x,a[100],ans1=0,ans2=0;
	cin>>n>>m>>x;
	for (int i=0;i<m;i++) cin>>a[i];
	for (int i=0;i<m;i++){
		if(a[i]>x) ans1+=1;
		if(a[i]<x) ans2+=1;
	}
	if (ans1<=ans2) cout<<ans1<<endl;
	else cout<<ans2;
	return 0;
}


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

int main(){
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0;; i++){
		cout << a[n - 1 - i];
		if (i == n - 1)break;
		cout << ' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3088
N = int(input())
a = [int(i) for i in input().split()]

m = 10 ** 9
c = 0
ans = 0

for x in a:
    m = min(abs(x), m)
    ans += abs(x)
    if x < 0:
        c += 1

if c % 2 == 1:
    ans -= m * 2

print(ans)


Measured memory_bytes: 14412
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 5e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}


 int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
     ld PI = (ld)atan(1)*(ld)4;
        ld a,b,h,m;
        cin >> a >> b >> h >> m;
        ld a1 = h * 30.0 + (m) / 2.0;
        ld a2 = m * 6.0;
     ld ans;
        if(a1 >= a2)
            ans = a1 - a2;
        else
            ans = a2 - a1;
     if(ans > 180.0)
         ans = 360 - ans;
 //    cout << ans;
     ans = (PI) / (180 / ans);
     
  //   ans = (PI) / (ld)ans;
        ld ANS = (a * a + b * b) - (2 * a * b * cos(ans));
    
      ANS = sqrtl(ANS);
     cout << fixed << setprecision(20) << ANS;
     
    }

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

int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  
  int ab = abs(a-b);
  int bc = abs(b-c);
  int ca = abs(c-a);
  
  string ans;
  if(ca<=d or (ab<=d and bc<=d)) ans="Yes";
  else ans = "No";
  cout <<ans<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<double> comd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bucnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

double Dist2(pdd a, pdd b) {
	return (a.fst - b.fst)*(a.fst - b.fst) + (a.scn - b.scn)*(a.scn - b.scn);
}

vector<pdd> getCenter(pdd a, pdd b) {
	vector<pdd> ret;
	pdd c = mp((a.fst + b.fst) / 2.0, (a.scn + b.scn) / 2.0);
	pdd v = mp(a.scn - b.scn, b.fst - a.fst);
	double D = sqrt(v.fst*v.fst + v.scn*v.scn);
	v.fst /= D;	v.scn /= D;
	D = sqrt(1 - Dist2(a, b)/4.0);
	v.fst *= D;	v.scn *= D;
	ret.push_back(mp(c.fst + v.fst, c.scn + v.scn));
	ret.push_back(mp(c.fst - v.fst, c.scn - v.scn));
	return ret;
}

int main() {
	while (true) {
		int n;	cin >> n;
		if (n == 0)	break;
		vector<pdd> p(n,mp(0,0));
		rep(i, n) cin >> p[i].fst >> p[i].scn;
		int ret = 1;
		rep(i, n) {
			rep(j, i) {
				if (Dist2(p[i], p[j]) <= 4.0) {
					vector<pdd> c = getCenter(p[i], p[j]);
					int tmp = 0;
					rep(k, n) {
						if (Dist2(c[0], p[k]) <= 1.0 + eps)	tmp++;
					}
					ret = max(ret, tmp);
					tmp = 0;
					rep(k, n) {
						if (Dist2(c[1], p[k]) <= 1.0 + eps)	tmp++;
					}
					ret = max(ret, tmp);
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define s(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
int vector_finder(std::vector<string> vec, string number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
int main(){
  int N;
  cin >>N;
  vector<string> ss(N); map<string,int> m;
  rep(i,N){
    cin>>ss[i];
    m[ss[i]]++;}
  int ans = 0;
  rep(i,N){
    ans = max(m[ss[i]],ans);
  }
  vector<string>aaa;
  rep(i,N){
    if(m[ss[i]]==ans){
      aaa.push_back(ss[i]);
  }
  }
  sort(s(aaa));
  aaa.erase(unique(aaa.begin(), aaa.end()), aaa.end());
  rep(i,aaa.size()){
    cout<<aaa[i]<<endl;
  }
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
ll a[1000005],num[1000005];
char s[1000005];

int main(){
	n=readint();
	for(int i=1;i<=n;i++) num[i]=num[i/2]+i/2;
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) a[i]=s[i]-'0';
	for(int i=1;i<n;i++) a[i]=abs(a[i]-a[i+1]);
	n--;
	if(n==1) return printf("%d\n",a[1]),0;
	bool fl=0;
	for(int i=1;i<=n;i++) if(a[i]==1) fl=1;
	if(!fl){
		int ans=0;
		for(int i=1;i<=n;i++) if(num[n-1]-num[i-1]-num[n-i]==0) ans^=a[i];
		printf("%d\n",ans);
	}
	else{
		int ans=0;
		for(int i=1;i<=n;i++) if(num[n-1]-num[i-1]-num[n-i]==0) ans^=a[i]&1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 16896
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

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

    cin >> s >> t;

    for(int i = 0; i < n; i++) {
        cout << s[i] << t[i] ;
    }

}


Measured memory_bytes: 256
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		int max = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			int num = a[i];
			max = Math.max(num, max);
			
		}
		int gcd = a[0];
		for(int i = 1; i < n; i++) {
			gcd = gcd(a[i],gcd);
		}
		if(k<=max&&(max-k)%gcd==0) System.out.println("POSSIBLE");
		else System.out.println("IMPOSSIBLE");
	}
	static int gcd(int m, int n) {
        if (m < n)
            return gcd(n, m);
        if (n == 0)
            return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 58920
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;

int n, h[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> h[i];
    for (int i = n - 1; i; --i)
        if (h[i] > h[i + 1]) --h[i];
    cout << (is_sorted(h, h + n) ? "Yes":"No") << '\n';
}

Measured memory_bytes: 640
S = input()
T = input()

ans = float('inf')
for i in range(len(S)):
    string = S[i:i + len(T)]
    if len(string) < len(T):
        continue

    score = len([1 for ch_s, ch_t in zip(string, T) if ch_s != ch_t])
    ans = min(ans, score)
print(ans)

Measured memory_bytes: 9128
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n = input()
    m = input()

    ans = 0

    for i in range(3):
        if n[i] == m[i]:
            ans += 1

    print(ans)
    

if __name__ == '__main__':
    main()

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

using namespace std;

# define ll long long
# define pll pair<ll,ll>
# define F first
# define S second
# define pb push_back
# define ld long double
ll mod=1000000007;
string ans;
ll func1(vector<vector<pll>>&dp,string &s,string &t,int a,int b)
{
    if(a==0||b==0)
    return 0;
    if(dp[a][b].F!=-1)
    return dp[a][b].F;
    if(s[a-1]==t[b-1])
    {
        //ans.pb(s[a-1]);
        dp[a][b].S=1;
        return dp[a][b].F=1+ func1(dp,s,t,a-1,b-1);
    }
    ll x=func1(dp,s,t,a-1,b);
    ll y=func1(dp,s,t,a,b-1);
    if(x>=y)
    {
        dp[a][b].S=2;
        return dp[a][b].F=x;
    }
    dp[a][b].S=0;
    return dp[a][b].F=y;
    
    
}

int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--)
        {
          ll i,j,k,h,w;
          cin>>h>>w;
          char a[h][w];
          ll dp[h][w];
          for(i=0;i<h;i++)
          {
              for(j=0;j<w;j++)
              {
                  cin>>a[i][j];
                  dp[i][j]=0;
              }
          }
          dp[0][0]=1;
          for(i=0;i<h;i++)
          {
              for(j=0;j<w;j++)
              {
                  if(i==0&&j==0)
                  continue;
                  if(a[i][j]!='#'){
                      if(i==0)
                      dp[i][j]=dp[i][j-1];
                      else if(j==0)
                      dp[i][j]=dp[i-1][j];
                      else
                  dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
                  }
              }
                  
          }
          cout<<dp[h-1][w-1];
        }
        
    }

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s; cin >> s;
    ll t = 0;
    for (int bit = 0; bit < (1<<(s.size()-1)); bit++) {
        ll num = 0, left = 0;
        for (int i = 1; i < s.size(); i++) {
            if ((bit>>(i-1)) & 1) {
                ll m = stoll(s.substr(left, i - left));
                num += m;
                left = i;
            }
        }
        ll m = stoll(s.substr(left, s.size()-left));
        num += m;
        t += num;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NIL NULL

struct node{
  int key;
  struct node *parent, *left, *right;
};

typedef struct node *Node;

Node root;

void insert(int); 
void inorder(Node);
void preorder(Node);

int main(){
  int n, k, i;
  char a[6];

  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%s", a);
    if(strcmp(a, "insert") == 0){
      scanf("%d", &k);
      insert(k);
    }
    else if(strcmp(a, "print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else y->right = z;
  }
}


void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

Measured memory_bytes: 24040
#include<bits/stdc++.h>
using namespace std;
int main (){
	int a,b,w,x,y,z=0;
	cin>>w>>a>>b;
	x= min(a,b);
	y=max(a,b);
	z=y-(x+w);
	if (z>0)
	cout<<z<<"\n";
	else 
	cout<<"0\n";
}
	

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main() {
  int N, M;
  bool ans = false;
  string *A, *B;

  cin >> N >> M;
  A = new string[N];
  for (int n = 0; n < N; n++) {
    cin >> A[n];
  }

  B = new string[N];
  for (int m = 0; m < N; m++) {
    cin >> B[m];
  }

  int n = 0, m = 0, left = -1;
  while (n < N && m < M) {
    if (left > -1) {
      if (A[n].substr(left, M) == B[m]) {
        n++; m++;
      }
      else {
        left = -1;
        n = n; m = 0;
      }
      continue;
    }

    left = A[n].find(B[m]);

    // not found
    if (left == -1) {
      n++;
      continue;
    }
    else {
      n++; m++;
    }
  }

  if (left > -1 && m == M) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))

data =[]
for i in range(n):
    tmp_a, tmp_b = list(map(int, input().split()))
    data.append((tmp_a, tmp_b))


total =0
cost = 0
for a, b in sorted(data, key=lambda x:x[0]):
    #print(a, b)
    if total + b < m:
        total += b
        cost += a*b
    else:
        cost += a*(m-total)
        break
print(cost)

Measured memory_bytes: 18888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;
int par[20][100010];
int dep[100010];
ll dst[100010];

vector<pp> edge[100010];

void dfs(int x){
	for(auto t:edge[x]){
		int y, d; tie(y, d) = t;
		if(par[0][x]==y) continue;
		par[0][y]=x;
		dep[y]=dep[x]+1;
		dst[y]=dst[x]+d;
		dfs(y);
	}
}

int lca(int a, int b){
	if(dep[a]<dep[b]) swap(a, b);
	int df = dep[a]-dep[b];
	for(int i=0; i<20; ++i) if(1&(df>>i)) a=par[i][a];
	for(int i=19; 0<=i; --i) if(par[i][a]!=par[i][b]){
		a=par[i][a], b=par[i][b];
	}
	if(a!=b) a=par[0][a];
	return a;
}

ll dist(int a, int b){
	return dst[a]+dst[b]-2*dst[lca(a, b)];
}

int main()
{
	read(n);
	for(int i=1; i<n; ++i){
		int a,b,c; read(a,b,c);
		edge[a].eb(b,c);
		edge[b].eb(a,c);
	}
	dfs(1);
	for(int i=1; i<20; ++i){
		for(int j=1; j<=n; ++j) par[i][j]=par[i-1][par[i-1][j]];
	}
	int q, k;
	read(q, k);
	for(;q--;){
		int x, y; read(x, y);
		printf("%lld\n", dist(x, k) + dist(k, y));
	}
	return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	ll a,b,c;
	cin>>a>>b>>c;
	if(b*c>=a)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <set>

using namespace std;

int main(int argc, char* argv[])
{
    string S; cin >> S;

    set<char> s;
    for (int i = 0; i < S.size(); i++) {
        s.insert(S[i]);
    }

    int i = 0;
    string ans = "None";
    for (auto c : s) {
        if (c != ('a'+i)) {
            ans = 'a'+i;
	    break;
        }
        i++;
    }

    if (i == 'z'-'a') {
      ans = 'z';
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int K;
	cin >> K;
	int ans = K/2;
	ans *= (K+1)/2;
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string st;
int i,bj,bj2;
int main()
{
	cin>>st;
	for(i=0; i<st.size(); i++)
	{
		if(st[i]=='C') bj=1;
		if(st[i]=='F'&&bj==1) bj2=1;
	}
	if(bj==1&&bj2==1) cout<<"Yes"; else cout<<"No";
	return 0;
}

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

int main()
{
	int a,b;
	cin >> a >> b;
	long c = a* b;
	if(c%2 == 0)	puts("Even");
	else puts("Odd");
	return 0;
}

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

int main() {
  int k, x;
  cin >> k >> x;
  if (k*500 >= x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int n,t,m[1000],l[1000],k[1000];

bool check(int x){
  int c[1001]={},used[1000]={},cnt=n;
  for(int i=0;i<t;i++){
    x+=c[i];
    for(int j=0;j<n&&x;j++){
      if(used[j])continue;
      if(i+m[j]>t)return 0;
      if(i%(l[j]+k[j])<=l[j])c[i+m[j]]++,cnt--,used[j]=1,x--;
    }
  }
  return !cnt;
}

int main(){
  while(scanf("%d%d",&n,&t),n){
    for(int i=0;i<n;i++)scanf("%d%d%d",&m[i],&l[i],&k[i]);
    int ans=0;
    for(int i=1;i<=n&&!ans;i++)if(check(i))ans=i;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
  for(int g,d;cin>>g>>d,g|d;){
    vector<char> t[100];
    for(int i=0;i<g;i++){
      bool on=true;
      for(int ti;cin>>ti,ti;){
	vector<char> v(ti,on);
	t[i].insert(end(t[i]),begin(v),end(v));
	on=!on;
      }
    }
    bool inque[100]={};
    queue<int> que;
    int a=0;
    int x[100]={};
    for(int i=0;i<d;i++){
      a+=max<int>(0,que.size()-1);
      for(int j=0;j<g;j++){
	if(!inque[j]){
	  x[j]=(x[j]+1)%t[j].size();
	}
      }
      if(!que.empty()){
	int id=que.front();
	x[id]=(x[id]+1)%t[id].size();
	if(t[id][x[id]]){
	  que.pop();
	  inque[id]=false;
	}
      }
      for(int j=0;j<g;j++){
	if(!inque[j]&&!t[j][x[j]]){
	  que.push(j);
	  inque[j]=true;
	}
      }
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 2572
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    Int H,W;
    cin>>H>>W;

    if(H == 1 || W == 1) {
        cout<<1<<endl;
    } else {
        cout<<(H*W+1)/2<<endl;
    }

    return 0;
}





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

int main(){
  int N;
  cin >> N ;
  
  vector<int> vec(N);
  rep(i, N){
    cin >> vec.at(i);
  }
  
  int tako = 0;
  
  rep(i, N){
    rep(j, N){
      if(i == j){
        continue;
      }
      else{
        tako += vec.at(i) * vec.at(j);
      }
    }
  }
  
  cout << tako / 2 << endl;
}

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

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

    for (int i = 1; i <= n; i++) {
        int t;
        scanf("%d", &t);
        if (t == 1) {one=i;}
    }

    int bef1 = one - 1,
        aft1 = n - one;

    int ret = 0;
    while (bef1 >= k-1) {
        bef1 -= k - 1;
        ret++;
    }

    while (aft1 >= k-1) {
        aft1 -= k - 1;
        ret++;
    }

    int tmp = bef1 + aft1;
    while (tmp > 0) {
        ret++;
        tmp -= k;
    }

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

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch HitachiString | diff HitachiString.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address HitachiString.cpp && ./a.out

/*
 
 3/8/2020
 
 11:15-
 
 */

string S;

bool solve() {
  string hi="hi";
  string hihi;
  REP(i,10) {
    hihi+=hi;
    if(S==hihi) return true;
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  cout<<(solve()?"Yes":"No")<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> pf(1000);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int t=i;
		for(int j=2;j<=t;j++){
			while(t%j==0){
				pf[j]++;
				t/=j;
			}
		}
	}
	const int mod=1e9+7;
	long long ans=1;
	for(int i=1;i<1000;i++){
		ans*=pf[i]+1;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] ary = new int[n];
        int[] ary_cp = new int[n];

        for(int i = 0; i < n; i++){
            ary[i] = stdIn.nextInt();
            ary_cp[i] = ary[i];
        }

        java.util.Arrays.sort(ary_cp);
        
        if(ary_cp[n / 2] == ary_cp[n / 2 - 1])
            for(int i = 0; i < n; i++)
                System.out.println(ary_cp[n / 2]);
        else{
            for(int i = 0; i < n; i++){
                if(ary[i] <= ary_cp[n / 2 - 1])
                    System.out.println(ary_cp[n / 2]);
                else
                    System.out.println(ary_cp[n / 2 - 1]);
            }
        }
    }
}

Measured memory_bytes: 91028
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		p(Math.max(0, a-b-b));
		
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        if (h == 1 || w == 1) {
            System.out.println(1);
        } else {
            System.out.println( (((long) h * w + 1 ) / 2));
        }
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << n / 3;
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if(A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll ans;
    if(x/d > k){
        ans = x - d*k;
    }else{
        ll e = x/d;
        k -= e;
        x -= e*d;
        if(k%2==1) x = abs(x-d);
        ans = x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632