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

void chmin(int& a, int b){
    a = min(a, b);
}

const int Tmax = 10000;
int N, M;
int Dst[Tmax];

int dist[400][400], E[400][400], Nxt[400][400], F[400];

void initialize(){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        E[a][b] = E[b][a] = c;
    }
    for(int i=0; i<N; i++) cin >> F[i];
    int _; cin >> _;

    for(int i=0; i<N; i++) for(int j=0; j<N; j++) if(i != j) dist[i][j] = (E[i][j] ? E[i][j] : 1e9);
    for(int k=0; k<N; k++) for(int i=0; i<N; i++) for(int j=0; j<N; j++) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        for(int k=0; k<N; k++) if(i != k && E[i][k] && E[i][k] + dist[k][j] == dist[i][j]){
            Nxt[i][j] = k;
            break;
        }
    }
}

vector<int> ans;
int stock[400], have[400], havesum;
int pos, now;
int scorenum = 0;

void addtime(){
    int n, _, dst;
    cin >> n;
    if(n){
        cin >> _ >> dst;
        stock[dst-1]++;
    }
    cin >> n;
    while(n--) cin >> _;
}
void output(int a){
    static int cnt = 0;
    cout << (a == -1 ? -1 : a+1) << endl;
    string verdict;
    cin >> verdict;
    if(verdict == "NG") exit(0);
    int n, _;
    cin >> n;
    while(n--) cin >> _;
    cnt++;
    if(cnt == Tmax) exit(0);
}
void visit(int v){
    if(v == 0) for(int i=0; i<N; i++){
        have[i] += stock[i];
        havesum += stock[i];
        stock[i] = 0;
    }
    scorenum += have[v];
    havesum -= have[v];
    have[v] = 0;
}

void moveto(int v){
    if(pos == v){
        addtime();
        output(-1);
        visit(pos);
        return;
    }
    while(pos != v){
        int nxt = Nxt[pos][v];
        int d = E[pos][nxt];
        while(d--){
            addtime();
            output(nxt);
        }
        pos = nxt;
        visit(nxt);
    }
}

int main(){
    initialize();
    while(true){
        if(havesum > 0){
            int nxt = -1;
            for(int i=0; i<N; i++) if(have[i]) if(nxt == -1 || dist[pos][nxt] > dist[pos][i]) nxt = i;
            moveto(nxt);
        }else{
            moveto(0);
        }
    }
}


Measured memory_bytes: 3152
falsify = "Yes"
c = int(input())
w = []
for i in range(c):
  w.append(input())
if len(set(w)) != len(w):
  falsify = "No"
for i in range(len(w) - 1):
  if w[i][-1] != w[i+1][0]:
    falsify = "No"
print(falsify)

Measured memory_bytes: 3060
from operator import itemgetter
n,k = map(int,input().split())
lists = []
cnt = 0
a_b = sorted([list(map(int,input().split())) for i in range(n)],key = itemgetter(0))
for a,b in a_b:
    cnt += b
    if cnt >= k:
        print(a)
        exit()

Measured memory_bytes: 29864
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

using Graph = vector<vector<int>>;

int main() {
  // 頂点数と辺数
  int N, M;
  cin >> N >> M;

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // BFS のためのデータ構造
  vector<int> sign(N, -1); // 全頂点を「未訪問」に初期化
  queue<int> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  sign[0] = 0;
  que.push(0); // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv : G[v]) {
      if (sign[nv] != -1)
        continue; // すでに発見済みの頂点は探索しない

      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      sign[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  // 結果出力 (各頂点の頂点 0 からの距離を見る)
  for (int v = 1; v < N; ++v)
    cout << sign[v] + 1 << endl;
  return 0;
}


Measured memory_bytes: 10260
#include<cstdio>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<cstring>
#define eps 1e-8
#define pi acos(-1)
#define mp make_pair
#define PH push
#define pb push_back
#define PII pair<ll,ll>
#define VI vector<int>
#define fi first
#define se second
#define N(a,b) a=N(a,b)
#define Min(a,b) a=min(a,b)
#define sqr(x) ((x)*(x))
#define CL(a) memset(a,0,sizeof a)
#define fr(i,n) for(int i=1;i<=n;i++)
#define FR(i,S,n) for(int i=S;i<=n;i++)
#define dr(i,n) for(int i=n;i;i--)
#define DR(i,n,S) for(int i=n;i>=S;i--)
#define SZ(x) ((int)(x).size())
#define all(n) n.begin(),n.end()
#define rd(x) scanf("%d",&x)
#define pr(x) printf("%d",x)
#define prn(x) printf("%d\n",x)
typedef long long ll;
typedef unsigned long long ull;
ll expow(ll a,ll b,ll p) {ll v=1; for (; b; b>>=1,a=a*a%p)if (b&1)v=v*a%p; return v;}
ll inv(ll a,ll p) {return expow(a,p-2,p);}
using namespace std;
const int N=1000+10;
int a[N];
int main(){
    a[1]=1;
  for(int j=2;j<=1000;j++){
       int cnt=j*j;
        while(cnt<=1000){
            a[cnt]=1;
          cnt*=j;
    }
    }
   int n;
    cin>>n;
    while(a[n]==0) n--;
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 200000;

const int Z = N - 2;
const int O = N - 1;

vector<tuple<char, int, int, int>> vv;

void ac(int x, int y, int z) {
	vv.emplace_back('<', x, y, z);
}

void ap(int x, int y, int z) {
	vv.emplace_back('+', x, y, z);
}

void print() {
	cout << vv.size() << "\n";
	for (auto x : vv) {
		auto [a, b, c, d] = x;
		cout << a << " " << b << " " << c << " " << d << "\n";
	}
}

void check(ll a, ll b) {
	vector<ll> x(N);
	x[0] = a;
	x[1] = b;
	for (auto t : vv) {
		auto [a, b, c, d] = t;
		if (a == '<') {
			x[d] = (x[b] < x[c]);
		} else {
			x[d] = (x[b] + x[c]);
		}
	}
	assert(x[2] == a * b);
	cerr << a << " " << b << ": OK!\n";
}

random_device rd;
void test() {
	mt19937 rnd(rd());
	for (int i = 0; i < 1000; ++i) {
		int x = rnd() % 1000000000;
		int y = rnd() % 1000000000;
		check(x, y);
	}
}

const int A[2] = {100, 200};
const int CUR = 50;
const int TMP = 100000;

void pw2(int base, int x, int p) {
	ap(Z, base, x);
	for (int i = 0; i < p; ++i) {
		ap(x, x, x);
	}
}

void neg(int x) {
	ac(x, O, x);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);

	// create 0, 1 in the end
	ac(2, 0, Z);
	ac(2, 1, O);
	ap(Z, O, O);
	ac(Z - 1, Z - 2, Z);
	ac(Z, O, O);

	for (int c : {0, 1}) {
		ac(Z, Z, CUR);
		for (int i = 29; i >= 0; --i) {
			pw2(O, CUR + 1, i);
			ap(CUR, CUR + 1, CUR + 2);

			ac(c, CUR + 2, CUR + 2);
			neg(CUR + 2);
			ap(Z, CUR + 2, A[c] + i);

			pw2(CUR + 2, CUR + 1, i);
			ap(CUR, CUR + 1, CUR);
		}
	}

	for (int i = 0; i <= 29; ++i) {
		for (int j = 0; j <= 29; ++j) {
			ap(A[0] + i, A[1] + j, TMP);
			ac(O, TMP, TMP);
			pw2(TMP, TMP, i + j);
			ap(2, TMP, 2);
		}
	}

	print();
	//test();
	return 0;
}




Measured memory_bytes: 3756
def win(x):
    if x == "r":
        return p
    elif x == "s":
        return r
    else:
        return s


n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = input()

flags = [False] * n
ans = 0
for i in range(n):
    if i - k >= 0 and t[i - k] == t[i] and not flags[i - k]:
        flags[i] = True
        continue
    ans += win(t[i])
print(ans)


Measured memory_bytes: 4084
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    String[] line = br.readLine().split(" ");

	    int r = Integer.parseInt(line[0]);
	    int c = Integer.parseInt(line[1]);

	    int[][] matrix = new int[r + 1][c + 1];

	    for (int i = 0; i < r; i++) {
	    	line = br.readLine().split(" ");

	    	for (int j = 0; j < line.length; j++) {
		    	matrix[i][j] = Integer.parseInt(line[j]);

		    	// row sum
		    	matrix[i][c] += matrix[i][j];
		    	// col sum
		    	matrix[r][j] += matrix[i][j];

		    	if (j == line.length - 1) {
			    	// all sum
			    	matrix[r][c] += matrix[i][c];
		    	}
	    	}
	    }

	    for (int i = 0; i < r + 1; i++) {
		    StringBuilder sb = new StringBuilder();
	    	for (int j = 0; j < c + 1; j++) {
	    		sb.append(matrix[i][j]);
	    		sb.append(" ");
	    	}
	    	System.out.println(sb.toString().substring(0, sb.toString().length() - 1));
	    }
	}
}

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

int main(){
  string S;
  cin >> S;
  string v1="RUD";
  string v2="LUD";
  bool flag=false;
  for(int i=0;i<S.size();i++){
    if(i%2==0){
      for(int j=0;j<v1.size();j++){
        if(S.at(i)==v1.at(j)){
          flag=true;
        }
      }
    }else{
      for(int j=0;j<v2.size();j++){
        if(S.at(i)==v2.at(j)){
          flag=true;
        }
      }
    }
    if(!flag){
      cout << "No" << endl;
      return 0;
    }
    flag=false;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long n = sc.nextLong();
			long p = sc.nextLong();
			
			TreeMap<Long, Long> map = primeFactorization(p);
			
			//System.out.println(map);
			
			long ret = 1;
			
			for(Map.Entry<Long, Long> e :map.entrySet()) {
				ret *= Math.pow(e.getKey(),e.getValue()/n );
			}
			
			System.out.println(ret);
			
	    }
		
		
		static TreeMap<Long, Long> primeFactorization (long n) {

			TreeMap<Long, Long> map = new TreeMap<>();
			long sq = (long)Math.sqrt(n);

			//nが素数ならn^1の形で返す
			if (isPrime(n) == true) {
				map.put(n, 1L);
				return map;
			}

			for (long i=2; i<=sq; i++) {
				//n<iなら明らかにnをiで除算できないので終了（ループを余計に回さない）
				if (n < i) break;

				//iが素数なら、nをiで何回除算できるか、その回数をmapに記録する
				if (isPrime(i) == true) {
					long count = 0;
					while (n%i == 0) {
						n /= i;
						count++;
					}
					if (count > 0) {//1回以上割れた場合のみ、mapに記録する
						map.put(i, count);
					}
				}

			}

			//2～sqrt(n)で除算した結果、なお残った数をmapに追加する
			if (n != 1) map.put(n, 1L);

			return map;

		}
		
		static boolean isPrime (long n) {
			if (n==2) return true;
			if (n<2 || n%2==0) return false;
			int d = (int)Math.sqrt(n);
			for (int i=3; i<=d; i+=2) {
				if(n%i==0){return false;}
			}
			return true;
		}
		
	}
	


Measured memory_bytes: 35920
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
typedef long long LL;
using namespace std;

LL n;

int dfs(LL num, bool is_three, bool is_five, bool is_seven){
    int ans;
    if(num > n){
        return 0;
    }
    if(is_three && is_five && is_seven){
        ans = 1;
    }else{
        ans = 0;
    }
    ans += dfs(num*10+3, true, is_five, is_seven);
    ans += dfs(num*10+5, is_three, true, is_seven);
    ans += dfs(num*10+7, is_three, is_five, true);

    return ans;
}

int main() {
    int ans;
    cin >> n;
    ans = dfs(0, false, false, false);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())

void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}

bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}

const int maxi = 1e6+10;
vector<int> v[maxi];
long long a[maxi];

void dfs(int x,int y){
    a[x]+=a[y];
    for(int i:v[x]){
        if(i!=y){
            dfs(i,x);
        }
    }
}

void test_case(){
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;++i){
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    for(int i=0;i<q;++i){
        int x,y;
        cin>>x>>y;
        a[x]+=y;
    }
    dfs(1,0);
    for(int i=1;i<=n;++i){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 44672
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
using pll = pair<long long, long long>;

int main() {
    int N, M; cin >> N >> M;
    vector<long long> A(N), B(M), C(M);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());
    B.resize(M);
    C.resize(M);
    for (int i = 0; i < M; ++i) cin >> B[i] >> C[i];

    // C をソート (B をまとめて)
    vector<int> id(M);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int i, int j) {
            return C[i] > C[j];});

    // A (小さい順) と C (大きい順) とを比べて大きい方を足していく
    long long sum = 0;
    long long K = 0;
    for (auto i : id) {
        for (int j = 0; j < B[i]; ++j) {
            if (K >= N) break;
            sum += max(A[K++], C[i]);  
        }
    }
    for (int i = K; i < N; ++i) sum += A[i];        
    cout << sum << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string res = "";
    while(n){
        --n;
        res += (char)('a' + (n % 26));
        n /= 26;
    }    
    reverse(all(res));
    cout << res << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s;
	cin>>s;
	if(s[s.length()-1]=='s'){
		s+='e';
		s+='s';
	}else{
		s+='s';
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3632
/*---------------Go Code GO---------------*/

#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;

template<typename T>
using Order_Set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff




int main()
{
    long long k;
    cin>>k;
    double res = 2*k*PI;
    cout<<precision(10)<<res<<endl;

    return 0;
}


Measured memory_bytes: 3788
#include<stdio.h>

typedef struct{
  double t;
  int num;
} hight;

int main()
{
  int n, i;
  scanf("%d\n", &n);
  hight h[n];
  double t, a, tempar;
  scanf("%lf%lf", &t, &a);
  for(i = 0; i < n; ++i){
    h[i].num = i+1;
    scanf("%lf", &h[i].t);
    tempar = t - h[i].t * 0.006;
    h[i].t = a - tempar;
    if(h[i].t < 0) h[i].t = -h[i].t;
  }
  int j;
  for(j = 0; j < n-1; ++j){
      for(i = 0; i < n - 1 -j; ++i){
	hight temp;
	if(h[i].t > h[i+1].t){
	  temp.t = h[i].t;
	  h[i].t = h[i+1].t;
	  h[i+1].t = temp.t;
	  temp.num = h[i].num;
	  h[i].num = h[i+1].num;
	  h[i+1].num = temp.num;
	}
      }
  }
  printf("%d\n", h[0].num);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sumvec(vector<S>&a){return accumulate(all(a),S());}
template<class S>S maxvec(vector<S>&a){return *max_element(all(a));}
template<class S>S minvec(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

vvl comb(ll n, ll r) {
  vvl v(n + 1,vl(n + 1, 0));
  for (ll i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (ll j = 1; j < v.size(); j++) {
    for (ll k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}


int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
  	
  	ll n,k;
  	cin>>n>>k;
  	vl h(n);
  	cin>>h;
  	rep(i,k*3){
  	    h.push_back(INF);
  	}
  	vl cost(n+k*3,INF);
  	cost[0]=0;
  	/*
  	range(i,1,n){
  	    ll a,b=INF;
  	    a=abs(h[i]-h[i-1]) + cost[i-1];
  	    if(i>1) b=abs(h[i]-h[i-2]) + cost[i-2];
  	    //cout<<a<<" "<<b<<" ";
  	    cost[i]=min(a,b);
  	    //puta(cost[i]);
  	}*/
  	
  	
  	rep(i,n+k+1){
  	    range(j,1,k+1){
      	    ll a=abs(h[i]-h[i+j]);
      	    //cout<<a<<" ";
      	    cost[i+j]=min(cost[i+j],cost[i]+a);
      	    //cout<<cost[i]<<" "<<cost[i+j]<<endl;
      	}
  	}
  	
  	puta(cost[n-1]);

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int ans = INF;
    REP(i, (int)S.size() - 2)
    {
        int p = atoi(S.substr(i, 3).c_str());
        ans = min(ans, abs(p - 753));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 200005
#define maxm 500005
#define pii pair <int,int>
#define Task ""
using namespace std;
int n;
long double a[maxn],sum[maxn],x,ans = 50.0*maxc*maxc;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(".inp", "r",stdin);
    cin >> n >> x;
    FOR(i,1,n) cin >> a[i],sum[i] = sum[i-1] + a[i];
    FOR(l,1,n)
    {
        int k = (n - 1) / l + 1;
        long double temp = 5.0*(sum[n] - sum[n-l]);
        FOR(j,2,k)
        {
            int q = max(0, n - j * l), w = n - (j - 1) * l;
            temp += 1.0*(2.0*j+1)*(sum[w] - sum[q]);
        }
        ans = min(ans,temp + 1.0*(l+n)*x);
    }
    cout << fixed << setprecision(0) << ans;
}


Measured memory_bytes: 6528
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int a=1,b=1,c=1;
	int sum=0;
	
	for(a=1; a<N; a++){
	    if(a*a>=N)break;
	    for(b=a; b<N; b++){
		if(a*b>=N)break;
		else if(a*b<N){
		    if(a==b)sum++;
		    else sum+=2;
		}
	    }
	}	
	System.out.println(sum);
    }
}

Measured memory_bytes: 36480
#include <cstdio>
#include <cstdlib>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a >= b && a >= c) printf("%d\n", b + c);
	else if (b >= a && b >= c) printf("%d\n", a + c);
	else if (c >= a && c >= b) printf("%d\n", a + b);
	return 0;
}


Measured memory_bytes: 128
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();

    let ans = if a % 2 == 1 && b % 2 == 1 {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>

int BubbleSort(int *A,int length) {

  int i, j, tmp, cnt=0;
  for(i = 0; i < length; i++) {
    for(j = length-1; j > i; j--) {
      if(A[j] < A[j-1]) {
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;
	cnt++;
      }
    }
  }
  return cnt;
}


main()
{
  int i;
  int n;
  int Arr[100];
  int cnt = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    scanf("%d", &Arr[i]);
  }

  cnt = BubbleSort(Arr,n);

  /* スペースをいれない方法！ */
  printf("%d", Arr[0]);

  for(i = 1; i < n; i++) {
    printf(" %d" ,Arr[i]);
  }

  printf("\n%d\n", cnt);

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void Dijkstra(Graph& G, ll s, Array& d, Array& u, ll l) {//O(|E|log|V|)
	d.resize(G.size());
	u.resize(G.size());
	REP(i, d.size())d[i] = INF;
	REP(i, u.size())u[i] = INF;
	d[s] = 0;
	u[s] = 0;
	priority_queue<pair<pair<ll, ll>, ll>,vector< pair<pair<ll, ll>, ll>>,greater<pair<pair<ll, ll>, ll>>> q;

	q.push(make_pair(make_pair(0, 0), s));
	while (!q.empty()) {
		ll k = q.top().first.first;
		ll dd = q.top().first.second;
		ll v = q.top().second;
		q.pop();
		if (u[v] < k)continue;
		if (d[v] < dd)continue;

		REP(i, G[v].size()) {
			Edge e = G[v][i];
			ll nd = dd + e.cap;
			ll nk = k;
			if (nd > l) {
				nd = e.cap;
				nk++;
			}
			if (u[e.to] > nk) {
				u[e.to] = nk;
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk, nd), e.to));
			}
			else if (u[e.to] == nk && d[e.to] > nd) {
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk, nd), e.to));
			}
		}
	}
}

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

	ll n, m, l;
	cin >> n >> m >> l;
	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		if(c<=l) add_edge(g, a, b, c, true, c);
	}

	Matrix ans(n);
	Matrix d(n);

	REP(i, n) {
		Dijkstra(g, i, d[i], ans[i], l);
	}
	/*
	for (auto i : ans) {
		for (auto j : i) {
			cout << j << " ";
		}
		cout << endl;
	}
	*/

	ll q;
	cin >> q;

	REP(i, q) {
		ll s, t;
		cin >> s >> t;
		s--; t--;
		if (ans[s][t] != INF) {
			cout << ans[s][t] << endl;
		}
		else {
			cout << -1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z;
		while( x!= 0 || y!= 0 ){
			if( x > y ){
				z = x;
				x = y;
				y = z;
			}
			System.out.println( x + " " + y );
			x = sc.nextInt();
			y = sc.nextInt();
		}
	}
}

Measured memory_bytes: 27140
A,B,C,D,E,F=map(int,input().split())

water=[]
for i in range(31):
    for j in range(30):
        if (A*i+B*j)*100<=F:
            water.append((A*i+B*j)*100)
sugar=[]
for i in range(501):
    for j in range(500):
        if C*i+D*j<=F//2:
            sugar.append(C*i+D*j)

ans_sum=A*100
ans_sugar=0
ans_rate=0
for i in water:
    for j in sugar:
        if i==0:
            continue
        if i+j<=F and ans_rate<j/i<=E/100:
            ans_sum=i+j
            ans_sugar=j
            ans_rate=j/i

print(ans_sum,ans_sugar)

Measured memory_bytes: 5108
mp = []
while True:
  try:
    lst = list(map(int, input().split(",")))
    mp.append(lst)
  except EOFError:
    break

half = len(mp) // 2

for i in range(1, len(mp)):
  for j in range(len(mp[i])):
    if i <= half:
      if j != 0 and j != len(mp[i]) - 1:
        mp[i][j] = max(mp[i - 1][j], mp[i - 1][j - 1]) + mp[i][j]
      elif j == 0:
        mp[i][j] = mp[i - 1][j] + mp[i][j]
      else:
        mp[i][j] = mp[i - 1][j - 1] + mp[i][j]

    else:
      mp[i][j] = max(mp[i - 1][j], mp[i - 1][j + 1]) + mp[i][j]

print(mp[-1][0])


Measured memory_bytes: 5608
import java.util.*;
import java.lang.Math;
public class Main{
	public static void main(String [] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int countn = 0;
		int countm =0;
		for(int i =2;i<=n*2;i=i+2){
			countn= countn+(n-(i/2));
		}
		for(int i=2;i<=m*2;i=i+2){
			countm=countm+(m-(i/2));
		}
		System.out.print(countn+countm);
		
	}
}

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

using namespace std;
int main(void){
	int n, l;
	cin >> n >> l;
	vector<string> vec;
	while(n--){
		string s;
		cin >> s;
		vec.push_back(s);
	}
	sort(vec.begin(), vec.end());
	for(string s : vec) cout << s;
	cout << endl;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	}
}




Measured memory_bytes: 22356
#include<iostream>
#include<cstring>
#include<vector>
#include<utility>

using namespace std;

vector<pair<int, int> > UFtree(100010);
vector<int> treeSize;

int root_Diff(int i) {
  if(UFtree[i].first == i) return 0;
  else return UFtree[i].second + root_Diff(UFtree[i].first);
}

int root(int i) {
  if(UFtree[i].first == i) return i;
  else {
    UFtree[i].second = root_Diff(i);
    return (UFtree[i].first = root(UFtree[i].first));
  }
}

bool is_same_set(int i, int j) {
  return root(i) == root(j);
}



void unite(int i, int j, int w) {//w_i-w_j = w
  int x, y, tmp1, tmp2;
  x = root(i); y = root(j);
  tmp1 = treeSize[x];
  tmp2 = treeSize[y];
  if(tmp1 > tmp2) {
    UFtree[y].first = x;
    UFtree[y].second = w + UFtree[i].second - UFtree[j].second;
  }
  else {
    UFtree[x].first = y;
    UFtree[x].second = -w - UFtree[i].second + UFtree[j].second;
  }
  if(x != i) {
    treeSize[i] += tmp2;
    treeSize[x] += tmp2;
  }
  else treeSize[i] += tmp2;
  if(y != j) {
    treeSize[y] += tmp1;
    treeSize[j] += tmp1;
  }
  else treeSize[j] += tmp1;
}

int main() {
  int N, M;
  vector<int> c(100010, 1);
  while(cin >> N >> M) {
    if(!N) break;
    for(int i = 1; i <= N; i++){
      UFtree[i] = make_pair(i, 0);
    }
    treeSize = c;
    string word;
    int a, b, w;
    for(int i = 0; i < M; i++) {
      cin >> word >> a >> b;
      if(word == "!") {
	cin >> w;
	unite(b, a, w);
      }
      else {
	if(is_same_set(a, b)) cout << root_Diff(a) - root_Diff(b) << endl;
	else cout << "UNKNOWN" << endl;
      }
    }
    UFtree.clear();
  }
  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n,x;
	cin >> n >> x;
	if(x==1 || x==2*n-1){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
		int ans[200010];
		if(x==2*n-2){
			vector<int> v;
			for(int i=1;i<=2*n-1;i++){
				if(i!=x && i!=2*n-1)v.push_back(i);
			}
			ans[n-1]=2*n-1;
			ans[n-2]=x;
			int cnt=0;
			FOR(i,2*n-1){
				if(i!=n-1 && i!=n-2){
					ans[i]=v[cnt];
					cnt++;
				}
			}
		}else{
			vector<int> v;
			for(int i=1;i<=2*n-1;i++){
				if(i!=x && i!=x+1 && i!=x+2 && i!=1)v.push_back(i);
			}
			ans[n-1]=1;
			ans[n-2]=x;
			ans[n-3]=x+1;
			ans[n]=x+2;
			int cnt=0;
			FOR(i,2*n-1){
				if(i!=n-1 && i!=n-2 && i!=n-3 && i!=n){
					ans[i]=v[cnt];
					cnt++;
				}
			}
		}
		FOR(i,2*n-1){
			cout << ans[i] << endl;
		}
	}
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j]<<" ";cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  for(i=0;i<n;i++)cin>>a[i];
  vector<ll>b(n,INF);
  map<ll,ll>p;
  for(i=n-1;i>=0;i--){
    if(p.find(a[i])==p.end()){
      p[a[i]]=i;
    }
    else{
      b[i]=p[a[i]];
      p[a[i]]=i;
    }
  }
  for(i=n-1;i>=0;i--){
    if(b[i]==INF)b[i]=p[a[i]];
  }
  buf=0;
  ll countbuf=0;
  vector<ll>c(n);
  vector<ll>d;
  d.push_back(n);
  while(1){
    //c[buf]=1;
    if(b[buf]==n-1){
      if(buf==n-1){
        d.push_back(n-1);
        countbuf++;
      }
      countbuf++;
      break;
    }
    else {
      if(buf>=b[buf]){
        countbuf++;
        d.push_back(buf);
      }
      buf=b[buf]+1;
    }
  }
  //cout<<countbuf spa d.size() spa k<<endl;  
  //for(i=0;i<d.size();i++)cout<<d[i]<<endl;
  //if((k-1)%countbuf<d.size()){
    for(i=d[k%countbuf];i<n;i++){
      if(b[i]<=i){
        cout<<a[i]<<" ";
      }
      else{
        i=b[i];
      } 
    }
  //}
  cout<<endl;




  return 0;
}

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

int qsc(const void *x, const void *y) {
	int a=*((int*)x);
	int b=*((int*)y);
	if(a>b)return 1;
	if(a<b)return -1;
	return 0;
}

int main(void) {
	int N,M,p;
	static int d[100000];
	int i;
	int answer;
	int candidate;
	if(scanf("%d%d%d",&N,&M,&p)!=3)return 1;
	for(i=0;i<M;i++) {
		if(scanf("%d",&d[i])!=1)return 1;
		d[i]-=p;
		if(d[i]<0)d[i]+=N;
	}
	qsort(d,M,sizeof(d[0]),qsc);
	/* R */
	answer=d[M-1];
	/* L */
	candidate=N-d[0];
	if(candidate<answer)answer=candidate;
	for(i=0;i<M;i++) {
		/* RL */
		candidate=d[i]+N-(d[(i+1)%M]-d[i]);
		if(candidate<answer)answer=candidate;
		/* LR */
		candidate=(N-d[i])+N-(d[i]-d[(i-1+M)%M]);
		if(candidate<answer)answer=candidate;
	}
	printf("%d\n",answer*100);
	return 0;
}

Measured memory_bytes: 712
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int start,end,S;
	bool check[361];
};


int main(){

	int N;
	scanf("%d",&N);

	Info info[N];

	for(int i = 0; i < N; i++){
		for(int day = 1; day <= 360; day++){
			info[i].check[day] = false;
		}
	}

	int month,day,length,value;

	for(int i = 0; i < N; i++){
		scanf("%d %d %d %d",&month,&day,&length,&value);
		info[i].start = 30*(month-1)+day;
		info[i].end = info[i].start+(length-1);

		for(int k = info[i].start; k <= info[i].end; k++){
			if(k > 360){
				info[i].check[k-360] = true;
			}else{
				info[i].check[k] = true;
			}
		}

		info[i].S = value;
	}

	int minimum = BIG_NUM,tmp,tmp_max,left_diff,right_diff,tmp_day;

	for(int day = 1; day <= 360; day++){
		tmp_max = 0;
		for(int i = 0; i < N; i++){

			if(info[i].check[day]){
				tmp = info[i].S;
			}else{

				for(tmp_day = day-1,left_diff = 1; ; left_diff++,tmp_day--){
					if(tmp_day <= 0){
						tmp_day = 360;
					}
					if(info[i].check[tmp_day]){
						break;
					}
				}

				for(tmp_day = day+1,right_diff = 1; ; right_diff++,tmp_day++){
					if(tmp_day > 360){
						tmp_day = 1;
					}
					if(info[i].check[tmp_day]){
						break;
					}
				}

				tmp = max(0,info[i].S-min(left_diff,right_diff));
			}

			tmp_max = max(tmp_max,tmp);
		}
		minimum = min(minimum,tmp_max);
	}

	printf("%d\n",minimum);

	return 0;
}

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

int main(){
    int x, y;
    cin >> x >> y;
    bool flag = false;
    for (int kame = 0; kame <= 100; kame++) {
        if (kame > x) break;
        int tsuru = x - kame;
        if (kame * 4 + tsuru * 2 == y) {
            flag = true;
        }
    }
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#define ENABLE_DEBUG 0
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
template <
usize N, class T, class... Args,
      std::enable_if_t<N==0, int> = 0
      >
      auto mkvec(Args... args) {
          return T(args...);
      }

template <
usize N, class T, class... Args,
      std::enable_if_t<N!=0, int> = 0
      >
      auto mkvec(usize sz, Args... args) {
          using value_type = std::decay_t<decltype(mkvec<N-1, T>(args...))>;
          return vec<value_type>(sz, value_type(args...));
      }
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    std::cin >> n;
    usize N = n * n;
    vec<std::pair<i32, i32>> a(N);
    for (usize i=0; i<N; i++) {
        i32 x;
        std::cin >> x;
        x--;
        a.at(i) = {x/n, x%n};
    }
    DEBUG(n,N,a);

    auto dist = mkvec<2, i32>(n, n);
    for (usize i=0; i<n; i++) {
        for (usize j=0; j<n; j++) {
            dist.at(i).at(j) = std::min({i, j, n-1-i, n-1-j});
        }
    }
    DEBUG(matrix_style(dist));

    vec<std::pair<i32, i32>> didj = {
        {1,0},
        {-1,0},
        {0, 1},
        {0, -1}
    };

    auto ocp = mkvec<2, i32>(n, n, 1);

    i32 ans = 0;
    for (usize ph=0; ph<N; ph++) {
        auto [si, sj] = a.at(ph);
        ans += dist.at(si).at(sj);
        ocp.at(si).at(sj) = false;

        vec<std::pair<i32, i32>> que = {{si, sj}};
        for (usize t=0; t<que.size(); t++) {
            auto [i, j] = que.at(t);
            for (i32 k=0; k<4; k++) {
                auto [di, dj] = didj.at(k);
                i32 ni = i + di;
                i32 nj = j + dj;
                i32 nd = dist.at(i).at(j) + ocp.at(i).at(j);
                if (0<=ni && ni<n && 0<=nj && nj<n
                        && nd < dist.at(ni).at(nj))
                {
                    dist.at(ni).at(nj) = nd;
                    que.emplace_back(ni, nj);
                }
            }
        }
        DEBUG(si,sj,dist.at(si).at(sj),ans);
        DEBUG(matrix_style(ocp));
        DEBUG(matrix_style(dist));
        DEBUG();
    }

    std::cout << ans << '\n';
}


Measured memory_bytes: 11024
import fractions
 
N = int(input())
A = list(map(int, input().split()))

max_gcd = 1

L, R, M = [0]*(N+1), [0]*(N+1), []

def gcd(a, b):
        if a == 0:
                return b
        elif b == 0:
                return a
        else:
                return fractions.gcd(a,b)

for i in range(N):
        L[i+1] = gcd(L[i], A[i])
for i in range(N-1,0,-1):
        R[i] = (gcd(R[i+1], A[i]))
for i in range(N):
        M.append(gcd(L[i], R[i+1]))

print(max(M))

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



int main() {
    string s;
    cin >> s;
    
    rep(i,3) {
        if(s[i] == s[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3540
#include <cstdio>
#include <cstring>

template<class T>inline void fr(T &a) {
    T s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=w*s;
}
template<class T>inline T fr() {T a;fr(a);return a;}
#define R() fr<int>()

char str[10010];

signed main() {
    int n=R();scanf("%s",str);
    int len=strlen(str);
    for(int i=0;i<len;i++) {
        int x=str[i]-'A'+n;
        str[i]='A'+x%26;
    }
    puts(str);
    return 0;
}

Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

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

  set<int> s = {0, N + 1}; //ç•ªå…µ
  int idx[202020];

  for (int i = 1; i <= N; i++) {
    int tmp;
    cin >> tmp;
    idx[tmp] = i;
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    auto itr = s.upper_bound(idx[i]);
    int r = *itr;
    int l = *(--itr);

    ans += i * abs(l - idx[i]) * abs(r - idx[i]);
    s.insert(idx[i]);
  }

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


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <ctime>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
 
int h, w;
string s[12];
 
string reverse(string s) {
	int l = 0, r = s.length() - 1;
	while (l < r) {
		swap(s[l], s[r]);
		l++; r--;
	}
	return s;
}
 
void random_col() {
	int i, j;
	srand(101);
	rep(i, 100) rand();
	
	int tikan[12]; bool used[12] = {false};
	rep(i, w) {
		int t;
		do {
			t = rand() % w;
		} while (used[t]);
		used[t] = true;
		tikan[i] = t;
	}
	
	string tmp[12]; rep(i, h) rep(j, w) tmp[i] += s[i][tikan[j]];
	rep(i, h) s[i] = tmp[i];
}
 
void random_row() {
	int i, j;
	srand(151);
	rep(i, 100) rand();
	
	int tikan[12]; bool used[12] = {false};
	rep(i, h) {
		int t;
		do {
			t = rand() % h;
		} while (used[t]);
		used[t] = true;
		tikan[i] = t;
	}
	
	string tmp[12]; rep(i, h) tmp[i] = s[tikan[i]];
	rep(i, h) s[i] = tmp[i];
}

//条件を満たすか？
bool check(vector<int> perm) {
	int i, j;
	string t[12];
	rep(i, h) rep(j, w) t[i] += s[i][perm[j]];
	bool used[12] = {false};
	rep(i, h) {
		if (used[i]) continue;
		string tmp = reverse(t[i]);
		rep(j, h) if (j != i && !used[j] && tmp == t[j]) break;
		if (j < h) {
			used[i] = true; used[j] = true;
		}
	}
	
	int ngCnt = 0;
	rep(i, h) {
		if (used[i]) continue;
		if (h % 2 == 0) break;
		ngCnt++;
		if (ngCnt >= 2) break;
		if (reverse(t[i]) != t[i]) break;
	}
	return i == h;
}

//探索 (ICPC2017-Asia-Bと本質は同じ)
int kumi[8][2];	//対称な位置にある元のペア
bool dfs(int rem, int noUse, int depth) {
	int i, j;
	vector<int> perm;
	
	if (w - depth * 2 == 1) {	//バグがあります
		perm.resize(w);
		for (j = 0; j < depth; j++) {
			perm[j] = kumi[j][0];
			perm[w - 1 - j] = kumi[j][1];
		}
		perm[(w - 1) / 2] = noUse;
		//for (j = 0; j < perm.size(); j++) cout << perm[j] << " "; cout << endl;
		if (check(perm)) return true;
		return false;
	}
	if (w == depth * 2) {
		perm.resize(w);
		for (j = 0; j < depth; j++) {
			perm[j] = kumi[j][0];
			perm[w - 1 - j] = kumi[j][1];
		}
		if (check(perm)) return true;
		return false;
	}
	
	for (i = 0; i < w; i++) if (i != noUse && ((rem >> i) & 1)) break;
	for (j = i + 1; j < w; j++) {
		if (j != noUse && ((rem >> j) & 1)) {
			kumi[depth][0] = i;
			kumi[depth][1] = j;
			bool res = dfs(rem - (1 << i) - (1 << j), noUse, depth + 1);
			if (res) { return true; }
		}
	}
	return false;
}

signed main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) cin >> s[i];
	
	//ランダムシャッフルを入れる
	random_row();
	random_col();
	
	//探索
	bool res = false;
	if (w % 2 == 0) res = dfs((1 << w) - 1, -1, 0);
	else {
		for (i = 0; i < w; i++) {
			res = dfs((1 << w) - 1, i, 0);
			if (res) break;
		}
	}
	
	if (res) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    bool flag = false;
    int cnt = 0;
    for(int i = 0;i<n;i++){
        cin >> a[i].first >> a[i].second;
        if(a[i].first == a[i].second){
            cnt++;
        }else cnt = 0;
        if(cnt == 3) flag = true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    
    string l="";
    string m="";
    for(int i=0;i<n;i++){
        m+=s.at(i);
        if(l!=m){
            ans++;
            l=m;
            m="";
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640