akhauriyash/Code-Regression huggingface dataset:
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

/*
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
Tree<int>tr;
*/

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int n,a[105],b[105],c[100],ans;

int32_t main(){_
	//freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++) b[i] = 1e9;
	for(int i = 1;i < n;i++){
		cin >> a[i];
		b[i] = min(b[i],a[i]);
		b[i + 1] = min(b[i + 1],a[i]);
	}
	for(int i = 1;i <= n;i++) ans += b[i];
	rc(ans);
	return 0;
}











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

int a[10],x;
char c;

int main()
{
    while(cin >> c && c != '\0')
    {
        if(c =='0') a[x++] = 0;
        else if(c == '1') a[x++] = 1;
        else
        {
            if(x) x--;
        }
    }
    if(x)
    {
        for(int i = 0;i < x;i++) cout << a[i];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

import collections
c = collections.Counter(A)
a = 0

for i,j in c.items():
    a += j *(j-1) //2
#print('===', a)
for k in range(n):
    nn = c[A[k]]
    ans = a -(nn-1)
    print(ans)



Measured memory_bytes: 24748
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 998244353;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

LL modpow(LL a, LL n, LL m) {
	LL r = 1;
	while(n != 0) {
		if(n&1)	r = (r*a)%m;
		a = (a*a)%m;
		n >>= 1;
	}
	return r;
}

const LL MAXN = 310, MAXSUM = 90000 + 10;
LL dp[MAXN][MAXSUM], dp2[MAXN][MAXSUM];

int main() {
	sll(n);
	LL nums[n], sum = 0;
	rep(i, 0, n) { 
		nums[i] = scanLong();
		sum += nums[i];
	}
	LL ans = modpow(3, n, MOD);
	rep(i, 0, n+1) {
		rep(j, 0, sum+1) {
			if(i == 0)	dp[i][j] = (j == 0 ? 1 : 0);
			else if(j == 0)	dp[i][j] = modpow(2, i, MOD);
			else if(nums[i-1] <= j)	dp[i][j] = 2*dp[i-1][j] + dp[i-1][j-nums[i-1]];
			else	dp[i][j] = 2*dp[i-1][j];
			dp[i][j] %= MOD;

			if(i == 0)	dp2[i][j] = (j == 0 ? 1 : 0);
			else if(j == 0)	dp2[i][j] = 1;
			else if(nums[i-1] <= j)	dp2[i][j] = dp2[i-1][j] + dp2[i-1][j-nums[i-1]];
			else	dp2[i][j] = dp2[i-1][j];
			dp2[i][j] %= MOD;

			if(i == n && 2*j >= sum) {
				ans -= 3*dp[i][j];
				while(ans < 0)	ans += MOD;
			}
			if(i == n && 2*j == sum) {
				ans += 3*dp2[i][j];
				ans %= MOD;
			}
		}
	}
	pll(ans); nl;
}


Measured memory_bytes: 426240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int M= sc.nextInt();
		int N = sc.nextInt();
		int M2= sc.nextInt();
		if (M!=M2) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdbool.h>

int main(void) {
	char set[] = "ACGT";

	char s[11];
	scanf("%s", s);

	int cur = 0, max = 0;

	int i = 0;
	while (s[i] != '\0') {
		bool found = false;
		for (int j = 0; j < sizeof(set); j++) {
			if (s[i] == set[j]) {
				found = true;
				break;
			}
		}

		if (found) {
			if (++cur > max) max = cur;
		} else cur = 0;
		i++;
	}

	printf("%d\n", max);
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
a1 = a[0]
a2 = a[1]
for i in range(2, n-1):
    if min(a1 - a2, a2)  < min(a1 - a[i], a[i]):
        a2 = a[i]
print(a1, a2)
    

Measured memory_bytes: 14060
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N, A, B; scanf("%d%d%d", &N, &A, &B);

	printf("%d %d"
		, min(A, B)
		, max(A + B - N, 0));

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

// 答えを見たよ。
int calc(int N, int K, int b) {
    int p = N / b;
    int r = N % b;

    // a % b >= K であるようなaの種類
    // (0 <= a <= N)
    int ans = p * max(0LL, b - K) + max(0LL, r - K + 1);

    // 0 % b => K であるものをカウントしてしまっているので引く
    if (K == 0) {
        ans -= 1;
    }

    return ans;
}

signed main() {
    int N, K;

    cin >> N >> K;

    int ans = 0;
    FORE(b, 1, N) {
        ans += calc(N, K, b);
    }

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


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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if(K >= S.size()){
    cout << S << endl;
  }else{
    for(int i= 0; i < K; i++){
      cout << S[i];
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3624
import math
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(0,len(l)-1):
    for j in range(i+1,len(l)):
        sum_num=0
        for k in range(d):
            sum_num+=(l[i][k]-l[j][k])**2
        sum_num=math.sqrt(sum_num)
        if int(sum_num)==sum_num:
            cnt+=1
print(cnt)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
  int k; cin >> k;
  if (e - a <= k) cout << "Yay!" << '\n';
  else cout << ":(" << '\n';
}

Measured memory_bytes: 256
//============================================================================
// Name        : TopCoderCompetition.cpp
// Author      : taguchi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <numeric>
using namespace std;
#define P pair<int,int>
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(n) push_back(n)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
struct edge{int cost,to;};

vector<string> split(string &in,char delimiter){
	vector<string> re; uint cur = 0,next;
	while((next = in.find_first_of(delimiter,cur)) != string::npos){
		re.pb(string(in,cur,next-cur));
		cur = next + 1;
	}
	re.pb(string(in,cur,in.size()-cur));
	return re;
}
vector<int> split_int(string &in, char delimiter){
	vector<string> str = split(in,delimiter);
	vector<int> re;
	rep(i,str.size()){
		re.pb(strtol(str[i].c_str(),NULL,10));
	}
	return re;
}





int N,M;
int h[210],r[210];
int mem[210];
bool used[210];
int solve(int p){
	if(mem[p]) return mem[p];
	used[p] = true;
	int ans = 1;
	for(int i = 0;i<N+M;i++){
		if(h[p] > h[i] && r[p] > r[i] && !used[i]){
			ans = max(ans,solve(i) + 1);
		}
	}
	used[p] = false;
	return mem[p] = ans;
}

int main(){
	while(true){
		cin >> N;
		if(!N) break;
		rep(i,N){
			cin >> h[i] >> r[i];
		}
		cin >> M;
		rep(i,M){
			cin >> h[i+N] >> r[i+N];
		}
		memset(mem,0,sizeof(mem));
		int ans = 0;
		rep(i,N+M){
			ans = max(ans,solve(i));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#ifdef DEBUG
  #include "debug.hpp"
#else
  #define DUMP(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
using value_type = typename iterator_traits<FwdIter>::value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int main(const int /*argc*/, char ** /*argv*/) {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

  constexpr uint64_t mod = 1000000007ULL;
  size_t n;
  string str;
  cin >> n >> str;

  uint64_t out = 1;
  uint64_t k = 0;
  for (const auto c: str) {
    if (c == 'W') {
      if (k & 1) {
        ++k;
      } else {
        out = out * k % mod;
        --k;
      }
    } else {  // 'B'
      if (k & 1) {
        out = out * k % mod;
        --k;
      } else {
        ++k;
      }
    }
  }
  DUMP(k);
  DUMP(out);
  if (k != 0) {
    out = 0;
  }

  for (size_t i = 1; i <= n; ++i) {
    out = out * i % mod;
  }
  cout << out;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 720
#include <iostream>

int main(int argc, char const* argv[])
{
	int a, b, c, N=0;
	std::cin >> a >> b >> c;

	for (int i = a; i <= b; i++)
		if (c % i == 0) N++;

	std::cout << N << std::endl;
	return 0;
}



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

using namespace std;

int main(){
    int N;
    double price=0;
    cin >> N;
    vector<double> x(N);
    vector<string> u(N);
    for(int i=0;i<N;i++){
        cin >> x.at(i) >> u.at(i);
    }

    for(int i=0;i<N;i++){
        if(u.at(i)=="JPY"){
            price += x.at(i);
        }
        else
        {
            price += x.at(i)*380000;
        }
        
    }
    cout << price << endl;

}

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

int main(){
    int n;
    set<string> st;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
//        scanf("%s", s);
        st.insert(s);
    }

    printf("%d\n", st.size());

    return 0;
}




// int main(void){
//     long int n = 0; 
//     char s[200001][11]; 
//     long int cnt = 0;

//     scanf("%d", &n);
//     scanf("%s", s[0]);
// //    printf("s = %s\n", s);

//     for(long int i = 1; i < n; i++){
//         char temp[11];
//         scanf("%s", temp);
// //        printf("temp = %s\n", temp);

//         for(long int j = 0; j <= cnt; j++){
// //            printf("temp = %s s = %s cnt = %d strlen() = %d\n", temp, s[j], j, strlen(temp));
//             if(strcmp(s[j], temp) == 0){
// //                printf("==\n");
//                 break;
//             }else{
// //                printf("=!\n");
//                 cnt++;
//                 strcpy(s[cnt], temp);
//                 break;
//             }
//             // for(int k = 0; k < strlen(temp); k++){
//             //     if(temp[k] != s[j][k]){
//             //         cnt++;
//             //         strcpy(s[cnt], temp);
//             //         break;
//             //     }
//             //     if((k + 1) == strlen(temp) ){
//             //         break;
//             //     }
//             // }
//         }

//     }
//     cnt++;
//     printf("%d\n", cnt);

//     return 0;

// } 


Measured memory_bytes: 19416
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli n,i;
	cin>>n;
	lli a[n],cur_max,ans=0;
	for(i=0;i<n;i++)
		cin>>a[i];
	cur_max=a[0];
	for(i=1;i<n;i++)
	{
		ans+=max((lli)0,cur_max-a[i]);
		cur_max=max(a[i],cur_max);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	string s;
	cin>>s;
	int x=200000,y;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A')x=min(i,x);
		if(s[i]=='Z')y=i;
	}
	cout<<y-x+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#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;
 
 
 typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell=998244353;
 
 int power(int a,int b)
 {
  if(b==0)return 1LL;
  if(b==1)return a;
  int t=power(a,b/2);
  t*=t;
  t%=hell;
  if(b&1)return (t*a)%hell;
  else return t;
 }
 int inverse(int a)
 {
    return power(a,hell-2);
 }
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;
    a%=10000000000LL;}
  return a;
}
 
int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}
 
bool cmp(pii a,pii b)
{
  return a.SS<b.SS;
}
 
 
int solve()
{  

int n;

cin>>n;
int ans=0;

rep(i,1,n+1)
{
    int j=i,cnt=0;
    while(j!=0)
    {
        cnt++;
        j/=10;
    }
    if(cnt%2)ans++;
}

cout<<ans;

return 0;
}
 
signed main()
{  int t=1;
//pri();
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
 
 

 
  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
 //cin>>t;
 
    int k=1;
     
   while(t--)
     {
      //cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
} 

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

int main(){
 int N,t=0;
  cin>>N;
  vector<int>w(N);
  
    vector<int>vec(N);
  for(int i=0 ;i<N;i++){
  cin>>w.at(i);
  t+=w.at(i);
    vec.at(i)=t;
  }
  vector<int>ans(N);
  for(int i=0 ;i<N;i++){
  if(t-vec.at(i)-vec.at(i)>0)
    ans.at(i)=t-vec.at(i)-vec.at(i);
    else
   ans.at(i)=-t+vec.at(i)+vec.at(i);
    
  }
  
    
  	sort(ans.begin(), ans.end());
  cout<< ans.at(0) <<endl;
  
  
}

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

using namespace std;
using ll = long long;

set<int> grp;
vector<bool> checked_lang;

template <typename T>
void func(int lang, const T& L, const T& can_speak_L) {
	for (int i = 0; i < can_speak_L[lang].size(); ++i) {
		int p = can_speak_L[lang][i];
		if (grp.count(p)) { continue; }
		grp.insert(p);
		for (int j = 0; j < L[p].size(); ++j) {
			int l = L[p][j];
			if (checked_lang[l]) { continue; }
			checked_lang[l] = true;
			func(l, L, can_speak_L);
		}
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> K(N);
	vector<vector<int>> L(N);
	vector<vector<int>> can_speak_L(M);
	for (int i = 0; i < N; ++i) {
		cin >> K[i];
		L[i].resize(K[i]);
		for (int j = 0; j < K[i]; ++j) {
			cin >> L[i][j];
			can_speak_L[--L[i][j]].push_back(i);
		}
	}

	checked_lang.resize(M, false);
	for (int i = 0; i < M; ++i) {
		if (can_speak_L[i].size() > 0) {
			func(i, L, can_speak_L);
			break;
		}
	}

	if (grp.size() == N) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }

	return 0;
}


Measured memory_bytes: 13560
h=0
i=0
j=0
a=[]

r,c = list(map(int,input().split()))
for h in range(c+1):
    a.append(0)
    h+=1
for i in range(r):
    I= list(map(int,input().split()))
    I.append(sum(I))
    print(*I)
    for j in range(c+1):
        
        a[j]=a[j]+I[j]
        #print(a[j])
        j+=1
    i+=1
    j=0
    
    
        
print(*a)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int MAX = 2e5+10, MAXL = 20;
ll n, cnt;


int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	if (n % 10 == (n/100))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
x, y = [int(x) for x in input().split()]
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]
for i in [A, B, C]:
    if x in i and y in i:
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
    }
    if n % k == 0 {
        println!("{}", 0);
    } else {
        println!("{}", 1);
    }
}


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

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll cnt = n / (a + b);
    ll amari = n % (a + b);
    /*
    int x = 0;
    if(a <= amari) x = amari;
    else x = a;
    */
    cout << cnt * a + min(amari, a) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 2e5+2;

int n;
ll a[MM], tot, ans = LLONG_MAX;

int main(){
    
    scan(n);
    
    for(int i = 1; i <= n; i++){
        scan(a[i]);
        a[i] += a[i-1];
    }
    double v = a[n]/2.0;
    for(int i = 1; i < n; i++){
        ans = min(ans, (ll)(2*abs(v-a[i])));
    }
    
    print(ans);
    
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int n,q,sum[200005],visit[200005],ans[200005];
vector <int> dis[200005];
queue <int> que;

void bfs(int from){
	que.push(from);
	visit[from]=1;
	while(!que.empty()){
		int u=que.front();
		que.pop();
		int len=dis[u].size();
		for(int i=0;i<len;i++){
			int t=dis[u][i];
			if(visit[t]==from)continue;
			que.push(t);
			ans[t]+=ans[u];
			visit[t]=from;
		}
	}
}

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')
	s=s*10+c-'0',c=getchar();
	return s*t;
}

int main(void){
	n=read();
	q=read();
	for(int i=1;i<n;i++){
		int a,b;
		a=read();
		b=read();
		dis[a].push_back(b);
	}
	for(int i=1;i<=q;i++){
		int a,b;
		a=read();
		b=read();
		ans[a]+=b;
	}
	bfs(1);
	for(int i=1;i<=n;i++)
	printf("%d ",ans[i]);
}

Measured memory_bytes: 14848
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll now = a[0];
    ll count = 0;
    for (auto itr = a.begin(); itr != a.end(); ++itr)
    {
        if (now < (*itr))
        {
            now = (*itr);
        }
        count += (now - (*itr));
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4364
import queue

h, w = map(int, input().split())
s = [input() for i in range(h)]

cost = [[99999999 for j in range(w)] for i in range(h)]

cost[0][0] = 0
xq = queue.Queue()
yq = queue.Queue()
xq.put(0)
yq.put(0)

while xq.qsize() > 0:
    x = xq.get()
    y = yq.get()

    if y + 1 < h:
        tmp = cost[y][x] + (1 if s[y][x] == '.' and s[y + 1][x] == '#' else 0)
        if tmp < cost[y + 1][x]:
            cost[y + 1][x] = tmp
            xq.put(x)
            yq.put(y + 1)
    if x + 1 < w:
        tmp = cost[y][x] + (1 if s[y][x] == '.' and s[y][x + 1] == '#' else 0)
        if tmp < cost[y][x + 1]:
            cost[y][x + 1] = tmp
            xq.put(x + 1)
            yq.put(y)

print((0 if s[0][0] == '.' else 1) + cost[h - 1][w - 1])


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

template<class T> inline bool chmax(T &a, T b) {
    if(a<b) {
        a=b; return 1;
    } 
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if(a>b) {
        a=b; return 1;
    } 
    return 0;
}

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int sum(int n){
    if(n==1) {
        return 1;
    }
    return sum(n-1)+n;
}

int main() {
    ll n;
    cin>>n;
    const auto &res = prime_factorize(n);
    int cnt=0;
    for (auto p : res) {
        int i=1;
        while(p.second>=sum(i)){
            cnt++;
            i++;
        }
        i=1;
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e18
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}


const int maxn = 10002, maxd = 102;
ll dp[2][maxd][maxn];

ll solver(string &k, ll d, ll ind = 0, ll sum = 0, bool tight = true)
{
	sum %= d;
	if (ind == k.size()) return sum == 0;
	if (dp[tight][sum][ind] != -1) return dp[tight][sum][ind];

	ll ans = 0;
	rep(i, 10) {
		bool ntight = tight and i == (k[ind] - '0');
		ans = (ans + solver(k, d, ind + 1, sum + i, ntight)) % MOD;
		if (ntight) break;
	}

	dp[tight][sum][ind] = ans;
	return ans;
}

void solve() {
	string k;
	ll d;
	cin >> k >> d;

	memset(dp, -1, sizeof(dp));
	cout << (solver(k, d) - 1 + MOD) % MOD << endl;
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 17152
import sys

BIT = []
n = 0


def init():
    # 初期化
    global BIT, n

    BIT = [0] * (n + 1)  # BIT は 最初のインデックスは 1(0001)


def add(i, x):

    global BIT, n

    # A[i] に x を加える動作
    while i < n + 1:
        BIT[i] += x
        i += (i & -i)  # i & -i は最下位ビットを取り出す動作


def sum(i):
    # i までの和

    global BIT, n

    _sum = 0
    while i > 0:
        _sum += BIT[i]
        i -= (i & -i)  # i & -i は最下位1ビットを表す

    return _sum


def main():

    global BIT, n
    n, q = map(int, sys.stdin.readline().rstrip().split())

    init()

    # print(n, len(BIT), BIT)

    for _ in range(q):
        com, x, y = map(int, sys.stdin.readline().rstrip().split())

        if com == 0:
            add(x, y)
            # print("add", BIT)
        else:
            # print(BIT)
            print(sum(y) - sum(x - 1))


main()



Measured memory_bytes: 8152
def solve(N, heights):
  dp = [float('inf')] * N
  dp[0] = 0
  for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(heights[i] - heights[i + 1]))
    if i + 2 < N:
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(heights[i] - heights[i + 2]))

  print(dp[N-1])

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

solve(iin(), iln())



Measured memory_bytes: 13980
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
#define N 200500
#define LL long long
#define mem(a,b) memset(a,b,sizeof(a));
using namespace std;
LL sum[N],t[N];
LL tree[N];
int n,k,a,m,nn;
void add(int x)
{
    while(x<=nn)//nn为上限，要大于离散化后的最大的数字，
    {
        tree[x]++;
        x+=x&-x;//向上更新，树状数组核心代码。此处就不解释了，不会的先学树状数组。
    }
}
LL query(int x)
{
    LL num=0;
    while(x)
    {
        num+=tree[x];
        x-=x&-x;//向下求和
    }
    return num;
}
int main()
{
    mem(t,0);
    mem(tree,0);
    mem(sum,0);
    scanf("%d%d",&n,&k);
    nn=n+10;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a);
        t[i]=sum[i]=sum[i-1]+a-k;//预处理出sum[i]数组（就是上面讲解的num数组）
    }//t[i]数组为离散化的辅助数组
    sort(t,t+n+1);//排序，排n+1个数字的序（包括了sum[0]）
    m=unique(t,t+n+1)-t;//去重
    for(int i=0; i<=n; i++)
        sum[i]=lower_bound(t,t+m+1,sum[i])-t+1;//离散化
    LL ans=0;
    for(int i=0;i<=n;i++)
    {
        ans+=query(sum[i]);//查询有多少个小于sum[i]的数字
        add(sum[i]);//更新树桩数组。
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#define MN 2000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,q[MN*2+5],top,res[MN*2+5];
int ask(int a,int b)
{
	static char r[5];
	printf("? %d %d\n",a-1,b-1);fflush(stdout);
	scanf("%s",r+1);return r[1]=='Y';
}
int main()
{		
	n=read();m=read();
	if(n<=m) return 0*puts("Impossible");
	for(int i=1;i<=n+m;++i)
	{
		if(top&&!ask(q[top],i)) --top;
		else q[++top]=i;	
	}
	for(int j=1;j<=n+m;++j) res[j]=ask(q[top],j);
	printf("! ");
	for(int j=1;j<=n+m;++j) printf("%d",res[j]);
	return 0;
}


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

int main() {
    vector<int> v;
    int n, m;
    while (cin >> n) {
        if (n < 2) {
            cin >> m;
        }
        if (n == 0) {
            v.push_back(m);
        } else if (n == 1) {
            cout << v[m] << endl;
        } else if (n == 2) {
            v.pop_back();
        }
    }
    
    return 0;
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  int ans = 0;
  int sum = 0;
  for(int i = 0; i < N-1; i++){
    if(H[i] >= H[i+1]){
      sum++;
    }
    else{
      ans = max(sum,ans);
      sum = 0;
    }
  }
  ans = max(ans,sum);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define ceil(a,b) ((a+b-1)/b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int A,B,X;
    cin >> A >> B >> X;
    if (X >= A && X <= A + B)
        cout << "YES";
    else
        cout << "NO";
}

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

int main() {
  int n; string s; cin >> n >> s;
  int x = 0, ans = 0;
  for (char e: s) {
    if (e == 'I') x++;
    else x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding Space*/

int s = 0;
int n;
random_device rnd;
mt19937 mtt(rnd());
void gap(const vi in,const vi in2){

  bool c[51];
  rep(i,n+1) c[i]=mtt()%2;
  int ts = INF;
  rep(i,n+1){
    for(int j = i-1; j >= 0; j--){
      //cerr << i << j << endl;
      int nowl = (c[i] == 0?in[i]:in2[i]);
      int nowr = (c[j] == 0?in[j]:in2[j]);
      ts = min(ts,min(24-abs(nowl-nowr),abs(nowl-nowr)));
    }
  }
  s = max(s,ts);
}

int main(){
  cin >> n;
  vi in(n);
  vi in2(n);
  
  rep(i,n){
    cin >> in[i];
    in2[i] = 24 - in[i];
  }
  in.pb(0);
  in2.pb(0);
  auto start = chrono::system_clock::now();

  while(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count() < 1990)
    gap(in,in2);
  //cerr <<chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count()<< endl;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 384
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var s = lines[0].split('');
 var st = [];
 var a = 0;
 for(i=0; i<s.length; i++){
   if(st.indexOf(s[i]) !== -1){
     console.log('no');
     a++;
     break;
   }
   st.push(s[i]);
 }

 if(a == 0){
   console.log('yes');
 }
 
  
 
});

Measured memory_bytes: 7628
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,M;
    set<int> A;
    map<int,int> B;
    cin>>N>>M;
    for (int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        if (A.find(a) != A.end()){
            B[a]+=b;
        }
        else{
            B[a]=b;
        }
        A.insert(a);
    }
    vector<int> Avec(A.begin(),A.end());
    sort(Avec.begin(),Avec.end());
    int num=A.size();
    int long number=0;
    int long price=0;
    for (int i=0;i<num;i++){
        if (B[Avec[i]]+number>=M){
            price+=(M-number)*Avec[i];
            cout<<price<<endl;
            break;
        }
        else{
            price+=Avec[i]*B[Avec[i]];
            number+=B[Avec[i]];
        }
    }
    
}

Measured memory_bytes: 9984
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N, K = ILI()
    A, B = [], []
    for __ in range(N):
        a, b = ILI()
        A.append(a)
        B.append(b)
    return N, K, A, B


def solve(N, K, A, B):
    l_K = [K]
    len_bin_K = len(bin(K)) - 2
    all_1 = sum([2 ** x for x in range(len_bin_K - 1)])
    l_K.append(all_1)
    for i in range(len(bin(K)) - 4, -1, -1):
        if K >> i & 1 == 1:
            now = K >> i
            now = now & ~1
            now = ~now
            now = now << (i)
            now = ~now
            l_K.append(now)

    l_ans = [0] * len(l_K)
    for i in range(N):
        for j in range(len(l_K)):
            if l_K[j] | A[i] == l_K[j]:
                l_ans[j] += B[i]
    ans = max(l_ans)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 16992
n,m,k = map(int,input().split())
mod = 10**9+7
rng = n*m+10
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod

cost = [[0 for i in range(m+1)] for j in range(n+1)]
cost[1][1] = ((n-1)+(m-1))*n*m//2
for i in range(1,n+1):
  for j in range(1,m+1):
    if j>1:
      cost[i][j] = cost[i][j-1]-(m-2*(j-1))*n
    elif i>1:
      cost[i][j] = cost[i-1][j]-(n-2*(i-1))*m
ans = 0
for i in cost:
  ans = (ans+sum(i))%mod
ans = ans*pow(2,mod-2,mod)%mod
ans = ans*cmb(n*m-2,k-2)%mod
print(ans)

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n, count;
		boolean[] primes = new boolean[1000001];
		
		primes[0] = primes[1] = false;
		for(int i = 2; i < 1000000; i++){
			boolean judge = true;
			for(int j = 2; j <= Math.sqrt(i); j++){
				if(i % j == 0){
					judge = false;
					break;
				}
			}
			if(judge) primes[i] = true;
			else      primes[i] = false;
		}
		
		while(!(string = reader.readLine()).equals("0")){
			n = Integer.parseInt(string);
			count = 0;
			
			for(int i = 0; i <= n / 2; i++){
				if(primes[i] && primes[n - i]) count++;
			}
			System.out.println(count);
		}
		reader.close();
	}
}

Measured memory_bytes: 25656
import java.util.*;
public class Main {
	public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 String s = sc.next();
		 int min = Integer.MAX_VALUE;
		 for (char i = 'a'; i <= 'z'; i++) {
			 int m = 0;
		     String[] ws = s.split("" + i);
		     for (String w : ws) {
		    	 m = Math.max(m, w.length());
		     }
		     min = Math.min(m, min);
		 }
		 System.out.println(min);
	}
}


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

namespace abc172_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = CIn.ReadInt();
            var M = CIn.ReadInt();
            var K = CIn.ReadInt();
            var A = CIn.ReadIntArray(N);
            var B = CIn.ReadIntArray(M);
            var sumA = new long[N + 1];
            var sumB = new long[M + 1];
            var books = 0;
            for(var i = 1; i <= M; i++)
            {
               
                 sumB[i] = sumB[i - 1] + B[i -1];
            }
            for(var j = 0; j <= N; j++)
            {
                if (j >= 1) 
                sumA[j] = sumA[j - 1] + A[j - 1];
                var min = K - sumA[j];
                if (min >= 0)
                {
                    
                    
                        var binary = Array.BinarySearch(sumB, min);
                        if (binary >= 0)
                        {
                            books = Math.Max(books, binary + j);

                        }
                        else
                        {
                            binary = ~binary - 1;
                            books = Math.Max(books, binary + j);

                        }
                    
                }
            }
            Console.WriteLine(books);
        }
    }
    class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }

            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() => int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = Read();
            }

            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadInt();
            }

            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadLong();
            }

            return array;
        }
        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadDouble();
            }

            return array;
        }
    }

}


Measured memory_bytes: 75472
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  
  int n;
  cin >> n;
  if(n<1200)
    cout<<"ABC";
  else if(n<2800)
    cout<<"ARC";
  else
    cout<<"AGC";
  return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
sn = []
sn_not10 = []
sn_10 = []
for _ in range(n):
  si = int(raw_input())
  sn.append(si)
  if si % 10 != 0:
    sn_not10.append(si)

total = sum(sn)
sn.sort()
sn_not10.sort()

if total % 10 != 0:
  print total
  exit()

if len(sn_not10) == 0:
  print 0
else:
  print total - sn_not10[0]


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

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    l = [-1]*n
    now = 0
    order = 0
    l[0] = 0
    s = {}
    ans = -100

    for i in range(n):
        a[i] -= 1

    while k > 0:
        k -= 1
        now = a[now]
        order += 1
        if l[now] != -1: #既に訪問済の場合
            loop = order - l[now]
            k %= loop
        if k == 0:
            ans = now + 1
            break
        l[now] = order #転送順で何番目の町かを記録

    print(max(ans, -1))

main()

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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	vector<vector<int>>dp(2501,vector<int>(2501));
	dp[0][0]=1;
	for(int i=0;i<N;i++){
		cin>>K;
		M+=K;
		for(int j=2500;j>=0;j--){
			for(int k=2500;k>=0;k--){
				if(j+K<=2500)dp[j+K][k]|=dp[j][k];
				if(k+K<=2500)dp[j][k+K]|=dp[j][k];
			}
		}
	}
	int ans=10000;
	for(int i=0;i<=2500;i++){
		for(int j=0;j<=2500;j++){
			if(dp[i][j]){
				ans=min(ans,max({(int)M-i-j,i,j}));
				//cout<<i<<" "<<j<<endl;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 27428
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
int main( void )
{
	int kotae = 0;
	string in;
	while ( 1 )
	{
		getline( cin, in );
		if ( cin.eof() ) break;
		for ( string::iterator it = in.begin(); it != in.end(); it++ )
			if ( !( *it >= '0' && *it <= '9' ) )
				*it = ' ';
		istringstream is( in );
		int n;
		while ( is >> n )
		{
			kotae += n;
		}
	}
	cout << kotae << endl;
	return 0;
}

Measured memory_bytes: 0
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

s = int(input())

reached = []
def F(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

counter = 1
a = []
a.append(s)
while True:
    counter += 1
    tmp = F(a[-1])
    if tmp in a:
        ans = counter
        break
    a.append(tmp)

print(ans)

Measured memory_bytes: 3064