akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = (int)(1e5 + 10);
const int MAX_T = (int)(2e5 + 10);

int n, cha;
int s[MAX_N], t[MAX_N], c[MAX_N];
int tab[MAX_T];
int ans[MAX_T];

int mx = -1;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &cha);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &s[i], &t[i], &c[i]);
  }

  for (int i = 1; i <= cha; ++i) {
    fill(tab, tab + MAX_T, 0);
    for (int j = 0; j < n; ++j) {
      if (c[j] == i) {tab[2 * s[j] - 1]++; tab[2 * t[j]]--;}
    }

    for (int j = 0; j < MAX_T - 1; ++j) {tab[j + 1] += tab[j];}
    for (int j = 0; j < MAX_T; ++j) {
      if (tab[j] > 0) ans[j]++;
      // if (tab[j] > 1) cout << "fu?!" << endl;
    }
  }

  for (int j = 0; j < MAX_T; ++j) {
    mx = max(ans[j], mx);
  }

  printf("%d\n", mx);

  return 0;
}

Measured memory_bytes: 2944
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
list3 = list(map(int, input().split()))
bingo = [list1, list2, list3]
n = int(input())
b_list = []

for i in range(n):
    b_list.append(int(input()))

for i in range(3):
    for j in range(3):
        if bingo[i][j] in b_list:
            bingo[i][j] = 'X'

pattern_list =[]
pattern_list.append(bingo[0])
pattern_list.append(bingo[1])
pattern_list.append(bingo[2])
pattern_list.append([bingo[0][0], bingo[1][0], bingo[2][0]])
pattern_list.append([bingo[0][1], bingo[1][1], bingo[2][1]])
pattern_list.append([bingo[0][2], bingo[1][2], bingo[2][2]])
pattern_list.append([bingo[0][0], bingo[1][1], bingo[2][2]])
pattern_list.append([bingo[0][2], bingo[1][1], bingo[2][0]])

if ['X', 'X', 'X'] in pattern_list:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int main() {
    int n, ans=0;
    string s;
    cin >> n >> s;
    int c = 0;
    rep(i,s.size()) {
        if (s.at(i) == 'I') c++;
        else c--;
        ans = max(ans, c);
    }
    ct(ans);
}

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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define ff(i,x,n) for(ll i=(int)x;i<(int)n;i++)
#define f(i,n) ff(i,0,n)
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)
#define MOD 1000000007

int main(){
	ll n;
	re(n);
	ll l[n];
	f(i, n){
		re(l[i]);
	}
	ll ans = 0;
	f(i, n-2){
		ff(j, i+1, n-1){
			ff(k, j+1, n){
				ll a[3] = {l[i], l[j], l[k]};
				sort(a,a+3);
				if(l[i]==l[j]||l[j]==l[k]||l[i]==l[k])
					continue;
				if(a[0]+a[1]>a[2])
					ans++;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3572
#include <iostream>  
using namespace std;  
int main()  
{ 
	int a,b;
	char s;
	cin>>a>>s>>b;
	if(a>=b && s=='-')
	cout<<a-b;
	else
	if(a<b && s=='-')
	cout<<'-'<<b-a;
	else
	cout<<a+b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(20)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n, k;
	cin >> n >> k;
	bool vis[n + 1] = {false};
	rep(i, 0, k - 1) {
		int a;
		cin >> a;
		rep(i, 0, a - 1) {
			int b;
			cin >> b;
			vis[b] = true;
		}
	}
	int cnt = 0;
	rep(i, 1 , n)
	if (vis[i] == false)
		cnt++;
	cout << cnt;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	int a1,a5,a10,a50,a100,a500;
	cin >> a1 >> a5 >> a10 >> a50 >> a100 >> a500;

	if (a1 + (a5 * 5) + (a10 * 10) + (a50 * 50) + (a100 * 100) + (a500 * 500) >= 1000)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}



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

int main(void) {
	int X; cin >> X;
	int i, j;
	int ans = 1, AA;

	if (X < 4) {
		cout << "1" << endl;
		return 0;
	}
	else{
		for (i = 2; i*i < X; i++) {
			for (j = 2; pow(i, j) <= X; j++) {
				AA = pow(i, j);
				ans = max(ans, AA);
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    string s; cin>>s;
    int n=s.size();

    int ans1=0, ans2=0;
    for(int i=0; i<n; i++){
        if(i % 2 == 0 && s[i] == '0') ans1++;
        if(i % 2 == 1 && s[i] == '1') ans1++;
        if(i % 2 == 0 && s[i] == '1') ans2++;
        if(i % 2 == 1 && s[i] == '0') ans2++;
    }

    cout << min(ans1, ans2) << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  string ans = "No";
  
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      if ( N == (i+1)*(j+1) ) ans = "Yes";
    }
  }
  
  cout << ans << endl;
  
}

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

int main() {
 char a,b,c,d;cin>>a>>b>>c>>d;
  int n;
 if(a=='+') n++;
   else n--;
  
  
  if(b=='+') n++;
   else n--;
  
  if(c=='+') n++;
   else n--;
  
  
  if(d=='+') n++;
   else n--;
  
  cout<<n<<endl;
}




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

using namespace std;

bool is_cat(string::const_iterator &begin, string::const_iterator end) {
	if (begin == end) {
		return true;
	}
	// empty
	if (*begin != 'm') {
		return true;
	}
	begin++;
	if (!is_cat(begin, end)) {
		return false;
	}
	if (begin == end || *begin != 'e') {
		return false;
	}
	begin++;
	if (!is_cat(begin, end)) {
		return false;
	}
	if (begin == end || *begin != 'w') {
		return false;
	}
	begin++;
	return true;
}

int main() {
	string line;
	getline(cin, line);
	auto begin = line.cbegin();
	if (is_cat(begin, line.cend()) && begin == line.cend()) {
		cout << "Cat" << endl;
	}
	else {
		cout << "Rabbit" << endl;
	}
}

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

const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int p = count(s.begin(), s.end(), 'p');
  cout << s.size() / 2 - p << endl;
  return 0;
}


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

int main() {
  int N, a, b, c = 0;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0;i < N;i++) {
    cin >> A[i] >> B[i];
    if(A[i] == B[i]) {
      c++;
      if(c > 2) break;
    }
    if(A[i] != B[i]) c = 0;
  }
  cout << (c > 2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main() {

	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int point_a = 0;
		int point_b = 0;

		for (int i = 0; i < n; ++i) {
			int a, b;
			cin >> a >> b;
			if (a > b) {
				point_a += a + b;
			}
			else if (a < b) {
				point_b += a + b;
			}
			else {
				point_a += a;
				point_b += b;
			}
		}
		cout << point_a << " " << point_b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_NM 202
 
struct D{int r, h;};
 
bool compr(const D& d1, const D& d2){
  return d1.r < d2.r;
}
bool comph(const D& d1, const D& d2){
  return d1.h < d2.h;
}
 
int main(void){
  int n, m, dp[MAX_NM];
  D d[MAX_NM];
 
  while(cin >> n, n){
    for(int i = 0; i < n; i++) cin >> d[i].h >> d[i].r;
    cin >> m;
    for(int i = n; i < n + m; i++) cin >> d[i].h >> d[i].r;
 
    int lis_r = 0, lis_h = 0;
    sort(d, d + n + m, compr);
 
    dp[0] = 1;
    for(int i = 1; i < n + m; i++){
      dp[i] = 1;
      for(int j = 0; j < i; j++){
        if(d[j].r < d[i].r && d[j].h < d[i].h){
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
    }
    lis_r = dp[n+m-1];
 
    sort(d, d + n + m, comph);
 
    dp[0] = 1;
    for(int i = 1; i < n + m; i++){
      dp[i] = 1;
      for(int j = 0; j < i; j++){
        if(d[j].r < d[i].r && d[j].h < d[i].h){
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
    }
    lis_h = dp[n+m-1];
 
    cout << max(lis_h, lis_r) << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, X, M;
  cin >> N >> X >> M;
  vector<i64> A(M + 2), sum(M + 2), ind(M + 1, -1);
  A[1] = X;
  sum[1] = X;
  ind[X] = 1;
  i64 loopStart, loopSize;
  for (i64 i = 2; i <= M + 1; i++)
  {
    A[i] = (A[i - 1] * A[i - 1]) % M;
    sum[i] = sum[i - 1] + A[i];
    if (i == N)
    {
      cout << sum[i] << endl;
      return 0;
    }
    if (ind[A[i]] != -1)
    {
      loopStart = ind[A[i]];
      loopSize = i - ind[A[i]];
      break;
    }
    ind[A[i]] = i;
  }
  i64 ans = 0;
  i64 loopCnt = (N - loopStart) / loopSize;
  ans += loopCnt * (sum[loopSize + loopStart] - sum[loopStart]);
  N -= loopSize * loopCnt;
  ans += sum[N];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
int l[1001];
int dfs(int k,int aa,int bb,int cc){
    if(k==n){
        if (aa == 0 || bb == 0 || cc == 0) return 1e9;
        return abs(aa-a)+abs(bb-b)+abs(cc-c);
    }
    int res = 1e9;
    res = min(res,dfs(k+1,aa+l[k],bb,cc)+(aa>0 ? 10:0));
    res = min(res,dfs(k+1,aa,bb+l[k],cc)+(bb>0 ? 10:0));
    res = min(res,dfs(k+1,aa,bb,cc+l[k])+(cc>0 ? 10:0));
    res = min(res,dfs(k+1,aa,bb,cc));
    return res;
}
int main(){
    cin>>n>>a>>b>>c;
    for(int i = 0; i<n;i++){
        cin>>l[i];
    }
    int res = dfs(0,0,0,0);
    cout<<res<<endl;
    return 0;
}

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

using namespace std;
int main() {
	int K;
	string s;


	cin >> s >> K;

	int len = s.length();

	vector<string>  sub;



	for (int i = 0; i < len; i++) {
		sub.push_back(s.substr(i, len));
	}

	sort(sub.begin(), sub.end());
	for (int i = 0; i < sub.size(); i++) {
	}

	vector<string> used_string;

	int kk = 0;
	int array_index = 0;
	int str_index = 1;
	while(true) {
		string cur = sub[array_index].substr(0,str_index);
		bool is_used = false;
		for (auto used : used_string) {
			if (used == cur) {
				is_used = true;
				break;
			}
		} 
		if (!is_used) {
			used_string.push_back(cur);
			kk++;
			if (kk == K) {
				cout << cur << endl;
				break;
			}
		}
		
		

		if (str_index == sub[array_index].length()) {
			str_index = 1;
			array_index ++;
			continue;
		}
 		str_index++;
	}

	return 0;

}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL comb2(int n){
  return n*(n-1)/2;
}
int main() {
  LL N, M;
  cin >> N >> M;
  cout<<comb2(N)+comb2(M)<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a=0,i=1;
    while(true){
      a = sc.nextInt();
      if(a==0) break;
      System.out.println("Case "+ i +": "+ a);
      i++;
    }
    sc.close(); 
  }
  
}


Measured memory_bytes: 41584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    int n=s.length();int cnt=0;
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A___The_Number_of_Even_Pairs
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_M = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = N_M[0], M = N_M[1];
            int ans = 0;

            if (N > 1) ans += N * (N - 1) / 2;
            if (M > 1) ans += M * (M - 1) / 2;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{

        //List<int> a = new List<int>();
        //List<int> b = new List<int>();

        string[] s = Console.ReadLine().Split(' ');

        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        int c = int.Parse(s[2]);
        int sum = 0;

        for(int i = a;i <= b;i++)
        {
            if (c % i == 0) sum++;
        }

        Console.WriteLine("{0}",sum);

		//Console.WriteLine("");


	}
}

Measured memory_bytes: 9224
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<fstream>
#include <map>
#include<math.h>
using namespace std;


int main(){
	std::istream & c_in = cin;
	int k;
	c_in >> k;
	map<int, int> all;
	while (k-- > 0)
	{
		map<int, int> t;
		int a;
		c_in >> a;
		int i = 2;
		while (a != 1)
		{
			if ((a % i) == 0) {
				a /= i;
				//cout << " " << i;
				if (t.find(i) == t.end()){
					t.insert(pair<int, int>(i, 0));
				}
				t.find(i)->second++;
				continue;
			}
			i += 1 + (i & 1);
			if (i > ::sqrt(a))
			{
				//cout << " " << a;
				if (t.find(a) == t.end()){
					t.insert(pair<int, int>(a, 0));
				}
				t.find(a)->second++;
				break;
			}
		}
		//marge(all, t);
		for (map<int, int>::iterator p = t.begin(); p != t.end(); ++p)
		{
			if (all.find(p->first) == all.end()){
				all.insert(pair<int, int>(p->first, 0));
			}
			map<int, int>::iterator q = all.find(p->first);
			if (q->second < p->second){
				q->second = p->second;
			}
		}
	}
	int x = 1;
	for (map<int, int>::iterator r = all.begin(); r != all.end(); ++r)
	{
		x *= pow(r->first, r->second);
	}
	cout << x << endl;
}

Measured memory_bytes: 1240
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

#define ODD true
#define EVEN false

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N)cin >> a[i];
	int ans = 1;

	int k = 0;
	while(a[k]!=2) {
		k = a[k] - 1;
		ans++;
		if (k == 0 || ans>N) {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,s,x[SZ],os[SZ],on;
ll p[SZ];
int main()
{
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;++i)
		scanf("%d%lld",x+i,p+i);
	int l=1,r=n;
	while(x[l]<s&&s<x[r])
	{
		if(p[l]>=p[r])
			p[l]+=p[r],os[++on]=x[r--];
		else p[r]+=p[l],os[++on]=x[l++];
	}
	if(x[l]>=s)
		for(int i=r;i>=l;--i) os[++on]=x[i];
	else
		for(int i=l;i<=r;++i) os[++on]=x[i];
	os[++on]=s; reverse(os+1,os+1+on);
	ll ans=0;
	for(int i=2;i<=on;++i)
		ans+=abs(os[i]-os[i-1]);
	printf("%lld\n",ans);
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N>>M>>S;
    mat ab(N, vec(2,0)), G(N, vec(0));
    rep(i,M){
        cin>>A>>B;
        --A; --B;
        G[B].push_back(A);
        G[A].push_back(B);
        ++ab[A][S[B] - 'A'];
        ++ab[B][S[A] - 'A'];
    }
    vector<bool> del(N,false);
    queue<ll> que;
    rep(i,N){
        rep(j,2){
            if(ab[i][j] == 0 && !del[i]) {
                del[i] = true;
                que.push(i);
            }
        }
    }
    while(!que.empty()){
        ll v = que.front(), c = S[v] - 'A';
        que.pop();
        for(ll to : G[v]){
            if(!del[to]){
                if(--ab[to][c] == 0){
                    del[to] = true;
                    que.push(to);
                }
            }
        }
    }
    ll ans = N;
    rep(i,N) ans -= del[i];
    cout<<(ans == 0 ? "No" : "Yes")<<endl;
}

Measured memory_bytes: 22916
#include<iostream>
using namespace std;
const int mod=1e9+7; 
long long res;
long long n,k;
int main(){
	res = 0;
	cin>>n>>k;
	while(k<=n+1){
		long long qian=((k-1)*k/2)%mod,hou=((2*n%mod-k%mod+1)*k/2)%mod;
		res=(res+hou-qian+1+mod)%mod;
		k++;
	} 
	cout<<res;
}

Measured memory_bytes: 3160
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

D = 'SUN,MON,TUE,WED,THU,FRI,SAT'.split(',')

dic = {x:7 - i%7 for i,x in enumerate(D)}

answer = dic[S]
print(answer)

Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	int number[10] = {63, 6, 91, 79, 102, 109, 125, 39, 127, 111};
	int show;
	int n;
	int i, j;
	int in;
	
	while (1){
		scanf("%d", &n);
		
		if (n == -1){
			break;
		}
		
		show = 0;
		
		for (i = 0; i < n; i++){
			scanf("%d", &in);
			show ^= number[in];
			for (j = 6; j >= 0; j--){
				printf("%d", (show >> j) & 1);
			}
			printf("\n");
			show = number[in];
		}
	}
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint L=5001;
struct djk{
  djk(int n):n(n),c(n),d(n,inf){
  }
  void add(int s,int t,lint v){
    c[s].push_back(make_pair(v,t));
  }
  void solve(int start){
    q.push(make_pair(0,start));
    d[start]=0;
    while(!q.empty()){
      auto p=q.top();
      q.pop();
      lint pv=p.first;
      int pt=p.second;
      if(d[pt]>pv)continue;
      for(auto e:c[pt]){
        lint ev=e.first;
        int et=e.second;
        if(d[et]>d[pt]+ev){
          d[et]=d[pt]+ev;
          q.push(make_pair(d[et],et));
        }
      }
    }
  }
  const lint inf =1e15;
  int n;
  using edge=pair<lint,int>;
  vector<vector<edge> > c;
  vector<lint> d;
  priority_queue<edge,vector<edge>,greater<edge> > q;
};

int main(){
  lint N,M,S;
  cin>>N>>M>>S;
  djk djk(N*L);
  REP(i,M){
    lint U,V,A,B;
    cin>>U>>V>>A>>B;
    U--;V--;
    REP(l,L)if(l>=A){
      djk.add(U*L+l,V*L+l-A,B);
      djk.add(V*L+l,U*L+l-A,B);
    }
  }
  REP(i,N){
    lint C,D;
    cin>>C>>D;
    REP(l,L){
      djk.add(i*L+l,i*L+min(L-1,l+C),D);
    }
  }
  djk.solve(min(S,L-1));
  FOR(i,1,N){
    lint ans=djk.d[i*L];
    REP(l,L)ans=min(ans,djk.d[i*L+l]);
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 44460
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define pb push_back
#define pi pair <int, int> 

int n, y;
int32_t main() {
	cin >> n >> y;
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= n; ++j) {
			int k = n - i - j;
			if (10000*i + 5000*j + 1000*k == y && k >= 0) {
				cout << i << ' ' << j << ' ' << k;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1";
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<ll> a(n), b(n);
	vector<pair<ll, int>> c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i] = { a[i] + b[i], i };
	}
	sort(c.rbegin(), c.rend());
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int idx = c[i].second;
		if (i % 2 == 0) {
			ans += a[idx];
		}
		else {
			ans -= b[idx];
		}
	}
	cout << ans << endl;
	return 0;
}

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

const int N = 1000;
vector< vector<int> > G(N);
int d[N],visited[N];

void bfs(){

  fill(d+2,d+N,N);
  queue<pair<int,int>> q;
  q.push({1,1});
  while(!q.empty()){
    auto p = q.front(); q.pop();
    int s = p.first;
    int cnt = p.second;
    for(int i = 0; i < G[s].size(); i++){
      int v = G[s][i];
      d[v] = min(d[v],cnt);
      if(!visited[v]) q.push({v,cnt+1});
      visited[v] = 1;
    }
  }
}

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

  int n; cin >> n;
  for(int i = 0; i < n; i++){
    int u,k; cin >> u >> k;
    for(int j = 0; j < k; j++){
      int v; cin >> v;
      G[u].push_back(v);
    }
  }

  bfs();
  for(int i = 1; i <= n; i++){
    if(d[i] != N) cout << i << " " << d[i] << endl;
    else cout << i << " " << -1 << endl;
  }

  return 0;
}



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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    ll n;
    cin >> n;

    ll sol = n-1;
    for(ll d = 2; d*d<=n; d++){
        if (n%d == 0){
            sol = min(sol, d-1 + n/d-1);
        }
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

int N;
string S;
int main (){
    cin >> N >> S;
    int putLast = 0;
    int putFirst = 0;
    int now = 0;

    for(int i=0; i<N; i++){
        if ( S[i] == '(' ) {
            now++;
        } else {
            now--;
            if(now < 0 ) {
                putFirst++;
                now = 0;
            }
        }
    }

    for(int i=0; i<putFirst; i++){
        cout << '(' ;
    }

    cout << S ;

    for(int i=0; i<now; i++){
        cout << ')' ;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

int N;
ll a[10010],b[10010];
ll sum;
int main(){
    cin>>N;
    REP(i,0,N){
        cin>>a[i];
    }
    REP(i,0,N){
        cin>>b[i];
    }
    REP(i,0,N){
        if(a[i] < b[i])sum += abs(a[i]-b[i]) / 2;
        else sum -= (a[i]-b[i]);
    }
    if(sum>=0){
        p("Yes");
    }else{
        p("No");
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        Set<String> set = new HashSet<>();
        String[] a = sc.nextLine().split(" ",0);
        for(int i = 0;i<n;i++){
            set.add(a[i]);
        }
        int answer = 0;
        if(set.contains("Y") == true){
            answer++;
        }
        if(set.contains("G") == true){
            answer++;
        }
        if(set.contains("W") == true){
            answer++;
        }
        if(set.contains("P") == true){
            answer++;
        }
        if(answer >= 4){
            System.out.println("Four");
        }else{
            System.out.println("Three");
        }
    }
}

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

int main(void){

    int n;
    long long int a[200000];

    int i, j;

    unsigned long long int total, ans, mul;

    total = 0;
    ans = 0;

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

    for(i=0;i<n;i++){
        total -= a[i];
        mul = (total % 1000000007);
        ans += a[i] * mul;
        ans = (ans % 1000000007);
    }

    cout << (ans % 1000000007);

    return 0;

}

Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    string s;
    int K;
    cin >> s >> K;
    vector<string> ss;
    rep(i, s.size()){
        for(int j = 1; j <= K && i + j <= s.size(); j++){
            string tmp = s.substr(i, j);
            ss.push_back(tmp);
        }
    }
    string ans;
    sort(ss.begin(), ss.end());
    unique(ss.begin(), ss.end());
    cout << ss[K - 1] << endl;
    return 0;
}


Measured memory_bytes: 1660
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll n,k,x,y;
    cin>>n>>k>>x>>y;
    ll sum=0;
    ll p=n;
    n-=k;
    if(n<=0){
        cout<<x*p<<endl;
    }
    else{
        sum+=x*k;
        sum+=(n*y);
        cout<<sum<<endl;
    }
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3552
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define mr  make_pair

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n,m;
       cin>>n>>m;
       int xx = n%m;
       cout<<min(xx,abs(xx-m));
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

bN = [0] * N
if N % 2 == 0:
    for i in range(N):
        if i % 2 == 0:
            bN[(N//2) + i//2] = str(aN[i])
        else:
            bN[(N//2) - (i+1)//2] = str(aN[i])
else:
    for i in range(N):
        if i % 2 == 0:
            bN[(N//2) - i//2] = str(aN[i])
        else:
            bN[(N//2) + (i+1)//2] = str(aN[i])

print(" ".join(bN))

Measured memory_bytes: 31940
def Main(A, N, B):
    BINGO = (
        (0,1,2),
        (3,4,5),
        (6,7,8),
        (0,3,6),
        (1,4,7),
        (2,5,8),
        (0,4,8),
        (2,4,6)
        )
    ans_ind = []
    for e in B:
        if e in A:
            ans_ind.append(A.index(e))
    if len(ans_ind) <= 2:
        return "No"
    else:
        for b in BINGO:
            counter = 0
            for c in b:
                if c in ans_ind:
                    counter += 1
                if counter == 3:
                    return "Yes"
    return "No"
                    
                

def main():
    A = []
    for i in range(3):
        A += list(map(int, input().split()))
    N = int(input())
    B = []
    for i in range(N):
        B.append(int(input()))
    print(Main(A, N, B))

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
    int h,w,k;
    cin>>h>>w>>k;
    long hn=(1<<h)-1;
    long wn=(1<<w)-1;
    long ans=0;
    char arr[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++){
            cin>>arr[i][j];
        }
    }    
    for(int i=0;i<=hn;i++){
        for(int j=0;j<=wn;j++){
            int tmp=0;
            for(int i1=0;i1<h;i1++){
                for(int j1=0;j1<w;j1++){
                    if(arr[i1][j1]=='#'&&(!((i&(1<<i1))||(j&(1<<j1))))){
                        tmp++;
                        // cout<<
                    }
                }
            }
            if(tmp==k){
                ans++;
            }
        }
    }
    cout<<ans;
}

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

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N, W;
    cin >> N >> W;

    vector<size_t> w(N), v(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    const size_t value_max = size_t(1e5);
    auto dp = make_v(LINF, N + 1, value_max + 1);
    dp[0][0] = 0;
    for (size_t i = 0; i < N; ++i) {
        for (size_t value = 0; value <= value_max; ++value) {
            chmin(dp[i + 1][value], dp[i][value]);
            if (value >= v[i]) {
                chmin(dp[i + 1][value], dp[i][value - v[i]] + w[i]);
            }
        }
    }

    size_t res = 0;
    for (size_t value = 0; value <= value_max; ++value) {
        if (dp[N][value] <= W) {
            res = value;
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, sum = 0;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n-1);

	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> c.at(i);
	}

	for (int i = 0; i < n; i++) {
		sum += b.at(a.at(i) - 1);
		if (i != n - 1) {
			if (a.at(i) + 1 == a.at(i + 1)) {
				sum += c.at(a.at(i) - 1);
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[][] dis;
	
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),m=sc.nextInt();dis=new long[n+1][n+1];
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				dis[i][j]=Integer.MAX_VALUE;
			}
			dis[i][i]=0;
		}
		List<Node> list=new ArrayList<Node>();
		for(int i=1;i<=m;i++)
		{
			int u=sc.nextInt(),v=sc.nextInt(),cost=sc.nextInt();dis[u][v]=dis[v][u]=Math.min(cost,dis[u][v]);
			list.add(new Node(u,v,cost));
		}
		for(int k=1;k<=n;k++)
		{
			for(int i=1;i<=n;i++)
			{
				for(int j=1;j<=n;j++)
				{
					dis[i][j]=Math.min(dis[i][j],dis[i][k]+dis[k][j]);
				}
			}
		}
		int ans=0;
		for(int i=0;i<list.size();i++)
		{
			int u=list.get(i).u,v=list.get(i).v,cost=list.get(i).cost;
			if(cost==dis[u][v])
			{
				continue;
			}
			ans++;
		}
		out.println(ans);out.close();
    }
}
class Node
{
	int u,v,cost;
	public Node(int u,int v,int cost)
	{
		this.u=u;this.v=v;this.cost=cost;
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 9428
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<string> s(n);
    for(int i=0; i<n; ++i)
        cin >> s[i];

    sort(s.begin(), s.end());
    for(int i=0; i<n; ++i)
        cout << s[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
  size = int(input())
  value = list(map(int, input().split()))
  cost = list(map(int, input().split()))
  diff = [value[i]-cost[i] for i in range(len(value))]
  diff.sort(reverse=True)
              
  sum = 0
  for i in range(len(value)):
    if diff[i] > 0:
      sum += diff[i]
    else: 
      break
        
  print(sum)

main()
              

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
from functools import partial, reduce
from operator import mul
prod = partial(reduce, mul)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

fibo = [1, 1]
for i in range(2, 9):
    fibo.append(fibo[i - 1] + fibo[i - 2])

def main():
    N = II()
    ans = int(N ** 0.5) ** 2
    return ans

print(main())

Measured memory_bytes: 3572
while True:
    ans = 0
    n, x = map(int, input().split())
    if n == x == 0:
        break
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    ans += 1
    print(ans)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

map<int,vi> link;
map<int,int> add;
vi ans;
vector<bool> visited;

void dfs(int v, int a) {
    // printf("v:%d a:%d\n",v,a);
    a += add[v];
    ans[v] += a;
    visited[v] = true;
    for(auto c : link[v]) {
        if(visited[c]) continue;
        dfs(c,a);
    }
}

int main() {
    int n; cin >> n;
    int total = 0;
    int mins = 100000;
    rep(i,n) {
        int s;cin >> s;
        total += s;
        if(s%10) {
            mins = min(s,mins);
        }
    }
    int ans = total%10?total:max(0,total-mins);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main(){
  int S,s,m,h;
  cin >> S;
  s = S%60;
  S /= 60;
  m = S%60;
  h = S/60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N,M;scanf("%lld %lld",&N,&M);
    vl candidate;
    repl(i,1,sqrt(M)+2){
        if(M%i==0){
            candidate.push_back(i);
            candidate.push_back(M/i);
        }
    }
    sort(all(candidate));
    per(i,candidate.size()){
        if(candidate[i]<=M/N){
            cout<<candidate[i]<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    int n;
	cin>>n;
	
	vector<double> p(n+1);
	for(int i=1;i<=n;i++)
		cin>>p[i];
	
	vector<vector<double>> dp(n+1, vector<double>(n+1,0.0));
	
	dp[0][0]=1.0;
	
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
		{
			if(j==0)
			{
				dp[i][j] = (1-p[i]) * dp[i-1][j];
			}
			else
			{
				dp[i][j] = (p[i])*dp[i-1][j-1] + (1-p[i]) * dp[i-1][j];
			}
				
		}
	
	double ans = 0.0;
	for(int i=n;i>n/2;i--)
		ans+=dp[n][i];
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 70784
my $s = <STDIN>;
chomp $s;
my ($n, $p) = split ' ', $s;
my @str = reverse <> =~ /./g;
my @c = 1;
my $t = 1;
my $output = '';
foreach my $i (@str) {
    $output += (10 % $p) ? $c[$a = ($a + $i * $t) % $p]++ : $n-- * !($i % $p);
    $t = $t * 10 % $p;
}
print $output;

Measured memory_bytes: 32256
import std.stdio, std.array, std.conv;

void main()
{
  int[] integers;
  int x;
  int y;
  int z;
  
  integers = readln.split.to!(int[]);
  x = integers[0];
  y = integers[1];
  z = integers[2];
  
  writeln(z, ' ', x, ' ', y);
}


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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        ans += min(b, (x[i + 1] - x[i]) * a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
n=int(input())
s1=input()
s2=input()
mod=10**9+7
if s1[0]==s2[0]:
  cnt=3
  flag=0
  i=1
else:
  cnt=6
  flag=1
  i=2
while i<n:
  if s1[i]==s2[i] and flag==0:
    i+=1
    cnt*=2
  elif s1[i]==s2[i] and flag==1:
    i+=1
    flag=0
  elif s1[i]!=s2[i] and flag==0:
    i+=2
    cnt*=2
    flag=1
  else:
    i+=2
    cnt*=3
  cnt%=mod
print(cnt%mod)

Measured memory_bytes: 61812
#include <bits/stdc++.h>
using namespace std;
string s;
int a,b,c;

int main(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='a'){
			a++;
		}else if(s[i]=='b'){
			b++;
		}else{
			c++;
		}
	}
	int t;
	t=min(a,min(b,c));
	a-=t;
	b-=t;
	c-=t;
	if(a<2&&b<2&&c<2){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512