akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  string ans="No";
  ll p=0,q=0;
  bool is=false;
  rep(i,n){
    if(a.at(i)%4==0){
      p+=2;
      is=true;
    }else if(a.at(i)%2==0){
      q++;
    }
  }
  if(is &&n%2==1){
    p++;
  }
  if(p+q>=n){
    ans="Yes";
  }
  cout << ans;
}

Measured memory_bytes: 4000
#include <stdio.h>
int main(int argc, char **argv)
{
  char buf[11] = {};
  int i, max = 0, cur = 0;
  gets(buf);
  for (i=0;i<11;i++) {
    if (buf[i]=='\0') break;
    if (buf[i]=='A'||buf[i]=='C'||buf[i]=='G'||buf[i]=='T') {
      cur++;
      if (max < cur) max = cur;
    } else {
     cur = 0; 
    }
  }
  printf("%d", max);
      
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
int prime[300000];

int main(){
	for (int i=2;i<300000;i++) prime[i]=1;
	
	for (int i=2;i<100005;i++) {
		if (prime[i]==0) continue;
		else{
			for (int j=i*2;j<100005;j+=i){
				prime[j]=0;
			}
		}
	}
	
	int a[200000];
	
	for (int i=3;i<=100005;i+=2){
		if(prime[i]&&prime[(i+1)/2]){
			a[i]=a[i-2]+1;
		}else{
			a[i]=a[i-2];
		}
	}
	for (int i=2;i<=100005;i+=2){
		a[i]=a[i-1];
	}
	
	
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		int l,r;
		cin>>l>>r;
		if (l==1) cout<<a[r]<<endl;
		else
		cout<<a[r]-a[l-2]<<endl;
	}
	
}

Measured memory_bytes: 2176
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(A * B % 2 == 1 ? "Yes" : "No");
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

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

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	int N, K;
	std::string S;
	std::vector<int> back;
	std::vector<int> stand;

	std::cin >> N >> K;
	std::cin >> S;

	int head = 0;
	while (head != S.size()) {
		int i;
		for (i = head; i < S.size(); ++i) {
			if (S[i] != '1')
				break;
		}
		back.push_back(i-head);
		head = i;
		if (head == S.size())
			break;
		for (; i < S.size(); ++i) {
			if (S[i] != '0')
				break;
		}
		stand.push_back(i-head);
		head = i;
	}
	back.push_back(0);

	if (stand.size() <= K) {
		std::cout << N << "\n";
		return 0;
	}

	int cur = back[0];
	for (int i = 1; i < K+1; ++i)
		cur += stand[i-1] + back[i];
	int max = cur;

	for (int i = K+1; i < stand.size() +1; ++i) {
		cur -= back[i-K-1] + stand[i-K-1];
		cur += stand[i-1] + back[i];
		if (max < cur)
			max = cur;
	}

	std::cout << max << "\n";
}


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll v[710000], t[710000];
bool ok[710000];
int main() {
	ll n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	REP(i, n)ok[i] = true;
	REP(i, n) {
		if (s[i] == 'o')v[i + c + 1] = max(v[i + c + 1], v[i] + 1);
		v[i + 1] = max(v[i + 1], v[i]);
		//cout << i << " " << v[i] << endl;
	}
	REPR(i, n - 1) {
		if (s[i] == 'o')t[i] = max(t[i], t[i + c + 1] + 1);
		t[i] = max(t[i + 1], t[i]);
		//cout << i << " " << t[i] << endl;
	}
	REP(i, n) {
		ll now = 0;
		now += v[i];
		if (i + 1 < n)now += t[i + 1];
		if (now >= k)ok[i] = false;
		//cout << now << " " << i << endl;
	}
	ll now = 0, cnt = 0;
	REP(i, n) {
		if (s[i] == 'o' and cnt == 0) {
			now++;
			cnt = c;
			//cout << i << " !" << endl;
		}
		else {
			if(cnt > 0)cnt--;
			ok[i] = false;
		}
	}
	if (now > k)return 0;
	REP(i, n) {
		if (ok[i])cout << i + 1 << endl;
	}

}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] n = line.split(" ");
		Arrays.sort(n);
		System.out.println(n[0] + " " + n[1] + " " + n[2]);
	}

}



Measured memory_bytes: 26148
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }

int MAX(int a, int b) { if (a > b) { return a; }return b; }
/*
int min(int a, int b) { if (a<b) { return a; }return b; }
*/
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



/// /////////////////////////////////////////////
/// <summary> 
/// ユークリッドの互除法
///機　能：ユークリッドの互除法によりa,bの最大公約数を求める
///戻り値: 最大公約数、(自然数以外が指定されたときは-1)
/// </summary> 
/// /////////////////////////////////////////////
int euclid(int a, int b)
{
	int temp;
	if (a < b) { temp = a; a = b; b = temp; }
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return euclid(b, a % b);
}

int main() {
	int N, X,A[100000];
	int a, b,ans;
	scanf("%d%d", &N, &X);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	a = abs(X - A[0]);
	if (N > 1) {
		for (int i = 0; i < N-1; i++) {
			b = abs(X - A[i+1]);
			a = euclid(a, b);
		}
	}
	ans = a;
	print(a);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 55;
const int maxD = 400;
const int maxH = 100; 
const int MOD = 1000000007;

char a[3][maxN];
int b[maxN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		scanf("%s",a[i]+1);
	int p = 1;
	int q = 0;
	while(p<=n)
	{
		++q;
		if(a[1][p] == a[2][p])
		{
			b[q] = 1;
			p++;
		}
		else
		{
			b[q] = 0;
			p+=2;
		}
	}
	ll ans = 0;
	if(b[1] == 1)
		ans = 3;
	else
		ans = 6;
	for(int i=1;i<q;i++)
	{
		int x = b[i];
		int y = b[i+1];
		if(x && y)
			ans = (ans * 2)%MOD;
		else if(x && !y )
			ans = (ans * 2)%MOD;
		else if(!x && !y)
			ans = (ans * 3)%MOD;
		else
			ans = ans;
	}
	printf("%lld\n",ans);
	return 0;
}  

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

using namespace std;

int h, w;
char all;
int go[110][110];
int maxx;
int dx[10] = {-1, 1, 0, 0};
int dy[10] = {0, 0, -1, 1};

int main(void)
{
	scanf("%d %d", &h, &w);
	
	for(int i = 1 ; i <= h ; i++)
	{
		for(int j = 1 ; j <= w ; j++)
		{
			scanf(" %c", &all);
			
			if(all == '.')
				go[i][j] = 1;
			else
				go[i][j] = 0;
		}
	}
	
	for(int i = 1 ; i <= h ; i++)
	{
		for(int j = 1 ; j <= w ; j++)
		{
			if(go[i][j] == 1)
			{
				queue<int> xq, yq, cq;
				xq.push(i);
				yq.push(j);
				cq.push(0);
				int chec[110][110] = {0, };
				chec[i][j] = 1;
				int maxxx = 0;
				
				while(!xq.empty())
				{
					int xx = xq.front();
					int yy = yq.front();
					int cc = cq.front();
					xq.pop();
					yq.pop();
					cq.pop();
					
					for(int k = 0 ; k < 4 ; k++)
					{
						if(xx + dx[k] <= 0 || xx + dx[k] > h || yy + dy[k] <= 0 || yy + dy[k] > w)
							continue;
						if(chec[xx + dx[k]][yy + dy[k]] == 1)
							continue;
						if(go[xx + dx[k]][yy + dy[k]] == 0)
							continue;
						xq.push(xx + dx[k]);
						yq.push(yy + dy[k]);
						cq.push(cc + 1);
						chec[xx + dx[k]][yy + dy[k]] = 1;
						maxxx = max(maxxx, cc + 1);
					}
				}
				
				maxx = max(maxxx, maxx);
			}
		}
	}
	
	printf("%d", maxx);
	return 0;
}

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var p = new List<int>();
        GeneratePrime(p, 10000);
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var a = int.Parse(line.Trim());
            var count = 0;
            foreach (var x in p)
            {
                var x2 = a + 1 - x;
                if (x2 > x)
                {
                    if (p.Contains(x2)) count += 2;
                }
                else if (x2 == x) count++;
                else break;
            }
            Console.WriteLine(count);
        }
    }
    public static void GeneratePrime(List<int> primeList, int m)
    {
        int prime;
        var sqrtMax = Math.Sqrt(m);
        var searchList = Enumerable.Range(2, m - 1).ToList();
        do
        {
            prime = searchList.First();
            primeList.Add(prime);
            searchList.RemoveAll(n => n % prime == 0);
        }
        while (prime < sqrtMax);
        primeList.AddRange(searchList);
    }
}

Measured memory_bytes: 9964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int a=0,b=0;
	rep(i,s.size()){
		if(s[i]=='A') a++;
		else b++;
	}
	if(a && b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int N;
double x[10];
string u[10];

int main() {
    cin >> N;
    rep(i, N) {
        cin >> x[i] >> u[i];
    }

    double ans = 0;
    rep(i, N) {
        if (u[i] == "JPY") {
            ans += x[i]; 
        } else {
            ans += x[i] * 380000.0;
        }
    }

    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<ll> data(5);
    ll i, j, k;
    for (i = 1; i <= 5;i++){
        cin >> k;
        if(k==0){
            cout << i;
            return 0;
        }
    }
        return 0;
}

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


int main() {
    int a ,b, x;
  cin >> a >> b >> x;
  double t = 0;
  double p = 3.14159265358979;
  if(x > a*a*b/2) {
    double c = 2*a*a*b - 2*x;
    double m = a*a*a;
    t = atan( c/m );
  }else{
    double c = a*b*b;
    double m = 2*x;
    t = atan( c/m );
  }
  
  cout << fixed << setprecision(12);
  cout << t*360/2/p << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()


int main(){
  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int h, w, n; cin >> h >> w >> n;
  int m = max(h, w);

  for (int i = 1; i <= 1000000; i++){
    n -= m;
    if(n <= 0){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
n=int(input())
x=input()

pcn=x.count('1')
px=int(x,2)%(pcn+1)
mx=int(x,2)%(pcn-1) if pcn>1 else 0
p2=[0]*n
m2=[0]*n

for i in range(n):
    p2[i]=pow(2,n-1-i,pcn+1)
    m2[i]=pow(2,n-1-i,pcn-1) if pcn>1 else 0

for i in range(n):
    p=False if int(x[i])&1 else True
    if pcn==1 and not p:
        print(0)
        continue
    ans=0
    tmp=0
    if(p):
        tmp=(px+p2[i])%(pcn+1)
    else:
        tmp=(mx-m2[i])%(pcn-1)
    ans+=1
    while tmp!=0:
        ipcn=str(bin(tmp)).count('1')
        tmp%=ipcn
        ans+=1
    print(ans)

Measured memory_bytes: 25220
#include "bits/stdc++.h"
using namespace std;

int main(void) {
  int n, seats[100010] = {};
  int l, r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    seats[l]++;
    seats[r + 1]--;
  }
  for (int i = 1; i < 100005; i++) 
    seats[i] += seats[i - 1];
  
  int ans = 0;
  for (int i = 0; i < 100010; i++) ans += seats[i];
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    ll ans = (ll)(N - 1) * N / 2;
    write(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string S;
    cin >> S;
    S[3]='8';
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
p=[]
for i in range(n):
    s,c = map(int,input().split())
    if i == 0:
        p.append(s)
    p.append(c)


m = [[0 for _ in range(n+1)] for _ in range(n+1)]

for j in range(1, n):
    for i in range(1, n+1):
        if i+j > n:
            break
        if i != i+j:
            m[i][i+j] = min([m[i][k] + m[k+1][i+j] + p[i+j]*p[k]*p[i-1] for k in range(i,i+j)])

print(m[1][n])


Measured memory_bytes: 5660
#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 fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define fbo find_by_order
    #define ook order_of_key
     
    typedef long long ll;
    typedef pair<ll,ll> ii;
    typedef vector<ll> vi;
    typedef long double ld; 
    typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
     
    int b[222222];
    int vis[6222];
    int a[6666];
     
    vector<ll> S;
     
    void dfs(int u, ll s)
    {
    	if(vis[u]) return ;
    	vis[u]=1;
    	s+=b[u];
    	S.pb(s);
    	dfs(a[u],s);
    }
     
    int main()
    {
    	ios_base::sync_with_stdio(0); cin.tie(0);
    	int n,k; cin>>n>>k;
    	for(int i=0;i<n;i++) 
    	{
    		cin>>a[i]; a[i]--;
    	}
    	for(int i=0;i<n;i++) 
    	{
    		cin>>b[i]; 
    	}
    	ll ans = -ll(1e18);
    	for(int i=0;i<n;i++)
    	{
    		memset(vis,0,sizeof(vis));
    		dfs(i,0);
    		if(S.back()>0&&k>int(S.size()))
    		{
    			ll q = k/int(S.size());
    			if(q>=1)
    			{
    				ll mx = -ll(1e18);
    				if(q-1>0) mx=0;
    				for(int i=0;i<int(S.size());i++)
    				{
    					mx=max(mx,S[i]);
    				}
    				ans=max(ans,(q-1)*S.back()+mx);
    			}
    			
    			{
    				int r = k%int(S.size());
    				ll mx = 0;
    				for(int i=0;i<r;i++)
    				{
    					mx=max(mx,S[i]);
    				}
    				ans=max(ans,mx+q*S.back());
    			}
    		}
    		else
    		{
    			for(int j=1;j<=k;j++)
    			{
    				if(j-1<S.size()) ans=max(ans,S[j-1]);
    				else break;
    			}
    		}
    		S.clear();
    	}
    	cout<<ans<<'\n';
    }

Measured memory_bytes: 3972
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N;
	cin >> N;

	lint sum = 0, tmp = N;
	while (tmp) {
		sum += tmp % 10;
		tmp /= 10;
	}

	if (N%sum == 0) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,x = map(int, input().split())

a,p = [1],[1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    else:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n-1])

print(f(n, x))


Measured memory_bytes: 8832
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll a,b,c,d;

    in4(a,b,c,d);
    prl(max(a*b,c*d));

    return 0;
}

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

int main(){
	unsigned a, b;
	for ( a = 1; a  <= 9; a++ )
	{
		for ( b = 1; b <= 9; b++ )
		{
			cout  << a << 'x' << b << '=' << a * b << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if((a==1&&b==2)||(a==2&&b==1)){
    printf("3");
  }
  else if((a==2&&b==3)||(a==3&&b==2)){
    printf("1");
  }
  else{
    printf("2");
  }
}

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

using namespace std;

int main()
{
  long long  n,a,k;

    cin >>n>>k;

    for(long long i=0 ;i<n;i++){
        cin >>a;
    }

    cout << (n-1+k-2)/(k-1);
return 0;
}

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

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		Integer[] cards = new Integer[N];
		for (int i = 0; i < cards.length; i++) {
			cards[i] = sc.nextInt();
		}
		Arrays.sort(cards, Comparator.reverseOrder());
		int ans = 0;
		for (int i = 0; i < K; i++) {
			ans += cards[i];
		}
		System.out.println(ans);
		sc.close();
	}
}

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

int main(){
int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int>x(N), y(M);
  for(int i=0; i<N; i++){
   cin>>x[i]; }
  for(int i=0; i<M; i++){
   cin>>y[i]; }
  
  bool ans=true;
  if(X>Y){ans=false;}

  for(int i=0; i<N; i++){
   for(int j=0; j<M; j++){
    if(x[i]>=y[j] || X>=y[j] || Y<=x[i]){ans=false;}
   }
  }
  
  if(ans){cout<<"No War";}
  else{cout<<"War";}
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int main()
{
    reg int a,b;
    a=read(),b=read();
    a=a-2*b;
    a=max(a,0);
    cout<<a<<"\n";
	return 0;
}


Measured memory_bytes: 256
// C - Monsters Battle Royale
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b){return b? gcd(b, a%b): a;}

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

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

	int g = A[0];
	for(int i=1; i<N; ++i) g = gcd(g, A[i]);
	cout<< g <<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
 int m, f, r;
 while(1){
  cin >> m >> f >> r;
  int c = m+f;
 if( m == -1 && f == -1 && r == -1)break;
 if( m == -1 || f == -1 ){
 cout << "F" << endl;
}else if ( c >= 80 ){
 cout << "A" << endl;
}else if( c >= 65 && c < 80 ){
 cout << "B" << endl;
}else if( c >= 50 && c < 65 ){
 cout << "C" << endl;
}else if( c >= 30 && c < 50 && r >= 50 ){
 cout << "C" << endl;
}else if( c >= 30 && c < 50 ){
 cout << "D" << endl;
}else if( c < 30){
 cout << "F" << endl;
}
}
return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
 
	
	ll N;
	cin >> N;
	
	vector<ll> W(N);
	vector<ll> G(N);
	
	for (ll i = 0; i < N; i++) {
		cin >> W.at(i);	
		G.at(i) = W.at(i);
	}
	sort(W.begin(), W.end());
	
	for (ll i = 0; i < N; i++) {

		if (G.at(i) >= W.at(N / 2)) {
			cout << W.at(N / 2 - 1) << endl;
		}
		else {
			cout << W.at(N / 2 ) << endl;
		}

	}

}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner io = new Scanner(System.in);
		long K = io.nextLong();
		System.out.println(50);
		long first = 49 + K/50 - K%50;
		long second = 100 + K/50 - K%50;
		for(int i=0;i<50-K%50;i++){
			System.out.print(first);
			if(i!=49) System.out.print(" ");
		}
		for(int i=0;i<K%50;i++){
			System.out.print(second);
			if(i!=K%50-1) System.out.print(" ");
		}
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 23892
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 101;
const int MAXW = 10001;

int main() {
    int N, W;
    vector<int> v(MAXN);
    vector<int> w(MAXN);
    vector<int> dp(MAXW, 0);
    scanf("%d %d", &N, &W);
    for (int i = 0; i < N; ++i) {
        scanf("%d %d", &v[i], &w[i]);
    }
    for (int i = 0; i < N; i++) {
        for (int j = W; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    printf("%d\n", dp[W]);
}

Measured memory_bytes: 2796
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
    string[] ss = readln.split;
    foreach (i, ref arg ; args)
        arg = ss[i].parse!int;
}


enum MOD = 10^^9 + 7;
pragma(inline, true)
int mul(long x, long y) {
    return (x * y) % MOD;
}

int[] f;
void make_table(int n) {
    f = new int[n + 1];
    f[0] = f[1] = 1;
    foreach (i ; 2..n+1)
        f[i] = mul(i, f[i-1]);
}

int powmod(S,T,U)(S x, T n, U MOD) {
    int r = 1;
    while (n > 0) {
        if (n & 1) r = mul(r, x);
        x = mul(x, x);
        n >>= 1;
    }
    return r;
}

pragma(inline, true)
int mod_inv(int x) {
    return powmod(x, MOD - 2, MOD);
}

pragma(inline, true)
int comb(int n, int r) {
    if (n - r < 0 || n < 0 || r < 0) return 0;
    return mul(mul(f[n], f[r].mod_inv), f[n - r].mod_inv);
}

void main() {
    int n, k;
    scan(n, k);
    make_table(2010);
    foreach (i; 1..k+1) {
        int x = mul(comb(n-k+1, i), comb(k-1, i-1));
        writeln(x);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, cap, cost, rev;
	edge(){}
	edge(llint a, llint b, llint c, llint d){
		to = a, cap = b, cost = c, rev = d;
	}
};

llint n, m, F;
llint S, T;
vector<edge> G[205];
llint dist[205];
llint prevv[205], preve[205];
llint h[205];

void BellmanFord()
{
	for(int i = 0; i <= T; i++) dist[i] = inf;
	dist[S] = 0, prevv[S] = -1;
	
	bool update = true;
	while(update){
		update = false;
		for(int i = 0; i <= T; i++){
			for(int j = 0; j < G[i].size(); j++){
				if(G[i][j].cap == 0) continue;
				if(dist[G[i][j].to] > dist[i] + G[i][j].cost){
					dist[G[i][j].to] = dist[i] + G[i][j].cost;
					prevv[G[i][j].to] = i;
					preve[G[i][j].to] = j;
					update = true;
				}
			}
		}
	}
}

void Dijkstra()
{
	for(int i = 0; i <= T; i++) dist[i] = inf;
	dist[S] = 0, prevv[S] = -1;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	
	llint v, d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(G[v][i].cap == 0) continue;
			llint u = G[v][i].to, c = h[v] - h[u] + G[v][i].cost;
			if(dist[u] > d + c){
				dist[u] = d + c;
				prevv[u] = v;
				preve[u] = i;
				Q.push( make_pair(dist[u], u) );
			}
		}
	}
}

void add_edge(llint from, llint to, llint cap, llint cost)
{
	G[from].push_back( edge(to, cap, cost, G[to].size()) );
	G[to].push_back( edge(from, 0, -cost, G[from].size()-1) );
}


int main()
{
	cin >> n >> m >> F;
	llint u, v, c, d;
	for(int i = 1; i <= m; i++){
		cin >> u >> v >> c >> d;
		add_edge(u, v, c, d);
	}
	S = 0, T = n-1;
	
	BellmanFord();
	for(int i = 0; i <= T; i++) h[i] = dist[i];
	
	llint f = F, ans = 0;
	while(f > 0){
		Dijkstra();
		if(dist[T] >= inf) break;
		
		llint p = T, flow = f;
		while(prevv[p] != -1){
			flow = min(flow, G[prevv[p]][preve[p]].cap);
			p = prevv[p];
		}
		
		p = T;
		while(prevv[p] != -1){
			G[prevv[p]][preve[p]].cap -= flow;
			G[p][G[prevv[p]][preve[p]].rev].cap += flow;
			p = prevv[p];
		}
		f -= flow;
		ans += (dist[T] + h[T] - h[S]) * flow;
		
		for(int i = 0; i <= T; i++) h[i] += dist[i];
	}
	
	if(f > 0) ans = -1;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

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

	int n;
	cin >> n;
	vector<LL> a(n + 1);
	for(LL &ai : a)
		cin >> ai;
	vector<LL> pref = a;
	for(int i = n; i > 0; --i)
		pref[i - 1] += pref[i];
	constexpr LL inf = LL(1e18);
	LL nonleaves = 1;
	FOR(i, 0, n) {
		pref[i] = min(pref[i], nonleaves);
		nonleaves -= a[i];
		if(nonleaves < 0) {
			cout << "-1\n";
			return 0;
		}
		nonleaves = min(2 * nonleaves, inf);
	}
	debug(a, pref);
	cout << accumulate(pref.begin(), pref.end(), 0LL) << '\n';
}


Measured memory_bytes: 4764
<?php
$str = trim(fgets(STDIN));
$l = strlen($str);
for($i = 0; $i < $l; $i++){
  @$c[ord($str[$i]) - 97]++;
}
$sum = 1+$l*($l-1)/2;
foreach($c as $count){
  $sum-=($count*($count-1)/2);
}
echo $sum, "\n";


Measured memory_bytes: 4984
import heapq
n,m=map(int, input().split())
A=[-1*int(i) for i in input().split()]
heapq.heapify(A)

while m>0:
    x = heapq.heappop(A)
    x*=-1
    x//=2
    x*=-1
    heapq.heappush(A, x)
    m-=1
print(-1*sum(A))


Measured memory_bytes: 14180
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,M;cin >> N >> M;
    vector<long long> X(N),Y(N),Z(N);
    for(int i = 0;i<N;i++) cin >> X.at(i) >> Y.at(i) >> Z.at(i);

    long long ans = 0;
    //X,Y,Zについて、それぞれ正に最大化するか負に最大化するか選ぶ 2^3
    for(int i = 0;i<(1<<3);i++){
        //X最大化Y最大化Z最小化なら、🎂の絶対値を大きくしたいので、X_i+Y_i-Z_iでソートする
        vector<long long> cakes(N);
        bitset<3> B(i);
        //bit立ってたら最大化
        for(int j = 0;j<N;j++){
            if(B.test(0)){
                cakes.at(j) += X.at(j);
            }
            else{
                cakes.at(j) -= X.at(j);
            }
            if(B.test(1)){
                cakes.at(j) += Y.at(j);
            }
            else{
                cakes.at(j) -= Y.at(j);
            }
            if(B.test(2)){
                cakes.at(j) += Z.at(j);
            }
            else{
                cakes.at(j) -= Z.at(j);
            }
            //cakes.at(j) = abs(cakes.at(j));
        }
        sort(cakes.begin(),cakes.end(),greater<long long>());
        long long sum = 0;
        for(int j = 0;j<M;j++) sum += cakes.at(j);
        ans = max(ans,sum);
        //cout << sum << " " << B << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3692
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

struct task{
	int cost;
	int deadLine;
};

bool myComp(task left,task right){
	return (left.deadLine < right.deadLine);
}

int main()
{
	string s;
	int start,end;
	cin>>s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'A'){
			start = i;
			break;
		}
	}
	for(int i = s.length()-1; i >= 0; i--){
		if(s[i] == 'Z'){
			end = i;
			break;
		}
	}
	cout<<(end - start + 1)<<endl;
	return 0;
}



Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2005;
int dp[2005][2];
int a[maxN];
int n, z, w;
int solve(int x, int t) {
    if (dp[x][t] != -1) return dp[x][t];
    if (t == 0) {
        for (int i = x + 1; i < n; i++) {
            dp[x][t] = max(solve(i, 1), dp[x][t]);
        }
        dp[x][t] = max(dp[x][t], abs(a[n] - a[x]));
        return dp[x][t];
    }
    if (t == 1) {
        dp[x][t] = abs(a[n] - a[x]);
        for (int i = x + 1; i < n; i++) {
            dp[x][t] = min(solve(i, 0), dp[x][t]);
        }
        return dp[x][t];
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> z >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    memset(dp, -1, sizeof dp);
    a[0] = w;
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
from collections import deque

import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


# @mt
def slv(H, W, C, D, S):
    C = (C[0]-1, C[1]-1)
    D = (D[0]-1, D[1]-1)
    q = deque()
    q.append((0, C))
    memo = {}
    T = 10**6
    while q:
        c, (x, y) = q.popleft()
        v = x*T + y
        if v in memo:
            continue
        memo[v] = c

        for nx in range(x-2, x+3):
            for ny in range(y-2, y+3):
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                    d = abs(nx-x) + abs(ny-y)
                    if d == 1:
                        q.appendleft((c, (nx, ny)))
                    elif d == 0:
                        pass
                    else:
                        q.append((c+1, (nx, ny)))
    g = D[0]*T + D[1]
    return -1 if g not in memo else memo[g]


def main():
    H, W = read_int_n()
    C = read_int_n()
    D = read_int_n()
    S = [read_str() for _ in range(H)]
    print(slv(H, W, C, D, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 240064
#include<bits/stdc++.h>
using namespace std;
int n,d,a[15][15],cnt=0;
int main()
{
	cin>>n>>d;
	for(int i=0;i<n;i++)
		for(int j=0;j<d;j++)
			cin>>a[i][j];
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			int sum=0;
			for(int k=0;k<d;k++)
				sum+=(abs(a[i][k]-a[j][k])*abs(a[i][k]-a[j][k]));
			int tmp=sqrt(sum);
			if(tmp*tmp==sum)
				++cnt;
		}
	cout<<cnt<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>

int h, w;
int A[1000][1000];

constexpr int mod = 1000000007;
int dp[1001][1001];

int main(){
  scanf("%d%d", &h, &w);
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      char c;
      do { scanf("%c", &c); } while(c != '.' && c != '#');
      A[i][j] = c == '#';
    }
  }

  dp[0][1] = 1;
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      if(A[i-1][j-1]) continue;
      dp[i][j] = dp[i-1][j] + dp[i][j-1];
      if(dp[i][j] >= mod) dp[i][j] -= mod;
    }
  }

  printf("%d\n", dp[h][w]);

  return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
bool d[51][51];
int a,b,s,_x,_y,dx[8]={0,-1,-1,-1,0,1,1,1},dy[8]={1,1,0,-1,-1,-1,0,1};
#define r(z,x) for(int z=0;z<x;z++)
void bfs(int x,int y){
    if(0>x||x>=b||0>y||y>=a)return;
    d[x][y]=0;
    r(i,8)if(d[_x=x+dx[i]][_y=y+dy[i]])bfs(_x,_y);
}
int main(){
    while(cin>>a>>b,a||b){
        s=0;
        r(i,b)r(j,a)cin>>d[i][j];
        r(i,b)r(j,a)if(d[i][j])bfs(i,j),s++;
        cout<<s<<endl;
    }
}

Measured memory_bytes: 3120
nums = [int(input()) for _ in range(5)]

h = [i % 10 for i in nums if i%10 != 0]
min1 = 0 if len(h)==0 else min(h)

amount = 0
last = True
for i in nums:
  if last and i% 10 == min1:
    amount += i
    last = False
  else:
    amount += (i //10 + 1)*10 if i %10 != 0 else (i//10)*10
print(amount)

Measured memory_bytes: 3064
#pragma GCC diagnostic ignored "-Wreturn-type"
#include<bits/stdc++.h>
#include<cstdio>
#include<limits>
#define deb(x) cout<<#x<<'='<<(x)<<endl
#define deb2(x,y) cout<<'['<<#x<<'='<<(x)<<','<<#y<<'='<<(y)<<']'<<endl
#define debmap(v) {cout<<#v<<'=';for(auto p:v)cout<<'('<<p.first<<','<<p.second<<") ";cout<<endl;}
#define debarr(a,n) {cout<<#a<<'='; for(int i=0;i<n;i++) cout << a[i] << ' '; cout<<endl;}
#define deb2darr(a,n,m) {cout<<#a<<"=\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<' ';cout<<endl;}}
#define debvec(v) {cout<<#v<<'=';for(auto itr=v.begin();itr!=v.end();itr++)cout<<*itr<<' ';cout<<endl;}
#define deb2dvec(v) {cout<<#v<<"=\n";for(auto x:v){for(auto y:x)cout<<y<<' ';cout<<endl;}}
#define ll long long
#define int long long
#define INF numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()
using namespace std;

int solve(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	sort(v.rbegin(), v.rend());
	int ans=0;
	int k=1; int x=0;
	for(int i=1;i<n;i++){
		if(k==2){
			k = 0;
			x++;
		}
		ans += v[x];
		k++;
	}
	return ans;
}

main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);

	int T=1;
	while(T--){
		cout<<solve()<<endl;
	}
}



Measured memory_bytes: 4812
x,k,d=map(int, input().split()) 
tmp = k

ans = abs(x)%d
k = k - int(abs(x)/d)

if k < 0:
    ans = abs(x)
    ans = ans - (tmp * d)
    print(ans)
    exit()

for i in range(k):
    if abs(ans) <= d and (k-i)%2 == 0:
        print(abs(ans))
        exit()
    elif ans >= 0:
        ans = ans - d
    elif ans < 0:
        ans = ans + d

print(abs(ans))


Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		double x1,y1,x2,y2,x3,y3,xp,yp,r;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		xp=0;
		yp=0;
		double a=y2-y1,b=y3-y1,c=y2-y3,d=x2-x1,e=x3-x1;
		if(y1 != y2 && y1 != y3){
			xp=(c/2-e*(x1+x3)/2/b+d*(x2+x1)/2/a)/(-e/b+d/a);
			yp=-e/b*(xp-(x1+x3)/2)+(y1+y3)/2;
		}else if(y1==y2){
			xp=(x1+x2)/2;
			yp=-e/b*(xp-(x1+x3)/2)+(y1+y3)/2;
		}else if(y1==y3){
			xp=(x1+x3)/2;
			yp=-d/a*(xp-(x1+x2)/2)+(y1+y2)/2;
		}
		r = sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));
		
		printf("%.3lf %.3lf %.3lf\n",xp,yp,r);
	}
	return 0;
}

Measured memory_bytes: 1244