akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    ll sum = 0;
    rep(i, 1, N + 1) {
        if(i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <utility>
#define REP(i, n) for (int i = 0; i < (n); i++)
    using namespace std;

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

        string s; cin >> s;
    int q; cin >> q;
    string t;

    REP(i, q) {
        int type;
        cin >> type;
        if (type == 1) swap(s, t);
        else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) t += c;
            else s += c;
        }
    }

    reverse(t.begin(), t.end());
    cout << t << s << '\n';
    return 0;
}


Measured memory_bytes: 980
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

bool dp[110000];//dp[i]=残りi個で先手が勝てるかどうか

int main(){cout<<fixed<<setprecision(20);
		   int n,k;
           cin>>n>>k;
           vin a(n);
           rep(i,0,n)cin>>a[i];
           rep(i,1,k+1){
            rep(j,0,n)if(i-a[j]>=0) dp[i]=dp[i]| !dp[i-a[j]];
           }
           if(dp[k])cout<<"First"<<endl;
           else cout<<"Second"<<endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,ans=0;
    cin >> n;
    vector<ll> a(n);
    ll total=0;
    rep(i,n){
        cin >> a[i];
        total+=a[i];
    }
    
    rep(i,n){
        total-=a[i];
        ans+=a[i]*(total%mod)%mod;
        ans=ans%mod;
    }
    
    cout << ans << endl;

    return 0;
}











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

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

	int n[200][3];
	int m[200][3];

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

	for (int i=0; i<N; i++) {
		m[i][0] = n[i][0];
		m[i][1] = n[i][1];
		m[i][2] = n[i][2];
	}

	for (int h=0; h<3; h++) {
		for (int i=0; i<N; i++) {

			for (int j=0; j<N; j++) {
				if (n[i][h] == n[j][h] && i != j) {
					m[i][h]	= 0;		
				}
			}
		}
	}

	for (int i=0; i<N; i++) {
		cout << m[i][0] + m[i][1] + m[i][2] << endl;
	}

	return 0;
}



Measured memory_bytes: 3044
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
for i in range(q):
    tempb,tempc=map(int,input().split())
    b.append(tempb)
    c.append(tempc)
cnt=[-1]+[0]*10**5
for i in range(n):
    cnt[a[i]]+=1
ans=sum(a)
for i in range(q):
    ans+=(c[i]-b[i])*cnt[b[i]]
    cnt[c[i]]+=cnt[b[i]]
    cnt[b[i]]=0
    print(ans)

Measured memory_bytes: 22916
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]
print(ans)


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  string N;
  cin >> N;
  
  if(N.at(0) == N.at(2)) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
var
	s:array[0..2]of String[100];
	c:array[0..2]of Longint;
	f,i:Longint;
begin
	for i:=0 to 2 do begin
		readln(s[i]);
		c[i]:=1;
	end;
	while c[f]<=length(s[f])do begin
		inc(c[f]);
		f:=ord(s[f][c[f]-1])-97;
	end;
	write(chr(f+65));
end.


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
char a[55],b[55],c[105];
int main(){
	int len1,len2,k=0,min=0,max=0;
	while(scanf("%s %s",&a,&b)!=EOF){
		k=0;memset(c,0,sizeof(c));min=0;max=0;
		len1=strlen(a);
		len2=strlen(b);
		if(len1==len2){
			for(int i=0;i<len2;i++){
				c[k]=a[i];
				k++;
				c[k]=b[i];
				k++;
			}
			for(int i=0;i<k;i++){
			printf("%c",c[i]);
		}
		}
		else{
			for(int i=0;i<len1;i++){
				c[k]=a[i];
				k++;
				c[k]=b[i];
				k++;
			}
			c[k]=a[len1-1];
		for(int i=0;i<k-1;i++){
			printf("%c",c[i]);
		}
		}	
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main() {
	long long int n,t,i;
	while(0<=scanf("%lld%*c",&n)){
		if(n==0)
			break;
		t=0;
		for(i=1;(long long int)pow(5,i)<=n;i++){
			if(n/(long long int)pow(5,i)>=1){
				t+=(long long int)(n/((long long int)pow(5,i)));
			}
		}
		printf("%lld\n",t);
	}
	return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]
def cands(N):
    if N ==1:
        return range(10)
    else:
        return range(10 ** (N-1), 10 **N)

def main(N, sc):
    nums = cands(N)
    for n in nums:
        try:
            for s,c in sc:
                assert(int(str(n)[s-1]) == c)
        except AssertionError as e:
            continue
        return n
    else:
        return -1
print(main(N, sc))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

// int MOD = 998244353;
int MOD = 1000000007;

int a[500][500] = {0};

void solve(int l,int r,int d){
    if(abs(l-r) == 1)return;
    int mid = (l+r)/2;
    for(int i = l;i < mid;i++){
        for(int j = mid;j < r;j++){
            a[i][j] = a[j][i] = d;
        }
    }
    solve(l,mid,d+1);
    solve(mid,r,d+1);
    return;
}

signed main(){
    
    ll n;
    cin >> n;
    solve(0,n,1);
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://jsc2019-qual.contest.atcoder.jp/tasks/jsc2019_qual_a
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc125.contest.atcoder.jp/tasks/abc125_a


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll A,B,K;
    cin >>A>>B>>K;
    ll t,a;
    ll z = 0;
    t = max(A-K,z);
    a = max(min(A+B-K,B),z);

    cout << t<<" "<<a << endl;


    return 0;
    

}

Measured memory_bytes: 3588
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[N][K] = sum(OPT[N-1][K-i]) 0 <= i <= A[N]
    OPT[0][0] = 1
    N*K
    3 4
    1 2 3

1 0 0 0 0
1 1 0 0 0
1 2 2 1 0
1 3 5 6 5

OPT[3][1] = OPT[2][1]+OPT[2][0]
OPT[3][2] = OPT[2][2]+OPT[2][1]+OPT[2][0]
OPT[3][3] = OPT[2][3]+OPT
    """
    N, K = read_ints()
    A = read_ints()
    modulo = 10**9+7
    OPT = [[0]*(K+1) for _ in range(N+1)]
    for i in range(N+1):
        OPT[i][0] = 1
    for j in range(K+1):
        OPT[0][j] = 1
    for i in range(1, N+1):
        for j in range(1, K+1):
            OPT[i][j] += OPT[i][j-1]+OPT[i-1][j]
            if j-A[i-1]-1 >= 0:
                OPT[i][j] -= OPT[i-1][j-A[i-1]-1]
            OPT[i][j] %= modulo
    if K == 0:
        return OPT[-1][-1]
    return (OPT[-1][-1]-OPT[-1][-2])%modulo


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 118000
n=input()
x=list(map(int, input().split()))

maxdist = x[int(n)-1]
p=int(sum(x)/len(x))
ret = 0
ret2 = 0
for i in x:
    ret = ret + (p-i)**2
    ret2 = ret2 + (p-i+1)**2
ret = ret if ret < ret2 else ret2
print(ret)

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

double average(int *points,int n){
  int i;
  double ave;
  ave=0;
  for(i=0;i<n;i++)
    ave+=*points++;
  ave/=(double)n;
  return(ave);
}

double std_diviation(int *points,int n){
  int i;
  double ave,ret;
  ret=0;
  ave=average(points,n);
  for(i=0;i<n;i++){
    ret+=(*points-ave)*(*points-ave);
    points++;
  }
  ret/=n;
  return(sqrt(ret));
}

int main(void){
  int i,n,*points;

  while(1){
    scanf("%d",&n);
    if(n>0){
      points=(int *)malloc(sizeof(int)*n);
      for(i=0;i<n;i++)
	scanf("%d",&points[i]);
      printf("%0.8lf\n",std_diviation(points,n));
      free(points);
    }
    else
      break;
  }
  
  return(0);
}

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



Measured memory_bytes: 2036
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int sums[1001];
int main()
{
	for(int i = 1; i <= 1000; ++i)
	{
		sums[i] = i + sums[i - 1];
	}
	int n, k;
	double mx = 0, tmp = 0, p[200001];
	scanf("%d%d", &n, &k);
	for(int i = 0, j; i < n; ++i)
	{
		scanf("%d", &j);
		p[i] = (double)sums[j] / j;
	}
	for(int i = 0; i < k; ++i)
	{
		tmp += p[i];
	}
	mx = max(mx, tmp);
	for(int i = k; i < n; ++i)
	{
		tmp = tmp + p[i] - p[i - k];
		mx = max(mx, tmp);
	}
	printf("%.7lf\n", mx);
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int N): par(N) {
        for(int i=0; i < N; i++) par[i] = i;
    }
    
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind tree(N);
    
    int X, Y, Z;
    for(int i=0; i<M; i++) {
        cin >> X >> Y>>Z;
        tree.unite(X-1,Y-1);
    }
    
    vector<int> vec(N);
    for(int i=0; i<N; i++) vec[i] = tree.root(i);
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    
    cout << vec.size() << endl;
    return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll x,a=100;
ll pos;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>x;
	while(1){
		pos++;
		a+=(a/100);
		if(a>=x){
			cout<<pos;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int n,k;
int p[1005];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		cin>>p[i];
	}
	sort(p+1,p+n+1);
	int ans=0;
	for(int i=1;i<=min(n,k);++i){
		ans+=p[i];
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
ll solve(ll a[],ll i,ll j,ll dp[][3005])
{
   if(i>j)
   return 0;
   if(dp[i][j]!=-1)
   return dp[i][j];
   ll op1=a[i]+min(solve(a,i+2,j,dp),solve(a,i+1,j-1,dp));
   ll op2=a[j]+min(solve(a,i+1,j-1,dp),solve(a,i,j-2,dp));
   dp[i][j]=max(op1,op2);
   return dp[i][j];
}
int main() {
    ll n;
    cin>>n;
    ll a[3005],i,s=0;
    for(i=0;i<n;i++){
    cin>>a[i];
    s+=a[i];}
    ll dp[n+5][3005];
    memset(dp,-1,sizeof(dp));
    ll y=solve(a,0,n-1,dp);
    ll w=s-y;
    cout<<(y-w)<<"\n";
	return 0;
}

Measured memory_bytes: 71040
#include<stdio.h>
int main(void){
int a,b,op;
while(1){
scanf("%d %c %d\n",&a,&op,&b);
if (op=='?') break;
if (op=='+') printf("%d\n",a+b);
if (op=='-') printf("%d\n",a-b);
if (op=='*') printf("%d\n",a*b);
if (op=='/') printf("%d\n",a/b);
}
}



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

int main(){
	int s[101][101] = {0};
	int i, j, r, c;
	
	cin >> r >> c;
	
	for(i = 0; i < r; i++){
		for(j = 0; j < c; j++){
			cin >> s[i][j];
			s[i][c] += s[i][j];
			s[r][j] += s[i][j];
		}
		s[r][c] += s[i][c];
	}
	
	for(i = 0; i < r + 1; i++){
		for(j = 0; j < c + 1; j++){
			cout << s[i][j];
			if(j != c){
				cout << " ";
			}
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
#define EPS  (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS)

// 点类
class Point {
public :
	double x, y;
	Point() {};
	Point(double x, double y) :x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(x * a, y * a); }
	Point operator / (double a) { return Point(x / a, y / a); }
	
	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};
// 线段类
class Segment {
public:
	Point p1, p2;
	Segment() {};
	Segment(Point p1, Point p2) :p1(p1), p2(p2) {};
};

#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3

class EndPoint {
public :
	Point p;
	int seg, st; // 线段的ID，端点的种类
	EndPoint() {}
	EndPoint(Point p, int seg, int st) :p(p), seg(seg), st(st) {}

	bool operator < (const EndPoint &ep) const {
		// 按y坐标升序排序
		if (p.y == ep.p.y) {
			return st < ep.st;
		}else {
			return p.y < ep.p.y;
		}
	}

};
EndPoint EP[2 * 1000010];

// 线段相交问题，曼哈顿几何
int manhattanIntersection(vector<Segment> S) {
	int n = S.size();

	for (int i = 0, k = 0; i < n; i++) {
		//调整端点p1、p2，保证左小右大
		if (S[i].p1.y == S[i].p2.y) {
			if(S[i].p1.x > S[i].p2.x)
				swap(S[i].p1, S[i].p2);
		}else if(S[i].p1.y > S[i].p2.y){
			swap(S[i].p1, S[i].p2);
		}

		// 将水平线段添加到端点列表
		if (S[i].p1.y == S[i].p2.y) {
			EP[k++] = EndPoint(S[i].p1, i, LEFT);
			EP[k++] = EndPoint(S[i].p2, i, RIGHT);
		}else { // 将垂直线段添加到端点列表
			EP[k++] = EndPoint(S[i].p1, i, BOTTOM);
			EP[k++] = EndPoint(S[i].p2, i, TOP);
		}
	}

	//按照端点的y坐标升序排序
	sort(EP, EP + (2 * n));

	set<int> BT;			// 二叉搜索树
	BT.insert(10000000001); // 设置标记
	int cnt = 0;

	for (int i = 0; i < 2 * n; i++) {
		if (EP[i].st == TOP)
			BT.erase(EP[i].p.x); //删除上端点
		else if (EP[i].st == BOTTOM)
			BT.insert(EP[i].p.x);
		else if (EP[i].st == LEFT) {
			set<int>::iterator b = BT.lower_bound(S[EP[i].seg].p1.x);
			set<int>::iterator e = BT.upper_bound(S[EP[i].seg].p2.x);

			// 加上b到e距离
			cnt += distance(b, e);
		}

	}
	return cnt;
}
int main() {
	vector<Segment> S;
	Segment seg;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf %lf %lf %lf", &seg.p1.x, &seg.p1.y, &seg.p2.x, &seg.p2.y);
		S.push_back(seg);
	}

	printf("%d\n", manhattanIntersection(S));
	return 0;
}


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

using namespace std;
typedef long long ll;

queue<pair<int, int>> pos_queue;
vector<vector<bool>> recorded;
vector<vector<int>> pos_count;

void bfs(int next_h, int next_w, int current_count) {
    if(pos_count[next_h][next_w] != INT_MAX) return;

    pos_queue.push(make_pair(next_h, next_w));
    pos_count[next_h][next_w] = current_count + 1;
}

int main(void) {
    int H, W;
    cin >> H >> W;

    vector<vector<char>> squares(H + 1, vector<char>(W + 1));

    int origin_white_num = 0;

    for(int i = 1; i <= H; i++) {
        string line_str;
        cin >> line_str;

        for(int j = 0; j < line_str.length(); j++) {
            char current_c = line_str[j];

            if(current_c == '.') origin_white_num++;

            squares[i][j + 1] = current_c;
        }
    }

    pos_queue.push(make_pair(1, 1));

    recorded.assign(H + 1, vector<bool>(W + 1, false));
    pos_count.assign(H + 1, vector<int>(W + 1, INT_MAX));
    pos_count[1][1] = 0;

    while(!pos_queue.empty()) {
        auto current_pos = pos_queue.front();
        pos_queue.pop();

        int current_h = current_pos.first;
        int current_w = current_pos.second;

        recorded[current_h][current_w] = true;

        int current_count = pos_count[current_h][current_w];

        if(current_h > 1 && squares[current_h - 1][current_w] == '.') bfs(current_h - 1, current_w, current_count);
        if(current_w < W && squares[current_h][current_w + 1] == '.') bfs(current_h, current_w + 1, current_count);
        if(current_h < H && squares[current_h + 1][current_w] == '.') bfs(current_h + 1, current_w, current_count);
        if(current_w > 1 && squares[current_h][current_w - 1] == '.') bfs(current_h, current_w - 1, current_count);
    }

    if(pos_count[H][W] == INT_MAX) cout << -1 << endl;
    else cout << origin_white_num - pos_count[H][W] - 1 << endl;
    
    return 0;
}

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




int main() {
	int N, K,ave,tmp;
	cin >> N >> K;
	ave = K / 2;
	int ans = 0;
	rep(i, N) {
		cin >> tmp;
		if (tmp<=ave)
		{
			ans += 2 * tmp;
		}
		else if (tmp>ave)
		{
			ans += (K - tmp) * 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

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

		int n = sc.nextInt();
		int oddCount = 0;
		for (int i = 1; i <= n; i++) {
			int ai = sc.nextInt();
			if (i % 2 == 1) {
				if (ai % 2 == 1) {
					oddCount++;
				}
			}
		}
		sc.close();

		System.out.println(oddCount);

	}
}


Measured memory_bytes: 27152
#include <iostream>
#include <algorithm>
#include <vector>
#define N 1000000
#define INFINITY 2000000000
using namespace std;
int DP(int);
int DP2(int);
int m=1,m2=1;
int dp[N],dp2[N],data[N];
vector<int> data2;
int main(){
  int i,out,out2,n,c;
  data2.push_back(0);
  for(i=1;i<N;i++){
    data[i]=i*(i+1)*(i+2)/6;
    if(data[i]>N){
      c=i;
    }
    if(data[i]%2==1){
      data2.push_back(data[i]);
    }
  }
  while(1){
    cin >> n;
    if(n==0) break;
    out=DP(n);
    out2=DP2(n);
    cout << out << ' ' << out2 << endl;
  }
  return 0;
}
int DP(int n){
  int i,j,s;
  for(i=1;i<N;i++){
    if(data[i]>n){
      s=i-1;
      break;
    }
  }
  if(s>=m){
    m=s;
    for(i=0;i<=n;i++) dp[i]=INFINITY;
    dp[0]=0;
    for(i=1;i<=s;i++){
      for(j=data[i];j<=n;j++){
	dp[j]=min(dp[j],dp[j-data[i]]+1);
      }
    }
  }
  return dp[n];
}
int DP2(int n){
  int i,j,s,len;
  len=data2.size();
  for(i=1;i<len;i++){
    if(data2[i]>n){
      s=i-1;
      break;
    }
  }
  if(s>=m2){
    m2=s;
    for(i=0;i<=n;i++) dp2[i]=INFINITY;
    dp2[0]=0;
    for(i=1;i<=s;i++){
      for(j=data2[i];j<=n;j++){
	dp2[j]=min(dp2[j],dp2[j-data2[i]]+1);
      }
    }
  }
  return dp2[n];
}

Measured memory_bytes: 13516
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int ans=0;
    for (int i=0;i<4;i++) {
      if (s.charAt(i)=='+') {
        ans++;
      }else{
        ans--;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
#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 pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

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

void solve()
{
    map<pair<int, int>, int>ans;
    set<pair<int, int>>sol;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        string s = to_string(i);
        int f = s[0] - '0';
        int l = s[s.size() - 1] - '0';
        ans[ {f, l}]++;
    }
    int solution = 0;
    for (int i = 10; i <= n; i++)
    {
        string s = to_string(i);
        int f = s[0] - '0';
        int l = s[s.size() - 1] - '0';
        if (f == l)
        {
            solution += 1;
        }
        solution += ans[ {l, f}];
        //cout << i << " " << f << " " << l << " " << ans[ {l, f}] << endl;
    }
    for (int i = 1; i <= 9 && i <= n; i++)
        solution++;
    cout << solution;
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; i+j <= n; j++ {
			k := n - i - j
			if 10000*i+5000*j+1000*k == y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#include<vector>
#include<cstdint>
#include<limits>
#include<queue>
#include<cstdio>

using to_t = std::size_t;
using ll = std::int64_t;

struct node {
    to_t to;
};
using graph = std::vector<std::vector<node>>;

graph add_orientation(const graph &g, const to_t e=0){
    graph h(g.size());
    std::queue<to_t> qu;
    std::vector<bool> is_visited(g.size(),false);
    qu.push(e);
    is_visited[e]=true;
    while(!qu.empty()){
        to_t a=qu.front();
        qu.pop();
        for(auto &v:g[a]){
            if(!is_visited[v.to]){
                is_visited[v.to]=true;
                h[a].push_back(v);
                qu.push(v.to);
            }
        }
    }
    return h;
}

ll ext_gcd(ll a,ll b,ll &x,ll &y){
    //b==0ならa*1+b*0=a
    if(b==0){x=1;y=0;return a;}
    ll q=a/b, g=ext_gcd(b,a-q*b,x,y), z=x-q*y;
    x=y; y=z;
    return g;
}

ll inv(ll a,ll p){
    ll x,y;
    ext_gcd(a,p,x,y);
    return (x+p)%p;
}

//x[i]=i*(i-1)*...*2*1
void make_factorial(ll *x, int len, ll p){
    x[0]=1;
    for(int i=1;i<len;i++)x[i]=(x[i-1]*i)%p;
}

ll npr(ll n,ll r,ll *fct,ll p){
    if(n<0||n<r||r<0)return 0;
    return fct[n]*inv(fct[n-r],p)%p;
}

ll fct[100000];
constexpr ll p=1e9+7;

int main(){
    //input
    int n,k;
    scanf("%d%d",&n,&k);
    graph g(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a-1].push_back({(b-1)});
        g[b-1].push_back({(a-1)});
    }
    auto g_add=add_orientation(g);
    make_factorial(fct,100000,p);
    //根から順番に決める
    std::queue<to_t> qu;
    //根の塗り方はk通り
    ll ans=k;
    //根に直でつながっている子はg_add[0].size()個で、それらは根と異なる色(k-1通り)を塗る
    for(auto &i:g_add[0]){
        qu.push(i.to);
    }
    ans=ans*npr(k-1,g_add[0].size(),fct,p)%p;
    //そのほかは、g_add[i].size()個の子に、自分ともその親とも異なる色(k-2通り)を塗る
    while(!qu.empty()){
        auto i=qu.front();
        qu.pop();
        for(auto &j:g_add[i]){
            qu.push(j.to);
        }
        ans=(ans*npr(k-2,g_add[i].size(),fct,p))%p;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 12032
// Problem : C - Digits in Multiplication
// Contest : AtCoder - AtCoder Beginner Contest 057
// URL : https://atcoder.jp/contests/abc057/tasks/abc057_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#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;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
inline int digits(ll i)
{
	int count=0;
	while(i>0)
	{
		i=i/10;
		count++;
	}
	return count;
}
ll n;
inline void factors(ll n)
{	
	int ans=INT_MAX;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		ans=min(ans,max(digits(i),digits(n/i)));
	}
	cout<<ans<<nl;	
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	cin>>n;
	factors(n);
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 1;i<n;++i)
using ll = long long;
using P = pair<int,int>;

int main(){
  ll x,y;
  cin >> x >> y;
  if(x % y == 0){
    puts("-1");
    return 0;
  }
  rep(i,100000){
    if(x*i % y != 0){
      cout << x*i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

 

int main()

{

    int W, H, x, y, r;

 

    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

 

    if( ((x - r) >= 0 && W >= (x + r)) && ((y - r) >= 0 && H >= (y + r)) )

    {

        printf("Yes\n");

    }

    else

    {

        printf("No\n");

    }

     

 

    return 0;

}

Measured memory_bytes: 584
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
	for(int i =g; i<n; i++){
		int v = A[i];
		int j = i- g;
		while(j >= 0 && A[j] > v){
			A[j+g] = A[j];
			j = j -g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n){
	for(int h=1;;){
		if(h>n) break;
		G.push_back(h);
		h = 3*h+1;
	}
	
	for(int i = G.size()-1; i>=0; i--){
		insertionSort(A, n, G[i]);
	}
}

int main(){
	cin >> n;
	for(int i=0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;
	
	shellSort(A,n);

	cout << G.size() << endl;
	for(int i = G.size()-1; i >=0; i--){
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for(int i=0; i < n ;i++) printf("%d\n", A[i]);
	return 0;
}





Measured memory_bytes: 7168
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,k = gi
d = gi

loop{
	s = n.to_s.split("").map(&:to_i)
	jd = true
	s.each do |ss|
		if d.include? ss
			jd = false
			break
		end
	end
	if jd
		break
	else
		n += 1
	end
}

puts n

Measured memory_bytes: 2812
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
vector< pair<ll , ll > > v[123456];
ll k ;
void dijkartas(ll src)
{
    priority_queue<pair<ll,ll> , vector<pair<ll,ll> > , greater<pair<ll,ll> > > pq ;
    vector<ll> dist(k+10 , 3e18);
    pq.push({0,src});
    dist[src] = 0 ;
    while(!pq.empty()){
        ll u = pq.top().second;
        pq.pop();
        for(auto &child:v[u]){
            ll v=child.first ;
            ll w = child.second ;
            if(dist[v] > dist[u] + w){
                dist[v] = dist[u] + w ;
                pq.push({dist[v] , v});
            }
        }
    }
    cout << 1 + dist[0] << el ;
}
int main()
{
    ios;
    cin >> k ;
    forn(i , 1 , k ){
       ll from = i%k ;
       ll to = (i+1)%k;
       ll w = 1 ;
       v[from].pb({to , 1});
    }
    forn(i , 1 , k ) {
       ll from = (i)%k ;
       ll to = (10*i) %k ;
       v[from].pb({to,0});
    }
    dijkartas(1);

}

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

public class Main implements Runnable{
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int[] a = fs.nextIntArray(n);
		long res = Long.MAX_VALUE;
		for(int num = -200; num <= 200; num++) {
			long ret = 0;
			for(int i = 0; i < n; i++) {
				long diff = a[i] - num;
				ret += diff*diff;
			}
			res = Math.min(res, ret);
		}
		out.println(res);
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 24916
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int n;
vint v;
vint tt;
vint used;
bool f=false;
int cnt=0;
int foo(int x);
int foo2(int c,int x,int y){
	if(c==0){
		return foo(x+1);
	}
	if(y>=n){
		return 0;
	}
	int ret=0;
	reep(i,y,n){
		if(v[i]<=c&&used[i]==0){
			used[i]=1;
			++cnt;
			if(foo2(c-v[i],x,i+1)&&cnt==n){
				return 1;
			}
			used[i]=0;
			--cnt;
		}
	}
	return 0;
}
int foo(int x){
	if(x==n){
		return 1;
	}
	if(used[x]==0) return 0;
	if(used[x]==2) return foo(x+1);
	int ret=0;
	used[x]=2;
	if(foo2(v[x],x,x+1)) return 1;
	used[x]=1;
	return foo(x+1);
}
void mainmain(){
	while(cin>>n,n){
		v=vint(n);
		rep(i,n){
			cin>>v[i];
		}
		sort(ALL(v));
		reverse(ALL(v));
		tt=vint(n,0);
		used=vint(n,0);
		// rep(i,n) cout<<used[i]<<" ";
		// cout<<endl;
		used[0]=1;
		tt[0]=v[0];
		cnt=1;
		if(foo(0)) cout<<"YES\n";
		else cout<<"NO\n";
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1180
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string S;
  cin >> S;
  ll ans = 754;

  for (ll i = 0; i < S.size() - 1; i++) {
    const string s = S.substr(i, 3);
    const int num = stoi(s);
    const ll sa = abs(num - 753);
    ans = min(sa, ans);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  int ans[h][w];
  char mp[h][w];
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      ans[i][j] = -1;
      cin>>mp[i][j];
      if(mp[i][j] == 'c')ans[i][j] = 0;
    }
  }
  for(int _ = 0; w > _; _++){
    for(int i = 0; h > i; i++){
      for(int j = w-1; 0 < j; j--){
        if(mp[i][j-1] == 'c'){
          mp[i][j] = 'c';
          if(ans[i][j] == -1) ans[i][j] = _+1;
        }
      }
    }
  }
  for(int i = 0; h > i; i++){
    for(int j = 0;w > j; j++){
      cout << ans[i][j];
      if(j+1!=w)cout << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 3124
taps = gets.chomp.split('')

odds = 'RUD'.split('')
evens = 'LUD'.split('')

res = true

taps.each_with_index do |i, idx|
    cnt = idx + 1
    if cnt.even?
        res = false unless evens.include?(i)
    else
        res = false unless odds.include?(i)
    end
end


puts res ? "Yes" : "No"

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

int main() {
  int N,K,X,Y,ans=0;
  cin>>N>>K>>X>>Y;
  for(int i=0;i<N;i++){
  	if(i<K) ans+=X;
    else ans+=Y;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int alicePoints = 0;
	int bobPoints = 0;
	
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a.at(i);
	
	sort( a.begin(), a.end(), greater<int>() ); // 降順にソート

	for (int i = 0; i < N; i++) {
		
		if (i % 2 == 0) {
			alicePoints += a.at(i);
		}
		else {
			bobPoints += a.at(i);
		}

	}
	
	cout << alicePoints - bobPoints << endl;
	return 0;
}

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

#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<"\n"
#define prints(a) for(auto i: a) cout<<i<<" "; cout<<"\n"
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e]

int main()
{
	fastio;
	int a[5];
	read(a, 5);
	for(int i=0; i<5; i++){
		if(a[i]==0)
			cout<<i+1<<"\n";
	}

	return 0;
}


Measured memory_bytes: 3652
from fractions import gcd
n,k = map(int,input().split())

def process(a,b):
	if a%b == 0:
		return 0
	a = a%b

	for i in range(100000):
		a = min(a,abs(a-b))
	return a
if n == 0:
	print(0)
elif n ==1:
	if k == 1:
		print(0)
	else:
		print(1)
elif k == 1:
	print(0)
else:
	print(process(n,k))



Measured memory_bytes: 5472
#include<cstdio>

int n;
int a, b;

bool chk_y(int x) {
	return true;
}

bool chk_m(int x) {
	return 1<=x && x<=12;
}

int main() {
	scanf("%d", &n);
	
	a = n/100; b = n%100;
	bool yymm = chk_y(a) && chk_m(b);
	bool mmyy = chk_m(a) && chk_y(b);
	
	if (yymm && mmyy) puts("AMBIGUOUS");
	else
	if (!yymm && !mmyy) puts("NA");
	else
	if (yymm) puts("YYMM");
	else puts("MMYY");
	
	return 0;
}

Measured memory_bytes: 128
import heapq

N, M = map(int, input().split()) # N個の駒、M個の地点
X = list( map(int, input().split())) #駒の座標


if N >= M:
    ans = 0
else:
    X.sort()
    distance = [0] * (M-1)
    for i in range(M-1):
        distance[i] = -abs(X[i+1] - X[i])

    sum_distance = sum(distance)
    heapq.heapify(distance)

    count = 0 
    for _ in range(N-1):
        max_num = heapq.heappop(distance)
        count += max_num

    ans = abs(sum_distance - count)

print(ans)


Measured memory_bytes: 20668
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	string s; cin >> s;
	string t;
	vi d(q);
	REP(i, q) {
		char a, b; cin >> a >> b;
		t += a;
		if (b == 'R')d[i] = 1;
		else d[i] = -1;
	}

	auto check = [&](int p) {
		char c = s[p];
		int pos = p;
		REP(i, q) {
			if (t[i] == c) {
				pos += d[i];
			
				if (pos == -1)return -1;
				if (pos == n)return 1;
				c = s[pos];
			}
		}
		return 0;
	};
	int a = check(0), b = check(n - 1);
	if (a == 0 && b == 0) {
		cout << n << endl;
	}
	else if (a == 0) {
		int l = 0, r = n;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (check(mid) == 0)l = mid;
			else r = mid;
		}
		cout << n - l - 1 << endl;
	}
	else if (b == 0) {
		int l = 0, r = n;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (check(mid) == 0) r = mid;
			else l = mid;
		}
		cout << n - r << endl;
	}
	else {
		int l = 0, r = n;
		int m = -1;
		while (r - l > 1) {
			
			int mid = (r + l) / 2;
			int c = check(mid);
			if (c == 0) {
				m = mid;
				break;
			}
			else if (c == 1) {
				r = mid;
			}
			else {
				l = mid;
			}
		}
		if (m == -1) {
			cout << 0 << endl;
			return 0;
		}
		int res = n;
		l = 0, r = m;
		while (r - l > 1) {

			int mid = (r + l) / 2;
			int c = check(mid);
			if (c == 0) r = mid;
			else l = mid;
		}
		res -= r;
		l = m, r = n;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			int c = check(mid);
			if (c == 0) l = mid;
			else r = mid;
		}
		res -= n - r;
		cout << res << endl;
	}



}

Measured memory_bytes: 1684
N = int(input())
A = list(map(int,input().split()))
L = [0]*100001
s = sum(A)
for a in A:
    L[a] += 1 #数字のカウント
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    s += L[B]*(C-B) #合計値の変化
    L[C] += L[B] 
    L[B] = 0 #Bの値の数だけCに移す
    print(s)


Measured memory_bytes: 21052
num_list = list(map(int,input().split()))
max_num = max(num_list)
f_max = 0
sum_result = 0
for i in num_list:
	if i == max_num and f_max == 0:
		sum_result = sum_result + 10 * i
		f_max = 1
	else:
		sum_result = sum_result + i
		
print(sum_result)

Measured memory_bytes: 2940
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,b*d,a*d,b*c})<<endl;
    return 0;
}

Measured memory_bytes: 3644