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

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

    vector<vector<int>> graph(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            graph[u - 1][v - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j > 0) {
                cout << " ";
            }
            cout << graph[i][j];
        }
        cout << endl;
    }

}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

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

	for (int i = 0; i < n; ++i)
	{
		if(a[i]%2==0){
			if((a[i]%3==0) || (a[i]%5==0)){
				continue;
			}
			else{
				cout<<"DENIED";
				return 0;	
			}
		}
	}
	cout<<"APPROVED";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

typedef string::const_iterator State;
ll expr(State &begin);
ll fact(State &begin);
ll posi(State &begin);
ll num(State &begin);
string s;
ll t[3];
ll x(ll a,ll b){
    if(a==2||b==2)return 2;
    if(a==0&&b==0)return 0;
    return 1;
}
ll y(ll a,ll b){
    if(a==0||b==0)return 0;
    if(a==2&&b==2)return 2;
    return 1;
}
ll num(State &begin){
    ll res=0;
    if(isdigit(*begin)){
        res=*begin-'0';
        begin++;
    }else{
        res=t[*begin-'P'];
        begin++;
    }
    return res;
}
ll posi(State &begin){
    ll res=0;
    if(*begin=='('){
        begin++;
        res=expr(begin);
        begin++;
    }else{
        res=num(begin);
    }
    return res;
}
ll fact(State &begin){
    ll res=0;
    if(*begin=='-'){
        begin++;
        res=2-fact(begin);
    }else{
        res=posi(begin);
    }
    return res;
}
ll expr(State &begin){
    ll res=fact(begin);
    while(1){
        if(*begin=='+'){
            begin++;
            ll next=fact(begin);
            res=x(res,next);
        }else if(*begin=='*'){
            begin++;
            ll next=fact(begin);
            res=y(res,next);
        }else{
            break;
        }
    }
    return res;
}

bool anspro(){
    ll count=0;
    rep(i,0,26){
        ll k=i;
        rep(j,0,2){
            t[j]=k%3;
            k/=3;
        }
        State begin=s.begin();
        if(expr(begin)==2)count++;
    }
    cout<<count<<endl;
    return 0;
}

int main(){fastio
    while(1){
        cin>>s;
        if(s[0]=='.')break;
        anspro();
    }
    
    return 0;
}



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

int main(void) {
    int N;
    cin>>N;
    bool hit = false;
    for (int i = 1; i <= 9 ; i++) {
        for (int j = 1; j <= 9; j++)
        {
            if (i * j == N) hit = true;
        }
    }
    if (hit) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  int n;
  map<int, int> p;
  int mx=0;
  while(cin>>n){
    mx=max(mx,++p[n]);
  }
  for(auto i:p)
    if(mx==i.second) cout<<i.first<<endl;
  return 0;
}



Measured memory_bytes: 3032
#include<iostream>
#include<string>
using namespace std;
static const int MAX=3000;
int dp[MAX+1][MAX+1];
int main(void){
	string s,t;
		cin >> s >> t;
	int ss=s.size();
	int ts=t.size();
	for(int i=0;i<ss;i++){
		for(int j=0;j<ts;j++){
			if(s[i]==t[j])
				dp[i+1][j+1]=dp[i][j]+1;
			else
				dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
		}
	}
	
	int i=ss;
	int j=ts;
	string ans="";
	while(dp[i][j]>0){
		if(s[i-1]==t[j-1]){
			ans=s[i-1]+ans;
			i--;j--;
		}
		else if(dp[i][j-1]==dp[i-1][j-1])
			i--;
		else
			j--;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(i%2==0 && a%2!=0)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

int main()
{
    string s;
    ll ans;
    cin >> s;
    if(s == "SUN")ans = 7;
    else if(s == "MON")ans = 6;
    else if(s == "TUE")ans = 5;
    else if(s == "WED")ans = 4;
    else if(s == "THU")ans = 3;
    else if(s == "FRI")ans = 2;
    else if(s == "SAT")ans = 1;

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

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

struct edge{int u,v,cost;};

int par[101],rank[101];
edge es[1000];
int V,E;

void init_union_find(int);
int find(int);
void unite(int,int);
bool same(int,int);
bool comp(const edge& e1,const edge& e2);
int kruskal(void);

using namespace std;

int main(void){
  int i,a,b,c;

  while(cin >> V >> E && V){
    for(i=0;i<E;i++){
      cin >> a >> b >> c;
      es[i].u=a;
      es[i].v=b;
      es[i].cost=c;
    }
    printf("%d\n",kruskal());
  }
  return 0;
}

void init_union_find(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

int find(int x){
  if(par[x]==x){
    return x;
}
  else {
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  
  if(rank[x] < rank[y]){
    par[x]=y;
  }
  else {
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

bool comp(const edge& e1,const edge& e2){
  return e1.cost < e2.cost;
}

int kruskal(){
  sort(es,es+E,comp);
  init_union_find(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res+=e.cost;
    }
  }
  return res;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    int sa,sb;
    sa = a.size();
    sb = b.size();
    if(sa>sb){
        cout << "GREATER" << endl;
        return 0;
    }else if(sa <sb){
        cout << "LESS" << endl;
        return 0;
    }else if(sa == sb){
        for(int i=0; i<sa; i++){
            if(a[i] < b[i]){
                cout << "LESS" << endl;
                return 0;
            }else if(a[i] > b[i]){
                cout << "GREATER" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}




Measured memory_bytes: 3628
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, m, x;
    int startMin=10000000,min=startMin, sum=0;
    cin >> n >> m >> x;
    bool ok = true;//理解できたか
    vector<int>c(n);//本の値段
    vector<vector<int>>a(n,vector<int>(m));
    for(int i=0; i<n; i++){
        cin >> c.at(i);
        for(int j=0; j<m; j++){
            cin >> a.at(i).at(j);
        }
    }
    
    for(int bit=0; bit<(1<<n); ++bit){
        sum=0;
        ok = true;
        vector<int>rikai(m);//理解度
        for(int i=0; i<n; i++){
            if(bit&(1<<i)){
                sum += c.at(i);
                for(int j=0; j<m; j++){
                    rikai.at(j) += a.at(i).at(j);
                }
            }
        }
        for(int j=0; j<m; j++){
            if(rikai.at(j)<x)ok=false;
        }
        if(ok)if(sum<min)min=sum;
    }
    if(min==startMin){
        cout << "-1" << endl;
    }else{
        cout << min << endl;   
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int x = scan.nextInt();
		int count = 0;
		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					if (500*i + 100*j + 50*k == x) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		// ABC132-A ok
		static void Main(string[] args)
		{
			string n = Console.ReadLine();
			string str = Console.ReadLine();

			int[] vs = str.Split().Select(p => int.Parse(p)).ToArray();
			int count = 0;
			for (int i = 0; i < vs.Length - 2; i++) {
				int p1 = vs[i], p2 = vs[i + 1], p3 = vs[i + 2];
				if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
					count++;
				}
			}
			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 13268
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	long T1, T2;
	long A1, A2;
	long B1, B2;
	long times = 1;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		T1 = Long.parseLong(tokens[0]);
		T2 = Long.parseLong(tokens[1]);
		tokens = in.readLine().split(" ");
		A1 = Long.parseLong(tokens[0]);
		A2 = Long.parseLong(tokens[1]);
		tokens = in.readLine().split(" ");
		B1 = Long.parseLong(tokens[0]);
		B2 = Long.parseLong(tokens[1]);
	}

	void calc() {
		long diff1 = B1 - A1;
		long diff2 = B2 - A2;
		if ((diff1 * T1 + diff2 * T2) == 0L) {
			times = -1;
		} else if (notMeet(diff1, diff2)) {
			times = 0;
		} else {
			long middlePos = Math.abs(diff1 * T1);
			long cyclePos = Math.abs(diff1 * T1 + diff2 * T2);
			if (middlePos < cyclePos) {
				times = 1;
			} else if (middlePos % cyclePos == 0) {
				times = middlePos / cyclePos * 2;
			} else {
				times = middlePos / cyclePos * 2 + 1;
			}
		}
	}

	boolean notMeet(long diff1, long diff2) {
		if (diff1 * T1 < 0 && (diff1 * T1 + diff2 * T2) < 0) {
			return true;
		} else if (diff1 * T1 > 0 && (diff1 * T1 + diff2 * T2) > 0) {
			return true;
		}
		return false;
	}

	void showResult() {
		if (times < 0) {
			System.out.println("infinity");
		} else {
			System.out.println(times);
		}
	}
}

Measured memory_bytes: 24660
#include<bits/stdc++.h>
#define maxn 100010
#define INF 1000000000
using namespace std;
int h[maxn],n,k,ans=INF;
template<typename T> void Read(T &s){
	s=0;int f=1;char c;
	while((c=getchar())<'0' || c>'9')if(c=='-')f=-1;
	while(c>='0' && c<='9')(s*=10)+=c-'0',c=getchar();
	s*=f;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i){
		Read(h[i]);
	}
	sort(h+1,h+1+n);
	int t;
	for(int i=1;i+k-1<=n;++i){
		t=h[i+k-1]-h[i];
		ans=min(t,ans);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 640
#include <stdio.h>

int main(){
	
	int a,p,total,pie;
	
	scanf("%d %d",&a,&p);
	
	if(a<0){
		printf("error");
	}
	else{
		if(p>100){
			printf("error");
		}
		else{
			total=3*a+p;
			pie=total/2;
			printf("%d",pie);	
            return 0;	
		}
	}	
}
    			

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> Z_algorithm(string S) {
	int c = 0, n = S.size();
	//接頭辞の長さを保存する配列を返す。
	//i = 1からやるとする。
	//Z[1]には赤下線が存在しないので、「溢れるor共通部分がない」のところにまずいく。
	//実装上、上のような挙動をしてもらうため、Z[0]=n;は[1, n - 1]まで計算が終わった後に入れる。
	//cは、赤下線の左端の位置。
	vector<int> Z(n, 0);
	for (int i = 1; i < n; i++) {
		int l = i - c;
		//今着目してる部分が赤下線の左端から何個分離れているかをlに入れる。
		if (i + Z[l] < c + Z[c]) {
			//この条件を満たすのは、「青下線が赤下線に収まる」。
			//この時、すでに計算されてるなのでそれを流用する。
			Z[i] = Z[l];
		} else {
			//この条件を満たすのは、「赤下線から青下線が溢れる」or「赤下線と青下線の共通部分がない」。
			int j = max(0, c + Z[c] - i);
			//c + Z[c] - i > 0の時、これは「溢れる」が該当する。
			//溢れてるのなら、収まる分は計算せずに、溢れた分(j番目から)だけ愚直に突き合わせればよい。
			//そもそも共通部分がないならば、全部突き合わせる。この時、式からj = 0;となるとわかる。

			//愚直に突き合せてる部分
			while (i + j < n && S[j] == S[i + j])j++;			
			Z[i] = j;
			//今の見てるiで、赤下線に完全に含まれなくなったので、今のiを赤下線の左端として、次のiをまた計算する。
			c = i;
		}
	}
	//最後にこれを忘れずに
	Z[0] = n;
	return Z;
}

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i=0; i<n; i++){
    vector<int> res = Z_algorithm(s.substr(i));
    for(int j=1; j<n-i; j++)if(res[j]<=j) ans = max(ans,res[j]);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n;
	int kai[101]={0};
	while(cin>>n){
		kai[n]++;
	}
	
	int max=0;
	for(int i=0; i<101; ++i){
		if(max<kai[i])max=kai[i];
	}
	for(int i=0; i<101; ++i){
		if(max==kai[i])cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
#define int long long
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(x...)
#endif
using namespace std;

int n;

int binpow(int a, int n){
    if(n == 0)
        return 1;
    return (n&1 ? binpow(a, n/2)*binpow(a, n/2)*a : binpow(a, n/2)*binpow(a, n/2));
}

void solve(){
    cin >> n;
    string s = "";
    while(n){
        n--;
        int rem = n%26;
        n /= 26;
        char c = 'a' + rem;
        s += c;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3656
using System;
using System.Linq;

namespace AtCoderBeginnerContest162
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = ReadString();
			if (input.Contains("7"))
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}

		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 25808
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz                size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define F                 first
#define S                 second
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define fin               freopen( "input.txt", "r", stdin );
#define fout              freopen( "output.txt", "w", stdout );
#define deb(x) cout << #x << " " << x << endl
#define inf INT_MAX
const ll N = 200010;
const ll MOD = 998244353;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}

int** gain;

int max_gain(int n){

    int dp[n+1][3];

    for(int i=0;i<3;i++)
        dp[1][i] = gain[0][i];

    for(int i=2;i<=n;i++){
        dp[i][0] = (gain[i-1][0] + max(dp[i-1][1], dp[i-1][2]));
        dp[i][1] = (gain[i-1][1] + max(dp[i-1][0], dp[i-1][2]));
        dp[i][2] = (gain[i-1][2] + max(dp[i-1][0], dp[i-1][1]));
    }

    return max(dp[n][0], max(dp[n][1], dp[n][2]));

}

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

    gain = new int*[n];

    for(int i=0;i<n;i++)
        gain[i] = new int[3];

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

    cout << max_gain(n) << endl;

}

int main(){
    //fin fout
    fast
    ll T = 1; //cin >> T;
    loop(i, 0, T) solve();
    /*#ifdef LOCAL
    clock_t tStart = clock();
    cerr<<fixed<<setprecision(10)<<"\nTime Taken: "<<(double)(clock()- tStart)/CLOCKS_PER_SEC<<endl;
    #endif*/
}


/*339 341 1
342 343 2
342 342 2*/



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

const int maxn=1e5+5;
struct edge{
	int to,next;
}e[maxn];

int head[maxn];
int cnt,ans;

void add(int x,int y)
{
	e[cnt].to=y;
	e[cnt].next=head[x];
	head[x]=cnt;
	cnt++;
}

int ru[maxn],chu[maxn],dp[maxn];
int dfs(int x)
{
	if(chu[x]==0) return 0;
	if(dp[x]) return dp[x];
	int ans=0;
	
	for(int i=head[x];~i;i=e[i].next)
	ans=max(dfs(e[i].to)+1,ans);
	
	return dp[x]=ans;
}

int main()
{
	int n,m,x,y;
	memset(head,-1,sizeof(head));
	cin>>n>>m;
	while(m--)
	{
		cin>>x>>y;
		add(x,y);
		ru[y]++;
		chu[x]++;
	}
	
	for(int i=1;i<=n;++i)
	{
		if(!ru[i])
		ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;
	
	return 0;
 } 

Measured memory_bytes: 10652
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

// 素数判定
// 計算量O(√n)
template<class T>
bool isPrime(T n){
    if(n < 2) return false;
    for(long long i = 2; i*i <= n; ++i) if(n % i == 0) return false;
    return true;
}


// 素数列挙
// nまでの素数をEratosthenesの篩で列挙する
// 計算量O(nloglogn)
template<class T>
vector<T> prime_list(T n){
    vector<T> ret;
    vector<T> isPrime(n+1,1);
    isPrime[0] = isPrime[1] = 0;
    for(long long i = 2; i <= n; ++i){
        if(isPrime[i] == 0) continue;
        ret.push_back(i);
        for(long long j = i*i; j <= n; j += i) isPrime[j] = 0;
    }
    return ret;
    // return isPrime;  // 状況によってはこっちを返す
}

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

    int m = 100001,q; cin >> q;

    vector<int> p = prime_list(m);
    int n = p.size();
    vector<bool> like_list(m+1,false);
    rep(i,n){
        if(isPrime((p[i]+1)/2)) like_list[p[i]] = true;
    }
    like_list[2] = false;
    vector<int> pn_sum(m+1);
    pn_sum[0] = 0;
    rep(i,m){
        if(like_list[i+1]) pn_sum[i+1] = pn_sum[i]+1;
        else pn_sum[i+1] = pn_sum[i];
    }
    
    int l,r;
    rep(i,q){
        cin >> l >> r;
        cout << pn_sum[r] - pn_sum[l-1] << "\n";
    }
}

Measured memory_bytes: 1144
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 60
int a[N], b[N], c[N], d[N];
int main(){
	int n, m;
  cin>>n>>m;
  rep(i, n) cin>>a[i]>>b[i];
  rep(i, m) cin>>c[i]>>d[i];
  rep(i, n){
    int r = 0, x = 1e9;
    rep(j, m){
      int t = abs(c[j]-a[i])+abs(d[j]-b[i]);
      if(t<x){
        x = t;
        r = j;
      }
    }
    cout<<r+1<<endl;
  }
	return 0;
}


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

using namespace std;

int N;
int r[101];
int v[3][101];

bool check(int k, int mb) {
  //if(v[k][0] + mb > 100) return false;

  v[k][0] += mb;
  int score[101] = {0};
  for(int i = 0; i < 3; i++) {
    vector<int> ts[303];
    for(int j = 0; j < N; j++) {
      ts[v[i][j]].push_back(j);
    }
    int cnt = 0;
    for(int j = 300; j >= 0; j--) {
      for(int id : ts[j]) {
    score[id] += r[cnt];
      }
      cnt += ts[j].size();
    }
  }
  v[k][0] -= mb;
  {
    vector<int> ts[303];
    for(int j = 0; j < N; j++) {
      ts[score[j]].push_back(j);
    }
    int cnt = 0;
    for(int j = 300; j >= 0; j--) {
      for(int id : ts[j]) {
    if(id == 0) return cnt < 8;
      }
      cnt += ts[j].size();
    }
  }
  assert(false);
}

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) cin >> r[i];
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 3; j++) cin >> v[j][i];
  }

  int ans = 1000;
  for(int i = 0; i < 3; i++) {
    for(int mb = 0; mb <= 101; mb++) {
      if(check(i, mb)) {
    ans = min(ans, mb);
    break;
      }
    }
  }
  if(ans == 1000) cout << "Saiko" << endl;
  else cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3120
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,n;
    cin >> n >> k;
    vll p(n);
    vector<double> sum(n+1,0.0);
    REP(i,n){
        cin >> p[i];
        sum[i+1] = sum[i]+((double)p[i]+1.0)/2.0;
    }
    /* 
    REP(i,n+1){
        cout << sum[i] << " ";
    }
    
    cout << endl;
    */
    double ans = 0.0;
    REP(i,n-k+1){
        double t = sum[i+k]-sum[i];
        if(t>ans){
            ans=t;
        }
    }
    printf("%.12f\n",ans);
    return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		stack<int> s;
		for(int i = 512; i > 0; i /= 2){
			if(n - i >= 0){
				s.push(i);
				n -= i;
			}
		}
		int o;
		while(!s.empty()){
			o = s.top();
			s.pop();
			if(s.empty())cout << o << endl;
			else cout << o << " ";
		}
	}
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, X, M;
    cin >> N >> X >> M;
    int sum = 0;
    map<int, pair<int, int>> mp;
    REP(i, N) {
        // 循環した初回のみループ変数iを最終ループへ飛ばす
        if (mp.count(X) > 0) {
            // 循環する長さ
            int len = i - mp[X].first;
            // 循環する回数
            int cnt = (N - i - 1) / len;
            sum += (sum - mp[X].second) * cnt;
            i += len * cnt;
        } else {
            mp[X] = {i, sum};
        }
        sum += X;
        X = X * X % M;
    }
    cout << sum << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 6728
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,a;
  cin >> n;
  vector<int> v;
  for(int i=0;i<n;i++){
    cin >> a;
    v.push_back(a);
  }
  long long int ans,kouho;
  for(int i=1;i<=100;i++){
    kouho = 0;
    for(int j=0;j<n;j++){
      kouho += (i-v[j])*(i-v[j]);
    }
    if(i==1){
      ans = kouho;
    }else{
      ans = min(ans,kouho);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_right

s = input()
t = input()

t_set = set(t)

if len(t_set -set(s)) != 0:
    print(-1)
    sys.exit()

s_len = len(s)
def index_list(char):
    word = s
    ret = list()
    sum = 0
    try:
        while True:
            index = word.index(char)+ 1        
            sum+=index
            ret.append(sum)
            word = word[index:]
    except:
        if sum == 0:
            ret.append(-1)
    return ret

alpha_dict = dict()
for char in t_set:
    alpha_dict[char] = index_list(char)

index_old = 0
n_s = 0
for char in t:
    index = alpha_dict[char]
    
    flg = True
    
    if index[-1] <= index_old:
        pass
    else:
        index_old = index[bisect_right(index, index_old)]
        flg =False
    if flg:
        index_old = index[0]
        n_s += 1
        
print(n_s*s_len + index_old)


Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define fo(i,s,e) for (int i=(s); i < (e); i++)
#define all(obj) (obj).begin(), (obj).end()
/*卍卍卍 #define int long long 卍卍卍*/
signed main () {
  int n;cin >> n;
  vector<int> b(n-1,0);
  rep(i,n-1) cin>>b[i];
  int ans=b[0]+b[n-2];
  fo(i,1,n-1) ans+=min(b[i-1],b[i]);
  cout << ans << endl;
}

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

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

  int minCnt = 1000000000;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;

    int cnt = 0;
    while (A % 2 == 0) {
      cnt++;
      A /= 2;
    }

    if (cnt < minCnt) {
      minCnt = cnt;
    }
  }

  cout << minCnt << endl;

  return 0;
}


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

int main() {
 int n,t,ans=0;
 cin >>n >>t;
 vector<int> time(n);
 for(int i=0;i<n;i++){
 cin >> time[i];
 }
  
 for(int i=0;i<n-1;i++){
   if(time[i+1]-time[i]<=t){
   ans+=time[i+1]-time[i];
   }
   else{
   ans+=t;
   }
 }
 cout << ans+t << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    long long N, M, R;
    cin >> N >> M >> R;
    vector<long long> r(R), A(M), B(M), C(M);
    REP (i, R) {
        cin >> r[i];
        r[i]--;
    }
    REP (i, M) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
    }

    vector<vector<long long> > distance(N, vector<long long>(N, INT_MAX));

    REP (i, N) {
        distance[i][i] = 0;
    }
    REP (i, M) {
        distance[A[i]][B[i]] = C[i];
        distance[B[i]][A[i]] = C[i];
    }
    REP (i, N) {
        REP (j, N) {
            REP (k, N) {
                distance[j][k] = min(distance[j][k], distance[j][i] + distance[i][k]);
            }
        }
    }
    long long ans = LLONG_MAX;
    long long num = 1;
    for (auto i = R; i > 0; --i) {
        num *= i;
    }
    for (long long n = 0; n < num; ++n) {
        long long tmp = 0;
        REP (i, R - 1) {
            tmp += distance[r[i]][r[i + 1]];
        }
        ans = min(ans, tmp);
        next_permutation(r.begin(), r.end());
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
x=int(input())
l=[i**5 for i in range(-1000,1001)]
ok=False
for i in range(len(l)):
    if ok:
        break
    for j in range(len(l)):
        if l[i]-l[j]==x:
            print(i-1000,j-1000)
            ok=True
            break
    

Measured memory_bytes: 66252
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  map<int,int> m;
  for(int i=0;i<N;i++)m[v[i]]++;
  if(v[N-1]&1){
    for(int i=v[N-1];i>v[N-1]/2;i--)if(m[i]<2)fin("Impossible");
    if(m[v[N-1]/2+1]>2)fin("Impossible");
    for(int i=v[N-1]/2;i>=0;i--)if(m[i])fin("Impossible");
    fin("Possible");
  }
  for(int i=v[N-1];i>v[N-1]/2;i--)if(m[i]<2)fin("Impossible");
  if(m[v[N-1]/2]!=1)fin("Impossible");
  for(int i=m[v[N-1]/2-1];i>=0;i--)if(m[i])fin("Impossible");
  fin("Possible");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 22, M = (1<<21)+2;
ll dp[N][M];
int compat[N][N];
int n;
const int MOD = 1e9+7;
ll count(int i, int mask)
{
	if(__builtin_popcount(mask) == n)
	{
		if(i == n)
			return 1;
		else
			return 0;
	}
	if(i >= n)
		return 0;

	if(dp[i][mask] != -1)
		return dp[i][mask];

	dp[i][mask] = 0;
	for(int j=0;j<n;j++)
	{
		if(!(mask&(1<<j)) && compat[i][j])
			dp[i][mask] = (dp[i][mask] + count(i+1, mask + (1<<j)))%MOD;
	}

	return dp[i][mask];

}

int main()
{
	memset(dp, -1, sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>compat[i][j];
		}
	}

	cout<<count(0, 0);
}

Measured memory_bytes: 360832
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskT solver = new TaskT();
        solver.solve(1, in, out);
        out.close();
    }
    
    

    static class TaskT {
    	static int cnt = Integer.MAX_VALUE;
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	
        		int D = in.nextInt();
        		int T = in.nextInt();
        		int S = in.nextInt();
        		
        		int X = T * S;
        		
        		String ans = X>=D ? "Yes" : "No";
        		out.print(ans);
        }
        
        

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32952
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;
typedef long long int lli;

class graph{
private:
    int V;
    vector<int> *adj;
public:
    graph(int v){
        this->V=v;
        adj=new vector<int>[v];
    }
    void addedge(int u, int w){
        adj[u].push_back(w);
    }
    int recu(int node, int visited[], int val[]){
        val[node]=0;
        visited[node]=1;
        for(auto i : adj[node]){
            if(visited[i]){
                val[node]=max(val[node], 1+val[i]);
            }
            else{
                val[node]=max(val[node], 1+recu(i, visited, val));
            }
        }
        return val[node];
    }
};


void solve(){
    int n,m;
    cin>>n>>m;
    graph g(n);
    int x,y;
    for(int i=0; i<m; i++){
        cin>>x>>y;
        x--;
        y--;
        g.addedge(x,y);
    }
    int visited[n], val[n];
    memset(visited, 0, sizeof(visited));
    memset(val, 0, sizeof(val));
    for(int i=0; i<n; i++){
        if(!visited[i]){
            g.recu(i, visited, val);
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        //cout<<val[i]<<" ";
        ans=max(ans, val[i]);
    }
    //cout<<endl;
    cout<<ans<<endl;
}

signed main(){
	//#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    //#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 7680
import sys, itertools
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    H, W = LI()
    s = [list(S()) for _ in range(H)]

    for i, j in itertools.product(range(H), range(W)):
        if s[i][j] != '#':
            cnt = 0
            for k, l in itertools.product(range(-1, 2), repeat=2):
                if 0 <= i + k < H and 0 <= j + l < W:
                    if s[i+k][j+l] == '#':
                        cnt += 1
            s[i][j] = str(cnt)

    for i in s:
        print(''.join(i))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long long,long long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long long,long long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long long,long long>>> lvvii;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

long long mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

long long mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n;
	cin>>n;
	ll k=n%1000;
	if(k!=0)
	cout<<1000-k<<endl;
	else
	{
		cout<<0<<endl;
	}
	return 0;
}	

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,n,a) for(int i=n;i>=a;i++)
#define ll long long int
#define p(a,b) pair<a,b>
#define mp(a,b) make_pair(a,b)
#define hpq(a) priority_queue<a>
#define lpq(a) priority_queue<a, vector<a>, greater<a>>
#define nl endl
#define pb(x) push_back(x);
#define ft(x,a) for(auto &it : a)
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
/*

   *                          (                            (
 (  `          )   )          )\ )            )            )\ )        (      )    *   )              )                                                  (
 )\))(      ( /(( /(   (  (  (()/(  (      ( /(   (  (    (()/(        )\  ( /(  ` )  /((   (      ( /(                   (         )    (               )\ )  (
((_)()\  (  )\())\()) ))\ )(  /(_))))\  (  )\()) ))\ )(    /(_))  (   ((_) )\())  ( )(_))(  )\ )   )\())(     (  (  `  )  )\ )     (     )\ )    (  (   (()/( ))\
(_()((_) )\(_))((_)\ /((_|()\(_))_/((_) )\((_)\ /((_|()\  (_))_   )\  )\ )(_))/  (_(_()|()\(()/(  (_))/ )\    )\ )\ /(/( (()/(     )\  '(()/(    )\ )\   ((_))((_)
|  \/  |((_) |_| |(_|_))  ((_) |_(_))( ((_) |(_|_))  ((_)  |   \ ((_)_(_/(| |_   |_   _|((_))(_)) | |_ ((_)  ((_|(_|(_)_\ )(_))  _((_))  )(_))  ((_|(_)  _| (_))
| |\/| / _ \  _| ' \/ -_)| '_| __| || / _|| / // -_)| '_|  | |) / _ \ ' \))  _|    | | | '_| || | |  _/ _ \ / _/ _ \ '_ \) || | | '  \()| || | / _/ _ \/ _` / -_)
|_|  |_\___/\__|_||_\___||_| |_|  \_,_\__||_\_\\___||_|    |___/\___/_||_| \__|    |_| |_|  \_, |  \__\___/ \__\___/ .__/ \_, | |_|_|_|  \_, | \__\___/\__,_\___|
                                                                                            |__/                   |_|    |__/           |__/

*/
int main()
{
    int n;
    cin>>n;
    map<string,int> m;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    int ma=0;
    for(auto &it : m)
    {
        if(it.second>=ma)
            ma=it.second;
    }
    for(auto &it : m)
    {
        if(it.second==ma)
            cout<<it.first<<endl;
    }
}


Measured memory_bytes: 25216
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n, k;

void in(){
    cin >> n >> k;    
}

void solve(){
    
    int zero = 0;
    int kdiv2 = 0;

    rep(i,1,n + 1){
        if(i % k == 0) zero++;
        if(k % 2 == 0 && i % k == k / 2) kdiv2++;
    }

    cout << zero * zero * zero + kdiv2 * kdiv2 * kdiv2 << endl;


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 10000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
int  main()
{
    string a,b;
    cin>>a>>b;
    int c,d;
    cin>>c>>d;
    string u; cin>>u;
    if(u==a) cout<<c-1<<' '<<d<<endl;
    else if(u==b) cout<<c<<' '<<d-1<<endl;
    else cout<<c<<' '<<d<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;

int flower(vector<int> &vec) {
	int ans = 0;
	vector<int> hana;

	for (auto e : vec) {

		if(e==0){
			if (!hana.empty()) ans++;
			ans += flower(hana);
			hana.erase(all(hana));
			continue;
		}
		hana.push_back(--e);
	}
	if (!hana.empty()) {
		ans += flower(hana) + 1;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	rep0(i, n)cin >> vec[i];

	int ans = flower(vec);

	cout << ans;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;


int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
vector<vector<int>>path(n);
rep(i,m){
    int a,b;
    cin>>a>>b;
    a--,b--;
    path[a].pb(b);
    path[b].pb(a);
}
vector<int> dist(n,1e9);
vector<int> marker(n);
dist[0]=0;
marker[0]=0;
queue<int> q;

for(auto v:path[0]){
    q.push(v);
    dist[v]=1;
    marker[v]=0;
}

while(!q.empty()){
    int node=q.front();
    q.pop();
    for(auto v:path[node]){
        if(chmin(dist[v],dist[node]+1)){
            marker[v]=node;
            q.push(v);
        }
    }
}
cout<<"Yes"<<endl;
reps(i,n,1){
    cout<<marker[i]+1<<endl;
}

return 0;
}

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

int main() {
	int n;
	cin >> n;
	int bs[n];
	for (int i = 0; i < n-1; i ++) {
		int a;
		cin >> a;
		bs[i] = a;
	}

	int sum = 0;
	for (int i = 0; i < n; i ++) {
		if (i == 0) {
			sum += bs[0];
		} else if (i == n-1) {
			sum += bs[i-1];
		} else {
			int min = bs[i-1];
			if (bs[i] < min) min = bs[i];
			sum += min;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 384
n = int(input())
aa = list(map(lambda x: int(x)-1, list(input())))

def parity(n, r):
    # parity of n choose r
    # via https://math.stackexchange.com/questions/233269/odd-and-even-numbers-in-pascals-triangle-sierpinskis-triangle
    if n <= 1:
        return 1
    if r == 1:
        return n % 2
    if r == 0:
        return 1
    if n % 2 == 0 and r % 2 != 0:
        return 0
    return parity(n//2, r//2)

def ab(x):
    if x < 0:
        return -x
    return x

ans = 0
for i, a in enumerate([a % 2 for a in aa]):
    p = parity(n-1, i)
    if p == 1:
        ans = ab(ans - a)

if ans == 1:
    print(1)
    exit(0)

if 1 in aa:
    print(0)
    exit(0)

ans = 0
for i, a in enumerate([a // 2 for a in aa]):
    p = parity(n-1, i)
    if p == 1:
        ans = ab(ans - a)
print(ans * 2)



Measured memory_bytes: 144188
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long ans = 0;
    //int[] a = new int[N];
    for(int i=1; i<=N; i++){
      //if(i%3!=0 && i%5!=0){
      if(i%3==0 || i%5==0){
        continue;
      } else {
        ans+=i;
      }
      //a[i] = sc.nextInt();
      //if(i%3==0 && i%5==0){
        //a[i]="FizzBuzz";
      //} else if(i%3==0) {
        //a[i]="Fizz";
      //} else if(i%5==0) {
        //a[i]="Buzz";
      //} else {
        //a[i]=String.valueOf(i);
      //}
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35640
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int n; 
vector <vector <int> > dp;
vector <vector <int> > input;
int func(int index , int mask)
{
   // cout<<index<<" "<<mask<<endl;
    if(index == n)
        return 1;
    if(dp[index][mask] != -1)
        return dp[index][mask];
    int result = 0;
    for(int i=0;i<n;i++)
    {
        //cout<<input[index][i]<<" "<<(mask & (1<<i)) <<endl;
        if(input[index][i] == 1 && (mask & (1<<i)))
        {
            result = (result%mod + func(index+1,mask^(1<<i))%mod)%mod;
        }
    }
    return dp[index][mask] = result%mod;
}
int main()
{
    cin>>n;
    input.clear();
    input.resize(n,vector<int>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>input[i][j];
        }
    }
    dp.clear();
    int mask = (1<<n)-1;
    dp.resize(n+1,vector <int> (mask+1,-1));
    cout<<func(0,mask);
}

Measured memory_bytes: 188800