akhauriyash/Code-Regression huggingface dataset:
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<int> d;
  rep(i, n){
    int x;
    cin >> x;
    d.pb(12 - x);
  }
  d.pb(12);
  sort(d.begin(), d.end());
  vector<int> l, r;
  for(int s = 12; s >= 0; s--){
    l.clear();
    r.clear();
    l.pb(d[0]);
    bool flag = true;
    FOR(j, 1, d.size()){
      int ltmp = d[j] - l[l.size() - 1];
      int rtmp = inf;
      if(r.size() > 0){
        rtmp = d[j] - r[r.size() - 1];
      }
      if(ltmp < rtmp){
        if(ltmp < s){
          if(rtmp < s){
            flag = false;
            break;
          }else{
            r.pb(d[j]);
          }
        }else{
          l.pb(d[j]);
        }
      }else{
        if(rtmp < s){
          if(ltmp < s){
            flag = false;
            break;
          }else{
            l.pb(d[j]);
          }
        }else{
          r.pb(d[j]);
        }
      }
    }
    if(!flag)continue;
    FOR(j, 1, l.size()){
      if(l[j] - l[j-1] < s){
        flag = false;
        break;
      }
    }
    FOR(j, 1, r.size()){
      if(r[j] - r[j-1] < s){
        flag = false;
        break;
      }
    }
    if(!flag)continue;
    if(r.size() > 0){
      if(24 - r[r.size() - 1] - l[l.size() - 1] < s){
        continue;
      }
      if(l[0] + r[0] < s)continue;
    }
    cout << s << endl;
    return 0;
  }
	return 0;
}


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;
const ll mod = 1e9 + 7;

int n;
vi adj[maxN];

ll dp[maxN][2];

void DFS(int u, int p)
{
    dp[u][0] = dp[u][1] = 1;
    for (auto &v: adj[u])
    {
        if (v != p)
        {
            DFS(v, u);
            dp[u][0] *= (dp[v][0] + dp[v][1]) % mod;
            dp[u][1] *= dp[v][0];
            dp[u][0] %= mod;
            dp[u][1] %= mod;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for1(i, n - 1)
    {
        int u, v;
        cin >> u >> v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    DFS(1, 0);
    cout << (dp[1][0] + dp[1][1]) % mod;
    return 0;
}


Measured memory_bytes: 12928
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll dp[301][301][301];
int N, M;
struct constraint{
    int l, x;
};

vector<constraint> v[301];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int l, r, x;
        cin >> l >> r >> x;
        v[r].push_back((constraint){l, x});
    }
    dp[0][0][0] = 1;
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < i; k++){
                dp[i][j][k]     =   (dp[i][j][k]        +   dp[i-1][j][k])%MOD;
                dp[k][i][j]     =   (dp[k][i][j]        +   dp[k][i-1][j])%MOD;
                dp[j][k][i]     =   (dp[j][k][i]        +   dp[j][k][i-1])%MOD;
                dp[i-1][i][k]   =   (dp[i-1][i][k]      +   dp[i-1][j][k])%MOD;
                dp[k][i-1][i]   =   (dp[k][i-1][i]      +   dp[k][i-1][j])%MOD;
                dp[i][k][i-1]   =   (dp[i][k][i-1]      +   dp[j][k][i-1])%MOD;
                dp[i-1][j][i]   =   (dp[i-1][j][i]      +   dp[i-1][j][k])%MOD;
                dp[i][i-1][j]   =   (dp[i][i-1][j]      +   dp[k][i-1][j])%MOD;
                dp[j][i][i-1]   =   (dp[j][i][i-1]      +   dp[j][k][i-1])%MOD;
            }
        }
        for(int j = 0; j < i; j++){
            for(int k = 0; k < i; k++){
                for(auto iter = v[i].begin(); iter != v[i].end(); iter++){
                    int l = iter->l;
                    int x = iter->x;
                    int cnt = 1;
                    if(j >= l) cnt++;
                    if(k >= l) cnt++;
                    if(cnt != x) {
                        dp[i][j][k] = 0;
                        dp[k][i][j] = 0;
                        dp[j][k][i] = 0;
                    } 
                }
                if(i == N){
                    ans += dp[i][j][k];
                    ans %= MOD;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
  bool flag=true;
  int n,k;
  cin>>n>>k;
  while(flag){
    vector<long long> a(n+1);
    a[0]=0;
    for(int i=0;i<n;i++){
      long long x;
      cin>>x;
      a[i+1]=a[i]+x;
    }
    long long ans=0;
    for(int i=0;i<=n-k;i++){
      ans=max(ans,a[k+i]-a[i]);
    }
    cout<<ans<<endl;
    cin>>n>>k;
    if(n==0&&k==0) flag=false;
  }
}
    


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;cin>>n;
  map<string,int>cnt;
  rep(i,n){
    string s;cin>>s;
    cnt[s]++;
  }
  for(string s:{"AC","WA","TLE","RE"}){
    cout<<s<<" x "<<cnt[s]<<endl;
  }
}

Measured memory_bytes: 3596
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        // write your code here
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) break;
            int temp;
            int sum = 0;
            temp = sc.nextInt();
            int min = temp,max = temp;
            sum += temp;
            for (int i = 0; i < n-1; i++){
                temp = sc.nextInt();
                if(temp<min) min = temp;
                if(temp>max) max = temp;
                sum += temp;
            }
            System.out.println((sum-(min+max))/(n-2));
        }
    }
}

Measured memory_bytes: 20936
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

const double EPS = 1e-11;

int ctimes(int j, int k) {
  int count = 0;
  while(j < k) {
    j = j * 2;
    count++;
  }
  return count;
}

int main () {
  int in, ik;
  cin >> in >> ik;
  long double n, k;
  n = in;
  k = ik;

  long double prob = 0.000000000000;
  for (int j = 1; j <= n; j++) {
    int times = ctimes(j, k);
    long double p = pow(0.5, times) / n;
    prob += p;
  }

  cout << setprecision(18) << prob << endl;

}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val in = new java.util.Scanner(System.in)
    print(getResult(in))
  }
  def getResult(in:java.util.Scanner):String = {
    if(!in.hasNext()){return ""}
    val a = in.nextInt()
    val b = in.nextInt()
    val v = a+b
    println(getDigit(v))
    return getResult(in)
    //    return getDigit(v) + "\n" + getResult(in)
    
  }
  def getDigit(v:Int):Int = {
    if(v/10== 0){
      return 1
    }
    return getDigit(v/10)+1
    
  }
}

Measured memory_bytes: 44872
#include <stdio.h>

int main(){
    int n;
    int m;
    int a;
    int x[31][31];
    int i,j;
    int o;
    int h[31]={0};
    int count=0;

    scanf("%d%d",&n,&m);

    for(i=0;i<n;i++){
        scanf("%d",&a);
        for(j=0;j<a;j++){
            scanf("%d",&x[i][j]);
            h[x[i][j]]++;
        }
    }
    
    for(i=0;i<31;i++){
        if(h[i]==n)
        count++;
    }

    printf("%d",count);
        


}

Measured memory_bytes: 128
n, m = map(int, input().split())
ac = [0] * n
wa = [0] * n
for i in range(m):
    p, s = input().split()
    p = int(p)-1
    if not ac[p]:
        if s=="AC": ac[p] = 1
        else: wa[p] += 1
was = 0
for i in range(n):
    if ac[i]: was += wa[i]
print(sum(ac), was)

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

#define int long long
 
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};
  
signed main(){
  int n, q, a, b;
  cin >> n >> q >> a >> b;
  a--; b--;
  
  SegmentTree<int, int>::F f=[](int a,int b){return min(a,b);};
  SegmentTree<int, int>::G g=[](int a,int b){return a+b;};
  const int INF = 1e15;
  SegmentTree<int, int> sl(n,f,g,g,INF,0);
  SegmentTree<int, int> sr(n,f,g,g,INF,0);

  sl.update(a, -a);
  sr.update(a, +a);

  for ( int i = 0; i < q; i++ ) {
    int x;
    cin >> x;
    x--;
    int mi = min(sl.query(0, x+1)+x, sr.query(x, n)-x);
    sl.update(0, n, abs(b-x));
    sr.update(0, n, abs(b-x));
    if ( mi-b < sl.query(b, b+1) ) sl.update(b, mi-b);      
    if ( mi+b < sr.query(b, b+1) ) sr.update(b, mi+b);      
    b = x;
  }

  int ans = sl.query(0, 1);
  for ( int i = 1; i < n; i++ ) {
    ans = min(ans, sl.query(i, i+1)+i);  
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 18688
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){
  int n;
  while(cin >> n , n){
    string in;
    cin >> in;
    while(n--){
      stringstream ss;
      int pos = 0;
      while(1){
	char num = in[pos];
	int len;
	for(len = 0; len + pos < in.size() && in[len + pos] == in[pos]; len++);
	ss << len << num;
	pos += len;
	if(pos >= in.size()) break;
      }
      in = ss.str();
    }
    cout << in << endl;
  }
  return 0;
}

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

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

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        String t = "abcdefghijklmnopqrstuvwxyz";
        for(int i=0;i<n;i++){
        	s[i] = sc.next();
        }
        int[][] num = new int[n][26];

        for(int i=0;i<n;i++){
        	for(int j=0;j<s[i].length();j++){
        		num[i][(int)s[i].charAt(j)-(int)'a']++;
        	}
        }

        int[] ans = new int[26];
        for(int i=0;i<26;i++){
        	ans[i] = num[0][i];
        	for(int j=1;j<n;j++){
        		ans[i] = Math.min(ans[i], num[j][i]); 
        	}
        }

        for(int i=0;i<26;i++){
        	for(int j=0;j<ans[i];j++){
        		System.out.print(t.charAt(i));
        	}
        }

        System.out.println();
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define PI 3.14159265358979323846



int main(void) {
	int N;
	scanf("%d", &N);
	printf("%d", N / 3);


	return 0;
}


Measured memory_bytes: 128
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	int x, y;
	cin >> x >> y;
	if (y % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	if (x * 4 < y||y/2<x) {
		cout << "No" << endl;
		return 0;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
T1,T2 = map(int, input().split())
A1,A2 = map(int, input().split())
B1,B2 = map(int, input().split())
d1 = (A1-B1)*T1
d2 = (A2-B2)*T2
if d1<0: d1,d2 = -d1,-d2
if d1+d2==0: print("infinity")
elif d1+d2>0: print(0)
elif d1%(-d1-d2) == 0: print(2*(d1//(-d1-d2)))
else: print(2*(d1//(-d1-d2))+1)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
    int so[500];
    int n, i = 0, t, nn, sum, ans = 1;

    scanf("%d", &n);

    for(int j = 2; j <= n; j++){
        if(j == 2){
            so[i] = j;
        }else{
            for(int k = 0; k <= i; k++){
                if(j % so[k] == 0) break;
                if(k == i) so[++i] = j;
            }
        }
    }
    
    for(int j = 0; j <= i; j++){
        nn = n;
        sum = 0;
        while(nn > 1){
            nn /= so[j];
            sum += nn;
        }
        if(ans >= (1000000000 + 7) / (sum + 1)){
            t = ans;
            for(int k = 0; k < sum; k++){
                ans += t;
                if(ans >= 1000000000 + 7) ans -= 1000000000 + 7;
            }
        }else{
            ans *= sum + 1;
        }
    }

    printf("%d", ans);

    return 0;
}

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

typedef long long LL;
const int MAXN = 1e5;
int a, b, c, ans,k;
int MAX;
int main(){
	cin >> a >> b >> c;
	cin >> k;
	MAX = max(a,b);
	MAX = max(c,MAX);
	if(MAX == a){
		ans = b + c + a*pow(2,k);
		cout << ans <<endl;
	}
	else if(MAX == b){
		ans = a + c + b*pow(2,k);
		cout << ans << endl;
	}
	else{
		ans = a + b + c*pow(2,k);
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
#掛け算表は対称行列
#対角成分に移動するときが最短移動
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(reverse=True)
    return divisors
div = make_divisors(N)
l = len(div) // 2
a = div[l]
b = N // a
ans = (a - 1) + (b - 1)
print(ans)

Measured memory_bytes: 3264
function Main(input) {
  const k = input;
  let sum = 0;

  const dv = n => {
    const divisors = [];
    const s = Math.sqrt(n);

    for (let i = 1; i <= s; i++) {
      if (n % i === 0) {
        if (i === n / i) {
          divisors.push(i);
        } else {
          divisors.push(i, n / i);
        }
      }
    }

    return divisors;
  }

  const gcd = (a, b, c) => {
    const min = Math.min(a, b, c);
    const dvmin = dv(min);
    const candidate = [];

    dvmin.forEach(i => {
      if (a % i === 0 && b % i === 0 && c % i === 0) {
        candidate.push(i);
      }
    })

    return Math.max(...candidate);
  }

  for (let a = 1; a <= k; a++) {
    for (let b = 1; b <= k; b++) {
      for (let c = 1; c <= k; c++) {
        sum += gcd(a, b, c);
      }
    }
  }

  console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37068
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String S = sc.next();
      	int i = 0;
        int count = 0; 
        int start = 0;
      	int end = 0;
      	String[] List = S.split("");

		for(i = 0;i < List.length; i++){
          if(List[i].equals("A")){
             start = 1;
          }
          if(start == 1){
            count += 1;
            if(List[i].equals("Z")){
              end = count;
            }
            
          }
          
        }
          System.out.println(end);   


    }
}

Measured memory_bytes: 54124
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	var ans int
	for i := 0; i <= len(s)-len(t); i++ {
		var cnt int
		for j := 0; j < len(t); j++ {
			if s[i:][j] == t[j] {
				cnt++
			}
		}
		ans = max(ans, cnt)
	}

	fmt.Println(len(t) - ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> d;

    rep(i,n){
        int tmp;
        cin >> tmp;
        d.pback(tmp);
    }

    int ans = 0;

    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;

}


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

#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "["<< *it << " = " << a << "]"<< endl;
    err(++it, args...);
}
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    string t,s;
    cin >> s;
    cin >> t;
    cout << t << s << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>
 
#define nl '\n'
 
using namespace std;
 
int n, m, c, a, t, x;

int main(){

    cin >> n >> m >> c;

    vector<int> b;

    for(int i = 0; i < m; i++){
        cin >> a;
        b.push_back(a);
    }

    for(int i = 0; i < n; i++){
        t = 0;
        for(int j = 0; j < m; j++){
            cin >> a;
            t += (b[j]*a);
        }
        t += c;
        if(t > 0){
            x++;
        }
    }

    cout << x;


}
 
//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out
 
//Surely this will AC

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int x = b-a;
    int y = c-b;
     if( x == y){
         cout << "YES" << endl;
     }else{
        cout << "NO" << endl;
     }
    return 0;
}

Measured memory_bytes: 256
/*||>>>> Praveen Ojha <<<<>>>> 26 May 2019 <<<<>>>> 17:33:48 <<<<||*/
// #pragma GCC optimize("Ofast") //(Very Fast but Inaccurate)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //(Small operations in many loops)
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf 1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
bool cmp(const pair<string,pii> &a,const pair<string,pii> &b){
  if(a.F!=b.F){
    return a.F < b.F;
  }
  else
    return a.S.F>b.S.F;
}
int32_t main(){__
  int n,x;
  cin>>n;
  vector <pair<string,pii> > vv;
  string s;
  for(int i=0;i<n;i++){
    cin>>s>>x;
    vv.push_back({s,{x,i+1}});
  }
  sort(all(vv),cmp);
  for(int i=0;i<n;i++){
    cout<<vv[i].S.S<<"\n";
  }
return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
max_val = max(A)
B = [0]*(max_val+3)
for i in range(N):
  B[A[i]]+=1
  B[A[i]+1]+=1
  B[A[i]+2]+=1
print(max(B))

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

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

    long long int count=0;
    for(int i=0;i<N;i++){
        if(B[i]==A[i]){
            count = count+A[i];
        }else if(B[i]>A[i]){
            count = count+A[i];

            int smp=A[i+1];
            A[i+1]=A[i+1]-(B[i]-A[i]);
            if(A[i+1]<=0){
                A[i+1]=0;
                count = count + smp;
            }else{
                count = count + (smp-A[i+1]);
            }
        }else{
            count =count+ B[i];
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 1024
// #include <iostream>
#include <bits/stdc++.h>
// https://beta.atcoder.jp/contests/arc098/submissions/2567080
// https://beta.atcoder.jp/contests/arc098/submissions/2563485

using namespace std;

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

    long n;
    cin >> n;
    // char s[n];
    string s;
    // scanf("%s", &s);
    cin >> s;
    long right_e = 0;
    // for (long i = 0; i < n; i++) if (s[i] == 'E') right_e++;
    for (long i = 1; i < n; i++) right_e += (s[i] == 'E');
    // for (long i = 1; i < n; i++) if (s[i] == 'E') right_e++;
    long min_count = right_e;
    long left_w = 0;
    for (long i = 1; i < n; i++) {
    // for (long i = 1; i < n; i++) {
        if (!min_count) break;
        right_e -= s[i] == 'E';
        left_w += s[i - 1] == 'W';
        min_count = min(min_count, right_e + left_w);
        //     if (s[i] == 'E') {
        //     right_e--;
        // } else {
        //     right_e++;
        // }
        // if (s[i ] == 'W') right_e++;
        // if (s[i -1] == 'W') left_w++;
        // min_count = min(min_count, right_e);
    }
    cout << min_count << '\n';
    
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
string s[maxn];
LL march[5];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = 0; i < n; i++)
	{
		switch (s[i][0])
		{
		case 'M':march[0]++; break;
		case 'A':march[1]++; break;
		case 'R':march[2]++; break;
		case 'C':march[3]++; break;
		case 'H':march[4]++; break;
		}
	}
	LL ans = march[0] * march[1] * march[2] + march[0] * march[1] * march[3] + march[0] * march[1] * march[4] + march[0] * march[2] * march[3] + march[0] * march[2] * march[4] + march[0] * march[3] * march[4] + march[1] * march[2] * march[3] + march[1] * march[2] * march[4] + march[1] * march[3] * march[4] + march[2] * march[3] * march[4];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <unordered_map>
#include <vector>
#include <cstdlib>
#include <utility>
using namespace std;

int main(){
    int n; cin >> n;
    unordered_map<string, bool> m;
    vector<long long> v(5, 0);

    for(int i = 0; i < n; ++i){
        string input; cin >> input;
        if(m.find(input) == m.end()){
            m.insert(make_pair(input, true));
            if(input[0] == 'M') v[0]++;
            else if(input[0] == 'A') v[1]++;
            else if(input[0] == 'R') v[2]++;
            else if(input[0] == 'C') v[3]++;
            else if(input[0] == 'H') v[4]++;
        }
    }

    long long ans = 0;
    for(int i = 0; i < 5; ++i)
        for(int j = i+1; j < 5; ++j)
            for(int k = j+1; k < 5; ++k)
                ans += v[i] * v[j] * v[k];

    cout << ans << endl;

    return EXIT_SUCCESS;
}


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

int main() {
  int max = 0;
  vector<vector<int>> v(3, vector<int>(3));
  for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin >> v[i][j];
  
  bool check = false;
  if(v[0][0]-v[1][0]!=v[0][1]-v[1][1] || v[0][1]-v[1][1]!=v[0][2]-v[1][2]) check = true;
  if(v[1][0]-v[2][0]!=v[1][1]-v[2][1] || v[1][1]-v[2][1]!=v[1][2]-v[2][2]) check = true;
  if(v[0][0]-v[0][1]!=v[1][0]-v[1][1] || v[1][0]-v[1][1]!=v[2][0]-v[2][1]) check = true;
  if(v[0][1]-v[0][2]!=v[1][1]-v[1][2] || v[1][1]-v[1][2]!=v[2][1]-v[2][2]) check = true;
  
  if(check) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main()
{
    string S;
    cin >> S;

    char c[4]={'A','C','G','T'};

    int max_cnt=0;
    int cnt=0;
    REP(i, S.size()){
        bool exist=false;
        REP(j, 4){
            if(S[i]==c[j]) {
                exist=true;
            }
        }
        if(exist) {
            cnt++;
          	if(max_cnt<cnt) max_cnt=cnt;
        }
        else cnt=0;
    }
    
    cout << max_cnt << endl;

    return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k,a;
    cin>>n>>k;
    int d;
    vi s(n,0);
    rep(i,0,k){
        cin>>d;
        rep(j,0,d){
            cin>>a;
            a--;
            s[a]++;
        }
    }
    int ans = 0;
    rep(i,0,n){
        if(s[i]==0){ans++;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3656
import java.util.*


/**
 * 有向グラフで　S -> T への路長 が3の倍数となるパスのうち，最短のものを求める
 *
 * グラフに状態を持たせた上で，そのグラフ上で，ゴールとするノードに特定の状態でたどり着くための最短パスを求める
 *
 * 説明
 * ・あるノードへのたどり着き方は S からの距離 %3 = 0, 1, 2 の３通りあると考える
 * ・グラフを３状態分作成する
 * ・例えばノード 1 -> 2 へのダイレクトパスがあるとすると，下記のような移動が可能になる
 *      1@状態0 -> 2@状態1
 *      1@状態1 -> 2@状態2
 *      1@状態2 -> 2@状態0
 *
 * このグラフ上で S@状態0 -> T@状態0 への最短パスを求めれば OK   うーむ賢い．．
 *
 */
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }

    // グラフを構築する ３倍のグラフを作るには？？
    // ノードすべてを３回ついかすればOK ？？
    // 最短パスを求めるには -> BFS で順に訪問していく & 値を割り振るのが BEST
    // BFS 訪問可能なものをすべて訪問した & T が未訪問状態 -> 答えはない と言える

    // グラフの持ち方はどうするのが良いか？？
    // 訪問先候補は queue で管理， 訪問済み候補は dp (n x 3) で管理（訪問した先には距離を入れる)
    // queue に追加するのは dp の値がまだ入っていない要素，
    // queue が空になったら探索修了 dp[T][0] を出力

    // グラフ構造をどう管理するか？？
    // 各ノード毎に状態数を持ったクラスを作成?? -> 次のノードクラスのどのフィールドを参照するか の指定が面倒では
    // あれ，グラフは３倍する必要はないのでは？？ !!!!
    // 距離の値 & queue に追加するかどうかは 3状態を管理する 配列 で制御
    // 配列のどの部分に距離を入れるかは BFS なので，ループ何巡目かで管理？？

    // -> 方針が経ってから 25分以内に実装できなかった．．実装完了まで 50分ほど -> パターン化しないと時間がもったいない

    // ここのグラフ作成はもう少しスマートにできないか？？
    val to = hashMapOf<Int, MutableList<Int>>()

    for (i in 0 until M) {
        val (u, v) = readLine()!!.split(" ").map { it.toInt() }
        val list = to.getOrElse(u-1) { mutableListOf() }
        list.add(v-1)
        to[u-1] = list
    }

    val (S, T) = readLine()!!.split(" ").map { it.toInt() }


    // 3状態の距離を格納する配列を定義, 初期値は -1
    val dist = Array(N) { IntArray(3) { -1 } }
    dist[S-1][0] = 0

    // BFS を実行 offer poll
    val queue = ArrayDeque<List<Int>>()
    queue.offer(listOf(S-1))

    // BFS の階層を管理するために，queue の中身はリストでまとめておく必要がある？
    var state = 0
    var currentDist = 0

    while (queue.size != 0) {
        // 次のBFSを開始
        val group = queue.poll()
        state = (state + 1) % 3
        currentDist += 1

        val set = hashSetOf<Int>()
        for (s in group) {
            // 次のBFSループで見に行く先を格納, dist が -1 (未訪問）の場合のみ距離を割り当て，queueに格納
            val nextGroupCand = to.getOrElse(s) { mutableListOf() }

            for (v in nextGroupCand){
                if (dist[v][state] == -1){
                    dist[v][state] = currentDist
                    set.add(v)
                }
            }
        }

        // 次の訪問候補群が存在する場合は queue に追加
        if (set.size > 0) queue.offer(set.toList())
    }

    // 答えを出力
    if(dist[T-1][0] == -1 ){
        println(-1)
    } else {
        println(dist[T-1][0] / 3)
    }
}

Measured memory_bytes: 103080
'use strict'

function main(input) {

  const isUpper = (char) => {
    return /[A-Z]/g.test(char);
  }

  const str = input.split('\n')[0];
  let ans = 'AC';

  const s1 = str.charAt(0);
  if (s1 !== 'A') ans = 'WA';

  const s2 = str.charAt(1);
  if (isUpper(s2)) ans = 'WA';

  const s3 = str.slice(2, str.length - 1).split('');
  let upper = 0;
  let hasC  = 0;
  for (const c of s3) {
    if (c === 'C') hasC += 1;
    if (isUpper(c)) upper += 1;
  }
  if (upper !== 1 || hasC !== 1) ans = 'WA'

  const s4 = str.charAt(str.length - 1);
  if (isUpper(s4)) ans = 'WA';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  int n;
  cin >> n;
  pair<ll,ll> p[n];
  ll a[n],b[n];
  rep(i,n){
    cin >> a[i] >> b[i];
    p[i].second=a[i];//length
    p[i].first=b[i];//end
  }
  ll t=0,ans=0;
  sort(p,p+n);
  rep(i,n){
    if(t<p[i].first && t+p[i].second<=p[i].first){
      ans++;
      t+=p[i].second;
    }
  }
  if(ans==n){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
return 0;}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#define INF 1<<28
using namespace std;

int sx, sy, gx, gy;
typedef pair < int, int > P;
vector < P > p[5];
int memo[5][5][1111];
int a, b;

int solve(int k, int t, int q){

  if(k == 4) return abs(p[t][q].first-gx) + abs(p[t][q].second-gy);
  if(memo[k][t][q]) return memo[k][t][q];

  int ans = INF, d = (t+1)%5, s;
  for(int i=0;i<p[d].size();i++){
    if(!k) s = abs(sx-p[d][i].first) + abs(sy-p[d][i].second);
    else s = abs(p[t][q].first-p[d][i].first) + abs(p[t][q].second-p[d][i].second);
    ans = min(ans, solve(k+1, d, i) + s);
  }

  return memo[k][t][q] = ans;
}

int main(){

  int w,h;
  char c;

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    for(int i=0;i<5;i++) p[i].clear();
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> c;
	if(c == 'S') sx = j, sy = i;
	if(c == 'G') gx = j, gy = i;
	else if(c != '.') p[c-'1'].push_back(P(j,i));
      }
    }
    
    b = INF;
    for(int i=0;i<5;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i, b = solve(0,i,0);
    }

    if(b == INF) cout << "NA\n";
    else cout << a+1 << " " << b << endl;

  }
}

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

using namespace std;

#define F first
#define S second

using ll = long long;


int main() {
    string s;
    cin >> s;
    cout << min(count(s.begin(), s.end(), '0'), count(s.begin(), s.end(), '1')) * 2 << '\n';
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	int[] a;
	int[] x;
	int[] y;

	public void run() {
		Scanner sc = new Scanner(System.in);

		int w = sc.nextInt();
		int n = sc.nextInt();

		a = new int[w + 1];
		for (int i = 1; i <= w; i++) {
			a[i] = i;
		}

		x = new int[n];
		y = new int[n];

		String[] str = new String[2];

		for (int i = 0; i < n; i++) {
			str = sc.next().split(",");
			x[i] = Integer.parseInt(str[0]);
			y[i] = Integer.parseInt(str[1]);
		}

		for (int i = 0; i < n; i++) {
			int tmp = a[x[i]];
			a[x[i]] = a[y[i]];
			a[y[i]] = tmp;
		}

		for (int i = 1; i <= w; i++) {
			System.out.println(a[i]);
		}

		sc.close();
	}

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

}

Measured memory_bytes: 17200
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int hist[3] = { };
  REP(i, N) {
    int P; cin >> P;
    if (P <= A) hist[0]++;
    else if (A < P && P <= B) hist[1]++;
    else hist[2]++;
  }
  cout << min({hist[0], hist[1], hist[2]}) << endl;
  return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

struct edge{
	int to;
	int cost;
};

vector<edge> graph[100010];
int color[100010];
struct edge e;

int search(int x, ll int l){
	int i;

	if(l%2==0){
		color[x]=0;
	}else{
		color[x]=1;
	}

	for(i=0;i<graph[x].size();i++){
		e=graph[x][i];
		if(color[e.to]==-1){
			search(e.to,l+e.cost);
		}
	}

	return 0;
}

int main(void)
{
	//変数の宣言
	int n;
	int u,v,w;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	double ans=0;
	int count=0;
	double temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


	for(i=0;i<n-1;i++){
		scanf("%d %d %d",&u,&v,&w);
//		scanf_s("%d %d %d",&u,&v,&w);
		e.to=v;
		e.cost=w;
		graph[u].push_back(e);
		e.to=u;
		graph[v].push_back(e);
	}

	for(i=1;i<=n;i++){
		color[i]=-1;
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	search(1,0);

	//	printf("計算部分終了\n");

	//出力
	for(i=1;i<=n;i++){
		printf("%d\n",color[i]);
	}


	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 8320
# d
require 'pp'
k = gets.to_i

stack = [1,2,3,4,5,6,7,8,9].reverse
ans = []



while true
  s = stack.pop
  ans << s
  ss = s.to_s
  if ss[-1] == ?0
    stack.unshift (ss + '1').to_i
    stack.unshift (ss + '0').to_i
  elsif ss[-1] == ?9
    stack.unshift (ss + '8').to_i
    stack.unshift (ss + '9').to_i
  else
    stack.unshift (ss + (ss[-1].to_i - 1).to_s).to_i
    stack.unshift (ss + (ss[-1].to_i + 1).to_s).to_i
    stack.unshift (ss + (ss[-1].to_i    ).to_s).to_i
  end
  break if ans.size >= 10 ** 5 * 2
end
ans.sort!
p ans[k-1]
# 23 1 21 3234566667



Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n;
int main(){
	n=read();
	printf("%d\n",(n-2)*180);
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>

int judg(std::vector<std::vector<int>> x, int judgnumber){
    for(auto i = 0; i < x.size(); i++){
        for(auto j = 0; j < x.at(i).size(); j++){
            if(judgnumber == x.at(i).at(j)){
                return 0;
            }
        }
    }
    return 1;
}

int main(){
    int N, K, ans = 0;
    std::cin >> N >> K;
    std::vector<int> d(K);
    std::vector<std::vector<int>> A(K, std::vector<int>(N));
    for(auto i = 0; i < K; i++){
        std::cin >> d.at(i);
        A.at(i).resize(d.at(i));
        for(auto j = 0; j < d.at(i); j++){
            std::cin >> A.at(i).at(j);
        }
    }

    for(auto i = 1; i <= N; i++){
        ans += judg(A, i);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>
#include <algorithm>

template <class S, class T> void chmax(S& lhs, const T& rhs){ if(lhs < rhs) lhs = rhs; }

constexpr unsigned int MAX_N = 100'000; // '
constexpr unsigned int MAX_M = 100'000; // '
unsigned int A[MAX_N];
long long int P[2 * MAX_M + 1];
long long int Q[2 * MAX_M + 1];

int main(void){
    unsigned int n, m; scanf("%u%u", &n, &m);
    for(unsigned int i = 0; i < n; ++i){ scanf("%u", A + i); --A[i]; }

    long long int S = 0;
    for(unsigned int i = 0; i + 1 < n; ++i){
        unsigned int l, r, L;
        if(A[i] < A[i + 1]){l = A[i]; r = A[i + 1]; L = r - l; }
        else{ l = A[i]; r = A[i + 1] + m; L = r - l; }
        S += L;
        if(L <= 1) continue;
        ++P[l + 2]; --P[r + 1]; Q[r + 1] -= L - 1;
    }
    {
        const unsigned int M = m << 1;
        for(unsigned int i = 1; i <= M; ++i) P[i] += P[i - 1];
        for(unsigned int i = 0; i <= M; ++i) P[i] += Q[i];
        for(unsigned int i = 1; i <= M; ++i) P[i] += P[i - 1];
    }
    long long int mx = 0;
    for(unsigned int i = 0; i < m; ++i) chmax(mx, P[i] + P[i + m]);
    printf("%lld\n", S - mx);
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;cin>>x;
    ll u = x;
    ll cnt = 0;
    u = u/500;
    x = x-u*500;
    ll t = x/5;
    cout<< u*1000+t*5 <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=200005;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int x;

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(x);
	printf("%d\n",360/gcd(x,360));
	return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <math.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define REP(i, end) FOR(i, 0, end)

using namespace std;

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

	int* p = new int[size];

	REP(i, size)
		cin >> p[i];

	int min, max;
	min = max = p[0];

	FOR(i, 1, size){
		if(min > p[i])  min = p[i];
		if(max < p[i])  max = p[i];
	}

	int difference = max - min;               //最小値と最大値の差
	int target;                               //揃える数

  int sum = 0;      //borderとの差の総計

	REP(i, size){
		sum += p[i];
	}

	double average = (double)sum / size;
  target = round(average);

	int cost = 0;
	REP(i, size)
		cost += (int)pow(p[i] - target, 2);

	cout << cost << endl;

	delete[] p;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a;
	cin>>a;
	cout<<(a+1)/2<<endl;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);  // merge technique
    par[x] += par[y];
    par[y] = x;
    return true;
  }

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  vector<ll> ans;
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  UnionFind tree(n);
  ll now = n * (n - 1) / 2;
  rep(i, m) {
    int A = a[m - 1 - i];
    int B = b[m - 1 - i];
    ans.push_back(now);
    if (tree.issame(A, B)) continue;
    now -= tree.size(A) * tree.size(B);
    tree.merge(A, B);
  }
  RSORT(ans);
  rep(i, ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

vi to[200005];
vi ans;
void dfs(int v, int p=-1){
	for(int u : to[v]){
		if(u==p) continue;
		ans[u]+=ans[v];
		dfs(u,v);
	}
}

int main(){
	int a,b;
	cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b)<<endl;
    return 0;
}




























Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder172
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveC();
        }


        static void SolveC()
        {
            var nmk = ReadLine().Split(' ');
            var k = long.Parse(nmk.Last());
            var aList = ReadLine().Split(' ').Select(long.Parse).ToList();
            var bList = ReadLine().Split(' ').Select(long.Parse).ToList();
            var aMinutes = new List<long> {0};
            for (var i = 0; i < aList.Count; i++)
            {
                aMinutes.Add(aMinutes[i] + aList[i]);
            }

            var bMinutes = new List<long> {0};
            for (var i = 0; i < bList.Count; i++)
            {
                bMinutes.Add(bMinutes[i] + bList[i]);
            }

            var ans = 0;
            var j = bMinutes.Count-1;
            for (var i = 0; i < aMinutes.Count; i++)
            {
                if (aMinutes[i] > k) break;

                while (aMinutes[i] + bMinutes[j] > k) j -= 1;
                ans = Math.Max(ans, i + j);
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 77336
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const LL maxn = 1e18;
int main()
{
    LL x,y;
    scanf("%lld%lld",&x,&y);
    if(x%y==0)
        printf("-1\n");
    else{
        LL ans=-1;
        for(int i=2;i*x<=maxn;i++)
            if(i*x%y!=0)
            {
                ans=i*x;break;
            }
        if(ans!=-1)
            printf("%lld\n",ans);
        else
            printf("-1\n");
    }

    return 0;
}


Measured memory_bytes: 256