akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e4 + 10;

int dp[N];

bool cmp(const pair<pii, int> &a, const pair<pii, int> &b) {
	return a.fi.fi + a.fi.se < b.fi.fi + b.fi.se;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	pair<pii, int> a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i].fi.fi >> a[i].fi.se >> a[i].se;
	}
	sort(a, a + n, cmp);
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = a[i].fi.se; j >= 0; j--) {
			if(dp[j] != -1) {
				dp[j + a[i].fi.fi] = max(dp[j + a[i].fi.fi], dp[j] + a[i].se);
				ans = max(ans, dp[j + a[i].fi.fi]);
			}
		}
	}
	cout << ans;

	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

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

    int x3 = x2 - (y2 - y1); // こいつを求める
    int y3 = y2 + (x2 - x1);
    int x4 = x1 - (y2 - y1); // こいつを求める
    int y4 = y1 + (x2 - x1);

    

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

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int a, b;
	
	scanf("%d %d", &a, &b);
	
	if(a < b){
		printf("a < b");
	}else if(a > b){
		printf("a > b");
	}else {
		printf("a == b");
	}
	
	putchar('\n');
		
	return 0;
}

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


class Main {
    static final int N=110000;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int qq=sc.nextInt();
        int[]p=new int[N];
        Arrays.fill(p, 1);
        p[0]=p[1]=0;
        for(int i=2;i<N;++i){
            if(p[i]==0)continue;
            for(int j=2*i;j<N;j+=i)
                p[j]=0;
        }
        int[]q=new int[N];
        for(int i=1;i<N;++i)q[i]+=q[i-1]+(i%2)*p[i]*p[i/2+1];
        while(qq-->0){
            int l=sc.nextInt();
            int r=sc.nextInt();
            out.println(q[r]-q[l-1]);
        }
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}


Measured memory_bytes: 50116
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        if(N % 10 == N / 100){
            sb.Append("Yes\n");
        }
        else{
            sb.Append("No\n");
        }
    }
}

Measured memory_bytes: 13140
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
#define pb push_back
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,k;
vector <int> a1,a2;

int main()
{
	cin>>n>>k;
	int tot=(n-1)*(n-2)/2,f=n+1;
	if(k>tot) puts("-1");
	else
	{
		for(int i=2;i<=n;i++) a1.pb(1),a2.pb(i);
		int res=(n-1)*(n-2)/2-k,cnt=0;
		if(res==0)
		{
			cout<<a1.size()<<endl;
			for(int k=0;k<a1.size();k++) printf("%d %d\n",a1[k],a2[k]);
			return 0;
		}
		for(int i=2;i<=n;i++) for(int j=i+1;j<=n;j++)
		{
			a1.pb(i),a2.pb(j),cnt++;
			if(cnt==res)
			{
				cout<<a1.size()<<endl;
				for(int k=0;k<a1.size();k++) printf("%d %d\n",a1[k],a2[k]);
				return 0;
			}
		}
	}
	return 0;
}

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

int main(){
    int n,x;
  cin >> n >> x;
  
  int min_m = 100000,sum = 0;
  for ( int i = 0 ; i < n ; i++ ){
  	int m;
    cin >> m;
    min_m = min(min_m,m);
    sum += m;
  }
  
  int ans;
  ans = n + ( x - sum ) / min_m;
  
  cout << ans << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int num = 1;
  while (num * 2 < num + K && N > 0){
    num *= 2;
    N--;
  }
  num += N * K;
  cout << num << endl;
}


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

int main(){
  int N;
  int c = 200;
  cin >> N;
  
  for(int i = 0;i < N;i++){
    int A;
    int a, tmp = 0;
    cin >> A;
    a = A;
      while(a % 2 == 0){
      	tmp++;
        a /= 2;
      }
      c = min(c, tmp);
  }
  
  cout << c << endl;
  return 0;
}

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
ll A, B, C, D;
cin >> A >> B >> C >> D;

ll sa = B-A+1;
ll c = (B/C)-((A-1)/C);
ll d = (B/D)-((A-1)/D);
ll f =  C / GCD(C, D) * D;

ll e = (B/f)-((A-1)/f);


cout << sa -c -d + e << endl;




}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	vector<int> a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}

	vector<int> ans = { 5,5,7 };

	sort(a.begin(), a.end());
	
	if (a == ans) {
		cout << "YES" << endl;
	}
	
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
A = combinations_with_replacement(range(m), n)
L = []

for _ in range(q):
    L.append(list(map(int, input().split())))

r = 0
for a in A:
    t = 0
    for l in L:
        if a[l[1] - 1] - a[l[0] - 1] == l[2]:
            t += l[3]
    if t > r:
        r = t
print(r)


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

int main(void){
  int N;
  cin >> N;
  for(int i = 1; i <= 9;i++){
    if(N % i == 0 && N / i <= 9){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.split(/\n/).slice(1, -1);
  input = input.map(v => v.split(/\s/).map(v => ~~v));

  let ans = "Yes"; // 'Yes' or 'No'
  let distance = 0;
  let time = 0;
  let next = { x: 0, y: 0, t: 0 };
  let tmp = { x: 0, y: 0, t: 0 };

  for (let i = 0; i < input.length; i++) {
    next.t = input[i][0];
    next.x = input[i][1];
    next.y = input[i][2];

    time = next.t - tmp.t;

    distance = Math.abs(tmp.x - next.x) + Math.abs(tmp.y - next.y);

    // console.log(time, distance, time % 2, distance % 2)
    if (time < distance || next.t % 2 != (next.x + next.y) % 2) {
      ans = "No";
      //   break;
    }

    tmp.t = next.t;
    tmp.x = next.x;
    tmp.y = next.y;
  }
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 51104
import sys
input = sys.stdin.readline

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

AB=[]
for a in A:
    for b in B:
        AB.append(a+b)

AB.sort(reverse=True)
AB=AB[:K]

ALL=[]

for ab in AB:
    for c in C:
        ALL.append(ab+c)

ALL.sort(reverse=True)

for k in range(K):
    print(ALL[k])

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

int main() {

	ll n, m; cin >> n >> m;
	const ll mod = 1000000007;
	if (n < m) swap(n, m); // m <= n  
	if (2 <= n - m) {
		cout << 0 << endl;
	}
	else {
		ll ans = 1;
		if (n == m) {
			ll cnt = n;
			while (cnt--) {
				ans *= (cnt + 1);
				ans %= mod;
				ans *= (cnt + 1);
				ans %= mod;
			}
			ans *= 2;
			ans %= mod;
			cout << ans << endl;
		}
		else {
			while (n--) {
				ans *= (n + 1);
				ans %= mod;
			}
			while (m--) {
				ans *= (m + 1);
				ans %= mod;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3604
#pragma warning(disable:4996)
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

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

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

int main(void) {
	int N, K;
	cin >> N >> K;
	vec<int> h(N);
	REP(i, N) {
		cin >> h[i];
	}
	sort(ALL(h));
	int ans = 1e9;
	REP(i, N - K + 1) {
		ans = min(ans, h[i + K - 1] - h[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define spIO ios_base::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef long double lb;
int main()
{
	spIO;
	string in;
	cin >> in;
	unsigned long long s;
	stringstream ss;
	ss << in;
	ss >> s;
	cout << 0 << ' ' << 0 << ' ';
	if (in.size() == 19)
	{
		cout << 0 << ' ' << 1000000000 << ' ' << 1000000000 << ' ' << 0 << '\n';
	}
	else
	{
		unsigned long long t = sqrt(s) + 1;
		cout << t << ' ' << 1 << ' ' << t * t - s << ' ' << t << '\n';
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	ll N, K,ANS1,ANS2;
	cin >> N >> K;
	ANS1 = N % K;
	ANS2 = abs(N % K - K);
	cout << min(ANS1, ANS2) << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(10)]

for i in range(10):
  for j in range(10):
    for k in range(10):
      graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k])
      
ans = 0

for l in range(h):
  tile = list(map(int, input().split()))
  for m in tile:
    if m != -1:
      ans += graph[m][1]

print(ans)

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

int main() {
 int n,x;
  cin>>n>>x;
  vector<int> l(n);
  rep(i,n){
   cin>>l[i]; 
  }
  /////
  vector<int> hane(1,0);
  int now=0;
  rep(i,n){
    now+=l[i];
   hane.push_back( now);
  }
  int count=0;
  rep(i,n+1){
   if(hane[i]<=x){
    count++; 
   }
    
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int a[M];
 main()

{
    fast
    int n,x;
    cin>>n>>x;
    f(i,1,n)
    {
       cin>>a[i];
    }
    int ses=0;
    f(i,2,n)
    {
       int u=a[i-1];
       int v=a[i];
       if(u+v<=x)continue;
       int gap=(u+v)-x;
       if(v>=gap)
       {
           v=v-gap;
           ses+=gap;
           a[i]=v;
       }
       else
       {
           ses+=v;
           a[i]=0;
           gap-=v;
           u=u-gap;
           ses+=gap;
           a[i-1]=u;
       }
    }
    cout<<ses<<endl;
    return 0;

}




































Measured memory_bytes: 4368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  ll res = 0;
  ll sa = 0;
  sa = pow(10,18);
  for(int i = 0;i < n - 1;i++){
    if(abs(a[i] - a[n - 1] / 2) <= sa){
      sa = abs(a[i] - a[n - 1] / 2);
      res = a[i];
    }
    //cout << i << " " << sa << endl;
  }
  cout << a[n - 1] << " " << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, x, K, sum=0;
  cin>>N>>K;
  for(int i=1;i<=N;i++) {
    cin>>x;
    sum+=min(x*2, (K > x ? K - x : x - K) * 2);
  }
  cout << sum << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  int num[3]={};
  rep(i,n){
    num[s[i]-'a']++;
  }
  int M = max({num[0],num[1],num[2]});
  int m = min({num[0],num[1],num[2]});
  if(abs(M-m)<2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

using namespace std;

#define FaSt ios::sync_with_stdio(0),cin.tie(0);
#define random uniform_int_distribution<long long>(1, 2000000000000000LL)(rng)

const int N = 3005;
int n;
long double dp[N][N], ans;
long double a[N];
bool solved[N][N];

double calc(int i, int c)
{
    if (solved[i][c])
    {
        return dp[i][c];
    }
    
    if (i == n)
    {
        if (c == 0)
            return 1;
        else
            return 0;
    }
    
    if (c >= 1)
    {
        dp[i][c] = a[i] * calc(i + 1, c - 1) + (1 - a[i]) * calc(i + 1, c);
    }
    else
    {
        dp[i][c] = (1 - a[i]) * calc(i + 1, c);
    }
    
    solved[i][c] = 1;
    return dp[i][c];
}

int main()
{
    FaSt
    cin >> n;
    
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    long double ans = 0;
    for (int i = n; i > n / 2; i--)
    {
        ans += calc(0, i);
    }
    
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 150272
#include <iostream>

using namespace std;
int X[100], Y[100];

int main() {
    int w, h, n, x, y, a;
    cin >> w >> h >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> a;
        if (a == 1) {
            for (int j = 0; j < x; ++j) X[j] = 1;
        } else if (a == 2) {
            for (int j = x; j < w; ++j) X[j] = 1;
        } else if (a == 3) {
            for (int j = 0; j < y; ++j) Y[j] = 1;
        } else {
            for (int j = y; j < h; ++j) Y[j] = 1;
        }
    }
    int cntX = 0, cntY = 0;
    for (int i = 0; i < w; ++i) if (!X[i]) cntX++;
    for (int i = 0; i < h; ++i) if (!Y[i]) cntY++;
    cout << cntX * cntY << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>s>>ss;
    for0(s.size())
    {
        if(s[i]!=ss[i])c++;
    }
    cout<<c<<endl;
}



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

using namespace std;

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k; i++)
	{
		if (i % 2 == 0)
		{
			if (a % 2 == 1)
				a--;
			b += a / 2;
			a /= 2;
		}
		else
		{
			if (b % 2 == 1)
				b--;
			a += b / 2;
			b /= 2;
		}
	}
	cout << a << " " << b << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()

	if a <= 5 {
		fmt.Println(0)
	} else if a <= 12 {
		fmt.Println(b / 2)
	} else {
		fmt.Println(b)
	}

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int n;
    cin >> n;

    int a[n];

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

    sort(a, a+n);

    cout << a[n-1] - a[0] << endl;
    return 0;
       
}

Measured memory_bytes: 256
N=int(input())
S,T=[None]*N,[None]*N
for i in range(N):
    s,t=input().split()
    S[i]=s
    T[i]=int(t)
X=input()
for i in range(N):
    if S[i]==X:
        a=i
        break
print(sum(T[a+1:]))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x, y;
    cin >> x >> y;
    int t,k;
    t = (4*x-y);
    k = (-2*x+y);
    if(t%2==0 && k%2==0){
        if(t>=0 && k>=0){
            cout <<"Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}




Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main () {
  int input;
  vector<int> numbers;

  for (size_t i = 0; i < 3; i++) {
    cin >> input;
    numbers.push_back(input);
  }

  sort(numbers.begin(), numbers.end());

  cin >> input;

  for (size_t i = 0; i < input; i++) {
    numbers.back() *= 2;
  }

  long int count = 0;

  for(int &i : numbers) {
    count += i;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a+100*b+50*c == X:
                cnt += 1

print(cnt)

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

using namespace std;

int main() {

    long int N, X, Y; cin >> N >> X >> Y;

    long int distance[N];
    for (int i=0; i<=N; i++) distance[i] = 0;

    for (int i=1; i<N; i++) {
        for (int j=i+1; j<=N; j++) {
            long int a = abs(j-i);
            long int b = abs(X-i)+1+abs(Y-j);
            long int c = min(a, b);
            long int d = abs(Y-i)+1+abs(X-j);
            long int e = min(c, d);
            //cout << e << endl;
            distance[(int)e] += 1;
        }
    }

    for (int i=1; i<N; i++) cout << distance[i] << endl;

    
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
ll counter;

int main() {
	ll a = 0, b = 0, c = 0, d = 0, n = 0, m = 0, counter = 0, maxi = 0, asum = 0, bsum = 0, counter2 = 0;
	ll x = 0, y = 0;
	ll A[10001], B[10001];
	priority_queue<ll> pque;
	std::string str, str2;
	cin >> str;
	rep(i, str.size()) {
		if ((i + 1) % 2 == 0) {
			if (str[i] != 'L' && str[i] != 'U' && str[i] != 'D') {
				a++;
			}
		}
		if ((i + 1) % 2 == 1) {
			if (str[i] != 'R' && str[i] != 'U' && str[i] != 'D') {
				a++;
			}
		}
	}
	if (a != 0)cout << "No" << endl;
	else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
int n;
int trieroot;
int trien;
int triep[1001000];
int trier[1001000][26];
int triec[1001000];
int triecnt[1001000];
int triercnt[1001000][26];
char s[1001000];
int pd[200100];
int newtn(int prt, int c) {
	triep[trien] = prt;
	triec[trien] = c;
	trien++;
	return trien - 1;
}
int main() {
	scanf("%d", &n);
	trien = 1;
	trieroot = newtn(0, 0);
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		int x = trieroot;
		int len = 0;
		for (len = 0; s[len]; len++);
		for (int j = len - 1; j >= 0; j--) {
			int d = s[j] - 'a';
			if (trier[x][d] == 0) {
				trier[x][d] = newtn(x, d);
			}
			x = trier[x][d];
		}
		triecnt[x]++;
		pd[i] = x;
	}
	for (int i = trien - 1; i >= 1; i--) {
		triecnt[triep[i]] += triecnt[i];
		for (int j = 0; j < 26; j++) {
			if (j == triec[i]) {
				triercnt[triep[i]][j] += triecnt[i];
			}
			else {
				triercnt[triep[i]][j] += triercnt[i][j];
			}
		}
	}
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		int x = pd[i];
		int y = triep[x];
		int d = triec[x];
		ans += triercnt[y][d] - 1;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 216272
#include<bits/stdc++.h>
#include<string>
#define int long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
void solve(){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;
}


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--) solve();

}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
using namespace std;
int main() {
  long long A;
  int flag=0;
  string name="";

  cin >> A;
while (1){
  if(flag==1){
   A=(A-(A%26))/26;
   flag=0;
   }
   if(flag==2){
     A=((A-(A%26))/26)-1;
     flag=0;
   }
  if(A%26==0){
    if(A/26==0){
 
    }else{
      name=char(96+26)+name;
      flag=1;
      }
  }else{
    if(A/26==0){
      name=char(96+(A%26))+name;

    }else{
    name=char(96+(A%26))+name;
    
    }
  
  }
    if(A<26){
    break;
  }
  flag=flag+1;
}
  
  cout << name;
}

Measured memory_bytes: 3656
n=int(input())
a=list(map(int,input().split()))
b=[-1]*(n+1)
MOD=10**9+7
factorials=[1]
current=1
for i in range(1,n+2):
  current=(current*i)%MOD
  factorials.append(current)
inverses=[]
for i in range(n+2):
  inverses.append(pow(factorials[i],MOD-2,MOD))
for i in range(n+1):
  if b[a[i]]!=-1:
    l=b[a[i]]
    r=i
    break
  b[a[i]]=i
for i in range(1,n+2):
  ans=(factorials[n+1]*inverses[i]*inverses[n+1-i])%MOD
  
  rem=n-r+l
  if  rem>=i-1:
    ans=(ans-factorials[rem]*inverses[i-1]*inverses[rem-(i-1)])%MOD
  print(ans)


Measured memory_bytes: 97060
import math
a,b,x = map(int,input().split())
y = math.pi
if x >= 1/2 * (a*a*b):
    theta = math.atan(2*(a*a*b-x)/(a*a*a))
else:
    theta = y/2 - math.atan(2*x/(a*b*b))
print(theta*180/y)

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

int main()
{
  int n;
  cin >> n;
  vector<double> a(200);
  rep(i, n) cin >> a[i];
  double sum = 0;
  rep(i, n)
  {
    sum += ((double)1 / a[i]);
  }
  cout << setprecision(10) << ((double)1 / sum) << endl;
  
  return 0;
}
  

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

#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  bool operator<(const ll rhs) const {
    return x < rhs;
  }
  bool operator>(const ll rhs) const {
    return x > rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

mint memo[2005][2005];
mint comb(int n,int m){
  if(m>n) return 0;
  if(memo[n][m] > 0) return memo[n][m];
  if(m==0 || m == n){
    memo[n][m] = 1;
    return 1;
  }
  else{
    memo[n][m] = comb(n-1,m) + comb(n-1,m-1);
    return memo[n][m];
  }
}

int main(){
  int N,K;
  std::cin >> N >> K;
  rep(i,2005) rep(j,2005) memo[i][j] = 0;
  for(int i=1;i<=K;i++){
    cout << comb(N-K+1,i) * comb(K-1,i-1) << endl;
  }
  return 0;
}


Measured memory_bytes: 31744
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): pass
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


s = S()
t = S()
S,T = len(s),len(t)
dp = [[0]*(T+1) for _ in range(S+1)]
for i in range(S):
    for j in range(T):
        if s[i]==t[j]:
            dp[i+1][j+1] = 1 + dp[i][j]
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])



ans = ""
while dp[S][T]:
    if dp[S - 1][T] == dp[S][T]:
        S -= 1
    elif dp[S][T - 1] == dp[S][T]:
        T -= 1
    else:
        S -= 1
        T -= 1
        ans = s[S] + ans


if len(ans) == 0:
    print("")
else:
    print(ans)


Measured memory_bytes: 154120
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  long n;
  cin >> n;
  long sq = sqrt(n);
  for(long i = sq;i>=1;i--){
    if(n % i == 0){
      cout << (i-1) + (n/i)-1 << endl;
      return 0;
    }
  }
}


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

using namespace std;

int main(){
  string X, Y;
  int q;
  cin >> q;
  int ans[q];
  for(int i=0;i<q;i++){
    cin >> X;
    cin >> Y;
    int n = X.size();
    int m = Y.size();
    int dp[n+1][m+1];
    for(int j=0;j<n+1;j++){
      dp[j][0] = 0;
    }
    for(int j=0;j<m+1;j++){
      dp[0][j] = 0;
    }
    for(int j=1;j<n+1;j++){
      for(int k=1;k<m+1;k++){	
	if(X[j-1] == Y[k-1]){
	  dp[j][k] = dp[j-1][k-1]+1;
	}else{
	  dp[j][k] = max(dp[j][k-1], dp[j-1][k]);
	}   
       
      }

    }
    ans[i] = dp[n][m];
  }

  for(int i=0;i<q;i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 7096
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 50
#define LARGENUM 1000000007
#define INF 9223372036854775807
#define ull unsigned long long 
typedef pair <int, int> P;

int main(){
    int N, K, tmp, ans = 0;
    cin >> N >> K;
    vector<int> p;
    rep(i, N) {
        cin >> tmp;
        p.push_back(tmp);
    }
    sort(p.begin(), p.end());
    rep(i, K){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3164
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=sort(parseMap(split(readline())))
    start=1
    ruiseki=[a[i] for i in 1:n]
    for i in 2:n
        if ruiseki[i-1]*2<ruiseki[i]
            start=i
        end
        ruiseki[i]+=ruiseki[i-1]
    end
    println(n-start+1)
end
main()

Measured memory_bytes: 128208
import java.util.Arrays;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);

        System.out.println(arr[N - 1] - arr[0]);
    }
}

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

using ULL = unsigned long long;

int main(){
	ULL n, k; cin >> n >> k;
	multiset<unsigned> multia;
	unsigned a[2000]; for (int i = 0; i < n; i++) { cin >> a[i]; multia.insert(a[i]); }

	unsigned countmulti = 0;
	for (int i = 1; i <= 2000; i++) {
		unsigned c = multia.count(i);
		if (c == 0) continue;
		countmulti += c * (c - 1) / 2;
	}

	ULL flip = 0;

	for (unsigned i = 0; i < n; i++)
		for (unsigned ii = i + 1; ii < n; ii++)
			if (a[i] > a[ii]) flip++;

	ULL mac = n * (n - 1) / 2 - countmulti;
	ULL C = (k * (k - 1) / 2) % 1000000007;
	mac = mac * C % 1000000007;
	ULL macflip = (ULL)flip * k;
	mac = (mac + macflip) % 1000000007;

	cout << mac << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    string s, t;
    cin>> s>> t;
    int ans = INT_MAX;
    rep(i, 0, s.size() - t.size() + 1){
        int gg = 0;
        string x = s.substr(i, t.size());
        rep(j, 0, t.size())
            if(x[j] != t[j])
                gg++;
        ans = min(ans, gg);
    }
    cout<< ans<< "\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int i=(x);i<(n);i++)
#define EREP(i,n) for(int i=1;i<(n);i++)
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='9'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}


int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n, m; cin >> n >> m;
    if(n == 0 && m == 0) break;
    vi c(m), x(n+1);
    REP(i, m) {
      cin >> c[i];
    }
    REP(i, n) {
      cin >> x[i+1];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(256, LINF));
    dp[0][128] = 0;

    FOR(i, 1, n+1) {
      REP(j, 256) {
        REP(k, m) {
          int next = min(255, max(0, j+c[k]));
          dp[i][next] = min(dp[i][next], dp[i-1][j] + (x[i] - next) * (x[i] - next));
        }
      }
    }


/*     REP(i, n) {
      printv(dp[i]);
    } */

    ll ans = LINF;
    REP(i, 256) {
      ans = min(ans, dp[n][i]);
    }
    cout << ans << endl;
  }
}



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

int main(){
  int K;
  int N;
  
  cin >>K >>N;
  vector<int> A(N,0);
  for (int i=0; i<N; i++){
    cin >>A.at(i);
  }
  
  vector<int> dis(N);
  for (int i=0; i<N-1; i++){
    dis.at(i) = A.at(i+1) - A.at(i);
  }
  
  dis.at(N-1) = K+A.at(0)-A.at(N-1);
  
  sort(dis.begin(),dis.end());
  
  int ans;
  ans = K - dis.at(N-1);
  
  cout <<ans <<endl;
  
}

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

signed main(){
    int n , m , same;
    char a[50][50] , b[50][50];
    bool f = false;
    
    cin >> n >> m;
    for(int i=0 ;i<n ;i++ ){
        cin >> a[i];
    }
    for(int i=0 ;i<m ;i++ ){
        cin >> b[i];
    }
    
    for(int i=0 ;i<n-m+1 ;i++ ){
        for(int j=0 ;j<n-m+1 ;j++ ){
            same = 0;
            for(int k=i ;k<i+m ;k++ ){
                for(int l=j ;l<j+m ;l++ ){
                    if(a[k][l] == b[k-i][l-j]){
                        same++;
                    }
                }
            }
            if(same == m*m){
                f = true;
            }
        }
    }
    
    if(f){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return(0);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        long sumOfP = sc.nextLong();
        long countP = 0;
        long sumOfM = sumOfP;
        long countM = 0;

        if (sumOfP <= 0) {
            countP = -sumOfP + 1;
            sumOfP = 1;
        }

        if (sumOfM >= 0) {
            countM = sumOfM + 1;
            sumOfM = -1;
        }

        for (int i = 1; i < n; i++) {
            long a = sc.nextLong();

            if (sumOfP > 0) {
                if (sumOfP + a >= 0) {
                    countP += sumOfP + a + 1;
                    sumOfP = -1;
                } else {
                    sumOfP += a;
                }
            } else {
                if (sumOfP + a <= 0) {
                    countP += -(sumOfP + a) + 1;
                    sumOfP = 1;
                } else {
                    sumOfP += a;
                }
            }

            if (sumOfM > 0) {
                if (sumOfM + a >= 0) {
                    countM += sumOfM + a + 1;
                    sumOfM = -1;
                } else {
                    sumOfM += a;
                }
            } else {
                if (sumOfM + a <= 0) {
                    countM += -(sumOfM + a) + 1;
                    sumOfM = 1;
                } else {
                    sumOfM += a;
                }
            }
        }

        System.out.println(Math.min(countP, countM));
    }
}


Measured memory_bytes: 50212
#include <iostream>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> P;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

int is_intersected_ls(P a1,P a2,P b1,P b2){
	return ( (cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1) < 0) &&
					 (cross(b2-b1,a1-b1) * cross(b2-b1,a2-b1) < 0) );
}

P intersection_ls(P a1,P a2,P b1,P b2){
	P b = b2 - b1;
	double d1 = abs(cross(b,a1-b1));
	double d2 = abs(cross(b,a2-b1));
	double t = d1 / (d1 + d2);

	return a1 + (a2 - a1) * t;
}

int main(void){
	int n;

	while(cin>>n && n){
		int ans = 1;
		vector< pair<P,P> > p;

		for(int i=0;i<n;i++){
			P a,b;
			int count = 0;
			vector<P> intersctP;

			cin>>a.real()>>a.imag()>>b.real()>>b.imag();
			p.push_back(pair<P,P>(a,b));
			for(int j=0;j<i;j++){
				if(is_intersected_ls(a,b,p[j].first,p[j].second)){
					P tp = intersection_ls(a,b,p[j].first,p[j].second);
					bool flg = true;
					for(int k=0;k<intersctP.size();k++){
						if(EQ(tp,intersctP[k])){
							flg = false;
							break;
						}
					}
					if(flg) count++;
					intersctP.push_back(tp);
				}
			}

			ans += count + 1;
		}

		cout<<ans<<endl;
	}

	return 0;
}

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

using namespace std;

const int mod = 1000000007;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

    int xMax = -1000;
    int yMin = 1000;
    for (int i = 0; i < n; i++)
    {
        int tmpX;
        cin >> tmpX;
        if (tmpX > xMax)
        {
            xMax = tmpX;
        }
    }
    for (int i = 0; i < m; i++)
    {
        int tmpY;
        cin >> tmpY;
        if (tmpY < yMin)
        {
            yMin = tmpY;
        }
    }

    int z = xMax;
    while (yMin >= z)
    {
        if (z > x && z <= y)
        {
            if (z > xMax && z <= yMin)
            {
                cout << "No War" << endl;
                return 0;
            }
        }
        z++;
    }

    cout << "War" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005,INF=1000000000;
int n,cnt,Cnt,h[N],H[N],dis[N],cur[N],g[N],ans,s,t;
struct edge{int v,f,n;} e[N*6],E[N<<1];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void addedge(int u,int v)
{
	E[Cnt]=(edge){v,0,H[u]},H[u]=Cnt++;
	E[Cnt]=(edge){u,0,H[v]},H[v]=Cnt++;
}

void addedge(int u,int v,int f)
{
	e[cnt]=(edge){v,f,h[u]},h[u]=cnt++;
	e[cnt]=(edge){u,0,h[v]},h[v]=cnt++;
}

void dfs(int x,int fa,bool dep)
{
	if(dep) addedge(s,x,1);
	else addedge(x,t,1);
	for(int i=H[x]; i!=-1; i=E[i].n)
		if(E[i].v!=fa)
		{
			if(dep) addedge(x,E[i].v,INF);
			else addedge(E[i].v,x,INF);
			dfs(E[i].v,x,dep^1);
		}
}

int isap(int x,int rt)
{
	if(x==t) return rt;
	int sum=0;
	for(int i=cur[x]; i!=-1; i=e[i].n)
		if(e[i].f && dis[e[i].v]+1==dis[x])
		{
			int f=isap(e[i].v,min(e[i].f,rt-sum));
			e[i].f-=f,e[i^1].f+=f,sum+=f;
			if(cur[x]=i,rt==sum || dis[s]>=t) return sum;
		}
	if(!(--g[dis[x]++])) dis[s]=t;
	++g[dis[x]],cur[x]=h[x];
	return sum;
}

int main()
{
	n=getint(),s=n+1,t=s+1;
	memset(h,-1,sizeof(h));
	memset(H,-1,sizeof(H));
	if(n&1) {puts("First"); return 0;}
	rep(i,1,n-1) addedge(getint(),getint());
	dfs(1,0,1),memcpy(cur,h,sizeof(h));
	for(g[0]=t; dis[s]<t; ans+=isap(s,INF));
	if(ans==(n>>1)) puts("Second");
	else puts("First");
	return 0;
}

Measured memory_bytes: 11520
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		long X = in.nextLong();
		long[] r = new long[N];
		for (int i = 0; i < N; i++) {
			r[i] = Math.abs(X - in.nextLong());
		}
		Arrays.sort(r);
		long ans = r[0];
		for (int i = 1; i < N - 1; i++) {
			ans = gcd(r[i], ans);
		}
		System.out.println(ans);
		in.close();
	}

	static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}
}

Measured memory_bytes: 48088
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<class T> struct SegmentTree {
  int n;
  T ie;
  vector<T> data;
  function<T(T,T)> f;

  SegmentTree() {}
  SegmentTree(int len, T ie, function<T(T,T)> f) : ie(ie), f(f) {
    n = 1 << (32 - __builtin_clz(len));
    data.assign(n+n+1, ie);
  }

  void update(int i, T x) {
    i+=n;
    data[i] = x;
    while(i>>=1) data[i] = f(data[i+i+0], data[i+i+1]);
  }

  T query(int l, int r=1e9) {
    r = min(r, n);
    T res = ie;
    for(l+=n, r+=n; l<r; l>>=1, r>>=1) {
      if(l&1) res = f(res, data[l++]);
      if(r&1) res = f(res, data[--r]);
    }
    return res;
  }

  T operator[](int i) { return data[i+n]; }
};

int main() {
  lint H, W, M;
  cin >> H >> W >> M;

  // 行方向で全探索
  // 列の分布を保持
  SegmentTree<lint> seg(312345, 0, [](lint a, lint b){return max(a,b);});
  // 行ごとに点の位置を保持
  vector<lint> V[312345];
  for(lint i=0; i<M; i++) {
    lint h, w;
    cin >> h >> w;
    h--, w--;
    V[h].push_back(w);
    seg.update(w, seg[w] + 1);
  }

  lint ans = -1e18;
  for(lint i=0; i<H; i++) {
    for(auto w : V[i]) seg.update(w, seg[w]-1);
    ans = max(ans, (lint)V[i].size() + seg.query(0));
    for(auto w : V[i]) seg.update(w, seg[w]+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 27988
N=int(input())
a=[int(i)-1 for i in input().split()]
count=[0]*N
for i in range(N+1):
  count[a[i]]+=1
  if count[a[i]]==2:
    D=a[i]
    break
flag=False
k=0
mod=10**9+7
for i in range(N+1):
  if a[i]==D and not flag:
    flag=True
  elif a[i]==D and flag:
    break
  elif flag:
    k+=1
    
Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod

inverseFactorial=[1]*(N+1)
inverseFactorial[N]=power(Factorial[N],mod-2)
for i in range(0,N)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def comb(x,y):
  if x<y or y<0:
    return 0
  else:
    return (Factorial[x]*inverseFactorial[y]*inverseFactorial[x-y])%mod

dp=[[0]*3 for i in range(N+2)]
dp[0][0]=1

for i in range(N+1):
  dp[i+1][0]=comb(N-1,i+1)
  dp[i+1][1]=-comb(N-k-1,i)+2*dp[i][0]
  if i>=1:
    dp[i+1][2]=dp[i-1][0]
  print(sum(dp[i+1])%mod)


Measured memory_bytes: 99308
# -*- coding: utf-8 -*-
import heapq

n = int(input())
al = list(map(int, input().split()))
q = al[:n]
heapq.heapify(q)

s = sum(al[:n])
ll = [s]
for i in range(n,2*n):
    a = al[i]
    s += a
    a = heapq.heappushpop(q, a)
    s -= a
    ll.append(s)

s = 0
q = []
heapq.heapify(q)
for i in range(2*n, 3*n):
    s -= al[i]
    heapq.heappush(q, -al[i])

rl = [-s]
for i in range(2*n-1,n-1,-1):
    a = al[i]
    s += -a
    a = heapq.heappushpop(q, -a)
    s -= a
    rl.append(-s)
rl.reverse()

res = ll[0]-rl[0]
for i in range(1,n+1):
    res = max(res, ll[i]-rl[i])

print(res)


Measured memory_bytes: 38148