akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    int cnt = 0;
    rep(i,1,N-1){
        int ma = max({V[i-1], V[i], V[i+1]});
        int mi = min({V[i-1], V[i], V[i+1]});
        if(V[i] != ma && V[i] != mi)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int *T, N, K, result = 0;
    cin >> N >> K;
    T = new int[N];

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

    sort(T, T + N, greater<int>());

    for (int i = 0; i < K; i++)
        result += T[i];

    cout << result << endl;

    return 0;
}

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

int main()
{
  long s, s_len = 0, total = 0;
  cin >> s;
  for (long sdiv = s; sdiv > 0; sdiv /= 10) s_len++;
  for (long i = 0; i < 1 << (s_len - 1); i++) {
    long cache = s, div = 10;
    for (long j = 0; j < s_len - 1; j++) {
      if (i & (1 << j)) {
        total += cache % div;
        cache /= div;
        div = 10;
      } else {
        div *= 10;
      }
    }
    total += cache;
  }
  cout << total << endl;
}


Measured memory_bytes: 256
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	string s;
	cin >> s;
	string s1 = s.substr(0,s.size()/2);
	string s2 = s.substr(s.size()/2);
	int ans = 0;
	reverse(s2.begin(), s2.end());
	Rep(i,0,s1.size()){
		if(s1[i] != s2[i]){
			ans += 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int queue[1000];
int head=0;
int tail=0;
int n;
int adj[101][101];
int d[101];
int used[101];
void push(int x){
  queue[head]=x;
  head++;
}
int pop(){
  int x;
  x=queue[tail];
  tail++;
  return x;
}
void bfs(int x){
  int i;
  int v;
  push(x);
  used[x]=1;
  while(head!=tail){
    // for(i=tail;i<head;i++)printf("%d ",queue[i]);
    // printf("\n");
    v=pop();
    for(i=1;i<=n;i++){
      if(adj[v][i]==1 && used[i]==0){
	push(i);
	d[i]=d[v]+1;
	used[i]=1;
      }
    }
  }
}
int main(){
  int i,j;
  int u,k,v;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
    adj[u][v]=1;
    }
  }

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

Measured memory_bytes: 640
A, B, C, X, Y = map(int, input().split())

ans = 0
if A + B <= C * 2:
    ans = A * X + B * Y
else:
    if X > Y:
        ans = C * Y * 2 + (X - Y) * min(A, C * 2)
    elif X == Y:
        ans = C * X * 2
    else:
        ans = C * X * 2 + (Y - X) * min(B, C * 2)
print(ans)


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

bool from1[200001],toN[200001];
int main(){
    int N,M;cin>>N>>M;
    for(int i=0,p,q;i<M;i++){
        cin>>p>>q;
        if(p==1)from1[q]=true;
        else if(q==N)toN[p]=true;
    }
    int flag=0;
    for(int i=1;i<=N;i++){
        if(from1[i] and toN[i]){
            flag++;
            break;
        }
    }
    if(flag)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 640
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w
d=[I]*h*w
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if d[t]==I:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)

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

#define int64 long long

int main()
{
	char ss[11], tt[12];
	scanf("%s", ss);
	scanf("%s", tt);
	for(int ii = 0;ii < 11;ii++)
	{
		if(ss[ii] == '\0')
		{
			if(tt[ii] == '\0')
			{
				puts("No");
				return 0;
			}
			else
			{
				puts("Yes");
				return 0;
			}
		}
		else if(ss[ii] != tt[ii])
		{
			puts("No");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1644
#include<cstdio>
#include<algorithm>
#include<numeric>

using namespace std;

typedef long long ll;

const int MOD = 1000000007;

int h, w, k;
ll dp[110][8];

bool check(int s){
	for(int i = 0; i < w - 1; i++) if(((s >> i) & 1) && ((s >> (i + 1)) & 1)) return 0;
	return 1;
}

int main(){
	scanf("%d %d %d", &h, &w, &k);
	dp[0][0] = 1;
	for(int i = 0; i < h; i++){
		for(int s = 0; s < 1 << (w - 1); s++) if(check(s)){
			for(int j = 0; j < w - 1; j++) if((s >> j) & 1){
				dp[i + 1][j] = dp[i + 1][j] - dp[i][j] + dp[i][j + 1];
				dp[i + 1][j + 1] = dp[i + 1][j + 1] + dp[i][j] - dp[i][j + 1];
			}
			for(int j = 0; j < w; j++) dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
		}
	}
	printf("%lld\n", dp[h][k - 1]);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>p(n);
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    auto it=max_element(p.begin(),p.end());
    int index=it-p.begin();
    int sum=0;
    for(int i=0;i<p.size();i++)
    {
        if(i==index){
            sum+=p[i]/2;
        }
        else
        sum+=p[i];
    }
    cout<<sum;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
    int main(){
    int A,B;
    cin >> A >> B;
    if(A+B>=A-B && A+B>=A*B){
        cout << A+B << endl;
    }else if(A*B>=A+B && A*B>=A-B){
        cout << A*B << endl;
    }else if(A-B>=A+B && A-B>=A*B){
        cout << A-B << endl;
    }
    }

Measured memory_bytes: 256
import java.util.*;

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

		while(true){
			int x = sc.nextInt();
			int h = sc.nextInt();
			if(x==0 && h==0)break;
			
			double a = Math.sqrt(((double)x/2)*((double)x/2) + h*h);
			double sum = x*x + x*a*2;
			System.out.println(sum);
		}
	}	
}

Measured memory_bytes: 17180
#include<bits/stdc++.h>
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
#define abs(x) (((x)<0)?(-1*(x)):(x))
#define signum(x) (((x) < 0) ? (-1) : (((x) == 0) ? 0 : 1))
#define TESTC lli TC; cin>>TC; while(TC--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int, int> pri;
typedef pair<long long int, long long int> prlli;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')'; return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l = v.size(); for(int i = 0;i < l-1; i++) out<<v[i]<<' '; if(l > 0) out<<v[l-1]; return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int sumd(int a) {
	int ans = 0;
	while(a) {
		ans += a%10;
		a /= 10;
	}

	return ans;
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    int mm = 63;

    for(int i = 1; i < n; ++i) {
	    int temp = sumd(i) + sumd(n - i);
	    if(temp < mm) mm = temp;
    }

    cout<<mm<<endl;


    return 0;
}


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


int main()
{
	string s;
	getline(cin, s);
	for (int i = 0; i < s.length(); i++){
		if ('a' <= s[i] && s[i] <= 'z'){
			s[i] = s[i] - ('a'- 'A');
		}
	}
	cout << s<<endl;
	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,x,y,ans=0,ans_=0;cin>>n;
  ll T[n][n];memset(T,-1,sizeof(T));
  rep(i,n) {
    cin>>a;
    rep(j,a) {
      cin>>x>>y;x--; T[i][x]=y;
    }
  }
  bool honest=true;
  rep(i,1<<n) {
    honest=true;
    ans_=0;
    rep(j,n) {
      if(i>>j&1) {
        rep(k,n) {
          if(k==j) continue;
          if(T[j][k]!=-1&&T[j][k]!=((i>>k&1))) {honest=false;break;}
          if(!honest) break;
        }
      }
    }
    if(honest) ans_=__builtin_popcount(i);
    ans=max(ans,ans_);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int D[110]; // ?????¢????¨???¶
int v, A[100][100], u, k, w;
queue<int> Q;

void bfs(int src) {

	Q.push(src);
	D[src] = 0;

	while (!Q.empty()) {
		int cur = Q.front();
		Q.pop();
		for (int i = 0; i < v; ++i) {
			if (A[cur][i] == 1 && D[i] == 0) {
				D[i] = D[cur] + 1;
				Q.push(i);
			}
		}
	}

	for (int l = 0; l < v; ++l) {
		if (D[l] == 0) { D[l] = -1; }
		if (l == 0) { D[l] = 0; }
		cout << l+1 << " " << D[l] << endl;
	}

}

int main(){
	cin >> v;
	// ???????????§??????v
	for (int i = 0; i < v; ++i) {

		cin >> u >> k;
		// ??????????????????u???k?????\?????????????????°??????

		for (int j = 0; j < k; ++j) {

			cin >> w;
			A[u - 1][w - 1] = 1;

			// ??£??\???????????§?¨??????????????????????????????????

		}
	}

	
	bfs(0);

}

Measured memory_bytes: 1240
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int a,b;
  cin>>a>>b;

  if(a<10 & b<10) cout<<a*b;
  else cout<<-1;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var a = lines[1].split(' ');
 var ans = new Array(n);
 for(i=1; i<=n; i++){
   ans[a[i-1]-1] = i;
   // console.log(index);
 }
 console.log(ans.join(' '));
});

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

int main(){
	int N,flag;
	flag=0;
	int ti,x,y;
	x=y=ti=0;	
	int dis=0;
	int tim=0;	
	cin >> N;
	for(int i=0; i<N;i++){
		int tmp_t,tmp_x,tmp_y;
		cin >>tmp_t>>tmp_x>>tmp_y;
		//int d=tmp_x+tmp_y;
		int t=tmp_t;
		tim = tmp_t-ti;
		dis = abs(x-tmp_x)+abs(y-tmp_y);
		if(dis<=tim &&(tim-dis)%2==0){
		}else{
			flag=1;
		}
		ti=tmp_t;
		x=tmp_x;
		y=tmp_y;
	}
	if(flag==0){
		cout <<"Yes"<<endl;
	}else{
		cout << "No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

const int MOD = 998244353;

void add(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}

void sub(int &a, int b) {
  if ((a -= b) < 0) a += MOD;
}

int mul(int a, int b) {
  return (int) ((a * 1LL * b) % MOD);
}

int mpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int minv(int x) {
  return mpow(x, MOD - 2);
}

const int MAXN = 310000;

int facs[MAXN];
int ifacs[MAXN];

void init_facs() {
  facs[0] = ifacs[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    facs[i] = mul(facs[i - 1], i);
    ifacs[i] = minv(facs[i]);
  }
}

int cnk(int n, int k) {
  return mul(facs[n], mul(ifacs[k], ifacs[n - k]));
}

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
#endif

  init_facs();

  ll n, a, b, k;
  while (scanf("%lld%lld%lld%lld", &n, &a, &b, &k) == 4) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (i * a <= k && (k - i * a) % b == 0) {
        ll cnta = i;
        ll cntb = (k - i * a) / b;
        if (cntb <= n) {
          add(ans, mul(cnk(n, cnta), cnk(n, cntb)));
        }
      }
    }
    printf("%d\n", ans);
  }




  return 0;
}


Measured memory_bytes: 2688
N, x = map(int, input().split())
aList = [int(x) for x in input().split()]


aList.sort()

total_child = 0
isEqual = False
for a in aList:
    if x == 0:
        isEqual = True
        break
    elif x < 0:
        break
    x -= a
    total_child += 1

    if x == 0:
        isEqual = True

if isEqual:
    print(total_child)
else:
    print(total_child - 1)


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (b % a == 0)
    cout << a + b << endl;
  else
    cout << b - a << endl;
  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,b,h,m = LI()
    ar = (h / 12 + m / 12 / 60) * math.pi * 2
    ay = a * math.cos(ar)
    ax = a * math.sin(ar)
    br = m / 60 * math.pi * 2
    by = b * math.cos(br)
    bx = b * math.sin(br)

    return pow(pow(ay-by, 2) + pow(ax-bx, 2), 0.5)

print(main())





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

using namespace std;

const int max_n = 300333, inf = 1000111222;
const int max_b = 9;
const int max_mask = (1 << max_b) + 5;

int n, q, a[max_n], b[max_n];
vector<pair<int, int>> all, all1, all2;
pair<int, int> sum[2][max_mask];
pair<int, int> buf[max_mask];

void get_all(const vector<pair<int, int>> &all, pair<int, int> sum[]) {
    for (int i = 0; i < all.size(); ++i) {
        for (int j = 0; j < (1 << i); ++j) {
            sum[(1 << i) + j] = sum[j];
            sum[(1 << i) + j].first += all[i].first;
            sum[(1 << i) + j].second += all[i].second;
        }
        merge(sum, sum + (1 << i), sum + (1 << i), sum + (1 << (i + 1)), buf);
        copy(buf, buf + (1 << (i + 1)), sum);
    }
}

const bool debug = 0;

mt19937 generator(1);

int rnd() {
    return generator() >> 1;
}

int rnd(int r) {
    return rnd() % r;
}

int rnd(int l, int r) {
    return l + rnd(r - l + 1);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    if (debug) {
        n = (1 << 18) - 1;
        for (int i = 1; i <= n; ++i) {
            a[i] = rnd(100000);
            b[i] = rnd(100000);
        }
        q = 100000;
    } else {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf("%d%d", &a[i], &b[i]);
        }
        scanf("%d", &q);
    }
    while (q--) {
        int v, mx;
        if (debug) {
            v = rnd(n / 2 + 2, n);
            mx = 100000;
        } else {
            scanf("%d%d", &v, &mx);
        }
        all.clear();
        all1.clear();
        all2.clear();
        while (v) {
            all.push_back({b[v], a[v]});
            v /= 2;
        }
        const int sz1 = min(9, (int) all.size() / 2);
        const int sz2 = all.size() - sz1;
        for (int i = 0; i < sz1; ++i) {
            all1.push_back(all[i]);
        }
        for (int i = sz1; i < all.size(); ++i) {
            all2.push_back(all[i]);
        }
        get_all(all1, sum[0]);
        get_all(all2, sum[1]);
        for (int i = 1; i < (1 << sz1); ++i) {
            sum[0][i].second = max(sum[0][i].second, sum[0][i - 1].second);
        }
        int ans = 0, pos = (1 << sz1) - 1;
        for (int i = 0; i < (1 << sz2) && sum[1][i].first <= mx; ++i) {
            while (sum[1][i].first + sum[0][pos].first > mx) {
                --pos;
            }
            ans = max(ans, sum[1][i].second + sum[0][pos].second);
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 5904
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
string S[200000];

vector<pair<int,int>> I; // 2, 5

ll cnt[100][100] ={};

signed main(){
    cin >> N;
    rep(i, N){
        cin >> S[i];
        int d = -1;
        rep(j, S[i].size()){
            if(S[i][j] == '.') d = j;
        }
        if(d != -1){
            while(S[i].back() == '0') S[i].pop_back();
            if(S[i].back() == '.') S[i].pop_back();
        }
        d = -1;
        rep(j, S[i].size()){
            if(S[i][j] == '.') d = j;
        }
        if(d == -1){
            ll a = stoi(S[i]);
            int t1 = 0;
            int t2 = 0;
            while(a%2 == 0){
                a /= 2;
                t1++;
            }
            while(a%5 == 0){
                a /= 5;
                t2++;
            }
            I.pb({ t1, t2 });
        }
        else{
            ll a = stoll(S[i].substr(0, d) + S[i].substr(d+1, S[i].size()-d-1));
            int t1 = -(int)S[i].size()+d+1;
            int t2 = -(int)S[i].size()+d+1;
            while(a%2 == 0){
                a /= 2;
                t1++;
            }
            while(a%5 == 0){
                a /= 5;
                t2++;
            }
            I.pb({ t1, t2 });
        }
    }

    rep(i, I.size()){
        cnt[50 + I[i].first][50 + I[i].second]++;
        //cout << I[i].first << " " << I[i].second << endl;
    }
    for(int i=98; i>=0; i--){
        for(int j=98; j>=0; j--){
            cnt[i][j] += cnt[i+1][j] + cnt[i][j+1] - cnt[i+1][j+1];
        }
    }

    ll ans = 0;
    rep(i, I.size()){
        if(I[i].first >= 0 && I[i].second >= 0) ans--;
        ans += cnt[-I[i].first+50][-I[i].second+50];
        //cout << cnt[-I[i].first+50][-I[i].second+50] << endl;
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 11500
S = input()
T = input()
ls = len(S)
lt = len(T)


m = 0
for i in range(ls-lt+1):
    tmp = S[i:i+lt]
    cnt = 0
    for idx,j in enumerate(tmp):
        if T[idx]==j:
            cnt+=1
    m = max(cnt,m)

print(lt-m)

Measured memory_bytes: 67572
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

vector<int> sieve(int n) {
  vector<int> p(n);p[2]=2;
  for(int i=3;i<n;i+=2)p[i]=i;
  for(int i=3;i*i<n;i+=2)if(p[i])for(int j=i*i;j<n;j+=i)p[j]=0;
  p.erase(remove(p.begin(), p.end(), 0), p.end());
  return p;
}

void Main() {
  vector<int> v=sieve(1000000);
  ll x;
  R x;
  pr(*lower_bound(all(v),x));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define maxn 20000020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
typedef long long ll;
typedef pair<int,int> pr;

const ll mod = 1e9 + 7;
ll fac[maxn],inv[maxn],ans;

int h,w,k;

inline ll power(ll x,ll y){
	ll res = 1;
	while ( y ){
		if ( y & 1 ) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
void init(){
	inv[0] = fac[0] = 1;
	rep(i,1,20000000) fac[i] = fac[i - 1] * i % mod;
	inv[20000000] = power(fac[20000000],mod - 2);
	repd(i,20000000-1,1) inv[i] = inv[i + 1] * (i + 1) % mod;
}
inline ll C(int n,int m){
	return fac[n] * inv[m] % mod * inv[n - m] % mod;	
}

int main(){
	init();
	scanf("%d %d %d",&h,&w,&k);
	int n = h + w;
	ll f = (C(k,2) * power(C(n,2),mod - 2) + C(k,3) * power(C(n,3) * 3 % mod,mod - 2) % mod * (n - 2)) % mod;
	ll g= (k * power(n,mod - 2) + C(k,2) * power(C(n,2) * 2 % mod,mod - 2) % mod * (n - 1)) % mod;
	ans = fac[n] * inv[n - k] % mod * (f * h % mod * w % mod + g * (h + w) % mod + k) % mod;
	cout<<ans<<endl;	
}


Measured memory_bytes: 312704
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


llint X;


signed main(){
	cin >> X;

	cout << (llint)ceil((-1+sqrt(1+8*X))/2.0) << endl;

	return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	int ans=0;
	for(int i=1;i<s.size();++i){
		string s2=s.substr(i);
		vector<bool>a(26,false),b(26,false);
		for(int j=0;j<i;++j){
			a.at(s.at(j)-'a')=true;
		}
		for(int j=0;j<s2.size();++j){
			b.at(s2.at(j)-'a')=true;
		}
		int tmp=0;
		for(int j=0;j<26;++j){
			if(a.at(j)&&b.at(j))++tmp;
		}
		ans=max(ans,tmp);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n, k;
    cin >> n >> k;
    k--;
    string s;
    cin >> s;
    rep(i,n){
        if(i == k){
            char a = tolower(s[i]);
            cout << a;
        }else{
            cout << s[i];
        }
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3500
#include<iostream>
#include <vector>
#include <queue>
using namespace std;
long long T[10][10]={0};
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    int a,b;
    a=i;
    while(a>=10)a/=10;
    b=i%10;
    T[a][b]++;
  }
  long long ans=0;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      ans+=T[i][j]*T[j][i];
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);
const long MOD =1000000007;

long n;
long ans = 1;
long a[1005];

int main(){
    scanf("%ld", &n);
    for(long i = 0; i <= n; i++){
        a[i] = i;
    }
    for(long div = 2; div <= n; div++){
        long cnt = 0;
        for(long i = 1; i <= n; i++){
            while(a[i] % div == 0){
                cnt++;
                a[i] /= div;
            }
        }
        ans *= (cnt + 1);
        ans %= MOD;
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int a, b, c, n, k, h, w;
  cin >> a >> b;
  if(a >= 13){
    cout << b << endl;
  }
  else if(a <= 5){
    cout << 0 << endl;
  }
  else cout << b/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200001);

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  mint res = 0;

  for (int i = 0; i < n; i++) {
    res -= comb(n - i - 1, k - 1) * a[i];
    res += comb(i, k - 1) * a[i];
  }
  cout << res.x << endl;
  return 0;
} 

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


#define ll unsigned long long
#define ALL(x) x.begin(),x.end()

#define FASTIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int MOD = 1e9+7;
const int maxn = static_cast<int>(1e5+3);


ll power(ll x, ll int y){
    int res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x + MOD)%MOD;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%MOD; // Change x to x^2
    }
    return res;
}
int arr[maxn];

int main(){

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

    ll ans = 1;
    for(int i = (n%2==0 ? 1 : 0);i < n;i += 2){

        if((i != 0 && arr[i] != 2) || (i == 0 && arr[0] != 1)){
            ans = 0;
            break;
        }
        ans = (ans*arr[i])%MOD;
    }
    cout << ans;
}


Measured memory_bytes: 640
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    #
    s0 = input().strip()
    q = int(input().strip())

    #
    stc1 = []
    stc2 = []
    flag = 0

    # def f(flag1, flag2, val):
    #     if flag1 ^ flag2:
    #         stc1 += val
    #     else:
    #         stc2 += val

    #
    for i in range(q):
        t, *fc = map(lambda x: int(x) if x.isdecimal() else x, input().strip().split())
        # eprint('t,fc ', end=':\n')
        # eprint(t, fc, "\n")

        if t == 2:    # 文字列付加
            # f(fc[0], flag, fc[1])
            if (fc[0]-1)^flag==1:  # fc[0]は前方/後方， flagは非反転/反転，をそれぞれ表す
                stc2.append(fc[1])
            else:
                stc1.append(fc[1])
        else:       # 反転命令
            flag = flag ^ 1

    #
    if flag == 0:
        ans ="".join(stc1[::-1] + list(s0) + stc2)
    else:
        ans ="".join( stc2[::-1] + list(s0)[::-1] + stc1)
    print(ans)
    # eprint(ans[::-1])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 104024
N, M = map(int, input().split())
liners = {}

for i in range(M):
    a, b = map(int, input().split())
    liners.setdefault(a, [])
    liners[a].append(b)

ans = "IMPOSSIBLE"

for i in liners[1]:
    if i in liners and N in liners[i]:
        ans = "POSSIBLE"
        break

print(ans)


Measured memory_bytes: 31704
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
typedef long long ll;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }

    vector<ll> michi;

    ll v = 0;
    ll cnt = 0;
    michi.push_back(0);
    set<ll> st;
    st.insert(0);
    ll keykey;
    while(true) {
        cnt++;
        if(st.find(a[v]) != st.end()) {
            keykey = a[v];
            break;
        }
        michi.push_back(a[v]);
        st.insert(a[v]);
        v = a[v];
    }
    // cout << "hello" << endl;

    // reverse(michi.begin(), michi.end());

    ll i = 0;
    while(true) {
        if(keykey == michi[i]) {
            break;
        }
        i++;
    }
    // cout << "world" << endl;

    // reverse(michi.begin(), michi.end());

    ll ans = -1;
    if(k < i) {
        ans = michi[k];
    } else {
        k -= i;
        k %= cnt - i;
        ans = michi[i + k];
    }
    ans ++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15572
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <queue>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl

int W, H;

void bfs(int y, int x, const vector<vector<int>> &table, vector<vector<int>> &flag)
{
    using P = pair<int, int>;
    queue<P> que;
    que.push(P(y, x));
    flag[y][x] = 0;
    while(que.size())
    {
        P p = que.front(); que.pop();
        for(int i = 0; i < 8; i++)
        {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(ny < 0 or nx < 0 or ny >= H or nx >= W) continue;
            if(table[ny][nx] == 0 or not flag[ny][nx]) continue;
            flag[ny][nx] = 0;
            que.push(P(ny, nx));
        }
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> W >> H, W or H)
    {
        vector<vector<int>> table(H, vector<int>(W));
        for(int i = 0; i < H; i++)
        {
            for(int j = 0; j < W; j++) cin >> table[i][j];
        }
        vector<vector<int>> flag = table;
        int ans = 0;
        for(int i = 0; i < H; i++)
        {
            for(int j = 0; j < W; j++)
            {
                if(not flag[i][j]) continue;
                ans++;
                bfs(i, j, table, flag);
            }
        }
        cout << ans << endl;
    }
    return 0;
}




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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    void solve(){
        int a,b,c;
        cin>>a>>b>>c;
        int d=b/a;
        cout<<min(d,c);
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3624
#include<stdio.h>

int main(){
	
    int a,b,c,count=0;
    scanf("%d %d %d",&a,&b,&c);
    
    for(int i=a ; i<=b ; i++){
        if(c%i==0){
            count++;
        }
    }
    printf("%d\n",count);
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 1992
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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 ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  ll a,b;
  rep(i,n){
    ll l,r;
    cin >> l >> r;
    if(i == 0){
      a=l;
      b=r;
    }
    else{
      ll m = max((a+l-1)/l,(b+r-1)/r);
      a = l*m;
      b = r*m;
    }
  }
  cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void vecscl(double c, const double v0[2], double v1[2])
{
    v1[0] = v0[0] * c;
    v1[1] = v0[1] * c;
}

void vecadd(const double v0[2], const double v1[2], double v2[2])
{
    v2[0] = v0[0] + v1[0];
    v2[1] = v0[1] + v1[1];
}

void vecsub(const double v0[2], const double v1[2], double v2[2])
{
    v2[0] = v0[0] - v1[0];
    v2[1] = v0[1] - v1[1];
}

double vecprd(const double v0[2], const double v1[2])
{
    return v0[0] * v1[1] - v0[1] * v1[0];
}

double vecsum(const double v0[2], const double v1[2])
{
    return v0[0] * v1[0] + v0[1] * v1[1];
}

double veclen(const double v[2])
{
    return sqrt(v[0] * v[0] + v[1] * v[1]);
}

bool vecnrm(double eps, const double v0[2], double v1[2])
{
    double len = veclen(v0);
    if (len < eps) {
        return false;
    }
    vecscl(1 / len, v0, v1);
    return true;
}

const double eps = 1e-12;

void solve()
{
    int Q;
    scanf("%d", &Q);
    int t;
    for (t = 0; t < Q; t++) {
        int x[4], y[4];
        int k;
        for (k = 0; k < 4; k++) {
            scanf("%d%d", &x[k], &y[k]);
        }
        double v0[2] = { x[1] - x[0], y[1] - y[0] };
        double v1[2] = { x[3] - x[2], y[3] - y[2] };
        double tmp = vecsum(v0, v1);
        if (fabs(tmp) < eps) {
            printf("1\n"); continue;
        }
        tmp = vecprd(v0, v1);
        if (fabs(tmp) < eps) {
            printf("2\n"); continue;
        }
        printf("0\n");
    }

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 2696
import java.util.Scanner;

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

		while (true) {
			int sum = 0;

			char[] num = sc.next().toCharArray();

			if (num[0] == '0') {
				break;
			}

			for (int i = 0; i < num.length; i++) {
				int n = Character.getNumericValue(num[i]);
				sum += n;
			}
			System.out.println(sum);
		}

	}
}


Measured memory_bytes: 26248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 29;
 
int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int moveX = x2 - x1, moveY = y2 - y1;
	int x3 = x2 - moveY, y3 = y2 + moveX;
	cout << x3 << " ";
	cout << y3 << " ";
	int x4 = x3 - moveX, y4 = y3 - moveY;
	cout << x4 << " " << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <functional>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
        string s;cin>>s;
	int n=s.length();
	int m=n/2;
	int ans=0;
	for(int i=0;i<m;i++)
	{
		if(s[i]!=s[n-1-i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
while true
  w, h = gets.split.map(&:to_i)
  break if w == 0
  xh = {}; yh = {}
  xa = []; ya = []
  xa << 0; xa << w
  ya << 0; ya << h
  points = []
  gets.to_i.times do
    point = gets.split.map(&:to_i)
    points << point
    xa << point[0]; xa << point[2]
    ya << point[1]; ya << point[3]
  end
  xa = xa.uniq; xa = xa.sort; ya = ya.uniq; ya = ya.sort
  xs = xa.size; ys = ya.size
  xa.each_with_index{ |a, i| xh[a] = i+1 }
  ya.each_with_index{ |b, i| yh[b] = i+1 }
  fld = Array.new(ys+1){ Array.new(xs+1, true) }
  fld[0].fill(false); fld[ys].fill(false)
  fld.map{ |arr| arr[0] = arr[xs] = false }

  for point in points
    x1, y1, x2, y2 = point
    for a in (yh[y1]...yh[y2])
      for b in (xh[x1]...xh[x2])
        fld[a][b] = false
      end
    end
  end
  ret = 0
  for y in (1...ys)
    for x in (1...xs)
      next unless fld[y][x]
      arr = []
      arr << [y, x]
      until arr.empty?
        ny, nx = arr.shift
        [[-1,0],[0,-1],[1,0],[0,1]].each do |dy, dx|
          px = nx+dx; py = ny+dy
          if fld[py][px]
            arr << [py, px] 
            fld[py][px] = false
          end
        end
      end
      ret += 1
    end
  end
  p ret
end

Measured memory_bytes: 14204
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD9, b / 2) % MOD9;
//     else return a * POW(a * a % MOD9, b / 2) % MOD9;
//   }
// }

int main(){
  int K;
  string S;
  cin >> K >> S;
  if(S.length()<=K){
    cout << S << endl;
    return 0;
  }else{
    for(int i=0; i<K; ++i){
      cout << S[i];
    }
    cout << "..." << endl;
    return 0;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#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())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

using Gragh = vector<vector<int>>;

int main() {
    int n, m;
    cin >> n >> m;
    Gragh to(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> order(n);
    rep(i, n) order[i] = i;

    int ans = 0;
    do {
        if(order[0] != 0) continue;
        bool check;
        int cnt = 0;
        rep(i, n - 1) {
            check = true;
            for(auto x : to[order[i]]) {
                if(x == order[i + 1]) check = false;
            }
            if(check) break;
            cnt++;
        }
        if(cnt == n - 1) ans++;
    } while(next_permutation(ALL(order)));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int,input().split())
a = list(map(int,input().split()))

zerofrag = 0
zerobig = []
zerosmall = []

for i in a:
    if i == 0:
        zerofrag =1
    elif i > 0:
        zerobig.append(i)
    else:
        zerosmall.append(abs(i))

if k == 1 and zerofrag == 1:
    print(0)
else:
    if zerofrag == 1:
        k = k -1

    zerobig.sort()
    zerosmall.sort()
    #print(zerobig,zerosmall)
    kouho = []
    if len(zerobig) >=k:
        kouho.append(zerobig[k-1])
    if len(zerosmall) >=k:
        kouho.append(zerosmall[k-1])
        
    for ii in range(len(zerosmall)):
        if k - (ii) > len(zerobig):
            continue
        else:
            try:
                kouho.append(zerosmall[ii] * 2 + zerobig[k - ii - 2])
            except:
                continue
    for jj in range(len(zerobig)):
        if k - (jj ) > len(zerosmall):
            continue
        else:
            try:
                kouho.append(zerobig[jj] * 2 + zerosmall[k - jj - 2])
            except:
                continue
    #print(kouho)
    if zerofrag == 1:
        k = k + 1
    if kouho == [] :
        print(min( (max(zerosmall)*2 + max(zerobig)) ,  max(zerobig) * 2 + max(zerosmall)) )
    else:
        print(min(kouho))

Measured memory_bytes: 14224
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;
typedef long long ll;

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

template <typename T> void read(T &x) {
  x = 0;
  char c = getchar();
  T sig = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      sig = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  x *= sig;
}

class Solution {
public:
  void solve() {
    int n, k;
    read(n), read(k);
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
      read(a[i]);
    ll l = 1, r = *max_element(a.begin(), a.end());
    while (l <= r) {
      ll mid = l + (r - l) / 2;
      ll req = 0;
      for (int i : a)
        req += (i - 1) / mid;
      if (req > k)
        l = mid + 1;
      else
        r = mid - 1;
    }
    printf("%lld", l);
  }
};

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

Measured memory_bytes: 3980