akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			int[] h = new int[n];
			for(int i = 0 ; i < n ; i++) {
				h[i] = sc.nextInt();
			}
			int[] dp = new int[n];
			for(int i = 0 ; i < n ; i++) {
				if(i == 0) {
					dp[i] = 0;
				} else if(i == 1) {
					dp[i] = dp[i - 1] + Math.abs(h[i - 1] - h[i]);
				} else {
					dp[i] = Math.min(dp[i - 2] + Math.abs(h[i - 2] - h[i]), dp[i - 1] + Math.abs(h[i - 1] - h[i]));
				}
			}
			System.out.println(dp[n - 1]);

		}
	}
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int n;
  string s;

  cin >> n;
  getline(cin, s);
  REP(i, n) {
    getline(cin, s);
    while(1) {
      string::size_type index = s.find("Hoshino");
      if(index == string::npos) break;
      else s.replace(index, 7, "Hoshina");
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1208
import java.util.*;

public class Main{
  public static void main( String args[] ){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    ArrayList<ArrayList<Integer>> e = new ArrayList<ArrayList<Integer>>();
    for( int i = 0; i < N; i++ ){
      e.add(new ArrayList<Integer>());
    }
    
    int u,v;
    for( int i = 0; i < M; i++ ){
      u = sc.nextInt()-1;
      v = sc.nextInt()-1;
      e.get(u).add(v);
      e.get(v).add(u);
    }
    
    int[] s = new int[N];
    for( int i = 0; i < N; i++ ){ s[i] = -1; };
    Queue<Integer> q = new ArrayDeque<>();
    
    q.add(0);
    s[0] = 0;
    
    while(!q.isEmpty()){
      int from = q.poll();
      for( int to : e.get(from) ){
        if( s[to] == -1 ){
          q.add(to);
          s[to] = from;
        }
      } 
    }
    
    System.out.println("Yes");
    
    for( int i = 1; i < N; i++ ){
      System.out.println(s[i]+1);
    }
    
  }
}

Measured memory_bytes: 74912
#include <iostream>
#include <string>
typedef long long ll;
//#include <algorithm>
using namespace std;

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

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

  bool isundern = false;
  for(int i = 0; i < 5; i++){
    if(trans[i] < n){
      isundern = true;
      break;
    }
  }
  if(!isundern){
    cout << 5 << endl;
    return 0;
  }

  ll mintrans = 100000000000000000;
  for(int i = 0; i < 5; i++){
    if(trans[i] < mintrans){
      mintrans = trans[i];
    }
  }

  ll mintranstime;
  if(n % mintrans == 0){
    mintranstime = n / mintrans;
  }else{
    mintranstime = (n / mintrans + 1);
  }



  cout << (mintranstime + 4) << endl;


}


Measured memory_bytes: 256
//abc073_d.cpp
//Sun Sep 30 12:36:08 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
struct edge {int to, cost;};

vector<edge> G[200];
int d[200];
int v,e;

void dijkstra (int s){
	priority_queue<P, vector<P>, greater<P>> pq; //小さい順 
	fill (d,d+v,INTINF);
	d[s] = 0;
	pq.push(P(0,s));
	while(!pq.empty()){
		P p = pq.top();
		pq.pop();
		int vtemp = p.second;
		if (d[vtemp] < p.first){
			continue;
		}
		for (int i=0;i<G[vtemp].size();i++){
			edge e = G[vtemp][i];
			if (d[e.to] > d[vtemp] + e.cost){
				d[e.to] = d[vtemp] + e.cost;
				pq.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
	int r;
	cin >> v >> e >> r;

	int visittown[r];
	for (int i=0;i<r;i++){
		cin >> visittown[i];
		visittown[i]--;
	}

//	int a[m],b[m],c[m];

	for (int i=0;i<e;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;
		b--;
		edge temp;
		temp.to = b;
		temp.cost = c;
		G[a].push_back(temp);
		temp.to = a;
		G[b].push_back(temp);
	}

//	cout << G[2][1].cost << endl;
	int gotown[r][r];
	for (int i=0;i<r;i++){
		dijkstra(visittown[i]);
		for (int j=0;j<r;j++){
			gotown[i][j] = d[visittown[j]];
//			cout << d[visittown[j]];
//			cout << visittown[j];
		}
//		printf("\n");
	}
//	printf("\n");

	int a[r];
	for (int i=0;i<r;i++){
		a[i] = i;
	}
	int ans = INTINF;
	do {
		int tempdir = 0;
		for (int i=0;i<r;i++){
			if (i>0){
				tempdir += gotown[a[i-1]][a[i]];
			}
//			cout << a[i] << " ";
		}
		if (ans > tempdir){
			ans = tempdir;
		}
//		cout << tempdir;
//		printf("\n");
	} while (next_permutation(a,a+r));

	cout << ans << endl;
}

Measured memory_bytes: 768
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k
    real(8)::a,b
    integer(8),allocatable::x(:)
    
  
    read(*,*) n,k
    allocate(x(n))
    read(*,*)x
    call msort(x)
    m=0
    do i=1,k
        m=m+x(i)
    end do
    write(*,*)m
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
 

end program sample
  



Measured memory_bytes: 2864
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    if (N == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        int flag = -1;
        string ans = "";
        while (N != 0)
        {
            if (abs(N) % 2 == 1)
            {
                ans = "1" + ans;
                N = (N + flag) / 2;
            }
            else
            {
                ans = "0" + ans;
                N /= 2;
            }
            flag *= -1;
        }
        cout << ans << endl;
    }
}

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

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

    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a.at(i);
    }

    ll ans = 0;
    for (int i = 1; i < N; ++i) {
        if (a.at(i - 1) + a.at(i) > x) {
            int res = a.at(i - 1) + a.at(i) - x;
            ans += res;
            a.at(i) = max(0, a.at(i) - res);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>

int main() {
	int t;
	std::cin >> t;
	std::vector<int> space;
	space.reserve(100000);

	for (int i = 0; i < t; ++i) {
		int n, k;
		std::cin >> n >> k;
		if (k >= n) {
			//テゥツ?ゥテ・ツスツ禿」ツ?ォテ、ツクツ?・ツ崢榲・ツ?・テ・ツ環崚」ツ?凖」ツつ?
			for (int j = 0; j < n; ++j)
				std::cin >> k;
			std::cout << 0 << std::endl;
			continue;
		}

		space.resize(n - 1);
		int before_pos, road_size, first_pos;
		std::cin >> before_pos;
		first_pos = before_pos;
		for (int j = 1; j < n; ++j) {
			int new_pos;
			std::cin >> new_pos;

			if (j == n - 1)
				road_size = new_pos;

			space[j - 1] = new_pos - before_pos;
			before_pos = new_pos;
		}

		std::sort(space.begin(), space.end(), std::greater<int>());

		std::cout << road_size - first_pos - std::accumulate(space.begin(), space.begin() + k - 1, 0) << std::endl;

		space.clear();
	}
}

Measured memory_bytes: 3140
import sys
from collections import deque, defaultdict
import heapq

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()

# Aでxの根を求める
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    # 根をbxに統一
    A[by] = bx

edges = [[] for _ in range(N)]
V = [i for i in range(N)]
for _ in range(M):
    x, y = lr()
    if find(V, x) != find(V, y):
        union(V, x, y)
    edges[x].append(y)
    edges[y].append(x)

for i in range(N):
    V[i] = find(V, i)

if M == N - 1:
    print(0); exit()
elif N < 2 * (N-M-1):
    print('Impossible'); exit()

root_point = defaultdict(list)
for i in range(N):
    r = V[i]
    heapq.heappush(root_point[r], A[i])

#各グループの最小値以外で使うコストの数
answer = 0
candidates = []
for p_list in root_point:
    answer += heapq.heappop(root_point[p_list])
    candidates.extend(root_point[p_list])

remain = 2 * (N-M-1) - len(set(V))
candidates.sort()
answer += sum(candidates[:remain])
print(answer)


Measured memory_bytes: 35616
#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; }

const ll INF = 2e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, c, k;
	cin >> n >> c >> k;
	vector<ll> t(n);
	rep(i,n) cin >> t[i];
	sort(t.begin(), t.end());
	ll time = 0, cnt = 0, ans = 0;
	rep(i,n){
		if(cnt == 0){
			++ans;
			cnt = c - 1;
			time = t[i] + k;
		}
		else --cnt;
		if(time < t[i]){
			++ans;
			cnt = c - 1;
			time = t[i] + k;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define deb(a) cout << a << ": "
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
const int MAXN = 1e7 + 1;
int spf[MAXN];
void sieve() 
{ 
	spf[1] = 1; 
	for (int i=2; i<MAXN; i++) 
		// marking smallest prime factor for every 
		// number to be itself. 
		spf[i] = i; 

	// separately marking spf for every even 
	// number as 2 
	for (int i=4; i<MAXN; i+=2) 
		spf[i] = 2; 

	for (int i=3; i*i<MAXN; i++) 
	{ 
		// checking if i is prime 
		if (spf[i] == i) 
		{ 
			// marking SPF for all numbers divisible by i 
			for (int j=i*i; j<MAXN; j+=i) 
				// marking spf[j] if it is not 
				// previously marked 
				if (spf[j]==j) 
					spf[j] = i; 
		} 
	} 
} 
void sliczny() {
    sieve();
    int n;
    int ans = 0;
    cin >> n;
    for(int i=1; i<=n; i++) {
        map<int, int> cnt;
        int cur = 1;
        int x = i;
        while(x != 1) {
            cnt[spf[x]]++;
            x /= spf[x];
        }
        for(auto it : cnt) {
            cur *= (it.S + 1);
        }
        ans += i * cur;
    }
    cout << ans << '\n';
}

int32_t main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    //cin >> T; 
    for(int t = 1; t <= T; t++) {
        //cout << "Case #" << t << ": ";
        sliczny();
    }
    return 0;
}


Measured memory_bytes: 81780
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
  if (i > j) swap(i,j);
  return id[i][j];
}
 
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int v) {
  if (visited[v]) {
    if (!calculated[v]) return -1;
    return dp[v];
  }
  visited[v] = true;
  dp[v] = 1;
  for (int u : to[v]) {
    int res = dfs(u);
    if (res == -1) return -1;
    dp[v] = max(dp[v], res+1);
  }
  calculated[v] = true;
  return dp[v];
}
 
int main() {
  int n;
  cin >> n;
  vector< vector<int> > a(n, vector<int>(n-1));
  rep(i,n) {
    rep(j,n-1) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int V = 0;
  rep(i,n)rep(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      a[i][j] = toId(i,a[i][j]);
    }
    rep(j,n-2) {
      to[a[i][j+1]].push_back(a[i][j]);
    }
  }
  int ans = 0;
  rep(i,V) {
    int res = dfs(i);
    if (res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 38528
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  //int num=b-a;
  if((b-a)%2){
    cout<<"Borys"<<endl;
  }else{
    cout<<"Alice"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	int i,j,k;
	int a[101][101];
	int b[101];
	cin>>n>>m;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}
	for(i=0;i<n;i++){
		int sum=0;
		for(j=0;j<m;j++){
			sum+=a[i][j]*b[j];
		}
		cout<<sum<<endl;
	}
	return 0;
}


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

int main(){

  string S;
  cin >> S;
  long long len = S.length();

  long long count = 0;

  vector<long long> mod(2019,0);

  long long nowNum = 0;
  long long digit = 1;
  long long nowMod = nowNum%2019;
  mod[nowMod]++;
  for(long long i=len-1;i>=0;i--){
    nowNum = (nowNum + (S[i]-'0')*digit)%2019;
    digit = (digit*10)%2019;
    mod[nowNum%2019]++;
  }

  for(long long i=0;i<2019;i++){
    if(mod[i] <= 0) continue;
    else{
      count += mod[i]*(mod[i]-1)/2;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n ,ans,i;
	cin >> n;
	ans = n;
	for (i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				n /= i;
			}
			ans = ans  - ans / i;
		}
	}
	if (n > 1) ans = ans - ans / n;
	cout << ans<<endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b - 1);
    cout << a * x / b - a * (x / b) << endl;
}

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


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define MAXN 100005

const int inf=0x3f3f3f3f;

using namespace std;

struct edge{
	int next,to,v;
}e[MAXN<<1];

int n,tot,head[MAXN],dist[MAXN];
bool vis[MAXN];

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

void bfs(){
	memset(dist,inf,n*sizeof(dist[0]));
	memset(vis,0,n*sizeof(vis[0]));
	deque<int> q;
	dist[1]=1;
	q.push_back(1);
	while(!q.empty()){
		int u=q.front();q.pop_front();
		if(vis[u]) continue;
		vis[u]=1;
		for(int p=head[u];p;p=e[p].next){
			int v=e[p].to;
			if(dist[v]>dist[u]+e[p].v){
				dist[v]=dist[u]+e[p].v;
				if(e[p].v) q.push_back(v);
				else q.push_front(v);
			}
		}
	}
}

int main(){
	scanf("%d", &n);
	tot=0;
	memset(head,0,n*sizeof(head[0]));
	for(int i=1;i<=n-1;i++){
		add(i,(i+1)%n,1);
		add(i,i*10%n,0);
	}
	bfs();
	printf("%d\n",dist[0]);
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;

public class Main {
	long[][][] dp = new long[10][101][1001];
	
	void init(){
		for(int i=0;i<10;i++){
			for(int j=0;j<101;j++){
				for(int k=0;k<1001;k++){
					dp[i][j][k] = -1;
				}
			}
		}
	}
	
	long loop(int n, int x, int s){
		if(n==0 && s==0) return 1;
		if(n<0 || x<0 || s<0) return 0;
		if(dp[n][x][s]>=0) return dp[n][x][s];
		
		long sum = 0;
		for(int i=x;i>=0;i--){
			sum += loop(n-1,i-1,s-i);
		}
		dp[n][x][s] = sum;
		return dp[n][x][s];
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		init();
		while(true){
			int n = sc.nextInt();
			int s = sc.nextInt();
			if(n==0 && s==0) break;
			System.out.println(loop(n,100,s));
		}
	}
	
		
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 29740
int check(int a[12]){ //adapted from rummy card game :p
	int i=1;
	for(;i<10;i++){
		a[i]%=3;
		if(a[i]>0){
			if(a[i+1]-a[i]<0 || a[i+2]-a[i]<0)return 0;
			a[i+1]-=a[i];a[i+2]-=a[i];a[i]=0;
		}
	}
	return 1;
}

int main(){
	char S[16];
	for(;~scanf("%s",S);){
		int x[12],y[12],i=0,j,count=0;
		memset(x,0,sizeof(x));
		for(;i<13;i++)x[S[i]-'0']++;
		for(i=1;i<10;i++){
			if(x[i]>3)continue;
			x[i]++;
			for(j=1;j<10;j++){ //head is j?
				if(x[j]<2)continue;
				memcpy(y,x,sizeof(x));
				y[j]-=2;
				if(check(y)){
					if(count)putchar(' ');
					printf("%d",i);
					count++;
					break;
				}
			}
			x[i]--;
		}
		puts(count?"":"0");	
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
    // Your code here!
    long a,b,r,x;
    while(scanf("%ld %ld\n",&a,&b)!=EOF){
        r=a*b;
        for( ;b!=0;){
            x=a%b;
            a=b;
            b=x;
            
        }
        printf("%ld %ld\n",a,r/a);
    }
    
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
struct edge
{
    int u,v,w;
};
vector <edge> ans;

int n,L;

int main()
{
   // freopen("file.inp","r",stdin);
    cin >> L;
    if (L == 2)
    {
        cout << "2 2" << endl;
        cout << "1 2 0" << endl;
        cout << "1 2 1" << endl;
        return 0;
    }
    L--;
    int d = 1;
    while (4 * d <= L)
    {
        d <<= 1;
    }
    for (int i = 1; i <= 19; i++)
    {
        ans.push_back({i, i + 1, d});
        ans.push_back({i, i + 1, 0});
        d >>= 1;
        n = i + 1;
        if (d == 0) break;
    }
    d = 1;
    while (2 * d <= L)
    {
        d <<= 1;
    }
    for (int i = 1 ; n - i - 1 >= 0; i++)
    {
        if (((L >> (n - i - 1)) & 1) == 1)
        {
            ans.push_back({1, i + 1, d});
            d += 1 << (n - i - 1);
        }
    }
    ans.push_back({1, n, L});
    cout << n << " " << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i].u << " " << ans[i].v << " " << ans[i].w << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n;
	ll a, b;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans+=i*(i+1)/2;
	}
	REP(i,n-1){
		cin >> a >> b;
		if(a>b)
			swap(a,b);
		ans-=a*(n-b+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]

u = [-1] * (n + 1)

def find(v):
    if u[v] < 0:
        return v
    else:
        return find(u[v])

total = n * (n - 1) // 2
ans = [total]

for a, b in reversed(ab[1:]):
    af = find(a)
    bf = find(b)
    af, bf =sorted([af, bf])
    if af != bf:
        total -= u[af] * u[bf]
        u[af] += u[bf]
        u[bf] = af
    ans.append(total)

for a in reversed(ans):
    print(a)

Measured memory_bytes: 22420
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
    int n,tmp,count = 0;
    int lim;
    cin>>n;

    for(int i = 0; i < n; i++)
    {
        cin>>tmp;
        lim = sqrt(tmp);
        for(int j=2;j<=lim;j++){
            if(tmp%j==0){
                count++;
                break;
            }
        }
    }
    cout<<n-count<<"\n";
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

using Facts = map<ll, int>; 
void factrize(ll n, Facts& mp) {
  if(n < 2) return;
  ll m = sqrt(n);
  REP(i, 2, m+1) {
    int cnt = 0;
    while(n%i == 0) {
      n /= i;
      ++cnt;
    }
    if(cnt != 0) mp[i] += cnt;
  }
  if(n != 1) mp[n]++;
}

ll calc(int n, int m) {
    vector<vl> dp(n+1, vl(m+1, 0));
    dp[0][0] = 1LL;
    rep(i, n) rep(j, m+1) {
        if(j == m) (dp[i+1][j] += dp[i][j]) %= MOD;
        else {
            (dp[i+1][j] += dp[i][j]) %= MOD;
            (dp[i][j+1] += dp[i][j]) %= MOD;
        }
    }
    return dp[n][m];
}

int main(){
    ll n, m;
    cin >> n >> m;
    Facts f;
    factrize(m, f);
    ll ans = 1LL;
    for(auto&& p : f) {
        // cout << p.fi << " " << p.se << endl;
        (ans *= calc(n, p.se)) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  while (1)
  {
    int h, w;
    cin >> h >> w;

    for (int i = h; i > 0; i--)
    {
      for (int j = w; j > 0; j--)
      {
        cout << "#";
      }
      cout << endl;
    }

    if (h == 0 && w == 0)
    {
      break;
    }
    
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
N = int(input())
S = {}
for i in range(N):
  tmp = input()
  if tmp in S:
    S[tmp] += 1
  else:
    S[tmp] = 0

l = list(S.items())
l.sort(key=lambda s: (-s[1], s[0]))
M = l[0][1]
print("\n".join([a[0] for a in list(filter(lambda b: b[1] == M, l))]))

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

const long long MOD = 1e9+7;

long long getPower(long long base, long long power){
    if(power==0){
        return 1;
    }
    long long x=getPower(base, power/2);
    x=(x*x)%MOD;

    if(power%2){
        return (base*x)%MOD;
    }else{
        return (x)%MOD;
    }
}

long long buildAnswer(long long n){
    long long x=getPower(10, n);
    long long y=getPower(9, n);
    y=(y*2)%MOD;
    long long z=getPower(8, n);
    x=(x-y)%MOD;
    x=(x+z)%MOD;
    x=(x+MOD)%MOD;

    return x;
}

int main(){
    long long n;
    cin>>n;
    cout<<buildAnswer(n)<<endl;
}

Measured memory_bytes: 3520
//gauravsinghh
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 1000000000
#define lim 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
int main(){
    IOS
    //io_set();
    ll n;
    string a, b;
    vector < char > v;
    cin >> n >> a >> b;
    rep(i, n){
      v.pb(a[i]), v.pb(b[i]);
    }
    for(auto it : v){
      cout << it;
    }
    cout << endl;
    return 0;
} 




































































































 

Measured memory_bytes: 256
// Restoring Road Network
// 所要時間 47分
// 問題文の理解と道路の構造の検知に手間取った
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n;
    cin >> n;
    vector<vector<ll>> d(n, vector<ll>(n));
    rep(i, n){
        rep(j, n){
            cin >> d[i][j];
        }
    }

    vector<vector<bool>> avoid(n, vector<bool>(n, false));
    bool ok = true;
    rep(k, n){
        rep(i, n){
            rep(j, n){
                // i == k k == j じゃないとき d[i][j] == d[i][k]+d[k][j]
                // が成り立つなら i から j に直接道路はない
                if(i != k && k != j && d[i][j] == d[i][k]+d[k][j]){
                    avoid[i][j] = true;
                }
                // d[i][k]+d[k][j] が d[i][j] のとき最短経路が更新されるので条件を満たさない
                if(d[i][j] > d[i][k]+d[k][j]){
                    ok = false;
                }
            }
        }
    }

    if(ok){
        ll ans = 0;
        rep(i, n){
            // 被りがないように i+1 から始める
            for(int j=i+1; j<n; ++j){
                if(!avoid[i][j]){
                    ans += d[i][j];
                }
            }
        }
        cout << ans << endl;
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
  int n, score_a, score_b, a, b;
  while (cin >> n) {
    if (n == 0) break;

    score_a = 0;
    score_b = 0;

    for (int i = 0; i < n; i++) {
      cin >> a >> b;

      if (a > b) {
        score_a += a + b;
      } else if (a < b) {
        score_b += a + b;
      } else {
        score_a += a;
        score_b += b;
      }

    }

    cout << score_a << " " << score_b << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		ll A,B;
		cin>>A>>B;
		if(B>A) swap(A,B);
		if(A==B){
			cout<<2*(A-1)<<endl;
			continue;
		}
		ll l=1,r=inf;
		while(r-l>1){
			ll m=(l+r)/2;
			if(m*m<A*B) l=m;
			else r=m;
		}
		if(l*(l+1)<A*B) cout<<2*l-1-(A==l?1:0)<<endl;
		else cout<<2*l-2<<endl;
	}
}

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

int main(){
  int p,q,r; cin>>p>>q>>r;

  int m=max(p,q);
  m=max(m,r);
  m=p+q+r-m;
  cout<<m<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int hight[10];
	int num;
	int baffer;
	int flag=1;

	for(num=0;num!=10;num++)
	{
		cin>>hight[num];
	};

	for(num=0;num!=10;num++)
	{
		if(hight[num]<hight[(num+1)]){

		baffer=hight[(num+1)];

		hight[(num+1)] = hight[num];
		
		hight[num] = baffer;
		
		flag++;}
		
		if(num==8){
			if(flag==0){break;}
			else{num=-1;flag=0;};

		};
	};

	cout<<hight[0]<<endl;
	cout<<hight[1]<<endl;
	cout<<hight[2]<<endl;

return 0;
}

Measured memory_bytes: 0
#shink and stone
h,w=map(int,input().split())
flag=True
dif=[]
for i in range(h):
    s=input()
    lists=[]
    for i in range(w):
        if s[i]=="#":
            lists.append(i+1)
    for i in range(len(lists)-1):
        if lists[i+1]-lists[i]>1:
            flag=False
            break
    dif.append((lists[0],lists[-1]))
if flag:
    subflag=True
    for i in range(h-1):
        if dif[i+1][0]!=dif[i][1]:
            subflag=False
            break
    if subflag:
        print("Possible")
    else:
        print("Impossible")
else:
    print("Impossible")

Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=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))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N;
int cnt[114514]={0};
int main(){
	cin>>N;
	ll ans=1;
	rep(i,N){
		int x;
		cin>>x;
		cnt[x]++;
		if(cnt[x]>3)ans=0;
		if(x>0&&cnt[x]>cnt[x-1])ans=0;
		if(x==0)ans*=ll(4-cnt[x]);
		else ans*=ll(cnt[x-1]+1-cnt[x]);
		ans%=MOD;
	}
	cout<<ans<<endl;
}





Measured memory_bytes: 640
Q,H,S,D = map(int, input().split())
N = int(input())

if N % 2 == 0:
  print(min(Q*N*4,H*N*2,S*N,D*N//2))
else:
  N -= 1
  print(min(Q*N*4,H*N*2,S*N,D*N//2) + min(Q*4,H*2,S))

Measured memory_bytes: 3060
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;




int main(){
    string err;
    set<char> S;
    for(int i='a';i<='z';i++){
        err.push_back(i);
        S.insert(i);
    }
    reverse(err.begin(),err.end());
    
    string s;
    cin>>s;
    if(s==err){
        cout<<-1<<endl;
        return 0;
    }
    else if(s.size()<26){
        for(int i=0;i<s.size();i++){
            S.erase(s[i]);
        }
        s.push_back(*S.begin());
    }
    else{
        set<char> S;
        S.insert(s[25]);
        s.pop_back();
        for(int i=24;s.size()>0;i--){
            if(S.upper_bound(s[i])!=S.end()){
                s[i]=*S.upper_bound(s[i]);
            }
            else{
                S.insert(s[i]);
                s.pop_back();
                continue;
            }
            break;
        }
    }
    cout<<s<<endl;
    
    return 0;
}


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



int main(void){
   
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,a,b,count1=0,a2,b2;

scanf("%lld%lld",&n,&m);
n*=3;
n+=m;
n/=2;
printf("%lld",n);
return 0;
}


Measured memory_bytes: 128
#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<ll, ll> 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;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	vector<ll> l(n+1, 0), r(n+1, 0);
	rep(i,n) l[i+1] = l[i] + a[i];
	for(int i = n; i > 0; --i){
		r[i-1] = r[i] + a[i-1];
	}
	ll ans = 1e18;
	rep(i,n+1){
		chmin(ans, abs(l[i] - r[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
N , M , K = input().split()
N = int(N)
M = int(M)
K = int(K)
OK = False


for n in range(N + 1):
    if N == 2*n : 
        if K == N*M / 2 : OK = True
    else :     
        flag =  (K - M * n) % (N - 2*n) == 0
        if(flag):
            m = (K - M * n) / (N - 2*n)
            if( (m >= 0) & (m <= M) ) : 
                OK = True
            
if(OK) : print("Yes")
else : print("No")

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

int main() {
    int N, M; cin >>N >> M;
    int X[M];
    int ans=0;
    for (int i=0; i < M; i++) {
        cin >> X[i];
    }
   
    if (N >= M) {
        cout << 0;
    } else {
        sort(X, X+M);
        int dist[M-1];
        for (int i=0; i< M-1;i++){
            dist[i] = X[i+1] - X[i];
            // cout << i << dist[i] << endl;
        }
        sort(dist, dist+M-1, greater<>());
        for (int i=N-1;i < sizeof(dist)/sizeof(*dist); i++) {
            ans += dist[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import itertools as I,math;
def lcm(x,y):return x*y//math.gcd(x,y);
while 1:
    a,b,c,d,e,f=map(int,input().split());
    if a==0:break;
    A=I.dropwhile(lambda x:1<pow(a,x,b),range(1,b));
    B=I.dropwhile(lambda x:1<pow(c,x,d),range(1,d));
    C=I.dropwhile(lambda x:1<pow(e,x,f),range(1,f));
    x,y,z=map(lambda u:list(u)[0],[A,B,C]);
    print(lcm(x,lcm(y,z)))



Measured memory_bytes: 6968
n = int(input())

arr = []
for i in range(n - 1):
    c, s, f = map(int, input().split())
    arr.append([c, s, f])

for i in range(n - 1):
    current = 0
    for j in range(i, n - 1):
        if current >= arr[j][1]:
            if current % arr[j][2] == 0:
                current = current + arr[j][0]
            else:
                current = (arr[j][2] - (current % arr[j][2])) + current + arr[j][0]
                pass
        else:
            current = arr[j][1] + arr[j][0]
    print(current)

print(0)


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int p;
    int max = 0, price = 0;
    for (int i=0;i<N;i++) {
        cin >> p;
        if (max < p) max = p;
        price += p;
    }
    price -= max/2;
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
int main()
{
	ll n;
	cin>>n;
	ll arr[n][3];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			cin>>arr[i][j];
		}
	}
	ll dp[n][3];
	memset(dp,0,sizeof(dp));
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	for(ll i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+arr[i][2];
	}
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
}


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

const int Nmax=200010;
//#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//#definr REP(i,n) FOR(i,0,n)
//#define dump(x) cout << #x << "=" << (x) << endl;
//#define debug(x) cout << #x << "=" << (x) << "(L" << _LINE_ << ")" << "" << _FILE_ << endl;
//ll a[Nmax];
//int* P = new int[N];

/*ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}*/

int main() {
	int o;
	ll n,a[Nmax],col=0,mina=0,r;
	cin >> n;
	for(int i=0;i < n;i++) cin >> a[i];
	sort(a, a+n);
  //nCrの値はnに比例して大きくなる
	mina=a[n-1];
  	for(int i=0;i < n-1;i++){
      	r = abs(a[n-1]/2-a[i]);
		mina=min(mina, r);
      	if(mina == r) o = a[i];
    }
	cout << a[n-1] <<" "<< o << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bitset>

using namespace std;

int main()
{
    bitset<24> alphabet;
    char c;
    while (cin >> c) {
        int v = alphabet[c - 'a'];
        v ^= 1;
        alphabet[c - 'a'] = v;
    }
    for (int i = 0; i < alphabet.size(); ++i) {
        if (alphabet[i] != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)

int32_t main(){
  
  fast;
  int n; cin >> n;
  int ar[n];

  for(int i=0;i<n;i++) cin >> ar[i];

  int prefix[n] , suffix[n];
  prefix[0] = ar[0]; suffix[n-1] = ar[n-1];

  for(int i=1;i<n;i++) prefix[i] = max(prefix[i-1],ar[i]);
  for(int i=n-2;i>=0;i--) suffix[i] = max(suffix[i+1],ar[i]);


  for(int i=0;i<n;i++){
    int left = (i-1>=0)?prefix[i-1]:-1;
    int right = (i+1<n)?suffix[i+1]:-1;

    cout << max(left,right) << '\n';
  }
  


 
  return 0;
} 

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

int main()
{
    int a, b, c, d, e = -1, t = 0;

    cin >> a >> b >> c;

    while(1)
    {
        d = 60 * t + c - ( a + b ) * ( ( 60 * t + c ) / ( a + b ) );
        if( d == e || t > 1000 )
        {
            cout << -1 << endl;
            break;
        }
        e = d;
        if( d - a <= 0 )
        {
            cout << 60 * t + c << endl;
            break;
        }
        else
            t++;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vll vector <pll>
#pragma 03
using namespace std;
ll n;
ll dp[3005][3005][2];
ll a[3005];
ll calc(ll l, ll r, ll c){
	if (l > r) return 0;
	if (dp[l][r][c] != -1) return dp[l][r][c];
	ll i = calc(l + 1, r, 1 - c);
	ll j = calc(l, r-1, 1 - c);
	dp[l][r][c] = c * max(a[l] + i, a[r] + j) + (1 - c) * min(i - a[l], j - a[r]);
	return dp[l][r][c];
}
int main(){
	cin >> n;
	for (ll i = 0; i<n; i++) cin >> a[i];
	for (int i = 0; i<3005; i++){
		for (int j = 0; j<3005; j++){
			for (int k = 0; k<2; k++) dp[i][j][k] = -1;
		}
	}
	cout << calc(0, n-1, 1) << endl;
}	

Measured memory_bytes: 141440
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
const int INF=999999999;
int ver[510][510];
int hor[510][510];
char dir[6]="UDLR";
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
char str[1100];
int dist[510][510];
int visit[510][510];
int main(){
    int W,H,N;
    int fromX,toX,fromY,toY;
    scanf("%d%d%d",&W,&H,&N);
	scanf("%d%d%d%d",&fromX,&fromY,&toX,&toY);
    for(int i=0;i<N;i++){
        int initX,initY;
        scanf("%d%d",&initX,&initY);
        int T;
        scanf("%d%s",&T,str);
        int nowX=initX;
        int nowY=initY;
        for(int j=0;j<T;j++){
            for(int k=0;str[k];k++){
                int toX=nowX;
                int toY=nowY;
                for(int l=0;l<4;l++){
                    if(str[k]==dir[l]){
                        toX+=dx[l];
                        toY+=dy[l];
                    }
                }
                if(toX<0||toX>=W||toY<0||toY>=H)continue;
                if(toX==nowX){
                    ver[nowX][max(nowY,toY)]++;
                }else{
                    hor[max(nowX,toX)][nowY]++;
                }
                nowX=toX;
                nowY=toY;
            }
        }
    }
	/*for(int i=0;i<=H;i++){
		for(int j=0;j<=W;j++)printf("%d ",ver[i][j]);
		printf("\n");
	}*/
    for(int i=0;i<=W;i++)for(int j=0;j<=H;j++)dist[i][j]=INF;
    priority_queue<pair<int,pair<int,int> > >Q;
	dist[fromX][fromY]=0;
	Q.push(make_pair(0,make_pair(fromX,fromY)));
    
    while(Q.size()){
        int cost=-Q.top().first;
        int row=Q.top().second.first;
        int col=Q.top().second.second;
        Q.pop();
        if(visit[row][col])continue;
        visit[row][col]=1;
	//	printf("%d %d: %d\n",row,col,cost);
        for(int i=0;i<4;i++){
            int toX=row+dx[i];
            int toY=col+dy[i];
            int ncost=0;
            if(toX==row)ncost=hor[toX][min(toY,col)];
            else ncost=ver[min(toX,row)][toY];
            if(toX<0||toX>W||toY<0||toY>H||visit[toX][toY]||dist[toX][toY]<=cost+ncost)continue;
            dist[toX][toY]=cost+ncost;
            Q.push(make_pair(-dist[toX][toY],make_pair(toX,toY)));
        }
    }
    int ret=dist[toX][toY];
    
    printf("%d\n",ret);
}

Measured memory_bytes: 8000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	string s;
	cin>>s;
	int f = 0;
	for(int i = 1; i < n && k; i++){
		if(s[i] != s[0]){
			f = 1;
			s[i] = s[0];
		}
		else if(f){
			f = 0;
			k--;
		}
	}
	long long ans = 0;
	for(int i = 1; i < s.length(); i++){
		if(s[i] == s[i-1]){
			ans++;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

    ll ans = infll;

    for (int i = 0; i < N; i++)
    {
        ll sum = 0;
        for (int j = 0; j < N; j++)
        {
            b[j] = i == 0 ? a[j] : min(b[j], a[(N + j - i) % N]);
            sum += b[j];
        }
        ans = min(sum + x * i, ans);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	sort(a + 1, a + n + 1);
	int ans = a[1];
	for (int i = 1; i <= n - 1; i++) {
		int tmp = min(a[i], a[n] - a[i]);
		if (tmp > min(ans, a[n] - ans)) ans = a[i];
	}
	printf("%d %d\n", a[n], ans);
	return 0;
}

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

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

int a[maxn];
int pre[maxn];
map<int, int> cnt;

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        pre[i] = (pre[i-1] + a[i]) % m;
        cnt[pre[i]] ++;
    }
    cnt[0] ++;
    ll ans = 0;
    for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); ++it)
        ans += (ll)it->second * (it->second - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3968
#include<iostream>

using namespace std;

int main(){
  int n, m, x, y, mx=-101, mn=101;
  cin >> n >> m >> x >> y;
  mx = max(mx, x);
  mn = min(mn, y);
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    mx = max(mx, tmp);
  }
  for(int i=0;i<m;i++){
    int tmp;
    cin >> tmp;
    mn = min(mn, tmp);
  }
  if(mx<mn){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256