akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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 T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N;
string s;
int main() {
	cin >> N;
	cin >> s;
	lint cnt = 0;
	REP(i, N) {
		if (s[i] == 'R') cnt++;
	}
	lint _cnt = 0;
	REP(i, cnt) {
		if (s[i] == 'W') _cnt++;
	}
	cout << _cnt << endl;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

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

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'o
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
    cin>>n>>m;
    int sum = 0;
    for(int i=0; i<m; i++)
    {
        int e;
        cin>>e;
        sum+=e;
    }
    if(sum > n)
        cout<<-1;
    else
        cout<<n-sum;
	return 0;
}

Measured memory_bytes: 3652
/**
 * @author yuzining
 * @date 2020/07/12 19:06
*/

#ifdef local
#include "D:\vscode\acm\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

int f[200005];
int p[2][200005];

void Main() {
  for(int i = 1; i < 200005; i++) {
    f[i] = f[i % __builtin_popcount(i)] + 1;
  }
  int n; cin >> n;
  string s; cin >> s;
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == '1') cnt++;
  }
  if(cnt == 0) {
    for(int i = 0; i < n; i++) cout << "1\n";
    return;
  }
  p[0][0] = p[1][0] = 1;
  int s1 = 0, s2 = 0;
  for(int i = 1; i < 200005; i++) {
    if(cnt != 1) {
      p[0][i] = p[0][i - 1] * 2 % (cnt - 1);
    }
    p[1][i] = p[1][i - 1] * 2 % (cnt + 1);
  }
  for(int i = 0; i < n; i++) {
    if(cnt != 1) {
      s1 = (s1 * 2 + s[i] - '0') % (cnt - 1);
    }
    s2 = (s2 * 2 + s[i] - '0') % (cnt + 1);
  }
  for(int i = 0; i < n; i++) {
    const int idx = n - i - 1;
    if(s[i] == '1') {
      if(cnt == 1) {
        cout << 0 << '\n';
      } else {
        int cur = s1 - p[0][idx];
        if(cur < 0) cur += cnt - 1;
        cout << f[cur] + 1 << '\n';
      }
    } else {
      int cur = s2 + p[1][idx];
      if(cur >= cnt + 1) cur -= cnt + 1;
      cout << f[cur] + 1 << '\n';
    }
  }
}

Measured memory_bytes: 5968
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

map<ll,int> prf(ll n){
  map<ll,int> ret;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
     ret[i]++;
      n/=i;
    }
  }
  if(n!=1){
    ret[n]=1;
  }
  return ret;
}


int main(){cout<<fixed<<setprecision(10);
		   //p素因数分解してn以上
           ll n,p;
           cin>>n>>p;
           map<ll,int> a;
           a=prf(p);
           ll ans=1;
           for(auto v:a){
            while(v.second>=n){
             ans*=v.first; 
              v.second-=n;
            }
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 3616
k, a, b = [int(n) for n in input().split(" ")]

f = False

if a < b-1:
    f = True

if f == False:
    print(k + 1)

if f == True:
    if k <= a:
        print(k + 1)
        exit()
    k -= a - 1
    r = (b - a) * int(k / 2)
    if k % 2 == 1:
        print(r + a + 1)
    else:
        print(r+a)


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

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_A

int LargestSquare(int H,int W,vector<vector<int> > c) {
  vector<vector<int> > dp(H,vector<int>(W,0));
  int maxi = 0;
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      if( c[i][j] ) continue;
      int mini = INT_MAX;
      mini = min(mini,(i-1>=0)?dp[i-1][j]:0);
      mini = min(mini,(j-1>=0)?dp[i][j-1]:0);
      mini = min(mini,((i-1>=0)&&(j-1>=0))?dp[i-1][j-1]:0);
      dp[i][j] = mini + 1;
      maxi = max(maxi,dp[i][j]);
    }
  }
  return maxi * maxi;
}

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int> > c(H,vector<int>(W));
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin >> c[i][j];
    }
  }
  cout << LargestSquare(H,W,c) << endl;
  return 0;
}

Measured memory_bytes: 24236
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String N = input.next();
        if (N.contains("7")) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
    }
}

Measured memory_bytes: 35632
N, K = map(int, input().split())
border = []
inx = 0
while K > 1:
  border.append(K)
  K = (K + 1) >> 1
  inx += 1
border.append(1)
border.reverse()
pre = 1
cnt = []
for i in range(1, len(border)):
  if N < border[i]:
    cnt.append(N - pre + 1)
    break
  elif N == border[i]:
    cnt.append(border[i] - pre)
    cnt.append(1)
    break
  else:
    cnt.append(border[i] - pre)
    pre = border[i]
if N >= border[-1]:
  cnt.append(N - border[-1] + 1)
ans = 0
for c in cnt:
  ans += c * 0.5 ** inx
  inx -= 1
print(ans/N)

Measured memory_bytes: 9420
n = int(input())

MAXVAL = 10**5
a = [MAXVAL] * n

b = list(map(int, input().split()))
for i in range(n-1):
  a[i] = min(a[i], b[i])
  a[i+1] = min(a[i+1], b[i])
    
print(sum(a))

Measured memory_bytes: 3060
/**
     **author : _KMS_
     **created : 27-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =2e5+10,MOD=998244353;
typedef long long ll;
int arr[M];
int dp[M];
int main() {
   
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  cin>>arr[i];
 // dp[2]=abs(arr[1]-arr[2])
 arr[0]=arr[1];
  for(int i=2;i<=n;i++)
  {
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<dp[n]<<"\n";

  return 0;
} 

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

map<int,int>vis;
int a[200005],b[200005];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		vis[a[i]]++;
	}
	int m;
	bool ok = true;
	scanf("%d",&m);
	for(int i = 1;i <= m;i++){
		scanf("%d",&b[i]);
	}
	for(int i = 1;i <= m;i++){
		if(vis[b[i]] > 0){
			vis[b[i]]--;
		}
		else ok = false;
	}
	if(ok) printf("YES");
	else printf("NO");
}

Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		
		int b = scan.nextInt();
		
		int c = scan.nextInt();
		
		if(a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}

}


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

int main() {
  long long n; cin >> n;
  long long ans = 1LL << 62;
  for(long long i = 1; i * i <= n; ++i) {
    if(n % i == 0) {
      ans = min(ans, i + n / i);
    }
  }
  cout << ans - 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC60(void);
void ABC61(void);
void ABC62(void);
void ABC63(void);
void ABC64(void);
void ABC65(void);
void ABC66(void);
void ABC67(void);
void ABC68(void);
void ABC69(void);

int main(void){
    ABC65();
}

void ABC65(){
    int n,i,a,pro=0;
    cin>>n;
    vector<int> vec(n),det(n,0);
    for(i=0;i<n;i++){
        cin>>vec[i];
    }
    a=1;
    while(1){
        pro++;
        det[a-1]++;
        if(det[a-1]==2){
            pro=-1;
            break;
        }
        a=vec[a-1];
        if(a==2)break;
    }
    cout<<pro<<endl;
}

Measured memory_bytes: 1024
function Main(input){
  input = input.trim().split('\n').map(x=>x.split(' ').map(y=>parseInt(y)));
  const inf = 100000000
  var ans = inf;
  for (let i=0;i<2**input[0][0];i++){
    var toRead = binary(i,input[0][0]);
    var skill = Array(input[0][1]).fill(0);
    var price = 0
    for (let j=0;j<toRead.length;j++){
      if (toRead[j] == '1'){
        price += input[j+1][0];
      }
    }
    if (price < ans){
      for (let j=0;j<toRead.length;j++){
        if (toRead[j] == '1'){
          for (let k=0;k<skill.length;k++){
            skill[k] += input[j+1][k+1];
          }
        }
      }
      var ok = 1
      for (let j=0;j<skill.length;j++){
        if (skill[j] < input[0][2]){
          ok = 0;
          break;
        }
      }
      if (ok == 1){
        ans = price;
      }
    }
  }
  if (ans == inf){
    ans = -1;
  }
  console.log(ans)
}

function binary(num, digits){
  var a = num.toString(2);
  var l = a.length
  for (let j=0;j < digits - l;j++){
    a = '0' + a;
  }
  return a
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(void){
    int h,n;
    cin >> h >> n;
    bool check = false;
    long long int sum = 0;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        sum += a;
        if(sum >= h){
            check = true;
            break;
        }
    } 
    if(check)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = input()
s = int(n)
l = len(n)
if l == 1:
    print(s)
if l == 2:
    print(9)
if l == 3:
    print(9+s-99)
if l == 4:
    print(909)
if l == 5:
    print(9+900+s-9999)
if l == 6:
    print(90909)

Measured memory_bytes: 3060
#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(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int 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(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(vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            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; }



int main(int argc, char const *argv[]) {
    int n; cin>>n;
    string s;
    cin >> s;
    s.push_back('.');
    int ans = 0;
    rep(i,n) {
        if (s[i]!=s[i+1]) ans++;
    }

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

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,L;
    cin >> N >> L;
    vector<ld> T(N);
    rep(i,N){
        cin >> T[i];
    }
    ld resx=0,resy=0;
    rep(i,N){
        rep(j,i){
          	resx+=(N-2+2*(j-i+1))*cos((PI*(T[i]+T[j])/L));resy+=(N-2+2*(j-i+1))*sin(PI*(T[i]+T[j])/L);
        }
    }
    cout << fixed << setprecision(10) << resx*6/(N*(N-1)*(N-2)) << ' ' << resy*6/(N*(N-1)*(N-2)) << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


Measured memory_bytes: 4256
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int val[1 << 12], deg[1 << 12][12];
signed main()
{
	int n, m, x, c[12], a[12][12], ans = 1 << 30;
	scanf("%d%d%d", &n, &m, &x);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &c[i]);
		for(int j = 0; j < m; ++j)
		{
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 0; i < (1 << n); ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			if(i & (1 << j))
			{
				val[i] += c[j];
				for(int k = 0; k < m; ++k)
				{
					deg[i][k] += a[j][k];
				}
			}
		}
		bool isacc = true;
		for(int j = 0; j < m; ++j)
		{
			isacc &= deg[i][j] >= x;
		}
		if(isacc)
		{
			ans = min(ans, val[i]);
		}
	}
	printf("%d\n", ans == (1 << 30) ? -1 : ans);
}



Measured memory_bytes: 4024
#include<stdio.h>

#define M 100000

int partition(int *A, int p, int r){
  int x,i,j,z;
  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      z = A[i];
      A[i] = A[j];
      A[j] = z;
    }
  }
  z = A[i + 1];
  A[i + 1] = A[r];
  A[r] = z;
  return i+1;

}

int n;
int A[M];

int main(){
  int i,r;
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  r = partition(A,0,n - 1);

   for(i = 0; i < n; i++){
    if(i == r) printf("[%d] ",A[i]);
    else if(i == n - 1) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);

int h=scan.nextInt();
int a=scan.nextInt();

int sum=0;
  if(h%a==0){
    sum=h/a;
  }else{
    sum=h/a+1;
  }
  System.out.println(sum);
}
}


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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int a;
	cin >> a;
	cout << a + a * a + a * a * a;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = N / (A + B);
  ans *= A;
  N %= (A + B);
  ans += min(N, A);
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)

int n, m;
int S[3];

int toC(int a, int b, int c) {
	if (!a && !b)return 0;
	if (c & 1)return toC(a >> 1, b >> 1, c >> 1);
	if (b & 1)return toC(c >> 1, b >> 1, a >> 1) + toC((a | b | c) >> 1, 0, 0) + 1;
	if (a & 1)return toC(a >> 1, b >> 1, c >> 1) + 2 * toC((a | b | c) >> 1, 0, 0) + 2;
}

int main(){
	while (scanf("%d%d", &n, &m), n | m){
		rep(i, 3)S[i] = 0;
		rep(t, 3){
			int c;
			scanf("%d", &c);
			rep(i, c){
				int a;
				scanf("%d", &a);
				S[t] |= 1 << a - 1;
			}
		}
		int ans = std::min(toC(S[0], S[1], S[2]), toC(S[2], S[1], S[0]));
		printf("%d\n", ans <= m ? ans : -1);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

const int N=1e5+100;
using namespace std;

typedef long long ll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;

int main()
{
    int n,m;
    cin>>n>>m;
    string s;
    s=n<=m?"unsafe":"safe";
    cout<<s;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
using namespace std;
long long N, K, A[1 << 18];
int main() {
cin >> N >> K;
for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = K + 1; i <= N; i++) {
if (A[i - K] < A[i]) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}

Measured memory_bytes: 4584
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		new Main().main();
	}
	void main() {
		Scanner sc = new Scanner(System.in);
		
		long[][] dp = new long[11][1001];
		dp[0][0] = 1;
		for(int j=1;j<=1000;j++) {
			dp[0][j] = 0;
		}
		for(int d=0;d<=100;d++) {
			for(int i=10;i>=1;i--) {
				for(int j=d;j<=1000;j++) {
					dp[i][j] += dp[i-1][j-d];
				}
			}
		}
		while(true) {
			int n = sc.nextInt();
			int s = sc.nextInt();
			if(n + s == 0) break;
			System.out.println(dp[n][s]);
		}
	}
}


Measured memory_bytes: 27144
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, yy;
  cin >> n >> yy;
  yy /= 1000;
  REP(x, 0, n + 1) {
    REP(y, 0, n - x + 1) {
      int z = n - x - y;
      if (10 * x + 5 * y + z == yy) {
	cout << x << " " << y << " " << z << "\n";
	return 0;
      }
    }
  }
  cout << "-1 -1 -1\n";
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
box = Array.new(n+1, 0)

n.downto(1) do |i|
    sum = 0
    2.upto(n) do |j|
        break if i * j > n
        sum ^= box[i * j]
    end
    box[i] = a[i-1] ^ sum
end

box.map!.with_index{|e, i| e == 1 ? i : nil}.compact!
puts box.size, box.join(" ")

Measured memory_bytes: 21124
x,k,d = map(int,input().split())
x = abs(x)
n = x//d
if n <= k :
    x -= d*n
    count = k-n+2
    if count % 2 == 0 :
        now = x
    else :
        now = d-x
else :
    now = x - k*d

print(abs(now))


Measured memory_bytes: 9168
#include<iostream>
#include<deque>
#include<cmath>
#include<cstring>
#include<map>
#include<algorithm>
#include<vector>
#include<ios>
#include<sstream>
#include<locale>
using namespace std;
#define ive(cris) int long long 
#define in(out) long double
#define INF 100000007
int main(){
  int a,b;
  cin>>a>>b;
  if(a+b>=24){
    cout<<a+b-24<<'\n';
  }
  else{
    cout<<a+b<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

char s[15];

signed main() {
	scanf("%s", s);
	if (s[0] == 'Y')
	if (s[1] == 'A')
	if (s[2] == 'K')
	if (s[3] == 'I')
		return puts("Yes"), 0;
	return puts("No"), 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

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

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

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

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> G(N + 2, 0);
	for (int i = 0; i < M; ++i) {
		int L, R;
		cin >> L >> R;
		G[L]++;
		G[R + 1]--;
	}
	for (int i = 1; i < N + 2; ++i) {
		G[i] += G[i - 1];
	}
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		ans += (G[i] == M);
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    const string pattern[] = {"SS", "SW", "WS", "WW"};
    
    rep(i, 4) {
        vector<char> ans(n + 1, '*');
        ans[n] = '\0';
        rep(ii, pattern[i].length()) ans[ii] = pattern[i][ii];
        bool correct;
        
        reps(ii, 1, n - 1) {
            if (
                ((s[ii] == 'o') && (ans[ii] == 'S')) ||
                ((s[ii] == 'x') && (ans[ii] == 'W'))
            ) {
                ans[ii + 1] = ans[ii - 1];
            }
            else {
                ans[ii + 1] = ((ans[ii - 1] == 'S') ? 'W' : 'S');
            }
        }
        
        reps(ii, n - 1, n + 1) {
            int l = ((ii == 0) ? n - 1 : ii - 1);
            int c = ii % n;
            int r = (ii + 1) % n;
            
            if (
                ((ans[c] == 'S') && (s[c] == 'o')) ||
                ((ans[c] == 'W') && (s[c] == 'x'))
            ) {
                correct = (ans[l] == ans[r]);
            }
            else {
                correct = (ans[l] != ans[r]);
            }
            
            if (!correct) {
                break;
            }
        }
        
        if (correct) {
            printf("%s\n", &ans[0]);
            return 0;
        }
    }
    
    printf("%d\n", -1);
    return 0;
}


Measured memory_bytes: 640
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i,n){
		cin >> l[i];
	}
	sort(l.rbegin(),l.rend());
	int sum = 0;
	rep(i,k){
		sum += l[i];
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

typedef vector<vector<int>> vv;

int hashp(int i, int j){
    return i*100 + j;
}

void bfs(const vv& table, vv& is_visited, int si, int sj) {
    queue<int> q;
    q.push(hashp(si,sj));
    while(!q.empty()) {
        int hash_value = q.front();
        q.pop();
        int i = hash_value/100;
        int j = hash_value%100;

        if(i >= table.size() || i < 0 || j >= table[0].size() || j < 0)
            continue;
        if(!table[i][j])
            continue;
        if(is_visited[i][j])
            continue;
        is_visited[i][j] = 1;
        q.push(hashp(i+1,j));
        q.push(hashp(i-1,j));
        q.push(hashp(i,j+1));
        q.push(hashp(i,j-1));
        q.push(hashp(i+1,j+1));
        q.push(hashp(i+1,j-1));
        q.push(hashp(i-1,j+1));
        q.push(hashp(i-1,j-1));
        // cout << "pushed" << endl;
    }
    return;
}

int main(){
    int w,h;
    while(cin >> w >> h) {
        if (w == 0 && h ==0)
            break;
        vector<vector<int>> table;
        vector<vector<int>> is_visited;
        rep(i, h) {
            vector<int> tmp(w, 0);
            table.push_back(tmp);
            is_visited.push_back(tmp);
            rep(j, w) {
                cin >> table[i][j];
            }
        }
        int count = 0;
        rep(i, h) {
            rep(j, w) {
                if(table[i][j] == 1 && is_visited[i][j] == 0) {
                    count++;
                    bfs(table, is_visited, i, j);
                }
            }
        }
        cout << count << endl;
    }
}



Measured memory_bytes: 3112
def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x:x[1])
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            return False
    return True

print('Yes' if main() else 'No')


Measured memory_bytes: 31808
#include <bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

bool isprime(int n){
  if (n==1) return false;
  else if(n==2) return true;
  else if(n%2==0) return false;
  else{
    for(int i=3;i*i<=n;i+=2){
      if(n%i==0) return false;
    }
    return true;
  }
}

int Q;
const int maxr=1e5+10;
int a[maxr];
int S[maxr];

int main(){
  cin >> Q;
  for(int i=1;i<maxr;i+=2){
    if(isprime(i)&&isprime((i+1)/2)) a[i]=1;
  }
  for(int i=0;i<maxr;i++){
    S[i+1]=S[i]+a[i];
  }
  vector<int> ans(Q);
  rep(i,Q){
    int l,r;
    cin >> l >> r;
    ans[i]=S[r+1]-S[l];
  }
  rep(i,Q){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  string s,t=""; cin>>s;
  ll n=s.length(),ans=0,cons=0;
  rep(i,n){
    if(i<n-1 && s[i]=='B' && s[i+1]=='C'){
      t=t+"D";
      i++;
    }else{
      t=t+s[i];
    }
  }
  rep(i,t.length()){
    if(t[i]=='A'){
      cons++;
    }else if(t[i]=='D'){
      ans+=cons;
    }else{
      cons=0;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 1436
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;

int main(){
    cout << fixed << setprecision(6);
    int n; cin >> n;
    vector<int> o(n);
    for (int i = 0; i < n; i++)
    {
        cin >> o[i];
    }
    int sum=0;
    for (int i = 0; i <n; i++)
    {

        for (int j = i+1; j < n; j++)
        {
            sum+=o[i]*o[j];
        }
        
    }
    cout << sum << endl;
    
    return 0;
}

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

using namespace std;

#define int long long

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(args...) { string _s = #args; replace(ALL(_s), ',', ' '); stringstream ss(_s); cerr << endl;_debug(ss, args); }
#define _rg auto it = next(v.begin()); it != v.end(); it++
#define _input ostream& operator <<(ostream& out

template<typename T, typename U>
_input, const pair<T, U>& p) {
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}

#define cont(c) template<typename T> _input, const c<T>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}
				
#define cont2(c) template<typename T, typename U> _input, const c<T, U>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}

cont(vector) cont(set) cont(multiset) cont(queue) cont2(map)

template<typename T, size_t n, typename= enable_if_t<!is_same<T, char>::value>>
_input, const T(&v)[n]) {
	if (n == 0) return out;
	out << "[" << v[0];
	for (int i = 1; i < (int)n; i++) out << ", " << v[i];
	out  << "]"; return out;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T &arg) {
	string name; ss >> name;
	cerr << name << " = " << arg << endl;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T& arg, const Ts&... args) {
	string name; ss >> name; 
	cerr << name << " = " << arg << ", ";
	if (is_class<T>::value || is_array<T>::value) cerr << endl;
	_debug(ss, args...);
}

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX/2;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;
	
	int x[5];
	for (int& a: x) cin >> a;
	
	for (int i = 0; i < 5; i++) {
		if (!x[i]) {
			cout << i+1 << endl;
			return 0;
		}
	}
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 3612
h,w=map(int,input().split())

M=[]
for i in range(h):
    M.append(input())

L=[]
for j in range(h):
    Lj=[]
    for i in range(w):
        if M[j][i]=="#":
            Lj.append(0)
        elif i==0:
            Lj.append(1)
        else:
            Lj.append(Lj[i-1]+1)
    L.append(Lj)
R=[]
for j in range(h):
    Rj=[]
    for i in range(w):
        if M[j][w-1-i]=="#":
            Rj.append(0)
        elif i==0:
            Rj.append(1)
        else:
            Rj.append(Rj[i-1]+1)
    R.append(Rj)   
U=[]
for i in range(w):
    Ui=[]
    for j in range(h):
        if M[j][i]=="#":
            Ui.append(0)
        elif j==0:
            Ui.append(1)
        else:
            Ui.append(Ui[j-1]+1)
    U.append(Ui)
D=[]
for i in range(w):
    Di=[]
    for j in range(h):
        if M[h-1-j][i]=="#":
            Di.append(0)
        elif j==0:
            Di.append(1)
        else:
            Di.append(Di[j-1]+1)
    D.append(Di)

s=0
for i in range(w):
    for j in range(h):
        s=max(s,L[j][i]+R[j][w-1-i]+U[i][j]+D[i][h-1-j]-3)

print(s)

Measured memory_bytes: 186408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int N=4100,mod=998244353;
int ksm(int x,int k)
{
	int s=1;for(;k;k>>=1,x=1ll*x*x%mod)
				if(k&1) s=1ll*s*x%mod;return s;
}
int n,jc[N],bl,rd,dp[N][N],ans;
char s[N];
void add(int &x,int y) {x+=y;if(x>=mod) x-=mod;}
int C(int n,int k) {return 1ll*jc[n]*ksm(jc[k],mod-2)%mod*ksm(jc[n-k],mod-2)%mod;}
void Get(int i,int &rd,int &bl)
{
	if(s[i]=='1') rd++,bl++;
	else if(s[i]=='0') rd+=2;
	else bl+=2;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);jc[0]=1;
	for(int i=1;i<=n*2;i++) jc[i]=1ll*jc[i-1]*i%mod;
	for(int i=1;i<=n;i++) Get(i,rd,bl);

	dp[0][0]=1;
	for(int i=0;i<n;i++)
		for(int r=0;r<=i;r++)
			if(dp[i][r])
			{
				int sr=r,sb=i-r;
				Get(i+1,sr,sb);
				if(sr) add(dp[i+1][sr-1],dp[i][r]);
				if(sb) add(dp[i+1][sr],dp[i][r]);
			}
	for(int r=0;r<=n;r++)
		add(ans,1ll*dp[n][r]*C(n,r)%mod);
	cout<<ans<<endl;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }


ll dp0[110][4],dp1[110][4];

void solve(){
    string s;
    ll k;
    cin>>s>>k;
    ll n=s.size();
    ll a[200];
    rep(i,n) a[i]=s[i]-'0';
    dp0[0][0]=1;

    rep(i,n){
        rep(j,k+1){
            if(a[i]==0){
                dp0[i+1][j]+=dp0[i][j];
                dp1[i+1][j]+=dp1[i][j];
                if(j==k) continue;
                dp1[i+1][j+1]+=dp1[i][j]*9;
            }
            else{
                dp1[i+1][j]+=dp1[i][j];
                dp1[i+1][j]+=dp0[i][j];
                if(j==k) continue;
                dp1[i+1][j+1]+=dp1[i][j]*9;
                dp0[i+1][j+1]+=dp0[i][j];
                dp1[i+1][j+1]+=dp0[i][j]*(a[i]-1);

            }

        }
    }
    cout<<dp0[n][k]+dp1[n][k]<<endl;
    

}


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

    solve(); 


    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int main()
{
	int a=read(),b=read(),c=read();ll k;
	cin>>k;
	if(k&1LL)
	cout<<b-a;
	else cout<<a-b;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using Int = long long;
Int a(Int n) { return (1LL << (n + 2)) - 3; }
Int p(Int n) { return (1LL << (n + 1)) - 1; }
Int f(Int N, Int X) {
	if (N == 0) return X > 0;
	else if (X <= 1 + a(N - 1)) return f(N - 1, X - 1);
	return p(N - 1) + 1 + f(N - 1, X - 2 - a(N - 1));
}
int main() {
	Int N, X;
	cin >> N >> X;
	cout << f(N, X) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>
#include <algorithm>
 
using namespace std;
 
double calcDist(double x, double y) {
    return sqrt(x * x + y * y);
}
 
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
 
    long long a;
    cin >> a;
    long long ans = (a/11) * 2;
    a = a%11;
    if(a == 0) cout << ans << endl;
    else if(a <= 6) cout << ans+1 << endl;
    else cout << ans+2 << endl;
 
    return 0;
}

Measured memory_bytes: 256
using System;
public class Hello{
    static int Sum(int n){
        int ans = 0;
        while(n > 0){
            ans += n % 10;
            n /= 10;
        }
        
        return ans;
    }
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int ans = int.MaxValue;
        for(var i = 1;i < n;i++){
            int j = n - i;
            ans = Math.Min(ans,Sum(i) + Sum(j));
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  string S;
  cin>>N>>S;
  int ok=0,ng=N/2+1;
  while(ng-ok>1){
    int n=(ok+ng)/2;
    set<string> s;
    for(int i=n;i+n<=N;i++){
      s.insert(S.substr(i-n,n));
      if(s.count(S.substr(i,n))){
        ok=n;
        goto home;
      }
    }
    ng=n;
    continue;
    home:;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 7668
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int cnt[128];
int main()
{
	memset(cnt, 0, sizeof(cnt) );
	int ch = 0;
	string in;
	cin >> in;
	for(int i = 0; i < (int)in.length(); i++) cnt[(int)in[i]]++;
	bool ans = true;
	for(int i = 0; i < 128; i++) {
		if(cnt[i] == 1) ans = false;
		else if(cnt[i] == 2) ch++;
	}
	if(ans && ch == 2) cout << "Yes" << endl;
	else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x <= 3){
        ans += 400000 - x * 100000;
    }
    if(y <= 3){
        ans += 400000 - y * 100000;
    }
    if(x * y == 1){
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;cin >> n >> m;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
    	a[i]=-2;
    }
    pp b[m];map<ll,ll> mp;
    for (int i = 0; i < m; ++i)
    {
    	cin >> b[i].first >> b[i].second;b[i].first--;
    	if(mp.find(b[i].first)!=mp.end() and mp[b[i].first]!=b[i].second){cout << -1;return 0;}
    	mp[b[i].first]=b[i].second;
    }
    sort(b,b+m);
    if(n==1)
    {
    	for (int i = 0; i < m; ++i)
    	{
    		a[b[i].first]=b[i].second;
    	}
    	if(m==0)a[0]=0;
    	cout << a[0];
    	return 0;
    }
    if(b[0].first==0 and b[0].second==0){cout << -1;return 0;}
    for (int i = 0; i < m; ++i)
    {
    	a[b[i].first]=b[i].second;
    }
    ll t=1;
    if(a[0]!=-2)t=0;
    for (int i = 0; i < n; ++i)
    {
    	if(a[i]==-2)
    	{
    		if(t){a[i]=1;t=0;}
    		else a[i]=0;
    	}
    }
    for (int i = 0; i < n; ++i)
    {
    	cout << a[i];
    }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  int t = N, c = 0;
  while (t > 0) c += t % 10, t /= 10;
  if (N % c == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = int(3e3 + 5);

int dp[MAX_N][MAX_N]; // dp[i][j] sのi文字目,tのj文字目まで見たときの最長共通部分列
string s, t;

int lcs() {
    for (int i = 0; i <= s.size(); i++) fill(dp[i], dp[i] + t.size() + 1, 0);
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }
    return dp[s.size()][t.size()];
}

string get_lcs() {
    int i = s.size(), j = t.size();
    string res = "";
    while (i > 0 && j > 0) {
        if (dp[i][j - 1] == dp[i][j]) {
            j--;
        } else if (dp[i - 1][j] == dp[i][j]) {
            i--;
        } else {
            res += s[i - 1];
            i--;
            j--;
        }
    }
    reverse(res.begin(), res.end());
    return res;
}

int main() {
    cin >> s >> t;
    lcs();
    cout << get_lcs() << endl;
    return 0;
}


Measured memory_bytes: 35456
# フェルマーの小定理
N, K = map(int, input().split())

fac = [0] * (N + 1)
fac[0] = 1
for i in range(N):
    fac[i + 1] = fac[i] * (i + 1) % 1000000007


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], 1000000005, 1000000007) * pow(fac[k], 1000000005, 1000000007) % 1000000007


result = []
for i in range(1, K + 1):
    result.append(mcomb(K - 1, i - 1) * mcomb(N - K + 1, i) % 1000000007)
print('\n'.join(str(i) for i in result))


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

int N, W;
const int MAX = 1e5+5;
int values[MAX];
int weights[MAX];
long long int dp[100][MAX];

long long int solve(int n, int w){
    if(dp[n][w]!=-1) return dp[n][w];
    if(n<0 || w<=0) return 0;
    if(n==0){
        long long int best = 0;
        return dp[n][w]= weights[n]<=w ?  values[n]: 0;
    }
    return dp[n][w]=max(solve(n-1, w),w>=weights[n] ?  solve(n-1, w-weights[n])+values[n] : 0);

}



int main(void){
    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>weights[i]>>values[i];
    }
    memset(dp, -1, sizeof dp);
    cout<<solve(N-1, W)<<endl;

    return 0;
}


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

int k[2020],f[2000005],a[2000005],b[2000005],g[2000005];
long long sum;

int main()
{
	string s;
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++)
	{
		a[i+1]=s[i]-'0';
	}
	int l=1;
	for(int i=n;i>=1;i--)
	{
		g[i]=l;
		l*=10;
		l%=2019;
	}
	for(int i=n;i>=1;i--)
	{
		f[i]=(f[i+1]+a[i]*g[i])%2019;
		k[f[i]]++;
	}
	sum=k[0];
	sum+=(k[0]*(k[0]-1)/2);
	for(int i=1;i<=2018;i++)
	{
		sum+=(k[i]*(k[i]-1)/2);
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 6040
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 1e5 + 2;
 
struct IOsetup{
  IOsetup(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout.tie(nullptr);
    cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
 int k, x;
 cin >> k >> x;
 if ( k * 500 >= x) cout << "Yes" << endl;
 else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Iterator;

class Parser {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final Iterator<String> stringIterator = br.lines().iterator();
    private static final Deque<String> inputs = new ArrayDeque<>();

    void fill() throws IOException {
        if(inputs.isEmpty()){
            if(!stringIterator.hasNext()) throw new IOException();
            inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
        }
    }

    Integer parseInt() throws IOException {
        fill();
        if(!inputs.isEmpty()) {
            return Integer.parseInt(inputs.pollFirst());
        }
        throw new IOException();
    }

    Double parseDouble() throws IOException {
        fill();
        if(!inputs.isEmpty()) {
            return Double.parseDouble(inputs.pollFirst());
        }
        throw new IOException();
    }

    String parseString() throws IOException {
        fill();
        return inputs.pollFirst();
    }

}

public class Main {


    public static void main(String[] args) throws IOException {

        Parser parser = new Parser();
        int N = parser.parseInt();
        int M = parser.parseInt();

        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = parser.parseInt();
        }

        long[] costs = new long[M + 1];
        long[] cnts = new long[M + 1];
        long costSum = 0;

        for(int i = 1; i < N; i++){
            if(a[i - 1] < a[i]){
                long v = a[i] - a[i - 1];
                costs[a[i]] += v;
                cnts[a[i]] += 1;
                cnts[a[i - 1]] -= 1;

                costSum += v;
            }else if(a[i - 1] > a[i]){
                long v = (M - a[i - 1]) + a[i];
                costs[M] += (M - a[i - 1]);
                cnts[M] += 1;
                cnts[a[i - 1]] -= 1;

                costs[a[i]] += v;
                cnts[a[i]] += 1;
                costSum += v;
            }
        }

        long answer = costSum;

        long cntSum = 0;
        long cntAcc = 0;
        long currCostSum = 0;

        for(int i = M; i >= 1; i--){
            cntSum += cnts[i];
            cntAcc += cntSum;
            currCostSum += costs[i];
            long v = costSum + cntAcc - currCostSum;

            answer = Math.min(answer, v);
        }

        System.out.print(answer);
    }
}

Measured memory_bytes: 41228