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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int x, a, b; cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)) cout << "A" << endl;
    else cout << "B" << endl;
}

Measured memory_bytes: 3632
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i==0 or i==H-1 or j==0 or j==W-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[,] dp=new int[s[0]+1,s[0]+1];
		string[,] h=new string[s[0]+1,s[0]+1];
		int[][] arr=new int[s[1]][];
		bool[] b=new bool[s[1]];
		int ans=0;

		for(int i=1;i<=s[0];i++){
			for(int j=1;j<=s[0];j++){
				if(i!=j){dp[i,j]=int.MaxValue/2;}
			}
		}
		for(int i=0;i<s[1];i++){
			arr[i]=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			dp[arr[i][0],arr[i][1]]=arr[i][2];
			h[arr[i][0],arr[i][1]]=i.ToString();
			dp[arr[i][1],arr[i][0]]=arr[i][2];
			h[arr[i][1],arr[i][0]]=i.ToString();
		}
		for(int i=1;i<=s[0];i++){
			for(int j=1;j<=s[0];j++){
				for(int k=1;k<=s[0];k++){
					if(dp[j,k]>dp[j,i]+dp[i,k]){
						dp[j,k]=dp[j,i]+dp[i,k];
						h[j,k]=h[j,i]+" "+h[i,k];
					}
				}
			}
		}
		for(int i=1;i<=s[0];i++){
			for(int j=1;j<=s[0];j++){
				if(h[i,j]!=null){
					int[] q=Array.ConvertAll(h[i,j].Split(),int.Parse);
					foreach(int k in q){b[k]=true;}
				}
			}
		}
		for(int i=0;i<s[1];i++){if(!b[i]){ans++;}}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 19920
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}

int dp[5010*5010];

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  int g[3][2];

  cin>>n;
  rep(i,2){
    rep(j,3){
      cin>>g[j][i];
    }
  }

  rep(i,n+1){
    dp[i]=n;
  }

  int res=n;
  rep(i,3){
    rep(j,n+1){
      if(j-g[i][0]<0) continue;
      dp[j]=max(dp[j],dp[j-g[i][0]]-g[i][0]+g[i][1]);
      res=max(res,dp[j]);
    }
  }

  rep(i,res+1){
    dp[i]=res;
  }

  int ans=max(n,res);

  rep(i,3){
    rep(j,res+1){
      if(j-g[i][1]<0) continue;
      dp[j]=max(dp[j],dp[j-g[i][1]]-g[i][1]+g[i][0]);
      ans=max(ans,dp[j]);
    }
  }



  cout<<ans<<endl;

}

Measured memory_bytes: 195584
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int INF=1e18;
int N,P;
int powMOD(int x,int r,int MOD){
    if(r==0)return 1;
    if(r%2==0)return powMOD(x,r/2,MOD)*powMOD(x,r/2,MOD)%MOD;
    else return powMOD(x,r-1,MOD)*x%MOD;
}

signed main(){
    string S;cin>>N>>P>>S;
    int ans=0;
    reverse(S.begin(),S.end());
    if(P!=2&&P!=5){
        int R[N];
        REP(i,N){
            int d=(int)S[i]-'0';
            if(i==0)R[0]=d%P;
            else R[i]=(R[i-1]+d*powMOD(10,i,P))%P;
        }
        map<int,int>memo;
        REP(i,N)memo[R[i]]++;
      	memo[0]++;
        for(auto v:memo){
            ans+=v.second*(v.second-1)/2;
        }
    }
    else{
        REP(i,N){
            int d=S[i]-'0';
            if(d%P==0)ans+=N-i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2564
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    vector<ll> v(n);
    rep(i,n){
      cin>>v[i];
    }
    deque<ll> ans;
    if(n%2){
      rep(i,n){
        if(i%2) ans.push_back(v[i]);
        else ans.push_front(v[i]);
      }
    }else{
      rep(i,n){
        if(i%2) ans.push_front(v[i]);
        else ans.push_back(v[i]);
      }
    }
    rep(i,n) cout<<ans[i]<<" ";
    return 0;
}


Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  string s;
  cin >> s;
  string t;
  int n = s.size();
  rep(i,n){
    if(s.at(i) == 'd' && s.at(i+1) == 'r' && s.at(i+2) == 'e' && s.at(i+3) == 'a' && s.at(i+4) == 'm'){
      t += "A";
      i += 4;
      continue;
    }
    if(s.at(i) == 'e' && s.at(i+1) == 'r'){
      t += "B";
      i += 1;
      continue;
    }
    if(s.at(i) == 'a' && s.at(i+1) == 's' && s.at(i+2) == 'e'){
      t += "C";
      i += 2;
      continue;
    }
    if(s.at(i) == 'r'){
      t += "D";
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }
  n = t.size();
  for(int i=n-1;i>=0;i--){
    if(t.at(i) == 'A') continue;
    if(t.at(i) == 'B' && i >= 1){
      if(t.at(i-1) == 'A'){
        i--;
        continue;
      }
    }
    if(t.at(i) == 'C' && i >= 1){
      if(t.at(i-1) == 'B'){
        i--;
        continue;
      }
    }
    if(t.at(i) == 'D' && i >= 2){
      if(t.at(i-1) == 'C' && t.at(i-2) == 'B'){
        i -= 2;
        continue;
      }
    }
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;

class MyClass
{
    public static UInt64 Euclid(UInt64 a, UInt64 b)
    {
        UInt64 c = 0;
        do
        {
            c = a % b;
            a = b;
            b = c;
        } while (c != 0);
        return a;
    }

    static void Main(string[] args)
    {
        UInt64 a, b;
        string[] str;
        string str2;
        while ((str2 = Console.ReadLine()) != null)
        {
            str = str2.Split(' ');
            a = UInt64.Parse(str[0]);
            b = UInt64.Parse(str[1]);
            UInt64 gcd = Euclid(a, b);
            UInt64 lcm = (a * b) / gcd;
            Console.WriteLine("{0} {1}", gcd, lcm);
        }
    }
}


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

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

int main(){
  int N;
  cin>>N;
  vector<string> S(N+1);
  rep(i,N+1) cin>>S[i];

  vector<char> ans(N+1,'n');
  for(int i=1;i<=N;i++){
    for(int j=0;j<min(S[0].size(),S[i].size());j++){
      if(S[i][j]>='0'&&S[i][j]<='9'){
        if(S[0][j]>='0'&&S[0][j]<='9'){
          int val0=0,vali=0;
          int k=j;
          for(;k<S[0].size();k++){
            if(S[0][k]>='0'&&S[0][k]<='9'){
              val0=val0*10+S[0][k]-'0';
            }else break;
          }
          k=j;
          for(;k<S[i].size();k++){
            if(S[i][k]>='0'&&S[i][k]<='9'){
              vali=vali*10+S[i][k]-'0';
            }else break;
          }
          if(val0<vali) ans[i]='+';
          else if(val0>vali) ans[i]='-';
          j=k-1;
        }else ans[i]='-';
      }else if(S[0][j]>='0'&&S[0][j]<='9') ans[i]='+';
      else if(S[0][j]<S[i][j]) ans[i]='+';
      else if(S[i][j]<S[0][j]) ans[i]='-';
      
      if(ans[i]!='n') break;
    }
    if(ans[i]=='n'){
      if(S[i].size()<S[0].size()) ans[i]='-';
      else ans[i]='+';
    }
  }

  for(int i=1;i<=N;i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 3232
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 * 
 * https://atcoder.jp/contests/abc176/submissions/16164166 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int n3 = n * 3;
			int[] a = new int[n3];
			IntStream.range(0, n3).forEach(i -> a[i] = scanner.nextInt() - 1);
			int[][] dp = new int[n][n];
			IntStream.range(0, n).forEach(i -> Arrays.fill(dp[i], -1));
			dp[a[0]][a[1]] = dp[a[1]][a[0]] = 0;
			int[] max = new int[n];
			Arrays.fill(max, -1);
			int maxOfMax = 0, answer = 0;
			for (int i = 2; i < n3; i += 3) {
				if (n3 - 1 == i) {
					maxOfMax = Math.max(maxOfMax, dp[a[i]][a[i]] + 1);
				} else {
					// 左から 3,4,5 番目の数字が等しいときは、必ずそれら 3 枚を取り除くことにします
					if ((a[i] == a[i + 1]) && (a[i] == a[i + 2])) {
						answer++;
						continue;
					}

					List<Data> updates = new ArrayList<>();
					for (int j = 0; j < 3; j++) {
						int t1 = i + j;
						// 3,4,5 番目の数字の一つを p、残りを左から q,r として、DP[i+1][q][r] を DP[i][p][p]+1 で最大化します
						if (-1 != dp[a[t1]][a[t1]]) {
							int t2 = i + ((j + 1) % 3), t3 = i + ((j + 2) % 3);
							updates.add(new Data(a[t2], a[t3], dp[a[t1]][a[t1]] + 1));
						}
					}
					for (int t1 = i; t1 < i + 3; t1++) {
						for (int t2 = t1 + 1; t2 < i + 3; t2++) {
							int t3 = 3 * (i + 1) - t1 - t2;
							if (a[t1] == a[t2]) {
								// 3,4,5 番目の数字に等しい数字のペアがあるとき、その値を p、残りの一つの値を q 、k を 1 以上 N 以下の任意の整数として、DP[i+1][k][q] を
								// DP[i][p][k]+1 や DP[i][k][p]+1 で最大化します
								for (int k = 0; k < n; k++) {
									if (-1 != dp[k][a[t1]]) {
										updates.add(new Data(k, a[t3], dp[k][a[t1]] + 1));
									}
								}
							}
							// 3,4,5 番目の数字を左から p,q,r 、k,l を 1 以上 N 以下の任意の整数として、DP[i+1][p][q] や DP[i+1][p][r] や
							// DP[i+1][q][r] を DP[i][k][l] の最大値で最大化します
							updates.add(new Data(a[t1], a[t2], maxOfMax));
						}
						// DP[i+1][k][q] を DP[i][p][k]+1 や DP[i][k][p]+1 で最大化します
						for (int k = 0; k < n; k++) {
							updates.add(new Data(k, a[t1], max[k]));
						}
					}
					for (Data data : updates) {
						dp[data.i][data.j] = dp[data.j][data.i] = Math.max(dp[data.i][data.j], data.dp);
						max[data.i] = Math.max(max[data.i], dp[data.i][data.j]);
						max[data.j] = Math.max(max[data.j], dp[data.j][data.i]);
						maxOfMax = Math.max(dp[data.i][data.j], maxOfMax);
					}
				}
			}
			System.out.println(maxOfMax + answer);
		}
	}

	/**
	 * i,j,dpを表すクラス
	 */
	private static class Data {
		int i;
		int j;
		int dp;

		Data(int i, int j, int dp) {
			super();
			this.i = i;
			this.j = j;
			this.dp = dp;
		}
	}
}


Measured memory_bytes: 81504
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    vector<int> a(N);
    read(a);

    int minv = a[0];
    int ans = 0;
    rep(i, 0, N) {
        if (minv >= a[i]) ++ans;
        chmin(minv, a[i]);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n;
    cin >> n;
    map<string,int> m;
    rep(i,n) {
        string s;
        cin >> s;
        m[s]++;
    }
    int ans = 0;
    for (auto itr = m.begin(); itr != m.end(); itr++)
    {
        ans++;       
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19224
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N, Q = LI()
    s = S()
    L, R = [], []
    for _ in range(Q):
        l, r = LI_()
        L.append(l)
        R.append(r)
    num_ac = [0] * len(s)
    for i in range(len(s) - 1):
        if s[i] == 'A' and s[i+1] == 'C':
            num_ac[i+1] += 1
    for i in range(1, len(s)):
        num_ac[i] += num_ac[i-1]
    for i in range(Q):
        print(num_ac[R[i]] - num_ac[L[i]])

main()



Measured memory_bytes: 18336
n = int(input())
s = input()

if n == 1:
    print("No")
    exit()
if n % 2 == 1:
    print("No")
    exit()
if n != 1:
    a = 0
for i in range(n//2):
    #print(s[i], s[(n//2)+i])
    if s[i] == s[(n//2)+i]:
        a += 1

if a == (n//2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	    char[]wb=sc.next().toCharArray();
	    char now=wb[0];
	    int ans=0;
	    for(int i=0;i<wb.length-1;i++){
	    	if(now!=wb[i+1])ans++;
	    	now=wb[i+1];
	    }
	    System.out.println(ans);
		
	}
	
}

Measured memory_bytes: 14096
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
#define LOCAL



int main(int argc, char * argv[]) 
{
	int a, b;
	cin >> a >> b;
	if (a > b) cout << a - 1 << endl;
	else cout << a << endl;


    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

ans =0
for i in range(n):
    if sum([a[i][j]*b[j] for j in range(m)]) + c > 0:
        ans += 1
print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define INF 1e7
#define dsec 86400

using namespace std;
typedef long long int ll;
typedef tuple<int,int,int> tii;
typedef tuple<long long int,long long int,long long int> tll;
typedef tuple<double,double,double> tdd;

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b,a%b);
}


ll lcm(ll a, ll b)
{
    return a*b/gcd(a,b);
}


int main()
{
    ll N,M; cin >> N >> M;
    vector<ll>a(N);
    for(ll i = 0; i < N; i++) cin >> a[i];
    ll t = 0;
    for(ll i = 0; i < N; i++)
    {
        if(i == 0)
        {
            while(a[i]%2 == 0)
            {
                t++;
                a[i] /= 2;
            }
        }
        else
        {
            ll tmp = 0;
            while(a[i]%2 == 0)
            {
                tmp++;
                a[i] /= 2;
            }
            if(t != tmp)
            {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    ll l = 1;
    for(ll i = 0; i < N; i++)
    {
        l = lcm(l,a[i]);
        if(l > M)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    M >>= (t-1);
    M /= l;
    ll ans = (M+1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 4024
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=1
    if 0 in A:
        print(0)
        exit()
    for a in A:
        ans*=a
        if ans>10**18:
            print(-1)
            exit()
        
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 22960
import java.io.*;

class Main{
    public static void main(String[] args){
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                int x = j * i;
                System.out.println(i + "x" + j + "=" + x);
            }
        }
    }
}

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

# define C continue;
# define R return;

# define D double
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()

# define pii pair < int , int >
# define vpii vector < pii >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(-1,1);
const D tpie = 2*pie;

void solve( int test_case )
{
    string s;
    cin>>s;

    if ( s=="0000" ) { cout<<"NA"; R; }

    int a = (s[0]-'0')*10 + s[1]-'0';
    int b = (s[2]-'0')*10 + s[3]-'0';

    if ( a==0 )
    {
        if ( b>0 && b<=12 ) cout<<"YYMM";
        else cout<<"NA";
    }
    else if ( b==0 )
    {
        if ( a>0 && a<=12 ) cout<<"MMYY";
        else cout<<"NA";
    }

    else
    {
        if ( a<=12 && b<=12 ) cout<<"AMBIGUOUS";
        else if ( a>12 && b<=12 ) cout<<"YYMM";
        else if ( b>12 && a<=12 ) cout<<"MMYY";
        else cout<<"NA";
    }


}

int main()
{
    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    class Program
    {
        static void Main(string[] arg)
        {
            var answer = "";
            string[] str = Console.ReadLine().Split('/');

            if (int.Parse(str[0]) > 2019)
            {
                answer = "TBD";
            }
            else if (int.Parse(str[0]) == 2019)
            {
                if (int.Parse(str[1]) >= 5)
                {
                    answer = "TBD";
                }
                else
                {
                    answer = "Heisei";
                }
            }
            else
            {
                answer = "Heisei";
            }

            Console.WriteLine(answer);
            Console.ReadLine();

        }
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();

        }
    }
}

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

//#define int long long
//signed main(){
int main (){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll n,k;
    cin >> n >> k ;
    vector<ll> a(n),f(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < n; i++) cin >> f[i];

    sort(a.begin(),a.end());
    sort(f.rbegin(),f.rend());

    ll l=-1;
    ll r=1e17;
    while(r-l>1) {
        ll mid=(r+l)/2;
        ll cnt=0;
        for(ll i = 0; i < n; i++) {
            ll ra = mid/f[i];
            if(ra<a[i]) cnt+=(a[i]-ra);
        }
        if(cnt>k) l=mid;
        else r=mid;
    }
    cout << r << "\n";

    return 0;
}

Measured memory_bytes: 6428
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())
s = c11 + c22 + c33
if s - c12 - c23 != c31 or s - c13 - c32 != c21:
    print("No")
else:
    print("Yes")


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



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  vector<int> s(32);
  s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  ll n;
  cin >> n;
  
  //vector<int> a(n);  rep(i, 0, n) cin >> a.at(i);
  
  cout << s.at(n-1) << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;

int main() {
    string s, t; cin >> s >> t;
    int n = (int)s.size(), m = (int)t.size();
    vector<vector<int>> alpha(26);
    for(int i = 0; i < n; i++) {
        alpha[s[i]-'a'].push_back(i);
    }
    for (int i = 0; i < n; i++){
        alpha[s[i]-'a'].push_back(i+n);
    }

    ll ans = 0;
    int now = 0;
    for (int i = 0; i < m; i++) {
        int c = t[i] - 'a';

        //sにtの文字がない
        if ((int)alpha[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }

        now = *lower_bound(alpha[c].begin(), alpha[c].end(), now) + 1;
        if (now >= n) {
            now -= n;
            ans += n;
        }
    }
    ans += now;
    cout << ans << endl;

    return 0;
}

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

public class Main{
	public String[] data0 = new String[]{
		"A", "B", "C", "D", "E", "F", "G", "H",
		"I", "J", "K", "L", "M", "N", "O", "P",
		"Q", "R", "S", "T", "U", "V", "W", "X",
		"Y", "Z", " ", ".", ",", "-", "'", "?"
	};

	public String[] data1 = new String[]{
		"00000", "00001", "00010", "00011",
		"00100", "00101", "00110", "00111",
		"01000", "01001", "01010", "01011",
		"01100", "01101", "01110", "01111",
		"10000", "10001", "10010", "10011",
		"10100", "10101", "10110", "10111",
		"11000", "11001", "11010", "11011",
		"11100", "11101", "11110", "11111"
	};

	public String[] data2 = new String[]{
		"101", "000000", "000011", "10010001",
		"010001", "000001", "100101", "10011010",
		"0101", "0001", "110", "01001",
		"10011011", "010000", "0111", "10011000",
		"0110", "00100", "10011001", "10011110",
		"00101", "111", "10011111", "1000",
		"00110", "00111", "10011100", "10011101",
		"000010", "10010010", "10010011", "10010000"
	};

	public String[] data3 = new String[]{
		" ", "'", ",", "-", ".", "?", "A", "B",
		"C", "D", "E", "F", "G", "H", "I", "J",
		"K", "L", "M", "N", "O", "P", "Q", "R",
		"S", "T", "U", "V", "W", "X", "Y", "Z"
	};

	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<String> Ans = new ArrayList<String>();
		String line;

		while((line = in.readLine()) != null){

			String line1 = "";
			for(int i=0; i<line.length(); i++){
				String l = line.substring(i, i+1);
				for(int n=0; n<data0.length; n++){
					if(l.equals(data0[n])){
						line1 += data1[n];
					}
				}
			}

			String line2 = "";
			String str = "";
			for(int i=0; i<line1.length(); i++){
				str += line1.substring(i, i+1);
				for(int n=0; n<data2.length; n++){
					if(str.equals(data2[n])){
						line2 += data3[n];
						str = "";
					}
				}
			}

			Ans.add(line2);
		}

		for(int i=0; i<Ans.size(); i++){
			System.out.println(Ans.get(i));
		}
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

pair<ll, ll> f(int x){
  ll a=x%10;
  ll b=0;
  while(x) {
    b=x;
    x/=10;
  }
  return make_pair(a,b);
}

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int n;
    cin >> n;
    map<pair<ll, ll>, int> A;
    for(int i=1; i<=n; i++){
      pair<ll, ll> B=f(i);
      A[B]++;
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
      pair<ll, ll> C=f(i);
      pair<ll, ll> Q=make_pair(C.S,C.F);
      ans+=A[Q];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
	long long a,b,c,d,e,f,g;
	cin>>a>>b>>c>>d>>e>>f>>g;
	
	long long ans = 0;
	
	ans += b*2;
	
	long long x = 0;
	
	x += 4*(a/2);
	
	x += 4*(d/2);
	
	x += 4*(e/2);
	
	if(a%2&&d%2&&e%2)x+=6;
	
	long long y = 0;
	if(a&&d&&e){
		y+=6;
		a--;d--;e--;
	}
	
	y+=4*(a/2);
	y+=4*(d/2);
	y+=4*(e/2);
	
	ans += max(x,y);
	
	cout<<ans/2<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 256
from fractions import gcd

def lcm(a, b):
    if a == 0 or b == 0:
        return 0
    return int(a * b // gcd(a, b))
  
def solve():
    n = int(input())
    tl = [int(input()) for _ in range(n)]
    ans = tl[0]
    for elem in tl[1:]:
        ans = lcm(ans, elem)
    print(ans)
 
if __name__=="__main__":
    solve()

Measured memory_bytes: 70636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;
ll H[MAX];
ll psum[MAX], A, B;

bool check(ll m) {
	ll dmg = B * m;
	ll extra = A - B;
	ll cnt = m;
	for (int i = 1; i <= N; ++i) {
		if (H[i] <= dmg) continue;
		ll need = ((H[i] - dmg) + extra - 1) / extra;
		cnt -= need;
		if (cnt < 0) return false;
	}
	return true;
}

int main()
{
	int i, j, k;
	scanf("%d%lld%lld", &N, &A, &B);
	ll maxi = 0;
	for (i = 1; i <= N; ++i) {
		scanf("%lld", &H[i]);
		maxi = max(maxi, H[i]);
		psum[i] = psum[i - 1] + H[i];
	}

	ll l = 1;
	ll h = (maxi + B)/B;
	ll m;
	sort(H, H + N);
	while (l < h) {
		m = l + (h - l) / 2;
		if (check(m)) {
			h = m;
		}
		else l = m + 1;
	}
	if (check(l)) m = l;
	printf("%lld", m);
}


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

using namespace std;

const int N = 100001;
int n;
int a[N];

int gcd(int a, int b)
{
    while(b)
    {
        a %= b;
        swap(a, b);
    }
    return a;
}

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

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

    int ans = a[0];
    for(int i = 1; i < n; i++)
        ans = gcd(ans, a[i]);

    cout << ans;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
};

vector<edge> G[225000];
vector<edge> G_[50];
int N, M, S;
int A[100];
ll B[100], C[50], D[50];

P devide(int v){
    return P(v%N, v/N);
}

map<P, int> mpa;

const ll INF = 1e+15;
ll d[200000];

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> S;
    for(int i = 0; i < M; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G_[v].push_back((edge){u, b});
        G_[u].push_back((edge){v, b});
        mpa[P(u, v)] = a;
        mpa[P(v, u)] = a;
    }
    for(int i = 0; i < N; i++) {
        cin >> C[i] >> D[i];
        for(int j = 0; j <= N*50; j++){
            int v = j*N+i;
            for(auto k:G_[i]){
                // v-> k
                int a = mpa[P(k.to, i)];
                if(j >= a){
                    int u = (j-a)*N+k.to;
                    G[v].push_back((edge){u, k.cost});
                }
            }
            if(j+C[i] <= N*50){
                int k = j+C[i];
                int u = k*N+i;
                G[v].push_back((edge){u, D[i]});
            }
        }
    }
    S = min(S, N*50);
    int s = S*N;
    dijkstra(s, N*N*51);
    for(int i = 1; i < N; i++){
        ll ans = INF;
        for(int j = 0; j <= N*50; j++){
            int u = j*N+i;
            ans = min(ans, d[u]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 25964
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N;
V<V<int>> e;
V<int> c;

void solve() {
    V<bool> vis1;
    vis1.resize(N+1,true);
    std::stack<tuple<int,int>> stk1;
    stk1.push(make_tuple(1,0));
    int u = 1, maxd1 = 0, s, d;
    vis1[u] = false;
    while(!stk1.empty()) {
        std::tie(s,d) = stk1.top();
        stk1.pop();
        REP(i,e[s].size()) if(vis1[e[s][i]]) {
            stk1.push(make_tuple(e[s][i],d+1));
            vis1[e[s][i]] = false;
            if(maxd1 < d+1) u = e[s][i], maxd1 = d+1;
        }
    }

    LL ans = 0;
    V<int> vis2;
    vis2.resize(N+1, -1);
    queue<int> q;
    int idx = N-1;
    vis2[u] = c[idx--];
    q.push(u);
    while(!q.empty()) {
        int s = q.front(); q.pop();
        REP(i,e[s].size()) {
            int nt = e[s][i];
            if(vis2[nt] != -1) {
                ans += std::min(vis2[s], vis2[nt]);
            } else {
                vis2[nt] = c[idx--];
                q.push(nt);
            }
        }
    }
    cout << ans << "\n";
    REP(i,N) {
        cout << vis2[i+1] << " ";
    }
}

int main(){
    INIT;
    cin >> N;
    e.resize(N+1);
    REP(i,N-1) {
        int x,y; cin >> x; cin >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    REP(i,N) {
        int x; cin >> x;
        c.push_back(x);
    }
    std::sort(ALL(c));
    solve();
}

Measured memory_bytes: 1024
// Prime Number:
// int w[10100];
// for(i=2;i<=n+1;i++){
//         for(j=i+i;j<=n+1;j+=i){
//             w[j] = 1;
//         }
//    }
 
//  int x='a';
//  char p=65;
//   a[i]=i+'a';
 
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
 
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
#define forn(i, n) for(long long int i = 0; i < (long long int)(n); i++)
#define ford(i, n) for(long long int i = (long long int)(n) - 1; i >= 0; i--)
#define fore(i, a, n) for(long long int i = (long long int)(a); i <(long long int)(n); i++)
#define endl '\n'
#define pb push_back
#define po pop_back
#define mx (int)1e10
#define mn (int)-1e9
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout<<x
int main()
{
   
  int n;
  cin>>n;
  vector<int> v;
  forn(i,n)
  {
      int x;
      cin>>x;
      v.pb(x);
  }
  
  int ans=0;
  forn(i,n)
  {
      fore(j,i+1,n)
      {
          fore(k,j+1,n)
          {
              int a =v[i]+v[j];
              int b =v[k]+v[j];
              int c=v[i]+v[k];
              if(a>v[k] and b>v[i] and c>v[j] and (v[i]!=v[j]) and v[i]!=v[k] and v[j]!=v[k])
              ans++;
          }
      }
  }
  
  cout<<ans;
   
   return 0;
   
     
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
    int n,i,c=0; cin>>n;
    vector<int>v(n+1);
    for(i=1;i<=n;i++){cin>>v[i]; if(i==v[i])a[i]=1;}
    if(a[1])
    {
        if(a[2])a[2]=0;
        c++; a[0]=0;
    }
    for(i=2;i<n;i++)
    {
      if(a[i])
      {
          if(a[i+1])a[i+1]=0;
          c++,a[i]=0;
      }
    }
    if(a[n])
        c++;
    cout<<c;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a == b){
    cout << "Draw" << endl;
    return 0;
  }
  if(a == 1){
    cout << "Alice" << endl;
    return 0;
  }
  if(b == 1){
    cout << "Bob" << endl;
    return 0;
  }
  if(a>b){
    cout << "Alice" << endl;
  }else{
    cout << "Bob" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  string s;
  int len,ii,cnt;
  bool flg = true;
  cin >> s;
  len = s.size();
  cnt = 0;

  if(s[0] == 'A'){
	for(ii=2;ii<=len-2;ii++){
	  if(s[ii] == 'C'){
		cnt++;
	  }
	  else if(s[ii] < 'a' || s[ii] > 'z'){
		flg = false;
	  }
	}
  }
  else{
	flg = false;
  }
  if(s[1] < 'a' || s[1] > 'z'){
	flg =  false;
  }
  
  if(s[len-1] < 'a' || s[len-1] > 'z'){
	flg =  false;
  }
  
  //cout << "cnt:" << cnt  << endl;
  if(cnt != 1){
	flg = false;
  }
  
  if(flg){
	cout << "AC" << endl;
  }
  else{
	cout << "WA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

struct team {
	int no, ac, wa[10], time;
	bool operator < (const team& a) const {
		if(ac == a.ac) {
			if(time == a.time)
				return no > a.no;
			else
				return time < a.time;
		}
		else
			return ac > a.ac;
	}
};

int main() {
	int M, T, P, R;
	while(cin >> M >> T >> P >> R, M|T|P|R) {
		vector<team> vt;
		REP(i, T) {
			team t;
			t.no = i + 1;
			t.ac = t.time = 0;
			memset(t.wa, 0, sizeof(t.wa));
			vt.push_back(t);
		}
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			if(j)
				vt[t-1].wa[p-1]++;
			else {
				vt[t-1].ac++;
				vt[t-1].time += m + vt[t-1].wa[p-1] * 20;
			}
		}
		sort(vt.begin(), vt.end());
		int a = vt[0].ac, t = vt[0].time;
		cout << vt[0].no;
		FOR(i, 1, vt.size()) {
			if(vt[i].ac == a && vt[i].time == t)
				cout << '=';
			else {
				a = vt[i].ac;
				t = vt[i].time;
				cout << ',';
			}
			cout << vt[i].no;
		}
		cout << endl;
//		REP(i, vt.size()) cout << vt[i].no << ' ' << vt[i].ac << ' ' << vt[i].time << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    println!("{}", std::cmp::min(n * a, b));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int ms = 1e5+109;
int h[ms], cost[ms];

int main(){
  int n, k;
  cin >> n >> k;
  for(int i = 0 ; i < n; i++) cin >> h[i];

  for(int i = 1; i <=n; i++) cost[i] = 1e9+10;

  for(int i = 0; i < n; i++){
    for(int j = 1; j<=k; j++)
      cost[i+j] = min(cost[i+j], cost[i] + abs(h[i] - h[i+j]));
  
  }

  cout<<cost[n-1];

}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cctype>

using namespace std;

int main()
{
    int H, W;

    scanf("%d", &H);
    scanf("%d", &W);

    char map[50][50];
    char map2[50][50];

    memset(map, 0, sizeof(char) * 50 * 50);

    for( int h = 0; h < H; h++ )
    {
        for( int w = 0; w < W; w++ )
        {
            char chr;
            while(isspace((chr = getchar())));
            map[h][w] = chr;
        }
    }

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

    for( int h = 0; h < H; h++ )
    {
        for( int w = 0; w < W; w++ )
        {
            if( map[h][w] == '#' ) continue;

            int bomb = 0;

            for( int i = 0; i < 8; i++)
            {
                int x = h + dx[i];
                int y = w + dy[i];

                if( x < 0 || H <= x ) continue;
                if( y < 0 || W <= y ) continue;

                bomb += map[x][y] == '#' ? 1 : 0;
            }

            map2[h][w] = '0' + bomb;
        }
    }

    for( int h = 0; h < H; h++ )
    {
        for( int w = 0; w < W; w++ )
        {
            if( map[h][w] == '#' )
                putchar('#');
            else
                putchar(map2[h][w]);
        }
        putchar('\n');
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(A<=8 && B<=8){
			System.out.println("Yay!");
		}else{
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N; cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; ++i) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < p.size() - 1; ++i) {
		ans += p[i];
	}
	ans += p[p.size() - 1] / 2;
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

using namespace std;

int main() {
    int N, ans = 0;
    long long H, W;
    cin >> N >> H >> W;
    
    vector<long long> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    
    for (int i = 0; i < N; i++) {
        if (A[i] >= H && B[i] >= W) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N, *T = map(int, read().split())

    ans = 1
    for t in T:
        ans = lcm(ans, t)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
x, y = gets.split.map(&:to_i)
mod = 10**9 + 7

def factorial(x, mod)
  return 1 if x == 0
  1.upto(x).inject { |i, j| i * j % mod }
end

def inv_fact(x, mod)
  factorial(x, mod).pow(mod - 2, mod)
end

def combination(x, y, mod)
  factorial(x, mod) * inv_fact(y, mod) * inv_fact(x - y, mod)
end

if (2 * x - y) % 3 == 0 && (-x + 2 * y) % 3 == 0
  u = (2 * x - y) / 3
  v = (-x + 2 * y) / 3

  if u >= 0 && v >= 0
    puts combination(u + v, u, mod) % mod
  else
    puts 0
  end
else
  puts 0
end

Measured memory_bytes: 14380
#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(){
    std::cout<<std::fixed<<std::setprecision(10);
    int n; cin>>n;
    double v[51];
    rep(i, n) cin >> v[i];
    sort(v, v+n);
    double ans = v[0];
    for(int i=1; i<n; i++){
        ans = (ans+v[i])/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256