akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<Integer> list = new ArrayList<Integer>();
        for(int tmp = 0; tmp<n; tmp++){
            int w = sc.nextInt();
            list.add(w);
        }

        long min = Integer.MAX_VALUE;
        for(int tmp =1; tmp<n ;tmp++){
            long before = 0;
            long after =0;
            for(int tmp2 = 0; tmp2 < n ; tmp2++){
                if(tmp2 < tmp){
                    before += list.get(tmp2);

                }else{
                    after += list.get(tmp2);
                }
            }
            if(min > Math.abs(before - after)){
                min = Math.abs(before - after);
            }
        }


        System.out.println(min);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int min (int a, int b){
    return (a<b) ? a : b ;
}

int main() {

    int x,n ;
    cin >> x >> n ;
    int p[n] ;

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

    int ans = INF ;
    int o ;
    bool q = true ;
    for (int  i = -300; i <= 300; i++)
    {
         for (int j = 0; j < n; j++)
         {
            if(i==p[j]){
                q = false ;
                break ;
            }
         }
        if(q){
          int tmp = abs(i-x) ;
          if(ans!=min(tmp,ans)) o = i ;
          ans = min(tmp,ans) ;
        }else{
          q = true ;
          continue ;
        }
          q = true ;
    }
    
       cout << o << endl ;
       return 0; 
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>

using namespace std;

#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}


int M,T,P,R;
int a[105][12];
bool ac[105][12];
int pe[105];

struct data{
	int sol,pe,idx;
	data(int A,int B,int C){
		sol=A;
		pe=B;
		idx=C;
	}
};
bool sf(data a,data b){
	if(a.sol==b.sol){
		if(a.pe==b.pe)return a.idx>b.idx;
		return a.pe<b.pe;
	}return a.sol>b.sol;
}
vector<data> v;

int main(){

	while(cin>>M>>T>>P>>R,M){
		memset(a,0,sizeof(a));
		memset(ac,0,sizeof(ac));
		memset(pe,0,sizeof(pe));

		for(int i=0;i<R;i++){
			int m,t,p,r;
			scanf("%d%d%d%d",&m,&t,&p,&r);

			if(ac[t][p])continue;

			if(r==0){
				ac[t][p]=1;
				pe[t]+=m;
				pe[t]+= 20*a[t][p];
			}else a[t][p]++;
		}

		v.clear();
		for(int i=1;i<=T;i++){
			int cnt=0;
			for(int k=1;k<=P;k++)if(ac[i][k])cnt++;
			v.pb( data(cnt,pe[i],i) );
		}
		sort(ALL(v),sf);

		printf("%d",v[0].idx);
		for(int i=1;i<v.size();i++){
			if(v[i-1].sol== v[i].sol && v[i-1].pe==v[i].pe)printf("=");
			else printf(",");
			printf("%d",v[i].idx);
		}
		puts("");
	}

}

Measured memory_bytes: 1244
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
        long v = sc.nextLong();
		long b = sc.nextLong();
        long w = sc.nextLong();
        long t = sc.nextLong();
        long r = Math.max(a-b,b-a);
        if(t*(v-w)>=r){System.out.println("YES");}
		else{System.out.println("NO");}
	}
}


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

#include<string>
#include<vector>
std::string minus2(long long n) {
  std::vector<long long> memo_power = {1, 2}, memo_sum = {1, 2};
  auto power = [&](int i) {
    if(i < 0) return 0ll;
    while(int(memo_power.size()) <= i) memo_power.emplace_back(memo_power.back() << 1);
    return memo_power[i];
  };
  auto sum = [&](int i) {
    if(i < 0) return 0ll;
    while(int(memo_sum.size()) <= i) memo_sum.emplace_back(memo_sum[memo_sum.size() - 2] + power(memo_sum.size()));
    return memo_sum[i];
  };
  if(n == 0) return "0";
  auto i = 0;
  long long l = 0, r = 1;
  while(!(l <= n && n <= r)) {
    if(i & 1) l = -sum(i++);
    else      r = sum(i++);
  }
  std::string res = "";
  while(i--) {
    if(i & 1) {
      l = -sum(i - 2);
      auto nex = n + power(i);
      if(l <= nex && nex <= r) {
        res += "1";
        n = nex;
      } else {
        res += "0";
      }
    } else {
      r = sum(i - 2);
      auto nex = n - power(i);
      if(l <= nex && nex <= r) {
        res += "1";
        n = nex;
      } else {
        res += "0";
      }
    }
  }
  return res;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  cout << minus2(N) << endl;
}


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

int main()
{
    int n, k;
    cin >> n;

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

    sort(distance, distance + n);

    int b;

    b = distance[n/2];

    ll ans = 0; ll ans2 = 0;

    for (int i = 0; i < n; i++)
    {
        ans += abs(distance[i] - b);
    }

    b = distance[n/2 + 1];

    for (int i = 0; i < n; i++)
    {
        ans2 += abs(distance[i] - b);
    }

    if (n % 2 == 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << min(ans, ans2) << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=1010;
LL gi() {
	LL w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=1e9+7;
bool o[N][N];
inline int qpow(int x,LL y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}
struct M{ int a[3][3]; };
inline M operator * (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			for (int k=0;k<3;k++)
				ans.a[i][j]=(ans.a[i][j]+1LL*a.a[i][k]*b.a[k][j])%mod;
	return ans;
}
int main()
{
	int n=gi(),m=gi(),i,j,A=0,B=0,C=0;LL k=gi();
	char c;
	bool t1=false,t2=false;
	if (!m) return puts("1"),0;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;A+=o[i][j++]=c=='#')
			while ((c=getchar())!='.'&&c!='#');
	for (i=1;i<=n;i++) if (o[i][1]&&o[i][m]) t1=true,C++;
	for (j=1;j<=m;j++) if (o[1][j]&&o[n][j]) t2=true,C++;
	if (t1&&t2) return puts("1"),0;
	if (!t1&&!t2) return printf("%d\n",qpow(A,k-1)),0;
	if (t1)
		for (i=1;i<=n;i++)
			for (j=1;j<m;j++)
				B+=o[i][j]&&o[i][j+1];
	else
		for (i=1;i<n;i++)
			for (j=1;j<=m;j++)
				B+=o[i][j]&&o[i+1][j];
	M ans={},trans={};
	ans.a[0][0]=1,ans.a[0][1]=0,ans.a[0][2]=1;
	trans.a[0][0]=A;trans.a[1][1]=A;
	trans.a[2][1]=B;
	trans.a[2][2]=C;
	for (--k;k;k>>=1) {
		if (k&1) ans=ans*trans;
		trans=trans*trans;
	}
	printf("%d\n",(ans.a[0][0]-ans.a[0][1]+mod)%mod);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 string s;
 int n=0;
 cin >> s;
 for(int i=0;i<3;i++){
     if(s[i]=='1'){
         n++;
     }
 }
cout << n << endl;
return 0;
}

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

typedef struct{
	char suit;
	int num;
}Card;

void merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int i, j, k;
    Card L[n1+1], R[n2+1];

    for(int i = 0; i < n1; i++)
        L[i] = A[left + i];
    for(int i = 0; i < n2; i++)
        R[i] = A[mid + i];
    L[n1].num = R[n2].num = INT_MAX;

    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i].num <= R[j].num) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(Card A[], int p, int r){
	int x = A[r].num;
	int i = p-1;
	for(int j = p; j < r; j++){
		if(A[j].num <= x){
			i++;
			swap(A[i], A[j]);
		}
	}
	i++;
	swap(A[i], A[r]);
	return i;
}

void quickSort(Card A[], int p, int r){
	if(p < r){
		int q = partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}

int main(){
	int n;
	cin >> n;
	Card Q[n], M[n];
	map<int, string> m;
	r(i, n){
		cin >> M[i].suit >> M[i].num;
		Q[i] = M[i];

	}
	quickSort(Q, 0, n-1);
	mergeSort(M, 0, n);

	bool isStable = true;
	r(i, n){
		if(Q[i].suit != M[i].suit){
			isStable = false;
			break;
		}
	}
	printf(isStable ? "Stable\n" : "Not stable\n");
	r(i, n){
		cout << Q[i].suit << ' ' << Q[i].num << endl;
	}
	return 0;
}


Measured memory_bytes: 5460
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc(int a, int b, int flg){
  if(a == 0 && b == 0) return -1;
  if(a == 0) return 0;
  if(b == 0) return 1;
  if(flg == -1) return 0;
  if(flg == 2) return a < b;
  return flg;
}

int main(){
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  vector<char> ans;
  rep(i, n){
    int pa, pb, flg;
    if(s.at(i) == "AB"){
      pa = a;
      pb = b;
    }else if(s.at(i) == "AC"){
      pa = a;
      pb = c;
    }else{
      pa = b;
      pb = c;
    }
    if(i == n-1){
      flg = -1;
    }else if(s.at(i) == "AB"){
      if(s.at(i+1) == "AB") flg = 2;
      else if(s.at(i+1) == "AC") flg = 0;
      else flg = 1;
    }else if(s.at(i) == "AC"){
      if(s.at(i+1) == "AC") flg = 2;
      else if(s.at(i+1) == "AB") flg = 0;
      else flg = 1;
    }else{
      if(s.at(i+1) == "BC") flg = 2;
      else if(s.at(i+1) == "AB") flg = 0;
      else flg = 1;
    }
    int rs = fc(pa, pb, flg);
    if(rs == -1){
      cout << "No" << endl;
      return 0;
    }
    char pl = s.at(i).at(rs), mi = s.at(i).at(1-rs);
    ans.push_back(pl);
    if(pl == 'A') a++;
    if(pl == 'B') b++;
    if(pl == 'C') c++;
    if(mi == 'A') a--;
    if(mi == 'B') b--;
    if(mi == 'C') c--;
    // cerr << a << " " << b << " " << c << endl;
  }
  cout << "Yes" << endl;
  for(auto c : ans){
    cout << c << endl;
  }
  return 0;
}

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

int n, k;
int a[105];
bool w[100005];
int main(){
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 0; i <= 100000; i++){
		for (int j = 1; j <= n && i + a[j] <= 100000; j++){
			w[i + a[j]] |= (w[i] ^ 1);
		}
	}
	cout << (w[k] ? "First\n" : "Second\n");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

int main() {
	int a[3],ans = 0;
	REP(i, 3) cin >> a[i];
	sort(a, a + 3);
	if (a[0] % 2 == a[1] % 2) {
		ans = ((a[2] - a[0]) / 2) + ((a[2] - a[1]) / 2) + (a[2] - a[0]) % 2;
	}
	else {
		ans = ((a[2] - a[0]) / 2) + ((a[2] - a[1]) / 2) + 2;
	}
	cout << ans << endl;
}
	


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N;cin>>N;
    vector<int>V[3];
    set<int>S[3];
    for(int i=0;i<3;i++){
        int s,t;
        cin>>s;
        while(s--){
            cin>>t;
            V[i].push_back(t);
            S[i].insert(t);
        }
    }
    int cnt=0;
    for(int i=0;i<V[2].size();i++){
        if(S[0].find(V[2][i])==S[0].end()){
            cnt++;continue;
        }
        if(S[1].find(V[2][i])!=S[1].end())cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3164
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, cc;
	cin >> n >> cc;
	vector<pair<pair<int, int>, int> > v;
	for(int i = 0; i < n; i++){
		int s, t, c;
		cin >> s >> t >> c;
		v.push_back(make_pair(make_pair(s, t), c));
	}
	sort(v.begin(), v.end());
	vector<pair<int, int> > videos;
	videos.push_back(make_pair((v[0].first).second, v[0].second));
	for(int i = 0; i < v.size(); i++){
		int s = (v[i].first).first;
		int t = (v[i].first).second;
		int c = v[i].second;
		for(int j = 0; j < videos.size(); j++){
			if(videos[j].first < s || c == videos[j].second){
				videos[j] = make_pair(t, c);
				break;
			} else if(j == videos.size() - 1){
				videos.push_back(make_pair(t, c));
				break;
			}
		}
		sort(videos.begin(), videos.end());
	}
	cout << videos.size() << endl;
}

Measured memory_bytes: 1912
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll f[111][2];
int i,j,k,n,a[111];
int main(){
	scanf("%d",&n);memset(f,0,sizeof(f));
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1,f[0][0]=1;i<=n;i++)
	 for (j=a[i]-1;j<=a[i]+1;j++) f[i][1]+=f[i-1][1],f[i][1-(j&1)]+=f[i-1][0];
	printf("%lld\n",f[n][1]);
	return 0;
}

Measured memory_bytes: 128
#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; }
struct UnionFind {
	std::vector<int> par;
	std::vector<int> sizes;

	UnionFind(int n) {
		par.resize(n);
		sizes.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			sizes[i] = 1;
		}
	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

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

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return;
		if (sizes[x] < sizes[y]) std::swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
	}
	int size(int x) {
		return sizes[root(x)];
	}
};


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

	int n;
	while (cin >> n, n) {
		vector<set<int>> v(n);
		REP(i, n) {
			int a; cin >> a;
			REP(j, a) {
				int t; cin >> t;
				v[i].insert(t);
			}
		}
		vector<UnionFind> uf(n, UnionFind(n));
		FOR(i, 1, 31) {
			vi t;
			REP(j, n) {
				if (v[j].count(i)) {
					t.push_back(j);
				}
			}
			REP(j, n) {
				vi ok;
				REP(k, t.size())if (uf[j].same(j, t[k]))ok.push_back(t[k]);
				REP(a, ok.size()) {
					REP(b, t.size()) {
						uf[j].unite(ok[a], t[b]);
					}
				}

			}
			REP(j, n) {
				bool ok = true;
				REP(k, n) {
					if (!uf[k].same(k, j))ok = false;
				}
				if (ok) {
					cout << i << endl;
					goto done;
				}
			}
		}
		cout << -1 << endl;
	done:;
	}
}


Measured memory_bytes: 3228
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
lis=[]
for i in H:
    kionn=abs(T-i*0.006-A)
    lis.append(kionn)
MIN_1=lis.index(min(lis))
print(MIN_1+1)

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 数値
		int n1 = sc.nextInt();
		long h = n1;

		int n2 = sc.nextInt();
		int n = n2;

		boolean flg = false;

		for (int i = 0; i < n; i++) {
			int n3 = sc.nextInt();
			h = h - n3;
			if (h <= 0) {
				flg = true;
				break;
			}
		}

		if (flg) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 48956
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		long l = Long.parseLong(str[1]);

		long a[] = new long[n];
		str = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		int aN = -1;

		for (int i = 0; i + 1 < n; ++i) {
			if (a[i] + a[i + 1] >= l) {
				aN = i;
				break;
			}
		}

		if (aN == -1) {
			System.out.println("Impossible");
			return;
		}

		System.out.println("Possible");
		for (int i = 0; i < aN; i++)
			System.out.println(i + 1);
		for (int i = a.length - 2; i > aN; i--)
			System.out.println(i + 1);
		System.out.println(aN + 1);
	}
}


Measured memory_bytes: 59796
<?php
$x = [];
$y = [];
$tmp = 0;
fscanf(STDIN, '%d', $cnt);
for ($i=0; $i < $cnt; $i++) { 
    fscanf(STDIN, '%d %d', $x[], $y[]);
}

for ($i=0; $i < $cnt; $i++) { 
    for ($j=$i; $j < $cnt; $j++) { 
        if ($j === $i) {
            continue;
        }
        $tmp += sqrt(pow($x[$i]-$x[$j], 2) + pow($y[$i]-$y[$j], 2));
    }
}

for ($i=0; $i < $cnt; $i++) { 
    for ($j=$i; $j < $cnt; $j++) { 
        if ($j === $i) {
            continue;
        }
        $tmp += sqrt(pow($x[$j]-$x[$i], 2) + pow($y[$j]-$y[$i], 2));
    }
}

echo $tmp/$cnt."\n";

Measured memory_bytes: 4728
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

def inverse(N, mod):
	return (pow(N, mod - 2, mod))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

#強連結成分の個数と、それぞれの頂点がどの成分に属すかを返す
def scc(N, G, Grev):
	order = []
	visit = [0] * N
	group = [None] * N #あるノードが強連結の何番目のグループに含まれるか
	def dfs(node):
		visit[node] = 1
		for i in G.graph[node]:
			if not visit[i]:
				dfs(i)
		order.append(node)

	def dfs_rev(node, num):
		group[node] = num
		visit[node] = 1
		for i in Grev.graph[node]:
			if not visit[i]:
				dfs_rev(i, num)

	#順方向のグラフ上でDFSを行い、帰りがけ順に頂点を記録
	for i in range(N):
		if not visit[i]:
			dfs(i)

	#逆方向のグラフ上で帰りが遅かった頂点から順にDFSを行い分解
	visit = [0] * N
	num = 0
	for i in reversed(order):
		if not visit[i]:
			dfs_rev(i, num)
			num += 1

	return num, group

#scc後のDAGを構築
def construct(N, G, num, group):
	DAG = [[] for i in range(num)]
	for i in range(N):
		itr = group[i]
		DAG[itr].append(i)

	return DAG

def getlist():
	return list(map(int, input().split()))


def main():
	N, M = getlist()
	G = Graph()
	Grev = Graph()
	for i in range(M):
		a, b = getlist()
		G.add_edge(a, b)
		Grev.add_edge(b, a)

	num, group = scc(N, G, Grev)

	DAG = construct(N, G, num, group)
	x = len(DAG)
	print(x)
	for i in range(x):
		print(len(DAG[i]), *DAG[i])




if __name__ == '__main__':
	main()

Measured memory_bytes: 267416
s = gets.chomp
x = y = 0
j = 4
if(s.include?("W") and !(s.include?("E")))
  j = 0
end
if(s.include?("E") and !(s.include?("W")))
  j = 0
end
if(s.include?("N") and !(s.include?("S")))
  j = 0
end
if(s.include?("S") and !(s.include?("N")))
  j = 0
end
puts (j == 4)? "Yes" : "No"

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(void) {
    constexpr double PI = 3.1415926535897932;
    double a, b, x;
    cin >> a >> b >> x;
    double h = x/a/a;
    if(h/b > 0.5) {
        cout << setprecision(15) << atan((2*(b-h))/a) * 180.0 / PI << endl;
    } else {
        cout << setprecision(15) << atan((b*b)/(2*a*h)) * 180.0 / PI << endl;
    }
    return 0;
}

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

using namespace std;
#define rep(x, n)           for (int x = 0; x < n; x++)
#define REP(x, a, b)        for (int x = a; x <= b; x++)
#define all(container)      (container).begin(), container.end()
#define rall(container)     (container).begin(), container.end()
#define sz(container)       (int) (container).size()
#define pb                  push_back
#define eb                  emplace_back

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define debug(...) 0
#endif
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
vector<vector<int>> g;
vector<int> wts,ans,LIS;
int n;
stack<pii> rem;

void dfs(int curr,int parent){
    int pos=lower_bound(all(LIS),wts[curr])-LIS.begin();
    if(pos==sz(LIS)){
        rem.push({-1,-1});
        LIS.pb(wts[curr]);
    } else{
        rem.push({pos,LIS[pos]});
        LIS[pos]=wts[curr];
    }
    ans[curr]=sz(LIS);
    for(auto& v:g[curr]){
        if(v==parent) continue;
        dfs(v,curr);
    }
    pii replace=rem.top();
    rem.pop();
    if(replace.first==-1) LIS.pop_back();
    else LIS[replace.first]=replace.second;
}

int main(void) {
    scanf("%d", &n);
    wts.resize(n);
    g.resize(n);
    ans.resize(n);
    rep(i,n) scanf("%d",&wts[i]);
    rep(i,n-1){
        int from,to;
        scanf("%d%d",&from,&to);
        --from,--to;
        g[from].pb(to);
        g[to].pb(from);
    }
    dfs(0,0);
    rep(i,n) printf("%d\n",ans[i]);    
    return 0;
}

Measured memory_bytes: 28632
#ITP1_5_C
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print('#', end = '')
            else:
                print('.', end = '')
        print()
    print()


Measured memory_bytes: 7008
N = int(input())
W = list(map(int,input().split()))
a = 9999999999999
for t in range(0,N):
    if abs(sum([W[i] for i in range(t+1)]) -  sum([W[_] for _ in range(t+1,N)])) < a:
        a = abs(sum([W[i] for i in range(t+1)]) -  sum([W[_] for _ in range(t+1,N)]))
print(a)


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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

const int mod=1000000007;
template<class T,class U>
void add(T& a,U b){
	a=((ll)a+b)%mod;
}

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

template<class T,class U>
void sub(T& a,U b){
	a=((ll)a-b%mod+mod)%mod;
}

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

template<class T,class U>
void mult(T& a,U b){
	a=((ll)a*b)%mod;
}

const ll inf=LLONG_MAX/3;
ll dp[5010][2525];
struct Interval{
	ll l,r;
};

int main(){
	int n=read();
	vector<Interval> itv;
	REP(i,n){
		int l=read(),r=read();
		itv.PB(Interval{l,r});
	}
	sort(ALL(itv),[](Interval a,Interval b){
		return a.l+a.r<b.l+b.r;
	});
	REP(i,5010)REP(j,5010)
		dp[i][j]=inf;
	dp[n][0]=0;
	for(int i=n-1;i>=0;i--){
		const int s=n-i;
		REP(p,min(s+1,2525)){
			const int q=s-p;
			if(p>0)
				chmin(dp[i][p],dp[i+1][p-1]+itv[i].r+(itv[i].l+itv[i].r)*(p-1));
			if(q>0)
				chmin(dp[i][p],dp[i+1][p]+itv[i].l+(itv[i].l+itv[i].r)*(q-1));
		}
	}
	ll ans=inf;
	auto Wafrelka=[&](int leftCount){
		vector<ll> cur(2525,inf),nx(2525);
		cur[0]=0;
		REP(i,n){
			REP(p,leftCount+1)
				chmin(ans,cur[p]+dp[i+1][leftCount-p]+itv[i].l*leftCount+itv[i].r*(n-1-leftCount));
			nx.assign(2525,inf);
			const int s=i+1;
			REP(p,min(s+1,2525)){
				const int q=s-p;
				if(p>0)
					chmin(nx[p],cur[p-1]+itv[i].r+(itv[i].l+itv[i].r)*(leftCount-p));
				if(q>0)
					chmin(nx[p],cur[p]+itv[i].l+(itv[i].l+itv[i].r)*(n-1-leftCount-q));
			}
			swap(nx,cur);
		}
	};
	if((n-1)%2==0)
		Wafrelka((n-1)/2);
	else{
		Wafrelka((n-1)/2);
		Wafrelka((n-1)/2+1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 100736
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll power(ll a, ll b){
  ll ans = 1;
  if(b%2==0){
    REP(i, b/2){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans;
  }else{
    b = b/2;
    REP(i, b){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans* a;
  }
}
int main(void){
  
  long long a;
  double b;
  cin>>a>>b;
  long long ib = b*100+0.5;
  cout<<a*ib/100<<endl;
 
  return 0;
  
}

Measured memory_bytes: 3792
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let N = parseInt(input[0][0], 10);
    let M = parseInt(input[0][1], 10);

    var uf = new UnionFind(N);
    let line;
    for (let i = 0; i < M; i++){
        line = input[i + 1].map(e => parseInt(e, 10));

        uf.union(line[0] - 1, line[1] - 1);
    }
    let ans = 0;
    for (let i = 0; i < N; i++){
        if (uf.find(i) === i) ans++;
        // console.log(i, uf.find(i));
    }
    console.log(ans);
    // console.log(uf);

}

function UnionFind (n) {
    this.parents = [];
    for (let i = 0; i < n; i++) {
        this.parents.push(-1);
    }
}

UnionFind.prototype.find = function (x) {
    if (this.parents[x] < 0) return x;
    return this.parents[x] = this.find(this.parents[x]);    
}


UnionFind.prototype.union = function (x, y) {
    x = this.find(x);
    y = this.find(y);
    if (x === y) return;
    if (this.parents[x] > this.parents[y]) [x, y] = [y, x];
    
    this.parents[x] += this.parents[y];
    this.parents[y] = x;
}


UnionFind.prototype.size = function (x) {
    x = this.find(x);
    while (x >= 0) {
        x = this.parents[x];
    }
    return x * -1;
}

// 例
// var uf = new UnionFind(5);
// uf.union(3,4);
// uf.union(1,2);
// uf.union(0,4);
// console.log(uf.find(0)); //3 (3-4-0)
// console.log(uf.size(2)); //2 (1-2)
// console.log(uf) // UnionFind { parents: [ 3, -2, 1, -3, 3 ] } //経路圧縮された各ノードの親が格納 それ自身が親の場合はその木のサイズ*-1を返す


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


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

int main(void){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long max;
  max=a*c;
  if(max<=a*d)max=a*d;
  if(max<=b*c)max=b*c;
  if(max<=b*d)max=b*d;
  cout<<max<<endl;
  
  return 0; 
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << 23 - n + 25 <<endl;
    return 0;
}


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

int main() {
    int n,ans=0;
    int h,w;
    int a,b;
    scanf("%d %d", &h,&w);
    scanf("%d %d", &a,&b);
    cout << (h-a)*(w-b) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     int ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/















bool compare(pair<int,int> p1,pair<int,int> p2){
     if(p1.fi<p2.fi)return true;
     else if(p1.fi==p2.fi&&p1.se<p2.fi)return true;
     return false;

}

int main(){
     int n;
     cin>>n;
     int res=n%1000;
    if(res!=0){
         res=1000-res;
    }
    cout<<res;
}



















































Measured memory_bytes: 3632
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n, k, q = sc.intarr()
    member = [k-q] * n
    for i in range(q):
        member[sc.intarr()[0]-1] += 1

    for i in member:
        if i > 0:
            print('Yes')
        else:
            print('No')


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
bool bo[100000] = { false };
int main(){
	int n, k, a, b;
	long long ans = 1, co = 0;
	cin >> n >> k;
	vector<vector<int>> vec(n+10);
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		vec[a].emplace_back(b);
		vec[b].emplace_back(a);
	}
	ans *= k;
	k--;
	queue<int> que;
	que.emplace(1);
	bo[1] = true;
	while (!que.empty()) {
		int k1 = k;
		for (int j = 0; j < vec[que.front()].size(); j++) {
			if (bo[vec[que.front()][j]] == false) {
				bo[vec[que.front()][j]] = true;
				que.emplace(vec[que.front()][j]);
				ans = ans * k1 % 1000000007;
				k1--;
			}
		}
		if (co < 1) {
			k--;
		}
		co++;
		que.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 6648
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << min(a,b)+min(c,d);
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    # readline = sys.stdin.readline
    readlines = sys.stdin.readlines
    H, N = map(int, input().split())
    M = [tuple(map(int, s.split())) for s in readlines()]
    INF = 10 ** 9
    dp = [INF] * (H + 1)
    dp[0] = 0
    
    for i in range(N):
        a, b = M[i]
        for j in range(H):
            nj = min(H, j + a)
            dp[nj] = min(dp[nj], dp[j] + b)

    print(dp[H])


if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second

inline int in(){int X, Y; Y = scanf("%d", &X); return X; }

const int N = -1;
const ld EPS = 1e-12;

bool eq(ld a, ld b){
	return abs(a-b) < EPS;
}

struct PT{
	ld X, Y;
	PT (ld X = 0, ld Y = 0) : X(X), Y(Y) {}
	PT operator + (PT ro) const{
		return PT(X+ro.X, Y+ro.Y);
	}
	PT operator - (PT ro) const{
		return PT(X-ro.X, Y-ro.Y);
	}
	PT operator * (ld co) const{
		return PT(X*co, Y*co);
	}
	PT operator / (ld co) const{
		return PT(X/co, Y/co);
	}
	ld operator * (PT ro) const{
		return X*ro.X + Y*ro.Y;
	}
	ld operator ^ (PT ro) const{
		return X*ro.Y - Y*ro.X;
	}
};

istream& operator>> (istream &is, PT &p){
	ld val;
	is >> val;
	p.X = val;
	is >> val;
	p.Y = val;
	return is;
}

PT operator * (ld co, PT p){
	return p*co;
}

ld len(PT a){
	return sqrt(a*a);
}

PT unit(PT a){
	return a/len(a);
}

PT clrot(PT a){
	return PT(-a.Y, a.X);
}

PT proj(PT a, PT b, PT c){
	b = b-a, c = c-a;
	return a + (b*c)/(b*b)*b;
}

PT reflect(PT a, PT b, PT c){
	PT d = c;
	b = b-a, c = c-a;
	return d + (c^b)/len(b)*clrot(unit(b))*2;
}

int sgn(PT a, PT b, PT c){
	ld cr = (b-a)^(c-a);
	return cr > EPS ? 1 : (cr + EPS < 0 ? -1 : 0);
}

bool intersect(PT a, PT b, PT c, PT d){
	int as = sgn(c, d, a),
		bs = sgn(c, d, b),
		cs = sgn(a, b, c),
		ds = sgn(a, b, d);
	if (as && as == bs || cs && cs == ds)
		return false;
	else if (as || bs || cs || ds)
		return true;
	for (int j = 0; j < 2; j++){
		ld mX = min(a.X, b.X),
		   MX = max(a.X, b.X),
		   mY = min(a.Y, b.Y),
		   MY = max(a.Y, b.Y);
		for (int k = 0; k < 2; k++){
			if (c.X + EPS > mX && c.X < MX + EPS && c.Y + EPS > mY && c.Y < MY + EPS)
				return true;
			swap(c, d);
		}
		swap(a, c);
		swap(b, d);
	}
	return false;
}

int main(){
	for (int i = in(); i; i--){
		PT a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << intersect(a, b, c, d) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3284
def n_comb_k( n, k, MOD ):
    chld = 1
    prnt = 1
    for r in range( 1, k + 1 ):
        chld = ( chld * ( n - k + r ) ) % MOD
        prnt = ( prnt * r ) % MOD
    return chld * pow( prnt, MOD - 2, MOD ) % MOD

n, a, b = map( int, input().split() )
MOD = 10 ** 9 + 7

ans = pow( 2, n, MOD ) -1

ans = ( ans - n_comb_k( n, a, MOD ) ) % MOD
ans = ( ans - n_comb_k( n, b, MOD ) ) % MOD

print( ans )

Measured memory_bytes: 3064
N=int(input())
a=list(map(int,input().split()))
sumal=[0]*N
sumal[0]=a[0]
suma=sum(a)
for i in range(1,N-1):
    sumal[i]=sumal[i-1]+a[i]
minabs=10**10
sumal[N-1]=a[N-1]
for i in range(N):
    minabs=min(minabs,abs(suma-2*sumal[i]))
print(minabs)



Measured memory_bytes: 23792
W,H,N = map(int,input().split())
XY = [0, W, 0, H]
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        XY[0] = max(XY[0], x)
    elif a == 2:
        XY[1] = min(XY[1], x)
    elif a == 3:
        XY[2] = max(XY[2], y)
    else:
        XY[3] = min(XY[3], y)

print(max(0, XY[1]-XY[0])*max(0, XY[3]-XY[2]))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// B
void solve() {
    ll N;
    cin >> N;
    ll sum  = 0;
    FOR(i,1,N+1) {
        bool cond1 = i%3 == 0;
        bool cond2 = i%5 == 0;
        if (cond1 || cond2) continue;
        else sum+=i;
    }

    cout << sum << endl;
}

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


Measured memory_bytes: 3636
import java.util.*;

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

    boolean flg = true;
    int count = 1;

    while(flg) {
      int n = sc.nextInt();
      if(n == 0) {
        break;
      }
      System.out.println("Case " + count + ": " + n);

      count++;
    }
    sc.close();
  }
}


Measured memory_bytes: 40796
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_130
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nx = ReadInts();
            int n = nx[0];
            int x = nx[1];
            int[] ls = ReadInts();
            int now = 0;
            int res = 1;
            for(int i =0; i < n; i++)
            {
                now += ls[i];
                if (now <= x) res++;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *prev, *next;
};

struct Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil;
    nil -> prev = nil;
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x -> key = key;
    x -> next = nil -> next;
    nil -> next -> prev = x;
    nil -> next = x;
    x -> prev = nil;
}

Node* search(int key) {
    Node *cur = nil -> next;
    while (cur != nil && cur -> key != key){
        cur = cur -> next;
    }
    return cur;
}

void printList() {
    Node *cur = nil -> next;
    int isf = 0;
    while (cur != nil) {
        if (isf++ > 0) {printf(" ");}
        printf("%d", cur -> key);
        cur = cur -> next;
    }
    printf("\n");
    
}

void deleteNode(Node *t) {
    if (t == nil){
        return;
    }
    t -> prev -> next = t -> next;
    t -> next -> prev = t -> prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil -> next);
}

void deleteLast() {
    deleteNode(nil -> prev);
}

void deleteKey(int key) {
    deleteNode(search(key));
}

int main(int argc, char const *argv[])
{
    int key, n, i;
    int size = 0;
    char com[20];
    
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i'){
            insert(key); size++;
        }
        else if (com[0] == 'd') {
            if (strlen(com) > 6 ) {
                if (com[6] == 'F') {deleteFirst();}
                else if (com[6] == 'L') {deleteLast();}
            } else {
                deleteKey(key);
            }
            size--;
        }
    }
    printList();

    return 0;
}



Measured memory_bytes: 33848
#include <stdio.h>

int main(void) {

  while (1) {
    int i,j;
    int H, W;
    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 == 0) || (i == (H-1)))
          printf("#");
        else if ((j == 0) || (j == (W-1)))
          printf("#");
        else
          printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
s,n=list(map(int,input().split()))
ss=list(input())
if ss[n-1]=='A':
  ss[n-1]='a'
if ss[n-1]=='B':
  ss[n-1]='b'
if ss[n-1]=='C':
  ss[n-1]='c'
print(''.join(ss))

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

signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n, p;
	string s;
	cin >> n >> p >> s;
	int ans = 0;
	unordered_map<int, int> m;
	if(p <= 100) {
		for(int i = 0; i < n; ++i) {
			// Just s[i]
			int use = (s[i] - '0') % p;
			if(use == 0) {
				++ans;
			}
			// New map
			unordered_map<int, int> nm;
			for(auto it: m) {
				int r1 = (10 * it.first + use) % p;
				if(r1 == 0) {
					ans += it.second;
				}
				nm[r1] += it.second;
			}

			++nm[use];
			m = nm;
		}
		cout << ans;
	}
	else {
		vector<int> pre(n);
		int ten = 1;
		for(int i = n-1; i >= 0; --i) {
			pre[i] = (ten * (s[i] - '0')) % p;
			ten = (ten * 10) % p;
		}
		for(int i = 1; i < n; ++i) pre[i] = (pre[i] + pre[i-1]) % p;
		m[0] = 1;
		for(int i = 0; i < n; ++i) {
			ans += m[pre[i]];
			++m[pre[i]];
		}
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 2452
#include <stdio.h>

#define MAX(A, B) ((A) < (B) ? (B) : (A))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAXNUM 10001

int main(void) {
  int n, a[MAXNUM],  i, max, min;
  long long  sum;
  scanf ("%d", &n);
  for (i = 0; i < n ; i++) {
  scanf ("%d", &a[i]);
  }
  max = a[0];
  min = a[0];
  sum = a[0];
  //   printf ("%d %d %LLd\n", min, max, sum);
  for (i = 1; i < n ; i++) {
    max = MAX (max, a[i]);
    min = MIN (min, a[i]);
    sum = sum + a[i];
    //  printf ("%d %d %LLd\n", min, max, sum);
  }
  printf ("%d %d %lld\n", min, max, sum);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct edge {
    int to, cost;
};

int n;
vector<vector<edge>> g;
vector<int> color;

void dfs(int v, int p, int c) {
    color[v] = c;
    for(const auto &e : g[v]) {
        if(e.to != p) {
            dfs(e.to, v, (e.cost & 1) ? 1 - c : c);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    color.resize(n, -1);
    for(int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        g[--a].emplace_back(edge{--b, c});
        g[b].emplace_back(edge{a, c});
    }
    dfs(0, -1, 0);
    for(int i = 0; i < n; i++) {
        print(color[i]);
    }
}

Measured memory_bytes: 8960
import java.util.Arrays;
import java.util.Scanner;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 0;

    String s = sc.next();
    for(int i=0; i<s.length();i++){
      if(String.valueOf(s.charAt(i)).equals("o")){
        ans++;
      }
    }
    System.out.println(700 + 100*ans);

    sc.close();
  }
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
typedef pair<int,int>P;
const int maxn = 1005;
char Map[maxn][maxn];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int dis[maxn][maxn];
P fac[10];
int n,h,w;
int bfs(P a,P b){
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)dis[i][j]=-1;
    queue<P>que;
    que.push(a);
    dis[a.first][a.second]=0;
    while(que.size()){
        P p = que.front();que.pop();
        if(p==b)break;
        for(int i=0;i<4;i++){
            int nx=dx[i]+p.first;
            int ny=dy[i]+p.second;
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&Map[nx][ny]!='X'&&dis[nx][ny]==-1){
                que.push(P(nx,ny));
                dis[nx][ny]=dis[p.first][p.second]+1;
            }
        }
    }
    return dis[b.first][b.second];
}
int main()
{
    cin>>h>>w>>n;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>Map[i][j];
            if(Map[i][j]=='S'){
                fac[0].first=i;
                fac[0].second=j;
                Map[i][j]='.';
            }
            else if('1'<=Map[i][j]&&Map[i][j]<='9'){
                int flag = Map[i][j] - '0';
                fac[flag].first=i;
                fac[flag].second=j;
            }
        }
    }
    int setp = 0;
    for(int i=0;i<n;i++){
        setp += bfs(fac[i],fac[i+1]);
    }
    cout<<setp<<endl;
    return 0;
}

Measured memory_bytes: 6144