akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    string inp[h];
    int ans = 0;
    rep(i, h){
    	cin >> inp[i];
    }
    for (int i = 0; i < (1<<(h+w)); i++){
        string tmp[h];
        rep(t, h){
        	tmp[t] = inp[t];
        }
        for (int d = 0; d < h; d++){
            if (i&(1<<d)){
                for (int j = 0; j < w; j++) tmp[d][j] = 'R';
            }
        }

        for (int d = 0; d < w; d++){
            if (i&(1<<(d+h))){
                for (int j = 0; j < h; j++) tmp[j][d] = 'R';
            }
        }

        ll cnt = 0;
        rep(rows, h) rep(cols, w) if (tmp[rows][cols] == '#') cnt++;
        if (cnt == k) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
map<ll,ll> hr,hg,hb;
vector<ll> r,g,b;
int main(){
   string s;
   ll n;
   cin>>n;
   cin>>s;
   ll ans=0;
   
   
   for(ll i=0;i<n;i++){
   	   if(s[i]=='R')hr[i]=1,r.pb(i);
   	   if(s[i]=='G')hg[i]=1,g.pb(i);
   	   if(s[i]=='B')hb[i]=1,b.pb(i);
   }
   ans=0;
   for(ll i=0;i<n;i++){
   	  for(ll j=i+1;j<n;j++){
   	  	    if(s[i]!=s[j]){
   	  	    	ll fr=0;
   	  	    	ll fg=0;
   	  	    	ll fb=0;
   	  	    	if(s[i]=='R' || s[j]=='R') fr=1;
   	  	    	if(s[i]=='G' || s[j]=='G') fg=1;
   	  	    	if(s[i]=='B' || s[j]=='B') fb=1;
                ll k=2*j-i;
				if(fg==0){
					ll ind=g.end()-upper_bound(all(g),j);
					ind-=hg[k];
					ans+=ind;
				} 	
				if(fb==0){
					ll ind=b.end()-upper_bound(all(b),j);
					ind-=hb[k];
					ans+=ind;
				}  	
				if(fr==0){
					ll ind=r.end()-upper_bound(all(r),j);
					ind-=hr[k];
					ans+=ind;
				}    	
   	  	    	
			}
		
		}
   }
   cout<<ans;
   
   
}

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

using namespace std;
typedef long long ll ;
const int N =  1e5 ;
int main()
{
    vector<int>primes;
    int vis[100001];
    memset(vis , 0 , sizeof vis);
    for(int i =2 ; i <= N ; i++)
    {
        if(!vis[i])
        {
            primes.push_back(i);
            for(int j = i+i ; j <= N ;j+=i)
            {
                vis[j]=1;
            }
        }
    }
    primes.push_back(100003);
    ll n;
    cin >> n;
    cout << *lower_bound(primes.begin(),primes.end(),n) ;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> d(N);
    REP(i,N) cin >> d[i];
    ll ans = 0;
    REP(i,N){
        for(int j=i+1;j<N;j++) ans += d[i] * d[j];
    }
    cout << ans << endl;
}


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

using namespace std;

int gcd(int a,int b)
{
    if(!b) return a;
    else return gcd(b,a%b);
}

int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int left[n],right[n];
    left[0]=a[0];
    for(int i=1;i<n;i++) left[i]=gcd(left[i-1],a[i]);
    right[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--) right[i]=gcd(right[i+1],a[i]);
    int res=max(left[n-2],right[1]);
    for(int i=1;i<n-1;i++) res=max(res,gcd(left[i-1],right[i+1]));
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>

long fib(int n){
	if(n < 0)return 0;
	long a = 1, b = 1;
	long tmp;
	while(n){
		tmp = a;
		a += b;
		b = tmp;
		if(b > 1000000007)b -= 1000000007;
		if(a > 1000000007)a -= 1000000007;
		n--;
	}
	return b;
}

int main(void){
	//memo[0] = 1;
	int n, m;
	long ans = 1;
	int last = 0;
	int in;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; i++){
		scanf("%d", &in);
		ans *= fib(in - last - 1);
		if(ans > 1000000007)ans %= 1000000007;
		last = in + 1;
	}
	ans *= fib(n - last);
	printf("%ld\n", ans % 1000000007);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}



ll  d, n, r, l, k, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k >> s;
	ll x = 0, y = 0;
	rep(i, n) {
		if (s[i] == '0') {
			if (i == 0 || s[i - 1] == '1') x++;
		}
		if (x > k) {
			while (s[y] == '1') y++;
			while (s[y] == '0')y++;
			x--;
		}
		ans = max(ans, i - y + 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n,m;
	cin>>n;
	map<string,int>tmp;
	vi ne(n);
	rep(i,n){
		string s;
		cin>>s>>ne[i];
		tmp[s]=i;
	}
	cin>>m;
	vi in1,in2;
	rep(i,m){
		string a,b;
		cin>>a>>b;
		in1.pb(tmp[a]);
		in2.pb(tmp[b]);
	}
	rep(i,m){
		rep(j,m){
			if(ne[in1[j]]>ne[in2[j]])ne[in1[j]]=ne[in2[j]];
			else ne[in2[j]]=ne[in1[j]];
		}
	}
	int sum=0;
	rep(i,n)sum+=ne[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1840
#include<bits/stdc++.h>
using namespace std;
int n,num[112];
int ans=INT_MAX,totalsum;

int main()
{
	int i,j,a;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}
	for(i=-100;i<=100;i++)
	{
		totalsum = 0;
		for(j=0;j<n;j++)
		{
			totalsum += (num[j]-i)*(num[j]-i);
		}
		ans = min(ans,totalsum);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


/*
Euclidean Algorithm
 */
ll euclid(ll a, ll b){
  while (b>0){
    a = a % b;
    swap(a, b);
  }
  return a;
}


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

  ll A, B;
  cin >> A >> B;

  ll ans = A * B / euclid(A,B);
  cout << ans << "\n";
  return 0;
}


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

/*
ll mod = 1e9+7;
#define NMAX 1000010
ll *fac;

void mae_nck(){
    fac[1] = 1;
    for(ll i = 2; i < NMAX; i++){
        fac[i] = (fac[i-1] * i);
    }
}

ll nck(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(k == 0 || k == n) return 1;
    ll ret = fac[n]/(fac[k]*fac[n-k]);
    return ret;
}
*/
ll nck(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  if(k == 0 || k == n) return 1;
  ll nume = 1, deno = 1;
  for(int i=0; i<k; i++){
    nume *= (n-i);
    deno *= (i+1);
  }
  return (ll)(nume/deno);
}

int main(){
    //fac = (ll *)malloc(NMAX*sizeof(ll));
    ll n;
    cin >> n;
    vector<ll> c(n+1,0), a(n), s(n+1,0);
    rep(i, 0, n){
        cin >> a[i];
        c[a[i]]++;
    }
    //mae_nck();
    ll sum = 0;
    rep(i, 1, n+1){
        s[i] = nck(c[i], 2);
        sum += s[i];
    }

    rep(i, 0, n){
        ll ans = sum - s[a[i]];
        ans += nck(c[a[i]]-1, 2);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8960
package main

import "fmt"

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func main() {
	var n, m int
	var s, t string
	fmt.Scan(&n, &m, &s, &t)
	g := gcd(n, m)
	x, y := n/g, m/g
	ok := true
	for i, j := 0, 0; i < n && j < m; i, j = i+x, j+y {
		if s[i] != t[j] {
			ok = false
			break
		}
	}
	var ans int
	if ok {
		ans = n / g * m
	} else {
		ans = -1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1152
#include<stdio.h>

void swap(int *p,int *q){
  int x;
  x = *p;
  *p = *q;
  *q = x;
}

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  while((a<=b && b<=c)==0){
    if(a>b) swap(&a,&b);
    if(b>c) swap(&b,&c);
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <cstdio>
using namespace std;

typedef long long LL;
const int N = 55;
int n; LL K, a[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + (LL)ch-'0', ch = getchar();
	x *= f;
}

inline void work() {
	in(K), n = 50; LL tmp = K / n;
	for (int i = 1; i <= n; ++i) a[i] = n - 1;
	for (int i = 1; i <= n; ++i) a[i] += tmp;
	for (int i = 1; i <= K % n; ++i) {
		a[i] += n;
		for (int j = 1; j <= n; ++j) if (i != j) --a[j];
	}
	int lim = K % n;
	printf("%d\n", n);
	for (int i = 1; i < n; ++i) printf("%lld ", a[i]);
	printf("%lld\n", a[n]);
}

int main() {work(); return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int tmp,ans;
  rep(i,5){
    cin >> tmp;
    if(tmp == 0){
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main() {
    int a,b,c;

    cin>>a>>b>>c;

    int temp;
    temp = a;
    a = b;
    b = temp;

    temp = a;
    a = c;
    c = temp;

    cout<<a<<" "<<b<<" "<<c;

}

Measured memory_bytes: 3592
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn dfs(i: usize, G: &Vec<Vec<usize>>, visited: &mut Vec<bool>)-> bool {
    if visited[i] || G[i].len() > 2 {
        return false;
    }

    visited[i] = true;
    for j in 0..G[i].len() {
        let p = G[i][j];
        if p != i && dfs(p, G, visited) {
            return true;
        }
    }
    if G[i].len() == 1 {
        for j in 0..4 {
            if !visited[j] {
                visited[i] = false;
                return false;
            }
        }
    }

    return true;
}


fn main() {
    let mut G: Vec<Vec<usize>> = vec![Vec::new(); 4];
    for i in 0..3 {
        let nk: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = nk[0]-1;
        let b = nk[1]-1;
        G[a].push(b);
        G[b].push(a);
    }

    let mut ans = false;
    for i in 0..4 {
        if G[i].len() == 1 {
            let mut visited = vec![false; 4];
            if dfs(i, &G, &mut visited) {
                ans = true;
                break;
            }
        }
    }


    if ans {
        println!("YES");
    } else {

        println!("NO");
    }
}


Measured memory_bytes: 4352
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define mo 1000000007
using namespace std;
long long m,d,i,j,ans;
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
int main(){
	m=read();d=read();
	for(i=2;i*10<=d;i++)
		for(j=2;i*10+j<=d&&j<=9;j++)
			if(i*j<=m)
				ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int i;
	std::string s;
	std::cin >> s;
	for(i=0; i<3; ++i){
		if(s[i]=='7'){
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}
	std::cout << "No" << std::endl;
	return 0;
}


Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var h [3][3]int
	for i := 0; i < 3; i++ {
		fmt.Scan(&h[i][0], &h[i][1], &h[i][2])
	}

	//a1
	for i := 0; i <= 100; i++ {
		b1 := h[0][0] - i
		b2 := h[0][1] - i
		b3 := h[0][2] - i

		//a2
		for j := 0; j <= 100; j++ {
			if h[1][0]-j == b1 &&
				h[1][1]-j == b2 &&
				h[1][2]-j == b3 {

				//a3
				for k := 0; k <= 100; k++ {
					if h[2][0]-k == b1 &&
						h[2][1]-k == b2 &&
						h[2][2]-k == b3 {
						fmt.Println("Yes")
						return
					}
				}
			}
		}

	}
	fmt.Println("No")

}

Measured memory_bytes: 512
from collections import deque

N,Q = map(int, input().split())
g = [[] for i in range(N)]
q,s,c = [0]*N,[False]*N,[0]*N
d = deque()

for _ in range(N-1):
	a,b = map(int, input().split())
	a,b = a-1,b-1
	g[a].append(b)
	g[b].append(a)

for _ in range(Q):
	p,x = map(int, input().split())
	q[p-1] += x

d.append(0)
while d:
	v = d.popleft()
	s[v] = True
	for x in g[v]:
		if not s[x]:
			d.append(x)
			q[x] += q[v]

print(' '.join(map(str,q)))

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

using namespace std;

typedef complex<double> P;

double const EPS = 1e-10;

double cross(P const& a, P const& b) {
  return imag(conj(a)*b);
}

bool is_parallel(P const& a1, P const& a2, P const& b1, P const& b2)
{ return abs(cross(a2-a1, b2-b1)) <= EPS; }

int main() {
  
  int N; cin >> N;
  for(int i=0; i<N; i++) {
    P ps[4];
    for(int i=0; i<4; i++)
      cin >> ps[i].real() >> ps[i].imag();
    printf("%s\n", (is_parallel(ps[0], ps[1], ps[2], ps[3]) ? "YES" : "NO" ));
  }
  
  return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

    int n;cin >> n;
    map<int,int> mp;
    rep(i,n){
        int a;cin >> a;
        if(mp[a] == 0)mp[a] = 1;
        else mp[a]++;
    }
    ll ans = 0;
    for(auto i : mp){
        if(i.first - i.second > 0)ans += i.second;
        else if(i.first - i.second < 0)ans += i.second - i.first;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;
typedef complex<ld>     cld;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define kill(x)         return cout << x << endl, 0;
#define Mp              make_pair
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

const ll MAXN = 3e3 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7,
         LOG  = 32;
//const ld PI   = M_PI;

ll n;
ld p[MAXN], dp[MAXN][MAXN], ans;

int main()
{
    fastio;
    ld_io;

    cin >> n;
    for (ll i = 1; i <= n; i++)
        cin >> p[i];

    dp[0][0] = 1;
    for (ll i = 1; i <= n; i++) {
        for (ll j = 0; j <= n; j++) {
            if (j != 0)
                dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]);
            else
                dp[i][j] = dp[i-1][j] * (1 - p[i]);
        }
    }

    for (ll i = (n+1)/2; i <= n; i++) {
        ans += dp[n][i];
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 141568
import sys
mod=998244353
MAX=3*10**5+100
g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

N,A,B,K=map(int,input().split())
data=[]
for x in range(N+1):
    if (K-A*x)%B!=0:
        continue
    y=(K-A*x)//B
    if 0<=x<=N and 0<=y<=N:
        data.append([x,y])
ans=0
for x,y in data:
    ans=(ans+cmb(N,x)*cmb(N,y)%mod)%mod
print(ans)

Measured memory_bytes: 79984
let (p1, p2, p3) = (257, 251, 1000000007)

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let pow x n =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x mod p3) (n / 2) acc
    else doit (x * x mod p3) (n / 2) (acc * x mod p3) in
  doit x n 1

let hash x c = (x + c) mod p3

let make_hash v (x, y) (r, c) =
  let h1 = Array.make_matrix x y 0 in
  let c1 = pow p1 c in
  for i = 0 to x - 1 do
    let rec aux j acc =
      if j = c then acc
      else hash (acc*p1) (Char.code v.(i).(j)) |> aux (j + 1)  in
    let rec doit j z =
      if j = y - c then h1.(i).(j) <- z
      else begin
        h1.(i).(j) <- z;
        let z = hash (z*p1) (Char.code v.(i).(j+c) - Char.code v.(i).(j) * c1) in
        doit (j + 1) (if z < 0 then z + p3 else z)
      end in
    aux 0 0 |> doit 0;
  done;
  let h2 = Array.make_matrix x y 0 in
  let c2 = pow p2 r in
  for j = 0 to y - 1 do
    let rec aux i acc =
      if i = r then acc
      else hash (acc*p2) h1.(i).(j) |> aux (i + 1) in
    let rec doit i z =
      if i = x - r then h2.(i).(j) <- z
      else begin
        h2.(i).(j) <- z;
        let z = hash (z*p2) (h1.(i+r).(j) - h1.(i).(j) * c2) in
        doit (i + 1) (if z < 0 then z + p3 else z)
      end in
    aux 0 0 |> doit 0;
  done;
  h2

let solve (h, w) (r, c) a b =
  let s = make_hash a (h, w) (r, c) in
  let t = make_hash b (r, c) (r, c) in
  for i = 0 to h - r do
    for j = 0 to w -c do
      if s.(i).(j) = t.(0).(0) then Printf.printf "%d %d\n" i j;
    done
  done

let read_array x y =
  let a = Array.make_matrix x y '\000' in
  for i = 0 to x - 1 do
    let l = read_line () in
    for j = 0 to y - 1 do
      a.(i).(j) <- l.[j];
    done
  done;
  a

let () =
  match read_line () |> split_on_char ' ' |> List.map int_of_string with
  | [h; w] ->
    begin
      let a = read_array h w in
      match read_line () |> split_on_char ' ' |> List.map int_of_string with
      | [r; c] ->
        if h < r || w < c then ()
        else read_array r c |> solve (h, w) (r, c) a
      | _ -> assert false
    end
  | _ -> assert false

Measured memory_bytes: 42968
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n, m, x;
	cin >> n >> m >> x;

	vector<ll> a(n);
	vector<vector<ll>> b(n, vector<ll>(m));

	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
		for (ll j = 0; j < m; j++)
		{
			cin >> b[i][j];
		}
	}

	ll res = inf;
	bool f = false;
	for (ll bit = 0; bit < (1 << n); bit++)
	{
		ll sum = 0;
		vector<ll> c(m, 0);
		for (int i = 0; i < n; i++)
		{
			if (bit & 1 << i)
			{
				sum += a[i];

				for (ll j = 0; j < m; j++)
				{
					c[j] += b[i][j];
				}
			}
		}

		bool flg = true;
		for (ll j = 0; j < m; j++)
		{
			if (c[j] < x)
			{
				flg = false;
			}
		}

		if (flg)
		{
			f = true;
			res = min(res, sum);
		}
	}

	if (f)
	{
		println(res);
	}
	else
	{
		println(-1);
	}
}


Measured memory_bytes: 3584
#include <stdio.h>
int main(void){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if ( a <= b && b <= c )
    printf("%d %d %d\n", a, b, c);
    else if ( a <= c && c <= b )
    printf("%d %d %d\n", a, c, b);
    else if ( b <= a && a <= c )
    printf("%d %d %d\n", b, a, c);
    else if ( b <= c && c <= a )
    printf("%d %d %d\n", b, c, a);
    else if ( c <= a && a <= b )
    printf("%d %d %d\n", c, a, b);
    else 
    printf("%d %d %d\n", c, b, a);

    return 0;
}



Measured memory_bytes: 2104
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, y) = readLine.split(" ").map(_.toInt)

  for (a <- 0 to n; b <- 0 to n - a) {
    val c = n - a - b

    val t = 1000 * a
    val f = 5000 * b
    val m = 10000 * c
    if (t + f + m == y && a + b + c == n) {
      println(s"$c $b $a");
      sys.exit()
    }
  }
  println("-1 -1 -1")

}


Measured memory_bytes: 27332
using System;

namespace apc001_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(0);
            Console.Clear();
            string lowgender = Console.ReadLine();
            if (lowgender != "Vacant")
            {
                Console.WriteLine(n - 1);
                Console.Clear();
                string highgender = Console.ReadLine();
                if (highgender != "Vacant")
                {
                    int low = 0; int high = n - 1;
                    while (true)
                    {
                        int mid = (low + high) / 2;
                        Console.WriteLine(mid);
                        Console.Clear();
                        string s = Console.ReadLine();
                        if (s == "Vacant") break;
                        if (((mid - 1 - low) % 2 == 1) == (lowgender != s))
                        {
                            high = mid;
                            highgender = s == "Male" ? "Male" : "Female";
                        }
                        else
                        {
                            low = mid;
                            lowgender = s == "Male" ? "Male" : "Female";
                        }
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 13508
# Q_D
n, m = list(map(int, input().split()))
x = [[0]*3] * n
for i in range(n):
    x[i] = list(map(int, input().split()))

r = [0] * n
result = 0

for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            r = [0] * n
            for l in range(n):
                r[l] = x[l][0] * i + x[l][1] * j + x[l][2] * k
            r.sort(reverse=True)
            tmp = sum(r[0:m])
            if tmp > result:
                result = tmp
                
print(result)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    ll n,q;
    cin >> n >> q;
    ll x = 0;
    for(int i=0;i<q;i++){
        ll a,b;
        cin >> a >> b;
        if(a==1){
            x += b;
            x %= n; 
        }else{
            cout << (x+b-1)%n+1 << endl;
        }
        //cout << x << endl;
    }


    return 0;
}


Measured memory_bytes: 3092
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
count = 0
for i in range(n):
  count += min(la[i],lb[i])
  if la[i]<lb[i]:
    if la[i+1] >= lb[i]-la[i]:
      count+=(lb[i]-la[i])
      la[i+1]-=(lb[i]-la[i])
    else:
      count+=la[i+1]
      la[i+1]=0
print(count)

Measured memory_bytes: 24224
# 隣り合う和がL未満ならそもそもimpossible
# ならば隣り合う和がL以上ならば？ -> そこから連続して隣り合うやつをどうやって足しても常にL以上

n, l = map(int, input().split())
a = list(map(int, input().split()))
idx = 0
for i in range(1, n):
    if a[i - 1] + a[i] >= l:
        idx = i
        break
if idx == 0:
    print("Impossible")
    exit()

print("Possible")

ans = [idx]
for i in range(idx - 1, 0, -1):
    ans.append(i)
for i in range(idx + 1, n):
    ans.append(i)
for a in ans[::-1]:
    print(a)

Measured memory_bytes: 19996
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

S = [0]

for i, a in enumerate(A):
    S.append(S[i] + a)

S = sorted(S)
a = Counter(S).most_common()
cnt = 0

for i in range(len(a)):
    cnt += ((a[i][1]-1)*a[i][1])//2

print(cnt)


Measured memory_bytes: 48488
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  string s;
  cin >> s;
  long long ans;
  cin >> ans;
  long long mfans = 0, flans = 0;
  int num = 0;
  bool b = true;
  char ls = '+';
  for(int i = 0; i < s.size(); i++) {
    if(b) {
      num = s[i] - '0';
      b = false;
    } else {
      if(s[i] == '+' || s[i] == '*') {
        if(ls == '+') flans += num;
        else flans *= num;
        ls = s[i];
        b = true;
      } else {
        num = num * 10 + s[i] - '0';
      }
    }
  }
  if(ls == '+') flans += num;
  else flans *= num;
  
  string ss = "0+" + s + "+0";
  while(true) {
    bool bb = false;
    for(int i = 0; i < ss.size(); i++) {
      if(ss[i] == '*') {
        int k = i - 1;
        for(; k > 0; k--) if(ss[k] == '+' || ss[k] == '*') {
          k++;
          break;
        }
        int l = i + 1;
        for(; l < ss.size(); l++) if(ss[l] == '+' || ss[l] == '*') {
          l--;
          break;
        }
        int lhs = stoi(ss.substr(k, i - k));
        int rhs = stoi(ss.substr(i + 1, l - i));
        ss = ss.substr(0, k) + to_string(lhs * rhs) + ss.substr(l + 1, ss.size());
        bb = true;
        break;
      }
    }
    if(!bb) break;
  }
  num = 0;
  b = true;
  for(int i = 0; i < ss.size(); i++) {
    if(b) {
      num = ss[i] - '0';
      b = false;
    } else {
      if(ss[i] == '+') {
        mfans += num;
        b = true;
      } else {
        num = num * 10 + ss[i] - '0';
      }
    }
  }
  mfans += num;
  
  
  if(flans == ans && mfans == ans) cout << "U" << endl;
  else if(mfans == ans) cout << "M" << endl;
  else if(flans == ans) cout << "L" << endl;
  else cout << "I" << endl;

  return 0;
}

Measured memory_bytes: 3288
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
            int k = in.nextInt();
            int sum = a + b + c;
            int tmp = Math.max(Math.max(a, b), c);
            sum -= tmp;
            sum += tmp << k;
            out.println(sum);
        }

    }
}



Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;
int comb[2010][2010];

void comb_table(int n){
  for(int i=0;i<=n;++i){
    for(int j=0;j<=i;++j){
      if(j==0 or j==i){
        comb[i][j]=1;
      }else{
        comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%int(1e9+7);
      }
    }
  }
}

int main(){
  int n, k;cin>>n>>k;
  comb_table(2005);
  if(n==k){
    for(int m=1;m<=k;m++){
      if(m==1)cout<<1<<endl;
      else cout<<0<<endl;
    }
  }else{
    for(int m=1;m<=k;m++){
      ll red;
      if(m==1){
        red = ((comb[n-k-1][m-1]*2)%int(1e9+7)+(comb[n-k-1][m])%int(1e9+7))%int(1e9+7);
      }else{
        red = ((comb[n-k-1][m-1]*2)%int(1e9+7)+(comb[n-k-1][m-2]+comb[n-k-1][m])%int(1e9+7))%int(1e9+7);
      }
      ll blue = (comb[k-1][m-1])%int(1e9+7);
      ll ans = (red*blue)%int(1e9+7);
      cout<<ans<<endl;
    }
  }
}

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

int main(){
    int N;cin>>N;
    string S;cin>>S;
    map<int,bool> red;
    map<int,bool> green;
    map<int,bool> blue;
    for(int i=0;i<N;i++){
        red[i]=0;
        green[i]=0;
        blue[i]=0;
    } 
    int r=0;
    int g=0;
    int b=0;
    for(int i=0;i<N;i++){
        if(S.at(i)=='R'){
            red[i]=1;
            r++;
        }
        if(S.at(i)=='G'){
            green[i]=1;
            g++;
        }
        if(S.at(i)=='B'){
             blue[i]=1;
             b++;
        }
       
    }
  if(b==0){
    cout<<0<<endl;
    return 0;
  }
    long count=0;
    for(int i=0;i<N;i++){
        if(red[i]){
            for(int j=0;j<N;j++){
                if(green[j]){
                  if((max(i,j)-min(i,j))%2==0){
                  int h=0;
                  if(blue[2*i-j]&&blue[2*j-i])h=2;
                  else if(blue[2*j-i]||blue[2*i-j])h=1;
                  if(blue[(max(i,j)+min(i,j))/2])h++;
                  count = count+b-h;
                  }else{
                  int h=0;
                  if(blue[2*i-j]&&blue[2*j-i])h=2;
                  else if(blue[2*j-i]||blue[2*i-j])h=1;
                  count = count+b-h;
                  }
                }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 4420
module Main where

import Data.List
import Data.Char (digitToInt)
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import qualified Data.Map.Strict as M


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> Int -> Int
solve n k = head . filter (\num -> k ^ num > n ) $ [0..]


main = do
    (n, k) <- readTuple2
    print $ solve n k



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

using namespace std;


int main(){
  int n;
  int m;
  int ans=0;
  int under=1;
  int top=100000;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  for(int i=0;i<m;i++){
    cin >> l.at(i);
    cin >> r.at(i);
  }
  for(int i=0;i<m;i++){
    if(under <= l.at(i)){
      under=l.at(i);
    }
    if(top >= r.at(i)){
      top=r.at(i);
    }
  }
  for(int i=1;i<=n;i++){
    if( (i>=under)&&(i<=top) ){
      ans++;
    }
  }

  // cout << under << " " << top << endl;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
    
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
    

template<int LG = 20>
struct LCA {
    vector<int> ro[LG], dps;
    
    /// 事前処理を行う rはroot頂点のid
    template<class E>
    void exec(const VV<E> &g, int r) {
        int V = (int)g.size();
        for (int i = 0; i < LG; i++) {
            ro[i].resize(V);
            fill_n(ro[i].begin(), V, -1);
        }
        dps.resize(V);
        dfs(g, r, -1, 0);
        for (int i = 1; i < LG; i++) {
            for (int j = 0; j < V; j++) {
                ro[i][j] = (ro[i-1][j] == -1) ? -1 : ro[i-1][ro[i-1][j]];
            }
        }
    }
    /// lとrの頂点のLCAを求める
    int query(int l, int r) {
        if (dps[l] < dps[r]) swap(l, r);
        int dd = dps[l]-dps[r];
        for (int i = LG-1; i >= 0; i--) {
            if (dd < (1<<i)) continue;
            dd -= 1<<i;
            l = ro[i][l];
        }
        if (l == r) return l;
        for (int i = LG-1; i >= 0; i--) {
            if (ro[i][l] == ro[i][r]) continue;
            l = ro[i][l]; r = ro[i][r];
        }
        return ro[0][l];
    }
    
    template<class E>
    void dfs(const VV<E> &g, int p, int b, int now) {
        ro[0][p] = b;
        dps[p] = now;
        for (E e: g[p]) {
            if (e.to == b) continue;
            dfs(g, e.to, p, now+1);
        }
    }
};
    
struct Edge {
    int to;
    ll dist;
};

V<ll> dps;
VV<Edge> g;

void dfs(int p, int b, ll sm) {
    dps[p] = sm;
    for (auto e: g[p]) {
        if (e.to == b) continue;
        dfs(e.to, p, sm + e.dist);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    dps = V<ll>(n);
    g = VV<Edge>(n);
    for (int i = 0; i < n-1; i++) {
        int a, b; ll c;
        scanf("%d %d %lld", &a, &b, &c); a--; b--;
        g[a].push_back(Edge{b, c});
        g[b].push_back(Edge{a, c});
    }
    dfs(0, -1, 0);
    LCA<18> lca; lca.exec(g, 0);
    auto dist = [&](int a, int b) {
        int c = lca.query(a, b);
        return dps[a]+dps[b]-2*dps[c];
    };
    int q, c;
    scanf("%d %d", &q, &c); c--;
    for (int i = 0; i < q; i++) {
        int a, b;
        scanf("%d %d", &a, &b); a--; b--;
        printf("%lld\n", dist(a, c) + dist(c, b));
    }
    return 0;
}

Measured memory_bytes: 21760
#include<stdio.h>
#include<math.h>
double d[1001][1001]={0};
int n,i,j,k,b[1001],x[1001],y[1001],min,mi,e,s,r;
double c[1001][1001]={0};
int from[1001][1001]={0};
int main(){
  while(scanf("%d",&n),n){
    for(i=0;i<1000;i++){
      for(j=0;j<1000;j++)c[i][j]=from[i][j]=0;
    }
    for(i=0;i<n;i++){
      scanf("%d %d %d",&b[i],&x[i],&y[i]);
      for(j=i;j>-1;j--)d[b[i]][b[j]]=d[b[j]][b[i]]=hypot(x[i]-x[j],y[i]-y[j]);
    }
    /*for(i=0;i<n;i++){
      for(j=0;j<n;j++)printf("%f ",d[b[i]][b[j]]);printf("\n");
      }//*/
    for(i=0;i<n;i++){
      mi=b[i];
      int f[1000]={0};
      for(j=0;j<n;j++){
	f[mi]=1;
	for(k=0;k<n;k++){
	  if(f[b[k]]||d[mi][b[k]]>50)continue;
	  if(c[b[i]][b[k]]==0||c[b[i]][b[k]]>c[b[i]][mi]+d[mi][b[k]]){
	    c[b[i]][b[k]]=c[b[i]][mi]+d[mi][b[k]];
	    from[b[i]][b[k]]=mi;
	  }
	}
	min=2100000000;
	for(k=0;k<n;k++){
	  if(f[b[k]]||c[b[i]][b[k]]==0)continue;
	  if(min>c[b[i]][b[k]])min=c[b[i]][mi=b[k]];
	}
      }
    }
    scanf("%d",&n);
    while(n--){
      scanf("%d %d",&s,&e);
      if(from[s][e]){
	int ans[1000];
	r=0;
	for(i=e;i-s;i=from[s][i])ans[++r]=i;//,printf("%d ",ans[r-1]);printf("\n");
	printf("%d",s);
	while(r)printf(" %d",ans[r--]);
      }
      else printf("NA");
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 14964
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            int iR = int.Parse(Console.ReadLine().Trim());

            // 解析
            string sOut = "AGC";
            if (iR < 1200 ) { sOut = "ABC"; }
            else if (iR < 2800 ) { sOut = "ARC"; }

            //出力
            Console.WriteLine("{0}", sOut.ToString());

#if DEBUG
        Console.WriteLine("続行するには何かキーを押してください．．．");
        Console.ReadKey();
#endif

    }

}


Measured memory_bytes: 13140
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	int ans;
	int a,b;
	cin >> a >> b;
	if (b % a == 0) {
		ans = a + b;
	}
	else {
		ans = b - a;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  ll n;
  cin >> n;
  V<int> ms(1e6 + 1);

  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll m = n / i - 1;
      if (m == 0) continue;
      if (n / m == n % m) ans += m;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7196
# -*- coding: utf-8 -*-
from collections import Counter
import math
N = int(input())

As = list(map(int, input().split()))

cnter = Counter(As)
V = dict()
select = 0

for k, v in cnter.most_common():
    if v>=2:
        V[k] = math.floor(v/2)
#print(V)
tmp = 0
h = 0

if len(V) < 2:
    print(0)
    exit()

for k, v in sorted(V.items(), key=lambda x:-x[0]):
    if v >= 2 and tmp == 0:
        print(int(k*k))
        exit()
    else:
        if(tmp==1):
            print(int(h*k))
            exit()
        tmp += 1
        h = k




Measured memory_bytes: 21668
#include<bits/stdc++.h>
using namespace std;
char a[1001];
bool x=false,y=false;
int main()
{
	gets(a);
	for(int i=0;i<strlen(a);i++){
		if(a[i]=='C')x=true;
		if(a[i]=='F'&&x==true)y=true;
	}
	if(x==true&&y==true)cout<<"Yes";
	else cout<<"No";
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; ll c;
	cin >> n >> c;
	ll dis[n];
	ll kcal[n];
	ll sumkcalC[n];
	ll sumkcalA[n];
	ll maxkcalC[n];
	ll maxkcalA[n];
	for( int i = 0; i < n; ++i ){
		ll x, y; cin >> x >> y;
		dis[i] = x;
		kcal[i] = y;
	}
	sumkcalC[0] = kcal[0];
	sumkcalA[0] = kcal[n-1];
	maxkcalC[0] = -INF;
	maxkcalA[0] = -INF;
	for( int i = 1; i < n; ++i ){
		sumkcalC[i] = sumkcalC[i-1] + kcal[i];
		sumkcalA[i] = sumkcalA[i-1] + kcal[n-i-1];		
	}
	for( int i = 1; i < n; ++i ){
		maxkcalC[i] = max( sumkcalC[i-1]-dis[i-1], maxkcalC[i-1] );
		maxkcalA[i] = max( sumkcalA[i-1]-(c-dis[n-i]), maxkcalA[i-1] );
	}
	
	ll ans = 0;
	for( int i = 0; i < n; ++i ){
		ans = max(ans, max( sumkcalC[i] - dis[i], sumkcalC[i] - 2*dis[i] + maxkcalA[n-i-1] ));
	}
	for( int i = 0; i < n; ++i ){
		ans = max(ans, max( sumkcalA[i] - (c-dis[n-i-1]), sumkcalA[i] - 2*(c-dis[n-i-1]) + maxkcalC[n-i-1] ));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4992
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
    n = parseInt(readline())
    a = parseMap(split(readline()))

    ans = 0
    for i in 1:n
        while a[i]%2 == 0
            a[i] /= 2
            ans += 1
        end
    end

    println(ans)
end

main()


Measured memory_bytes: 114220