akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    int N , M;
    cin >> N >> M;
    vi S[M];
    vi k(M);
    rep(i, M) {
        cin >> k[i];
        rep(j, k[i]) {
            int s; cin >> s;
            S[i].pb(s - 1);
        }
    }
    vi p(M);
    rep(i, M) cin >> p[i];

    int ans = 0;
    rep(i, (1 << N)) {
        bool f = true;
        rep(j, M) {
            int sum = 0;
            rep(a, k[j]) {
                int x = S[j][a];
                if (i & (1 << x)) sum++;
            }
            if(sum % 2 != p[j]) f = false;
        }
        if(f) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main()
{

    int K,a=0,b=0;

    cin>>K;


    for(int i=1;i<=K;i++)
    {
        if(i%2==0)
        {
            a++;
        }
        else { b++;}
    }

    cout<<a*b;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
long double ans,sum,n,d,x,d1,x1,sum1;
int main()
{
    cin>>n>>d>>x; sum=2*d*n+n*x*(2*n-1);
    for(int i=n;i;i--)
    {
        ans+=sum/2/n;
        d1=(2*d+2*n*d+5*x)/2/n, sum1=sum-(2*d+(2*n-1)*x)/n;
        n-=1;
        x1=(sum1-2*d1*n)/n/(2*n-1);
        d=d1, x=x1, sum=sum1;
    }
    printf("%.15lf\n",(double)ans);
    return 0;
}

Measured memory_bytes: 256
while True:
    N, M = map(int, raw_input().split())
    if N == 0:
        break
    ls = []
    for i in range(M):
        t, s, d = map(int, raw_input().split())
        ls.append((t, s, d))
    ls.sort()
    cnt = [0, 1] + [0] * N
    for p in ls:
        cnt[p[2]] = max(cnt[p[1]], cnt[p[2]])
    print sum(cnt)


Measured memory_bytes: 8852
#include<bits/stdc++.h>
using namespace std;
int a[150];
int main()
{
	int n,m,sum=0;
	cin>>n>>m;
	for (int i=1;i<=n;++i) scanf("%d",&a[i]),sum+=a[i];
	if (sum%(4*m)==0) sum/=4*m;
	else sum=sum/(4*m)+1;
	int t=0;
	for (int i=1;i<=n;++i) if (a[i]>=sum) ++t;
	if (t>=m) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ffor(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rfor(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) ffor(i, 0, j, 1)
#define rrep(i, j) rfor(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
//#define f first
//#define s second
#define inf (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define trace1(x)                     cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)        cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double pi=acos(-1.0);
typedef pair<long long int,long long int> pii;
typedef long long ll;
typedef vector<long long int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<long long int,long long int> mpii;
typedef set<long long int> sei;
typedef multiset<long long int> msei;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n>>m;
    string s[n];
    for(i=0;i<n;i++)
    cin>>s[i];
    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    dp[1][1]=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s[i-1][j-1]=='#' || (i==1 && j==1))
            continue;
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    cout<<dp[n][m];
    return 0;
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        if((B-A)%2==0){
            System.out.println("Alice");
        }else{
            System.out.println("Borys");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>

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

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){ //List,Start
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
}

/////////////////////////////////////////

int main(){
  initialize();
  int L,R;
  cin >> L >> R;
  if(R-L>=2019){
    cout << "0" << endl;
    return 0;
  }
  if(R/2019-L/2019>0){
    cout << "0" << endl;
    return 0;
  }
  R=R%2019;
  L=L%2019;
  if(R-L<0){
    cout << "0" << endl;
    return 0;
  }
  int ans=2018;
  for(int i=L;i<R;i++)for(int j=i+1;j<=R;j++){
    ans=min(ans,(i*j)%2019);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

int main() {

    int N, M;
    std::cin >> N >> M;

    std::vector<std::deque<int>> nodes(N);
    std::vector<std::pair<int, int>> edges(M);
    for (int i = 0; i < M; ++i) {
        int a, b;
        std::cin >> a >> b;
        nodes[a - 1].push_back(b - 1);
        nodes[b - 1].push_back(a - 1);
        edges[i] = std::make_pair(a - 1, b - 1);
    }
    int ans = 0;
    for (int i = 0; i < M; ++i) {
        std::vector<bool> memo(N, false);
        std::queue<int> q;
        q.push(0);
        while (!q.empty()) {
            int from = q.front();
            q.pop();
            memo[from] = true;
            for (auto& to : nodes[from]) {
                if (
                    (edges[i].first == from && edges[i].second == to) ||
                    (edges[i].first == to && edges[i].second == from)
                    )continue;
                if (!memo[to]) {
                    q.push(to);
                }
            }
        }
        if (std::any_of(memo.begin(), memo.end(), [](auto a) { return !a; }))++ans;
    }

    std::cout << ans << std::endl;

}

Measured memory_bytes: 256
s = input()
s = list(s)
count_b = [0] * len(s)
for i in range(len(s)):
    if s[i] == 'B':
        if i == 0:
            count_b[i] = 1
        else:
            count_b[i] = count_b[i-1] + 1
    else:
        if i > 0:
            count_b[i] = count_b[i-1]
count = 0
for i in range(len(s)):
    if s[i] == 'W':
        count += count_b[i]
print(count)

Measured memory_bytes: 12580
#include <stdio.h>

char S[1001001];

int main()
{
	scanf ("%s", S);

	int l = 0, r = 0;
	while (S[r]) r++;
	while (l + 1 < r){
		int m = (l + r) / 2;

		int p = 0, q = m, d = 1; bool g = 1;
		for (int i = 0; S[i]; i++){
			if (S[i] == '0') p++, q++;
			if (S[i] == '1') p--, q--;
			if (S[i] == '?') p--, q++;
			if (p < 0){
				p = 0;
				if (d == 2 && p % 2 != q % 2) p++;
			}
			if (q > m){
				q = m;
				if (d == 2 && p % 2 != q % 2) q--;
			}
			if (p > q){
				g = 0; break;
			}
			if (p == q) d = 2;
		}

		if (g) r = m;
		else l = m;
	}
	printf ("%d\n", r);

	return 0;
}

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

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

  int ans = 0;
  for (int i=0; i<N; i++) {
    int sum = 0;
    for (int j=0; j<M; j++) {
      sum += A[i][j] * B[j];
    }
    if (sum + C > 0) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main()
{
    int x, n;
    cin >> x >> n;
    vi p(n);
    rep(i, n)
    {
        cin >> p[i];
        p[i]--;
    }
    vi a(100, 0);
    rep(i, n)
    {
        a[p[i]]++;
    }
    int i = 0;
    while (1)
    {
        if (a[x - 1 - i] == 0)
        {
            cout << x - i << endl;
            break;
        }
        if (a[x - 1 + i] == 0)
        {
            cout << x + i << endl;
            break;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 3592
def multiple_array():
	n = int(raw_input())
	a = []
	b = []
	for i in range(n):
		_a, _b = map(int, raw_input().split(" "))
		a.append(_a)
		b.append(_b)

	accumulate_sum = 0
	for i in range(1, n+1):
		a[-i]+=accumulate_sum
		if a[-i]%b[-i]!=0:
			numbers_to_pushbutton = b[-i]-a[-i]%b[-i]
			accumulate_sum +=numbers_to_pushbutton
	print accumulate_sum


if __name__ == "__main__":
	multiple_array()

Measured memory_bytes: 12208
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<int,int> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<int> sta;   
    //queue<int> que;


int main(){
	int N,M,K;
	std::cin >> N;
    
	string s;
    
	
	//std::vector<long long> v(N);
	
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    std::cin >> s;
    std::cin >> K;
    
    //ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    
    // 配列入力
    /*
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	*/
	
	//文字列入力
	
	for(long long i=0; i<N; i++){
		
		if(s[K-1]!=s[i]){
			s[i]='*';
		}
	}
	
    if(1){
		//for(long long i=0; i<N; i++){
    	//printf("%s",s);
    	std::cout << s << std::endl;

    	//}
	}
	else{
		
	}
	return 0;
}

Measured memory_bytes: 256
A = []
for _ in range(12):
	A.append([0]*10)

n = int(input())
for _ in range(n):
	b, f, r, v = map(int, input().split())
	A[3*b-(3-f)-1][r-1] += v

for i in range(12):        
	print(' ', end='')
	print(' '.join(map(str, A[i])))
	if i in [2, 5, 8]:
		print('#'*20)


Measured memory_bytes: 5600
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
    
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){

    long H,W;
    cin>>H>>W;
    char s[H][W];
    long way =0;
    for(long i=0;i<H;i++){
        for(long j=0;j<W;j++){
            cin>>s[i][j];
            if(s[i][j]=='.')way++;
        }
    }
    vector<vector<long>> dist(H,vector<long>(W,-1));
    dist[0][0] = 0;
    queue<pair<long,long>> que;
    que.push(make_pair(0,0));
    while(!que.empty()){
        pair<long,long> p = que.front();
        que.pop();
        long x=p.first;
        long y=p.second;
        for(long i=0;i<4;i++){
            long nx = x+dx[i];
            long ny = y+dy[i];
            if(x>=0&&x<H&&y>=0&&y<W&&s[nx][ny]=='.'&&dist[nx][ny]==-1){
                dist[nx][ny] = dist[x][y]+1;
                que.push(make_pair(nx,ny));
            }
        }
    } 
    if(dist[H-1][W-1]==-1){
        cout<<-1<<endl;
        return 0;
    }
    cout<<way-1-dist[H-1][W-1]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101

void print(int n,int *A){
  int i;
  for(i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
}
/*
void insertion_sort(int n,int *A){
  int i,j,v;
  for(i=0;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    print(n,A);
  } 
}
*/

void insertion_sort(int n,int *A){
  int i,j,v;
  for(i=0;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    print(n,A);
  } 
}

int main(){
  int n,i;
  int a[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  insertion_sort(n,a);
  return 0;
}



Measured memory_bytes: 2108
import java.util.*;
 
public class Main
{
  public static void main(String[]args)
  {
 	Scanner console = new Scanner(System.in);
    int n = console.nextInt();
    n = n % 1000;
    if(n == 0)
    {
    	System.out.print(n);
    }
    else
    {
    	int answer = 1000 - n;
    	System.out.print(answer);
    }
  }
}

Measured memory_bytes: 35632
n = int(input())
p =list(map(int,input().split()))
l = [i for i in range(1,n+1)]

cnt = 0
for i in range(n):
    if p[i] != l[i]:
        cnt += 1

if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

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

int main(){
  int n, ans=0;
  cin>>n;
  vector<int> a(n);
  for(auto &b:a){
    cin>>b;
    ans+=b;
  }
  sort(a.begin(),a.end());
  ans-=(a[n-1]/2);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;
vector<double> x, y;
void judline(int i, int j);
double calarea();
double divtri(int i, int j, int k);

int main(){
    x.clear();
    y.clear();
    double tmpx, tmpy;
    while(scanf("%lf,%lf", &tmpx, &tmpy) != EOF){
        x.push_back(tmpx);
        y.push_back(tmpy);
    }
    printf("%f\n", calarea());
    return 0;
}

double calarea(){
    double ans = 0;
    for(int i = 1; i < x.size() - 1; i++){
        ans += divtri(0, i, i + 1);
    }
    return ans;
}

double divtri(int i, int j, int k){
    double a = sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i]- y[j])));
    double b = sqrt(((x[j] - x[k]) * (x[j] - x[k])) + ((y[j] - y[k]) * (y[j]- y[k])));
    double c = sqrt(((x[k] - x[i]) * (x[k] - x[i])) + ((y[k] - y[i]) * (y[k]- y[i])));
    double z = (a + b + c) / 2;
    double ans = sqrt(z * (z - a) * (z - b) * (z - c));
    return ans;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n = 0; string s; cin >> s >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i != s.size() - 1 && s[i] != s[i + 1]) {
			i++; n++;
		}
	}
	cout << n << endl;
}



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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;

void solve(int ze) {
    int n;
    cin >> n;
    int c = 0 , y = 1;
    while(c < n) {
        
        c += pow(26 , y ++);
        //cout << c << ' ';
    }
    //cout << '\n';
    y --;
    n -= (c - pow(26 , y));
    
    //cout << n << ' ' << y << '\n';
    vector<int> v;
    int pr = 0;
    while(y) {
        int t = y;
        //cout << y << ' ' << pr << ' ';
        for(int i = 1 ; i <= 26 ; i ++) {
            if((pow(26 , t - 1) * i) >= (n - pr)){
                v.pb(i) , y -- , pr += pow(26 , t - 1) * (i - 1);
                break;
            }
        }
    }
    
    for(auto x : v) {
        //cout << x << ' ';
        cout << char('a' + (x - 1));
    }
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    return 0;
}
 



Measured memory_bytes: 4048
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<pair<int, int> , pair<int, int> > PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int x, y;

signed main()
{
    cin >> x >> y;
    cout << x + y / 2 << endl;


    return 0;
}
/*




*/



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int c[100010];
bool f[100010];
int sum[100010];
    
int main(){
    for(int i=2;i<=100000;i++){
        if(!f[i])for(int j=i+i;j<=100000;j+=i){
            f[j]=true;
        }
    }
    for(int i=3;i<=100000;i++){
        if(!f[i]&&!f[(i+1)/2])sum[i]=sum[i-1]+1;
        else sum[i]=sum[i-1];
    }
    int q;
    cin >> q;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << sum[r]-sum[l-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}

int main(){
	int n,m;
	cin >>n>>m;
	int bef;
	int tep;
	vector<pair<int,int>>data(m+1,pair<int,int>(0,0));//munber,yen
	vector<vector<int>>dp(m+2,vector<int>((1<<(n+1)),INF));
	dp[0][0]=0;
		//	at,umbder ->yen
	for(int i=0;i<m;i++){
		cin>>data[i].first>>bef;
		for(int j=0;j<bef;j++){
			cin>>tep;
			data[i].second+=(1<<(tep-1));
			
		}
		//cout << "       --->" << data[i].second << endl;
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<(1<<n);j++){
			//cout<<dp[i][j]<<" ";
			chmin(dp[i+1][j],dp[i][j]);
			chmin(dp[i+1][j|data[i].second],dp[i][j]+data[i].first);
		}
		//cout<<endl;
	}
if(dp[m][(1<<n)-1]==INF){
	cout<<-1<<endl;
}else{
	cout<<dp[m][(1<<n)-1]<<endl;
}}

Measured memory_bytes: 32384
#define rep(i,n) for(i=0;i<(n);++i)
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<utility>
#include<string>
#include<algorithm>
#include<bitset>
#include<queue>
#include<cmath>
#include<iomanip>
using ll = unsigned long long int;
using namespace std;

std::vector<pair<ll,ll>> enum_div(ll n)//nの約数を列挙
{
	std::vector<pair<ll,ll>> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back({i,n/i});
			// if(i!=1 && i*i!=n)
			// {
			// 	ret.push_back({n/i,i});
			// }
		}
	}
	return ret;
}

int src(){
    long double a,b,x;
    cin>>a>>b>>x;
    long double theta;
    if((x/a) > a*b/2.0){
        theta = 180/M_PI*atan(2.0/(a*a)*(-x/a+a*b));
    }else{
        theta = 180/M_PI*atan(1.0/( x/(a)*(2.0/(b*b)) ));
    }
    cout<<setprecision(10)<<fixed<<theta;
    return 0;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] );
    //cin.rdbuf(in.rdbuf());
    src();    
    return 0;
}

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


int main(){

    
    int n, k;

    string s;


    cin >> n >> k >> s;


    if( s.at(k - 1) == 'A' ) s.at(k - 1) = 'a';

    if( s.at(k - 1) == 'B' ) s.at(k - 1) = 'b';

    if( s.at(k - 1) == 'C' ) s.at(k - 1) = 'c';


    cout << s << endl;


    return 0;

    }


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1){
			res=res*a;
		}
		a=a*a;
		b>>=1;
	}
	return res;
}

ll a[60];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll x;
	cin>>n>>x;
	a[0]=1;
	REP(i, n){
		a[i+1]=a[i]*2+3;
	}
	ll ans=0;
	int ind=n;
	bool ok=true;
	while(x>0){
		while(x>0 && a[ind]>x){
			--ind;
			--x;
			if(x==0){
				ok=false;
			}
		}
		if(!ok){
			break;
		}
		if(a[ind]==x){
			ans+=(a[ind]+1)/2;
			break;
		}
		if(a[ind]==x+1){
			ans+=(a[ind]+1)/2+1;
			break;
		}
		ans+=(a[ind]+1)/2+1;
		x-=a[ind]+1;
	}
	cout<<ans<<'\n';
	return 0;
}


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

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

Measured memory_bytes: 256
import queue
from collections import deque
h,w,n = map(int,input().split())
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
for i in range(h):
  s = "X" + input() + "X"
  if "S" in s:
    factrys[0] = (i + 1, s.index("S"))
  for j in range(1,n + 1):
    if str(j) in s:
      factrys[j] = (i + 1, s.index(str(j)))
  ss.append(s)
ss.append("X" * (w + 2))

def bfs(i):
  mp = [[None] * (w + 2) for j in range(h + 2)]
  x,y = factrys[i]
  mp[x][y] = 0
  que = queue.Queue()
  que.put((x, y))
  while True:
    (x,y) = que.get()
  #  print(i,x,y)
  #  print(mp[x][y])
    if (x,y) == factrys[i + 1]:
      return mp[x][y]
    count = mp[x][y]
    if ss[x + 1][y] != "X" and mp[x + 1][y] is None:
      mp[x + 1][y] = count + 1
      que.put((x + 1, y))
    if ss[x - 1][y] != "X" and mp[x - 1][y] is None:
      mp[x - 1][y] = count + 1
      que.put((x - 1, y))
    if ss[x][y + 1] != "X" and mp[x][y + 1] is None:
      mp[x][y + 1] = count + 1
      que.put((x, y + 1))
    if ss[x][y - 1] != "X" and mp[x][y - 1] is None:
      mp[x][y - 1] = count + 1
      que.put((x, y - 1))

ans = 0
for i in range(n):
  ret = bfs(i)
  if ret is None:
    ans += 0
  else:
    ans += (ret)
print(ans)


Measured memory_bytes: 29300
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
def main():
    n, d = map(int, input().split())
    r = 0
    m = map(int, read().split())
    ab = zip(m, m)
    d2 = d**2
    for a, b in ab:
        r += (a ** 2 + b ** 2) <= d2
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 107832
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int a,b,c;
set<int> s;

int main(){
    cin>>a>>b>>c;
    s.insert(a);
    s.insert(b);
    s.insert(c);

    cout<<s.size()<<endl;
}

Measured memory_bytes: 256
/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int solve(string s, string t)
{
  int n1 = s.size();
  int n2 = t.size();
  int ans = INT_MAX;
  for (int i = 0; i < n1; i++)
  {
    int cnt = 0;
    int k = i;
    int j = 0;
    if (k + n2 - 1 >= n1)
    {
      continue;
    }
    while (k < n1 && j < n2)
    {
      if (s[k] == t[j])
        cnt++;
      k++;
      j++;
    }
    ans = min(n2 - cnt, ans);

  }
  return ans;
}
int main()
{


  string s;
  string t;
  cin >> s >> t;

  int xx = solve(s, t);

  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());

  int yy = solve(s, t);
  cout << min(xx, yy) << endl;



}







Measured memory_bytes: 3624
// #define int long long
// #define repeat(i, n) for (int i = 0; i < n; ++i)

#include <cmath> // cmath includes sqrt, abs
#include <iostream> // iostream includes cout, endl
#include <string> // string
#include <algorithm> // algorithm includes sort

// #include <bits/stdc++.h>
#include <map>

using namespace std;

int main() {
  bool can = true;
  int num = 0;
  int sum = 0;
  string S;
  int N;
  
  int M;
  int D[200000];
  int T[200000];
  map<int, int> P;
  // int P[1000000000];

  cin >> N;
  for (int i = 0; i < N; ++i) cin >> D[i];
  cin >> M;
  for (int i = 0; i < M; ++i) cin >> T[i];

  // for (int i = 0; i < 1000000000; ++i) P[i] = 0;

  for (int i = 0; i < N; ++i) {
    P[D[i]] = P[D[i]] + 1;
  }

  for (int i = 0; i < M; ++i) {
    if (P[T[i]] > 0) {
      P[T[i]] = P[T[i]] - 1;
    } else {
      can = false;
      break;
    }
  }

  // cout << sum << endl;
  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}












const int limit = 51;
int n,m;
bool vec[limit][limit];
bool vis[limit];

void DFS(int x){
    if(vis[x]) return;

    vis[x] = true;

    REP(i,n){
        if(vec[i][x]){
            DFS(i);
        }
    }
}
using namespace std;
int main(){
    int n,l,ma,sum = 0,anss=INF;
    cin >> n >> l;

    vector<int> vec(n+2),ans(n+2);

    vec[0] = 0;
    FOR(i,1,n+1){
        vec[i] = vec[i-1] + i+ l -1;
        
    }

    ma = vec[n];
    FOR(i,1,n+1){
        ans[i] = ma-(i+l-1);
        sum = max(sum,ans[i]);
        anss = min( abs(ma-ans[i]), anss);
    }
    int ko;
    if(ma > 0){
        ko = ma-anss;
    }else{
        ko = ma + anss;
    }
    cout << ko <<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    Scanner sc = new Scanner(System.in);

    Main(){
	int a=sc.nextInt();
	int b=sc.nextInt();
	System.out.println( (a*b) + " " + (a*2+b*2) );
    }

    public static void main(String[] args){
	new Main();
    }
}


Measured memory_bytes: 26176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		PrimeNumberGenerator png = new PrimeNumberGenerator();
		
		while(true){
			String tmpStr = br.readLine();
			if(tmpStr == null){
				break;
			}
			
			int n = Integer.parseInt(tmpStr);
			
			int count = 0;
			for(int i = 2; i <= n; i++){
				if(png.isPrime(i)){
					//System.out.println(i);
					count++;
				}
			}
			
			System.out.println(count);
		}
	}

}

//?????£???????????¨??????????´???°?????????????????£????????????
class PrimeNumberGenerator {
	private boolean[] isPrime= new boolean[1000000];
	
	public PrimeNumberGenerator() {
		// TODO ?????????????????????????????????????????????????????????
		Arrays.fill(isPrime, true);
		
		isPrime[0] = false;
		isPrime[1] = false;
		isPrime[2] = true;
		
		for(int i = 3; i <= 999999 ; i++){
			if(i % 2 == 0){
				isPrime[i] = false;
				continue;
			}
			
			if(isPrime[i] == false){
				continue;
			}
			
			for(int j = i * 2; j <= 999999; j += i){
				isPrime[j] = false;
			}
		}
	}
	
	public boolean isPrime(int index){
		return isPrime[index];
	}
}

Measured memory_bytes: 25992
#include <stdio.h>
int main(void){
  int n,a,b,c,i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d %d %d",&a,&b,&c);
      
      if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a)){
	  printf("YES\n");
	}    
      else{
	printf("NO\n");
	}
    }
  return 0;
  
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

int main(){
    int n; cin >> n;
    int s[n];

    //リストに格納
    rep(i, 0, n) cin >> s[i];
    //総和
    int sum = 0;
    rep(i, 0, n) sum += s[i];
    //一次判定
    if(sum % 10 != 0) goto end;

    //条件に合うように整形
    sort(s, s + n);
    rep(i, 0, n){
        if(s[i] % 10 != 0){
            sum -= s[i];
            goto end;
        }
    }
    if(sum % 10 == 0) sum = 0;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    int n; cin >> n;
    int tnow = 0, xnow = 0, ynow = 0;
    bool flag = true;
    REP(i, n){
        int tn, xn, yn;
        cin >> tn >> xn >> yn;
        int tlim = tn - tnow;
        int dist = abs(xn - xnow) + abs(yn - ynow);
        if((dist%2) ^ (tlim%2)){
            flag = false;
            break;
        }
        if(dist > tlim){
            flag = false;
            break;
        }
        tnow = tn, xnow = xn, ynow = yn;
    }
    if(flag) Yes();
    else No();
}

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

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

int main() {
	while (1) {
		int i, j, n, k, sum = 0, maxsum;

		cin >> n >> k;
		if (n == 0)break;
		int *a = new int[n + 1];
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}

		for (i = 0; i < k; i++) {
			sum += a[i];
		}

		maxsum = sum;

		for (i = 0; i < n - k; i++) {
			sum -= a[i];
			sum += a[i + k];
			maxsum = max(maxsum, sum);
		}

		cout << maxsum << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3352
#include <stdio.h>
int main(void){
   int a,n,x,i, j, k;
   while(1){
       scanf("%d %d",&n,&x);
       if(n==0&&x==0) break;
       a=0;
for ( i =1;i<=n;i++) {
    for ( j =2;j<=n;j++) {
        for ( k =3;k<=n;k++) {
            if(i<j&&j<k){
                if(x==i+j+k){
                a=a+1;
                }   
            }
        }
    }
}
      printf("%d\n",a);
    }
    return 0;
}



Measured memory_bytes: 2668
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

struct State{
	int bits, f, x, y;
	State(int bits_, int f_, int x_, int y_){
		bits = bits_; f = f_; x = x_; y = y_;
	}
	State(){}
};

const int INF = 1e+8;
// 入力
int w, h, s;
// m[y][x] := (x,y) の状態が返ってくる.
char m[51][51];
// ms[k][y][x] := k 番目のスイッチについて(x,y)が移動するときは '*' が返ってくる
char ms[10][51][51];
// スタートとゴール
int sx, sy, gx, gy;

// d[bits][f][y][x] := スイッチを押した状態bits, f 階の(x,y) までの最小の step数
int d[(1<<10)+1][2][51][51];
// 4近傍
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

// (スイッチの押した状態,階,x座標,y座標)を状態にして幅優先探索
int bfs(){
	// 初期化
	for(int i=0 ; i < (1<<s) ; i++ ){
		for(int f=0 ; f < 2 ; f++ ){
			for(int y=0 ; y < h ; y++ ){
				for(int x=0 ; x < w ; x++ ){
					d[i][f][y][x] = INF;
				}
			}
		}
	}
	queue<State> q;
	q.push( State(0,0,sx,sy) );
	d[0][0][sy][sx] = 0;
	
	int res = -1;
	while( !q.empty() ){
		int x = q.front().x;
		int y = q.front().y;
		int f = q.front().f;
		int bits = q.front().bits;
		int cost = d[bits][f][y][x];
		q.pop();
		// ゴールのとき
		if( x == gx && y == gy ){
			res = cost;
			break;
		}
		
		// 4 方向に移動
		for(int i=0 ; i < 4 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			// (mx,my) が何階にあるか (2Fにいるのは'^'か大文字のアルファベットのときのみ)
			int f2 = ( m[my][mx] == '^' || isupper(m[my][mx])? 1 : 0 );
			// すべてのONのスイッチをチェックして自分の階を調べる
			for(int j=0 ; j < s ; j++ ){
				if( bits & (1<<j) && ms[j][my][mx] == '*' ){
					f2 = (f2+1) % 2;
				}
			}
			// 階段はどちらの階からも行き来可能
			if( m[my][mx] == '|' ) f2 = f;
			
			// 侵入できないとき
			if( m[my][mx] == '#' || f2 != f ) continue;
			
			if( cost + 1 < d[bits][f][my][mx] ){
				d[bits][f][my][mx] = cost + 1;
				q.push( State(bits, f, mx, my) );
            }
		}
		
		// はしごにいるとき
		if( m[y][x] == '|' ){
			int next_f = (f+1) % 2;
			if( cost + 1 < d[bits][next_f][y][x] ){
				d[bits][next_f][y][x] = cost + 1;
				q.push( State(bits, next_f, x, y) );
			}
		}
		
		// スイッチがあるとき
		if( isalpha(m[y][x]) ){
			int k = tolower(m[y][x]) - 'a';
			int f2 = f;
			// xor でk番目のスイッチを ON => OFF か OFF => ON に変更
			int next_bits = bits ^ (1<<k);
			// 自分のいる階が変わるとき
			if( ms[k][y][x] == '*' ){
				f2 = (f2+1) % 2;
			}
			
			if( cost + 1 < d[next_bits][f2][y][x] ){
				d[next_bits][f2][y][x] = cost + 1;
				q.push( State(next_bits, f2, x, y) );
			}
        }
	}
	return res;
}

int main(){
	cin >> w >> h;
	for(int y=0 ; y < h ; y++ ){
		cin >> m[y];
	}
	cin >> s;
	for(int i=0 ; i < s ; i++ ){
		for(int y=0 ; y < h ; y++ ){
			cin >> ms[i][y];
		}
	}
	// スタートとゴールの位置をチェック.
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( m[y][x] == '%' ){
				sx = x; sy = y;
				m[y][x] = '_';
			}else if( m[y][x] == '&' ){
				gx = x; gy = y;
				m[y][x] = '_';
			}
		}
	}
	
	// 解を出力
	cout << bfs() << endl;
}

Measured memory_bytes: 22568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int N = 1e5 + 10;

int n, k;
vector<int> adj[N];
int ans = 0;

void dfs(int u, int par) {
    int mul = k - 1;
    if (par != 0) {
        mul--;
    }
    for (int v : adj[u]) {
        if (par == v) {
            continue;
        }
        ans = mprod(ans, max(0, mul));
        dfs(v, u);
        mul--;
    }
}

int main() {
    cin >> n >> k;
    REP(i, n-1) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ans = k;
    dfs(1, 0);
    cout << ans << endl;
}






























Measured memory_bytes: 10368
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,m = map(int, input().split())
    # 素因数分解
    def prime_decomp(n):
        i = 2
        res = []
        while i ** 2 <= n:
            while n % i==0:
                n //= i
                res.append(i)
            i += 1
        if n > 1:
            res.append(n)
        return res
    a = prime_decomp(m)
    c = Counter(a)

    def ncr(n, r, mod):
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    res = 1
    for v in c.values():
        res *= ncr(n-1+v, n-1, mod)
    print(res % mod)

if __name__ == '__main__':
    main()

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

int dp[3005][3005];
string  getLCS(string &s,string &t,int len)
{
    int i=0,j=0;
    string LCS;
    while(len>0)
    {
        if(s[i]==t[j])
        {
            LCS.push_back(s[i]);
            i++;
            j++;
            len--;
        }
        else
        {
            if(dp[i][j+1]>dp[i+1][j])
                j++;

            else
                i++;
        }
    }
return LCS;
}
int lenLCS(string& s,string& t,int i,int j)  //topdown lcs
{
    if(i>=s.length() || j>=t.length())
        return 0;

    if(dp[i][j]!=-1)
        return dp[i][j];
 
    if(s[i]==t[j])
    { 
        dp[i][j]=1+lenLCS(s,t,i+1,j+1);
        
        return dp[i][j];
        
    }

    else{
        
         dp[i][j] = max(lenLCS(s,t,i+1,j),lenLCS(s,t,i,j+1));
        
         return dp[i][j];
    }

}
string solve(string s,string t)
{
    memset(dp,-1,sizeof dp);
    int len = lenLCS(s,t,0,0);
    return getLCS(s,t,len);
}

int main(){

string s,t;
cin>>s>>t;

cout<<solve(s,t)<<"\n";
return 0;
}



Measured memory_bytes: 35968
#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define f first
#define inf 100000000000000000
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define sc(i) scanf("%lld",&i);
#define s second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=1000000007;
 
// ll arr1[10000009];
// vector<ll> sieve;
// void sievefun(ll n){
//     for(ll i=2;i<=n;i++){
//         if(arr1[i]==0){
//             for(ll j=i*i;j<=n;j+=i){
//                 arr1[j]=1;
//             }
//         }
//     }
//     for(int i=2;i<=n;i++){
//     	if(arr1[i]==0)sieve.pb(i);
//     }
// }
 
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;
 
            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
ll power(ll x, ll y) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return ((temp)*(temp));
	else
		return (((x))*((temp*temp)));
}
ll gcd1(ll a, ll b){
if (a == 0)
    return b;
return gcd1(b % a, a);
}
ll lcm(ll a, ll b)
{
return (a*b)/gcd1(a, b);
}
ll dp[100009][2];
vi g[100009];
void DFS(int node,int p){
	ll temp1=1,temp=1;
	for(auto i:g[node]){
		if(i!=p){
			DFS(i,node);
			temp*=((dp[i][0]+dp[i][1])%mod)%mod;
			temp1*=(dp[i][0]);
			temp%=mod;
			temp1%=mod;
		}
	}
	dp[node][0]=temp;
	dp[node][1]=temp1;
}
int main()
{	//sievefun(10000007);
	//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	ll x,y;
	forn(i,n-1){
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	DFS(1,-1);
	cout<<(dp[1][0]+dp[1][1])%mod;
}

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

#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 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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


int main()
{
int n;
cin>>n;
vector<int> a(n,0);
REP(i,n) cin>>a[i];
sort(a.begin(),a.end());
a.push_back(-1);
int ans=0;
for(int i=0; i<n; i++)
{
    if(a[i]!=a[i+1])
    {
        ++ans;
    }
}
if(ans%2==0) cout<<ans-1<<endl;
else cout<<ans<<endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (B == 1) {
    cout << 0 << endl;
  } else if (A >= B) {
  	cout << 1 << endl;
  } else {
    B -= A;
  	int count = B / (A - 1);
    int amari = B % (A - 1);
    if (amari) count++;
    count++;
    cout << count << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

long long n, c, k, tab[100010], ans;
vector< int > v;
long long sum;
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n;
	for( int a = 1; a <= n; a++ )
	{
		cin>>tab[a];	
	}
	sort( tab + 1, tab + n + 1 );
	int p = 0;
	for( int a = 1; a < n; a++ )
	{
		sum += tab[a];
		if( sum * 2 < tab[a+1] )p = a;
	}
	cout<<n-p;
	return 0;
}
 


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
 
def p_prime(n): 
    prime = [2]
    for i in range(3,n+1):
        flag = 0
        for j in prime:
            if i%j == 0:
                flag = 1
                break
            if i**0.5 < j:
                break
        if flag == 0:
            prime.append(i)
    return prime

prime = p_prime(int(mod**0.5+1))
def soinsuu(M):
    a = {}
    for p in prime:
        count = 0
        while M%p ==0:
            count += 1
            M //= p
        if count > 0:
            a[p] = count
    if M != 1:
        a[M] = 1
    return a

from collections import defaultdict
AA = defaultdict(int)

for i in range(N):
    tmp = soinsuu(A[i])
    for j in tmp:
        AA[j] = max(AA[j], tmp[j])
        
L = 1
for i in AA:
    L *= pow(i,AA[i],mod)

ans = 0
for i in range(N):
    ans += L*pow(A[i],mod-2,mod)
    
print(ans%mod)

Measured memory_bytes: 47964
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  string s, t;
  cin >> s >> t;
  bool ans = false;
  rep(i, s.size()){
    if(s == t) ans = true;
    char c = s[0];
    s = s.substr(1, s.size() - 1) + c;
  }
  puts(ans ? "Yes" : "No");
  return 0;
} 


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

struct Node{
  int key;
  struct Node *next,*prev;
};
struct Node *nil;
struct Node *listSearch(int key){
  struct Node *cur = nil->next;
  while(cur!=nil && cur->key!=key){cur=cur->next;}
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct Node *cur=nil->next;
  int i=0;
  while(1){
    if(cur==nil) break;
    if(i++>0) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i,size=0,np=0,nd=0;;
  char ch[15];

  init();

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",ch,&key);
    if(ch[0]=='i'){
      insert(key);
      np++;
      size++;
    }

    else if(ch[0]=='d'){
      if(strlen(ch)>6){
        if(ch[6]=='F') {deleteFirst();}
        else if(ch[6]=='L') {deleteLast();}
      }
      else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
}


Measured memory_bytes: 33044