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

float getave(float a, float b) {
  float ave;
  ave = (a+b)/2;
  return ave;
}

int main() {
  
  int n; 
  cin >> n;
  
  vector<float> v(n);
  for (int i=0; i<n; i++){
    cin >> v.at(i);
  }
  
  sort(v.begin(),v.end());
  
  double ans = v[0];
  
  for (int i=1; i<n; i++) ans = (ans + v[i])/2;
  printf("%.10f",ans);
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+500;
int a[N];
ll quick(ll a,ll b,ll mod) {
	int ans=1%mod;
	a%=mod;
	while(b) {
		if(b&1)ans=ans*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ans%mod;
}
int main() {
	int n;
	scanf("%d",&n);
	int sum=0;
	for(int i=1; i<=n; ++i) {
		scanf("%1d",&a[i]);
		sum+=a[i];
	}
	if(sum>1) {
		ll cut0=0,cut2=0;
		for(int i=1; i<=n; ++i) {
			if(a[i]==1) {
				cut0=(cut0+quick(2,n-i,sum-1))%(sum-1);
				cut2=(cut2+quick(2,n-i,sum+1))%(sum+1);
			}
		}
		for(int i=1; i<=n; ++i) {
			ll ans=0;
			int cut=1;
			if(a[i]==0) {
				ans+=cut2;
				ans=(ans+quick(2,n-i,sum+1))%(sum+1);
			} else {
				ans+=cut0;
				ans=(ans-quick(2,n-i,sum-1)+(sum-1))%(sum-1);
			}
			while(ans>0) {
				ans=ans%__builtin_popcount(ans);
				cut++;
			}
			printf("%d\n",cut);
		}
	} else if(sum==0) {
		for(int i=1; i<=n; ++i) {
			printf("1\n");
		}
	} else {
		for(int i=1; i<=n; i++) {
			if(a[i]==1) {
				printf("0\n");
			} else {
				if(i==n)printf("2\n");
				else printf("1\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4576
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;



int main()
{
    int m,n,o=0,i,j,k;
    int sum=0,sum2=0,range=0;
    double ans=0.0,half;
    //long long int m,n,o,i,j,k=0;
    //vector <int> v;
    //float f,g,h;
    char now,pre;
    //string a;
    int num[ten5];
    cin>>n;
    for(i=0;i<ten5;i++) num[i]=0;
    for(i=0;i<n;i++)
    {
        cin>>m;
        num[m]++;
        num[m+1]++;
        if(m!=0) num[m-1]++;
    }
    for(i=0;i<ten5;i++) range=max(range,num[i]);
    cout<<range;
    return 0;
}





Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, j, n) for (int i = j; i < (n); ++i);
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int n; cin >> n;
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 2 == 1) {
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 3604
# include <stdio.h>
# include <stdlib.h>
# define MAX 101
int main()

{
    int n;
    int d[MAX];
    long sum=0;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&d[i]);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            sum += d[i]*d[j];
        }
    }
    printf("%ld", sum);
    system("pause");
    return 0;

}

Measured memory_bytes: 376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 100000
#define mod 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sd(n) scanf("%lld",&n)
int main()
{
 ll a,b;
 string s;
 cin>>a>>b>>s;
 bool fl=1;
 for(int i=0;i<s.length();i++)
 {
  if(i==a)
  {
    if(s[i]!='-')
    {
      fl=0;
      break;
    }
  }
  else
  {
    if(s[i]<'0'||s[i]>'9')
    {
      fl=0;
      break;
    }
  }
 }
 if(fl)
  cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d){
        cout << "Yes" << endl;
    }else if(abs(a - b) <= d && abs(b - c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
A = list(input().split() for l in range(3))
N = int(input())
B = list(int(input()) for i in range(N))

for s in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == str(s):
                A[i][j] = "0"

def bingo(A):
    for i in range(3):
        if A[i][0] + A[i][1] + A[i][2] == "000" or A[0][i] + A[1][i] + A[2][i] == "000" or A[0][0] + A[1][1] + A[2][2] == "000" or A[0][2] + A[1][1] + A[2][0] == "000":
            return "Yes"
    return "No"

print(bingo(A))


Measured memory_bytes: 3064
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        N: i64,
    }

    let ans: i64 = (1..N + 1).filter(|n| n % 3 != 0 && n % 5 != 0).sum();
    // let ans: u32 = (1..n + 1).filter(|i| i % 3 != 0 && i % 5 != 0).sum();
    println!("{}", ans);
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define N 1000000
vector<int> par(N);
vector<int> ranks(N);

void init(int n)
{
  int i;
  rep(i,n)
  {
    par[i]=i;
    ranks[i]=0;
  }
}

int find(int x)
{
  if(par[x]==x)return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y)
{
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(ranks[x]<ranks[y])par[x]=y;
  else
  {
    par[y]=x;
    if(ranks[x]==ranks[y])ranks[x]++;
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}

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

int main()
{
  int n;cin>>n;
  vector<int> x(n);
  vector<int> y(n);
  int i;
  rep(i,n)cin>>x[i]>>y[i];
  vector<pair<int,int>> p1(n);
  rep(i,n)p1[i]=make_pair(x[i],i);
  vector<pair<int,int>> p2(n);
  rep(i,n)p2[i]=make_pair(y[i],i);
  sort(all(p1));
  sort(all(p2));
  vector<int> a(n*2-2);
  vector<int> b(n*2-2);
  vector<int> c(n*2-2);
  rep(i,n-1)
  {
    a[i*2]=p1[i].second;
    b[i*2]=p1[i+1].second;
    c[i*2]=p1[i+1].first-p1[i].first;
    a[i*2+1]=p2[i].second;
    b[i*2+1]=p2[i+1].second;
    c[i*2+1]=p2[i+1].first-p2[i].first;
  }
  vector<pair<int,int>> g(n*2-2);
  rep(i,n*2-2)
  {
    g[i]=make_pair(c[i],i);
  }
  sort(all(g));
  init(n);
  int ans=0;
  rep(i,n*2-2)
  {
    int nowi=g[i].second;
    if(!same(a[nowi],b[nowi]))
    {
      unite(a[nowi],b[nowi]);
      ans+=g[i].first;
    }
  }
  cout<<ans<<endl;
}

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

#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define ll long long int
#define mod 1000000007
const int N=1e5+5;

int n,k;
int cache[N];
int val[N];

int dp(int pos)
{
	if(pos==0)
		return cache[pos];
	for(int i=pos-1;i>=max(0,pos-k);i--)
	{
		cache[i]=min(cache[i],cache[pos]+abs(val[pos]-val[i]));
	}
	return dp(pos-1);
}

int32_t main()
{
	fastIO;
	
	int i;
	cin>>n>>k;
	for(i=0;i<n;i++)
		cin>>val[i];
	for(i=0;i<n;i++)
		cache[i]=INT_MAX;
	cache[n-1]=0;
	
	cout<<dp(n-1);

	return 0;
}

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



int main() {
   int h1, m1, h2, m2, k;
   cin >> h1 >> m1 >> h2 >> m2 >> k;
   cout << h2*60+m2-k-(h1*60+m1) << endl;
   return 0;
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    }

    public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    }
}

Measured memory_bytes: 22996
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int difx = x2 - x1;
  int dify = y2 - y1;

  int x3 = x2 - dify;
  int y3 = y2 + difx;
  int x4 = x1 - dify;
  int y4 = y1 + difx;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}


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

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (; N >= 3; N--, r.erase(r.begin())) {
		do {
			double ub = DBL_MAX;
			for (int i = 0; i < N; i++)
				ub = min(ub, (double)r[i] * r[(i + 1) % N]);
			double lb = -ub;
			bool ok = false;
			for (int t = 0; t < 50; t++) {
				double mid = (lb + ub) / 2, sum = 0;
				for (int i = 0; i < N; i++)
					sum += acos(mid / r[i] / r[(i + 1) % N]);
				if (sum <= M_PI*2) {
					ub = mid;
					ok = true;
				}
				else lb = mid;
			}
			if (!ok) continue;
			double S = 0;
			for (int i = 0; i < N; i++)
				S += sqrt(pow(r[i] * r[(i + 1) % N], 2) - lb * lb);
			ma = max(ma, S);
		} while (next_permutation(r.begin(), r.end()));
	}
	printf("%.15f\n", ma / 2);
}

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

int main(){
    long long n,min,time;
    min=1000000000000000;
    long long array[5];
    cin>>n;
    for(int i=0;i<5;i++){
        cin>>array[i];
        if(min>array[i]) min=array[i];
    }
    time=n/min;
    if(n%min!=0)
    time+=5;
    else if(n%min==0)
    {
        time+=4;
    }
    
    cout<<time<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
li = list(map(int, input().split()))

list = list(np.arange(1, N+1))
check = 1
for i in range(N):
    if li[i] == check:
        check += 1

count = N - (check - 1)
if check == 1:
    print(-1)
else:
    print(count)


Measured memory_bytes: 34128
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

int tbl[25][25];
int N;
int node[25];
int res;
int sum;
int maxt;

void dfs1 (int curr, int parent )
{
	bool found = false;

	rep (i, N ){
		if (i != curr && i != parent && tbl[curr][i] ){
			found = true;
//			cout << curr << " is middle node." << endl; 
			dfs1 (i, curr );
		} // end if
	} // end rep

	if (!found ){
//		cout << curr << " is leaf. " << endl;
		node[curr] = 1;
	} // end if
}

void dfs2 (int curr, int parent )
{
	rep (i, N ){
		if (i != parent && tbl[curr][i] && !node[i] ){
			res += tbl[curr][i];
			sum += tbl[curr][i];
//			cout << curr << " -> " << i << " sum:" << sum << endl;
			maxt = max (maxt, sum );
			dfs2 (i, curr );
			res += tbl[curr][i];
			sum -= tbl[curr][i];
		} // end if
	} // end rep
}		

int main()
{
//	cut here before submit 
//	freopen ("testcase.SR", "r", stdin );
	int n;
	while (cin >> n && n ){
		memset (tbl, 0, sizeof (tbl ) );
		memset (node, 0, sizeof (node ) );
		rep (i, n-1 ){
			int a, b, t;
			cin >> a >> b >> t;
			N = max (N, max (a, b ) );	
			a--; b--;
			tbl[a][b] = t;
			tbl[b][a] = t;
		} // end rep
		res = 0;
		maxt = 0;
		sum = 0;
		dfs1 (0, -1 );
		dfs2 (0, -1 );
		cout << res - maxt << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int ans = 0;
		for (int i = 1; i <= N; i+=2) {
			int tot = 0;
			for (int j = 1; j <= i ; j++) {
				if (i % j == 0) tot++;
			}
			if (tot == 8) ans++;
		}
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 21332
n,m=map(int,input().split())
l=[0]*n
s_list=[]
x=0
for i in range(m):
  s,c=map(int,input().split())
  if s in set(s_list) and l[s-1]!=c:
    x=-1
    break
  else:
    s_list.append(s)
    l[s-1]=c
if x==-1 or (1 in set(s_list) and n>1 and l[0]==0):
  print(-1)
else:
  if not 1 in set(s_list) and n>1:
    l[0]=1
  re=map(str,l)
  print(int(''.join(re)))

Measured memory_bytes: 3064
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {in_k: usize, in_a: usize, in_b: usize};

    let (a_d, a_m) = (in_a / in_k, in_a % in_k);
    let (b_d, b_m) = (in_b / in_k, in_b % in_k);

    if a_m == 0 || b_m == 0 {
        println!("OK");
    }    
    else if a_d != b_d{
        println!("OK");
    }
    else{
        println!("NG");
    }
}


Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
int a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  REP(i, n) cin >> a[i];
  sort(a, a + n);

  vector<P> pv(m);
  REP(i, m) {
    int b, c;
    cin >> b >> c;
    pv.push_back(P(c, b));
  }
  sort(pv.begin(), pv.end(), greater<P>());

  int index = 0;
  REP(i, m) {
    P p = pv[i];
    bool f = false;
    REP(j, p.second) {
      if(a[index] >= p.first || index >= n) {
        f = true;
        break;
      } else {
        a[index++] = p.first;
      }
    }
    if(f) break;
  }

  ll ans = 0;
  REP(i, n) {
    ans += a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2176
#include<stdio.h>
long long f(long long a,int b){
  if(b==0||b==4)return a;
  if(b==1||b==3)return a?a%2:2;
  return 1-a%2;
}
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  long long n,a,i,j,k,min,d[200010][5]={};
  scanf("%lld",&n);
  for(i=1;i<5;i++)d[0][i]=1e18;
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    for(j=0;j<5;j++){
      min=1e18;
      for(k=0;k<=j;k++)min=MIN(d[i][k],min);
      d[i+1][j]=min+f(a,j);
    }
  }
  min=1e18;
  for(i=0;i<5;i++)min=MIN(min,d[n][i]);
  /*for(i=0;i<=n;i++){
    for(a=0;a<5;a++)printf("%3lld ",d[i][a]);printf("\n");
    }//*/
  printf("%lld\n",min);
  return 0;
}


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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> ban(h);
    for (int i = 0; i < h; i++) cin >> ban[i];

    vector<vector<vector<int>>> dp(h, vector<vector<int>>(w, vector<int>(4)));
    for (int i = 0; i < h; i++) {
        dp[i][0][0] = (ban[i][0] == '.' ? 1 : 0);
        for (int j = 1; j < w; j++)
            dp[i][j][0] = ban[i][j] == '.' ? dp[i][j - 1][0] + 1 : 0;
    }
    for (int j = 0; j < w; j++) {
        dp[0][j][1] = (ban[0][j] == '.' ? 1 : 0);
        for (int i = 1; i < h; i++)
            dp[i][j][1] = ban[i][j] == '.' ? dp[i - 1][j][1] + 1 : 0;
    }
    for (int i = 0; i < h; i++) {
        dp[i][w - 1][2] = (ban[i][w - 1] == '.' ? 1 : 0);
        for (int j = w - 2; j >= 0; j--)
            dp[i][j][2] = ban[i][j] == '.' ? dp[i][j + 1][2] + 1 : 0;
    }
    for (int j = 0; j < w; j++) {
        dp[h - 1][j][3] = (ban[h - 1][j] == '.' ? 1 : 0);
        for (int i = h - 2; i >= 0; i--)
            dp[i][j][3] = ban[i][j] == '.' ? dp[i + 1][j][3] + 1 : 0;
    }

    int ret = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ret = max(ret, dp[i][j][0] + dp[i][j][1] + dp[i][j][2] + dp[i][j][3]);
        }
    }

    cout << ret - 3 << endl;
    return 0;
}

Measured memory_bytes: 223232
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    vector<vector<pair<int, int>>> edges(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push({0, k});
    vector<char> visited(n);
    vector<ll> lens(n, MLL);
    while(pq.size()){
        auto e = pq.top(); pq.pop();
        if(visited[e.second]){ continue; }
        visited[e.second] = true;
        lens[e.second] = e.first;
        for(auto edge : edges[e.second]){
            pq.push({e.first + edge.second, edge.first});
        }
    }
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << lens[x] + lens[y] << '\n';
    }
    exit(0);
}


Measured memory_bytes: 10096
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstring>

using namespace std;

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

    for (int i = 0; i < 100; i++) {
        if ((int)s.find(t) != -1) {
            cout << "Yes" << endl;
            return (0);
        }
        s.push_back(s[0]);
        s.erase(s.begin());
    }
    cout << "No" << endl;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define DBG 0

int N=50;
int K=250;
int A[50][50];

int cnt;

int q(int y1,int x1,int y2,int x2){
    if((y2-y1)*(x2-x1)==0)return 0;

    if(DBG){
        int res=0;
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)res+=A[y][x];
        return res;
    }

    else{
        cout<<"? "<<y1<<" "<<x1<<" "<<y2-1<<" "<<x2-1<<endl;
        int p;cin>>p;
        return p;
    }
}


vector<int>lis[2555];
int dfs(int y1,int x1,int y2,int x2,int p){
    if(y1==y2)return 0;
    if(x1==x2)return 0;

    if((y2-y1)*(x2-x1)==p){
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)A[y][x]=1;
        return 0;
    }

    if(p==0)return 0;
    int y3=(y1+y2)/2;
    int x3=(x1+x2)/2;

    int pl=q(y1,x1,y2,x3);
    int pu=q(y1,x1,y3,x2);

    int p11,p12,p21,p22;

    int cnt=2;

    if(pl==0){
        p11=p21=0;
        p12=pu;
        p22=p-pu;
    }
    else if(pl==p){
        p12=p22=0;
        p11=pu;
        p21=p-pu;
    }
    else if(pu==0){
        p11=p12=0;
        p21=pl;
        p22=p-pl;
    }
    else if(pu==p){
        p21=p22=0;
        p11=pl;
        p12=p-pl;
    }
    else{
        p11=q(y1,x1,y3,x3);
        p12=pu-p11;
        p21=pl-p11;
        p22=p-p11-p12-p21;
        cnt++;
    }

    cnt+=dfs(y1,x1,y3,x3,p11);
    cnt+=dfs(y1,x3,y3,x2,p12);
    cnt+=dfs(y3,x1,y2,x3,p21);
    cnt+=dfs(y3,x3,y2,x2,p22);

    lis[(y2-y1)*(x2-x1)].pb(cnt);
    return cnt;
}
const int B=16;

signed main(){
    if(DBG){
        vector<pint>v;
        rep(i,N)rep(j,N)v.pb({i,j});
        srand((unsigned)time(NULL));
        random_shuffle(all(v));

        for(int i=0;i<K;i++){
            A[v[i].fi][v[i].se]=1;
        }
        int sum=0;
        for(int i=0;i<(N+B-1)/B;i++){
            for(int j=0;j<(N+B-1)/B;j++){
                int p=q(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B));
                sum++;
                sum+=dfs(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B),p);
            }
        }
        int cnt=0;
        rep(i,N)rep(j,N)cnt+=A[i][j];
        cout<<cnt<<endl;
        cout<<sum<<endl;

        cout<<dfs(0,0,N,N,K)<<endl;
    }

    else{
        int tmp;
        cin>>tmp;cin>>tmp;cin>>tmp;
        int mod;cin>>mod;

        for(int i=0;i<(N+B-1)/B;i++){
            for(int j=0;j<(N+B-1)/B;j++){
                int p=q(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B));
                dfs(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B),p);
            }
        }

        int p=1;
        int res=0;
        rep(i,N)rep(j,N){
            res=(res+p*A[i][j])%mod;
            p=p*2%mod;
        }

        cout<<"! "<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 848
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;

#define F(i) for (int i = 0; i < 3; ++i)
struct Mat {
	int a[3][3];
	Mat() {}
	Mat(int v) {
		F(i) F(j) a[i][j] = (i == j) * v;
	}
	int * operator [] (int i) {
		return a[i];
	}
	friend Mat operator * (Mat a, Mat b) {
		Mat c(0);
		F(i) F(k) F(j) c[i][j] = (c[i][j] + (LL)a[i][k] * b[k][j]) % Mod;
		return c;
	}
};

int N, M;
Mat A, B, Ans(1);

int main() {
	A[0][0] = 2, A[0][1] = 1, A[0][2] = 1;
	A[1][0] = 2, A[1][1] = 1, A[1][2] = 0;
	A[2][0] = 1, A[2][1] = 1, A[2][2] = 1;
	B[0][0] = 1, B[0][1] = 0, B[0][2] = 0;
	B[1][0] = 2, B[1][1] = 1, B[1][2] = 0;
	B[2][0] = 1, B[2][1] = 1, B[2][2] = 1;
	scanf("%d%d", &N, &M);
	int lst = 0;
	for (int i = 1, x; i <= M; ++i) {
		scanf("%d", &x);
		int e = x - lst - 1;
		Mat C = A;
		for (; e; e >>= 1, C = C * C)
			if (e & 1) Ans = C * Ans;
		Ans = B * Ans;
		lst = x;
	}
	int e = N - lst - 1;
	Mat C = A;
	for (; e; e >>= 1, C = C * C)
		if (e & 1) Ans = C * Ans;
	Ans = B * Ans;
	printf("%d\n", Ans[2][0]);
	return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>

int main()
{
	char S[200001];
	scanf("%s", S);
	
	int i, j, k, res[2][2019] = {};
	long long count = 0;
	for (i = 1, res[0][S[0]-'0'] = 1; S[i] != 0; i++) {
		for (j = 0; j < 2019; j++) {
			k = (j * 10 + S[i] - '0') % 2019;
			res[i%2][k] = res[1-i%2][j];
		}
		res[i%2][S[i]-'0']++;
		count += res[i%2][0];
	}
	
	printf("%lld\n", count);
	fflush(stdout);
	return 0;
}

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

int main() {
	vector<int> menu(5);
	int min = 10, answer = 0;
	for (int i = 0;i < 5; i++){
		cin >> menu.at(i);
		//cout << " dbg men " << menu.at(i) << endl;
		if ((min > (menu.at(i) % 10)) && ((menu.at(i) % 10) != 0)){
			//cout << "dbg minin " << min << (menu.at(i) % 10) << endl;
			
			min = (menu.at(i) % 10);
		}
	}
	if (min == 10){
		min = 0;
	}
	for (int i = 0; i < 5; i++){
		if (menu.at(i) % 10){
			menu.at(i) = ((menu.at(i) /10) + 1) * 10;
		//	cout << "dbg " << i << " " << menu.at(i) << endl;
		}
		answer += menu.at(i);
	}
	//cout << "dbg min" << min << " ans" << answer << endl;
	if (min){
		cout << answer - 10 + min << endl;
	}else{
		cout << answer << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,R;
    cin>>N>>R;
    int ans;
    if(N>=10)cout<<R;
    else{
        cout<<R+100*(10-N);
    }
    return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n, k;
    cin >> n >> k;
    cout << min( n%k, abs((n%k)-k) ) << endl;
    return 0;
}


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

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

  int ans = 0;
  if (s[0]==t[0])
  ans++;
  if (s[1]==t[1])
  ans++;
  if (s[2]==t[2])
  ans++;

  cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

// s をスタートとしたときの最長パスを求める
ll longest_path(const vector<vector<int>>& path, const int& s, vector<ll>& lp) {
  if (lp[s] != -1) return lp[s];
  ll ans = 0;
  for (auto& y : path[s]) {
    ll tmp = longest_path(path, y, lp);
    chmax(ans, tmp+1);
  }
  lp[s] = ans;
  return ans;
}

int main(int argc, char* argv[])
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> path(n, vector<int>());

  rep(i, m) {
    int x , y;
    cin >> x >> y;
    x--; y--;
    path[x].push_back(y);
  }

  vector<ll> lp(n, -1);  // i を出発点とした時の最長パス
  ll ans = 0;
  rep(i, n) {
    ll tmp = longest_path(path, i, lp);
    chmax(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9216
def solve(N, XUs):
    p = 380000.0
    ans = 0
    for x, u in XUs:
        if u == "BTC":
            ans += float(x) * p
        else:
            ans += float(x)
    return ans


if __name__ == "__main__":
    N = int(input())
    XUs = list(tuple(input().split(" ")) for _ in range(N))
    print(solve(N, XUs))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int x; cin>>x;
    cout<<x/11*2+(x%11+5)/6<<endl;
}

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

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

    struct shop{
        int price;
        int num;
    };

    vector<shop> shops(N);

    for(int i =0; i < N; i++)
    {
        cin >> shops.at(i).price >> shops.at(i).num;
    }
    sort(shops.begin(), shops.end(), [](const shop &x, const shop &y){return x.price < y.price;});

    int numOfDrinks = 0;
    int j = -1;
    while(numOfDrinks < M)
    {
        j ++;
        numOfDrinks += shops.at(j).num;
    }
    long sumOfPrice = 0;
    for(int i = 0; i < j + 1; i++)
    {
        sumOfPrice += (long)shops.at(i).price * (long)shops.at(i).num;
    }
    sumOfPrice -= (long)shops.at(j).price * (long)(numOfDrinks - M);
    
    cout << sumOfPrice << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,s;
	cin>>a>>s;
	int d,f=0;
	for(int i=1;i<=a;i++)
	{
		cin>>d;
		f+=d;
		if(f>s){
			cout<<i;
			return 0;
		}
	}
	cout<<a+1;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d){
        cout<<"Left";
    }
    else if(a+b<c+d){
        cout<<"Right";
    }
    else if(a+b==c+d){
        cout<<"Balanced";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  string s;
  cin>>s;
  if(s == "Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(s =="Cloudy"){
    cout <<"Rainy"<<endl;
  }
  else if(s=="Rainy"){
    cout <<"Sunny"<<endl;
  }
  


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  map<string, int> s;
  rep(i, n){
    string t;
    cin >> t;
    s[t]++;
  }
  int maxNum = 0;
  for(auto a : s){
    maxNum = maxNum < a.second ? a.second : maxNum;
  }
  for(auto a : s){
    if(maxNum == a.second){
      cout << a.first << endl;
    }
  }
}

Measured memory_bytes: 26752
import numpy as np
import sys

input = sys.stdin.readline

a,b  =  map(int,input().split())


cnt = b - a +1

if a <= 0 and b >= 0:
    print("Zero")
elif a > 0 and b > 0:
    print("Positive")
elif a < 0 and b < 0 and cnt%2 == 0:
    print("Positive")
elif a < 0 and b < 0 and cnt%2 == 1:
    print("Negative")

Measured memory_bytes: 22316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)

int main()
{
    fast;
    int n;
    cin>>n;
    n%=1000;
    //cout<<n<<endl;
    cout<<(n?1000-n:0)<<endl;
}



Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  LL N, M; cin >> N >> M;
  vector<LL> A(N); cin >> A;

  priority_queue<LL> que;
  for (LL x : A) que.push(x);

  for (int i = 0; i < M; ++i) {
    LL x = que.top(); que.pop();
    que.push(x/2);
  }

  LL sum = 0;
  while (!que.empty()) {
    LL x = que.top(); que.pop();
    sum += x;
  }
  cout << sum << endl;
}


Measured memory_bytes: 5024
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    int n,k=0;
    long long sum=0;
    scanf("%d",&n);
    int num[100005];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        if(num[i]<0)
        {
            num[i]=-num[i];
            k++;
        }
        sum+=num[i];
    }
    sort(num,num+n);
    if(k%2!=0)
       sum=sum-num[0]*2;
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 4208
import sys
import collections

class UnionFind:
    def __init__(self, size):
        self.parent = [-1] * (size + 1)  # 非負なら親ノード，負ならグループの要素数

    def root(self, x):  # root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[x])  # xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y):  # merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]:  # xの要素数がyの要素数より「小さい」とき入れ替える
            x, y = y, x
        self.parent[x] += self.parent[y]  # xの要素数を更新
        self.parent[y] = x  # yをxにつなぐ
        return True

    def issame(self, x, y):  # same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)

    def size(self, x):  # size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]


def do():
    sys.setrecursionlimit(100000000)

    N, M, K = map(int, input().split())
    friends = [list(map(int, input().split())) for _ in range(M)]
    blocks = [list(map(int, input().split())) for _ in range(K)]

    uf1 = UnionFind(N + 1) # 友達候補のUF
    friends_list= [set() for _ in range(N + 1)]
    block_list = [set() for _ in range(N + 1)]

    for query in friends :
        a,b= query
        uf1.merge(a,b)
        friends_list[a].add(b)
        friends_list[b].add(a)

    for query in blocks:
        a, b = query
        block_list[a].add(b)
        block_list[b].add(a)
    anss = []
    for i in range(1,N+1):
        s = uf1.size(i) -1 #ベースの人数

        friends = friends_list[i]
        for friend in friends:
            if uf1.issame(friend,i):
                s -=1

        blocks = block_list[i]
        for block in blocks:
            if uf1.issame(block,i):
                s -=1
        anss.append(s)
    print(*(anss))

if __name__ == "__main__":
    do()

Measured memory_bytes: 109888
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a, b, x; cin >> a >> b >> x;
  if(a<=x && x <= a+b) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    S = ' ' + S;
    ll dp[S.length()];

    dp[0] = 0;
    dp[1] = 1;
    for(int i=2; i<S.length(); i++) {
        if(S[i] != S[i-1]) {
            dp[i] = dp[i-1] + 1;
        } else {
            if(i==2) {
                dp[i] = 1;
            } else {
                dp[i] = dp[i-3] + 2;
            }
        }
    }
    
    cout << dp[S.length()-1] << endl;

    return 0;
}

Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int h, w;
char s[100][100];
int ans[100][100];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };

void bfs(int a, int b) {
	queue<P> que;
	que.push(P(a, b));
	while (!que.empty()) {
		int e = que.front().first, f = que.front().second;
		que.pop();
		rep(i, 4) {
			int A = e + dx[i], B = f + dy[i];
			if (A < 0 || B < 0 || A >= h || B >= w) continue;
			if (s[A][B] == '#') continue;
			if (ans[A][B] != inf) continue;
			ans[A][B] = ans[e][f] + 1;
			que.push(P(A, B));
		}
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> h >> w;
	int res = 0;
	rep(i, h)rep(j, w) {
		cin >> s[i][j];
		if (s[i][j] == '#') res++;
	}
	rep(i, h)rep(j, w) ans[i][j] = inf;

	ans[0][0] = 0;
	bfs(0, 0);
	if (ans[h - 1][w - 1] == inf) {
		dunk(-1);
		return 0;
	}

	int j_ans = h * w - res - (ans[h - 1][w - 1] + 1);

	dunk(j_ans);
	
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std; 
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; }

const long long INF = 1LL << 60;
 
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,0,n) cin >> a[i];

    int cnt = 0;
    REP(i,1,n) {
        if (a[i-1] == a[i]) {
            cnt++;
            a[i] = 0;
        }
    }

    cout << cnt << endl;
}

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

combinations = {}

def create_combinations(idx, sum):
    combinations[sum] = 1
    if idx >= N:
        return
    create_combinations(idx+1, sum)
    create_combinations(idx+1, sum+A[idx])
    return

create_combinations(0, 0)

for target in M:
    if target in combinations.keys():
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5644
# coding: utf-8
X = input()
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    elif x == "T" and tmp[-1]=="S":
            cnt -= 1
            tmp = tmp[0:len(tmp)-1]
    else:
        tmp += x
        cnt += 1
print(cnt)


Measured memory_bytes: 3756
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
int main(void){
  
 int a;
  
  cin>>a;
  
  if(a==3||a==5||a==7){
    
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
    
  
  return 0;
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  int s[h][w]={};
  int cnt=0;
  rep(i,h){
    cnt++;
    if(cnt<=b){
      rep(j,w){
        if(j<a)s[i][j]=0;
        else s[i][j]=1;
      }
    }else{
      rep(j,w){
        if(j<a)s[i][j]=1;
        else s[i][j]=0;
      }
    }
  }
  rep(i,h){
    rep(j,w)cout << s[i][j];
    cout << endl;
  }
return 0;}

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,bottom,ceiling) for(auto (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(auto (i) = (ceiling); (i) >= (bottom); --(i))
#define repS(n) for(int s = 0; s < 1 << n; ++s)
#define repV(i,v) for(auto (i) = begin(v); (i) < end(v); ++(i))
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define divceil(n,d) ((n)/(d) + ((n)%(d) > 0))
#define parity(a,b) (((a) & 1)^((b) & 1)^1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = -1 + (1<<30);
const int MOD = (int)1e9 + 7;

ull next_subset(ull subset){
	ull tem = subset + (subset & -subset);
	ull btm = (~tem & subset) / (subset & -subset) >> 1;
	return btm | tem;
}

ll N,A[200001];
ll S[200001];

void solve(){
	
	ll cnt = 0,cur = 0;
	ll r = 0,last = 0;
	
	rep(i,N){
		while(r < N){
			cur ^= A[r];
			if(cur != S[r + 1] - S[i]) break;
			++r;
		}
		ll len = r - i, len2 = last - i;
		cnt += len * (len - 1) / 2 - len2 * (len2 - 1) / 2 + len - len2;
		cur ^= A[i];
		cur ^= A[r];
		last = r;
	}
	
	cout<<cnt<<endl;
	
	return;
}

void input(){
	
	cin>>N;
	S[0] = 0;
	rep(i,N){ cin>>A[i]; S[i+1] = S[i] + A[i]; }
	
	return;
}

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





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

vector<int> v;
int n;

int main(){
scanf("%d",&n);
for (int x = 0; x<n; x++){
    int t;
    scanf("%d",&t);
    v.push_back(t);
}
sort(v.begin(),v.end(),greater<int>());
v.push_back(0);
for (int x = 0; x<=n; x++){
    if (v[x]<=x){
        int x1 = 1;
        int x2 = 1;
        x1 = v[x-1]-(x-1);

        int y = x;
        if (v[x]==x){
            while (v[y]==v[x] && y!=n){
                y++;
            }
            x2 = y-x+1;
        }

        if (x2%2==1 && x1%2==1){
            printf("Second");
        }
        else{
            printf("First");
        }
        return 0;
    }
}
}


Measured memory_bytes: 892
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        B[i], C[i] = map(int, input().split())
        
    #output
    from collections import Counter
    D = Counter(A)
    S = sum(A)

    for i in range(Q):
        x = D[B[i]]
        temp = S - x*B[i] + x*C[i] 
        print(temp)
        D[B[i]] = 0
        D[C[i]] += x
        S = temp    

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()


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

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m, k;
	static long mod = 998244353;
	static Boolean[][][] memo;
	static String s;
	static HashSet<Integer> nodes;
	static ArrayList<Integer>[] ad;
	static boolean[] vis;
	static TreeSet<Long> al;
	static int[][] val;
	static int[] b;
	static int ans;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		int q = sc.nextInt();
		val = new int[q][4];
		for (int i = 0; i < q; i++) {
			val[i][0] = sc.nextInt();
			val[i][1] = sc.nextInt();
			val[i][2] = sc.nextInt();
			val[i][3] = sc.nextInt();
		}
		b = new int[n];
		rec(0, 1);
		System.out.println(ans);
		out.flush();
	}

	static void rec(int i, int l) {
		if (i == n) {
			int tem = 0;
			for (int j = 0; j < val.length; j++) {
                   if(b[val[j][1]-1]-b[val[j][0]-1]==val[j][2])
                	   tem+=val[j][3];
			}
			ans = Math.max(ans, tem);
			return;
		}
		for (int j = l; j <= m; j++) {
			b[i] = j;
			rec(i + 1, j);
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 33760
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}



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

    ll N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    ll ans = 0;
    Rep (i, K) {
        string s;
        for (ll j = i; j < N; j += K) {
            s += T[j];
        }

        vector<char> run;
        vector<ll> length;
        ll cnt = 1;
        Rep (j, s.size()-1) {
            if (s[j] == s[j+1]) {
                cnt++;
            } else {
                run.push_back(s[j]);
                length.push_back(cnt);
                cnt = 1;
            }
        }
        run.push_back(s[s.size()-1]);
        length.push_back(cnt);

        Rep (j, run.size()) {
            // cout << run[j] << " " << length[j] << endl;
            if (run[j] == 'r') {
                ans += (length[j]+1)/2 * P;
            } else if (run[j] == 's') {
                ans += (length[j]+1)/2 * R;
            } else {
                ans += (length[j]+1)/2 * S;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1736