akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

struct Treap{
	struct Node{
		int x, size, fix, y;
		long long sum;
		Node *left, *right;
		Node(){}
		Node(int _x, int _y, Node *l = NULL, Node *r = NULL){
			x = _x, y = _y, left = l, right = r, fix = rand(), sum = y, size = 1;
		}
		long long lsum(){return left ? left->sum : 0;}
		long long rsum(){return right ? right->sum : 0;}
		int lsize(){return left ? left->size : 0;}
		int rsize(){return right ? right->size : 0;}
		void pushup(){sum = lsum() + rsum() + y, size = lsize() + rsize() + 1;}
	}*T;
	typedef pair <Node *, Node *> pnn;
	void init(){T = NULL;}
	Node *merge(Node *l, Node *r){
		if (!l || !r) return l ? l : r;
		if (l->fix > r->fix){
			l->right = merge(l->right, r);
			l->pushup();
			return l;
		} else {
			r->left = merge(l, r->left);
			r->pushup();
			return r;
		}
	}
	pnn split(Node *T, int val){
		if (!T) return pnn(NULL, NULL);
		if (val < T->x){
			pnn tmp = split(T->left, val);
			T->left = tmp.se, T->pushup();
			return mp(tmp.fi, T);
		} else {
			pnn tmp = split(T->right, val);
			T->right = tmp.fi, T->pushup();
			return mp(T, tmp.se);
		}
	}
	void Insert(int x, int y){
		pnn t = split(T, x);
		T = merge(t.fi, merge(new Node(x, y), t.se));
	}
	long long Query(int x){
		pnn t = split(T, x - 1);
		long long ans = !t.se ? 0 : 1ll * x * t.se->size - t.se->sum - t.se->size;
		T = merge(t.fi, t.se);
		return ans;
	}
};

struct Segment_tree{
	Treap T[800010];
	void Build(int now, int l, int r){
		T[now].init();
		if (l == r) return ;
		int mid = l + r >> 1;
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
	}
	void Update(int now, int l, int r, int pos, int x){
//		cout << "Update:" << now << " " << l << " " << r << " " << pos << " " << x << endl;
		T[now].Insert(x, pos);
		if (l == r) return ;
		int mid = l + r >> 1;
		if (pos <= mid) Update(now << 1, l, mid, pos, x);
		else Update(now << 1 | 1, mid + 1, r, pos, x);
//		cout << "    end" << endl; 
	}
	long long Query(int now, int l, int r, int L, int R, int x){
//		cout << "Query:" << now << " " << l << " " << r << " " << L << " " << R << " " << x << endl;
		if (L > R) return 0;
		if (l == L && r == R) return T[now].Query(x);
		int mid = l + r >> 1;
		if (R <= mid) return Query(now << 1, l, mid, L, R, x);
		if (L > mid) return Query(now << 1 | 1, mid + 1, r, L, R, x);
		return Query(now << 1, l, mid, L, mid, x) + Query(now << 1 | 1, mid + 1, r, mid + 1, R, x);
	}
}seg;

int a[100010];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	seg.Build(1, 1, 2 * m);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	long long sum = 0;
	for (int i = 1; i < n; i++){
		seg.Update(1, 1, 2 * m, a[i - 1], a[i] < a[i - 1] ? a[i] + m : a[i]);
		sum += a[i] > a[i - 1] ? a[i] - a[i - 1] : a[i] + m - a[i - 1];
	}
	long long ans = 0x3f3f3f3f3f3f3f3f;
	for (int i = 1; i <= m; i++){
		long long val = sum - seg.Query(1, 1, 2 * m, 1, i - 1, i) - seg.Query(1, 1, 2 * m, 1, i + m - 1, i + m);
//		cout << "i:" << i << " " << val << endl;
		ans = min(ans, val);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 94080
#include<iostream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;
typedef long long ll;

int main(){
	ll  X, Y, A, B, C;
	cin>>X>>Y>>A>>B>>C;
	vector<ll> p(A);
	vector<ll> q(B);
	vector<ll> r(C);
	for(ll i=0; i<A; i++) cin>>p[i];
	for(ll i=0; i<B; i++) cin>>q[i];
	for(ll i=0; i<C; i++) cin>>r[i];
	sort(p.begin(), p.end(),greater<int>());
	sort(q.begin(), q.end(),greater<int>());
	sort(r.begin(), r.end(),greater<int>());

	ll i=X-1;
	ll j=Y-1;
	ll k=0;
	while(i>=0&&j>=0&&k<C){
		if(r[k]<p[i]&&r[k]<q[j]){
			break;
		}
//		cout<<i<<"\t"<<j<<"\t"<<k<<endl;
		if(p[i]<=q[j]){
			if(r[k]>p[i]){
				p[i]=r[k];
				i--;
			}
		}else{
			if(r[k]>q[j]){
				q[j]=r[k];
				j--;
			}
		}

		k++;
	}
	while(i>=0&&k<C){
		if(r[k]>p[i]){
			p[i]=r[k];
			i--;
		}
		k++;
	}
	while(j>=0&&k<C){
		if(r[k]>q[j]){
			q[j]=r[k];
			j--;
		}
		k++;
	}
	ll ans=0;
	for(ll i=0; i<X; i++){
		ans+=p[i];
//		cout<<p[i]<<endl;
	}
	for(ll i=0; i<Y; i++){
		ans+=q[i];
//		cout<<q[i]<<endl;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 510;

int main()
{
    int A,B;
    while (cin >> A >> B) {
        const int ans = A*B - A - B + 1;
        cout << ans  << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;

int main(){
	bool ans = false;
	int a, b, c, k;
	cin >> a >> b >>c>> k;
	rep(i, 0, k + 1) {
		rep(j, 0, k + 1) {
			if (i + j > k)continue;
			int x = k - (i + j);
			if (a * pow(2, i) < b * pow(2, j) && b * pow(2, j) < c * pow(2, x))ans = true;
		}
	}
	Yes(ans);
	return 0;
}


Measured memory_bytes: 4020
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=200010;
int n,x,ans,mx,t1,t2,tot,a[N],b[N],c[N];
struct P{ int x,y; }p[N];

int main(){
	scanf("%d",&n); a[0]=-20000;
	rep(i,1,n){
		scanf("%d",&a[i]);
		if (a[i]>a[mx]) mx=i;
	}
	swap(a[1],a[mx]);
	rep(i,2,n) if (a[i]>0) b[++t1]=a[i]; else c[++t2]=a[i];
	if (t2){
		rep(i,1,t1) p[++tot]=(P){c[1],b[i]},c[1]-=b[i];
		rep(i,1,t2) p[++tot]=(P){a[1],c[i]},a[1]-=c[i];
		printf("%d\n",a[1]);
		rep(i,1,tot) printf("%d %d\n",p[i].x,p[i].y);
	}else{
		sort(b+1,b+t1+1);
		rep(i,2,t1) p[++tot]=(P){b[1],b[i]},b[1]-=b[i];
		printf("%d\n",a[1]-b[1]);
		rep(i,1,tot) printf("%d %d\n",p[i].x,p[i].y);
		printf("%d %d\n",a[1],b[1]);
	}
	return 0;
}

Measured memory_bytes: 3456
import sys
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())

from collections import deque
def main():
    n = ii()
    edge = [[] for _ in range(n)]
    ans = [0]*(n-1)
    for i in range(n-1):
        u, v = mi()
        u -= 1
        v -= 1
        edge[u].append((v, i))
        edge[v].append((u, i))
    k = 0
    q = deque([0])
    visited = [False]*n
    visited[0] = True
    c = [0]*n
    while q:
        v = q.popleft()
        cur = 1
        k = max(k, len(edge[v]))
        for nv, idx in edge[v]:
            if visited[nv]:
                continue
            if cur == c[v]:
                cur += 1
            visited[nv] = True
            c[nv] = cur
            ans[idx] = cur
            cur += 1
            q.append(nv)
    print(k)
    print(*ans, sep='\n')





if __name__ == '__main__':
    main()

Measured memory_bytes: 45996
#include <stdio.h>
#include <math.h>

#define PI acos(-1)
#define EPS 1e-14
#define sqr(x) ((x) * (x))

double angle(double d1, double d2, double d3)
{
    return acos((d1 * d1 + d2 * d2 - d3 * d3) / (2 * d1 * d2));
}

int main(void)
{
    double x[4], y[4];

    while (~scanf("%lf,%lf", x, y)){
        int i;
        double sum = 0;

        for (i = 1; i < 4; i++) scanf(",%lf,%lf", x + i, y + i);
        for (i = 0; i < 4; i++){
            double d1 = sqrt(sqr(x[(i + 1) % 4] - x[i]) + sqr(y[(i + 1) % 4] - y[i]));
            double d2 = sqrt(sqr(x[(i + 2) % 4] - x[(i + 1) % 4]) + sqr(y[(i + 2) % 4] - y[(i + 1) % 4]));
            double d3 = sqrt(sqr(x[i] - x[(i + 2) % 4]) + sqr(y[i] - y[(i + 2) % 4]));
            sum += angle(d1, d2, d3);
        }

        if (PI * 2 - EPS < sum && sum < PI * 2 + EPS) puts("YES");
        else puts("NO");
    }

    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

vector<ll> fac(402000), finv(402000), inv(402000);
void initcom(){
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  for(int i=2; i<402000; i++){
    fac[i] = (fac[i-1]*i) % mod;
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll nCr(int n, int k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
  initcom();
  ll N, K; cin >> N >> K;
  ll ans=0;
  // 0人の部屋がi部屋となるとき
  for(ll i=0; i<=min(N-1,K); i++){
    ans += nCr(N,i)*nCr(N-1,N-i-1);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9728
#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++)
int main()
{
    int A;
    cin >> A;
    
    cout << (A/1000==0?"ABC":"ABD") << endl; 

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
int n,m,fa[N],cnt[N];
long long w[N];
struct edge{
	int x,y;
	long long v;
	bool operator < (const edge &rhs) const {
		return v<rhs.v;
	}
}e[N];

int getfa(int x) {
	if (x==fa[x]) return x;
	int f=getfa(fa[x]);
	cnt[f]+=cnt[x]; cnt[x]=0;
	w[f]+=w[x]; w[x]=0;
	return fa[x]=f;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%lld",&w[i]);
	for (int i=1;i<=m;i++) scanf("%d%d%lld",&e[i].x,&e[i].y,&e[i].v);
	
	for (int i=1;i<=n;i++) {
		cnt[i]=0; fa[i]=i;
	}
	
	sort(e+1,e+m+1);
	int ans=0;
	for (int i=1;i<=m;i++) {
		int fx=getfa(e[i].x),fy=getfa(e[i].y);
		if (fx!=fy) {
			fa[fx]=fa[fy];
			cnt[fy]+=cnt[fx]+1; cnt[fx]=0;
			w[fy]+=w[fx]; w[fx]=0;
		} else cnt[fx]++;
		if (w[fy]>=e[i].v) {
			ans+=cnt[fy];
			cnt[fy]=0;
		}
	}
	cout<<m-ans;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }

int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a/gcd(a,b)*b<<endl;
    return 0;
}


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

int G[110][110];///构造图
bool vis[110];///设置是否访问过
int tot;///设置访问次序
int st[110],ed[110];///设置顶点的发现时刻，顶点的结束时刻
int n;

int next_(int u){
    for(int i=1;i<=n;i++){
        if(G[u][i]&&vis[i]==0)
            return i;
    }
    return -1;
}

void DFS(int r){
    stack<int> s;
    s.push(r);
    vis[r]=true;
    st[r]=++tot;
    while(!s.empty()){
        int u=s.top();
        int v=next_(u);
        if(v!=-1){
            if(vis[v]==false){
                vis[v]=true;
                st[v]=++tot;
                s.push(v);
            }
        }
        else{
            s.pop();
            ed[u]=++tot;
        }

    }
}

void DFS_Visit(){
    memset(st,0,sizeof(st));
    memset(ed,0,sizeof(ed));
    memset(vis,0,sizeof(vis));
    tot=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==false)
            DFS(i);
    }
    for(int i=1;i<=n;i++){
        printf("%d %d %d\n",i,st[i],ed[i]);
    }
}

int main(){
    scanf("%d",&n);
    memset(G,0,sizeof(G));

    for(int i=0;i<n;i++){
        int u,k;
        scanf("%d%d",&u,&k);
        for(int j=0;j<k;j++){
            int v;
            scanf("%d",&v);
            G[u][v]=1;
        }
    }
    DFS_Visit();
    return 0;
}


Measured memory_bytes: 3272
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		if(s.equals("SUN")) {
			System.out.println(7);
		}else if(s.equals("MON")) {
			System.out.println(6);
		}else if(s.equals("TUE")){
			System.out.println(5);
		}else if(s.equals("WED")) {
			System.out.println(4);
		}else if(s.equals("THU")) {
			System.out.println(3);
		}else if(s.equals("FRI")) {
			System.out.println(2);
		}else if(s.equals("SAT")) {
			System.out.println(1);
		}
		
	}
	


}




Measured memory_bytes: 21716
import java.util.Scanner;
class Main
{
  public static void main(String args[])
  {
    int c,i;
    Scanner sc = new Scanner(System.in);
    String s=sc.nextLine();
    c=0;
    String str [] = s.split("S",-1);
    for(i=0;i<str.length;i++)
    {
      if(str[i].length()>c)
      c=str[i].length();
    }
    System.out.println(c);
  }
}

Measured memory_bytes: 35564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		if(s.contains("a") && s.contains("b") && s.contains("c")) {
			System.out.println("Yes");

		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 22100
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let mut N = read::<i32>();
    let mut sum: u32 = 0;
    while N > 1 {
        N = N / 2;
        sum += 1;
    }
    let x: i32 = 2;
    println!("{}", x.pow(sum));

}


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

const double eps = 1e-9;

struct P {
   double x, y;
   P(double a = 0.0, double b = 0.0) : x(a), y(b) {}
   void read() { cin >> x >> y; }
   P operator+(const P& rhs) const { return P{x + rhs.x, y + rhs.y}; }
   P operator-(const P& rhs) const { return P{x - rhs.x, y - rhs.y}; }
   double abs() { return x * x + y * y; }
};

vector<P> points;

double get2(double x, double y) {
   P cur{x, y};
   double mx = -1e9;
   for (auto &x : points) {
      mx = max(mx, (cur - x).abs());
   }
   return mx;
}

double get1(double m) {
   double l = 0.0, r = 1000.0;
   while (r - l > eps) {
      double m1 = l + (r - l) / 3;
      double m2 = r - (r - l) / 3;
      if (get2(m, m1) > get2(m, m2))
         l = m1;
      else
         r = m2;
   }
   return get2(m, l);
}

int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.precision(10);
   cout << fixed;
   int n;
   cin >> n;
   points.resize(n);
   for (auto &x : points)
      x.read();
   double l = 0, r = 1000;
   while (r - l > eps) {
      double m1 = l + (r - l) / 3;
      double m2 = r - (r - l) / 3;
      if (get1(m1) > get1(m2))
         l = m1;
      else
         r = m2;
   }
   cout << sqrt(get1(l)) << '\n';
   return 0;
}

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

int main() {
  int N,M; cin >> N >> M;
  int c[N]; rep(i,0,N) c[i] =0;
  rep (i,0,M) {
    int a,b; cin >> a >> b;
    c[a-1]++; c[b-1]++;
  }
  
  rep(i,0,N) cout << c[i] << endl;
}

Measured memory_bytes: 3480
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    x = n * (n + 1) // 2
    y = sum(a)

    if y % x != 0:
        return print("NO")

    b = [0] * n
    c = y // x
    for i in range(n):
        b[i] = a[i] - a[(i + 1) % n] + c

    p = [0] * n
    for i in range(n):
        if b[i] % n != 0 or b[i] < 0:
            return print("NO")
        else:
            p[i] = b[i] // n

    if sum(p) == c:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 86224
#include <bits/stdc++.h>
using namespace std;
     
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  long long w;
  cin >> n >> w;
  vector<int> vi(n);
  vector<int> wi(n);
  int ac = 0;
  for(int i = 0; i<n;i++){
    cin >> wi[i] >> vi[i];
    ac+=vi[i];
  }
  long long dp[n+1][ac+1];
  fill(*dp,*dp+(n+1)*(ac+1),1000000000000);
  dp[0][0] = 0;
  for(int i = 1; i<=n; i++){
    for(int j = 0; j<=ac; j++){
      if(j>=vi[i-1]){
	dp[i][j] = min(dp[i-1][j],dp[i-1][j-vi[i-1]]+wi[i-1]);
      }else{
	dp[i][j] = dp[i-1][j];
      }
    }
  }
  int ans = 0;
  for(int i = 0; i<=ac;i++){
    if(dp[n][i]<=w){
      ans = max(ans,i);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 82420
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    map<int, int> mp;
    vector<int> val;
    ll c1 = 0, c2 = 0;
    bool b = (k%2 == 0 ? true : false);
    rep(i, 1, n+1) {
        if(i%k == 0) {
            c1++;
        }
        if(b)
            if(i%k == k/2) c2++;
    }
    cout << c1*c1*c1+c2*c2*c2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

 fun main(args:Array<String>) {
    val scan = Scanner(System.`in`)
    val DICE = 6
    val dice = IntArray(DICE)
    val dice2 = IntArray(DICE)
    for (i in 0 until DICE)
    {
      dice[i] = scan.nextInt()
    }
    val direction = scan.next()
    scan.close()
    for (i in 0 until direction.length)
    {
      when (direction.get(i)) {
        'N' -> {
          dice2[0] = dice[1]
          dice2[1] = dice[5]
          dice2[2] = dice[2]
          dice2[3] = dice[3]
          dice2[4] = dice[0]
          dice2[5] = dice[4]
        }
        'E' -> {
          dice2[0] = dice[3]
          dice2[1] = dice[1]
          dice2[2] = dice[0]
          dice2[3] = dice[5]
          dice2[4] = dice[4]
          dice2[5] = dice[2]
        }
        'S' -> {
          dice2[0] = dice[4]
          dice2[1] = dice[0]
          dice2[2] = dice[2]
          dice2[3] = dice[3]
          dice2[4] = dice[5]
          dice2[5] = dice[1]
        }
        'W' -> {
          dice2[0] = dice[2]
          dice2[1] = dice[1]
          dice2[2] = dice[5]
          dice2[3] = dice[0]
          dice2[4] = dice[4]
          dice2[5] = dice[3]
        }
        else -> {}
      }
      for (j in 0..5)
      {
        dice[j] = dice2[j]
      }
    }
    println(dice[0])
  }



Measured memory_bytes: 25640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair



int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	ll A, B, C, D, n;
	cin >> A >> B >> C >> D >> n;
	B = min(B, 2 * A);
	C = min(C, 2 * B);
	D = min(D, 2 * C);
	ll ans = (n / 2) * D + (n & 1) * C;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 764
cards = [[False for i in range(14)] for m in range(4)]

pattern = ["S", "H", "C", "D"]

N = int(input())

for j in range(N):
	
	mark,num = input().split()
	num = int(num)
	
	if mark== 'S':
		cards[0][num] = True
	
	elif mark=='H':
		cards[1][num] = True
	
	elif mark=='C':
		cards[2][num] = True
	
	else:
		cards[3][num] = True
		
for k in range(4):
	for l in range(1,14):
		if cards[k][l] == False:
			print(f"{pattern[k]} {l}")
			


Measured memory_bytes: 5608
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4

output:
1
0
1
1
"""

import sys
from math import isinf

sys.setrecursionlimit(int(1e5))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
    return init_adj_table


def Tarjan(current, low, disc, scc_stack, in_scc_stack):
    global timer
    disc[current] = low[current] = timer
    timer += 1

    in_scc_stack[current] = True
    scc_stack.append(current)

    current_scc_set = set()
    for adj in adj_table[current]:
        if isinf(disc[adj]):
            Tarjan(adj, low, disc, scc_stack, in_scc_stack)
            low[current] = min(low[current], low[adj])

        elif in_scc_stack[adj]:
            low[current] = min(low[current], disc[adj])

    scc_candidate = -1
    if disc[current] == low[current]:
        while scc_candidate != current:
            scc_candidate = scc_stack.pop()
            current_scc_set.add(scc_candidate)
            in_scc_stack[scc_candidate] = False

        init_scc_sets_list.append(current_scc_set)

    return None


def scc():
    disc = [float('inf')] * vertices
    low = [float('inf')] * vertices
    scc_stack = list()
    in_scc_stack = [False] * vertices

    for v in range(vertices):
        if isinf(disc[v]):
            Tarjan(v, low, disc, scc_stack, in_scc_stack)

    return init_scc_sets_list


def solve():
    for question in q_list:
        flag = False
        ele1, ele2 = map(int, question)
        for each in scc_sets_list:
            if (ele1 in each) and (ele2 in each):
                flag = True
                break
        if flag:
            print('1')
        else:
            print('0')

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:edges + 1])
    q_num = int(_input[edges + 1])
    q_list = map(lambda x: x.split(), _input[edges + 2:])

    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    init_scc_sets_list = []
    scc_sets_list = scc()
    solve()

Measured memory_bytes: 26488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());

		int num = n;
		if (n == 100) {
			if (d == 0)
				num = n + 1;
			if (d == 1)
				num = n * 100 + 100;
			if (d == 2)
				num = n * 10000 + 10000;
		} else {
			if (d == 1)
				num = n * 100;
			if (d == 2)
				num = n * 10000;
		}
		System.out.println(num);
		sc.close();
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x <<  " " << x << endl;
#define all(x) x.begin(), x.end()
typedef std::vector<int> vi;
typedef std::vector<vector<int>> vvi;
typedef std::vector<string> vs;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef long long ll;
const int inf = 1e9 + 5;

template <typename T>
void print(T v){ for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(2)<<*i<<" ";cout<<endl; }
template <typename T>
void print_vv(T v, bool same_line=true){
for(auto i= 0; i<v.size(); i++){cout<<"{";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(3)<<v[i][j]<<",";}cout<<"},";if(same_line) cout<<endl;}cout<<endl;}

// one dimensional
int main(){
    int n;
    while(cin>>n){
        vi dp(3);

        for(int day=0; day<n; day++){
            vi new_dp(3);
            vi c(3);

            for(int i=0; i<3; i++)
                cin>>c[i];
            
            for(int i=0; i<3; i++){
                for(int j=0; j<3; j++){
                    if(i!=j){
                        new_dp[i] = max(new_dp[i], c[i] + dp[j]);
                    }
                }
            }
            dp = new_dp;
        }

        cout<<*max_element(all(dp))<<endl;
    }
}

// 2 dimensional
int main1(){
    int n;
    while(cin>>n){
        int dp[3][n];
        memset(dp, 0, sizeof dp);

        vvi act(3, vi(n));

        int a,b,c;
        for(int i=0; i<n; i++){
            cin>>act[0][i]>>act[1][i]>>act[2][i];
        }

        for(int i=0; i<3; i++)
            dp[i][0] = act[i][0];

        // for(int i=1; i<n; i++){
        //     for(int ac=0; ac<3; ac++){
        //         if(ac==0)
        //             dp[ac][i] = act[ac][i] + max(dp[1][i-1], dp[2][i-1]);
        //         else if(ac==1)
        //             dp[ac][i] = act[ac][i] + max(dp[0][i-1], dp[2][i-1]);
        //         else if(ac=2)
        //             dp[ac][i] = act[ac][i] + max(dp[0][i-1], dp[1][i-1]);
        //     }
        // }

        for(int i=1; i<n; i++){ //i: day
            for(int ac = 0; ac<3; ac++){ //ac: activity
                for(int oac = 0; oac <3; oac++){ //oac: other activity
                    if(ac!=oac){
                        dp[ac][i] = max(dp[ac][i], act[ac][i] + dp[oac][i-1]);
                    }
                }
            }
        }

        cout<<max({dp[0][n-1], dp[1][n-1], dp[2][n-1]})<<endl;
    }
    return 0;
}

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

#define LL long long

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s,t;
	cin >> s >> t;
	map<char,set<LL>> indices;
	for (char c = 'a'; c <= 'z'; c++)
		indices[c] = {};
	for (LL i = 0; i < s.size(); i++)
		indices[s[i]].insert(i);
	LL res = 0;
	LL pos = -1;
	for (char c : t){
		if (indices[c].empty()){
			cout << "-1\n";
			return 0;
		}
		auto it = indices[c].upper_bound(pos);
		if (it == indices[c].end()){
			it = indices[c].begin();
			res += s.size()-pos+*it;
			pos = *it;
		}
		else{
			res += *it-pos;
			pos = *it;
		}
		pos %= s.size();
	}
	cout << res << "\n";
}


Measured memory_bytes: 5200
n = int(input())
a = 0
b = 0
c = 0
d = 0

for i in range(n):
    s = input()
    if s == "AC":
        a += 1
    elif s == "WA":
        b += 1
    elif s == "TLE":
        c += 1
    else:
        d += 1

print("AC x " + str(a))
print("WA x " + str(b))
print("TLE x " + str(c))
print("RE x " + str(d))

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

bool    com(vector<int> A, vector<int> B) {
        return (A.at(2) < B.at(2));
}

int     main() {
        int N;
        cin >> N;
        vector<vector<int>>     job(N, vector<int> (3));
        for (int i=0; i<N; i++) {
                cin >> job.at(i).at(1);
                cin >> job.at(i).at(2);
                job.at(i).at(0) = job.at(i).at(2) - job.at(i).at(1);
        }
        sort(job.begin(), job.end(), com);
        long S=0;
        for (int i=0; i<N; i++) {
                if (S > job.at(i).at(0)) {
                        cout <<"No" << endl;
                        return 0;
                }
                S += job.at(i).at(1);
        }
        cout << "Yes" << endl;
        return 0;
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(a) (a.size)
#define lb lower_bound
#define ub upper_bound
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;
typedef unsigned long long ull;
const int MOD=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const int N=2e3+5;
const int dir[4][2]= {0,1,1,0,0,-1,-1,0};
int main()
{
    string s;
    while(cin >> s)
    {
        int sz=s.size();
        int ans=sz/2,left=(sz-1)/2,right=sz-(sz+1)/2,center=left;
        while (left >= 0)
        {
            if(s[center] != s[left] || s[center] != s[right])
                break;
            ++ans;
            --left, ++right;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

vector<vector<double> > dp(100001, vector<double>(20, 0));
vector<double> per(20);
vector<double> ans(100001);
int main(){
	FOR(i, 0, 15) per[i]=pow(0.5, i);
	dp[0][0]=1;
	double sum=0;
		
	FOR(i, 0, 100000){
		FOR(j, 0, 15){
			sum+=dp[i][j]*per[j];
			if(j==0){
				dp[i+1][j+1]+=dp[i][j];
			}
			else{
				dp[i+1][0]+=dp[i][j]*(1-per[j]);
				dp[i+1][j+1]+=dp[i][j]*per[j];
			}
		}
		
		ans[i]=sum;
	}
	
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) return 0;
		printf("%.5f\n", ans[n-1]);
	}
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int s=a.size();
    for(int i=0;i<s-1;i++){
        if(a[i]=='A'&&a[i+1]=='C'){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bitset<2000007> dp;
int main(){
  int n;
  cin>>n;
  vector<int> arr(n);
  int sum=0;
  dp[0]=1;
  for(int i=0;i<n;i++){
  	int x;
    cin>>x;
    sum += x;
    dp = (dp|dp<<x);
  }
  int target = (sum+1)/2;
  int i;
  for( i=target;i<=sum;i++){
   	if(dp[i]){
     	break; 
    }
  }
  cout<<i;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int n,d1,d2,m,i,j,cnt,col[605][605],vis[605][605];
vector<pair<int,int> > cant;
void dfs(int x,int y)
{
	int i;
	vis[x][y]=1;
	for (i=0;i<cant.size();i++)
	{
		int xx=x+cant[i].first,yy=y+cant[i].second;
		if (xx<0||yy<0||xx>=n+n||yy>=n+n) continue;
		if (vis[xx][yy]||col[xx][yy]==-1) continue;
		col[xx][yy]=3-col[x][y];
		dfs(xx,yy);
	}
}
int main()
{
	cin>>n>>d1>>d2;
	m=n*n;
	for (i=0;i<=d1;i++)
	{
		j=sqrt(d1-i*i+0.5);
		if (j>=0&&i*i+j*j==d1)
		{
			cant.push_back(make_pair(i,j));
			cant.push_back(make_pair(i,-j));
			cant.push_back(make_pair(-i,j));
			cant.push_back(make_pair(-i,-j));
		}
	}
	for (i=0;i<n+n;i++)
	{
		for (j=0;j<n+n;j++)
		{
			if (!vis[i][j]&&col[i][j]!=-1)
			{
				col[i][j]=1;
				dfs(i,j);
			}
		}
	}
	for (i=0;i<n+n;i++)
	{
		for (j=0;j<n+n;j++)
		{
			if (col[i][j]==1) cnt++;
		}
	}
	if (cnt<m+m)
	{
		for (i=0;i<n+n;i++)
		{
			for (j=0;j<n+n;j++)
			{
				col[i][j]=3-col[i][j];
			}
		}
	}
	for (i=0;i<n+n;i++)
	{
		for (j=0;j<n+n;j++)
		{
			if (col[i][j]==2) col[i][j]=-1; else col[i][j]=0;
		}
	}
	cant.clear();
	for (i=0;i<=d2;i++)
	{
		j=sqrt(d2-i*i+0.5);
		if (j>=0&&i*i+j*j==d2)
		{
			cant.push_back(make_pair(i,j));
			cant.push_back(make_pair(i,-j));
			cant.push_back(make_pair(-i,j));
			cant.push_back(make_pair(-i,-j));
		}
	}
	memset(vis,0,sizeof(vis));
	for (i=0;i<n+n;i++)
	{
		for (j=0;j<n+n;j++)
		{
			if (!vis[i][j]&&col[i][j]!=-1)
			{
				col[i][j]=1;
				dfs(i,j);
			}
		}
	}
	if (cnt<m)
	{
		for (i=0;i<n+n;i++)
		{
			for (j=0;j<n+n;j++)
			{
				col[i][j]=3-col[i][j];
			}
		}
	}
	for (i=0;i<n+n;i++)
	{
		for (j=0;j<n+n;j++)
		{
			if (m>0&&col[i][j]==1)
			{
				cout<<i<<' '<<j<<endl;
				m--;
			}
		}
	}
	//if (m>0) return -1;
	return 0;
}

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

int main()
{
        int n;
        string s;
  		cin >> n>> s;
        int ans = 0;
        for(int i = 0; i<= n-3; i++)
        {
                if(s[i] == 'A' && s[i + 1] == 'B' &&s[i+2] == 'C')
                        ans++;
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int n,k,c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> work(k);
  int mae = 0;
  mae = INT_MIN;
  int count = 0;
  for(int i = 0;i < n;i++){
    if(count == k)break;
    if(i >= mae + c + 1 && s[i] == 'o')work[count] = i,count++,mae = i;
  }
  count = 0;
  count = k - 1;
  mae = INT_MAX;
  vector<int> res;
  /*for(int i = 0;i < k;i++)cout << work[i] << " ";
  cout << endl;*/
  for(int i = n - 1;i >= 0;i--){
    if(count == -1)break;
    if(i <= mae - c - 1 && s[i] == 'o'){
      if(work[count] == i)res.push_back(i + 1);
      work[count] = i;
      count--;
      mae = i;
    }
  }
  sort(res.begin(),res.end());
  for(auto item:res)cout << item << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

struct day {
    int a, b, c;
};

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

    int n;
    cin >> n;

    vector<int> a(n + 1);
    vector<int> b(n + 1);
    vector<int> c(n + 1);

    int ai, bi, ci;
    for (int i = 1; i <= n; i++) {
        cin >> ai >> bi >> ci;
        a[i] = ai + max(b[i - 1], c[i - 1]);
        b[i] = bi + max(a[i - 1], c[i - 1]);
        c[i] = ci + max(a[i - 1], b[i - 1]);
    }

    cout << max(a[n], max(b[n], c[n])) << endl;
}



Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点

n, m, k = map(int, input().split())
par = [-1]*n
f = [set() for _ in range(n)]
b = [set() for _ in range(n)]
for _ in range(m):
    a, _b = map(int, input().split())
    f[a-1].add(_b-1)
    f[_b-1].add(a-1)
    unite(a-1, _b-1)
for _ in range(k):
    a, _b = map(int, input().split())
    b[a-1].add(_b-1)
    b[_b-1].add(a-1)

for i in range(n):
    ans = size(i)-len(f[i])-1
    for node in b[i]-f[i]:
        if same(i, node):
            ans -= 1
    print(ans, end=" " if i!=n-1 else "\n")


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  int N,W;
  cin >> N >> W;
  vector<int> v(N+1);
  vector<int> w(N+1);
  rep(i,N) cin >> v.at(i+1) >> w.at(i+1);

  vector<vector<int>> V(N+1,vector<int>(W+1));

  for(int i=1;i <= N;i++){
    for(int ww=1;ww <= W;ww++){
      if(ww >= w.at(i)){//
        V[i][ww] = max(V[i-1][ww-w[i]]+v[i],V[i-1][ww]);
      }
      else{//i番目の荷物を使わない時
        V[i][ww] = V[i-1][ww];
      }
    }
  }

  cout << V[N][W] << endl;

  return 0;
}



Measured memory_bytes: 6816
#include <bits/stdc++.h>
#define mp make_pair
#define PII pair <int, int>
#define x first
#define y second
using namespace std;
int n, m;
char a[10][10];
bool b[10][10];
int tot, cnt;
queue <PII> Q;

int solve (int i, int j)
{
	while (!Q.empty())
	{
		PII node = Q.front();
		Q.pop();
		int x = node.x + 1 , y = node.y;
		int xx = node.x, yy = node.y+1;
		if (x <= n && y <= m && a[x][y] == '#' && !b[x][y])
			Q.push(mp(x,y)), b[x][y] = 1;
		else if (xx <= n && yy <= m && a[xx][yy] == '#' && !b[xx][yy])
			Q.push(mp(xx,yy)), b[xx][yy] = 1;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i][j] == '#' && !b[i][j]) return 0;
	return 1;
}

int main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	Q.push(mp(1,1));
	b[1][1] = 1;
	cout << (solve(1,1) ? "Possible" : "Impossible");
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
def main():
    n = int(input())
    s = input()
    high = n//2
    low = 1
    ans = 0

    while low <= high:
        t = set()
        i = (high+low)//2
        for j in range(n-i*2+1):
            t.add(s[j:i+j])
            if s[i+j:j+2*i] in t:
                if ans < i:
                    ans = i
                    low = i+1
                    break
        if ans < i:
            high = i-1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

int main() {
  set<string> st;

  int N;
  cin >> N;

  rep(i, N) {
    string S;
    cin >> S;
    st.insert(S);
  }

  cout << st.size() << endl;

  return 0;
}


Measured memory_bytes: 19228
mod = 10**9 + 7
n,k = map(int,input().split())
A = list(map(int,input().split()))

t = 0
for i in range(n):
  for j in range(i+1,n):
    if A[i]>A[j]:
      t += 1

sA = sorted(A)
C = [0]*n
for i in range(1,n):
  if sA[i-1] == sA[i]:
    C[i] = C[i-1]
  else:
    C[i] = i

ans = (t*k) % mod
multi = k*(k-1)//2

for i in range(n):
  ans = (ans + (C[i]*multi) ) %mod
  
print(ans)  

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

def generate(p):
    for i in [3, 5, 7]:
        yield p * 10 + i

nums = [3, 5, 7]
ans = 0
num = 0
p = 0

while num < n:
    for a in generate(nums[p]):
        nums.append(a)
        num = a
        if a <= n and set(list(str(a))) == set(list(str(357))):
            ans += 1
    p += 1

print(ans)

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

double dis(double x1, double y1, double x2, double y2){
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main(){
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double hx = A * cos(2.0 * M_PI * (60.0 * H + M) / 720.0);
    double hy = A * sin(2.0 * M_PI * (60.0 * H + M) / 720.0);
    double mx = B * cos(2.0 * M_PI * M / 60.0);
    double my = B * sin(2.0 * M_PI * M / 60.0);
    
    cout << fixed << setprecision(15) << dis(hx, hy, mx, my) << endl;
    
    return 0;
}

Measured memory_bytes: 4132
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if ( a > b ) {
        cout << "a > b" << endl;
    } else if ( a < b ) {
        cout << "a < b" << endl;
    } else {
        cout << "a == b" << endl;
    }
}

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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(a);
        Array.Reverse(a);

        double search = (double)a[0] / 2;
        int num = 0;
        double dis = int.MaxValue;
        for (int i = 1; i < N; i++)
        {
            if (dis > Abs(search - a[i]))
            {
                dis = Abs(search - a[i]);
                num = a[i];
            }
        }
        WriteLine($"{a[0]} {num}");
    }
}


Measured memory_bytes: 38464
import java.util.*;

class Node{
	int key;
	int parent = -1;
	int left = -1;
	int right = -1;
	public Node(int key){
		this.key = key;
	}
}

class Tree{
	Node[] nodes;
	int root = -1;

	public Tree(int n){
		nodes = new Node[n];
	}

	public void find(int key){
		find(root, key);
	}

	private void find(int x, int key){
		if(x == -1)
			System.out.println("no");
		else if(nodes[x].key == key)
			System.out.println("yes");
		else if(key < nodes[x].key)
			find(nodes[x].left, key);
		else
			find(nodes[x].right, key);
	}

	public void printPreorder(){
		printPre(root);
		System.out.println();
	}

	private void printPre(int id){
		if(id == -1)
			return;
		System.out.print(" " + nodes[id].key);
		printPre(nodes[id].left);
		printPre(nodes[id].right);
	}

	public void printInorder(){
		printIn(root);
		System.out.println();
	}

	private void printIn(int id){
		if(id == -1)
			return;
		printIn(nodes[id].left);
		System.out.print(" " + nodes[id].key);
		printIn(nodes[id].right);
	}

	public void insert(int i, int key){
		nodes[i] = new Node(key);
		insert(i);
	}

	private void insert(int z){
		int y = -1;
		int x = root;
		while(x != -1){
			y = x;
			if(nodes[z].key < nodes[x].key)
				x = nodes[x].left;
			else
				x = nodes[x].right;
		}
		nodes[z].parent = y;

		if(y == -1)
			root = z;
		else if(nodes[z].key < nodes[y].key)
			nodes[y].left = z;
		else
			nodes[y].right = z;
	}
}

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

		Tree t = new Tree(n);

		for(int i = 0; i < n; i++){
			String s = scan.next();
			if(s.equals("insert"))
				t.insert(i, scan.nextInt());
			else if(s.equals("find"))
				t.find(scan.nextInt());
			else{
				t.printInorder();
				t.printPreorder();
			}
		}

		scan.close();
		System.exit(0);
	}
}

Measured memory_bytes: 218688
#include<stdio.h>
#include<string.h>
int main(void){
	
	char s[100];
	
	scanf("%s",s);
	int i=strlen(s);
	
	
	
	printf("\n%c%d%c\n\n",s[0],i-2,s[i-1]);
	
	
	return 0;
}

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

main(){
  int n;
  while(cin >> n){
    int ans;
    string in;
    for(int i=0;i<n;i++){
      map<string,bool> data;
      cin >> in;
      ans=0;
      for(int j=1;j<in.size();j++){
	string a="", b="";
	int tmp;
	for(int k=0;;k++){
	  if(k==j){
	    tmp=k;
	    break;
	  }
	  a+=in[k];
	}
	for(int k=tmp;k<in.size();k++){
	  b+=in[k];
	}
	
	string t;
	t=a+b;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	t=b+a;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	string c="";
	for(int k=a.size()-1;k>=0;k--){
	  c+=a[k];
	}
	t=c+b;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	t=b+c;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	string d="";
	for(int k=b.size()-1;k>=0;k--){
	  d+=b[k];
	}
	t=a+d;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	t=d+a;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	t=c+d;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
	t=d+c;
	if(!data[t]){
	  data[t]=true;
	  ans++;
	}
      }
      cout << ans << endl;
    }
  }
  return 0;
}

  

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

a=input()
b=input()
c=input()

count=0
for i in range(n):
    if(a[i]==b[i] and b[i]==c[i]):
        continue
    elif(a[i]==b[i] and b[i]!=c[i]):
        count+=1
    elif(a[i]!=b[i] and b[i]==c[i]):
        count+=1
    elif(a[i]==c[i] and b[i]!=c[i]):
        count+=1
    elif(a[i]!=b[i] and c[i]!=b[i]):
        count+=2

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{int m,n;
cin>>m>>n;
int a[m][n];
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
  cin>>a[i][j];}
  int r=0;
for(int i=0;i<m-1;i++)
{
for(int j=i+1;j<m;j++)
{float s=0;
for(int k=0;k<n;k++)
  {s=s+((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));}
  s=sqrt(s);
  if(abs(floor(s)-s)==0)
    r=r+1;
      }}
      cout<<r;}


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

const int64_t MOD = 1'000'000'007;
int64_t fact[200001], factinv[200001];

int64_t mpow(int64_t x, int64_t y){
    if(y==0) return 1;
    if(y==1) return x%MOD;
    if(y%2==0) return mpow(x*x%MOD, y/2)%MOD;
    return mpow(x*x%MOD, y/2)*x%MOD;
}

int64_t comb(int64_t n, int64_t r){
    if(r > n) return 0;
    return fact[n]*factinv[r]%MOD*factinv[n-r]%MOD;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int B, W;
    cin >> B >> W;
    if(B==0){
        for(int i=0;i<B+W;i++) cout << 0 << endl;
        return 0;
    }
    if(W==0){
        for(int i=0;i<B+W;i++) cout << 1 << endl;
        return 0;
    }

    const int64_t half = mpow(2, MOD-2);
    fact[0] = fact[1] = 1;
    for(int i=2;i<=200000;i++) fact[i] = i*fact[i-1]%MOD;
    factinv[200000] = mpow(fact[200000], MOD-2);
    for(int i=199999;i>=0;i--) factinv[i] = (i+1)*factinv[i+1]%MOD;

    int64_t p[200001], q[200001];
    p[0] = q[0] = 0;
    for(int i=1;i<B+W;i++){
        p[i] = p[i-1];
        q[i] = q[i-1];
        if(W-1 >= 0 && i-W >= 0){
            p[i] = (p[i] + comb(i-1, W-1)*mpow(half, i-1)%MOD*half%MOD) % MOD;
        }
        if(B-1 >= 0 && i-B >= 0){
            q[i] = (q[i] + comb(i-1, B-1)*mpow(half, i-1)%MOD*half%MOD) % MOD;
        }
    }

    for(int i=0;i<B+W;i++){
        cout << (p[i] + (1-p[i]-q[i]+2*MOD)%MOD*half%MOD)%MOD << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8448
<?php
    fscanf(STDIN, "%s", $s);




    $result = '';
    if($s == 'Sunny'){
      
      
      
      
        $result = 'Cloudy';
    }else if($s == 'Cloudy'){
        $result =  'Rainy';
      
      
      
      
      
    }else if($s == 'Rainy'){
        $result = 'Sunny';
    }
    echo $result;
  ?>

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

int main(){
    int n,k;
    int h[100000];
    int deltah[100000];

    cin>>n>>k;

    for(int i=0;i<n;i++){
        cin>>h[i];
    }

    sort(h,h+n);

    for(int i=0;i<=n-k;i++){
        deltah[i]=h[i+k-1]-h[i];
    }

    sort(deltah,deltah+n-k+1);

    cout<<deltah[0]<<endl;
    return 0;


}

Measured memory_bytes: 1024