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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

template<typename T>
T gcd(T a, T b) {
    T r, temp;

    while(1) {
        if(a < b) {
            temp = a;
            a = b;
            b = temp;
        }
        if(b < 1) continue;

        while((r = a % b) != 0) {
            a = b;
            b = r;
        }
        return b;
    }
}

// 最小公倍数
template<typename T>
T lcm(T a, T b) {
    return (a/gcd(a, b))*b;
}

int main() {
    int N;
    cin >> N;
    vector<LL> T(N);
    REP(i, N) {
        cin >> T[i];
    }
    if(N == 1) {
        cout << T[0] << endl;
        return 0;
    }
    LL res = lcm(T[0], T[1]);
    FOR(i, 2, N) {
        res = lcm(res, T[i]);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define DIV 1000000007LL

u_long mod(u_long m, u_long n)
{
	u_long res = 1;

	while (n > 0) {
		if (n & 1) {
			res *= m;
			res %= DIV;
		}
		n >>= 1;
		m *= m;
		m %= DIV;
	}

	return res;
}

int main(void)
{
    u_long m, n;
	cin >> m >> n;
	cout << mod(m, n) << endl;
    return 0;
}

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

int main() {
  int w, n, a, b;
  char c;
  cin >> w >> n;
  vector<int> v(w);
  for (int i = 0; i < w; i++) {
    v[i] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> a >> c >> b;
    int tmp = v[a - 1];
    v[a - 1] = v[b - 1];
    v[b - 1] = tmp;
  }
  for (int i = 0; i < w; i++) {
    cout << v[i] << "\n";
  }
  return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N,M,V,P; cin >> N >> M >> V >> P;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    SORT(A); REVERSE(A);

    ll l = 0, r = N, n = (l+r)/2;
    while(r-l>1){
        bool flag;
        vector<ll> v(A);
        if(v[n] >= A[P-1]) flag = true;
        else if(v[n]+M < A[P-1]) flag = false;
        else{
            v[n] += M;
            ll res = M*(V-1);
            REP(i,min(P-1,V-1)){
                v[i] += M;
                res -= M;
            }
            RREP(i,N){
                if(i == n) continue;
                if(res <= 0 || v[i]>=v[n]) break;
                res -= min(M,v[n]-v[i]);
                v[i] += min(M,v[n]-v[i]);
            }
            flag = res>0 ? false : true;
        }
        if(flag) l = n;
        else r = n;
        n = (l+r)/2;
    }
    ll ans = r;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
//============================================================================
// Name        : abca110.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int N, M;
	int X, Y;
	cin >> N >> M >> X >> Y;
	vector<pair<int, int>> P(N + M);
	int xmax = -1000;
	int ymin = 1000;

	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		xmax = max(xmax, x);
	}
	for (int i = N; i < M + N; ++i) {
		int y;
		cin >> y;
		ymin = min(ymin, y);
	}

	if (xmax < ymin) {
		for (int i = X + 1; i <= Y; ++i) {
			if (xmax < i && i <= ymin) {
				cout << "No War" << endl;
				return 0;
			}
		}
	}
	cout << "War" << endl;


	return 0;
}


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

int main(){
    int H, W;
    int a[600][600], b[600][600];
    cin >> H >> W;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> a[i][j];
            b[i][j]=a[i][j];
        }
    }
    
    int sum[600], sum2[600]; //各行の和
    for(int i=0; i<H; i++){
        sum[i]=0;
        for(int j=0; j<W; j++){
            sum[i] += a[i][j];
        }
        sum[i] %=2;
        sum2[i]=sum[i];
    }

    int cnt =0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W-1; j++){
            if(a[i][j]%2==1){
                a[i][j]--;
                a[i][j+1]++;
                cnt++;
            }
        }
    }
    for(int i=0; i<H-1; i++){
        if(sum[i]%2==1){
            sum[i+1]=1-sum[i+1];
            cnt++;
        }
    }

    cout << cnt <<endl;

    for(int i=0; i<H; i++){
        for(int j=0; j<W-1; j++){
            if(b[i][j]%2==1){
                b[i][j]--;
                b[i][j+1]++;
                cout << i+1 << " " << j+1 << " " << i+1 << " " << j+2 << endl; 
            }
        }
    }
    for(int i=0; i<H-1; i++){
        if(sum2[i]%2==1){
            sum2[i+1]=1-sum2[i+1];
            cout << i+1 << " " << W << " " << i+2 << " " << W << endl;    
        }
    }
}

Measured memory_bytes: 4864
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

cost_0, cost_N = 0, 0

for i in range(M):
    if A[i] < X:
        cost_0 += 1
    else:
        cost_N += 1

if cost_0 < cost_N:
    print(cost_0)
else:
    print(cost_N)    

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

int main() {
	string N;
	cin >> N;
	bool is_good = false;

	if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) {
		is_good = true;
	}
	else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)) {
		is_good = true;
	}

	if (is_good) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int> vec(n);
    int count=0;
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    for(int i=0;i<n-1;i++){
        int check=i;
        int minimum=vec.at(i);
        for(int j=i;j<n;j++){
            if(minimum>vec.at(j)){
                minimum=vec.at(j);
                check=j;
            }
        }
        swap(vec.at(check),vec.at(i));
        if(check!=i){
            count++;
        }
    }
    for(int i=0;i<n;i++){
        if (i) cout<<" ";
        cout<<vec.at(i);
    }
    cout<<endl;
    cout<<count<<endl;
}


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

vector<int> divisor(long long N) {
    vector<int> ret;
    long long i;
    for (i = 1; i*i < N; i++) {
        if (N % i != 0) continue;
        ret.push_back(i);
        ret.push_back(N/i);
    }
    if (i*i == N) ret.push_back(i);
    return ret;
}

bool check(int N, int K, vector<int> &A) {
    vector<int> mod(A.size());
    vector<long long> plus_sum(A.size() + 1);
    for (int i = 0; i < A.size(); i++) {
        mod[i] = A[i]%N;
    }
    sort(mod.begin(), mod.end());
    for (int i = mod.size()-1; i >= 0; i--) {
        int tmp = (mod[i] == 0 ? 0 : N - mod[i]);
        plus_sum[i] = plus_sum[i+1] + tmp;
    }
    long long sum = 0;
    for (int i = 0; i <= mod.size(); i++) {
        if (i == 0) {
            if (plus_sum[0] <= K) return true;
        } else {
        sum += mod[i-1];
            if (max(sum, plus_sum[i]) <= K) {
                return true;
            }
        }
    }
    return false;
}

int main(void){
    int N, K; cin >> N >> K;
    vector<int> A(N);
    long long A_sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A_sum += A[i];
    }
    
    vector<int> divs = divisor(A_sum);
    
    int ans = 1;
    for (auto &i : divs) {
        if (check(i, K, A)) ans = max(i, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
s = gets.chomp

answer = 'Yes'

0.upto(s.size - 1) do |i|
  if i.even?
    if s[i] == 'L'
      answer = 'No'
      break
    end
  else
    if s[i] == 'R'
      answer = 'No'
      break
    end
  end
end

puts answer


Measured memory_bytes: 1788
x,b,z = input().split()
a=int(x)
c=int(z)
while b!="?":
    if b=="+":
        print(a+c)
    elif b=="-":
        print(int(a)-int(c))
    elif b=="*":
        print(a*c)
    elif b=="/":
        print(int(a/c))
    x,b,z = input().split()
    a=int(x)
    c=int(z)

Measured memory_bytes: 5596
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の標準入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		// 入力した整数の積が偶数かどうか
		if(a * b % 2 == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		sc.close();
	}
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

N %= 500;

if(A >= N) yes;
else no;

}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
    if a[i-1]<a[i] and a[i]<a[i+1]:
        cnt+=1
    elif a[i-1]>a[i] and a[i]>a[i+1]:
        cnt+=1
print(cnt)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n;cin >>n;
  vector<int> a(n), idx(n), ans(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i];  --a[i];
    idx[a[i]]=i;
  }
  for(int i = 0; i < n-1; ++i){
    if(idx[i]<idx[i+1])ans[i]=1;
  }
  int j=0, len = 0;
  for(int i = 0; i < n; ++i){
    if(ans[i]==1){++j;}
    else{len=max(len, j);j=0;}
  }
 
  cout << n-len -1<< endl;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  rep(i, H) rep(j, W) cin >> a[i][j];
  vector<P> from;
  vector<P> to;
  rep(i, H) rep(j, W - 1) {
    if(a[i][j] % 2 == 1) {
      from.push_back(make_pair(i, j));
      to.push_back(make_pair(i, j + 1));
      --a[i][j];
      ++a[i][j + 1];
    }
  }
  rep(i, H - 1) if(a[i][W - 1] % 2 == 1) {
    from.push_back(make_pair(i, W - 1));
    to.push_back(make_pair(i + 1, W - 1));
    --a[i][W - 1];
    ++a[i + 1][W - 1];
  }
  int n = from.size();
  cout << n << endl;
  rep(i, n) {
    cout << ++from[i].first << ' ';
    cout << ++from[i].second << ' ';
    cout << ++to[i].first << ' ';
    cout << ++to[i].second << endl;
  }
  return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  if (A == B) cout << C << endl;
  else if (A == C) cout << B << endl;
  else if (B == C) cout << A << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 3050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
using namespace std;
int n,m,k;
vector<string>ar(N);
int pr[15][N];
vector<int>row;
int on = 1;
int solve(vector<int>&hcut){
    int ans = sz(hcut);
    hcut.pb(n-1);
    int prev = - 1;
    int sum[15]={0};
    int u = ans;
    for(int j=0;j<m;j++){
        int fl = 0;
      	prev = -1;
       for(int i=0;i<sz(hcut);i++){
           int tell = 0;
           for(int l=prev+1;l<=hcut[i];l++)
            tell+=ar[l][j]-'0';
            if(tell>k)return 1e9;
            if(sum[i]+tell>k){
                memset(sum,0,sizeof(sum));
                ans++;
                fl = 1; break;
            }
         else sum[i]+=tell;
       //  if(u==0)cout<<sum[i]<<" f\n";
          prev = hcut[i];
       }
       j-=fl;
    }
    
  //	cout<<ans;
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    int ans = (n-1)*(m-1);
    for(int i=0;i<(1<<(n-1));i++){
        row.clear();
        for(int j=0;j<n-1;j++){
            if((on<<j)&i){
                row.pb(j);
            }
        }
      //	cout<<i<<" ";
        ans = min(ans,solve(row));
     //  cout<<"\n";
    }
    cout<<ans;
    
        return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = str(input())
dp = [0]*n
fl = [True]*k
for i in range(n):
    if t[i] == "r":
        h = p
    elif  t[i] == "s":
        h = r
    else:
        h = s
    if i < k:
        if i == 0:
            dp[i] = h
            fl[i%k-1] = False
        else:
            dp[i] = h + dp[i-1]
            fl[i%k-1] = False
    else:
        if t[i] == t[i-k]:
            if fl[i%k-1] == True:
                dp[i] = dp[i-1]+h
                fl[i%k-1] = False
            else:
                dp[i] = dp[i-1]
                fl[i%k-1] = True
        else:
            dp[i] = dp[i-1] + h
            fl[i%k-1] = False    
print(dp[-1])

Measured memory_bytes: 75176
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  cout<<"ABC";
  cout<<n<<endl;

  return 0;

}


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

int main() {
    int k, a, b, temp;
    cin >> k >> a >> b;
    temp = 0;
    while(temp + k <= b) temp += k;
    if(a <= temp) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3580
ans = []
while True:
  m, f, r = list(map(int, input().split(' ')))
  if m == -1 and f == -1 and r == -1:
    break
  if  m == -1 or f == -1:
    ans.append('F')
  elif 80 <= m+f:
    ans.append('A')
  elif 65 <= m+f < 80:
    ans.append('B')
  elif 50 <= m+f < 65:
    ans.append('C')
  elif 30 <= m+f < 50:
    if 50 <= r:
      ans.append('C')
    else:
      ans.append('D')
  else:
    ans.append('F')
for n in ans:
  print(n)


Measured memory_bytes: 5596
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

dist_max = 0
for i, (x, y) in enumerate(xy):
    dist = abs(x) + abs(y)
    if i == 0:
        parity = dist%2
    else:
        if dist%2 != parity:
            print(-1)
            exit()

    if parity == 0:
        x -= 1
        dist = abs(x) + abs(y)

    dist_max = max(dist_max, dist)
    xy[i] = [x, y]

d = []
d_i = 1
for i in range(40):
    if d_i > dist_max:
        break
    d.append(d_i)
    d_i *= 2
d = sorted(d, reverse = True)
if parity == 0:
    d.append(1)

print(len(d))
print(' '.join(map(str, d)))

for x, y in xy:
    ans = ''
    prev = 0
    for d_i in d:
        if prev == d_i and d_i == 1:
            ans += 'R'
            break
        if x+y < 0:
            if x-y < 0:
                ans += 'L'
                x += d_i
            else:
                ans += 'D'
                y += d_i
        else:
            if x-y < 0:
                ans += 'U'
                y -= d_i
            else:
                ans += 'R'
                x -= d_i
        prev = d_i
    print(ans)


Measured memory_bytes: 3316
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		int X = sc.nextInt()-1;
		int Y = sc.nextInt()-1;
		
		int[] ans = new int[N];
		
		for(int i=0; i<N; i++) {
			for(int j=i+1; j<N; j++) {
				int d = Math.min(j-i, Math.abs(j-Y) + 1 + Math.abs(i-X));
				ans[d]++;
			}
		}
		
		
		for(int i=1; i<N; i++)
			pw.println(ans[i]);
		pw.close();
		sc.close();
	}
}


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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll n, m;
	cin >> n >> m;
	cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2; 		
	return 0; 	
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = 7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        string s = to_string(n);
        int m = s.length();
        int num = 7LL%n;
        int mark[n]= {};
        for(int i=1;;i++)
        {
            if(!num)return cout<<i,0;
            if(mark[num])return cout<<-1,0;
            mark[num]++;
            num *= 10LL;
            num %= n;
            num += 7LL;
            num %= n;
        }
    }
    return 0;
}


Measured memory_bytes: 11428
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    s+='T';
    int x,y;
    cin >> x >> y;
    int n=s.size();
    int direction=0;//0はx方向、1はy方向
    int count=0;
    vector<int> X,Y;
    Y.push_back(0);
    for (int i=0; i<n; i++){
        if (s[i]=='F'){
            count++;
        } else {
            if (direction==0){
                X.push_back(count);
            }else{
                Y.push_back(count);
            }
            count=0;
            direction=1-direction;
        }
    }
    int x_dp[2][16001],y_dp[2][16001];
  for (int i=0;i<2;i++){
    for (int j=0; j<=16000; j++){
      x_dp[i][j]=0;
      y_dp[i][j]=0;
    }
  }

    x_dp[0][8000+X[0]]=1;
    for (int i=1; i<X.size(); i++){
        for (int j=0; j<=16000; j++){
            if (0<=j-X[i] && j-X[i]<=16000){
                if (x_dp[0][j-X[i]]==1)
                    x_dp[1][j]=1;
                }
            if (0<=j+X[i] && j+X[i]<=16000){
                if (x_dp[0][j+X[i]]==1){
                    x_dp[1][j]=1;
                }                                      
            }
        }
        for (int k=0; k<=16000; k++){
            x_dp[0][k]=x_dp[1][k];
            x_dp[1][k]=0;
        }
    }
    y_dp[0][8000]=1;
    for (int i=1; i<Y.size(); i++){
        for (int j=0; j<=16000; j++){
            if (0<=j-Y[i] && j-Y[i]<=16000 ){
              if (y_dp[0][j-Y[i]]==1){
                  y_dp[1][j]=1;
                }
                
            }
            if (0<=j+Y[i] && j+Y[i]<=16000){
                 if (y_dp[0][j+Y[i]]==1){
                    y_dp[1][j]=1;
                }
            }
        }
        for (int k=0; k<=16000; k++){
            y_dp[0][k]=y_dp[1][k];
            y_dp[1][k]=0;
        }
    }
    if (x_dp[0][x+8000]!=0 && y_dp[0][y+8000]!=0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

using namespace std;
typedef long long int llint;

struct Node {
	llint parent;
	llint depth;
	string state;
	vector<llint> children;
	Node():parent(-1),depth(0){
	}
};
struct faster_io{
	faster_io() {
		cin.tie(0);
		ios::sync_with_stdio(false);
	}
};

void set_depth(vector<Node> &Nodes, Node &node, int depth) {
	node.depth = depth;
	for (int i = 0; i < node.children.size(); i++) {
		set_depth(Nodes, Nodes[node.children[i]], depth + 1);
	}
}


int main() {
	llint const N_MAX = 100000;
	faster_io io;

	llint n;
	cin >> n;

	vector<Node> Nodes;
	Nodes.resize(N_MAX);

	for (llint i = 0; i < n; i++) {
		llint id, k;
		cin >> id >> k;
		Node &x = Nodes[id];
		for (llint j = 0; j < k; j++) {
			llint c;
			cin >> c;
			x.children.push_back(c);
			Nodes[c].parent = id;
		}
	}

	Node root;
	for (llint i = 0; i < n; i++) {
		Node &x = Nodes[i];
		if (x.parent == -1) {
			x.state = "root";
			root = x;
		}
		else if (x.children.size() == 0) {
			x.state = "leaf";
		}
		else {
			x.state = "internal node";
		}
	}

	set_depth(Nodes, root, 0);

	for (llint i = 0; i < n; i++) {
		Node x = Nodes[i];
		cout << "node " << i
			<< ": parent = " << x.parent
			<< ", depth = " << x.depth
			<< ", " << x.state
			<< ", [";
		for (llint j = 0; j < x.children.size(); j++)	{
			if (j != x.children.size() - 1) cout << x.children[j] << ", ";
			else cout << x.children[j];
		}
		cout << "]\n";
	}
}

Measured memory_bytes: 14444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<vector<pint>> vv;
    for(int i=0; i<n; i++){
        int a; cin>>a;
        vector<pint> voice;
        for(int j=0; j<a; j++){
            int x,y; cin>>x>>y;
            x--;
            voice.emplace_back(pint(x,y));
        }
        vv.emplace_back(voice);
    }
    int ans=0;
    for(int bit=0; bit<(1<<n); bit++){
        bool ok =true;
        for(int i=0; i<n; i++){
            if(bit&(1<<i))
            {
                for(auto w: vv[i])
                {
                    if((w.second==0)&&(bit&(1<<w.first))) ok=false;
                    if((w.second==1)&&!(bit&(1<<w.first))) ok=false;
                }
            }
        }
        if(ok){
            int cnt=0;
            for(int i=0; i<n; i++){
                if(bit&(1<<i)) cnt++;
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(void)
{
  char s[3]={};
  int i,fa=0,fb=0,fc=0;
  scanf("%s",s);
  for(i=0;i<3;i++)
  {
    if(s[i]=='a')
    {
      fa=1;
    }
    if(s[i]=='b')
    {
      fb=1;
    }
    if(s[i]=='c')
    {
      fc=1;
    }
  }
  if(fa==1 && fb==1 && fc==1)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
 
using namespace std;
 
int main()
{
	int x;
  	cin >> x;
  	if(x <= 599){
		cout << "8";
    }else if(600 <= x && x <= 799){
     	cout << "7"; 
    }else if(800 <= x && x <= 999){
     	cout << "6";
    }else if(1000 <= x && x <= 1199){
     	cout << "5";
    }else if(1200 <= x && x <= 1399){
     	cout << "4";
    }else if(1400 <= x && x <= 1599){
     	cout << "3";
    }else if(1600 <= x && x <= 1799){
     	cout << "2";
    }else if(1800 <= x && x <= 1999){
     	cout << "1";
    }
 
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

bool solve(int A[], int n, int p, int t) {
    if(A[p] == t) return true;
    else if(n-1 <= p) return false;
    else if(A[p] > t) return solve(A, n, p+1, t);
    else return solve(A, n, p+1, t) || solve(A, n, p+1, t-A[p]);
}

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

    int m;
    for(int i = 0; i < q; i++) {
        cin >> m;
        if(solve(A, n, 0, m)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 1000;
ll dp[N][N];

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

	int h, w;
	cin >> h >> w;

	dp[0][0] = 1;
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			char c;
			cin >> c;
			if (c == '.') {
				if (y > 0) dp[y][x] += dp[y-1][x];
				if (x > 0) dp[y][x] += dp[y][x-1];
				dp[y][x] %= MOD;
			} else {
				dp[y][x] = 0;
			}
		}
	}
	cout << dp[h-1][w-1] << '\n';
}


Measured memory_bytes: 8064
import math
import copy

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

sum = 0
for i, xy in enumerate(a):
    xi, yi = xy
    aa = copy.deepcopy(a)
    aa.pop(i)
    for xj, yj in aa:
        sum += math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)

print(sum * math.factorial(n - 1) / math.factorial(n))

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  int count = 0;
  for (int i = 0; i < c; i++) {
    if (b >= a) {
      ++count;
      b -= a;
    }
    else {
      break;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s;
    cin>>s;
    if(s[0]!='A'){
        cout<<"WA"<<endl;
    }else{
        int l = 2;
        int r = s.size()-2;
        
        int count = 0;
        for(int i=l;i<=r;i++){
            if(s[i]=='C')count++;
        }
        if(count!=1){
            cout<<"WA"<<endl;
        }else{
            int upper = 0;
            rep(i,s.size()){
                if(isupper(s[i]))upper++;
            }
            
            if(upper==2)cout<<"AC"<<endl;
            else cout<<"WA"<<endl;
        }
    }
}


Measured memory_bytes: 256
// O(N^2 * logN)

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1004;

struct Seg {
  int begin, end;

  Seg() {}
  Seg(int begin, int end)
    : begin(begin), end(end) {}

  bool operator < (const Seg &s) const {
    if(begin != s.begin) return begin > s.begin;
    return end < s.end;
  }
};

int main() {
  int N;
  int A[MAXN], B[MAXN];

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

    vector<Seg> v;
    for(int i = 0; i < N; ++i) {
      v.push_back(Seg(B[i]-A[i], B[i]));
    }
    sort(v.begin(), v.end());
    int res = 0;
    for(int i = 0; i < v.size(); ++i) {
      if(v[i].begin < 0) continue;
      ++res;
      for(int j = i+1; j < v.size(); ++j) {
        v[j].begin -= min( max(v[j].end - v[i].begin, 0),
                           v[i].end - v[i].begin );
      }
      sort(v.begin(), v.end());
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1208
#include <stdio.h>

int main(void){

  long n,y;
  scanf("%ld %ld", &n, &y);
  for (long i = 0; i <= n; i++) {
    for (long j = 0; i+j <= n; j++) {
      if (i*10000+j*5000+(n-i-j)*1000 == y) {
        printf("%ld %ld %ld\n", i, j, n-i-j);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");

  return 0;
}

Measured memory_bytes: 128
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void main() {
    int n, k;
    scan(n, k);
    auto p = readln.split.to!(int[]).sort();
    auto ans = p[0 .. k].sum();
    writeln(ans);
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2756
import sys
input=sys.stdin.readline

def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    
    bin_k=format(k,'b').zfill(50)
    l=50
    
    flag=False
    power=pow(2,l-1)
    ans=0
    for i in range(l):
        keta=l-i-1
        cnt=0
        for num in a:
            if (num>>keta)&1:
                cnt+=1

        if flag:
            ans+=max(cnt,n-cnt)*power
        
        else:
            if 2*cnt >= n and bin_k[i]=='1':
                flag=True
                ans+=cnt*power
          
            elif 2*cnt >= n:
                ans+=cnt*power
           
            elif bin_k[i]=='1':
                ans+=(n-cnt)*power
       
            else:
                ans+=cnt*power
        
        power//=2
    
    print(ans)
if __name__=='__main__':
    main()


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

typedef long long ll;
using namespace std;
const int INF = 1e9;
long long mod = 1000000000+7;
vector<vector<int> >g;
   //         int n,m;

    vector<vector<int> > grid(501,vector<int>(501,INF));
    vector<vector<int> > x(501,vector<int>(501,-1));
  long long  pow(long long  a, long long  b, long long m)
 {
        stack<int>k;
        int j = 128;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }


 int main(){
   ios_base::sync_with_stdio(0);cin.tie(NULL);
   // freopen("zeros.in","r",stdin);
    //freopen("pizza.out","w",stdout);

            int n;
            cin>>n;
           vector<int>v(2*n);
           for(int i = 0;i<2*n;++i)cin>>v[i];
           sort(v.begin(),v.end());
           int sum = 0;
           for(int i = 0;i<2*n;i+=2){

                sum += v[i];

           }
           cout<<sum<<endl;
                return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

const int MAX = 300002;
const int P = 1000000007; //shuoud be prime

long long fac[MAX], finv[MAX], inv[MAX];

void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % P;
        inv[i] = P - inv[P%i] * (P / i) % P;
        finv[i] = finv[i - 1] * inv[i] % P;
    }
}

long long COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % P) % P;
}

long long GCD(long long x, long long y){
	long long r=0;

	if( x<y ) swap(x, y);
	r = x % y;
	while(r!=0){
		x = y;
		y = r;
		r = x % y;
	}
    return y;
}

LL H, W, A, B;
int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> H >> W >> A >> B;
	COMBinit();

	LL ans = 0;
	ans = fac[(H-1)+(W-1)];
	ans *= finv[H-1];
	ans %= P;
	ans *= finv[W-1];
	ans %= P;

	for(int i=1; i<=B; i++){
		LL u = fac[(H-A-1)+(i-1)];
		u *= finv[H-A-1];
		u %= P;
		u *= finv[i-1];
		u %= P;
		LL v = fac[(A-1) + (W-i)];
		v *= finv[A-1];
		v %= P;
		v *= finv[W-i];
		v %= P;
		LL w = (u * v) % P;
		ans -= w;
		if(ans < 0){
			ans += P;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 10816
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

int test(vector<int> v,int C){
	vector<int> ter = v;
	
	int size = ter.size();
	bool flag = true;
	for(int i=0;i<size;++i,--size){
		flag = true;
		vector<int> next = ter;
		for(int j=0;j<size-1;++j){
			if( ter[j] == C || ter[j+1] == C ){
				next[j] = C;
			}else{
				flag = false;
			}
		}
		if( flag ){
			return i+1;
		}
		ter = next;
	}
	return INF;
}
void solve(){
	string str;
	cin >> str;
	int size = str.size();
	vector< int > v(size,0);
	for(int i=0;i<size;++i){
		int X = str[i]-'a';
		v[i] = X;
	}
	bool flag = true;
	for(int i=0;i<size-1;++i){
		if( v[i] != v[i+1] ){
			flag = false;
		}
	}
	if( flag ){
		cout << 0 << endl;
		return;
	}
	int ans = INF;
	for(int i=0;i<26;++i){
		ans = min(ans, test(v,i) );
	}
	cout << ans << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


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

int main() {
    int n,buf;
    int min = 1000000;
    int max = -1000000;
    long sum = 0;
    cin >> n;
    
    for(int i=0; i<n; i++) {
        cin >> buf;
        if(min > buf) {
            min = buf;
        }
        
        if(max < buf) {
            max = buf;
        }
        
        sum += buf;
    }
    
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>

#define PY "Yes\n"    // printf(PY);
#define PN "No\n"     // printf(PN);

int main()
{
    int n, ans;
    scanf("%d", &n);
    if(n<10)
        ans = n;
    else if(n>=10 && n<=99)
        ans = 9;
    else if(n>=100 && n<=999)
        ans = 9 + n-99;
    else if(n>=1000 && n<=9999)
        ans = 909;
    else if(n>=10000 && n<=99999)
        ans = n-9999 + 909;
    else
        ans = 90909;
        
    printf("%d\n", ans);
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_L 3000
string s, t;
i64 dp[2 * MAX_L][2 * MAX_L];
i64 prev_i[2 * MAX_L];
i64 prev_j[2 * MAX_L];

int main() {
    cin >> s >> t;
    REP(i, s.length() + 1) {
        REP(j, t.length() + 1) {
            dp[i][j] = 0;
        }
    }

    REP(i, s.length()) {
        REP(j, t.length()) {
            if (s[i] == t[j]) {
                chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            } else {
                chmax(dp[i + 1][j + 1], dp[i][j + 1]);
                chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            }
        }
    }

    string ans = "";
    i64 i = s.length(), j = t.length();
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) {
            i--;
        } else if (dp[i][j] == dp[i][j - 1]) {
            j--;
        } else {
            ans = s[i - 1] + ans;
            i--; j--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 140672
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
using namespace std;

const ll N = 1e5+5;
const ll MOD = 1e9+7;
vll adj[N];
map<pll,bool> Map;
bool vis[N];
ll comp = 1;
vll cc[N];
ll component[N];
void dfs(ll cur){
	vis[cur]=true;
	cc[comp].pb(cur);
	for(auto v:adj[cur]){
		if(!vis[v]){
			dfs(v);
		}
	}
}


int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	ll n,m,k;
	cin >> n >> m >> k;

	vector<pll> v1;
	vector<pll> v2;

	for(int i =1;i<=m;i++){
		ll u,v;
		cin >> u >> v;
		v1.pb(mp(u,v));
		adj[u].pb(v);
		adj[v].pb(u);
	}
	
	for(int i =1;i<=k;i++){
		ll u,v;
		cin >> u >> v;
		v2.pb(mp(u,v));
		Map[mp(u,v)]=true;
		Map[mp(v,u)] = true;
	}



	for(int i =1;i<=n;i++){
		if(!vis[i]){
			dfs(i);
			comp++;
		}
	}

	vll ans(n+1,0);
	for(int i =1;i<comp;i++){
	///	cout << i << "-> ";
		for(auto x:cc[i]){
			ans[x] = (ll)cc[i].size() - ((ll)adj[x].size()+1);
	//			cout << x << ' ';
			component[x] = i;
		}
	}


	for(int i = 0;i<k;i++){
		ll u = v2[i].f;
		ll v = v2[i].s;
		if(component[u] == component[v] && component[u] != 0){
			ans[u]--;
			ans[v]--;
		}
	}

	for(int i =1;i<=n;i++) cout << ans[i] << " ";cout<<endl;

	return 0;	
}

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

int main(){
	long long a, b, k;
	cin >> a >> b >> k;
	if (a >= k) cout << a - k << " " << b;
	else if (a + b >= k) cout << "0 " << b - k + a;
	else cout << "0 " << "0";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

typedef long long ll;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

const int MOD = 1000000007;
ll modPow(ll a, ll n, ll p) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}


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

    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    d.erase(unique(d.begin(),d.end()),d.end());
    cout << d.size() << endl;
}

Measured memory_bytes: 3540
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
string BinaryNum(int N)
{
        string S;
        while (N != 0)
        {
                if (N % 2 == 1)
                {
                        N--;
                        S = '1' + S;
                }
                else
                {
                        S = '0' + S;
                }
                N /= 2;
        }
        return S;
}

int main() //input->compute->output
{
        int N;
        cin >> N;

        vector<int> vec(N);
        rep(i, N) { cin >> vec[i]; }

        ll dp[100010];
        rep(i, N) { dp[i] = 1e9; }

        dp[0] = 0;
        dp[1] = abs(vec[1] - vec[0]);

        rep2(i, 0, N)
        {
                if (i+1<=N-1)
                {
                        dp[i+1] = min(dp[i+1], dp[i] + abs(vec[i + 1] - vec[i]));
                }

                if (i+2<=N-1)
                {
                        dp[i + 2] = min(dp[i + 2], dp[i] + abs(vec[i + 2] - vec[i]));
                }

        }

        cout << dp[N - 1] << endl;

        return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using ull = unsigned long long;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
const ll md = 1000000007;
vector<ll> fact(1e6 + 7), invfact(1e6 + 7);

ll fn(ll a, ll r, ll n, ll mod = md) {
    ll res = 1, x = r%mod;
    ll ans = 0;
    while(n) {
        if(n&1) ans = (x*ans + res)%mod;
        res = ((res*x)%mod + res%mod)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    ans = (ans*a)%mod;
    return ans;
}

ll nCr(ll n, ll r) {
    if(r == 0) return 1;
    ll num = fact[n];
    ll den = (invfact[r] % md *invfact[n-r] % md)%md;
    return (num*den)%md;
}

ll mul(ll a, ll b, ll mod = md) {
    ll res = (a%mod * b%mod)%mod;
    return res;
}

ll mulm(ll a, ll b, ll mod = md) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) r = (r+a)%mod;
        a = (a+a)%mod;
        b = b/2;
    }
    r %= mod;
    return r;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(ll x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll compgcd(ll n, vector<ll> const &primes) { 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<bool> &prime, vector<ll> &primes, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

void sieveGCD(ll lim, vector<ll> &tab, vector<ll> const &primes) {
    for(int  i = 1; i <= lim; i++) {
        tab[i] = i;
    }
    for(int i = 0; i<primes.size() && primes[i] <= lim; i++) {
        tab[primes[i]] = primes[i]-1;
        for(int j = 2; primes[i]*j <= lim; j++) {
            tab[primes[i]*j] = (tab[primes[i]*j]/primes[i])*(primes[i]-1);
        }
    }
}

ll calc(ll a, ll b, ll r) {
    ll total = r+1;
    ll tmp = a*b;
    ll count = (r/tmp)*max(a,b) + max(a,b);
    if((r/tmp)*tmp + max(a,b) > r) {
        count -= ((r/tmp)*tmp + max(a,b) - r - 1);
    }
    total -= count;
    return total;
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin >> a >> b;
    cout << (a*b)/__gcd(a,b) << "\n";
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

using vi = vector<int>;
using p = pair<int, int>;
using ll = long long;

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

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

  map<char, vi> m;
  for (int i = 0; i < s.length(); ++i) {
    if (m.find(s[i]) == m.end())
      m[s[i]] = vi();
    m[s[i]].push_back(i+1);
  }
  int before = -1;
  ll count = 0;

  for (const auto& e : t) {
    if (m.find(e) == m.end()) {
      OUT(-1);
      return 0;
    }
    bool flag = true;
    auto it = upper_bound(ALL(m[e]), before);
    if (it == m[e].end()) {
      before = m[e][0];
      ++count;
    } else {
      before = *it;
    }
    // for (const auto x : m[e]) {
    //   before
    //   if (before < x) {
    //     before = x;
    //     flag = false;
    //     break;
    //   }
    // }
    // if (flag) {
    //   before = m[e][0];
    //   ++count;
    // }
  }
  OUT((ll)before + count * s.length());

  return 0;
}


Measured memory_bytes: 1216