akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <string.h>
#include <algorithm>
#define mod 1000000007
#define inf 1LL<<61
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int nmax = 1001;
	int mmax = 2001;
	int a[mmax];
	int b[mmax];
	ll c[mmax];
	int N, M;
	cin >> N >> M;

	REP(i,0,M){
		cin >> a[i] >> b[i] >> c[i];
	}

	ll dp[nmax];
	REP(i,0,N)
		dp[i] = -(inf);
	dp[0] = 0;
	REP(i,0,N-1){
		REP(i,0,M){
			if(dp[a[i] - 1] == -(inf))
				continue;
			dp[b[i]-1]=max(dp[b[i]-1], dp[a[i] -1] + c[i]);
		}
	}
	ll ans = dp[N-1];
	REP(i,0,N-1){
		REP(i,0,M){
			if(dp[a[i] - 1] == inf)
				continue;
			dp[b[i]-1]=max(dp[b[i]-1], dp[a[i] -1 ] + c[i]);
		}
	}
	if(ans != dp[N-1])
		cout << "inf";
	else
		cout << ans;
	
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int h[] = new int[n];
		for(int i=0;i<n;i++) {
			h[i]=scan.nextInt();
		}
		scan.close();
		int check=1;
		if(n!=1) {
			for(int i=n-2;i>=0;i--) {
				if(h[i] > h[i+1]) h[i]--;
				if(h[i] > h[i+1]) {
					check=0;
					break;
				}
			}
		}
		System.out.println((check == 1)? "Yes":"No");
	}
}

Measured memory_bytes: 51816
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    string s;
    cin>>s;
    vector<int>alpha(26,0);
    for(int i=0;i<s.length();i++)
    {
        if(s[i]>='a'&&s[i]<='z'){
            alpha[s[i]-'a']++;
        }
    }
    bool no=false;
    for(int i=0;i<alpha.size();i++)
    {
        if(alpha[i]%2!=0){
            no=1;
        }
    }
    if(no){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>

using namespace std;
/**
2^60 = 1152921504606846976
 */
long long xor_sum4(int n, long long a[]) {
  long long divider = 1000000007;
  vector<bitset<60>> ba;
  long long ans = 0;
  for(int i=0;i<n;i++) {
    bitset<60> b = a[i];
    ba.push_back(b);
    // cout << b << endl;
  }
  for(int i=0;i<60;i++) {
    long long count_zero = 0;
    long long count_one = 0;
    for(int j=0;j<ba.size();j++) {
      bitset<60> b = ba[j];
      if (b[i] == 0)
	count_zero++;
      else
	count_one++;
    }
    // cout << i << " -> one: " << count_one << ", zero: " << count_zero << endl;
    /*
    long long adder = (count_one * count_zero) * pow(2, i);
    adder = adder % divider;
    ans += adder;
    */
    ans += (((count_one * count_zero) % divider) * ((1LL << i) % divider)) % divider;
    ans = ans % divider;
    // cout << ans << endl;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  long long a[n];
  for(int i =0;i<n;i++) {
    cin >> a[i];
  }
  auto ans = xor_sum4(n, a);
  cout << ans;
}


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

public class  Main{
	static long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	static long lcm(long a,long b) {
		return (a/gcd(a,b))*b;
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt(),m=sc.nextInt();
		int cnt2=0;
		int[]in=new int[n];
		for(int i=0;i<n;i++) {
			int x=sc.nextInt()/2;
			in[i]=x;
			int cnt=0;
			while(x%2==0) {
				x/=2;
				cnt++;
			}
			if(i==0)cnt2=cnt;
			else {
				if(cnt2!=cnt) {
					pw.println(0);
					pw.flush();
					return;
				}
			}
		}
		long lcm=1;
		for(int i=0;i<n;i++) {
			lcm=lcm(in[i],lcm);
			if(lcm>m) {
				pw.println(0);
				pw.flush();
				return;
			}
		}
		long cnt=m/lcm;
		pw.println((cnt+1)/2);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 38584
#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int N, A, B, C;
	scanf("%d %d %d %d", &N, &A, &B, &C);
	
	int i;
	long long fact[200001], fact_inv[200001], pow[2][100001] = {{1, div_mod(A, A + B, Mod)}, {1, div_mod(B, A + B, Mod)}};
	for (i = 1, fact[0] = 1; i <= N * 2; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N * 2 - 1, fact_inv[N*2] = div_mod(1, fact[N*2], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	for (i = 2; i <= N; i++) {
		pow[0][i] = pow[0][i-1] * pow[0][1] % Mod;
		pow[1][i] = pow[1][i-1] * pow[1][1] % Mod;
	}
	
	long long prob[2], ans = 0;
	for (i = 0; i < N; i++) {
		prob[0] = pow[0][N] * pow[1][i] % Mod * fact[N+i-1] % Mod * fact_inv[N-1] % Mod * fact_inv[i] % Mod;
		prob[1] = pow[1][N] * pow[0][i] % Mod * fact[N+i-1] % Mod * fact_inv[N-1] % Mod * fact_inv[i] % Mod;
		ans = (ans + (prob[0] + prob[1]) * (N + i)) % Mod;
	}
	printf("%lld\n", div_mod(ans * 100 % Mod, A + B, Mod));
	fflush(stdout);
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    bool prime[SIZE];
    for(int i = 2; i < SIZE; ++i) prime[i] = 1;

    for(int i = 2; i < SIZE; ++i) {
        if(prime[i] == 1) {
            for(int j = i * 2; j < SIZE; j += i) {
                prime[j] = 0;

            }
        }
    }

    int sum[SIZE] = {};
    for(int i = 3; i < SIZE; ++i) {
        if(prime[i] == 1 && prime[(i + 1) / 2] == 1) sum[i]++;
        sum[i] += sum[i - 1];

    }

    int Q;
    cin >> Q;
    while(Q--) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;

    }

    return 0;
}



Measured memory_bytes: 1664
mtc ([],v) [] = v
mtc ((p0:ps),v) (a0:as) =
  if p0 == '*'
  then v
  else if p0 == a0
       then mtc (ps,v) as
       else 0

ans (["0","0"]:_) = []
ans ([m',n']:x) =
  let m = read m'
      n = read n'
      t = map (\[p,v] -> (reverse p,read v)) $ take m x :: [(String,Int)]
      a = map reverse $ concat $ take n $ drop m x :: [String]
      p = sum $ concat $ map (\t0-> map (mtc t0) a) t
      r = drop (m+n) x
  in
    p:(ans r)

main = do
  c <- getContents
  let i = map words $ lines c
      o = ans i
  mapM_ print o



Measured memory_bytes: 22132
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
#define forn(n) for(long long int i=0; i<n; ++i)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;

int n,k;
vi p,aum;

int main() {
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	p=vi(n);
	aum=vi(n);
	forn(n)
		cin>>p[i];
	int cant=0;
	
	for(int i=1;i<n;++i){
		if(p[i]>p[i-1])
			aum[i]=1;
		else
			aum[i]=-1;
	}
	
	aum[0]=1;
	int pg=0;
	bool pv=false;
	
	priority_queue<pair<int,int>> menores,mayores;
	
	for(int i=0;i<k;i++){
		pg+=aum[i];
		menores.push({-p[i],i});
		mayores.push({p[i],i});
	}
		
	if(pg-aum[0]!=k-1 || k==1 )
		cant++;
	else{	
		cant++;
		pv=true;
	}
	
	for(int i=k;i<n;++i){
		pg-=aum[i-k];
		bool men=false;
		//cout<<menores.top().second<<endl;
		while(menores.top().second<=i-k){
			//cout<<"entre"<<endl;
			men=true;
			menores.pop();
		}
		bool mayor=false;
		while(mayores.top().second<=i-k){
			mayores.pop();
		}
		pg+=aum[i];
		mayores.push({p[i],i});
		menores.push({-p[i],i});
		
		if(mayores.top().second==i)
			mayor=true;
		
		//cout<<"i: "<<i<<endl<<"pg: "<<pg<<endl;
		
		if((pg-aum[i-k+1]!=k-1 && (men==false || mayor==false)) || k==1 )
			cant++;
		if(pg-aum[i-k+1]==k-1 && (men==false || mayor==false) && !pv){
			cant++;
			pv=true;
		}
	}
	
	cout<<cant<<endl;
	return 0;
}

Measured memory_bytes: 5220
import numpy as np
import itertools

Cmin = 10**10
N, M, X = map(int, input().split())
L = np.array([[int(j) for j in input().split()] for i in range(N)])
for i in range(N):
  for idx in itertools.combinations(list(range(N)), i+1):
    A = np.zeros(M+1, dtype=int)
    A = A + np.sum(L[list(idx)], axis=0)
    if A[0] < Cmin and (A[1:] >= X).all() == True:
      Cmin = A[0]
if Cmin == 10**10:
  print(-1)
  exit()
print(Cmin)

Measured memory_bytes: 27396
import java.util.Scanner;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.nextLine();
    String result = "Good";
    String[] split = s.split("",0);
    for(int i = 0;i < 3;i++){
        if(split[i].equals(split[i+1])){
          result = "Bad";
        }
    }
      System.out.println(result);
  }
}

Measured memory_bytes: 23252
#include<stdio.h>

int main(){
    int x[4][2],y;
    int i;

    for(i = 0; i < 4; i++){
        scanf("%d %d",&x[i][0],&x[i][1]);
    }


    for(i = 0; i < 4; i++){
        if(x[i][0] == 1){
            printf("%d\n",x[i][1]*6000);
        }
        if(x[i][0] == 2){
            printf("%d\n",x[i][1]*4000);
        }
        if(x[i][0] == 3){
            printf("%d\n",x[i][1]*3000);
        }
        if(x[i][0] == 4){
            printf("%d\n",x[i][1]*2000);
        }
    }

    return 0;
}

Measured memory_bytes: 1032
N, M = map(int, input().split())
penalty = [0] * N
AC = [False] * N

for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == "AC":
        AC[p] = True
    else:
        if not AC[p]:
            penalty[p] += 1

for i in range(N):
    if not AC[i]:
        penalty[i] = 0 

print("{} {}".format(sum(AC), sum(penalty)))

Measured memory_bytes: 45656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

struct Coo{
  double x,y,deg;
};

bool comp(const Coo& l, const Coo& r){
  return l.deg < r.deg;
}

int dec(int i,int N){
  return (i+N-1)%N;
}

int inc(int i,int N){
  return (i+1)%N;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<Coo> v(N);
  rep(i,N){
    cin >> v[i].x >> v[i].y;
    v[i].deg = 180.0/M_PI*atan2(v[i].x,v[i].y);
    if(v[i].deg < 0) v[i].deg+=360.0;
  }
  sort(all(v),comp);

  double ans = 0.0;
  double x_ = 0, y_ = 0;
  rep(i,N){
    x_ += v[i].x;
    y_ += v[i].y;
  }
  rep(i,N) repp(j,i+1,N+1){
    double x = 0, y = 0;
    repp(k,i,j){
      x += v[k].x;
      y += v[k].y;
    }
    ans = max(ans,sqrt(x*x+y*y));
    ans = max(ans,sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_)));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;


int main(){
  ll n,ans=0;
  cin>>n;
  rep(i,0,n)ans+=i;
  cout<<ans;
}


Measured memory_bytes: 256
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key = lambda x:x[1])
ttime = 0
ans = 'Yes'
for i in A:
  if ttime + i[0] > i[1]:
    ans = 'No'
    break
  else:
    ttime += i[0]
print(ans)

Measured memory_bytes: 55196
#include <iostream>
#include <iomanip>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

typedef double D;
typedef complex<D> P;
typedef pair<D,int> pdi;

D pi;
D smax, smin, tmax, tmin;
vector<P> ps;

D dot(const P &a, const P &b){
	return real(a) * real(b) + imag(a) * imag(b);
}

P check(D t){
	while(t < 0.0){ t += pi; }
	while(t >= pi){ t -= pi; }
	t += 0.0;
	
	int n = ps.size();
	P a = polar(D(1.0), 0.5 * pi - t);
	vector<pdi> v(2 * n);
	for(int i = 0; i < n; ++i){
		D z = dot(ps[i], a);
		v[2 * i] = pdi(z - 1.0, i);
		v[2 * i + 1] = pdi(z + 1.0, ~i);
	}
	sort(v.begin(), v.end());
	int cnt = 0;
	D sum = 0.0;
	P ret;
	for(int i = 0; i < 2 * n; ++i){
		if(cnt){ sum += v[i].first - v[i - 1].first; }
		if(v[i].second >= 0){
			if(!cnt++){ ret -= ps[v[i].second]; }
		}
		else{
			if(!--cnt){ ret += ps[~v[i].second]; }
		}
	}
	
	if(sum > smax){
		smax = sum;
		tmax = t;
	}
	if(sum < smin){
		smin = sum;
		tmin = t;
	}

	return ret;
}

int main(){
	pi = acos(D(-1.0));
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	while(cin >> n, n){
		smax = -1e300;
		smin = 1e300;
	
		ps.resize(n);
		for(int i = 0; i < n; ++i){
			int x, y;
			cin >> x >> y;
			ps[i] = P(x, y);
		}

		check(0);

		vector<D> cand;
		for(int i = 0; i < n; ++i)
		for(int j = 0; j < i; ++j){
			D a = -arg(ps[j] - ps[i]);
			D b = asin(2.0 / abs(ps[j] - ps[i]));
			cand.push_back(a);
			cand.push_back(a - b);
			cand.push_back(a + b);
		}
		for(size_t i = 0; i < cand.size(); ++i){
			while(cand[i] < 0.0){ cand[i] += pi; }
			while(cand[i] > pi){ cand[i] -= pi; }
			check(cand[i]);
		}
		sort(cand.begin(), cand.end());
		for(size_t i = 1; i < cand.size(); ++i){
			P ret = check(0.5 * (cand[i - 1] + cand[i]));
			if(abs(ret) > 1e-10){
				check(0.5 * pi - arg(ret));
			}
		}

		tmin = min(tmin, pi - 1e-10);
		tmax = min(tmax, pi - 1e-10);
		cout << tmin << '\n' << tmax << '\n';
	}
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
using VP = vector<P>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int inf = 1e9;
constexpr ll  lnf = 1LL << 60;
constexpr int mod = 1e9+7;
template<class T> inline bool chmax(T& a, const T& b) { if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if(a>b) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}


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

    VP wv(n);
    rep(i, n) cin >> wv[i].first >> wv[i].second;

    vector<V> dp(n+1, V(w+1));
    rep(i, n) {
        rep(sum_w, w+1) {
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
            if(sum_w - wv[i].first >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - wv[i].first] + wv[i].second);
            }
        }
    }

    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000 + 5;
int arr[N];
ll dp[2][N][N];
int n;

ll solve(int l, int r, int turn) {
    if (l > r)
        return 0;
    if (dp[turn][l][r] != -1)
        return dp[turn][l][r];
    ll res = 0;
    if (turn == 0)
        res = max(solve(l + 1, r, 1) + arr[l], solve(l, r - 1, 1) + arr[r]);
    else
        res = min(solve(l + 1, r, 0) - arr[l], solve(l, r - 1, 0) - arr[r]);
    return dp[turn][l][r] = res;
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, n - 1, 0);
    return 0;
}


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

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

    int cur = 0;

    while(cur <= (int)s.length()-8){
        string t = s.substr(cur, 8);
        sort(t.begin(), t.end());
        if(t == "AADINNUY"){
            for(int i = 0; i < 8; i++){
                s[cur++] = "AIZUNYAN"[i];
            }
        }else{
            cur++;
        }
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
int binarySearch(int S[], int n, int key){
  int left=0, right=n;
  int mid;
  while(left<right){
	mid=(left+right)/2;
	if(S[mid]==key)
	  return 1;
	else if(S[mid]<key)
	  left=mid+1;
	else 
	  right=mid;
  }
  return 0;
}

int main(){
  int n, q;
  int S[100005];
  int i, j;
  int count=0;
  int key;
  scanf("%d", &n);
  for(i=0; i<n; ++i){
	scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; ++i){
	scanf("%d", &key);
	count+=binarySearch(S, n, key);
  }
  //
  printf("%d\n", count);
  return 0;
}



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

int main() {
  
  //都市の数N，道の数Mを宣言 	都市一時保存用A
  int N, M, A=0;
  cin >> N >> M;
  
  vector<int> road ( N,0 );
  
  for( int i = 0; i < 2*M ; i++){
   	cin >> A;
    road.at(A-1)++;
  }
  
  for( int i = 0; i < N ; i++){
   	cout << road.at(i) << endl; 
  }
  
  
}


Measured memory_bytes: 3600
n,k = map(int,input().split())
lis = list(map(int,input().split()))

dp = [10 ** 10 for i in range(n+k+1)]

dp[0] = 0
for i in range(n):
    for j in range(1,min(n-i,k+1)):
        dp[i+j] = min(dp[i+j],dp[i]+abs(lis[i+j]-lis[i]))
print(dp[n-1])

Measured memory_bytes: 56544
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,a,b; cin>>a>>b>>n;
    ll ans = 0;

    if (b-1 <= n) {
        ll x = b-1;
        cout << (a*x)/b - a*(x/b) << '\n';
    }
    else {
        cout << (a*n)/b - a*(n/b) << '\n';
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll a, b, k; cin >> a >> b >> k;

  ll eat_1 = min(a, k);
  a -= eat_1;
  k -= eat_1;

  ll eat_2 = min(b, k);
  b -= eat_2;
  k -= eat_2; // not needed.

  cout << a << ' ' << b << '\n';

  return 0;
}


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

struct unknown_atom_exception {};
int parse_number(string::const_iterator & first, string::const_iterator last) {
    assert (first != last);
    int n = 0;
    while (first != last and isdigit(*first)) {
        n *= 10;
        n += *first - '0';
        ++ first;
    }
    return n;
}
string parse_atom(string::const_iterator & first, string::const_iterator last) {
    assert (first != last);
    assert (isupper(*first));
    string name;
    name += *first;
    ++ first;
    if (first != last and islower(*first)) {
        name += *first;
        ++ first;
    }
    return name;
}
int parse_molecules(string::const_iterator & first, string::const_iterator last, map<string, int> const & weight);
int parse_molecule(string::const_iterator & first, string::const_iterator last, map<string, int> const & weight) {
    assert (first != last);
    int value;
    if (isalpha(*first)) {
        string atom = parse_atom(first, last);
        if (weight.count(atom)) {
            value = weight.at(atom);
        } else {
            throw unknown_atom_exception {};
        }
    } else {
        assert (*first == '(');
        ++ first;
        value = parse_molecules(first, last, weight);
        assert (*first == ')');
        ++ first;
    }
    if (first != last and isdigit(*first)) {
        value *= parse_number(first, last);
    }
    return value;
}
int parse_molecules(string::const_iterator & first, string::const_iterator last, map<string, int> const & weight) {
    assert (first != last);
    int value = 0;
    while (first != last and *first != ')') {
        value += parse_molecule(first, last, weight);
    }
    return value;
}
int parse(string const & s, map<string, int> const & weight) {
    try {
        auto it = s.begin();
        return parse_molecules(it, s.end(), weight);
    } catch (unknown_atom_exception e) {
        return -1;
    }
}

int main() {
    map<string, int> weight;
    while (true) {
        string atom; cin >> atom;
        if (atom == "END_OF_FIRST_PART") break;
        cin >> weight[atom];
    }
    while (true) {
        string expr; cin >> expr;
        if (expr == "0") break;
        int result = parse(expr, weight);
        if (result == -1) {
            cout << "UNKNOWN" << endl;
        } else {
            cout << result << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int N;
    int T, A;
    int H[1002];

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

    int near = 1;
    double min = abs(A - (T - H[1] * 0.006));
    for (int i = 2; i <= N; i++) {
        if (abs(A - (T - H[i] * 0.006)) < min) {
            near = i;
            min = abs(A - (T - H[i] * 0.006));
        }
    }

    cout << near << endl;
}


Measured memory_bytes: 256
def include3(x):
    if (x % 10 == 3):
        return True
    else:
        x //= 10
        if (x>0):
            return include3(x)
        else:
            return False

n = int(input())

s = ''
for i in range(1,n+1):
    if (i % 3 == 0):
        s += ' '+str(i)
    elif (include3(i)):
        s += ' '+str(i)
print(s)



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

using namespace std;

long long result;
string s;

void go(int pos, long long val, long long sum) {
    if (pos == (int)s.size()) {
        if (val > 0) {
            sum += val;
            result += sum;
        }
        return;
    }
    go(pos + 1, val * 10 + (s[pos] - '0'), sum);
    if (val > 0)
        go(pos + 1, s[pos]-'0', sum + val);
}

int main() {
    cin >> s;
    go(0, 0, 0);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
inf=1e13

def bellmanford(E,N):
    score=[inf for i in range(N)]
    score[0]=0
    for i in range(N-1):
        for edge in E:
            u=edge[0]
            v=edge[1]
            if u!=inf:
                score[v]=min(score[v],score[u]+edge[2])
    temp=score[N-1]
    score = [inf for i in range(N)]
    score[0] = 0
    for i in range(N):
        for edge in E:
            u=edge[0]
            v=edge[1]
            if u!=inf:
                score[v]=min(score[v],score[u]+edge[2])
    loop=(temp!=score[N-1])

    return temp,loop


if __name__ == '__main__':
    N,M=list(map(int, input().split()))
    E=[list(map(int, input().split())) for _ in range(M)]
    negative_E=[]
    for a,b,c in E:
        negative_E.append((a-1,b-1,-c))

    score,loop=bellmanford(negative_E,N)
    if loop:
        print("inf")
    else:
        print(-score)

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

struct MAX_FLOW {
    struct edge {
        int to, cap, rev;

        edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector<vector<edge>> G;
    vector<bool> used;
    int sz;

    MAX_FLOW(int size) {
        sz = size;
        G.resize(sz);
        used.resize(sz);
    }

    void add_edge(int from, int to, int cap) {
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size() - 1);
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (auto& e : G[v]) {
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            used.clear();
            used.resize(sz);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

class FLotusLeaves {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int H, W;
        cin >> H >> W;

        MAX_FLOW mf(H + W + 2);
        int s = H + W;
        int t = s + 1;
        REP(i, H) {
            REP(j, W) {
                char c;
                cin >> c;
                if (c != '.') {
                    mf.add_edge(i, j + H, 1);
                    mf.add_edge(j + H, i, 1);
                }
                if (c == 'S') {
                    mf.add_edge(s, i, INF);
                    mf.add_edge(s, j + H, INF);
                }
                if (c == 'T') {
                    mf.add_edge(i, t, INF);
                    mf.add_edge(j + H, t, INF);
                }
            }
        }
        int val = mf.max_flow(s, t);
        if (val >= INF) val = -1;
        cout << val << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    FLotusLeaves solver;
    solver.solve(in, out);
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	int N = s.length();
	int i = 0, j = N - 1, ans = 0;
	while (i < j) {
		while (s[i] == 'x' && s[j] == 'x') {
			if (i < N - 1) i++;
			if (j > 0) j--;
			if (i >= j) break;
		}
		while (s[i] == 'x' && s[j] != 'x') {
			ans++;
			if (i < N - 1) i++;
			if (i >= j) break;
		}
		while (s[i] != 'x' && s[j] == 'x') {
			ans++;
			if (j > 0) j--;
			if (i >= j) break;
		}

		if (s[i] != s[j]) {
			cout << -1 << endl;
			return 0;
		}
		i++;
		j--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    int n, m;
    cin >>n >> m;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    int sm = accumulate(all(a), 0);
    int x = 0;
    rep(i, n){
        if(a[i]*4*m >= sm) x++;
    }
    cout << (x>=m ? "Yes":"No") << endl;
}

Measured memory_bytes: 256
let m = 1000000007
let ( +^ ) x y = (x + y) mod m

module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let cs = Array.make (n + 2) 0 in
  for i = 1 to n do
    Scanf.scanf "%d\n" @@ Array.set cs i
  done;
  let dp = Array.make (n + 2) 1 in
  let acc = Array.make (n + 2) IntMap.empty in
  for i = 1 to n do
    dp.(i) <- dp.(i - 1) +^
      if cs.(i) = cs.(i - 1)
      then 0
      else (try IntMap.find cs.(i) acc.(i - 1) with Not_found -> 0);
    acc.(i) <-
      if cs.(i) = cs.(i - 1)
      then acc.(i - 1)
      else IntMap.add cs.(i) (dp.(i - 1) +^ try IntMap.find cs.(i) acc.(i - 1) with Not_found -> 0) acc.(i - 1)
  done;
  Printf.printf "%d\n" dp.(n)


Measured memory_bytes: 176820
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    ll n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    if(p == 2) {
        ll ans = 0;
        rep(i, n) if(s[i] % 2 == 0) ans += i + 1;
        cout << ans << endl;
        return 0;
    }
    if(p == 5) {
        ll ans = 0;
        rep(i, n) if((s[i] - '0') % 5 == 0) ans += i + 1;
        cout << ans << endl;
        return 0;
    }

    ll dp[p] = {}, x = 1, m = 0;
    dp[0] = 1;
    ll ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        m += x * (s[i] - '0');
        m %= p;
        ans += dp[m];
        dp[m]++;
        x *= 10;
        x %= p;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false);\
				cin.tie(0);\
				cout.tie(0)
#define REP(_i, _a) for(int _i = 0; _i < (int)_a; ++_i)
#define FOR(_i, _a, _b) for(int _i = (int)_a; _i <= (int)_b; ++_i)
#define FORD(_i, _a, _b) for(int _i = (int)_a; _i >= (int)_b; --_i)
#define RESET(_a, _value) fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define ALL(_a) _a.begin(), _a.end()
#define SIZE(_a) _a.size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define newline '\n';

// DEBUG UTIL
#define DEBUG(args...) { cerr << "> "; \
						string _s = #args; \
						replace(_s.begin(), _s.end(), ',', ' '); \
						stringstream _ss(_s); istream_iterator<string> _it(_ss); \
						err(_it, args); }

void err(istream_iterator<string> it) { cerr << endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << ": " << a << " ";
	err(++it, args...);
}

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 2e9;

int n;
multiset<int> now;
vi arr;
multiset<int>::iterator mid;

void read() {
	cin >> n;
	arr.resize(n);
	REP(i, n) {
		cin >> arr[i];
		now.insert(arr[i]);
	}
	mid = next(now.begin(), n / 2);
}

void solve() {
	vi ans;
	--mid;
	REP(i, n) {

		if (arr[i] <= *mid) {
			++mid;
			ans.pb(*mid);
			--mid;
		} else {
			ans.pb(*mid);
		}
	}

	for (auto e: ans) {
		cout << e << endl;
	}	
}

int main() {
	FAST_IO;
	
	int TC = 1;
	// cin >> TC;
	FOR(tc, 1, TC) {
		read();
		solve();
	}

	return 0;
}


Measured memory_bytes: 13568
def judge():
    count = 0
    for _ in range(x):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            count += 1
        else:
            count = 0
        
        if count == 3:
            return True

    return False

x = int(input())

if judge():
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int y = sc.nextInt();
		int x = y / 1000 - n;
		int coefficient1 = 9;	//10000円の係数
		int coefficient2 = 4; //5000円の係数
		int result[] = {-1, -1, -1};
		
		for (int i = 0; i <= n; i++) {
			int tmp = x - (9 * i);
			int tmp2[] = new int[3];
			if (tmp % 4 ==0 && tmp >= 0 && tmp <= 4 * n) {
				tmp2[0] = i;
				tmp2[1] = tmp / 4;
				tmp2[2] = n - tmp2[0] - tmp2[1];
				if (tmp2[2] >= 0 && tmp2[2] <= n) {
					result = tmp2;
					break;
				}
			}
		}
		
		System.out.println(result[0] + " " + result[1] + " " + result[2]);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >>a >>b;
  ll x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
   ll tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
cout << x/b <<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var t = input[0];
        var a = input[1];
        var num = input[2];
        for(var i = 0; i < num; i++)
        {
            if (i % 2 == 0)
            {
                a += t/2;
                t /= 2;
            }
            else
            {
                t += a / 2;
                a /= 2;
            }
        }
        WriteLine($"{t} {a}");
    }
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	cin >> S;
	int w;
	cin >> w;
	string ansS;
	for (int i = 0; i < S.size(); i+=w) {
		ansS += S[i];
	}
	cout << ansS << endl;
	return 0;
}

Measured memory_bytes: 3560
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, T;
    cin >> A >> B >> T;
    cout << (T / A) * B << endl;

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

int main(){
  int n;
  cin >> n;
  string cl;

  rep(i, n){
    cin >> cl;
    if(cl == "Y"){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W));
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j)
            cin >> A[i][j];
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j)
            cin >> B[i][j];

    static bool dp[82][82][12800];
    dp[0][1][0] = dp[1][0][0] = true;
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            for(int k = 0; k < 12800; ++k) {
                int tmp = abs(A[i - 1][j - 1] - B[i - 1][j - 1]);
                if(dp[i - 1][j][k]) {
                    dp[i][j][k + tmp] = true;
                    dp[i][j][abs(k - tmp)] = true;
                }
                if(dp[i][j - 1][k]) {
                    dp[i][j][k + tmp] = true;
                    dp[i][j][abs(k - tmp)] = true;
                }
            }
        }
    }

    int ans = INF;
    for(int k = 0; k < 12800; ++k)
        if(dp[H][W][k])
            ans = min(ans, k);

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


Measured memory_bytes: 82944
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	vector<pair<string,long long> >v;
	long long a,ans=0,c=0,sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>s>>a;
		v.push_back({s,a});
		sum+=a;
	}
	cin>>s;
	for(int i=0;i<n;i++)
	{
		c+=v[i].second;
		if(v[i].first==s)
		{
			ans=sum-c;
			break;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD			1000000007
#define FOR(i,l,r)	for(int i=l;i<=r;i++)
#define REP(i,n)	for(int i=1;i<=n;i++)
#define REP0(i,n)	for(int i=0;i<n;i++)
#define PB			push_back
#define MP			make_pair
#define PII			pair<int,int>
#define VI			vector<int>
#define ALL(x)		(x).begin(),(x).end()
#define MAKE1(a)	int a;
#define MAKE2(a,b)	int a,b;
#define MAKE3(a,b,c) int a,b,c;
#define MAKE4(a,b,c,d) int a,b,c,d;
#define DR1(a)		MAKE1(a);cin>>a;
#define DR2(a,b)	MAKE2(a,b);cin>>a>>b;
#define DR3(a,b,c)	MAKE3(a,b,c);cin>>a>>b>>c;
#define DR4(a,b,c,d) MAKE4(a,b,c,d);cin>>a>>b>>c>>d;
int n,a[55];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	bool flag=1;
	for(int i=1;i<=n;i++)	if(a[i]!=i)	flag=0;
	if(flag)	return puts("YES"),0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			swap(a[i],a[j]);
			bool flag=1;
			for(int k=1;k<=n;k++)	if(a[k]!=k)	flag=0;
			if(flag)	return puts("YES"),0;
			swap(a[i],a[j]);
		}
	}
	puts("NO");
	return 0;
}

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

using namespace std;

int
main(void){
	string s; cin >> s;
	int pos = 0;
	bool check = true;
	while(pos < (int)s.size()){
		string temp = s.substr(pos, min(11, (int)s.size() - pos));
		if(temp == "dreameraser"){
			pos += 11;
		}
		else if(temp.substr(0, 10) == "dreamerase"){
			pos += 10;
		}
		else if(temp.substr(0, 7) == "dreamer"){
			pos += 7;
		}
		else if(temp.substr(0, 5) == "dream"){
			pos += 5;
		}
		else if(temp.substr(0, 6) == "eraser"){
			pos += 6;
		}
		else if(temp.substr(0, 5) == "erase"){
			pos += 5;
		}
		else{
			check = false;
			break;
		}
		
	}
	if(check) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=10050;
const int M=100;
const int mod=1e9+7;
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
int sub(int x, int y){ x-=y;return x<0?x+mod:x;}
int mul(int x, int y){ return (ll)x*y%mod;}
int dp[N][M];
int main()
{
	string s;
	int k;
	cin>>s;
	scanf("%i",&k);
	dp[0][0]=1;
	for(int i=1;i<=s.size();i++)
		for(int j=0;j<k;j++)
			for(int d=0;d<=9;d++)
				dp[i][j]=add(dp[i][j],dp[i-1][(j-d%k+k)%k]);
	int sum=0,ans=0;
	int sz=s.size();
	for(int i=0;i<s.size();i++)
	{
		sz--;
		for(int j=0;j<s[i]-'0';j++)
		{
			ans=add(ans,dp[sz][(k-((sum+j)%k))%k]);
		}
		sum=(sum+(s[i]-'0'))%k;
	}
	if(sum==0) ans=add(ans,1);
	ans=sub(ans,1);
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 4224
import java.util.*;
	
	
	
	public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			Set<Integer> a = new HashSet<Integer>();
			
			for (int i=0;i<N;i++) {
				a.add(sc.nextInt());
			}
			int s =a.size();
			if(s == N) {
				System.out.println("YES");
				return;
			}else {
				System.out.println("NO");
			}
				
			
		}
				
	}

Measured memory_bytes: 100128
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

bool match(string s, int i, string t)
{
    if (i + 1 < t.size()) return false;
    for (int j = i; j > i-t.size(); --j)
    {
        if (s[j] != t[i-j])
            return false;
    }
    return true;
}

void solve()
{
    string s; cin >> s;
    string ts[] = {"dream", "dreamer", "erase", "eraser"};
    rep(j, 4)
    {
        reverse(all(ts[j]));
    }
    int i = s.size() - 1;
    while (i >= 0)
    {
        rep(j, 4)
        {
            if (match(s, i, ts[j]))
            {
                i -= ts[j].size();
                goto end;
            }
        }
        cout << "NO" << endl;
        return;
        end:;
    }
    cout << "YES" << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 H, W;
    cin >> H >> W;

    if (H == 1 && W == 1) {
        cout << 1 << endl;
    } else if (H == 1) {
        cout << W - 2 << endl;
    } else if (W == 1) {
        cout << H -2 << endl;
    } else {
        cout << (H - 2) * (W - 2) << endl;
    }

    // int cnt[5][10] {};
    // rep(i, H) {
    //     rep(j, W) {
    //         reps(y, i-1, i+1) reps(x, j-1, j+1) {
    //             if (y < 0 || y >= H || x < 0 || x >= W) continue;
    //             ++cnt[y][x];
    //         }
    //     }
    // }
    //
    //
    // cout << endl;
    // rep(i, H) {
    //     rep(j, W) {
    //         cout << cnt[i][j] << ' ';
    //     }
    //     cout << endl;
    // }

    return 0;
}


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

void swap(int &x, int &y) {
    int t=x;
    x=y;
    y=t;
}

int main() {
    int x,y,z;
    scanf("%d%d%d", &x, &y, &z);

    swap(x,y);
    swap(x,z);

    printf("%d %d %d\n", x, y, z);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int x,y; 
    while(1){
      cin>>x>>y;
      if( x>y ){
         cout<<y<<" "<<x<<endl;}
     else if (x==0 && y==0) break;
     else cout<<x<<" "<<y<<endl;}
}



Measured memory_bytes: 3080