akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  ll n,d,a,u=0,w,ans=0;
  cin >> n >> d >> a;
  vector<pair<ll,ll>> e(n);
  vector<ll> y(n,0);
  rep(i,n) cin >> e[i].first >> e[i].second;
  sort(all(e));
  int k=0;
  rep(i,n){
    w=e[i].first+2*d;
    for (int j=k;j<n;j++){
      if (e[j].first<=w) y[j]=u;
    else break;
    k++;
    }
    ll t=0;
    if (u-y[i]<e[i].second) t=(e[i].second-u+y[i]+a-1)/a;
    u+=a*t;
    ans+=t;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
// AtCoder
// ABC 179 B - Go to Jail

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <random>
#include <vector>
#include <chrono>

using namespace std;

int main()
{
	int N;
	cin >> N;
    int D[N+1][2];
	
	for (int i=0; i<N; i++) {
		cin >> D[i][0] >> D[i][1];
	}
	// 計算
	int cnt = 0;
	for (int i=0; i<N; i++) {
		if (D[i][0] == D[i][1]) {
			if (D[i+1][0] == D[i+1][1]) {
				if (D[i+2][0] == D[i+2][1]) {
					cnt += 1;
				}
			}
		}
	}
	if (cnt >= 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i, begin, end) for(int i = begin; i < (end); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int main(){
	int n, k;
	cin >> n >> k;
  	vector<int> a(n);
  	rep(i, 0, n) cin >> a[i];
  
  	int dp[100005];
  
  	rep(i, 1, n){
      	int diff = abs(a[i] - a[i-1]);
      	dp[i] = dp[i-1] + diff;	
      
      	rep(j, 2, k+1){
          	if(i - j < 0) break;
        	dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
        }
    }
  
  	cout << dp[n-1] << endl;
}	

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include <iomanip>


const double PI = acos(-1.0);
using namespace std;
int main(){
	double a,b,h,m;
	cin >> a >> b >> h >> m;
	double mdu = m*6;
	long double hdu = (long double)30*h + (long double)0.5 * m;
	long double difdu = hdu - (long double)mdu;
	long double ans = sqrt((long double)a*a + (long double)b*b - 2* a * b * cos(difdu * PI / 180.0 ));
	cout << setprecision(20) << ans;
	return 0; 
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int n;
ll k;
const int N = 100100;
int a[N];
VI chi[N];
int cnt = 0;
int d[N];
void dfs(int v, int qq) {
  d[v] = qq;
  REP(i, 0, chi[v].size()) {
    int c = chi[v][i];
    dfs(c, qq + 1);
  }
}
int marked[N];
void mark(int v) {
  if (marked[v]) {
    return;
  }
  marked[v] = 1;
  REP(i, 0, chi[v].size()) {
    int c = chi[v][i];
    mark(c);
  }
}

const int B = 20;
int lbt[N][B];
void lbt_init(void) {
  REP(i, 0, n) {
    lbt[i][0] = a[i];
  }
  REP(b, 1, B) {
    REP(i, 0, n) {
      lbt[i][b] = lbt[lbt[i][b - 1]][b - 1];
    }
  }
}

int get_anc(int v, int l) {
  REP(i, 0, B) {
    if (l & (1 << i)) {
      v = lbt[v][i];
    }
  }
  return v;
}

int main(void){
  cin >> n >> k;
  REP(i, 0, n) {
    cin >> a[i];
    a[i]--;
  }
  if (a[0] != 0) {
    a[0] = 0;
    cnt = 1;
  }
  if (k == 1) {
    REP(i, 0, n) {
      if (a[i] != 0) {
	a[i] = 0;
	cnt++;
      }
    }
    cout << cnt << endl;
    return 0;
  }
  if (k >= n - 1) {
    cout << cnt << endl;
    return 0;
  }
  REP(i, 1, n) {
    chi[a[i]].push_back(i);
  }
  dfs(0, 0);
  vector<PI> que;
  REP(i, 0, n) {
    que.push_back(PI(d[i], i));
  }
  sort(que.rbegin(), que.rend());
  lbt_init();
  REP(i, 0, que.size()) {
    PI t = que[i];
    //cerr << t.first << " " << t.second << endl;
    if (!marked[t.second] && t.first >= k + 1) {
      // mark k - 1 up vertex TODO
      /*
      int cur = t.second;
      REP(i, 0, k - 1) {
	cur = a[cur];
      }
      */
      int up = get_anc(t.second, k - 1);
      //mark
      mark(up);
      //      cerr << "mark:" << up << endl;
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 20340
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> left(n+1, 0), right(n+1, 0);
    rep(i,n) left[i+1] = gcd(left[i], a[i]);
    for(int i=n-1; i >= 0; i--) right[i] = gcd(right[i+1], a[i]);
    int ans=0;
    rep(i,n){
        int l=left[i];
        int r=right[i+1];
        ans = max(ans, gcd(l,r));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

struct Edge {
    int to;
    int weight;

    Edge(int to, int weight) : to(to), weight(weight) {}
};

using Graph = vector<vector<Edge>>;
vector<int> colors;
vector<bool> seen;

Graph graph;

void dfs(int v, int c) {
    seen[v] = true;
    colors[v] = c;
    for (auto e : graph[v]) {
        if (seen[e.to]) continue;
        if (e.weight % 2 != 0) dfs(e.to, 1 - c);
        else dfs(e.to, c);
    }
}

int main() {

    int N;
    cin >> N;

    graph.assign(N, vector<Edge>());
    seen.assign(N,false);
    colors.assign(N, 0);

    for (int i = 0; i < N - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        u -= 1;
        v -= 1;
        graph[u].push_back(Edge(v, w));
        graph[v].push_back(Edge(u, w));
    }

    dfs(0, 1);

    for (int i = 0; i < N; ++i) {
        cout << colors[i] << endl;
    }

}

Measured memory_bytes: 10948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int P,Q;
  cin>>N>>P>>Q;
  vector<int> c(N,0);
  rep(i,N) cin>>c.at(i);
  vector<pair<ll,ll> > cj(N,pair<ll,ll>(0,0));
  rep(i,N){
    cj.at(i).fi = c.at(i) + P * (i+1);
    cj.at(i).se = i+1;
  }
  sort(begin(cj),end(cj));
  vector<ll> ans(N+1,0);
  ll sumn=0;
  rep(i,N) sumn += c.at(i);
  rep(i,N+1){
    if(i == 0) {
      ans.at(0) = sumn;
      continue;
    }
    pair<ll,ll> p = cj.at(i-1);
    ans.at(i) = ans.at(i-1) - c.at(p.se-1) + P*(Q-p.se-1+2*i);
  }
  sort(begin(ans),end(ans));
  cout << ans.at(N) << endl;
}



Measured memory_bytes: 16688
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, M;
    cin >> N >> M;
    map<ll, ll> mp;
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    rep(i, N) {
        print(mp[i+1]);
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

int main(){
  char com[20];
  priority_queue<int> pq;
  while(1){
    scanf("%s",com);
    if(com[0] =='i'){
      int key; scanf("%d",&key);
      pq.push(key);
    }else if(com[1] == 'x'){
      printf("%d\n",pq.top());
      pq.pop();
    }else if(com[0] == 'e'){
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 6440
#include <cstdio>

void ToOctalNumber(int n){
	if(n){
		ToOctalNumber(n >> 3);
		printf("%d",(n&7)<4?n&7:(n&7)==4?5:(n&7)+2);
	}
}

int main(){
	int n;
	while(scanf("%d",&n),n){
		ToOctalNumber(n);
		puts("");
	}
}

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

int main() {
  int w;
  int cAng = 90, ang;
  char c;
  double x = 0.0, y = 0.0;

  while(cin>>w>>c>>ang) {
    if(w == 0 && ang == 0) break;
    x += w * cos(cAng*M_PI/180.0), y += w * sin(cAng*M_PI/180.0);
    cAng -= ang;
  }
  printf("%d\n%d\n", (int)x, (int)y);
  return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl

const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> P;


int main(){
   ll a,b,c,d;
   cin >> a >> b >> c >> d;
   cout << max(a*b,c*d) << endl;
   return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {


	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int HI = Integer.parseInt(W.split(" ")[0])+2;
		int WI = Integer.parseInt(W.split(" ")[1])+2;

		boolean[][] S = new boolean[HI][WI] ;
		for(int i=0;i<S.length;i++){
			Arrays.fill(S[i], false);
		}
		for(int i=0;i<S.length-2;i++){
			W = in.readLine();
			for(int k=0;k<W.length();k++){
				if('.' == W.charAt(k)){
					S[i+1][k+1] = true;
				}else{
					S[i+1][k+1] = false;
				}
			}
		}
		int ans = -1;
		for(int w=0;w<S.length;w++){
			for(int h=0;h<S[0].length;h++){
				if(!S[w][h]){
					continue;
				}
				boolean[][] tmpS = new boolean[HI][WI] ;
				for(int i=0;i<S.length;i++){
					tmpS[i] = Arrays.copyOf(S[i], S[i].length);
				}
				//ある道から幅優先で探索し経路の長さを全探索する
			 	ans = Math.max(BWS(w, h,tmpS),ans);
			}
		}

		System.out.println(ans);
	}

	public static int BWS(int w , int h,boolean[][] S){
		int len = 0;
		ArrayList<int[]> queue = new ArrayList<int[]>();
		int[] p = {w,h};
		queue.add(p);
		//現在地は壁に変更する
		S[p[0]][p[1]]=false;

		while(queue.size()!=0){
			ArrayList<int[]> queue2 = new ArrayList<int[]>();
			while(queue.size()!=0){
				p = queue.get(0);
				queue.remove(0);

				//pの上下左右で道があれば追加
				//上
				int[] aftP = new int[2];
				aftP[0] = p[0]-1;
				aftP[1] = p[1];
				if(S[aftP[0]][aftP[1]]){
					S[aftP[0]][aftP[1]]=false;
					queue2.add(aftP);
				}
				//下
				aftP = new int[2];
				aftP[0] = p[0]+1;
				aftP[1] = p[1];
				if(S[aftP[0]][aftP[1]]){
					S[aftP[0]][aftP[1]]=false;
					queue2.add(aftP);
				}
				//左
				aftP = new int[2];
				aftP[0] = p[0];
				aftP[1] = p[1]-1;
				if(S[aftP[0]][aftP[1]]){
					S[aftP[0]][aftP[1]]=false;
					queue2.add(aftP);
				}
				//右
				aftP = new int[2];
				aftP[0] = p[0];
				aftP[1] = p[1]+1;
				if(S[aftP[0]][aftP[1]]){
					S[aftP[0]][aftP[1]]=false;
					queue2.add(aftP);
				}
			}
			if(queue2.size()!=0){
				len++;
				queue=queue2;
			}
//			System.out.println(" ");
//			print(S);
		}

		return len;
	}

	public static void print(boolean[][] S){
		for(int i=0;i<S.length;i++){
			for(int k=0;k<S[0].length;k++){
				if(S[i][k]){
					System.out.print(". ");
				}else{
					System.out.print("# ");
				}
			}
			System.out.println("");
		}
	}
}


Measured memory_bytes: 36896
#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
using namespace std;
int main() {
    ll s, bd = 1e9;
    cin >> s;
    if (s == 1e18)cout << 0 << ' ' << 0 << ' ' << 1000000000 << ' ' << 0 << ' ' << 0 << ' ' << 1000000000;
    else if (s <= bd)cout << 0 << ' ' << 0 << ' ' << 0 << ' ' << 1 << ' ' << s << ' ' << 0;
    else {
        ll L = s / bd + 1, R = L * bd - s;
        cout << 0 << ' ' << 0 << ' ' << bd << ' ' << 1 << ' ' << R << ' ' << L;
    }
    return 0;
}


Measured memory_bytes: 3580
import math

n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]

d_sum = 0
cnt = 0
for i in range(n):
    for j in range(n):
        if i != j:
            d_sum += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
            cnt += 1

print(d_sum*(n-1)/cnt)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll func(vector<ll> val,vector<ll> wt,ll n,ll W)
{
  ll dp[n+1][W+1];
  ll i,j;
  for(i=0;i<=n;i++)
  {
    for(j=0;j<=W;j++)
    {
      if(i==0||j==0)
        dp[i][j]=0;
    }
  }
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=W;j++)
    {
      if(wt[i-1]<=j)
      {
        dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
      }
      else
        dp[i][j]=dp[i-1][j];
    }
  }
  return dp[n][W];
}
int main()
{
  ll n,W,i,val,wt;
  vector<ll> v,w;
  cin>>n>>W;

  for(i=0;i<n;i++)
  {
    ll wt;
    cin>>wt;
    w.push_back(wt);
    ll val;
    cin>>val;
    v.push_back(val);
  }
  cout<<func(v,w,n,W)<<"\n";
}


Measured memory_bytes: 79104
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		boolean prime[] = new boolean[300000];
		int sum[] = new int[300000];
		
		prime[0] = true;
		prime[1] = true;
		
		sum[0] = 0;
		for(int i =1 ; i < prime.length; i++){
			if(prime[i]){
				sum[i] = sum[i-1];
				continue;
			}
			sum[i] = sum[i-1]+1;
			for(int j = i*2; j < prime.length ; j+=i){
				prime[j] = true;
			}
		}
		
		for(;;){
			int n = sc.nextInt();
			if(n == 0 ){
				break;
			}
			System.out.println(sum[2*n]- sum[n]);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define Mod 1000000007
#define MN 300005
char ch[MN];
int f[MN][3][3],n;
void add(int &a,int b){(a+=b)>=Mod?(a-=Mod):0;}
void upd1(int i,int j,int k){
	if(j)add(f[i][j-1][k],f[i-1][j][k]);
	else add(f[i][j][min(k+1,2)],f[i-1][j][k]);
}
void upd0(int i,int j,int k){
	if(j==2) add(f[i][1][k],f[i-1][j][k]);
	else add(f[i][j+1][k],f[i-1][j][k]);
}
int main(){
	scanf("%s",ch+1);
	n=strlen(ch+1);
	f[0][0][0]=1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=2;++j)
			for(int k=0;k<=2;++k){
				if(ch[i]=='1'){
					upd1(i,j,k);
				}
				else if(ch[i]=='0'){
					upd0(i,j,k);
				}
				else upd1(i,j,k),upd0(i,j,k);
			}
	//	for(int j=0;j<=2;++j)
	//		for(int k=0;k<=2;++k)
	//			cerr<<i<<" "<<j<<" "<<k<<": "<<f[i][j][k]<<endl;
	}
	printf("%lld\n",((long long)f[n][0][1]+f[n][1][2]+f[n][2][2]+f[n][0][2])%Mod);
	return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y, S;

int main()
{
    cin >> W >> H >> N;
    int lbx = 0, lby = 0, rux = W, ruy = H;
    for (int i = 0; i < N; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        switch (a) {
            case 1:
                lbx = max(lbx, x);
                break;
            case 2:
                rux = min(rux, x);
                break;
            case 3:
                lby = max(lby, y);
                break;
            case 4:
                ruy = min(ruy, y);
        }
        //cout << lbx << "," << lby << " : " << rux << "," << ruy << endl;
    }

    if (lbx > rux || lby > ruy)
        cout << 0 << endl;
    else 
        cout << (rux - lbx)*(ruy - lby) << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

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

	ll x2 = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2)  x2 -= A[i];
		else  x2 += A[i];
	}
	
	int x = x2 / 2;
	vector <int> ans(n);
	ans[0] = x;
	for (int i = 1; i < n; i++) {
		ans[i] = A[i - 1] - ans[i - 1];
	}
	for (int i = 0; i < n; i++)  ans[i] *= 2;
	for (int i = 0; i < n; i++) {
		if (i)  cout << ' ';
		cout << ans[i];
	}
	cout << endl;
}

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

using namespace std;

int main(){
    int d; cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    else if (d == 24) cout << "Christmas Eve" << endl;
    else if (d == 23) cout << "Christmas Eve Eve" << endl;
    else if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
n, y = [int(x) for x in input().split()]

n100 = -1
n50 = -1
n10 = -1
flag = True
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i - j
        if 10000*i + 5000*j + 1000*k == y:
            n100 = i
            n50 = j
            n10 = k
            break
    else:
        continue
    break
print(str(n100) + ' ' + str(n50) + ' ' + str(n10))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int sum=0;
  sum=sum+a+b+c;
  if(sum==17)
  {
    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;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int cnt = 0;
	map<string, int> mp;
	rep(i,n){
		string s;
		cin >> s;
		chmax(cnt, ++mp[s]);
	}
	vector<string> ans;
	for(auto p : mp){
		if(p.second == cnt) ans.push_back(p.first);
	}
	sort(ans.begin(), ans.end());
	rep(i,ans.size()) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 27192
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint a[100005];
llint dif[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i]--;
	
	llint ans = 0;
	for(int i = 1; i < n; i++) ans += ((a[i+1]-a[i])%m+m)%m;
	
	for(int i = 1; i < n; i++){
		llint l = a[i], r = a[i+1];
		if(l > r) r += m;
		llint len = r-l;
		if(len <= 1) continue;
		dif[l+2]++, dif[r+1]-=len, dif[r+2]+=len-1;
	}
	for(int i = 1; i < 2*m; i++) dif[i] += dif[i-1];
	for(int i = 1; i < 2*m; i++) dif[i] += dif[i-1];
	
	llint mx = 0;
	for(int i = 0; i < m; i++) mx = max(mx, dif[i]+dif[m+i]);
	cout << ans-mx << endl;
	
	return 0;
}

Measured memory_bytes: 2560
import math
H,W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
elif H%2 == 0:
    print(int(H/2*W))
elif W%2 == 0:
    print(int(W/2*H))
else:
    ans = H*(int(W/2))+math.ceil(H/2)
    print(int(ans))

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

int main(void) {
    int s;
    cin >> s;
    set<int> set;
    set.insert(s);
    int i = 1;

    while (1) {
        if (s % 2 == 0) {
            s /= 2;
        } else {
            s = 3 * s + 1;
        }
        i++;

        if (set.find(s) != set.end()) {
            cout << i << endl;
            break;
        }
        set.insert(s);
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5 * 2;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N;
ll A[N_MAX + 1], B[N_MAX + 1];
priority_queue<Pl, vector<Pl>, greater<Pl>> q;

int main() {
  scanf("%d", &N);
  rep(i, N) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    q.push(P(b, a));
  }

  ll sum_time = 0;
  while(!q.empty()) {
    Pl p = q.top();
    q.pop();
    sum_time += p.second;
    if (sum_time > p.first) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}


Measured memory_bytes: 6256
N, M = map(int, input().split())
k = []*M
s = []*M
for i in range(M):
    inp = list(map(int, input().split()))
    k.append(inp[0])
    s.append(inp[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(0,2**N):
    n = format(i,'010b')
    for j in range(M):
        pj = 0
        for k in range(len(s[j])):
            pj += int(n[10-s[j][k]])
        if p[j] != pj%2:
            break
        if j == M-1:
            ans += 1

print(ans)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), dp(1<<n, mod);
    vector<vector<int>> c(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        rep(j, b[i]){
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    vector<int> key(m, 0);
    rep(i, m)rep(j, b[i])key[i] |= (1<<c[i][j]);
    dp[0] = 0;
    rep(bit, (1<<n)){
        rep(i, m){
            int next = bit | key[i];
            chmin(dp[next], dp[bit] + a[i]);
        }
    }
    cout << (dp[(1<<n)-1] == mod ? -1 : dp[(1<<n)-1]) << endl;
}

Measured memory_bytes: 3704
arr = Array.new(26){0}
lines = readlines

lines.each{|line|
  strs = line.chomp.downcase.split("")
  strs.each{|s|
    i = s.ord - 97
    next if i < 0 || i > 25
    arr[i] += 1
  }
}
("a".."z").each{|s|
  printf "%s : %d\n", s, arr[s.ord-97]
}

Measured memory_bytes: 8620
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;



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

	long long n, i, j, k, ans, n3, s, x;
	cin >> n;
	n3 = 3 * n;
	vector<long long> a(n3), ll(n3, 0), rr(n3, 0);
	for (i = 0; i < n3; i++) cin >> a[i];

	priority_queue<long long> pq;

	s = 0;
	for (i = 0; i < n; i++) {
		pq.push(-a[i]);
		s += a[i];
	}
	ll[n - 1] = s;

	for (i = n; i < n * 2; i++) {
		pq.push(-a[i]);
		s += a[i];

		x = -pq.top();
		s -= x;
		pq.pop();

		ll[i] = s;
	}


	while (!pq.empty()) pq.pop();

	s = 0;
	for (i = n3 - 1; i >= n * 2; i--) {
		pq.push(a[i]);
		s += a[i];
	}
	rr[n * 2] = s;

	for (i = n * 2 - 1; i >= n; i--){
		pq.push(a[i]);
		s += a[i];

		x = pq.top();
		s -= x;
		pq.pop();

		rr[i] = s;
	}

	ans = -(1LL << 61);
	for (i = n - 1; i < n * 2; i++) ans = max(ans, ll[i] - rr[i + 1]);

	cout << ans << "\n";


	return 0;
}



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

#define PRINT(x) cout << x << endl;
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 2e9

using namespace std;
typedef long long ll;

ll g[300][300];
ll dist[300][300];

int main() {
	ll N, M, L;
	ll A, B, C;

	cin >> N >> M >> L;

	REP(i, N) REP(j, N) g[i][j] = dist[i][j] = INF;

	REP(i, M) {
		cin >> A >> B >> C;
		if (C >= g[A - 1][B - 1]) continue;
		g[A - 1][B - 1] = C;
		g[B - 1][A - 1] = C;
	}

	REP(i, N) g[i][i] = dist[i][i] = 0;

	REP(k, N) REP(i, N) REP(j, N) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

	REP(i, N) REP(j, N) if (i != j && g[i][j] <= L) dist[i][j] = 1;

	REP(k, N) REP(i, N) REP(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	int Q, s, t;
	cin >> Q;

	REP(i, Q) {
		cin >> s >> t;
		if (dist[s - 1][t - 1] == INF) PRINT(-1)
		else PRINT(dist[s - 1][t - 1] - 1);
	}

	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

int main()
{
	int a, b;
	std::cin >> a >> b;
	if (a <= 5) std::cout << 0 << std::endl;
	else if (a <= 12) std::cout << b / 2 << std::endl;
	else if (a >= 13) std::cout << b << std::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))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct UnionFind {
	vector<int> data;
	void init(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if(x != y) {
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};

struct Query {
	int cost;
	int type;
	int A, B;
	bool operator>(const Query &that) const {
		return cost > that.cost;
	}
};

int main() {
	int N; int Q;
	while(~scanf("%d%d", &N, &Q)) {
		priority_queue<Query,vector<Query>,greater<Query>> queries;
		rep(i, Q) {
			int A; int B; int C;
			scanf("%d%d%d", &A, &B, &C);
			queries.push(Query{ C, 1, A, B });
			queries.push(Query{ C + 1, 2, A, A });
			queries.push(Query{ C + 2, 2, B, B });
		}
		UnionFind uf;
		uf.init(N);
		ll ans = 0;
		vector<bool> visType2(N);
		while(!queries.empty()) {
			Query q = queries.top();
			queries.pop();
			if(q.type == 1) {
				if(uf.unionSet(q.A, q.B))
					ans += q.cost;
			} else {
				if(visType2[q.A]) continue;
				visType2[q.A] = true;
				int B = (q.A + 1) % N;
				if(uf.unionSet(q.A, B))
					ans += q.cost;
				queries.push(Query{ q.cost + 2, 2, B, B });
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 16744
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
	int n; cin >> n;
	int a[n];
	int min = INF, max = -INF;
	int minid = 0, maxid = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] > max) { max = a[i]; maxid = i; }
		if(a[i] < min) { min = a[i]; minid = i; }
	}
	if(max > -min) {
		cout << 2 * n - 1 << endl;
		for (int i = 1; i <= n; i++)
		{
			cout << maxid+1 << " " << i << endl;
		}
		for (int i = 2; i <= n; i++)
		{
			cout << i - 1 << " " << i << endl;
		}
	}
	else {
		cout << 2 * n - 1 << endl;
		for (int i = 1; i <= n; i++)
		{
			cout << minid+1 << " " << i << endl;
		}
		for (int i = n-1; i >= 1; i--)
		{
			cout << i+1 << " " << i << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
#include <cstdlib>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int x, a, b;
    cin >> x >> a >> b;
    cout << ((abs(x-a) > abs(x-b)) ? "B" : "A") << endl;
    return 0;
}

Measured memory_bytes: 256
room = [[[0]*10 for i in range(3)] for j in range(4)]
for i in range(int(input())):
    b,f,r,k = map(int,input().split())
    room[b-1][f-1][r-1]+=k
for i in range(4): 
    for j in room[i]: print('',*j)
    if i<3: print('#'*20)


Measured memory_bytes: 5624
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

public static partial class Program
{
    //テンプレここから
    public static int ToInt(this string str)
    {
        return int.Parse(str);
    }
    public static long ToLong(this string str)
    {
        return long.Parse(str);
    }
    public static IEnumerable<int> ToInt(this string[] strs)
    {
        return strs.Select(x => x.ToInt());
    }
    public static IEnumerable<long> ToLong(this string[] strs)
    {
        return strs.Select(x => x.ToLong());
    }
    public static IEnumerable<int> SplToInt(this string str, char opr = ' ')
    {
        return str.Split(opr).ToInt();
    }
    public static IEnumerable<long> SplToLong(this string str, char opr = ' ')
    {
        return str.Split(opr).ToLong();
    }
    public static string CRL()
    {
        return Console.ReadLine();
    }
    public static void CWL(object obj)
    {
        Console.WriteLine(obj);
    }
    public static int Diff(int a, int b)
    {
        return Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    }
    public static long Diff(long a, long b)
    {
        return Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    }
    public static int Sign(this int i)
    {
        return Math.Sign(i);
    }
    public static bool IsEven(this int i)
    {
        return i % 2 == 0;
    }
    //テンプレここまで
}

public static partial class Program
{
    static void Main()
    {
        var n = CRL().ToInt();
        var xs = CRL().SplToInt().ToList();
        var ys = new List<int>(xs);
        ys.Sort();
        var a = ys[n / 2 - 1];
        var b = ys[n / 2];

        for (int i = 0; i < n; i++)
        {
            if (a < xs[i])
            {
                CWL(a);
            }
            else
            {
                CWL(b);
            }
        }
    }
}

Measured memory_bytes: 36188
using System;
using System.Text;

namespace AOJ_Hello_World {
	class Program {
		static void Main (string[] args) {
			int counter = 1;
			while (true) {
				long input=getInputs(1)[0];
				if (input == 0)
					break;
				Console.WriteLine("Case {0}: {1}",counter++,input);
			}
		}

		private static long[] getInputs (long length){
			var sab = Console.ReadLine();
			long[] a = new long[length];
			for (int i = 0;i < length;i++) {
				a[i] = long.Parse(sab.Split(' ')[i]);
			}
			return a;
		}
	}
}

Measured memory_bytes: 5836
#include <iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
  ll c;
  while(b != 0) {
    c = a;
    a = b;
    b = c % b;
  }
  return a;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}
int main(void) {
  int n;
  ll t, answer = 1LL * 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    answer = lcm(answer, t);
  }
  cout << answer << endl;
  return 0;
}

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

int main(void){
  int n; cin >> n;
  int a[n]; rep(i,n) cin >> a[i+1];
  int ans[n];
  rep(i,n) ans[i+1] = 0;
  ans[n] = a[n];
  int count = 0;
  if(ans[n] == 1) count++;
  for(int i = n-1; i >= 1; i--){
    int check = 0;
    int j = 2;
    while(j*i <= n){
      if(ans[j*i] == 1) check++;
      j++;
    }
    if(check % 2 == 1){
      if(a[i] ==  1){
        ans[i] = 0;
      }
      else{
        ans[i] = 1;
        count++;
      }
    }
    else{
      if(a[i] == 1){
        ans[i] = 1;
        count++;
      }
      else ans[i] = 0;
    }
  }
  cout << count << endl;
  rep(i,n){
    if(ans[i+1] != 0) cout << i+1 << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION

void solve(void)
{
  int N;cin>>N;
  bool check = 1;
  for (int i = 0; i < N; i++)
  {
    int A;cin>>A;
    if(A%2 != 0)check = 0;
  }
  if(check == 1)
  {
    cout<<"second"<<endl;
  }
  else
  {
    cout<<"first"<<endl;
  }
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	string S;
	cin >> S;
	int ans = 0;
	REP(i, 1, S.size()) {
		if (S[i] != S[i - 1])ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 512
import sys
stdin = sys.stdin
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,stdin.readline().split()))
    mod = 10**9+7
    ans = 0
    for i in range(61):
        bits = 0
        for x in A:
            if (x>>i)&1:
                bits += 1
        ans += ((bits*(N-bits))* 2**i) %mod
    ans %= mod
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 50940
// Answer by drken1215
// cf. http://drken1215.hatenablog.com/entry/2019/09/29/012000

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

vector< vector<int> > graph;
vector< vector<int> > revGraph;

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  graph.resize(N);
  revGraph.resize(N);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    --A; --B; // 0-indexed
    graph[A].push_back(B);
    revGraph[B].push_back(A);
  }

  int shortest = INF;
  vector<int> res;
  rep(s, N) {
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while (!q.empty()) {
      auto v = q.front(); q.pop();
      for (auto nv : graph[v]) {
        if (dist[nv] == -1) {
          dist[nv] = dist[v] + 1;
          prev[nv] = v;
          q.push(nv);
        }
      }
    }
    for (auto t : revGraph[s]) {
      if (dist[t] == -1) { continue; } // t is not reachable

      int d = dist[t] + 1; // cycle length
      if (d < shortest) {
        shortest = d;
        // Update res to the found shortest path.
        res.clear();
        int cur = t;
        while (cur != s) {
          res.push_back(cur);
          cur = prev[cur];
        }
        res.push_back(s);
      }
    }
  }

  if (shortest == INF) { // shortest is not updated. So, no cycle is found.
    cout << -1 << endl;
  } else {
    cout << res.size() << endl;
    for (auto v : res) {
      cout << v + 1 << endl; // shortest path
    }
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int sum, sum_times_10, res;
  sum = a + b;
  sum_times_10 = 10 * (a + b);
  res = (sum_times_10 / 2) % 10;
  if (res < 5 ) {
    cout << sum / 2 ;
  }
  else {
    cout << sum / 2 + 1;
  }
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=sum(A)
for i in range(n):
  if B[i] > A[i]:
    A[i+1]=max(0,A[i+1]-(B[i]-A[i]))
    A[i]=0
  else:
    A[i]-=B[i]
    B[i]=0
print(ans-sum(A))

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

using namespace std;

#define fo(i,CApiTaL_N) for(int i=0; i<CApiTaL_N; i++)
#define Fo(i,k,CApiTaL_N) for(int i=k; i<CApiTaL_N; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int t=1;
const int mxN=1e5;
vvi grp(mxN+1);
int n,m;
vi dp(mxN+1,-1);

void dfs(int node){
    if(dp[node]!=-1)return;
    dp[node]=0;
    for(auto child:grp[node]){
        dfs(child);
        dp[node]=max(dp[node], dp[child]+1);
    }
}

void test_case(){
    cin>>n>>m;
    fo(i,m){
        int a,b;
        cin>>a>>b;
        grp[a].pb(b);
    }
    Fo(i,1,n+1){
        if(dp[i]!=-1)continue;
        dfs(i);
    }
    int maxi=0;
    Fo(i,1,n+1){
        maxi=max(maxi,dp[i]);
    }
    cout<<maxi<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    // cin>>t;
    while(t--){
        test_case();
    }
    
    return 0;
}

Measured memory_bytes: 11032
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
//AtCoderC++.cpp

using namespace std;

inline int ceiling(int n, int d) {
	return n % d == 0 ? n / d : n / d + 1;
}

int main() {
	int N, M; cin >> N >> M;
	auto connected = vector<int>(N*N, 0);
	int a, b;
	for (size_t i = 0; i < M; i++) {
		cin >> a >> b;
		++connected[(a - 1)*N + (b - 1)];
		++connected[(b - 1)*N + (a - 1)];
	}
	int count;
	for (size_t i = 0; i < N; i++) {
		count = 0;
		for (size_t j = 0; j < N; j++) {
			count += connected[i*N + j];
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;

	ll a,b,c;
	vector< pair<ll, pair<ll,ll> > > vc;
	vc.ps({0,{0,0}});
	for(i=0;i<n;i++){
		cin>>a>>b>>c;
		vc.ps({a,{b,c}});
	}

	sort(all(vc));
	int f=1;
	for(i=1;i<=n;i++){
		a=vc[i].sc.fs-vc[i-1].sc.fs;
		b=vc[i].sc.sc-vc[i-1].sc.sc;
		c=vc[i].fs-vc[i-1].fs;
		if((a+b)%2==0&&c%2!=0){
			f=0;
			break;
		}
		else if((a+b)%2!=0&&c%2==0){
			f=0;
			break;
		}
		else if((a+b)>c){
			f=0;
			break;
		}
	}
	if(f==1){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}


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

const int Nmax=200010;

ll L[100] = {};
ll lucas(int N){
	if(L[N] != 0) return L[N];
  	if(N == 0) return 2;
  	if(N == 1) return 1;
	else L[N] = lucas(N-1) + lucas(N-2);
	return L[N];
}
int main() {
	int N;
	cin >> N;

	cout << lucas(N) << endl;
		
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 200000000
#define LINF 1000000000000000000

using namespace std;

const int N = 4e2 + 10;

LL a[N];
LL pr[N];
LL dp[N][N];

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

	for (int i = 1;i <= n;i++)
		scanf("%lld", &a[i]), pr[i] = pr[i - 1] + a[i];
	
	for (int L = n;L >= 1;L--)
		for (int R = L;R <= n;R++) 
			if (R != L) {
				LL mn = LINF;
				for (int i = R - 1;i >= L;i--)
					mn = min(mn, dp[L][i] + dp[i + 1][R]);
				dp[L][R] = mn + pr[R] - pr[L - 1];
			}

	printf("%lld\n", dp[1][n]);
}

Measured memory_bytes: 4492
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A = int(readline())
    B = int(readline())
    C = int(readline())
    D = int(readline())
    
    print(min(A,B)+min(C,D))


if __name__ == '__main__':
    main()


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

ans = 0
min = 0
max = n

for i in range(m):
    l,r = map(int, input().split())

    if l > min:
        min = l
    
    if r < max:
        max = r

ans = max - min + 1

if ans < 0:
    ans = 0

print(ans)

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, inf = 1000111222, mod = 1000000007;

vector<int> m;
int dp[max_n];
int n;
int sum[max_n];

int main()
{
    //freopen("input.txt", "r", stdin);
    m.PB(-1);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (m.back() != a) {
            m.push_back(a);
        }
    }
    n = m.size();
    dp[0] = 1;
    for (int i = 1; i < m.size(); ++i) {
        int cur = m[i];
        dp[i] = (dp[i - 1] + sum[cur]) % mod;
        sum[cur] += dp[i - 1];
        sum[cur] %= mod;
    }
    cout << dp[n - 1] << endl;
    return 0;
}




Measured memory_bytes: 2676