akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define mod 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string S;

    cin >> S;

    ll ans=0, num=0;

    for(ll i=0; i<3; i++){
        if(S[i]=='R') num++;
        else{
            chmax(ans,num);
            num = 0;
        }
    }

    chmax(ans,num);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 1400

int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare(int H, int W) {
  int maxWidth = 0;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      dp[i][j] = (G[i][j] + 1) % 2;
      maxWidth |= dp[i][j];
    }
  }
  
  for ( int i = 1; i < H; i++ ) {
    for ( int j = 1; j < W; j++ ) {
      if ( G[i][j] ) {
	dp[i][j] = 0;
      } else {
	dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
	maxWidth = max(maxWidth, dp[i][j]);
      }
    }
  }
  
  return maxWidth * maxWidth;
}

int main(void) {
  int H, W;
  scanf("%d %d", &H, &W);
  
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) scanf("%d", &G[i][j]);
  }
  
  printf("%d\n", getLargestSquare(H, W));
  
  return 0;
}

Measured memory_bytes: 16340
#include <iostream>

using namespace std;

int main() {
    int w, a, b;

    cin >> w >> a >> b;

    if (a > b) {
        int temp = a;
        a = b;
        b = temp;
    }

    int ans = (b - (a + w) >= 0) ? (b - (a + w)) : 0;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  vector<vector<ll>> F(N, vector<ll>(10));
  vector<vector<ll>> P(N, vector<ll>(11));

  rep(i, N) {
    rep(j, 10) {
      ll f;
      cin >> f;
      F[i][j] = f;
    }
  }

  rep(i, N) {
    rep(j, 11) {
      ll p;
      cin >> p;
      P[i][j] = p;
    }
  }

  ll ans = -INF;
  rep(bits, 2 << 9) {
    if (bits == 0) {
      continue;
    }
    ll sum = 0;
    rep(i, N) {
      ll c = 0;
      rep(j, 10) {
        if (bits >> j & 1 && F[i][j] == 1) {
          c++;
        }
      }
      sum += P[i][c];
    }
    ans = max(ans, sum);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		
		int circle=input.nextInt();
		for(int i=0;i<circle;i++){
/*			String[] str=input.nextLine().split(" ");*/
			double[] num=new double[6];
			for(int j=0;j<num.length;j++){
				num[j]=input.nextDouble();
				/*System.out.println(+" "+num[i]);*/
			}
			/*System.out.println(num[5]);*/
			double a1=2*(num[2]-num[0]);		
			double b1=2*(num[3]-num[1]);
			double c1=num[2]*num[2]+num[3]*num[3]-num[0]*num[0]-num[1]*num[1];
			double a2=2*(num[4]-num[2]);
			double b2=2*(num[5]-num[3]);
			double c2=num[4]*num[4]+num[5]*num[5]-num[2]*num[2]-num[3]*num[3];
			/*System.out.println(a1+" "+b1+" "+c1+" "+a2+" "+b2+" "+c2);*/
			double x=(c1*b2-c2*b1)/(a1*b2-a2*b1);
			double y=(a1*c2-a2*c1)/(a1*b2-a2*b1);
			
			double r=Math.sqrt((num[0]-x)*(num[0]-x)+(num[1]-y)*(num[1]-y));
			System.out.printf("%.3f %.3f %.3f\n",x,y,r);
			
		}
	}

}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

class union_find{
	private:
	vector<int> parent,rank,gs;
    int size;
	public:
    int count_group;
    union_find()=default;
    union_find(int n){ init(n); }

    void init(int n){
		size=n;
		count_group=n;
		parent.resize(size);
		rank.assign(size,0);
        gs.assign(size,1);
		for(int i=0; i<size; ++i) parent[i]=i;
	}

	int find(int x){
		if(parent[x]==x) return x;
		else return parent[x]=find(parent[x]);
	}

	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			parent[x]=y;
            gs[y]+=gs[x];
		} else {
			parent[y]=x;
            gs[x]+=gs[y];
			if(rank[x]==rank[y]) ++rank[x];
		}
		--count_group;
	}

	bool is_same_group(int x,int y){
		return find(x)==find(y);
	}

    int group_size(int x){
        return gs[find(x)];
    };
};

void solve(){
    typedef tuple<double,int,int> tup;
    int n,m;
    cin >> n >> m;
    vector<complex<double>> ps;
    vector<tup> edges;
    rep(i,0,n){
        int x,y;
        cin >> x >> y;
        ps.push_back(complex<double>(x,y));
    }
    double ans=0;
    rep(i,0,m){
        int p,q;
        cin >> p >> q;
        --p;
        --q;
        ans+=abs(ps[p]-ps[q]);
        edges.push_back(make_tuple(abs(ps[p]-ps[q]),p,q));
    }
    sort(edges.rbegin(),edges.rend());
    union_find uf(n);
    for(const auto &edge:edges){
        int p,q;
        double d;
        tie(d,p,q)=edge;
        if(uf.is_same_group(p,q)) continue;
        uf.unite(p,q);
        ans-=d;
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3672
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nm = Input.ar;
        if (nm[0] <= 5) { WriteLine(0); }
        else if (nm[0] <= 12) { WriteLine(nm[1] / 2); }
        else WriteLine(nm[1]);
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
#define sqr(x) ((x)*(x))
#define pb push_back 
const int N=1000002,M=998244353;
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%M)if(y&1)z=1ll*z*x%M;return z;}
void inc(int &x,int y){x+=y;if(x>=M)x-=M;}void dec(int &x,int y){x-=y;if(x<0)x+=M;}
void Max(int &x,int y){if(y>x)x=y;}void Min(int &x,int y){if(y<x)x=y;}
//struct node{int to,ne;}e[];
//void add(int x,int y){e[++tot]=(node){y,h[x]},h[x]=tot;}
int a;
char s[100];
signed main(){
	scanf("%d%s",&a,s);
	if (a>=3200) printf("%s",s);
	else puts("red");
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author JustLive
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int mod = 1000000007;
const int inf = 1000000000;
const ll infll = (ll)inf * (ll)inf;

class TaskA {
public:
    void solve(istream& in, ostream& out) {
        int n, a, b;
        in >> n >> a >> b;
        if (abs(a - b) % 2 == 0) {
            out << "Alice";
        } else {
            out << "Borys";
        }
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    TaskA solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

queue<string> que;

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

    int cnt_lum = 0;
    string ans;
    
    if (K<=9) ans = to_string(K);
    else {
        que.push("1"), que.push("2"), que.push("3"), que.push("4"), que.push("5");
        que.push("6"), que.push("7"), que.push("8"), que.push("9");
        cnt_lum += 9;

        while (cnt_lum < K) {
            string lum = que.front();
            que.pop();
            char bottom_ch = lum[lum.length() - 1];
            string next_m = to_string(bottom_ch-'0' - 1);
            string next_0 = to_string(bottom_ch-'0');
            string next_p = to_string(bottom_ch-'0' + 1);

            if (bottom_ch!='0') {
                que.push(lum + next_m);
                cnt_lum++;
                if (cnt_lum==K) ans = lum + next_m;
            }
            que.push(lum + next_0);
            cnt_lum++;
            if (cnt_lum==K) ans = lum + next_0;
            if (bottom_ch!='9') {
                que.push(lum + next_p);
                cnt_lum++;
                if (cnt_lum==K) ans = lum + next_p;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

int gcd(int a, int b){return (a % b)? gcd(b, a % b) : b;}
int lcm(int a, int b){return a * b / gcd(a, b);}

using Graph = vector< vector<int> >;

void solve_C(){
    int n, m;
    cin >> n >> m;

    int h[n];
    REP(i,n) cin >> h[i];

    Graph G(n);
    REP(i,m){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    
    ll ans = 0;
    for(int i = 0; i < n; i++){
        bool flag = true;
        int height = h[i];
        for(auto next : G[i]){
            if(height <= h[next]){
                flag = false;
            }
        }
        if(flag) ans++;
    }

    cout << ans << endl;
}

int main(void){
    solve_C();
    
    return 0;
}

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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        double n = in.nextInt();
        double m = in.nextInt();
        double d = in.nextInt();

        double x = d == 0 ? 1 / n : (2 * n - 2 * Math.min(n, d)) / (n * n);
        // out.println(x);
        out.printf("%.8f\n", (m - 1) * x);
    }

    private static double pow(double x, int pow) {
        double ans = 1;
        while (pow > 0) {
            if (pow % 2 == 1) {
                ans *= x;
            }
            x *= x;
            pow /= 2;
        }
        return ans;
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll n,i;
    cin>>n;
    ll a[n];
    map<ll,ll> f;
    for (i=0;i<n;i++)
    {
        cin>>a[i];
        f[a[i]]++;
    }
    ll ans=0,tp;
    for (auto e: f)
        ans+=((e.ss*(e.ss-1))/2);
    for (i=0;i<n;i++)
    {
        tp=ans;
        tp-=((f[a[i]]*(f[a[i]]-1))/2);
        tp+=(((f[a[i]]-1)*(f[a[i]]-2))/2);
        cout<<tp<<endl;
    }
}

Measured memory_bytes: 12248
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()

int aabs(double x){
	if(x<0) return x*=-1;
	else return x;

}
int main(){
	int n;
	int data1[150];
	int data2[150];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> data1[i];
	}
	for(int i=0;i<n;i++){
		cin >> data2[i];
	}
	double tmp = 0;
	for(int i=0;i<n;i++){
		tmp += aabs(data1[i]-data2[i]);
	}
	cout << fixed << setprecision(5) << tmp << endl;

	tmp = 0;
	for(int i=0;i<n;i++){
		tmp += ((data1[i]-data2[i])*(data1[i]-data2[i]));
	}
	cout << setprecision(5) << sqrt(tmp) << endl;

	tmp = 0;
	for(int i=0;i<n;i++){
		double t = aabs(data1[i]-data2[i]);
		tmp += t*t*t;
	}
	cout << setprecision(5) << cbrt(tmp) << endl;
	tmp = 0;
	for(int i=0;i<n;i++){
		if(tmp<aabs(data1[i]-data2[i])){
			tmp = aabs(data1[i]-data2[i]);
		}
	}
	cout << setprecision(5) << tmp << endl;
	return 0;

}

Measured memory_bytes: 1256
import Control.Monad
import Data.List

solve = foldl' f (0, 0)
  where
    f (n, c) [a, b] = if a < n then (n, c) else (b, succ $! c)

readN = map read . words <$> getLine

main = do
  [n, m] <- readN
  rs <- replicateM m readN
  print $ snd . solve . sortOn last $ rs


Measured memory_bytes: 94588
#include <bits/stdc++.h>
using namespace std;
char a[200100];
int main(){
    int N, s=0, cnt;
    scanf("%s", a);
    N = strlen(a);
    cnt = N;
    for(int i=0; i<N; i++){
        if(a[i] == 'S'){
            s++;
        }else{
            if(s){
                s--;
                cnt-=2;
            }
        }
    }
    printf("%d", cnt);
}


Measured memory_bytes: 384
s=[]
p=[]
a=i=0
for c in input():
     if"\\"==c:
         s+=[i]
     elif"/"==c and s:
         j=s.pop()
         t=i-j
         a+=t
         while p and p[-1][0]>j:
             t+=p[-1][1];
             p.pop()
         p+=[(j,t)]
     i+=1
print(a)
if p:
    print(len(p),*list(zip(*p))[1])
else:
    print(0)


Measured memory_bytes: 6496
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_size(long long X){
  int ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  int N;
  cin>>N;
  
  vector<long long> T(N);
  for(int i=0;i<N;i++){
    cin>>T[i];
  }
  
  long long ans=1;
  
  for(int i=0;i<N;i++){
    ans=LCM(ans,T[i]);
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
n,a,b = [int(i) for i in input().split()]

s = input()
ct = 0
bct = 0

for i in s:
    if i == 'a':
        if ct < (a+b):
            print('Yes')
            ct += 1
        else:
            print('No')
    elif i == 'b':
        if ct < (a+b) and bct < b:
            print('Yes')
            ct += 1
            bct += 1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 4016
N = int(input())
An = list(map(int, input().split()))

ans = "APPROVED"
for i in range(N):
    if An[i] % 2 != 0:
        continue

    if An[i] % 3 == 0 or An[i] % 5 == 0:
        continue

    ans = "DENIED"

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N,K;
  cin>>N>>K;
  vector<int>A(N);
  REP(i,N)cin>>A[i];

  ll ans=0ll;
  REP(i,N){
    REP(j,i){
      if(A[j]>A[i])ans++;
    }
  }
  ans%=MOD;
  ans*=K;
  ans%=MOD;

  sort(ALL(A));
  ll cnt=0ll;
  REP(i,N){
    REP(j,i){
      if(A[j]<A[i])cnt++;
    }
  }
  ans+=cnt*((K*(K-1)/2ll)%MOD)%MOD;
  ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def baisu(x,a):
    return int(x//a)
a,b,c,d = map(int,input().split())

to_a = a-1 - baisu(a-1,c) - baisu(a-1,d) + baisu(a-1,int(c*d/gcd(c,d)))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,int(c*d/gcd(c,d)))

print(to_b - to_a)



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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  rep(i, n) {
    int x; cin >> x;
    if(x % 2 == 0) {
      if(x % 5 && x % 3) {
	cout << "DENIED"; return 0;
      }
    }
  } cout << "APPROVED";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,i,j;
	int a,b,data[100001];
	int min,ban;
	while(1){
		for(i=1;i<=100000;i++) data[i]=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++){
			cin>>b;
			for(j=0;j<8;j++){
				cin>>a;
				if(j%2==0) data[b]+=a*60;
				else data[b]+=a;
			}
		}
		for(i=0;i<2;i++){
			min=100000000;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min>data[j]) {
					ban=j;
					min=data[j];
				}
			}
			cout<<ban<<endl;
			data[ban]=0;
		}
		for(i=0;i<2;i++){
			min=0;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min<data[j]) {
					ban=j;
					min=data[j];
				}
			}
			data[ban]=0;
		}
		cout<<ban<<endl;
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;
/*
方針
X -> Z
Y -> W

a[N-2]
a[N-1]

Xが取れるパターン
X       Y
a[N-2]  a[N-1]
a[N-1]  W
*/
int main(){
  long long N, Z, W;
  cin >> N >> Z >> W;
  long long a[N];
  rep(i,N) cin >> a[i];
  long long maxScore ;
  if(N > 1) maxScore = max( abs(W - a[N-1]) , abs(a[N-1] - a[N-2]) );
  else      maxScore = abs(W - a[N-1]);
  cout << maxScore << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2*1e5;
const int mod = 1e9+7;

int main() {
    int a, b, c; cin >> a >> b >> c;
    int x = (a-c) % b;
    int y = a % b;
    bool ok = false;
    for (int n = 0; n <= b; n++) {
        if ((x+n*y)%b == 0) ok = true;
    }
    printf(ok?"YES\n":"NO\n");
}

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


Measured memory_bytes: 256
function main()

    comp(a, b) = a[1] < b[1]

    comp2(a, b) = a[2] > b[2]

    n = parse(Int, readline())
    d = []
    for i in 1:n
        input = split(readline())
        s = input[1]
        p = parse(Int, input[2])
        push!(d, (s, p, i))
    end

    sort!(d, lt=comp2)
    sort!(d, lt=comp)

    for i in d
        println(i[3])
    end

end

main()

Measured memory_bytes: 113032
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A, B, C = MI()
    print(A + B + C - max((A, B, C)))
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll n;
	cin >> n;
	vector<ll> x(n),y(n),p;
	FOR(i,0,n)cin>>x[i]>>y[i];
	FOR(i,0,n)p.push_back(i);

	double ans = 0;
	int cnt = 0;
	do{
		double len = 0;
		FOR(i,0,n-1){
			len += sqrt((x[p[i]]-x[p[i+1]])*(x[p[i]]-x[p[i+1]])+(y[p[i]]-y[p[i+1]])*(y[p[i]]-y[p[i+1]]));
		}
		cnt++;
		ans += len;
	}while(NEXTP(p));
	ans /= cnt;
	out(20) << ans << endl;
}

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

int main() {
	int n, m, x, y, ans, minp;
	int a[50], b[50], c[50], d[50], point[50];
	cin >> n >> m;
	for (int i = 0;i < n;++i)cin >> a[i] >> b[i];
	for (int i = 0;i < m;++i)cin >> c[i] >> d[i];
	for (int i = 0;i < n;++i) {
		for (int j = 0;j < m;++j) {
			x = a[i] - c[j];
			if (x < 0)x = -x;
			y = b[i] - d[j];
			if (y < 0)y = -y;
			if (j == 0) { 
				minp = x + y;
				ans = 1; 
			}
			if (minp > x + y) {
				minp = x + y;
				ans = j + 1;
			}
		}point[i] = ans;
	}
	for (int i = 0;i < n;++i)cout << point[i] << endl;
	return 0;
}

Measured memory_bytes: 256
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    n, x, t = map(int, input().split())
    times = (n+x-1) // x
    return times * t


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9076
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int>box(n),x(m),y(m);
    vector<bool>can_exist(n);
    can_exist[0]=true;
    REP(i,n)box[i]=1;
    REP(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    REP(i,m){
        box[x[i]]--;
        box[y[i]]++;
        if(can_exist[x[i]])can_exist[y[i]]=true;
        if(box[x[i]]==0)can_exist[x[i]]=false;
    }

    int answer=0;
    REP(i,n){
        if(box[i]!=0 && can_exist[i])answer++;
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int h, w;
vector<string> field;
vector<vector<int>> dist;
int black_cnt = 0;

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

int main() {
  cin >> h >> w;
  field.assign(h, "");
  dist.assign(h, vector<int>(w, -1));
  for (int i = 0; i < h; ++i) {
    cin >> field[i];
  }
  pair<int, int> stt = make_pair(0, 0);
  pair<int, int> goal = make_pair(h, w);
  queue<pair<int, int>> que;
  que.push(stt);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (field[i][j] == '#') black_cnt += 1;
    }
  }
  dist[0][0] = 0;

  while (!que.empty()) {
    pair<int, int> crnt_pos = que.front();
    int y = crnt_pos.first;
    int x = crnt_pos.second;
    que.pop();
    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if (field[ny][nx] == '#') continue;
      if (dist[ny][nx] != -1) continue;
      dist[ny][nx] = dist[y][x] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  int result = w * h - dist[h - 1][w - 1] - black_cnt - 1;
  if (dist[h - 1][w - 1] == -1) result = -1;
  cout << result << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int, S: str):
    s = list(S)
    s[K-1] = s[K-1].lower()
    print(''.join(s))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int x; cin >> x;
    cout << 1 - x << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdint>

int main() {
  intmax_t a, b, x;
  scanf("%jd %jd %jd", &a, &b, &x);
  if (a == 0) {
    printf("%jd\n", b/x+1);
  } else {
    printf("%jd\n", b/x-(a-1)/x);
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define ll long long
using namespace std;

ll get_pow(ll x, int n){
    ll ans = 1;
    while(n){
        if(n & 1) ans = ans * x;
        x = x * x;
        n >>= 1;
    }
    return ans;
}

ll sol(ll n, ll m){
    if(m == 0) return 1;
    ll ans = 1;
    for(ll i = n, j = 1; j <= m; j++, i--){
        ans *= i;
        ans /= j;
    }
    return ans;
}

int main(void){
    ll n, p, x, cnt = 0, ans = 0, cc = 0;
    cin >> n >> p;
    for(int i = 0; i < n; i++){
        cin >> x;
        if(x & 1) cnt++;
        else cc++;
    }
    ans = get_pow(2, n);
    cc = get_pow(2, cc);
    if(p & 1){
        for(int i = 0; i <= cnt; i++){
            if(i % 2 == 0) ans -= cc * sol(cnt, i);
        }
    }else{
        for(int i = 0; i <= cnt; i++){
            if(i % 2 == 1) ans -= cc * sol(cnt, i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
using namespace std;


int main() 
{
	string s;
	cin >> s;
	if (s == "Sunny") cout << "Cloudy" << endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else if (s == "Rainy") cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l=list(map(int, input().split()))

if(n>=m):
    print("0")
    exit()

l.sort()
d=[]
for i in range(m-1):
    d.append(abs(l[i+1]-l[i]))

d.sort()
print(sum(d[:m-n]))


Measured memory_bytes: 13968
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string a, b;
  cin >> a >> b;
  reverse(a.begin(), a.end());
  if (a == b) puts("YES");
  else puts("NO");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <stdio.h>


using namespace std;

int main(int argc, char *argv[]){

  string S;

  cin >> S;
  int l = S.length();
  for(int i = 0; i < l-8; i++){
    cout << S[i];
  }
  cout << endl;

  return 0;
}


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

int main() {
    int N;
    cin>>N;
    vector<vector<int>> S(N+1, vector<int>(3, 0));
    vector<vector<int>> DP(N+1, vector<int>(3, 0));
    REP(i, 1, N+1){
        cin >> S[i][0] >> S[i][1] >> S[i][2];
    }
    REP(i, 1, N + 1){
        REP(j, 0, 3){ //i日目の行動
            REP(k, 0, 3){ //前日の行動
                if(j != k){
                    DP[i][j]=max(DP[i][j], DP[i-1][k] + S[i][j]);
                }
            }
        }
    }
    int ans = 0;
    REP(i, 0, 3){
        ans = max(ans, DP[N][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin>>n;
	int a[n]={};
	for (int i=0;i<n;i++)
		cin>>a[i];
	int Xor=0;
	for (int i=0;i<n;i++)
		Xor ^=a[i];
	for (int i=0;i<n;i++)
		cout<<(Xor ^ a[i])<<' ';
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type* arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define all(v) (v.begin(), v.end())
#define tests(x) \
    int x;       \
    cin >> x;    \
    while (x--)
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int INF = 1e18;
const int N = 1e6 + 2;
void run() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("intput.txt", "r", stdin);
    freopen("o2.txt", "w", stdout);
#endif
}

int solve() {
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    int t = x / d;
    if (k <= t) return (x - k * d);
    x -= t * d;
    k -= t;
    if (k % 2) return abs(x - d);
    return x;
}
int32_t main() {
    run();
    // tests(t) {
    cout << solve() << "\n";
    //}
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  for (int i=0;i<N;i++){
    cin >> B[i];
  }
  for (int i=0;i<N;i++){
    cin >> C[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  vector<long long> can(N,0);
  int checked=0;
  for (int i=0;i<N;i++){
    int lb=-1,ub=N;
    while (ub-lb>1){
      int mid=(lb+ub)/2;
      if (C[mid]>B[i]){
        ub=mid;
      }
      else {
        lb=mid;
      }
    }
    can[i]+=N-ub;
  }
  for (int i=N-2;i>=0;i--){
    can[i]+=can[i+1];
  }
  long long ans=0;
  for (int i=0;i<N;i++){
    int lb=-1,ub=N;
    while (ub-lb>1){
      int mid=(lb+ub)/2;
      if (B[mid]>A[i]){
        ub=mid;
      }
      else {
        lb=mid;
      }
    }
    ans+=can[ub];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int c = 0;
  rep(i, A) {
    rep(j, B) {
      rep(k, C) {
        if(500 * i + 100 * j + 50 * k == X) {
          c++;
        }
      }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin>>N>>M;
 vector<pair<int,char>> P(M);
  int i;
  if(N==1){
    i=0;
  }
  else if(N==2){
    i=10;
  }
  else{
    i=100;
  }
  for(int j=0;j<M;j++){
    cin>>P.at(j).first>>P.at(j).second;
  }
  //cout<<1<<P.at(0).second;
  while(true){
    string s;
    s=to_string(i);
    for(int j=0;j<M;j++){
      if(s.at(P.at(j).first-1)!=P.at(j).second){
        goto PLAS;
      }
    }
    cout<<i;
    break;
    PLAS:
    i++;
    if(i==1000){
      cout<<-1;
      break;
    }
    
  
  }
  
      
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        ans += 1
print(ans)


Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<vector<ll>> A(n, vector<ll>(3));
    rep(i, n)
    {
        rep(j, 3) cin >> A[i][j];
    }

    vector<vector<ll>> dp(100010, vector<ll>(3));
    rep(i, 3) dp[0][i] = A[0][i];
    for (int i = 0; i < n - 1; i++)
    {
        rep(p, 3)
        {
            rep(q, 3)
            {
                if (p == q)
                    continue;
                dp[i + 1][q] = max(dp[i + 1][q], dp[i][p] + A[i + 1][q]);
            }
        }
    }
    ll ans = -1;
    rep(i, 3) ans = max(ans, dp[n - 1][i]);
    cout << ans << endl;
}

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

long long N, M;
long long A[100005];
map<long long, long long> memo;

int main(){
	cin >> N >> M;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
	}
	long long cur = 0;
	for(long long i = 0; i < N; i++){
		cur += A[i];
		cur %= M;
		memo[cur]++;
	}

	long long ans = 0;
	for(auto m: memo){
		ans += m.second * (m.second - 1) / 2;
		if(m.first == 0){
			ans += m.second;
		}
	}
	cout << ans << endl;
}


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

using LL = long long;
const LL M = 1e9+7;

string L;

map<pair<int,bool>, LL> memo;
LL dp(int i, bool eq) {
  if(i == L.size()) return 1;
  if(i == L.size()) return eq ? 1 : 2;
  auto p = make_pair(i, eq);
  if(memo.count(p)) return memo[p];
  LL res = 0;
  if(eq) {
    if(L[i] == '1') res += 2 * dp(i+1, true) + dp(i+1, false);
    else            res += dp(i+1, true);
    res %= M;
  } else {
    res += 3 * dp(i+1, false);
    res %= M;
  }
  return memo[p] = res;
}

int main() {
  cin >> L;
  cout << dp(0, true) << endl;
}


Measured memory_bytes: 20608
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long gcd(long long N, long long M){
    while (true){
        if (min(N,M)==0){
            return max(N,M);
        }else if (N>M){
            N%=M;
        }else{
            M%=N;
        }
    }
}

long long MOD = 1000000007;

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

    vector<long long> gcd1(N,0);
    vector<long long> gcd2(N,0);
    gcd1[0]=A[0];
    gcd2[N-1]=A[N-1];
    for(int i=1; i<N; i++){
        gcd1[i]=gcd(gcd1[i-1],A[i]);
        gcd2[N-i-1]=gcd(gcd2[N-i],A[N-i-1]);
    }
    long long ans=gcd2[1];
    for(int i=1; i<N-1; i++){
        ans=max(ans,gcd(gcd1[i-1],gcd2[i+1]));
    }
    ans=max(ans,gcd1[N-2]);
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int main(void){

    char a, ans;

    cin >> a;

    switch(a){
        case 'A':
            ans = 'T';
            break;
        
        case 'T':
            ans = 'A';
            break;

        case 'G':
            ans = 'C';
            break;

        case 'C':
            ans = 'G';
            break;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
public class Main {
  private static void solve() {
    int n = ni();
    int m = ni();
    int[] count = new int[n];
    for (int i = 0; i < m; i ++) {
      count[ni() - 1] ++;
      count[ni() - 1] ++;
    }
    
    for (int v : count) {
      if (v % 2 == 1) {
        System.out.println("NO");
        return;
      }
    }
    System.out.println("YES");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 43036
a, b, c, x, y = input().split()
A = int(a)
B = int(b)
C = int(c)
X = int(x)
Y = int(y)

sum = 0

if A + B >= 2 * C:
  sum += min(X,Y) * 2 * C
  if A >= 2 * C:
    sum += (X - min(X,Y)) * 2 * C
  else:
    sum += (X - min(X,Y)) * A
  
  if B >= 2 * C:
    sum += (Y - min(X,Y)) * 2 * C
  else:
    sum += (Y - min(X,Y)) * B

else:
  sum += A*X + B*Y
print(sum)

Measured memory_bytes: 9160
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
  int N;

  cin >> N;
 
  for(int i = 0; i < 20; i++){
   for(int j = 0; j < 20; j++){
    if( N == 4*i + 7*j){
     cout << "Yes" << endl;
     return 0;
    }
   }
  } 
  cout << "No" << endl;

  return 0;

}



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

int main() {
  int N, tmp, sum = 0;
  cin >> N;
  tmp = N;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  if (tmp % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n;
LL m;
LL a[maxn];

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

    LL g = 0;
    for(int i = 0; i < n; i++) g = __gcd(a[i], g);

    LL p = g;
    for(int i = 0; i < n; i++)
    {
        p = p / __gcd(p, a[i]) * a[i];
        if(p > 2 * m)
        {
            cout <<0 <<endl;
            return ;
        }
    }

    int cc[2] = {0};
    for(int i = 0; i < n; i++)
        cc[(p / a[i]) & 1]++;

    if(cc[0] && cc[1])
    {
        cout <<0 <<endl;
        return ;
    }

    LL t = 2 * m / p;

    if(cc[1])
        cout <<(t + 1) / 2 <<endl;
    else
        cout <<t / 2 <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> P(N);
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    P.at(i) = make_pair(A, B);
  }

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

  int num = 0;
  long long ans = 0;

  int cnt = 0;
  while (num < M) {
    if(P.at(cnt).second > 0) {
      ans += P.at(cnt).first;
      P.at(cnt).second--;
      num++;
    }
    else cnt++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1152