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

int a, b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)


int main() {
	int n,max=0,cnt=0;
	cin >> n;
	vector<int> h(n);
	REP(i, n) cin >> h[i];
	REP(i, n - 1) {
		if (h[i] >= h[i + 1]) cnt++;
		else if (h[i] < h[i + 1])cnt = 0;
		if (max < cnt)max = cnt;
	}
	cout << max << endl;
  return 0;
}


Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int C[] = new int[N-1];
        int S[] = new int[N-1];
        int F[] = new int[N-1];
        
        for( int i = 0; i < N - 1; i++ ) {
            C[i] = sc.nextInt();
            S[i] = sc.nextInt();
            F[i] = sc.nextInt();
        }
        
        for( int i = 0; i < N; i++ ) {
            int t = 0;
            for( int j = i; j < N - 1; j++) {
                if( S[j] > t ) {
                    t = S[j];
                } else {
                    if( t % F[j] != 0 ) {
                        t += F[j] - t % F[j];
                    }
                }
                t += C[j];
            }
            System.out.println( t );
        }
    }
}


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

vector<bool> shops;
const int nax = 1e5 + 5;
int h[nax];
bool good[nax];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for(int i = 1; i <= n; i++) {
        good[i] = true;
    }
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if(h[a] <= h[b]) {
            good[a] = false;
        }
        if(h[b] <= h[a]) {
            good[b] = false;
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += good[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  int X; cin >> X;
  int ans = (X/500)*1000;
  X %= 500;
  ans += 5*(X/5);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

ll cnt[1010];

int main() {
    int n;
    ll ans = 1;
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        int now = i;
        for (int j = 2; j <= now; ++j) {
            while(now %j == 0 && now > 0){
                now /= j;
                cnt[j]++;
            }
        }
    }
    for (int i = 2; i <= n; ++i) {
        if(cnt[i] != 0){
            ans *= (cnt[i]+1);
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#dp3 #Vacation

def c():
    n = int(input())
    dpa = [0]*n
    dpb = [0]*n
    dpc = [0]*n

    a,b,c = list(map(int,input().split()))
    dpa[0] = a
    dpb[0] = b
    dpc[0] = c
    for i in range(1,n):
        a,b,c = list(map(int,input().split()))
        dpa[i] = max(dpb[i-1] + a,dpc[i-1] + a)
        dpb[i] = max(dpa[i-1] + b,dpc[i-1] + b)
        dpc[i] = max(dpa[i-1] + c,dpb[i-1] + c)
    print(max(dpa[-1],dpb[-1],dpc[-1]))
if __name__ == '__main__':
    c()


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

int main(void) {
    int n, m;
    cin >> n >> m;
    int h[n];
    int a, b;
    vector< int > ans(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        if (h[a-1] < h[b-1]) {
            ans[a-1] = 1;
        } else if (h[a-1] > h[b-1]) {
            ans[b-1] = 1;
        } else {
            ans[a-1] = ans[b-1] = 1;
        }
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (ans[i] == 0) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4048
import math
a, b, x = map(int, input().split())

if 2*x/(a**2) > b:
    c = b- (2*x/(a**2) - b)
    rad = math.acos(a/math.sqrt(c**2 + a**2))
    deg = math.degrees(rad)
    ans = deg
else:
    c = 2*x/a/b
    h = b * c / math.sqrt(b**2 + c**2)
    rad = math.acos(h/b)
    deg = math.degrees(rad)
    ans = deg
    
print(ans)

Measured memory_bytes: 3060
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;



int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code
    char a1,b1,c1;
    cin>>a1>>b1>>c1;
    if(a1==b1&&b1==c1&&a1=='R') cout<<3<<endl;
    else if(a1==b1&&a1=='R')cout<<2<<endl;
    else if(b1==c1&&b1=='R') cout<<2<<endl;
    else if(a1=='R'||b1=='R'||c1=='R') cout<<1<<endl;
    else cout<<0<<endl;


    //code
    return 0;
}




Measured memory_bytes: 50532
n=gets.chomp.to_i
f=[]
f[0]=0
f[1]=0
for i in 0..n
  f[i]=f[i-1]+i-1 if i>=2
end
s=[]
for i in 0..n-1
  s[i]=gets.chomp.split("").sort.inject(:+).to_s
end
s.sort!.push(0)
ans=0
t=0
c=1
for i in 0..n
  if t==s[i]
    c+=1
  else
    ans+=f[c]
    c=1
    t=s[i]
  end
end

puts ans

Measured memory_bytes: 14792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, S;
    cin >> N >> S;
    ll sqN = (ll)sqrt(N);

    if(N<S){
        cout << -1 << endl;
        return 0;
    }
    else if(N==S){
        cout << S + 1 << endl;
        return 0;
    }
    ll ans = INF;
    repe(b,2,sqN+2){
        ll ts = 0, tn = N;
        while(tn!=0){
            ts += tn % b;
            tn /= b;
        }
        if(ts==S){
            ans = b;
            break;
        }
    }
    repe(a,1,sqN){
        ll b = (N - S) / a + 1;
        ll ts = 0, tn = N;
        if (b == 1) break;
        while(tn!=0){
            ts += tn % b;
            tn /= b;
        }
        if(ts==S){
            chmin(ans, b);
        }
    }
    cout << (ans != INF ? ans : -1) << endl;
}


Measured memory_bytes: 256
//Template Jollybee 2017-0720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
 
const int INF=(int)2e9;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
const ll MOD=(ll)1e9+7;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
 
int main(){
	int n;
	scanf("%d",&n);
	int temp;
	int count = 0;
	int arr[n+2];
	for(int i=1;i<=n;i++){
		scanf("%d",&arr[i]);
	}
	for(int i=1;i<=n;i++){
		if(i+1<=n&&arr[i]==i&&arr[i+1]==i+1){
			count++;
			i++;
		}
		else if(arr[i]==i){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    vector<int>a(5);
    for(int i=0;i<5;i++){
        cin >> a[i];
    }
    int k;
    cin >> k;
    sort(a.begin(),a.end());
    if(a[4]-a[0]>k){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl; 
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;
#define LINK(i,graph,pos) for (REG int i=graph.head[pos];i;i=graph.next[i])

#define MAXN 210000
#define MAXM 410000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

int n,m;
bool visit[MAXN];
int deg[MAXN];

class GRAPH 
{
	public:
		int to[MAXM],next[MAXM];
		bool rev[MAXN];
		int head[MAXN];
		int cnt;
		
	GRAPH()
	{
		cnt=1;
	} 
	
	void add(int x,int y)
	{
		next[cnt]=head[x];
		to[cnt]=y;
		head[x]=cnt++;
	}
};

int flip(int x)
{
	return (x&1) ? x+1:x-1;
}

GRAPH g;

int dfs(int pos)
{
	int sum=0;
	visit[pos]=true;
	LINK(i,g,pos)
		if (!visit[g.to[i]])
		{
			if (dfs(g.to[i]))
			{
				g.rev[i]=true;
				sum++;
			}
		}
	return (sum+(deg[pos] & 1)) & 1;
}

int main()
{
	int x,y;
	cin>>n>>m;
	if (m&1)
	{
		cout<<-1;
		return 0;
	}
	RPT(i,0,m)
	{
		scanf("%d%d",&x,&y);
		g.add(x,y);
		g.add(y,x);
		deg[x]++;
	}
	dfs(1);
	for (int i=1;i<g.cnt;i+=2)
		if (g.rev[i] || g.rev[i+1])
			printf("%d %d\n",g.to[i],g.to[i+1]);
		else
			printf("%d %d\n",g.to[i+1],g.to[i]);
	return ~~(0^_^0);
}


Measured memory_bytes: 8320
#include <algorithm>
#include <array>
#include <deque>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - (n % 1000) << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int i=1;
		while(true){
			int x=stdIn.nextInt();
			if(x==0){
				break;
			}
			System.out.println("Case "+i+": "+x);
			i++;
		}
	}
}

Measured memory_bytes: 41496
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int h,w;
  string s;
  cin >> h >> w;
  REP1(i,h){
    REP(j,w){
      cin >> s;
      if(s=="snuke"){
        cout << ALP[j] << i;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m;
    cin >> n >> m;
    if(n <= m){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

}

Measured memory_bytes: 3592
N=int(input())

import math
from itertools import permutations

town=[i+1 for i in range(N)]

roots = list(permutations(town))

# print(*roots,sep="\n")

info = []

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

total = 0 

for road in roots:
    for j in range(len(road)):
        if j==0:
            continue
        to = road[j]
        fr = road[j-1]

        total += math.sqrt( (info[to-1][0]-info[fr-1][0])**2 + (info[to-1][1] - info[fr-1][1])**2 )

print(total/math.factorial(N))


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

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

const int mod = 1e9 + 7;
int dp[100005][2];

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  
  dp[0][0] = 1;
  rep(i, n) {
    { // a+b = 0
      if (s[i] == '0') {
	dp[i+1][0] = dp[i][0];
	dp[i+1][1] = dp[i][1];
      } else {
	dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
      }
    }
    { // a+b = 1
      if (s[i] == '0') {
	(dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      } else {
	(dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
	(dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      }
    }
  }
  int ans = (dp[n][0] + dp[n][1]) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1280
number=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
M=[]
for i in range(H):
    tmp=list(input())
    M.append(tmp)
answer=0
for rowmask in range(1<<W):
    for cowmask in range(1<<H):
        count=0
        for x in range(H):
            for y in range(W):
                if (rowmask>>y)&1==0 and (cowmask>>x)&1==0 and M[x][y]=="#":
                    count+=1
        if count==K:
            answer+=1
print(answer)

Measured memory_bytes: 9144
#include<iostream>
#include<string>
#include<algorithm>
#include <map>  

using namespace std;


int h, w, S[51][51] = {};

void change(int i, int j) {
	if (i >= 0 && j >= 0 && i <= w && j <= h) {
		S[i][j]++;
	}
}

int main()
{

	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			char c = s[j];
			if (c == '#') {
				S[j][i] = -100;
				for (int k = -1; k < 2; k++) {
					for (int l = -1; l < 2; l++) {
						if(k != 0 || l != 0)
							change(j + k, i + l);
					}
				}
			}
		}
	}


	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int t = S[j][i];
			if (t >= 0)
				cout << t;
			else
				cout << '#';
		}
		cout << endl;
	}
	

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    sort(v.begin(),v.end());
    vector<int>dp(k+1,0);
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(v[j]>i)
                break;
            int t=i-v[j];
            if(dp[t]==0)
            {
                dp[i]=1;
                break;
            }
        }
    }
    if(dp[k]==1)
        cout << "First" << endl;
    else
        cout << "Second" << endl;
}

Measured memory_bytes: 640
import sys
#N枚のお金N，合計金額Y
N, Y = map(int, input().split())

"""
a = 0 #1000円札の枚数
b = 0 #5000円札の枚数
c = 0 #10000円札の枚数

X = 0 #合計金額
"""

for a in range(N+1):
    for b in range(N-a+1):

        if 10000*a + 5000*b + 1000*(N-a-b) == Y:
            print(a, b, N-a-b)
            sys.exit()


print("-1 -1 -1")

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

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

    int cnt = 0;
    for (int i = A; i <= B; i++)
    {
        if (i % 10 == i / 10000 && (i % 100) / 10 == (i / 1000) % 10)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}


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

    cin>>n;
    ll d1[n+1]={0};
    ll d2[n+1]={0};
    ll t,a;cin>>t>>a;
    for(ll i=1;i<n;i++)
    {
        ll a1,b;cin>>a1>>b;
        v[a1].push_back(b);
        v[b].push_back(a1);
    }

//    for(ll j=1;j<=n;j++)
//    {
//        cout<<j<<" : ";
//        for(ll i=0;i<v[j].size();i++)
//            cout<<v[j][i]<<" ";
//        cout<<endl;
//    }

    dfs(t,d1);
    memset(vis,0,sizeof(vis));
    dfs(a,d2);
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(d1[i]<d2[i])ans=max(ans,d2[i]);
    }
    cout<<ans-1<<endl;
}


Measured memory_bytes: 12032
import java.util.Scanner;

public class  Main{
	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);
			int a = src.nextInt();
			int b = src.nextInt();
			int c = src.nextInt();

			if((a <= b) && (b <= c)) {
				System.out.println(String.format("%d %d %d",a ,b ,c));
			}else if((a <= c) && (c <= b)) {
				System.out.println(String.format("%d %d %d",a ,c ,b));
			}else if((b <= a) && (a <= c)) {
				System.out.println(String.format("%d %d %d",b ,a ,c));
			}else if((b <= c) && (c <= a)) {
				System.out.println(String.format("%d %d %d",b ,c ,a));
			}else if((c <= b) && (b <= a)) {
				System.out.println(String.format("%d %d %d",c ,b ,a));
			}else if((c <= a) && (a <= b)) {
				System.out.println(String.format("%d %d %d",c ,a ,b));
	}
	}
}



Measured memory_bytes: 26432
let () =
    let main () =
        let n = int_of_string (read_line ()) in
        let zeros = if n mod 2 = 1 then 0 else (
            let rec loop i t acc =
                if i > n then acc else
                    loop (i * 5) (t + 0) (acc + t * (n / i))
            in
            loop 10 1 0
        )
        in
        Printf.printf "%d\n" zeros
    in
    main ()

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int a[2][3][2];    // (x/y)(-/0/+)(min/max)

double calc( double t )
{
    double range[2][2]={{a[0][1][0], a[0][1][1]}, {a[1][1][0], a[1][1][1]}};

    range[0][0]=MIN(range[0][0],(a[0][0][0]-t));
    range[0][0]=MIN(range[0][0],(a[0][2][0]+t));
    range[0][1]=MAX(range[0][1],(a[0][0][1]-t));
    range[0][1]=MAX(range[0][1],(a[0][2][1]+t));
    range[1][0]=MIN(range[1][0],(a[1][0][0]-t));
    range[1][0]=MIN(range[1][0],(a[1][2][0]+t));
    range[1][1]=MAX(range[1][1],(a[1][0][1]-t));
    range[1][1]=MAX(range[1][1],(a[1][2][1]+t));

    return (range[0][1]-range[0][0])*(range[1][1]-range[1][0]);
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    int i,j,k;
    for(i=0; i<2; i++) {
        for(j=0; j<3; j++) {
            a[i][j][0]=INF;  a[i][j][1]=-INF;
        }
    }

    for(i=0; i<n; i++) {
        int x,y;
        char str[3]={0};
        scanf("%d%d%s", &x, &y, str);
        if(str[0]=='R') {
            a[0][2][0]=MIN(a[0][2][0], x);
            a[0][2][1]=MAX(a[0][2][1], x);
            a[1][1][0]=MIN(a[1][1][0], y);
            a[1][1][1]=MAX(a[1][1][1], y);
        }
        else if(str[0]=='L') {
            a[0][0][0]=MIN(a[0][0][0], x);
            a[0][0][1]=MAX(a[0][0][1], x);
            a[1][1][0]=MIN(a[1][1][0], y);
            a[1][1][1]=MAX(a[1][1][1], y);
        }
        else if(str[0]=='U') {
            a[0][1][0]=MIN(a[0][1][0], x);
            a[0][1][1]=MAX(a[0][1][1], x);
            a[1][2][0]=MIN(a[1][2][0], y);
            a[1][2][1]=MAX(a[1][2][1], y);
        }
        else {
            a[0][1][0]=MIN(a[0][1][0], x);
            a[0][1][1]=MAX(a[0][1][1], x);
            a[1][0][0]=MIN(a[1][0][0], y);
            a[1][0][1]=MAX(a[1][0][1], y);
        }
    }

    double ans = (double)INF * (double)INF;

    vector<double> v;
    v.push_back(0);
    for(i=0; i<2; i++) {
        for(j=0; j<2; j++) {
            for(k=0; k<2; k++) {
                if(abs(a[i][1][j])!=INF && abs(a[i][2][k])!=INF) v.push_back( (double)a[i][1][j] - a[i][2][k]);
                if(abs(a[i][0][j])!=INF && abs(a[i][1][k])!=INF) v.push_back( (double)a[i][0][j] - a[i][1][k]);
                if(abs(a[i][0][j])!=INF && abs(a[i][2][k])!=INF) v.push_back( ((double)a[i][0][j] - a[i][2][k])/2.0);
            }
        }
    }

    double eps=1.0e-12;
    for(i=0; i<(int)v.size(); i++) {
        if(v[i]>=-eps) {
            double val = calc( v[i] );
            ans = MIN(ans, val);
        }
    }
    printf("%.10lf\n", ans);

    return 0;
}


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

using namespace std;

int main() {
  long long x;
  cin >> x;
  long long ans = (x / 11) * 2;
  x = x % 11;
  if (x == 0) {
    ans += 0;
  } else if (x % 11 <= 6) {
    ans++;
  } else {
    ans += 2;
  }
  cout << ans << endl;
  return 0;
}



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


int main(int argc, const char *argv[])
{
    int N;
    std::string S;
    int K;
    std::cin >> N >> S >> K;

    char c = S[K - 1];
    for (int i = 0; i < N; i++) if (S[i] != c) S[i] = '*';

    std::cout << S << std::endl;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=1000000007;
const int inf=0x7fffffff;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
using namespace std;
ll gcd(ll a,ll b) {return b==0? a: gcd(b,a%b);}
int main()
{
    ll a,b;
    while(cin>>a>>b){
        cout<<gcd(a,b)<<" "<<a/gcd(a,b)*b<<endl;
    }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
ll n,m,k,x,y;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION(10) ;
    ll a,b,c,d,i,j,t;//,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU  +  Graph Theory + Math + DP + Bitmasks + Geometry + Brute Force + Implementation + Binary Search
    cin>>n>>m;
    vvl v(n+1);
    vll ele(n+1);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        ele[i+1] = a;
    }
    for(i=0  ;i<m ; i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    x = 0;
    for(i=1 ; i<n+1 ; i++)
    {
        ok = true;
        for(auto j : v[i])
        {
            if(ele[i]<=ele[j])
            {
                ok = false;
                break;
            }
        }
        x+=ok;
    }
    cout<<x;
}

Measured memory_bytes: 9824
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define X first
#define Y second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 2e3 + 100;

int main() {
    int a, b;
    cin >> a >> b;
    if(a % b == 0) puts("-1");
    else cout << a << endl;
}


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

int main() {
    int n;
    cin>>n;
    int a[n];
    int prod= 0;
    rep(i,n){
        cin>>a[i];
        prod^=a[i];
    }
    rep(i,n){
        printf("%d ",prod^a[i]);
    }
}


Measured memory_bytes: 4328
//https://qiita.com/drken/items/56a6b68edef8fc605821#%E5%95%8F%E9%A1%8C-3-atcoder-abc-122-c---get-ac
//参考にさせて頂いている記事
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

int main(){
    ll N,ANS=0;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    vector<ll> D(N+1,0);
    map<ll,int> nums;
    for(ll i=0;i<N;i++){
        D[i+1]=D[i]+A[i];
    }
    for(int i=0;i<N+1;i++)nums[D[i]]++;

    //愚直にやるとTLEになるので、累積和の中からイコールとなるものを数え上げ、その組みが何通りあるかを数える。
    for(auto x:nums){
        ll n=x.second;
        ANS+=(n*(n-1))/2;
    }
    cout<<ANS<<endl;
    return 0;
}

//a=97,z=122


Measured memory_bytes: 15872
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d", &a,&b,&c);
    if(a==b || b==c ||a==c)
    {
        if(a==b && b==c)
        {
            printf("No");
        }
        else
        {
            printf("Yes");
        }
    }
    else
    printf("No");
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N); int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    vec.at(i) = x;
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sum_all = 0, sum_first = 0;
  
  for (int i = 0; i < N; i++)
    sum_all += vec.at(i);
  
  for (int i = 0; i < N; i += 2)
    sum_first += vec.at(i);
  
  int print;
  print = 2 * sum_first - sum_all;
  cout << print << endl;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())
if B - A <= 2 or K <= A:
    print(K + 1)
else:
    K -= A + 1
    if K % 2:
        print(B + (B - A) * ((K - 1) // 2) + 1)
    else:
        print(B + (B - A) * (K // 2))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

    int A, B, C;

    cin >> A >> B >> C;

    cout << A * B / 2 << endl;


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from itertools import combinations

def main():
  N = int(input())
  l = list(sorted(map(int,input().split())))
  combi = combinations(l,3)
  def judge(c):
    return c[0] < c[1] < c[2] and c[0] + c[1] > c[2]
  print(sum(judge(c) for c in combi))
  return

main()


Measured memory_bytes: 9060
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c, s, f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t += F[j] - (t % F[j])
        t += C[j]
    print(t)


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    char a[1000];
    int i,sum;
    while(1)
    {
        scanf("%s",&a);
        if(a[0]=='0')
        {
            return 0;
        }
        sum = 0;
        for(i=0;a[i]!='\0';i++)
        {
            sum+=a[i]-'0';
        }
        printf("%d\n",sum);
}
return 0;
    }



Measured memory_bytes: 2120
N, M = map(int, input().split())
KA = [list(map(int, input().split())) for i in range(N)]
cnt = [0]*M

for i in range(N):
    for j in range(1, KA[i][0]+1):
        cnt[KA[i][j]-1]+=1

ans = 0

for i in range(M):
    if cnt[i] == N:
        ans+=1
print(ans)

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    int ans = INF;
    for (int t=0; t<=100; t++) {
        int tmp = 0;
        bool ok = true;

        rep(i, 3) {
            if (A[i] > t) tmp += A[i] - t;
            else if (A[i] < t) {
                if ((t - A[i]) % 2 != 0) {
                    ok = false;
                    break;
                } 
                tmp += (t - A[i])/2;
            }
        }

        if (ok) ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

// #LIB#

using namespace std;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll n;
  cin >> n;
  vector<ll> w(n);
  rep(i, n) cin >> w[i];
  vector<ll> ws(n + 1);
  rep(i, n) ws[i + 1] = ws[i] + w[i];
  ll ans = LLONG_MAX;
  repr(i, 1, n) updatemin(ans, abs(ws[i] - (ws[n] - ws[i])));
  cout << ans << endl;
}


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


int main()
{

	int n,m;cin>>n>>m;

	if(m == 1){
		cout<<0<<"\n";
		return 0;
	}

	int st = n;
	int tot = n;
	int ans = 1;
	while(tot < m)
	{
		st-=1;
		if(st == 0)
			st = n;

		tot-=1;
		tot+=n;
		ans++;
	}


	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 384
/*
  kadai3_4 81
  unomi
*/
#include <stdio.h>

int main(void){
  int N=0, i=0, j=0;

  // N の入力を取得
  scanf("%d",&N);

  for(i=1;i<10;i++){
    for(j=1;j<10;j++){
      if(i*j == N){
        puts("Yes");
        return 0;
      }
    } 
  }
  puts("No");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) 
#define X first
#define Y second 
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a) 
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f;
ll a[N], sum[N]; 


int main()
{
	IOS;
	ll n, ans = 0;
	cin>>n;
	rep1(i, n)
	{
		cin>>a[i];
		sum[i] = (sum[i-1] + a[i])%mod;
	}
	rep1(i, n-1)
	{
		ans = (ans + (sum[n]-sum[i]+mod)%mod*a[i])%mod;
	}
	cout<<ans<<nl;
	
	AC;
} 

Measured memory_bytes: 6772
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
	int a, b;
	cin >> a; cin >> b;
	if (a*b % 2 == 1) {
		cout << "Odd" << endl;
	}
	else {
		cout << "Even" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int h, n;
    cin >> h >> n;
    vint a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    const int MAX = 20005;
    vll dp(MAX, LINF);
    dp[0] = 0;
    rep(i, h+1) {
        rep(j, n) {
            dp[i+a[j]] = min(dp[i]+b[j], dp[i+a[j]]);
        }
    }
    ll ans = LINF;
    srep(i, h, MAX) ans = min(ans, dp[i]);

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

Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

sx, sy, tx, ty = MAP()

for i in range(ty-sy):
	print("U", end="")
for i in range(tx-sx):
	print("R", end="")
for i in range(ty-sy):
	print("D", end="")
for i in range(tx-sx):
	print("L", end="")

print("L", end="")
for i in range(ty-sy+1):
	print("U", end="")
for i in range(tx-sx+1):
	print("R", end="")
print("D", end="")

print("R", end="")
for i in range(ty-sy+1):
	print("D", end="")
for i in range(tx-sx+1):
	print("L", end="")
print("U", end="")
print()

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

using namespace std;

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

	ans = s[0];

	int size = s.size() - 2;
	ans += to_string(size);


	ans += s[s.size()-1];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
	
  int a,b,c;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if(a+b+c == 17 && a % 5==0 && b % 5==0){
  printf("YES\n");
  } else if(a+b+c == 17 && a % 5==0 && c % 5==0){
  printf("YES\n");
  } else if(a+b+c == 17 && b % 5==0 && c % 5==0){
  printf("YES\n");
  } else {
  printf("NO\n");
  }
  return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
    string N; cin >> N; 
    
    sort(N.begin(), N.end());

    cout << ((N[0] == N[1] && N[1] == N[2]) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define INF 2140000000
#define min(x,y) ((x)<=(y)?(x):(y))

int n;

int matrixchainmultiplication(int *a){
  int i,j,k,l,m[N+1][N+1];

  for(i=1;i<=n;i++) m[i][i]=0;
  for(i=2;i<=n;i++){
    for(j=1;j<=n-i+1;j++){
      k=j+i-1;
      m[j][k]=INF;
      for(l=j;l<=k-1;l++){
	m[j][k]=min(m[j][k],m[j][l]+m[l+1][k]+a[j-1]*a[l]*a[k]);
      }
    }
  }
      return m[1][n];
}

int main(){
  int a[N+1],i;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d%d",&a[i],&a[i+1]);
  
  printf("%d\n",matrixchainmultiplication(a));
  
    return 0;
}




Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int count = 0, ans;
  for(int i = 0; i < S.size(); i++){
    if(i % 2 == 0){
      if(S.at(i) != '0')count++;
    } else {
      if(S.at(i) != '1')count++;
    }
  }
  ans = count;
  count = 0;
  for(int i = 0; i < S.size(); i++){
    if(i % 2 == 0){
      if(S.at(i) != '1')count++;
    } else {
      if(S.at(i) != '0')count++;
    }
  }
  ans = min(ans, count);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
def gcd(a, b):
  if a < b:
    a, b = b, a
  r = a % b
  if r == 0:
    return b
  return gcd(r, b)

def gcd3(a, b , c):
  return gcd(gcd(a, b), c)

K = int(input())

ans = 0
for i in range(1, K + 1):
  for j in range(i, K + 1):
    for k in range(j, K + 1):
      if i == j and j == k:
        ans += i
      elif i == j:
        ans += gcd(i, k) * 3
      elif j == k:
        ans += gcd(i, j) * 3
      else:
        ans += gcd3(i, j, k) * 6
print(ans)

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

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

const long long INF = 1LL << 40;

int main() {
  int num;
  
  cin >> num;
  
  long long dp[num];
  long long h[num];
  
  for(int i = 0; i < num; i++){
    cin >> h[i];
    dp[i] = INF;
  }
  
  dp[0] = 0;
  
  for(int i = 1; i < num; i++){
    ChkMin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if(i > 1) ChkMin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));           
  }
  
  cout << dp[num-1];
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pt;

#define fi first
#define se second
#define lson (p<<1)+1
#define rson (p<<1)+2
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll n, x, need;

int main () {
    fastIO;
    cin >> n;
    need = 1;
    for(li i = 0; i < n; i ++) {
        cin >> x;
        if(x == need) need ++;
    }
    if(need == 1) cout << -1;
    else cout << n - need + 1;
}


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

long  N,M,X;
long X,C[20],A[20][20];
long min=10010000;

int main(){
	scanf("%ld%ld%ld",&N,&M,&X);
	int i,j;
	long dd=0;
	for(i=0;i<N;i++){
		scanf("%ld",C+i);
		for(j=0;j<M;j++){
			scanf("%ld",&A[i][j]);
		}
	}
		
	for (int bit = 0; bit < (1<<N); ++bit) {
		long sum=0;
		long tmp[20];
		for(i=0;i<N;i++){
			tmp[i]=0;
		}
		for ( i = 0; i < N; ++i) {
			if (bit & (1 << i)) {
				sum += C[i];
				for(j=0;j<M;j++)tmp[j]+=A[i][j];
			}
        }
		int flag=1;
		for(i=0;i<M;i++){
			if(tmp[i]<X)flag=0;
		}
		if(flag){
			if(min>sum)min=sum;
		}
    }
	if(min==10010000)printf("-1\n");
	else	printf("%ld",min);
	return 0;
}


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

int H, W;
vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main() {
    
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];


    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Left[i][j] = cur;
        }
    }
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = W-1; j >= 0; --j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Right[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = 0; i < H; ++i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Up[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = H-1; i >= 0; --i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Down[i][j] = cur;
        }
    }
    
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') continue;
            res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 72448
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,a,b,c;
int dp[100005][3];
int main(){
cin>>n;
for(int i=1;n>=i;i++)
{
	for(int j=0;3>j;j++)
	{
		int a;
		cin>>a;
		for(int g=0;3>g;g++)
			if(g!=j)
				dp[i][j]=max(dp[i][j],dp[i-1][g]+a);
	}
}
int out=0;
for(int i=0;3>i;i++)
	out=max(out,dp[n][i]);
cout<<out;
return 0;
}


Measured memory_bytes: 1408