akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
using namespace std;

// 隣接リストで使う辺を表す型
struct Edge {
	long long to, cost;  // 辺の接続先頂点, 辺の重み
	Edge(long long to, long long cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<Edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
// graph[v][i]は頂点vから出るi番目の辺Edge

const long long INF = 922337203685477580;

vector<long long> dist; // 最短距離
vector<bool> neg;		//閉路を含むか

// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点
	dist = vector<long long>(n, INF);
	neg = vector<bool>(n, false);
	dist[s] = 0; // 開始点の距離は0
	for (long long i = 0; i < n; i++) {
		for (long long v = 0; v < n; v++) {
			for (long long k = 0; k < graph[v].size(); k++) {
				Edge e = graph[v][k];
				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					if (i == n - 1) {
						neg[e.to] = true;
						return true; // n回目にも更新があるなら負の閉路が存在
					}
				}
			}
		}
	}
	return false;
}

int main() {
	long long n, m;
	cin >> n >> m;
	n++;

	graph = AdjList(n);

	for (long long i = 0; i < m; i++) {
		long long from, to, cost;
		cin >> from >> to >> cost;
		cost *= -1;	//コストを-1倍することで最長経路を求める
		graph[from].push_back(Edge(to, cost));
	}

	bellman_ford(n, 1);
	for (int i = 0; i < 4000; i++){
		for (size_t j = 0; j < graph.size();j++){
			for (size_t k = 0; k < graph[j].size(); k++){
				if (neg[j]) neg[graph[j][k].to] = true;
			}
		}
	}

	if (neg[n-1]){ cout << "inf" << endl; }
	else{
		cout << -(dist[n - 1]) << endl;
	}

	return 0;
}

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


/*
string BN(ll a){
    string S="";
    S.push_back((a&1) + '0');
    while (a >>=1) {
        S.push_back((a&1) + '0');
    }
    reverse(S.begin(), S.end());
    return S;
}*/

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll s1 = b*d,s2=a*c,s3=a*d,s4=b*c;
    ll maxc = max(max(s1, s2), max(s3, s4));
    cout << maxc << endl;
}



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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void Dump(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

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

    auto v = vc<stack<int>>(n);

    REP(i, p) {
        int query, t;
        cin >> query >> t;

        if (query == 0) {
            int x;
            cin >> x;
            v[t].push(x);
        } else if (query == 1) {
            if (!v[t].empty()) cout << v[t].top() << endl;
        } else if (query == 2) {
            if (!v[t].empty()) v[t].pop();
        } else cout << "Error: query is not correct\n";
    }

    return 0;
}



Measured memory_bytes: 4448
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 100004

for x in a:
   cnt[x-1]+=1
   cnt[x]+=1
   cnt[x+1]+=1
ans = -1
for i in range(len(cnt)):
   if cnt[i] > ans:
      ans = cnt[i]
print(ans)

Measured memory_bytes: 13964
import heapq
from collections import deque

class job:
    def __init__(self,date,award):
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
#         elif self.award==other.award and self.date>other.date:
#             return True
#         elif self.award==other.award and self.date==other.date and self.name>other.name:
#             return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
#         elif self.date==other.date and self.award>other.award:
#             return True
#         elif self.award==other.award and self.date==other.date and self.name<other.name:
#             return False
        else:
            return False
    def __eq__(self,other):
        if self.award==other.award:
            return True
        else:
            return False

jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(info)
jobs.sort()

jobdeque=deque()
for i in jobs:
    jobdeque.append(i)
    
ans=0
heap=[]
heapq.heapify(heap)
for i in range(m):
    while jobdeque:
        a=jobdeque.popleft()
        if a[0]==i+1:
            heapq.heappush(heap,job(a[0],a[1]))
        else:
            jobdeque.appendleft(a)
            break
    if heap:
        b=heapq.heappop(heap)
        ans+=b.award
                          
print(ans)


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

using namespace std;

void dfs(int node, vector<int> &hnst, vector<vector<pair<int, int>>> &v) {
	hnst[node] = 1;
	for (auto it : v[node]) {
		if (hnst[it.first] == 0 && it.second == 1) {
			dfs(it.first, hnst, v);
		}
	}
}

bool check(vector<vector<pair<int, int>>> &v, vector<int> &s, int n, int nr) {	

	vector<int> hnst(n + 1, 0);

	for (auto it : s) {
		if (hnst[it] == 0) {
			dfs(it, hnst, v);
		}
	}

	for (int i = 1; i <= n; i++) {
		if (hnst[i] == 1) {
			for (auto it: v[i]) {
				if (hnst[it.first] != it.second) {
					return false;
				}
			}
		}
	}
	return true;
}

int main()
{
	int n;
	cin >> n;
	int ns = pow(2, n);
	vector<vector<pair<int, int>>> v(n + 1);
	for (int i = 1; i <= n; i++) {
		int nr;
		cin >> nr;
		for (int j = 0; j < nr; j++) {
			pair<int, int> x;
			cin >> x.first >> x.second;
			v[i].push_back(x);
		}
	}
	
	int res = 0;
	for (int i = 1; i <= ns; i++) {
		vector<int> s; 
		int nr = 0;
		for (int j = 1; j <= n; j++) {
			if (i & (1 << (j - 1))) {
				s.push_back(j);
				nr++;
			}
		}
		if (check(v, s, n, nr)) {
			res = max(res, nr);
		}
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
 
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
 
int N;
int D[201][201];
vector<vector<int>> edges;
 
bool is_bipartite(int now, int from, vector<int> &color) {
  for (auto e : edges[now]) {
    if (e == from) {
      continue;
    }
    if (color[e] == -1) {
      color[e] = (color[now] + 1) % 2;
    } else if (color[e] == color[now]) {
      return false;
    } else {
      continue;
    }
    if (!is_bipartite(e, now, color)) {
      return false;
    }
  }
  return true;
}
 
int main() {
  cin >> N;
  edges.assign(N, vector<int>());
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < N; j++) {
      D[i][j] = s[j] - '0';
      if (D[i][j]) {
        edges[i].push_back(j);
        edges[j].push_back(i);
      }
    }
  }
  vector<int> v(N, -1);
  v[0] = 0;
  if (!is_bipartite(0, -1, v)) {
    cout << -1 << endl;
    return 0;
  }
  const int INF = 1e9;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (!D[i][j] and i != j) {
        D[i][j] = INF;
      }
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        chmin(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (D[i][j] != INF) {
        chmax(ans, D[i][j]);
      }
    }
  }
  cout << ans + 1 << endl;
 
  return 0;
}

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


int main(){


    long long n, i, t;

    long long k1 = 0;

    long long k2 = 0;

    vector<long long> a;

    vector<long long> b;

 
    cin >> n;


    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> t;

         a.push_back(t);

         b.push_back(t);

         }


    sort( a.rbegin(), a.rend() );

    sort( b.begin(), b.end() );


    for( i = 0 ; 2 * i < n - 2 ; i = i + 1 ){

         k1 += 2 * a.at(i);

         k1 -= 2 * b.at(i);

         k2 += 2 * a.at(i);

         k2 -= 2 * b.at(i);

         }


    if( n % 2 == 0 ){

        k1 -= b.at(n / 2 - 1);

        k1 += a.at(n / 2 - 1);

        k2 -= b.at(n / 2 - 1);

        k2 += a.at(n / 2 - 1);

        }

    else{       

          k1 -= b.at(n / 2);

          k1 += b.at(n / 2 - 1);

          k2 += a.at(n / 2);

          k2 -= a.at(n / 2 - 1);

          }


    cout << max( k1, k2 ) << endl;


    return 0;


    }

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

int main(){
	int a,b;
	cin>>a>>b;
	string s[100];
	for(int i=0;i<a;++i)cin>>s[i];
	for(int i=0;i<a+2;++i){
		for(int j=0;j<b+2;++j){
			if(i==0||j==0||i==a+1||j==b+1)cout << "#";
			else cout << s[i-1][j-1];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define vi vector<int>
#define pb emplace_back
ll poww(ll n,ll x)
{
    ll res=1;
    
    while(x>0)
    {
        if(x&1)
          res*=n;
        
        x=x>>1;
        n*=n;
    }
    return res;
}





int main() 
{
	   ios::sync_with_stdio(0);
	   cin.tie(0);
	   cout.tie(0);
       
       string s,t;
       cin>>s>>t;
       
       int n1=t.length();
       int best=INT_MAX;
       for(int i=0;i<s.length()-n1+1;i++)
       {
       	   int cnt=0;
       	    string k= s.substr(i,n1);
       	    for(int i=0;i<k.length();i++)
       	    {
       	    	 if(k[i]!=t[i])
       	    	   cnt++;
       	    }
       	    best=min(best,cnt);
       }
       
       cout<<best;   
       
}

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

using namespace std;

int main() {
    int N, A[100000] = {0};
    int ptr = 0, ans = 0;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A, A + N);

    while ( ptr < N ) {
        int cc = A[ptr], t = 0;
        while (ptr < N && A[ptr] == cc) { t++, ptr++; }
        ans += t % 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
from heapq import heappush, heappop

N, M = map(int, input().split())

jobs = {i:[] for i in range(1, M+1)}


for _ in range(N):
  a, b = map(int, input().split())
  if a > M:
    continue
  else:
    jobs[a].append(b)
	

ans = 0
heap = []
for day in range(1,M+1):
  lis = jobs[day]
  for pay in lis:
    heappush(heap, -pay)
  if len(heap) != 0:
    ans += -heappop(heap)

print(ans)

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

int par[100010];
int find(int x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
}
void union_(int x, int y) {
    if ((x = find(x)) != (y = find(y))) par[y] = x;
}
void init() {
    memset(par, -1, sizeof par);
}

int main(void) {
    int n,q;
    scanf("%d%d",&n,&q);
    init();
    for(int i=0; i<q; i++) {
        int c,x,y;
        scanf("%d%d%d",&c,&x,&y);
        if(c)
            puts(find(x)==find(y) ? "1" : "0");
        else
            union_(x,y);
    }
    return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#include <cmath>
 
using namespace std;
int H,N;
int A;

int main()
{
  int i;
  int sum;

  cin >> H >> N;
  for (i=0, sum=0; i<N; i++) {
    cin >> A;
    sum += A;
    if (sum>=H) {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");
  return 0;
}


Measured memory_bytes: 256
import math
K = int(input())

def computeGCD(x, y):
    while (y):
        x, y = y, x % y

    return x

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        intermediate = computeGCD(a, b)
        for c in range(1, K+1):
            sum += computeGCD(c, intermediate)

print(sum)

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

using namespace std;

const int N = 610;
const int Mod = 1e9 + 7;

int add(int a, int b) {
  return (a += b) >= Mod ? a - Mod : a;
}

int sub(int a, int b) {
  return (a -= b) < 0 ? a + Mod : a;
}

int mul(int a, int b) {
  return 1ll * a * b % Mod;
}

void upd(int &a, int b) {
  a = add(a, b);
}

int n, m, a[N], vis[N], mark[N], num = 0;

int solve() {
  static int dp[N][N][N];
  dp[2 * n + 1][0][0] = 1;
  for (int i = 2 * n; i >= 1; i--) {
    if (mark[i]) {
      for (int j = 0; j <= n; j++) {
        for (int k = 0; k <= n; k++) {
          if (k) upd(dp[i][j][k - 1], dp[i + 1][j][k]);
          upd(dp[i][j + 1][k], dp[i + 1][j][k]);
        }
      }  
    } else {
      if (!vis[i]) {
        for (int j = 0; j <= n; j++) {
          for (int k = 0; k <= n; k++) {
            upd(dp[i][j][k + 1], dp[i + 1][j][k]);
            if (k) upd(dp[i][j][k - 1], dp[i + 1][j][k]);
            if (j) upd(dp[i][j - 1][k], mul(j, dp[i + 1][j][k]));  
          }
        }
      } else {
        for (int j = 0; j <= n; j++) {
          for (int k = 0; k <= n; k++) {
            dp[i][j][k] = dp[i + 1][j][k];
          }
        }
      }
    }
  }
  int res = dp[1][0][0];
  for (int i = 1; i <= num; i++) res = mul(res, i); 
  return res; 
}

int main() {
  cin >> n;
  for (int i = 1; i <= n * 2; i++) {
    cin >> a[i];
    if (a[i] != -1) vis[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    if (a[2 * i - 1] > 0) cnt++;
    if (a[2 * i] > 0) cnt++;
    if (cnt == 2) continue;
    if (cnt == 0) num++;
    else mark[max(a[2 * i], a[2 * i - 1])] = 1;
  }
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 873216
#include<bits/stdc++.h>
#define int  long long
#define N    105
#define K    100005
#define MOD  1000000007

using namespace std;
int n,k;
int arr[N],dp[N][K],pre[N][K];

int32_t main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	scanf("%lld %lld",&n,&k);
	// cin>>n>>k;

	for(int i=1;i<=n;i++){
		scanf("%lld",&arr[i]);
		// cin>>arr[i];
	}
	pre[1][0]=1,
	dp[1][0]=1;
	for(int i=1;i<=k;i++){
		if(i<=arr[1]){
			dp[1][i]=1;
		}
		pre[1][i]=(pre[1][i-1]+dp[1][i])%MOD;
	}
	for(int i=2;i<=n;i++){
		for(int j=0;j<=k;j++){
			dp[i][j]=(pre[i-1][j]);
			if((j-arr[i])>0){
				dp[i][j]-=pre[i-1][(j-arr[i])-1];
				dp[i][j]+=MOD;
				dp[i][j]%=MOD;
			}
			if(j==0){
				pre[i][j]=dp[i][j];
			}
			else{
				pre[i][j]=(dp[i][j]+pre[i][j-1])%MOD;
			}
		}
	}
	printf("%lld\n", ((dp[n][k]+MOD)%MOD));
}

Measured memory_bytes: 159232
#include<bits/stdc++.h>
using namespace std;
 
int N, Q, s[1000000];
vector< int > Student;
multiset< int > Leader;
 
char Query[10];
int a;
 
bool Check(int value, int x)
{
  vector< int >::iterator last = Student.begin();
  int Lost = 0;
  for(multiset< int >::iterator it = Leader.begin(); it != Leader.end() && last != Student.end(); ++it) {
    Lost += lower_bound(last, Student.end(), *it - value) - last;
    last = upper_bound(last, Student.end(), *it);
  }
  Lost += Student.end() - last;
  return(Lost <= x);
}
int BinarySearch(int Lower, int Upper, int x)
{
  int Mid = (Lower + Upper) >> 1;
  if(Lower >= Upper) return(Lower);
  if(Check(Mid, x)) return(BinarySearch(Lower, Mid, x));
  return(BinarySearch(Mid + 1, Upper, x));
}
main()
{
  scanf("%d %d", &N, &Q);
  Student.resize(N);
  for(int i = 0; i < N; ++i) {
    scanf("%d", &Student[i]);
    s[i] = Student[i];
  }
  sort(Student.begin(), Student.end());
  while(Q--) {
    scanf("%s %d", &Query, &a);
    if(Query[0] == 'A') { // "ADD"
      Leader.insert(s[--a]);
    } else if(Query[0] == 'R') { // "REMOVE"
      Leader.erase(Leader.find(s[--a]));
    } else { // "CHECK"
      int ret = BinarySearch(0, 1 << 30, a);
      if(ret == 1 << 30) puts("NA");
      else printf("%d\n", ret);
    }
  }
}

Measured memory_bytes: 8856
import sys

def check(a,b,C):
    for i in range(3):
        for j in range(3):
            if(C[i][j] != a[i] + b[j]):
                return False
    return True

C = []

for i in range(3):
    C.append(list(map(int, input().split())))

a = [0,0,0]
b = [0,0,0]
for b1 in range(101):
    b[0] = b1
    a[0] = C[0][0] - b1
    a[1] = C[1][0] - b1
    a[2] = C[2][0] - b1
    a_s = sum(a)

    b[1] = (C[0][1] + C[1][1] + C[2][1] - a_s) / 3
    b[2] = (C[0][2] + C[1][2] + C[2][2] - a_s) / 3

    if (check(a,b,C)):
        print('Yes')
        sys.exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>> ans(h, vector<int>(w));
    int index = 0;
    rep(i, h) rep(j, w) {
        if (a[index]==0) index++;
        ans[i][j] = index+1;
        a[index]--;
    }
    rep(i, h) {
        if (i%2==1) {
            reverse(whole(ans[i]));
        }
        rep(j, w) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3668
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] h = new int[n+1];
		int count = 0;
		int[] ma = new int[n+1];

		for(int i=1;i<=n;i++) {
			h[i] = scan.nextInt();
		}

		for(int j=0;j<m;j++) {

			int a = scan.nextInt();
			int b = scan.nextInt();
			ma[a] = Math.max(ma[a], h[b]);
			ma[b] = Math.max(ma[b], h[a]);

			}

		for(int i=1;i<ma.length;i++) {

			if(h[i] > ma[i]) {
				count++;
			}
		}
			System.out.println(count);


		scan.close();

	}

}


Measured memory_bytes: 50144
#include <iostream>
#include <algorithm>
#include <cmath>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)
#define X first
#define Y second

using namespace std;

typedef pair<double, double> pdd;

double distance_sq( pdd a, pdd b )
{
	double cx = a.X - b.X;
	double cy = a.Y - b.Y;
	return ((cx*cx) + (cy*cy));
}

double norm( pdd &v )
{
	double len = sqrt((v.X*v.X) + (v.Y*v.Y));
	v.X /= len;
	v.Y /= len;
	return len;
}

void rotate( pdd &p )
{
	swap(p.X, p.Y);
	p.Y = -p.Y;
}

int main( void )
{
	int n;
	pdd p[300];
	while(cin >> n, n)
	{
		rep(i, n) cin >> p[i].X >> p[i].Y;
		int Max = 1;
		rep(i, n) {
			rep2(j, i+1, n) {
				if(distance_sq(p[i], p[j]) <= 4.0) {
					pdd v = make_pair(p[i].X-p[j].X, p[i].Y-p[j].Y);
					pdd c = make_pair(v.X / 2.0000, v.Y / 2.0000);
					pdd m = c;
					double len_c = norm(c);
					double sin_x = sqrt(1.0000 - (len_c*len_c));
					rotate(c);
					c.X *= sin_x; c.Y *= sin_x;
					pdd p3 = make_pair(p[j].X+m.X+c.X, p[j].Y+m.Y+c.Y);
					pdd p4 = make_pair(p[j].X+m.X-c.X, p[j].Y+m.Y-c.Y);
					int count_p3, count_p4;
					count_p3 = count_p4 = 2;
					rep(k, n) {
						if(i==k || j==k) continue;
						if(distance_sq(p3, p[k]) < 1.000001) ++count_p3;
						if(distance_sq(p4, p[k]) < 1.000001) ++count_p4;
					}
					Max = max(Max, max(count_p3, count_p4));
				}
			}
		}
		cout << Max << endl;
	}
	return 0;
}

Measured memory_bytes: 964
import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    X = list(map(int, readline().rstrip().split()))

    if N >= M:
        print(0)
        return

    X.sort()
    X = [abs(X[i+1]-X[i]) for i in range(M-1)]
    X.sort(reverse=True)
    print(sum(X[N-1:]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 13964
import sys
from copy import copy
  
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors  
  
N, M = map(int, input().split())

factor = make_divisors(M)

for f in factor:
  if f >= N:
    print(M // f)
    sys.exit()

Measured memory_bytes: 3444
#include <stdio.h>

#define NUM 9

int main(void)
{
  int i, j;

  for (i = 1; i < NUM + 1; i++){
    for (j = 1; j < NUM + 1; j++){
      printf("%dx%d=%d\n", i, j, (i * j));
    }
  }

  return 0;
}

Measured memory_bytes: 0
K,N=(int(x) for x in input().split())
A = list(map(int,input().split()))
check = K- A[N-1] + A[0]

for i in range(N-1):
    if(A[i+1]-A[i]>check):
        check=A[i+1]-A[i]
        

num = K - check
print(num)

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n , l;
  cin >> n >> l;
  string s[n];
  for(int i = 0 ; i  < n ; i++) cin >> s[i];
  sort(s,s+n);  
  for(int i = 0 ; i  < n ; i++) cout << s[i];
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a,b;cin>>a>>b;
if(a==1 || b==1){
if(a==1&&b!=1){
cout<<"Alice";
}
if(b==1&&a!=1){
cout<<"Bob";
}
if(a==b){
cout<<"Draw";
}
}
else{
if(a>b){
cout<<"Alice";
}
if(a<b){
cout<<"Bob";
}
if(a==b){
cout<<"Draw";
}
}
 return 0;
}

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

int main() {
    string a,b,c;
    char next;
    cin >> a >> b >> c;

    next = a[0];
    a.replace(0,1,"");

    while(1){
        if(next == 'a'){
            if(a[0]=='\0'){
                cout << 'A' << endl;
                break;
            }
            next = a[0];
            a.replace(0,1,"");
        }else if(next == 'b'){
            if(b[0]=='\0'){
                cout << 'B' << endl;
                break;
            }
            next = b[0];
            b.replace(0,1,"");
        }else{
            if(c[0]=='\0'){
                cout << 'C' << endl;
                break;
            }
            next = c[0];
            c.replace(0,1,"");            
        }
    }
    return 0;
}

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

int main()
{
    long long A,B ;
    cin >> A >> B;

    if ( A % 2 != B % 2){
        cout << "IMPOSSIBLE" << endl;
    }else {
        cout << ( A + B ) / 2  << endl;
    }
    return 0;
}

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

int main() {
  int a,d,n;  
  while(cin >> a >> d >> n, a|d|n)
  {
    int max_size = 1e6+5;
    bool prime[max_size];
    for(int i = 2; i <= max_size; i++){
      prime[i] = true;
    }

    for(int i = 2; i <= sqrt(max_size)+2; i++){
      if(prime[i]){
        for(int j = 2*i; j <= max_size; j+=i){
          prime[j] = false;
        }
      }
    }

    int ni = 0;
    for(int i = 0; a + d*i <= max_size; i++){
      if(prime[a+d*i]){
        ni++;
      }
      if(ni == n){
        cout << a+d*i << "\n";
        break;
      }
    }
  }
}


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

int main(){
 int a, b, coins;
 cin >> a >> b;
  coins = 0;
  for (int i=0; i<2;i++){
    if (a>b){
      coins += a;
      a--;
    }else{
      coins += b;
      b--;
    }
  }
  cout << coins << endl;
  
  return 0;
}

Measured memory_bytes: 256
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <climits>
#include <deque>
#include <map>
#include <deque>
#include <iomanip>
#include <cmath>
#include <functional>
#include <set>
#include <list>
#include <bitset>
#include <stack>
#include <stdio.h>
#define endl '\n'
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
typedef pair<ll,ll> pll;
int main()
{
    /*
for reading from input.txt and writing on output.txt
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
*/
    cin.sync_with_stdio(false);
    ll n;cin>>n;
    ll arr[n+1];
    for(ll i=1;i<=n;i++)cin>>arr[i];
    ll ans=0;
    ll cnt=1;
    for(ll i=1;i<=n;i++)
    {
        if(arr[i]==cnt)
        {
            cnt++;
        }
        else
            ans++;
    }
    if(ans==n)cout<<-1;
    else cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
    string s, t;
    cin >> s >> t;
    int dp[3010][3010];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    //復元
    string res = "";
    int i = s.size(), j = t.size();
    while (i > 0 && j > 0) {
        //(i-1,j)->(i,j)と更新されていた場合
        if (dp[i][j] == dp[i - 1][j]) {
            --i;//DPの遷移を遡る
        }
        else if (dp[i][j] == dp[i][j - 1]) {
            --j;
        }
        //(i-1,j-1)->(i,j)と更新されていた場合
        else {
            res = s[i - 1] + res;//このときs[i-1]==t[j-1]なので、res+t[j-1]でもok
            --i, --j;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<=8&&b<=8) cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7; // 998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

mint multichoose(int n,int k,int type=0){
	return choose(n+k-1,k,type);
}

int main(){
	int n; scanf("%d",&n);
	vector<int> x(n);
	rep(i,n) scanf("%d",&x[i]);

	mint ans=0,sum=0;
	rep(i,n-1){
		sum+=fact(n-1)/(i+1);
		ans+=sum*(x[i+1]-x[i]);
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 1024
from itertools import combinations_with_replacement

N,M,Q = map(int,input().split())

comb = list(combinations_with_replacement(range(1,M+1),N))

abcd = []
for i in range(Q):
    a,b,c,d = map(int,input().split())
    abcd.append([a-1,b-1,c,d])

ans = 0
for i in comb:
    tmp = 0
    for a,b,c,d in abcd:
        if i[b] - i[a] == c:
            tmp += d
    ans = max(ans,tmp)

print(ans)

Measured memory_bytes: 21612
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
  int N = inputValue();
  int H[100000];
  REP(i, N){
    H[i] = inputValue();
  }
  int maxStep = 0;
  int curStep = 0;
  int curHigh = H[0];
  FOR(i, 1, N){
    if(curHigh>=H[i])
    {
      curStep++;
    }
    else
    {
      maxStep = max(maxStep, curStep);
      curStep = 0;
    }
    curHigh = H[i];
  }
  maxStep = max(maxStep, curStep);

  cout << maxStep << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
long long H;
long long W;
int main(){
  int KL2GvlyY, i, j, res;
  long long a, b, c;
  rd(H);
  rd(W);
  if(H%3==0 || W%3==0){
    wt_L(0);
    wt_L('\n');
    return 0;
  }
  res =min_L(H, W);
  for(KL2GvlyY=0;KL2GvlyY<(2);KL2GvlyY++){
    for(i=(1);i<(H);i++){
      a = i * W;
      b = (H-i) * (W / 2);
      c = (H-i) * (divup_L(W,2));
      chmin(res, max_L(max_L(a, b), c)-min_L(min_L(a, b), c));
    }
    swap(H, W);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190829-1

// --- original code ---
// ll H, W;
// {
//   int i, j, res;
//   ll a, b, c;
// 
//   rd(H,W);
// 
//   if(H%3==0 || W%3==0) wt(0), return 0;
//   res = min(H, W);
// 
//   rep(2){
//     rep(i,1,H){
//       a = i * W;
//       b = (H-i) * (W / 2);
//       c = (H-i) * (W /+ 2);
//       res <?= max(a,b,c) - min(a,b,c);
//     }
//     swap(H, W);
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	string w;
	cin >> w;
	map<char, int>m;
	for (auto i : w)m[i]++;
	for (auto i : m) {
		if (i.second & 1) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

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

int main(void){

  int height[10];
  int i;

  for(i=0;i<10;i++) cin >> height[i];

  sort(height, height+10);

  cout << height[9] << endl;
  cout << height[8] << endl;
  cout << height[7] << endl;

  return 0;

}

Measured memory_bytes: 1176
//tree DP
//ABC036-D
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val > ((sd*)b)->val){return -1;}
if(((sd*)a)->val < ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long dist[524288],par[524288];
void dfs(long long t,long long l,long long bp,rs g[],mkj x[]){
  long long i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  par[t]=bp;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,t,g,x);
  }
}

int main(void){
    long long i,j,n,m,k,a,b,c,h,w,r=0,l,t;
    long long bk,wk;
    long long res=0;
    long long dp[524288][2]={0};
    rs g[524288];
    mkj x[524288];
    sd dat[524288];
    scanf("%lld",&n);
    for(i=0;i<(n-1);i++){
      scanf("%lld%lld",&a,&b);
      g[2*i].st=a;
      g[2*i].fi=b;
      g[2*i].kr=1;
      g[2*i+1].st=b;
      g[2*i+1].fi=a;
      g[2*i+1].kr=1;
    }
    qsort(g,2*(n-1),sizeof(g[0]),sortfnc);
    makemkj(g,x,2*(n-1));
    for(i=0;i<=n;i++){
      dist[i]=inf;
    }
    dfs(1,0,-1,g,x);
    for(i=0;i<n;i++){
      dat[i].node=i+1;
      dat[i].val=dist[i+1];
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    for(i=0;i<n;i++){
      bk=1;wk=1;
      w=dat[i].node;
      for(j=x[w].st;j<x[w].st+x[w].kz;j++){
        if(par[w]==g[j].fi){continue;}
        bk*=dp[g[j].fi][0];
        bk%=mod;
        wk*=(dp[g[j].fi][0]+dp[g[j].fi][1]);
        wk%=mod;
      }
      dp[w][1]=bk;
      dp[w][0]=wk;
    }
    printf("%lld\n",(dp[1][0]+dp[1][1])%mod);
    return 0;
}


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

N,Q = map(int, input().split())

edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

P = []
for i in range(Q):
    x,y = map(int, input().split())
    P.append((x,y))

V = [0]*N
for p in P:
    V[p[0]-1] += p[1]

parent = {1}
done = {1}
while parent:
    children = set()
    for p in parent:
        for i in edge[p]:
            if i not in done:
                V[i-1] += V[p-1]
                children.add(i)
                done.add(i)
    parent = children

print(' '.join(map(str, V)))


Measured memory_bytes: 102472
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  rep(i, N)
  {
    cin >> A[i] >> B[i];
  }
  //mapを使う方法
  //TreeMap -> 順番がソートされる
  //HashMap -> 順番がソートされない
  map<int, long long> m;

  for (int i = 0; i < N; i++)
  {
    //A円のお店にはB個追加されたよ
    if (m.count(A[i]))
      m[A[i]] += B[i];
    else
      m[A[i]] = B[i];
  }

  long long ans = 0;
  for (auto shop : m)
  {
    long long buy = min((long long)M, shop.second);
    ans += buy * shop.first;
    M -= (int)buy;
  }

  cout << ans << endl;
}

Measured memory_bytes: 7424
X, Y, Z, K =map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = []
for i in range(X):
  for j in range(Y):
    AB.append(A[i] + B[j])
AB.sort(reverse=True)

ans = []
for i in range(min(K, len(AB))):
  for j in range(Z):
    ans.append(AB[i] + C[j])
ans.sort(reverse=True)

for i in range(K):
  print(ans[i])

Measured memory_bytes: 147776
def INT():
    return int(input())

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

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

from itertools import combinations
N = INT()
L = LI()
ans = 0

for c in combinations(L, 3):
    Li, Lj, Lk = c
    if len(set(c)) != 3:
        continue
    if Li + Lj > Lk and Lj + Lk > Li and Li + Lk > Lj:
        ans += 1
        
print(ans)

Measured memory_bytes: 74080
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b[ohara], c[ohara], d, tmp, m, h, w, x, y, sum, k, q;
pq que;
P p[ohara];
ll now;

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

  cin >> n >> m;
  rep(i, n) {
    cin >> a;
    que.push(a);
  }
  rep(i, m) {
    cin >> b[i] >> c[i];
    p[i] = m_p(c[i], b[i]);
  }
  sort(p, p + m);
  reverse(p, p + m);
  rep(i, m) {
    b[i] = p[i].se;
    c[i] = p[i].fi;
  }

  rep(i, n) {
    if (que.top() >= c[now]) {
      ans += que.top();
      que.pop();
    } else {
      ans += c[now];
      b[now]--;
      if (b[now] == 0) now++;
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 8948
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = scan.nextLong();
        }
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < n - 1; i++) {
            ans = Math.min(ans, gcd(a[i], a[i+1]));
        }
        System.out.println(ans);
    }

    public static long gcd(final long x, final long y) {
        if(x < y) {
            return gcd(y, x);
        }
        if(y == 0) {
            return x;
        }
        return gcd(y, x % y);
    }
}

Measured memory_bytes: 50920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[100000];
ll dp[100001];

int main()
{
	int N, M, index = 0;

	cin >> N >> M;
	rep(i, M) cin >> a[i];

	dp[0] = 1;
	if (a[index] == 1) {
		dp[1] = 0;
		index++;
	}
	else dp[1] = 1;

	repc(i, 2, N) {
		if (index < M && i == a[index]) {
			dp[i] = 0;
			index++;
		}
		else {
			dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
		}
	}

	cout << dp[N] << endl;

	return 0;
}


Measured memory_bytes: 1408
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)

max1_a = sorted_A[-1]
max2_a = sorted_A[-2]
if A.count(max1_a) > 1:
    for i in range(N):
        print(max1_a)
else:
    for i in range(N):
        if A[i] == max1_a:
            print(max2_a)
        else:
            print(max1_a)

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

using namespace std;

#define fileInput(problemName) freopen ((string(problemName) + ".inp").c_str(), "r", stdin);freopen ((string(problemName) + ".out").c_str(), "w", stdout);
#define ll long long
#define ii pair < int, int >
#define weight first
#define val second

const ll inf = 1e9 + 7;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 7;

int n, w, sumVal = 0;
int f[107][N];
ii a[N];

bool cmp(ii a, ii b) {
    return (a.val < b.val);
}

main() {
    //fileInput("knapsack-2");
    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].weight >> a[i].val;
        sumVal += a[i].val;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= sumVal; j++) {
            f[i][j] = inf;
        }
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 0; i <= n; i++) f[i][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sumVal; j++) {
            if (a[i].val <= j) {
                f[i][j] = min(f[i - 1][j], f[i - 1][j - a[i].val] + a[i].weight);
            } else f[i][j] = f[i - 1][j];
        }
    }
    // for (int i = 0; i <= n; i++) {
    //     for (int j = 0; j <= sumVal; j++) {
    //         cout << f[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    for (int i = sumVal; i >= 1; i--) {
        if (f[n][i] <= w) {
            cout << i << endl;
            return (0);
        }
    }
    cout << "nothing\n";
}

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

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

    long long ans = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0 or i % 5 == 0){
            continue;
        }
        ans += i;
    }

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

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int n,q,i,j,s[10000],t,c;
main(){  
  for(cin>>n;i<n;cin>>s[i++]);
  for(cin>>q;j<q;++j)
    for(cin>>t,i=0;i<n;++i)
      if(t==s[i])c++,i=n;
  cout<<c<<endl;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <cmath>
using namespace std;

int n, d;
int x[10][10];

int sq_sum(int a, int b){
    int sum = 0;
    for (int j=0;j<d;j++){
        sum += (x[a][j] - x[b][j])*(x[a][j] - x[b][j]);
    }
    return sum;
}

int main(){
    cin >> n >> d;
    for (int i=0;i<n;i++){
        for (int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i=0;i<n;i++){
        for (int j=i+1;j<n;j++){
            float sum = sqrt(sq_sum(i, j));
            if (sum == (int)sum) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    n=int(input())
    lst=list(map(int,input().split()))
    mod=10**9+7
    sm=1
    color=[0,0,0]
    for x in lst:
        if x not in color : sm=0;break
        sm*=color.count(x)
        sm%=mod
        color[color.index(x)]+=1
    print(sm)

main()

Measured memory_bytes: 20668
#n=int(input())  #数値入力 「N」だけの入力のとき
th, ta, ah, aa = map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

t_win = 'No'
while 1:
    ah -= ta
    if ah <= 0:
        t_win = 'Yes'
        break
    th -= aa
    if th <= 0:
        break
print(t_win)


Measured memory_bytes: 9100
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <map>
#include <assert.h>

using namespace std;

int n, m;
char object[200][20];

struct Set {
  unsigned long long bit[2];
  int count_bit() {
    int sum = 0;
    for (unsigned long long i = 0; i < 2; i++) {
      for (unsigned long long j = 0; j < 64; j++) {
        sum += (bit[i] >> (unsigned long long)j) & 1;
      }
    }
    return sum;
  }
  void set(int x) {
    if (x < 64) {
      bit[0] |= 1ULL << x;
    } else {
      bit[1] |= 1ULL << (x - 64);
    }
  }
  int get(int x) {
    if (x < 64) {
      return (bit[0] >> x) & 1;
    }
    return (bit[1] >> (x - 64)) & 1;
  }
  Set() {
    bit[0] = bit[1] = 0ULL;
  }
  bool operator==(const Set &rhs) const { return bit[0] == rhs.bit[0] && bit[1] == rhs.bit[1]; }
  bool operator<(const Set &rhs) const {
    if (bit[0] != rhs.bit[0]) { return bit[0] < rhs.bit[0]; }
    return bit[1] < rhs.bit[1];
  }
};

void printSet(Set s) {
  for (int i = 0; i < n; i++) {
    if (s.get(i)) {
      putchar('1');
    } else {
      putchar('0');
    }
  }
  puts("");
}


map<Set, int> memo;

int calc(Set s) {
  if (memo.find(s) != memo.end()) { return memo.find(s)->second; }
  //cout << s.count_bit() << endl;
  if (s.count_bit() == 1) {
    memo.insert(make_pair(s, 0));
    return 0;
  }
  int ret = 100;
  for (int i = 0; i < m; i++) {
    Set div1;
    Set div2;
    for (int j = 0; j < n; j++) {
      int a = s.get(j);
      if (a == 0) { continue; }
      if (object[j][i] == '1') {
        div1.set(j);
      } else {
        div2.set(j);
      }
    }
  //printSet(div1);
  //printSet(div2);
    if (s == div1 || s == div2) { continue; }
    ret = min(ret, 1 + max(calc(div1), calc(div2)));
  }
  memo.insert(make_pair(s, ret));
  //printSet(s);
  //cout << ret << endl << endl;
  //cout << s.bit[0] << " " << s.bit[1] << " " << s.count_bit() << endl;
  //assert(ret < 100);

  return ret;
}

int main() {
  while (scanf("%d %d", &m, &n), n|m) {
    Set first;
    for (int i = 0; i < n; i++) {
      scanf("%s", object[i]);
      first.set(i);
    }
    memo.clear();
    printf("%d\n", calc(first));
  }
}

Measured memory_bytes: 1688