akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main{

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int[][][] rooms = new int[4][3][10];
      for( int i = 0; i < 4; i++ ) {
        for( int j = 0; j < 3; j++ ) {
          Arrays.fill(rooms[i][j], 0);
        }
      }
      String[] lines = br.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int b,f,r;

      for(int i = 0; i < n; i++) {
        lines = br.readLine().split(" ");
        b = Integer.parseInt(lines[0]);
        f = Integer.parseInt(lines[1]);
        r = Integer.parseInt(lines[2]);
        rooms[b-1][f-1][r-1] += Integer.parseInt(lines[3]);
      }

      StringBuilder result = new StringBuilder(300);
      String sep = "####################\n";
      for(int i = 0; i < 4; i++ ) {
        for( int j = 0; j < 3; j++ ) {
          for( int k = 0; k < 10; k++ ){
            result.append(" " +rooms[i][j][k]);
          }
          result.append("\n");
        }
        if( i != 3) result.append(sep);
      }
      System.out.print(result);
    }
  }
}


Measured memory_bytes: 24608
n,x = gets.split.map(&:to_i)
dp = (n+2).times.map{Array.new(n,10**9)}
dp[0] = gets.split.map(&:to_i)

min = dp[0].inject(:+)
n.times{|b|
  res = dp[b].inject(:+) + x*b
  min = res if min > res
  (n-1).downto(0){|i|
    dp[b+1][i%n] = dp[b][(i-1)%n]
    dp[b+1][i%n] = dp[b][i%n] if dp[b+1][i%n] > dp[b][i%n]
  }
}

p min


Measured memory_bytes: 33276
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int k = -1;
  rep(i, 500) {
    if (i * (i + 1) / 2 == n) {
      k = i + 1;
      break;
    }
  }
  if (k == -1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  cout << k << endl;
  vector<int> s[k];
  int res = 1;
  rep(i, k) {
    rep(j, i) {
      s[i].push_back(res);
      s[j].push_back(res);
      res++;
    }
  }
  rep(i, k) {
    cout << s[i].size();
    rep(j, s[i].size()) {
      cout << ' ' << s[i][j];
    }
    cout << endl;
  }


  
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll T;
ll A, B, C, D;

ll gcd(ll p, ll q)
{
    if(q == 0) return p;
    else return gcd(q, p % q);
}

int main()
{
    cin>>T;
    while(T--)
    {
        cin>>A>>B>>C>>D;
        if(A < B || D < B)
        {
            cout<<"No"<<endl;
            continue;
        }
        ll g = gcd(D, B);
        if((C + g - A % g) / g * g + A % g < B)
        {
            cout<<"No"<<endl;
        }
        else
        {
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;  
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXBEAM=100000;
struct Beam { int a,b; int key; };
bool operator<(const Beam &p,const Beam &q) { return p.key<q.key; }
struct Frac { ll num,den; Frac():num(0),den(1) {} Frac(ll _num,ll _den) { num=_num,den=_den; ll g=gcd(num,den); num/=g; den/=g; } };
bool operator>(const Frac &p,const Frac &q) { return p.num*q.den>q.num*p.den; }

int nbeam;
Beam beam[MAXBEAM];

int nslow;
Beam slow[MAXBEAM];
int nfast;
Beam fast[MAXBEAM];


Frac solve() {
	nslow=nfast=0;
	REP(i,nbeam) if(beam[i].a<beam[i].b) fast[nfast++]=beam[i]; else slow[nslow++]=beam[i];
	REP(i,nfast) fast[i].key=fast[i].b; sort(fast,fast+nfast);
	REP(i,nslow) slow[i].key=slow[i].a; sort(slow,slow+nslow);
	
	if(nfast==0) return Frac(0,1);
	ll asum=0,bsum=0;
	REP(i,nfast) asum+=fast[i].a;
	int atslow=0;
	for(int i=nfast-1;i>=0;--i) {
		while(atslow<nslow&&bsum+fast[i].b>=asum) {
			if(slow[atslow].a>=fast[i].b) break;
			if(bsum+fast[i].b>=asum+slow[atslow].a) { asum+=slow[atslow++].a; continue; }
			if(i==0) break;
			if(slow[atslow].a>=fast[i-1].b) break;
			if(bsum+fast[i].b+fast[i-1].b>=asum+slow[atslow].a) { asum+=slow[atslow++].a; continue; }
			assert(false);
		}
		if(bsum+fast[i].b>=asum) {
			int ipart=atslow+i;
			Frac fpart(bsum+fast[i].b-asum,fast[i].b);
			int idx=-1; REP(k,atslow) if(idx==-1||slow[k].b>slow[idx].b) idx=k;
			FOR(k,atslow,nslow) {
				assert(bsum+fast[i].b<asum+slow[k].a);
				if(bsum+fast[i].b+slow[k].b>=asum+slow[k].a) {
					Frac cpart(bsum+fast[i].b+slow[k].b-asum-slow[k].a,slow[k].b);
					if(cpart>fpart) fpart=cpart;
				}
				if(i!=0&&bsum+fast[i].b+fast[i-1].b>=asum+slow[k].a) {
					Frac cpart(bsum+fast[i].b+fast[i-1].b-asum-slow[k].a,fast[i-1].b);
					if(cpart>fpart) fpart=cpart;
				}
				if(idx!=-1&&bsum+fast[i].b+slow[idx].b>=asum+slow[k].a) {
					Frac cpart(bsum+fast[i].b+slow[idx].b-asum-slow[k].a,slow[idx].b);
					if(cpart>fpart) fpart=cpart;
				}
			}
			return Frac((ll)ipart*fpart.den+fpart.num,(ll)fpart.den*nbeam);
		}
		bsum+=fast[i].b;
	}
	assert(false); return Frac(0,1);
}

void run() {
	scanf("%d",&nbeam);
	REP(i,nbeam) scanf("%d%d",&beam[i].a,&beam[i].b);
	Frac ans=solve();
	printf("%lld %lld\n",ans.num,ans.den);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int d;
	cin >> d;
	d=365;
	vector<int> c(27);
	vector<vector<int>> s(d + 1, vector<int>(27));
	vector<int> t(d + 1);
	vector<int> last(27);
	for (int i = 0; i <= 27; i++)
		last[i] = 0;
	for (int i = 1; i <= 26; i++)
		cin >> c[i];
	for (int i = 1; i <= d; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> s.at(i).at(j);
		}
	}
	int sum = 0;
	for (int i = 1; i <= d; i++) {
		int ma1 = -1, ma2 = -1;
		for (int j = 1; j <= 26; j++) {
			if (ma1 <= s[i][j]) {
				ma1 = s[i][j];
				ma2 = j;
			}
		}
		cout << ma2 << endl;
		sum += s[i][ma2];
		last[ma2] = i;
		for (int j = 1; j <= 26; j++) {
			sum -= c[j] * (i - last[j]);
		}
	}
	return 0;
}


Measured memory_bytes: 3716
function main(input) {
const S = input.split("\n")[0];
const K = parseInt(input.split("\n")[1],10);
let bool = true;
for(let i=0;i<K;i++){
  if(S.charAt(i)!=="1"){bool=false;break;}
}
 if(bool){
   console.log('1');
 }else{
   console.log(S.split('').find((v)=>v!=="1"))
 } 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
def examB():
    H, W = LI()
    St = [S() for _ in range(H)]
    ans = [[] for _ in range(H)]
    for i1,l in enumerate(St):
        for i2,j in enumerate(l):
            cur = int(0)
            if j==".":
                for k in range(3):
                    for p in range(3):
                        if 0<=i1-1+k<H and 0<=i2-1+p<W:
                            if St[i1 - 1 + k][i2 - 1 + p] == "#":
                                cur += 1
            else:
                cur = "#"
            ans[i1].append(str(cur))
    for v in ans:
        print("".join(map(str,v)))



import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 3636
#include <iostream>
using namespace std ;
int main()
{
	int S=0 , s=0 , m=0 , h=0 ;
	cin >> S ;
	h=S/3600 ;
	m=S%3600/60 ;
	s=S%3600%60 ;
	cout << h << ":" << m << ":" << s << endl ;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(ll i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    string s,t={'N', 'W', 'S', 'E'};
    cin >> s;
    map<char, int> m;
    rep(i,t.size()){
        m[t[i]] = 0;
    }
    rep(i,s.size()){
        m[s[i]]++;
    }
    if(m['N'] == 0 && m['S'] > 0){
        cout << "No" << endl;
        return 0;
    }
    if(m['N'] > 0 && m['S'] == 0){
        cout << "No" << endl;
        return 0;
    }
    if(m['W'] == 0 && m['E'] > 0){
        cout << "No" << endl;
        return 0;
    }
    if(m['W'] > 0 && m['E'] == 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int c = 0;
    int x = n;
    if (x < k) {
        cout << 1 << endl;
    }else {
        while (true) {
            x = (x - (x%k)) / k;
            c++;
            if (x < k) {
                break;
            }
        }
        cout << c+1 << endl;
    }
}


Measured memory_bytes: 256
function main(input) {
	const args = input.split(' ');
	const a = parseInt(args[0], 10);
	const b = parseInt(args[1], 10);

	if ((a * b) % 2 == 0) {
		console.log('Even');
	} else {
		console.log('Odd');
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int Combination(int n, int m) {
    int ans = 1; 
    for(int i=n; i>=(n-m+1); --i) 
        ans *= i; 
    while(m) 
        ans /= m--; 
    return ans; 
} 
int main(){
	int n,h,w;
	scanf("%d %d %d",&n,&h,&w);
//	if(h==1 && w==1){
//		printf("%d\n",n*n);
//	}else if(n==w){
//		printf("%d\n",Combination(n-h+1,1));
//	}else{
		printf("%d\n",Combination(n-h+1,1)*Combination(n-w+1,1));
//	}
	return 0;
}


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

//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2027297#1
public class Main {

	static int vertex;
	static int edges;
	static boolean[] visited;
	static int[] cost;
	static int[] parent;
	static ArrayList<Edge>[] graph;
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static final int INFINITY = Integer.MAX_VALUE;
	static Main obj = new Main();

	class Edge implements Comparable<Edge> {

		int from;
		int to;
		int weight;

		public Edge(int from, int to, int weight) {
			this.from = from;
			this.to = to;
			this.weight = weight;
		}

		@Override
		public int compareTo(Edge other) {
			int diff = weight - other.weight;
			return diff;
		}

	}

	public static void main(String[] args) throws IOException {

		input();
		prim();

	}

	@SuppressWarnings("unchecked")
	public static void input() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		vertex = Integer.parseInt(st.nextToken());
		edges = Integer.parseInt(st.nextToken());
		visited = new boolean[vertex];
		cost = new int[vertex];
		parent = new int[vertex];
		graph = new ArrayList[vertex];
		for (int i = 0; i < graph.length; i++) {
			graph[i] = new ArrayList<Edge>();
		}
		for (int i = 0; i < edges; i++) {
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());

			graph[a].add(obj.new Edge(a, b, c));
			graph[b].add(obj.new Edge(b, a, c));

		}
		for (int i = 0; i < cost.length; i++) {
			cost[i] = INFINITY;
		}

	}

	public static void prim() {

		int added = 1;
		int sum = 0;
		visited[0] = true;
		cost[0] = 0;
		PriorityQueue<Edge> pq = new PriorityQueue<Edge>();
		for (Edge e : graph[0]) {
			pq.offer(e);
		}
		while (!pq.isEmpty()) {
			Edge e = pq.poll();
			if (visited[e.to]) {
				continue;
			}

			sum += e.weight;
			added++;
			cost[e.to] = e.weight;
			parent[e.to] = e.from;
			visited[e.to] = true;

			if (added == vertex) {
				break;
			}
			for (Edge q : graph[e.to]) {
				if (visited[q.to]) {
					continue;
				} else {
					pq.offer(q);
				}
			}

		}
		System.out.println(sum);

	}

}

Measured memory_bytes: 71332
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int[] arr = new int[5];
        int ans = 0;
        for(int i=0;i<5;i++){
            arr[i]=sc.nextInt();
            if(arr[i]==0){
                ans=i+1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 32564
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
char s[200005];
int n,a[2];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int sum=0,sum2=0;
	ll res=0;
	For(i,1,n) if (s[i]=='1') ++sum; 
	For(i,1,sum) res+=(i+1)/2;
	sum=0; sum2=0;
	For(i,1,n){
		if (s[i]=='1'){
			res+=(sum2+sum%2)/2;
			++a[sum%2];
			++sum;
		}
		else{
			++sum2;
			res+=max(a[0],a[1]);
			a[0]=a[1]=max(a[0],a[1]);
		}
	}
	cout<<res<<endl;
}
/*
+1:1
+0:11
+1:12
+0:122
+1:223
*/

Measured memory_bytes: 3992
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b>=c){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

int main() {
	ll n;
	cin >> n;
	ll ans = n * (n - 1) / 2;
	cout << ans << endl;
	return 0;
}


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

int main() {
  long long A,B,N;
  cin >> A >> B >> N;
  long long ans = 0;
  if (B > N) {
    ans = A*N/B;
  }
  else {
    ans = A*(B-1)/B;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
char s[100001];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    scanf("%s", s+1);

    bool ok = 1;
    for(int i=2;i<=n;i++){
        if(s[i] == s[i-1]) continue;
        ok = 0;
    }

    if(ok){
        printf("%d\n", n-1);
        return 0;
    }

    int sum = 0;
    int cnt1 = 0, cnt2 = 0;
    vector<int> v;
    for(int i=1;i<=n;i++){
        if(s[i] == 'R'){
            if(cnt2 > 0){
                if(cnt2 == i-1) v.push_back(1);
                else v.push_back(2);
                sum += cnt2-1;
            }

            cnt1++;
            cnt2 = 0;
        }
        else{
            if(cnt1 > 0){
                if(cnt1 == i-1) v.push_back(1);
                else v.push_back(2);
                sum += cnt1-1;
            }

            cnt2++;
            cnt1 = 0;
        }
    }

    if(cnt1 > 0) sum += cnt1-1;
    if(cnt2 > 0) sum += cnt2-1;
    if(cnt1 > 0 || cnt2 > 0) v.push_back(1);

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    for(int i=0;i<min((int)v.size(), k);i++){
        sum += v[i];
    }
    sum = min(sum, n-1);
    printf("%d\n", sum);
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {

    public Main() {
    }

    private static Scanner sc;

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().run();
    }

    private void run() {
        String s = sc.next();
        int start = 0;
        int end = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'A') {
                start = i;
                break;
            }
        }

        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            if (c == 'Z') {
                end = i;
                break;
            }
        }

        System.out.println(end - start + 1);
    }
}


Measured memory_bytes: 14340
#!/usr/bin/env python
# coding: utf-8


f = lambda x: x ** 2


def calc_area(d):
    area = 0
    for i in xrange(1, 600 / d):
        area += f(d * i) * d
    return area


def main():
    while 1:
        try:
            d = int(raw_input())
        except EOFError:
            return
        print calc_area(d)

if __name__ == '__main__':
    main()

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

template <class T>
struct Unionfindw {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // edge weight
  vector<T> weight;
  // constructor
  Unionfindw(int n = 1, T initialnum = 0) {
    stree(n + 1, initialnum);
  }
  // make and initialization
  void stree(int n = 1, T initialnum = 0) {
    par.assign(n, -1);
    treerank.assign(n, 0);
    weight.assign(n, initialnum);
  }
  // search root
  int root(int x) {
    if(par[x] < 0) return x;
    int rx = root(par[x]);
    weight[x] += weight[par[x]];
    return par[x] = rx;
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }
  // calculate weight
  T calcw(int x) {
    root(x);
    return weight[x];
  }
  // add
  // x+w = y
  // already added, return 0
  bool uni(int x, int y, T w = 0) {
    w += calcw(x);
    w -= calcw(y);
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] > treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) ++treerank[x];
    par[y] -= size(x);
    par[x] = y;
    weight[x] = -w;
    return 1;
  }

  int size(int x) { return -par[root(x)]; }

  // calculate difference between x and y (y-x)
  // if not same tree, return 1
  T calcdiff(int x, int y) {
    if(!issame(x, y)) return -1;
    return calcw(y) - calcw(x);
  }
};


void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

long long n, m;
vector<pair<long long, long long>> edges[100005];
Unionfindw<long long> ufw;

bool solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    --l, --r;
    edges[l].push_back(make_pair(d, r));
  }
  prians(solve());
  return 0;
}

bool solve() {
  ufw = Unionfindw<long long>(n + 1);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < edges[i].size(); ++j) {
      long long r = edges[i][j].se, d = edges[i][j].fi;
      if(!ufw.issame(i, r))
        ufw.uni(i, r, d);
      else if(ufw.calcdiff(i, r) != d)
        return 0;
    }
  return 1;
}


Measured memory_bytes: 9216
a,b,c = list(map(int, input().split()))

"""
a ** 0.5 + b ** 0.5 < c ** 0.5
a + 2(a*b) ** 0.5 + b < c
2(a*b) ** 0.5 < (c - a -b)
#c-a-b>0のとき
4(a*b) < (c - a -b)**2
a*b < (c-a-b)**2/4
"""

if 4*(a*b) < (c-a-b)**2 and c-a-b>0:
    print("Yes")
else:
    print("No")

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
		ANS(0);
		return 0;
	}
	int x = abs(a-b);
	int y = abs(b-c);
	int z = abs(c-a);
	if(max(x , max(y, z)) == 0){
		ANS(-1);
		return 0;
	}
	int ans = 0;
	while(x % 2 == 0 && y % 2 == 0 && z % 2 == 0){
		x /= 2;
		y /= 2;
		z /= 2;
		ans++;
	}
	ANS(ans);
	return 0;
}


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

using namespace std;

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

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

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n;
   string s;
   cin >> n >> s;
   vector<int> black(n+1);
   for(int i=0;i<n;i++){
      if(s[i] == '#')black[i+1] = black[i] + 1;
      else black[i+1] = black[i];
   }
   int ans = n;
   for(int i=0;i<n+1;i++){
      int tmp = black[i] + (n - black[n] - i + black[i]);
      ans = min(tmp,ans);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll a, b, c;
 	cin >> a >> b >> c;
 	cout << c << ' ' << a << ' ' << b << endl;   
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x));
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 1e5 + 5, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
int n, rp[N], si[N];
ll ans;
vector<pair<int, pair<int, int>>>x, y;
map<int, vector<pair<int, int>>> mp;
int find(int u)
{
	return (rp[u] == u)? u : rp[u] = find(rp[u]);
}
bool join(int u, int v)
{
	u = find(u), v = find(v);
	if(u == v)
		return false;
	if(si[u] < si[v])
		swap(u, v);
	si[u] += si[v];
	rp[v] = u;
	return true;
}
int main()
{
    MuhammedAly
    cin >> n;
    fill(si, si + n + 1, 1);
    iota(rp, rp + n + 1, 0);
    x.resize(n);
    y.resize(n);
    for(int i = 0 ; i < n ; i++)
    {
    	cin >> x[i].first >> x[i].second.first;
    	y[i].first = x[i].second.first;
    	y[i].second.first = x[i].first;
    	x[i].second.second = y[i].second.second = i;
    }
    sort(all(x));
    sort(all(y));
    for(int i = 0 ; i < n - 1; i++)
    {
    	mp[x[i + 1].first - x[i].first].pb({x[i].second.second, x[i + 1].second.second});
    	mp[y[i + 1].first - y[i].first].pb({y[i].second.second, y[i + 1].second.second});
    }
    for(auto i : mp)
    {
    	for(auto j : i.second)
    		if(join(j.second, j.first))
    			ans += i.first;
    }
    cout << ans;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N), B(N), C(N - 1);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B.at(A.at(i) - 1);
    if (i >= 1 && (A.at(i) - A.at(i - 1) == 1)) {
      ans += C.at(A.at(i - 1) - 1);
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
X = int(input())

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(X):
        print(X)
        exit(0)
    X += 1

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/4;
    public static final int inf = Integer.MAX_VALUE/4;

    static void solve(InputReader in, PrintWriter out){
        long n = in.ni(), m = in.ni();
        long ans = 0;
        if(n==1||m==1){
            if(n==1&&m==1){
                ans = 1;
            }else{
                ans = n*m-2;
            }
        }else{
            ans = (n-2)*(m-2);
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

typedef long long ll;
using vi = vector<int>;
using vll = vector<ll>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

    int ans = 0;
    rep(i, n - 2) {
        if(s.substr(i, 3) == "ABC") ans++;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x) 
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define fo(i, a, b) for (int i = a; i <= b; ++i)

int n;
ll k;
int cnt[40];
ll res[40][2];

ll dp(int i, int bnd) {
    if (i == 0) return (bnd && ((k&1)==0)) ? cnt[i] : max(cnt[i], n-cnt[i]);
    if (~res[i][bnd]) return res[i][bnd];
    
    if (bnd) {
        if (k&(1LL<<i)) res[i][bnd] = max(dp(i-1, 1) + (ll)(n-cnt[i])*(1LL<<i), dp(i-1, 0) + (ll)cnt[i]*(1LL<<i));
        else res[i][bnd] = dp(i-1, 1) + (ll)cnt[i]*(1LL<<i);
    }
    else {
        res[i][bnd] = dp(i-1, 0) + (ll)max(cnt[i], n-cnt[i]) * (1LL<<i);
    }
    return res[i][bnd];
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    memset(cnt, 0, sizeof cnt);

    rep(i, n) {
        ll a; cin >> a;
        for (int j = 0; j < 40; ++j) {
            if (a&(1LL<<j)) ++cnt[j];
        }
    }
    //for (int i = 0; i < 40; ++i) cout << cnt[i] << ' '; cout << endl;

    memset(res, -1, sizeof res);
    cout << dp(39, 1) << '\n';
    //    for (int i = 0; i < 40; ++i) {
    //for (int s = 0; s < 2; ++s) {
    //        cout << res[i][s] << ' ';
    //    } cout << endl;
    //}
}



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

using namespace std;

int main(void){
  string s;
  cin >> s;
  int f_s = 0;
  int s_e = s.length()-1;
  int s_s = s.length()/2;
  int f_e = s_s-1;
  while(true){
    f_e = f_e - 1;
    s_s = s_s - 1;
    s_e = s_e - 2;
    int flag = 0;
    for(int i = 0; i<=f_e;i++){
      if(s[i] != s[s_s+i]){
        flag = 1;
        break;
      }
    }
    
    if(flag == 0){
      cout << s_e+1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main (void){
  int d , n;
  scanf("%d %d",&d , &n);
  
 int k = pow(100,d);
  
  if(n!=100){
  printf("%d",n*k);
  }
 
   else {  
      printf("%d",(n+1)*k);
    }
  
  return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ll a;
    double b;
    cin >> a >> b;
    ll x = b*100 + 0.001;
    cout << (ll)(a*x/100) << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

// __attribute__((constructor)) void initial() {
//   cin.tie(nullptr);
//   ios::sync_with_stdio(false);
//   cout << fixed << setprecision(15);
// }

signed main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll Q;
  cin >> Q;
  vector<ll> k(Q);
  rep(i, Q) {
    cin >> k[i];
  }

  rep(q, Q) {
    ll D = 0, M = 0, DM = 0;
    ll r = 0;
    ll ans = 0;
    rep(l, N - k[q] + 1) {
      while (r < N && r - l < k[q]) {
        if (S[r] == 'D')
          D++;
        else if (S[r] == 'M') {
          M++;
          DM += D;
        } else if (S[r] == 'C')
          ans += DM;
        r++;
      }

      if (S[l] == 'D') {
        D--;
        DM -= M;
      } else if (S[l] == 'M')
        M--;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1412
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a[]=new int[5];
		int z=0,y=0,fin=0;
		while(z<5){
			a[z]=stdIn.nextInt();
			z++;
		}z=0;
		int k=stdIn.nextInt();
		while(z<5){
			y=z+1;
			while(y<5){
				if(a[y]-a[z]>k){
					fin=1;
					break;
				}
				y++;
			}
			z++;
		}
		if(fin==1)
			System.out.println(":(");
		else
			System.out.println("Yay!");
	}
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var c1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var c2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var c3 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            string ans = "Yes";
            if (c1.Zip(c2, (x, y) => x - y).Distinct().Count() != 1) ans = "No";
            if (c1.Zip(c3, (x, y) => x - y).Distinct().Count() != 1) ans = "No";
            var temp = c1.ToArray();
            c1[1] = c2[0];
            c1[2] = c3[0];
            c2[0] = temp[1];
            c3[0] = temp[2];
            temp = c2.ToArray();
            c2[2] = c3[1];
            c3[1] = temp[2];
            if (c1.Zip(c2, (x, y) => x - y).Distinct().Count() != 1) ans = "No";
            if (c1.Zip(c3, (x, y) => x - y).Distinct().Count() != 1) ans = "No";
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define dump(X) cout << #X << ' ' << X << endl
#define pe(X) cout << X << endl
#define pb push_back
#define INF 1000000000
#define sec second
#define fi first
int dp[1<<11];
int N,M,H,K;
int S,T;
int Pn;
int pS[500],pcost[500];

struct edge{
	int to,cost,company;
	edge(){}
	edge(int to,int cost,int company):to(to),cost(cost),company(company){}
};
vector<edge> g[100100];
int d[100100];
int encode(int pos,int t){
	return 100*pos+t;
}
int rec(int Sb){
	if(dp[Sb]!=INF)return dp[Sb];
	for(int i=0;i<Pn;i++){
		if((pS[i]&Sb)!=pS[i])continue;
		int res = Sb-pS[i];
		for(int T=0;T<(1<<K);T++){
			if((res&T)!=res)continue;
			if((Sb&T)!=T)continue;
			if(Sb == T) continue;
			dp[Sb]=min(dp[Sb],pcost[i]+rec(T));
		}
	}
	return dp[Sb];
}

int dijkstra(int pas_S){
	for(int i=0;i<100100;i++)d[i]=INF;
	int s = encode(S,0);
	d[s]=0;
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(d[s],s));
	while(!q.empty()){
		int v = q.top().sec;
		int dv = q.top().fi;
		q.pop();
		if(d[v]<dv)continue;
		for(int i=0;i<g[v].size();i++){
			edge e = g[v][i];
			int cost = e.cost;
			if((pas_S>>e.company)&1){ // free
				cost = 0;
			}
			if(d[e.to]>d[v]+cost){
				d[e.to]=d[v]+cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
	int res = INF;
	for(int i=0;i<=H;i++){
		res = min(res,d[encode(T,i)]);
	}
	return res;
}
bool solve(){
	cin >> N >> M >> H >> K;
	if(N+M+H+K==0)return false;
	for(int i=0;i<100100;i++)g[i].clear();
	for(int i=0;i<M;i++){
		int a,b,c,h,r;
		cin >> a >> b >> c >> h >> r;
		a--;b--;
		r--;
		for(int i=0;i<H;i++){
			int v,u;
			v = encode(a,i);
			u = encode(b,i+h);
			g[v].pb(edge(u,c,r));
			//printf("%d %d %d %d\n",v,u,c,r); 
			
			v = encode(b,i);
			u = encode(a,i+h);
			g[v].pb(edge(u,c,r));
			//printf("%d %d %d %d\n",u,v,c,r);
		}
	}
	cin >> S >> T;
	S--;T--;
	cin >> Pn;
	for(int i=0;i<Pn;i++){
		int l;
		cin >> l >> pcost[i];
		pS[i]=0;
		for(int j=0;j<l;j++){
			int tmp;
			cin >> tmp;
			tmp--;
			pS[i] |= (1<<tmp);
		} 
	}

	// dp part
	for(int i=0;i<(1<<K);i++){
		dp[i]=INF;
	}
	dp[0]=0;
	for(int i=0;i<(1<<K);i++){
		rec(i);
	}
	/*for(int i=0;i<(1<<K);i++){
		cout << "a" << dp[i] << endl;
	}*/
	int ans = INF;
	for(int i=0;i<(1<<K);i++){
		//cout << i << ' '<< dijkstra(i) << endl;
		ans = min(ans,dijkstra(i)+dp[i]);
	}
	if(ans==INF)cout << -1 << endl;
	else cout << ans << endl;
	return true;
}
int main(){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 6632
#include <bits/stdc++.h>
#define forna(i,a,n) for(int i=a;i<n;i++)
typedef long long int lli;
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli k;string s,s2;
cin>>k>>s;
if(s.length()<=k) cout<<s<<endl;
else{
  string s2;
  forna(i,0,k) s2+=s[i];
  forna(i,0,3) s2+='.';
  cout<<s2<<endl;
}}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  vector<int> v(N+1, 0), w(N+1, 0);
  for(int i=N-1; i>=0; i--){
    v[i] = v[i+1] + ((S[i]=='.')?1:0);
    w[i] = w[i+1] + ((S[i]=='#')?1:0);
  }

  int ret = -1;
  int prev = 0;
  rep(i,N){
    if(S[i] == '.') continue;
    int j=i;
    while(j+1<N && S[j+1]=='#') j++;
    if(ret == -1) ret = min(v[i], w[i]);
    else {
      ret = min(ret, v[i] + prev);
      ret = min(ret, w[i] + prev);
    }
    //cerr << v[i] << " " << w[i] << " " << prev << endl;
    prev += j-i+1;
    i=j;
  }

  if(ret == -1) ret = 0;

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}



using namespace std;
int main(){
    int n,x,cnt = 0;
    cin >> n;

    vector<int> vec1;
    vector<int> vec2;

    if(n%2==0){
        REP(i,n){
            cin >> x;

            if(i%2 == 0){
                vec2.push_back(x);
            }else{
                vec1.push_back(x);
                cnt ++;
            }
        }
        REVERSE(vec1);
    }else{
        REP(i,n){
            cin >> x;
            
            if(i%2==0){
                vec1.push_back(x);
                cnt ++;
            }else{
                vec2.push_back(x);
            }
            
        }
        REVERSE(vec1);
    }
    
    REP(i,cnt){
        cout << vec1[i] << " ";
    }

    REP(i,n-cnt){
        cout << vec2[i] << " ";
    }

    cout<<endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl d(n);
  REP(i,n) cin >> d[i];
  ll ans = 0;
  REP(i,n){
    REP(j,n){
      if(i<j) ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <set>
#include <queue>
#define N 100010
using namespace std;
int n,m,d[N];
int ne=0,h[N];struct edge{int to,w,x;}e[400010];
inline void ins(int s,int t,int w) {
	e[++ne].to=t;e[ne].w=w;e[ne].x=h[s];h[s]=ne;
}
struct stat {
	int n,d;
	stat(){}
	stat(int a,int b){n=a;d=b;}
	inline bool operator>(const stat& a) const {
		return d!=a.d?d>a.d:n<a.n;
	}
};
set<int> vis[N];
inline int dij(int s,int t) {
	priority_queue<stat,vector<stat>,greater<stat> > q;
	stat u;int v,oo,nd;
	memset(d,33,sizeof(d));oo=*d;
	d[s]=0;q.push(stat(s,0));
	while(!q.empty()) {
		u=q.top();q.pop();
		if(u.d>d[u.n]) continue;
		for(int i=h[u.n];i;i=e[i].x) {
			v=e[i].to;nd=u.d+(vis[u.n].count(e[i].w)?0:1);
			if(nd<d[v]) {
				d[v]=nd;q.push(stat(v,nd));
				vis[v].clear();
			}
			if(nd==d[v]) vis[v].insert(e[i].w);
		}
	}
	return oo==d[t]?-1:d[t];
}
int main() {
	int a,b,c;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i) {
		scanf("%d%d%d",&a,&b,&c);
		ins(a,b,c);ins(b,a,c);
	}
	printf("%d",dij(1,n));
	return 0;
}

Measured memory_bytes: 20088
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import lru_cache

N, K = map(int,read().split())

@lru_cache(None)
def F(N, K):
    """N以下で0でないものがちょうどK個。0を含める"""
    assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        if K == 1:
            return N
        return 0
    q,r = divmod(N,10)
    ret = 0
    if K >= 1:
        # 1の位が nonzero
        ret += F(q, K-1) * r
        ret += F(q-1, K-1) * (9-r)
    # 1の位が zero
    ret += F(q, K)
    return ret

# F(100, 1), F(25, 2), F(314159, 2)

print(F(N, K))

Measured memory_bytes: 3940
#include <stdio.h>
#include <string.h>

int main(){
  int i=0,j;
  char str[100];
  char ch;
  while ((ch=getchar())!=EOF){
    if (islower(ch)!=0){
      str[i++]=toupper(ch);
    }else{
      str[i++]=ch;
    }
  }
  for (j=0;j<i;j++)
    printf("%c",str[j]);
  return 0;
}

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

for i in range(n):
    a, b, c = map(int, input().split())
    if (a**2 == b**2 + c**2) or (b**2 == a**2 + c**2) or (c**2 == a**2 + b**2):
        print("YES")
    else:
        print("NO")


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

int main() {
    string s;
    cin >> s;
    bool ans = false;
    
    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i + 1]) {
            ans = true;
            break;
        }
    }
    
    cout << (ans ? "Bad" : "Good") << endl;
    return 0;
}

Measured memory_bytes: 256
class fenwick_tree():
    def __init__(self, n:int):
        self.__n = n
        self.__data = [0] * self.__n

    def add(self, p:int, x:int):
        assert (0 <= p) & (p < self.__n)
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            p += p & -p

    def sum(self, l:int, r:int):
        assert (0 <= l) & (l <= r) & (r <= self.__n)
        return self.__sum_mod0(r) - self.__sum_mod0(l)

    def __sum_mod0(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            r -= r & -r
        return s


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
a = list(map(int,readline().split()))
query = list(map(int,read().split()))

ft = fenwick_tree(n)
ans = []

for i,ai in enumerate(a):
    ft.add(i,ai)

i = 0
for _ in range(q):
    if(query[i]==0):
        p,x = query[i+1:i+3]
        ft.add(p,x)
    else:
        l,r = query[i+1:i+3]
        ans.append(ft.sum(l,r))
    i += 3

print('\n'.join(map(str,ans)))


Measured memory_bytes: 252728
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, M;
vector<int> adj[100001];
ll H[100001];

signed main(){
    cin >> N >> M;
    REP(i, N) cin >> H[i];
    int a, b;
    REP(i, M){
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans = 0;
    REP(i, N){
        bool good = true;
        for(int j : adj[i]){
            if(H[i] <= H[j]){
                good = false;
                break;
            }
        }
        if(good) ans++;
    }
    PRINT(ans);
    return 0;
}

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

int main(){
    int n, m;   cin >> n >> m;
    map<int, int_fast8_t> mp;
    for(int i=0; i<n; i++){
        int k;  cin >> k;
        for(int j=0; j<k; j++){
            int x;  cin >> x;
            mp[x] += 1;
        }
    }
    int cnt=0;
    for(auto x: mp)
        if(x.second==n) cnt += 1;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n = 0 , a = 0 , c = 0;
  cin >> n;
  cin >> a;
  
  c = n % 500;
  if (a >= 499 || a >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256