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

int n;
vector<pair<int,string> > op,cl,bl;

void process(string s){
	int o = 0,c = 0;
	for(int i=0;i<(int)s.size();i++){
		if(s[i] == '(')o++;
		else c++;
	}
	if(o > c) op.push_back({c,s});
	if(o < c) cl.push_back({o,s});
	if(o == c)bl.push_back({0,s});
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n;
	for(int i=0;i<n;i++){
		string x;
		cin>>x;
		process(x);
	}
	
	sort(op.begin(),op.end());
	sort(cl.begin(),cl.end());
	reverse(cl.begin(),cl.end());
	
	string tot = "";
	for(int i=0;i<(int)op.size();i++){
		tot += op[i].second;
	}
	
	for(int i=0;i<(int)bl.size();i++){
		tot += bl[i].second;
	}
	
	for(int i=0;i<(int)cl.size();i++){
		tot += cl[i].second;
	}
	
	int cnt = 0;
	for(int i=0;i<(int)tot.size();i++){
		if(tot[i] == '(')cnt++;
		else cnt--;
		if(cnt < 0){
			cout<<"No";
			return 0;
		}
	}
	//cout<<tot<<endl;
	//cout<<cnt<<endl;
	if(cnt == 0)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 45228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
#define N 1e9+10;
ll n,m,i,j,k,t,l,r;
ll a,b,c,d;
char A,C,X,Y,Z;
ll ans,MAX,MIN,sum[2000000];
ll ax[2000500];
char cx[500];
ll dx[12];
ll bx[500];


int main()
{
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
        for(i=1;i<=1e6;i++)
        {
            if(i%5==0||i%3==0)    sum[i]=0+sum[i-1];
            else sum[i]=sum[i-1]+i;
        }
        scanf("%lld",&n);
        printf("%lld\n",sum[n]);
    }
	return 0;
}

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

int main(void){
  int N, max = 0;
  long long temp, before;
  cin >> N;
  int count = 0;
  cin >> before;
  for (int i = 1; i < N; i++){
    cin >> temp;
    if(before >= temp){
      count++;
    }
    else{
     count = 0;
    }
    if(count > max) max = count;
      
    before = temp;
  }
  cout << max << endl;
 return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[101][101];
	memset(a,0,sizeof(a));
	cin>>n;
	int u,k;
	for(int i = 0;i < n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			int x;
			cin>>x;
			x--;
			a[u][x]=1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j)cout<<" ";
			cout<<a[i][j];
		}
		cout<<endl;
	}
} 


Measured memory_bytes: 3128
#include <stdio.h>
#include <string.h>
#include <map>
#include <set>

typedef unsigned long long ull;
const ull H=300031;
const int SZ=300000;                // need SZ > n
//const ull H=10;
//const int SZ=6;
const int INF=0x3f3f3f3f;

ull h0,h1,h2;

int n;
char s[SZ];

ull hashes[SZ*2+5];
ull shash[SZ];
int p;

// if the interval [i,zerojump[i]) is eaten, then result is 0 everywhere
// also zerojump[i]>=i and zerojump is minimal
std::map<ull,int> m;
int zerojump[SZ];
int extraans[SZ];

std::map<ull,int> m2;       // answer search
std::set<int> s2[SZ];
std::set<int>::iterator it;

long long ans=0;

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    hashes[0]=1;
    for (int i=1; i<=SZ*2; i++) {
        hashes[i]=hashes[i-1]*H;
    }
    scanf("%d",&n);
    scanf(" %s",s);
    // get zerojump
    int p=0;
    h1=h2=0;
    memset(zerojump,0x3f,sizeof zerojump);
    m2[0]=0;
    s2[0].insert(0);
    m[0]=0;
    for (int i=0; i<n; i++) {
        // do the action
        if (s[i]=='<') p--;
        else if (s[i]=='>') p++;
        else if (s[i]=='+') {
            h1+=hashes[p+SZ];
        }
        else {
            h1-=hashes[p+SZ];
        }
        shash[i+1]=h1;
        h2=h1*hashes[SZ];
        // zerojump logic
        if (m.count(h1)) {
            zerojump[m[h1]]=i+1;
            m[h1]=i+1;
            s2[m2[h2]].insert(i+1);
        }
        else {
            m[h1]=i+1;
            m2[h2]=i+1;
            s2[i+1].insert(i+1);
        }
        //printf("s2 %d insert %d\n",m2[h2],i+1);
    }
    // fill in extraans
    extraans[n]=1;
    for (int i=n-1; i>=0; i--) {
        if (zerojump[i]==INF) extraans[i]=1;
        else extraans[i]=1+extraans[zerojump[i]];
    }
    // get answer
    // note: shash[n] is the final hash value wanted
    for (int i=0; i<SZ; i++) {
        if (s2[i].empty()) continue;
        s2[i].insert(INF);
    }
    p=SZ;
    //for (auto aa:m2) printf("h2      %lld %d\n",aa);
    //for (int i=0; i<=n; i++) printf("sh %d %lld\n",i,shash[i]);
    for (int i=0; i<n; i++) {
        h2=(shash[n]*hashes[p]+shash[i]*hashes[SZ]);
        //printf("go find %lld\n",h2);
        if (m2.count(h2)) {
            it=s2[m2[h2]].lower_bound(i+1);
            //printf("index %d got %d\n",i,*it);
            if ((*it)!=INF) {
                //printf("extraans %d\n",extraans[*it]);
                ans+=extraans[*it];
            }
        }
        if (s[i]=='<') p--;
        else if (s[i]=='>') p++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 78592
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
typedef pair<int, int> P;
int x[501];
int cnt[500];
int ans[500 * 500 + 1];
int main() {
	int N;
	cin >> N;
	vector<P> order;
	for (int i = 1; i <= N; i++) {
		cin >> x[i];
		ans[x[i]] = i;
		order.emplace_back(x[i], i);
	}
	sort(order.begin(), order.end());
	for (int i = 0; i < N; i++) {
		cnt[i] = order[i].second;
		if (i > 0) cnt[i] += cnt[i - 1];
		if (cnt[i] > order[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		cnt[i] = N - order[i].second + 1;
		if (i + 1 < N) cnt[i] += cnt[i + 1];
		if (cnt[i] > N*N - order[i].first + 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	priority_queue < int, vector<int>, greater<int>> Q1;
	for (int i = 1; i <= N * N; i++) {
		if (ans[i] == 0) {
			Q1.push(i);
		}
		else {
			for (int j = 0; j < ans[i] - 1; j++) {
				ans[Q1.top()] = ans[i];
				Q1.pop();
			}
		}
	}
	priority_queue<int> Q2;
	while (!Q1.empty()) {
		Q2.push(Q1.top());
		Q1.pop();
	}
	for (int i = N - 1; i >= 0; i--) {
		for (int j = 0; j < N - order[i].second; j++) {
			ans[Q2.top()] = order[i].second;
			Q2.pop();
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i <= N * N; i++) cout << ans[i] << " ";
	cout << endl;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	map<string,ll> m;
	rep(i,n){
		string s;cin >> s;
		sort(all(s));
		m[s]++;
	}
	ll ans = 0;
	for(auto i : m){
		ans += i.second * (i.second - 1) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010];
int main(){
    ll n, h;
    while(cin>>h>>n){
        ll ans=0, sm=0;
        for(int i=0; i<n; ++i){
            scanf("%lld",a+i);
            sm+=a[i];
        }
        if(sm>=h){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
  return 0;
}




Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    x=I()
    if x<1200:
        print("ABC")
    else:
        print("ARC")

main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,r;
  while(cin>>n>>r,n!=0||r!=0){
  int A[n];
  rep(i,n){
    A[i]=n-i;
  }
  rep(i,r){
    int p,c;
    cin>>p>>c;
    vector<long long> v(c);
    for(int j=p-1;j<p+c-1;j++){
      v[j-(p-1)]=A[j];
    }
    for(int j=p-2;j>=0;j--){
      A[j+c]=A[j];
    }
    for(int j=0;j<c;j++){
      A[j]=v[j];
    }
  }
  cout<<A[0]<<endl;
  }
 return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int n,x,ans,a[105];
int main()
{
	scanf("%d%d",&n,&x);
	for(RI i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(RI i=1;i<n;++i)
		if(x>=a[i]) x-=a[i],++ans;
	if(x==a[n]) ++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string n;
	while(cin>>n)
	{
		if(n=="SUN")
		cout<<7<<endl;
		else if(n=="MON")
		cout<<6<<endl;
		else if(n=="TUE")
		cout<<5<<endl;
		else if(n=="WED")
		cout<<4<<endl;
		else if(n=="THU")
		cout<<3<<endl;
		else if(n=="FRI")
		cout<<2<<endl;
		else if(n=="SAT")
		cout<<1<<endl;
	}
	return 0;
 } 

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

int arr[100010];

int main()
{
    int n;
    read(n);
    for(int i=1; i<=n; ++i) read(arr[i]);
    ll s=accumulate(arr+1, arr+n+1, 0LL);
    ll unit = ll(n)*(n+1)/2;
    if(s%unit) puts("NO"), exit(0);
    ll cnt = s/unit;
    for(int i=1; i<=n; ++i){
		int cur=arr[i], nxt=arr[i%n+1];
		ll tmp=nxt-cur-cnt;
		if(abs(tmp) % n) puts("NO"), exit(0);
		if(tmp > 0) puts("NO"), exit(0);
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main(){
  char S[10],T[10],U[10];
  int A,B;
  scanf("%s %s",S,T);
  scanf("%d %d",&A,&B);
  scanf("%s",U);
  
  if(strcmp(S,U)==0) A=A-1;
  else B=B-1;
  printf("%d %d",A,B);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;

string s;
string mozi;

int main()
{
	cin >> s;
	int ind;
	for(int i=0; i<s.size(); i++){
		mozi=s[i];
		if(mozi == "C"){
			ind = i;
			break;
		}
		if(i==s.size()-1){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=ind; i<s.size(); i++){
		mozi=s[i];
		if(mozi == "F"){
			cout << "Yes" << endl;	
			return 0;
		}
		if(i==s.size()-1){
			cout << "No" << endl;
			return 0;
		}
	
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    //MLE解消できず,他の人の解法をコピー
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    S = S.replaceAll("eraser", "@");
    S = S.replaceAll("erase", "@");
    S = S.replaceAll("dreamer", "@");
    S = S.replaceAll("dream", "@");
    S = S.replaceAll("@", "");
    if (S.length() == 0){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 30316
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  // {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  // {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int H, W; cin >> H >> W;
  vector<string> t(H); REP (i, H) cin >> t[i];
  auto valid = [&](ii p) {
    return 0 <= p.fi && p.fi < H && 0 <= p.se && p.se < W;
  };
  auto dp = make_vec<int>(H, W, -1);
  queue<ii> q;
  REP (i, H) {
    REP (j, W) {
      if (t[i][j] == '#') q.push({i, j}), dp[i][j] = 0;
    }
  }
  int ans = 0;
  while (!q.empty()) {
    ii p = q.front(); q.pop();
    for (auto dir: dirs) {
      ii p2 = {p.fi + dir.fi, p.se + dir.se};
      if (valid(p2) && dp[p2.fi][p2.se] == -1) {
        dp[p2.fi][p2.se] = dp[p.fi][p.se] + 1;
        q.push(p2);
        chmax(ans, dp[p2.fi][p2.se]);
      }
    }
  }
  cout << ans << endl;
}


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

struct Graph {
  int n;
  int time;
  vector<vector<int>> g;
  vector<int> num, low;
  vector<vector<int>> scc;
  stack<int, deque<int>> S;
  vector<bool> inS;

  Graph(int n) : n(n), g(n), num(n, -1), low(n, -1), inS(n) {}

  void addEdge(int u, int v) {
    g[u].push_back(v);
  }
  void dfs(int u) {
    num[u] = low[u] = time++;
    S.push(u);
    inS[u] = true;
    for (auto&& v : g[u]) {
      if (num[v] == -1) {
        dfs(v);
        low[u] = min(low[u], low[v]);
      } else if (inS[v]) {
        low[u] = min(low[u], num[v]);
      }
    }
    if (low[u] == num[u]) {
      scc.push_back({});
      while (true) {
        int v = S.top(); S.pop();
        inS[v] = false;
        scc.back().push_back(v);
        if (u == v) break;
      }
    }
  }
  void stronglyConnectedComponents() {
    for (int i = 0; i < n; ++i) {
      if (num[i] == -1) dfs(i);
    }
  }
};

int main() {
  int n, m; cin >> n >> m;
  Graph g(n);
  while (m--) {
    int s, t; cin >> s >> t;
    g.addEdge(s, t);
  }

  g.stronglyConnectedComponents();
  vector<int> id(n);
  for (int i = 0; i < g.scc.size(); ++i) {
    for (auto&& x : g.scc[i]) id[x] = i;
  }

  int q; cin >> q;
  while (q--) {
    int u, v; cin >> u >> v;
    cout << (id[u] == id[v]) << endl;
  }
  return 0;
}



Measured memory_bytes: 4412
#include<stdio.h>
#include<math.h>
int main()
{
	double v, t, y;
	int N;
	while(scanf("%lf", &v)>0) {
		t = v/9.8;
		y = 4.9*t*t;
		N=(int)ceil(y/5)+1;
		printf("%d\n", N);
	}
	return 0;
}

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int n,m;
	float sum = 0;
	float border;
	cin >> n >> m;
	vector<int> a(n);
	for( int i=0; i<n; i++ ){
		cin >> a[i];
		sum += a[i];
	}

	border = sum / ( 4 * m );

	sort( all(a), greater<int>() );

	for( int i=0; i<m; i++ ){
		if( a[i] < border ){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    ll dp[n];
    memset(dp,1e9+5,sizeof(dp));
    dp[0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        Scanner ir=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        for(;;){
            int n=ir.nextInt();
            int m=ir.nextInt();
            if(n==0&&m==0){
                break;
            }
            int[] ma=new int[m+1];
            for(int i=0;i<n;i++){
                int d=ir.nextInt();
                int v=ir.nextInt();
                ma[d]=Math.max(ma[d],v);
            }
            long tot=0;
            for(int i=1;i<=m;i++){
                tot+=ma[i];
            }
            out.println(tot);
        }
        out.flush();
    }
}


Measured memory_bytes: 35116
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    total = 0
    for k, v in C.items():
        if v > 1:
            total += v * (v - 1) // 2

    for a in A:
        v = C[a]
        if v > 1:
            print(total - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2)
        else:
            print(total)


main()


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

int main()
{
  int X,N;
  cin >> X >> N ;
  vector<int>p(N);
  vector<int>kakunin(101,0);
  
  int ans=101;
  int ansi=5;
  
  for(int i=0;i<N;i++){
    cin >> p.at(i) ;
    kakunin.at(p.at(i)-1)=1;
  }
  
  for(int i=0;i<101;i++){
    int A;
    if(kakunin.at(i)==0){
    	A = X-i-1;
    	if(A<0)
      		A*=-1;
    	if(ans>A){
     		ans = A;
     		ansi = i+1;
    	}
    	else if(ans == A){
      		ansi=min(ansi,i+1);
    	}
    }
  }
  
 if(ans>=X)
   ansi = 0;
  
  cout << ansi << endl;
  
return 0;
}



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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl //　少数の精度を高くする出力

int main(){
    ll A,B,N;
    cin >> A >> B >> N;
    if (N < B) {
        cout << (A*N)/B - A*(N/B) << endl;
    }

    else {
        cout << (A*(B-1))/B - A*((B-1)/B) << endl;
    }
}

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

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



Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>

using namespace std;
const int mod=1000000007;

vector<int> st;
vector<long long int> v;

bool check(string s){
    string c;
    c=s;
    reverse(s.begin(), s.end());
    if (c==s) {
        return true;
    }
    return false;
}




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int n,m,k,q,d,x,l,a,b,c;
    string sl,s,sr;
    cin>>s;
    n=s.length();
    if (n==1) {
        cout<<"Yes\n";
        return 0;
    }
    n/=2;
    sl=s.substr(0,n);sr=s.substr(n+1,n);
    if (check(s)&&check(sl)&&check(sr)) {
        cout<<"Yes\n";
    }
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007
using namespace std;
int C[2005][2005];
int pre[2005][2005];
int mat[2005][2005];
int A,B;
int add(int a,int b)
{
    a+=b;
    if(a>=MOD)a-=MOD;
    return a;
}
int mult(int a,int b)
{
    return 1LL*a*b%MOD;
}
int main()
{
    for(int i=0;i<=2000;i++)
    {
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++)
            C[i][j]=add(C[i-1][j],C[i-1][j-1]);
    }
    for(int i=0;i<=2000;i++)
    {
        pre[i][0]=C[i][0];
        for(int j=1;j<=i;j++)
            pre[i][j]=add(pre[i][j-1],C[i][j]);
    }
    for(int i=0;i<=2000;i++)
        mat[i][0]=mat[0][i]=1;
    for(int i=1;i<=2000;i++)
    {
        for(int j=1;j<=2000;j++)
        {
            mat[i][j]=add(mat[i-1][j],pre[j-1][min(i,j-1)]);
        }
    }
    cin>>A>>B;
    int ans=0;
    for(int i=0;i<=A;i++)
    {
        for(int j=0;j<=min(A-i,B-1);j++)
        {
            ans=add(ans,mult(mat[i][j],C[B-1][j]));
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 47360
#include <stdio.h>
int main(void){
    int W,H;
    int i,j;
    while(1){
         
        scanf("%d %d ",&H,&W);
         if(H==0&&W==0)
         break;
    
         
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++){
                
                if((i+j)%2==0){
                    printf("#");
                }
                else if((i+j)%2==1){
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
        
    }
    return 0;
}


Measured memory_bytes: 2140
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main(){
	int n, o[256], in[256], x[256], s, a, c, r, ms, ma, mc;
	double ans, ins;
	while(1){
		cin >> n;
		if(!n) break;
		ans = 999;
		REP(i,n) cin >> in[i];
		REP(s,16){
			REP(a,16){
				REP(c,16){
					REP(i,256) x[i]=0;
					r=s;
					REP(i,n){
						r = (r*a+c) % 256;
						o[i] = (in[i]+r)%256;
						x[o[i]]++;
						//cout << o[i] << " ";
					}
					//cout << endl;
					ins = 0;
					REP(i,256)if(x[i]>0)ins += -((double)x[i]/(double)n) * log2((double)x[i]/(double)n);
					//cout << "H:" << ins << endl;
					if(ans>ins){
						ms = s;
						ma = a;
						mc = c;
						ans = ins;
					}
				}
			}
		}
		cout << ms << " " << ma << " " << mc << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

ll dp[1005][1005];

void add(ll &a, ll b) {
    a += b;
    if (a >= mod) a -= mod;
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    rep(i,h)rep(j,w) {
        if (i == 0 && j == 0) dp[i][j] = 1;
        if (i-1 >= 0 && field[i-1][j] != '#') add(dp[i][j],dp[i-1][j]);
        if (j-1 >= 0 && field[i][j-1] != '#') add(dp[i][j],dp[i][j-1]);
    }
    cout << dp[h-1][w-1] << endl;
}

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

int main(){
  vector<vector<int>> C(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> C.at(i).at(j);
    }
  }
  vector<int> B(3);
  for(int i=0;i<3;i++){
    B.at(i) = C.at(0).at(i);
  }
  vector<int> A(3);
  A.at(1) = C.at(1).at(0) - B.at(0);
  A.at(2) = C.at(2).at(0) - B.at(0);
  for(int i=1;i<3;i++){
    for(int j=1;j<3;j++){
      if(C.at(i).at(j) != A.at(i) + B.at(j)){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

template<typename T, int DEFAULT_SIZE=0, int DEFAULT_MOD=0>
struct BIT {
  int n;
  int mod;
  std::vector<T> d;

  BIT(int n=DEFAULT_SIZE, int mod=DEFAULT_MOD) : n(n), mod(mod), d(n+1) {}

  void init(int size) {
      n = size;
      d = std::vector<T>(size);
  }

  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
      if (mod) {
          d[i] %= mod;
      }
    }
  }

  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
      if (mod) {
          x %= mod;
      }
    }
    return x;
  }

  T range(int from, int to) {
      T x = sum(to) - sum(from-1);
      if (mod) {
          x = (x + mod) % mod;
      }
      return x;
  }

  T val(int i) {
      return range(i, i);
  }
};

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);

    BIT<int> bit(1020);
    rep(i, N) {
        cin >> L[i];
        bit.add(L[i]);
    }

    sort(L.begin(), L.end(), greater<int>());

    LL ans = 0;

    //! suppose c <= b < a   =>  a < b+c  => c > a-b
    for (int i = 0; i < N-2; ++i) {
        int a = L[i];
        for (int j = i+1; j < N-1; ++j) {
            int b = L[j];
            if (a < b + b) {
                int minC = a - b + 1;
                //! exclude a, b, b
                ans += bit.range(minC, b-1);
                if (a < b + b) {
                    //! count a, b, b case 
                    for (int k = j+1; k < N && L[k] == b; ++k) {
                        ++ans;        
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;

  ll n = N;
  ll sum = 0LL;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }

  bool judge = N % sum == 0;
  if (judge) print("Yes");
  else print("No");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    //int n;
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='?')s[i]='D';
    }
    cout << s << endl;
}

Measured memory_bytes: 3752
#from https://atcoder.jp/contests/abc137/submissions/6808061
import heapq
import sys
input=sys.stdin.readline

def sol():
    n,m=map(int,input().split())
    d=[]
    for i in range(n):
        a,b=map(int,input().split())
        if a<=m: d.append((a,b))
    d.sort(reverse=True)
    q=[]
    ans=0
    for i in range(1,m+1):
        while d and d[-1][0]<=i:
            a,b=d.pop()
            heapq.heappush(q,-b)
        if q:
            ans += -heapq.heappop(q)
    print(ans)

if __name__=="__main__":
    sol()

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

const int N = 101;
int n, m;
int X, Y;
char s[N][N];
short dp[N][N][N][N];
short hor[N][N];
short ver[N][N];

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

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		scanf(" %s ", s[i]);
		for (int j = 0; j < m; j++)
			if (s[i][j] == 'E')
			{
				X = i;
				Y = j;
				s[i][j] = '.';
			}
	}
	for (int i = 0; i < n; i++)
	{
		hor[i][0] = 0;
		for (int j = 0; j < m; j++)
		{
			hor[i][j + 1] = hor[i][j];
			if (s[i][j] == 'o')
				hor[i][j + 1]++;
		}
	}
	for (int i = 0; i < m; i++)
	{
		ver[0][i] = 0;
		for (int j = 0; j < n; j++)
		{
			ver[j + 1][i] = ver[j][i];
			if (s[j][i] == 'o')
				ver[j + 1][i]++;
		}
	}
	short ans = 0;
	for (int len1 = 0; len1 < n; len1++)
		for (int len2 = 0; len2 < m; len2++)
			for (int x1 = 0; x1 + len1 < n; x1++)
				for (int y1 = 0; y1 + len2 < m; y1++)
				{
					int x2 = x1 + len1, y2 = y1 + len2;
					ans = max(ans, dp[x1][x2][y1][y2]);

					int yL = max(0, y2 - Y), yR = min(m, m - (Y - y1));
					int xL = max(0, x2 - X), xR = min(n, n - (X - x1));
					if (x1 > xL)
						dp[x1 - 1][x2][y1][y2] = max((int)dp[x1 - 1][x2][y1][y2], dp[x1][x2][y1][y2] + (hor[x1 - 1][min(yR, y2 + 1)] - hor[x1 - 1][max(yL, y1)]));
					if (x2 < xR - 1)
						dp[x1][x2 + 1][y1][y2] = max((int)dp[x1][x2 + 1][y1][y2], dp[x1][x2][y1][y2] + (hor[x2 + 1][min(yR, y2 + 1)] - hor[x2 + 1][max(yL, y1)]));
					if (y1 > yL)
						dp[x1][x2][y1 - 1][y2] = max((int)dp[x1][x2][y1 - 1][y2], dp[x1][x2][y1][y2] + (ver[min(xR, x2 + 1)][y1 - 1] - ver[max(xL, x1)][y1 - 1]));
					if (y2 < yR - 1)
						dp[x1][x2][y1][y2 + 1] = max((int)dp[x1][x2][y1][y2 + 1], dp[x1][x2][y1][y2] + (ver[min(xR, x2 + 1)][y2 + 1] - ver[max(xL, x1)][y2 + 1]));
				}
	printf("%d\n", (int)ans);

	return 0;
}

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

using namespace std;

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

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int ar[n];
    memset(ar,0,sizeof(ar));
    int a,b;
    for(int ctr1 = 0; ctr1 < m; ctr1++) {
        cin>>a>>b;
        a--,b--;
        ar[a]++;
        ar[b]++;
    }
    for(int ctr1 = 0; ctr1 < n; ctr1++) {
        if(ar[ctr1] & 1){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 768
import sys
   
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
   
   
S = str(input())
P = str(input())
   
is_ok = False
   
for i in range(len(S)):
    FLG = True
    for k in range(len(P)):
        if S[(i+k)%(len(S))] != P[k]:
            FLG = False
            break
   
    if FLG == True:
        is_ok = True
        break
   
if is_ok == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5580
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  string s, t;
  int cnt = 0;
  cin >> s >> t;
  for (int i = 0; i < s.length(); ++i)
  {
    if (s[i] != t[i]) ++cnt;
  }
  cout << cnt;
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,q;
  cin>>n>>q;
  vector<vi> v(n,vi());
  while(q--){
    int t;
    cin>>t;
    if(t==0){
      int a,b;
      cin>>a>>b;
      v[a].PB(b);
    }else if(t==1){
      int a;
      cin>>a;
      rep(i,v[a].size()){
        if(i) cout<<' ';
        cout<<v[a][i];
      }
      cout<<endl;
    }else{
      int a;
      cin>>a;
      v[a].clear();
    }
  }

}


Measured memory_bytes: 8920
# AtCoder Beginner Contest111
N = gets.chomp.to_i
zorome = N
ans = 0
for i in 0..999-N do
    if N <= zorome + i && (zorome + i).to_s[0] == (zorome + i).to_s[1] && (zorome + i).to_s[0] == (zorome + i).to_s[2] && (zorome + i).to_s[1] == (zorome + i).to_s[2] 
        ans = zorome + i
        break
    end
end

puts ans

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef double db;
typedef pair <db, db> pdd;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=2e5+5;

int n;
ll c, h[N];
ll dp[N];
vector <pll> hull;
int ind=0;

int ccw(pdd a, pdd b, pdd c) {
    double ret=a.X*(b.Y-c.Y)+b.X*(c.Y-a.Y)+c.X*(a.Y-b.Y);
    if (ret>0) return 1;
    if (ret==0) return 0;
    return -1;
}

ll f(pll a, ll x) {
    return a.X*x+a.Y;
}

void dodaj(pll pp) {
    while ((int)hull.size()>1 && ccw(hull[(int)hull.size()-2], hull.back(), pp)>=0) hull.pop_back();
    hull.pb(pp);
    ind=min(ind, (int)hull.size()-1);
}

ll query(ll x) {
    while (ind<(int)hull.size()-1 && f(hull[ind], x)>f(hull[ind+1], x)) ++ind;
    return f(hull[ind], x);
}

void load() {
    scanf("%d %lld", &n, &c);
    for (int i=1; i<=n; ++i) scanf("%lld", h+i);
}

void solve() {
    dp[1]=0;
    dodaj(mp(-h[1]*2, h[1]*h[1]));
    for (int i=2; i<=n; ++i) {
        dp[i]=query(h[i])+c+h[i]*h[i];
//        printf("i: %d, ind: %d\n", i, ind);
        dodaj(mp(-h[i]*2, h[i]*h[i]+dp[i]));
    }
    printf("%lld\n", dp[n]);
}

int main() {
    load();
    solve();
    return 0;
}


Measured memory_bytes: 10488
#include<vector>
#include<algorithm>
using namespace std;
class LowLink{
private:
    vector<vector<int>> Graph;
    vector<bool> visited; 
    vector<int> order, low;

    void dfs(int u = 0 , int ord = 0, int par = -1){
        visited[u] = true;
        order[u] = ord;
        low[u] = ord;
        bool is_articulation = false;
        int deg = 0;
        for(int& v : Graph[u]){
            if(par == v) continue;
            if(visited[v] == false){
                deg++;
                dfs(v, ord+1, u);
                is_articulation |= (par != -1 && order[u] <= low[v]);
                low[u] = min(low[u], low[v]);
                if(order[u] < low[v]) bridge.emplace_back(make_pair(min(u, v), max(u,v)));
            } else {
                low[u] = min(low[u], order[v]);
            }
        }
        is_articulation |= (par == -1 && deg > 1);
        if(is_articulation) articulation.emplace_back(u);
    }
public:
    vector<int> articulation;
    vector<pair<int, int>> bridge;
    LowLink() = delete;
    LowLink(vector<vector<int>>& G) :  Graph(G){
        visited.assign(Graph.size(), false);
        order.resize(Graph.size());
        low.resize(Graph.size());
        dfs(); 
    }

    vector<int> get_articulation(){
        return articulation;
    }

    vector<pair<int,int>> get_bridge(){
        return bridge;
    }
};

#include<iostream>
int main(){
    int V, E, u, v;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for(int i = 0; i < E; i++){
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    LowLink lowlink(G);
    auto bridges = lowlink.get_bridge();
    sort(bridges.begin(), bridges.end());
    for(auto& v : bridges){
        cout << v.first << " " << v.second << endl;
    }
}


Measured memory_bytes: 5124
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	Scanner sc = new Scanner(System.in);
	final int NUM_CONTEST = 26;
	int D;
	int [] c  = new int[NUM_CONTEST];
	int [][] s ;
	int [] t ;
	int [] last_day;
	void B() {
		D = sc.nextInt();
		s = new int[D][NUM_CONTEST];
		for(int i = 0; i < NUM_CONTEST; i++) {
			c[i] = sc.nextInt();
		}
		for(int i = 0; i < D; i++) {
			for(int j = 0; j < NUM_CONTEST; j++) {
				s[i][j] = sc.nextInt();
			}
			//System.out.println(Arrays.toString(s[i]));
		}

		t = new int[D];
		last_day = new int[NUM_CONTEST];
		Arrays.fill(last_day, -1);
		for(int i = 0; i < D; i++) {
			t[i] = sc.nextInt() - 1;
		}
		long ans = 0;
		for(int d = 0; d < D; d++) {
			int inc = s[d][t[d]];
			last_day[t[d]] = d;
			int dec = 0;
			for(int i = 0; i < NUM_CONTEST; i++) {
				dec += c[i] * (d - last_day[i]);
			}
			//System.out.println(inc + " " + dec + " " + (inc - dec));
			ans += (inc - dec);
			System.out.println(ans);

		}
	}
	void doIt() {
		B();
	}
	public static void main(String[] args) {
		new  Main().doIt();
	}

}


Measured memory_bytes: 46548
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(vv) vv.begin(), vv.end()
 
using namespace std;
const ll maxn=1e6+100,inf=1e18,LOG=23,mod=1e9 + 7;
 
#define int ll

int n, dp[maxn], a[maxn];

main()
{
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	dp[1] = 0;
	dp[2] = abs(a[1] - a[2]);
	forn(3, i, n)
	{
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n];
}

Measured memory_bytes: 5120
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int>> prefs(n, vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      scanf("%d", &prefs[i][j]), --prefs[i][j];
  vector<int> current(n, 0);
  vector<bool> removed(m, false);
  int result = n;
  for (int remove_count = 0; remove_count <= m - 1; ++remove_count) {
    static vector<int> sport_count(m); sport_count.assign(m, 0);
    for (int i = 0; i < n; ++i)
      ++sport_count[prefs[i][current[i]]];
    int res = *max_element(sport_count.begin(), sport_count.end());
    result = min(result, res);

    if (remove_count + 1 <= m - 1) {
      int bottleneck = max_element(sport_count.begin(), sport_count.end()) -
                       sport_count.begin();
      removed[bottleneck] = true;
      for (int i = 0; i < n; ++i)
        while (removed[prefs[i][current[i]]])
          ++current[i];
    }
  }
  printf("%d\n", result);
  return 0;
}


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

int main(){
  int n,a;
  vector<int> x;
  int memory = 0;
  cin >> n >> a;
  for(int i=0;i<n;i++){
    int input;
    cin >> input;
    if(memory<input) memory = input;
    input -= a;
    x.push_back(input);
  }
  if(memory < a) memory = a;

  vector<vector<long long>> dp(n+1,vector<long long>(memory*n*2 + 1,0));
  dp.at(0).at(memory*n) = 1;

  for(int i=1;i<n+1;i++){
    for(int j=0;j<memory*n*2 +1;j++){
      if(j-x.at(i-1) >= 0 && j-x.at(i-1) <= 2*memory*n){
        dp.at(i).at(j) = dp.at(i-1).at(j-x.at(i-1)) + dp.at(i-1).at(j);
      }else{
        dp.at(i).at(j) = dp.at(i-1).at(j);
      }
    }
  }
  cout << dp.at(n).at(memory*n) - 1 <<endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;

const ll siz = 1e5 + 10;
const ll SIZ = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll maxx = 2e9;
const ll MAXX = 1e18;
const ll base = 31;

int x;
int temp;
int ans;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen ("IN_3.INP", "r", stdin);
//    freopen ("OUT_3.OUT", "w", stdout);
    cin >> x;
    temp = x / 500;
    ans += temp * 500;
    x -= ans;
    ans *= 2;
    temp = x / 5;
    ans += temp * 5;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n);
  ll sum = 0;
  ll sum2 = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    if (i & 1) {
      sum2 += a[i];
    }
  }
  sum = sum / 2;
  vl m(n, 0);
  m[0] = sum - sum2;
  REP(i, 1, n) { m[i] = a[i - 1] - m[i - 1]; }
  rep(i, n) {
    cout << 2 * m[i];
    if (i == n - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll a,b,m;
        cin>>a>>b>>m;
        vl A(a);
        vl B(b);
        rep(i,a)cin>>A[i];
        rep(i,b)cin>>B[i];
        ll cost=INF;
        rep(i,m){
            ll x,y,c;
            cin>>x>>y>>c;
            chmin(cost,A[x-1]+B[y-1]-c);
        }
        sort(all(A));
        sort(all(B));
        chmin(cost,A[0]+B[0]);
        cout<<cost<<endl;
    }

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define MAX_X (1000005)
 
void calcPrime(bool prime[])
{
    for ( int i = 2; i < MAX_X; i++ ) {
        prime[i] = true;
    }
 
    for ( int i = 2; i * i < MAX_X; i++ ) {
        if ( prime[i] ) {
            for ( int j = i * i; j < MAX_X; j += i ) {
                prime[j] = false;
            }
        }
    }
}
 
int main()
{
    int N, X;
    bool prime[MAX_X];
 
    calcPrime(prime);
 
    while ( cin >> N >> X, N || X ) {
        bool dp[MAX_X] = {};
 
        dp[0] = true;
        for ( int i = 0; i < N; i++ ) {
            int v;
            cin >> v;
            for ( int j = 0; j <= X; j++ ) {
                if ( dp[j] && j + v <= X ) {
                    dp[j + v] = true;
                }
            }
        }
        int k = X;
        while ( k > 0 && (!prime[k] || !dp[k]) ) {
            k--;
        }
        if ( k > 0 ) {
            cout << k << endl;
        } else {
            cout << "NA" << endl;
        }
    }
 
    return (0);
}


Measured memory_bytes: 5048