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

using namespace std;

int euclid(int a, int b){
  if(a < b){
    int tmp = a;
    a = b;
    b = tmp;
  }

  if(a % b == 0) return b;
  return euclid(b, a % b);
}

int main(){
  int N;
  bool pairwise  = true;
  cin >> N;
  vector<int> count(1000001);
  int N_gcd = 1;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    count.at(a)++;

    if(i == 0) N_gcd = a;
    else N_gcd = euclid(N_gcd, a);
  }

  for(int i = 2; i < 1000001; i++){
    int total = 0;
    for(int j = i; j < 1000001; j += i){
      total+= count.at(j);
    }
    if(total > 1){
      pairwise = false;
      break;
    }
  }

  if(pairwise) cout << "pairwise coprime" << endl;
  else if(N_gcd == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  
  return 0;
}

Measured memory_bytes: 7216
h,w,k=map(int,input().split())
cake=[]
for i in range(h):
    cake.append(list(input()))
cnt=0
C=1
for i in range(h):
    if cake[i].count('#')==0:
        cnt+=1
        continue
    else:
        sb=cake[i].count('#')
        if cake[i][-1]=='#':
            for j in range(w):
                if cake[i][j]=='.':
                    cake[i][j]=str(C)
                else:
                    cake[i][j]=str(C)
                    C+=1
        else:
            row_b=0
            for j in range(w):
                if cake[i][j]=='.':
                    cake[i][j]=str(C)
                else:
                    cake[i][j]=str(C)
                    row_b+=1
                    if row_b<sb:
                        C+=1
                    else:
                        continue
            C+=1

T=[]
for i in range(h):
    if cake[i][0]=='.':
        T.append(i)
for i in T:
    if i+1 not in T and i+1<h:
        cake[i]=cake[i+1]
    elif i+1 not in T and i+1==h:
        cake[i]=cake[i-1]
    else:
        a=i
        while i in T:
            i+=1
        if i<h:
            for j in range(a,i):
                cake[j]=cake[i]
        else:
            for j in range(a,i):
                cake[j]=cake[a-1]
                
for i in range(h):
    print(' '.join(cake[i]))


Measured memory_bytes: 9332
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
    string S;
    cin >> S;
    int cnt=0;
    vector<int> vec;
    for (int i=0; i<S.length(); i++) {
        if (S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T') {
            cnt++;
        } else {
            vec.push_back(cnt);
            cnt=0;
        }
    }
    vec.push_back(cnt);
    sort(vec.begin(),vec.end(),greater<int>());
    cout << vec[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
#ifndef ONLINE_JUDGE
	#define debug 1
#else
	#define debug 0
#endif
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, m, a[100005], mx, mn, b[100005], cnt[100005];
bool can() {
	rep(i,1,n) cnt[b[i]]++;
	int total=0;
	rep(i,1,n) if (cnt[i]) total++;
	rep(i,1,n) if (a[i]!=total-(cnt[b[i]]==1)) return false;
	return true;
}
int main() {
	n=readint();
	rep(i,1,n) {
		a[i]=readint();
		mx=(i==1?a[i]:max(mx,a[i]));
		mn=(i==1?a[i]:min(mn,a[i]));
	}
	if (mx-mn>1) {
		printstr("No\n");
		return 0;
	}
	if (mx==n-1&&mx==mn) {
		printstr("Yes\n");
		return 0;
	}
	int cnt=0, tms=0;
	if ((mx==n-1&&mn!=mx)||mx<n-1) m=mx; else m=n;
	if (mn<mx) {
		rep(i,1,n) if (a[i]==mn) b[i]=++cnt;
		cnt++;
	}
	rep(i,1,n) if (a[i]==mx) {
		if (tms++==2) cnt++,tms=1;
		if (cnt>m) break;
		b[i]=cnt;
	}
	rep(i,1,n) if (a[i]==mx&&!b[i]) {
		b[i]=m;
	}
//	rep(i,1,n) cerr<<b[i]<<(i==n?'\n':' ');
	if (can()) printstr("Yes\n");
	else printstr("No\n");
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    if(n == 3) {
        cout << "2 5 63\n";
        return 0;
    }
    rep2(i,1,15001) {
        if(i%3 == 1) continue;
        int j = n-i;
        if(j < 2 or j > 5000) continue;
        if(j&1) continue;
        rep(k,i) cout << 2+k*2 << ' ';
        rep(k,j) cout << 3+k*6 << (k == j-1 ? '\n' : ' ');
        return 0;
    }
}


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

bool judge(ll n, const vector<ll> h, ll N, ll A, ll B){
  ll add_cnt = 0;
  ll tmp;
  rep(i, N){
    tmp = h[i] - (B * n);
    if(tmp > 0){
      add_cnt += ceil((double)tmp / (A-B));
    }
    if(add_cnt > n){
      return false;
    }
  }
  return true;
}

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  ll r = pow(10, 9);
  ll l = 0;
  while(r > l + 1){
    ll m = (r+l) / 2;
    if(judge(m, H, N, A, B)) r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
}



Measured memory_bytes: 1792
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,H,M = II()

H_angle = ((H * 60 + M) * 360) / (12 * 60)
M_angle = (M * 360)/60

angle = abs(H_angle - M_angle)
#print(angle)
#theta = min(angle,(angle + 180) % 360)
#print(theta)
ans = math.sqrt(A ** 2 + B ** 2 - (2 * A * B * math.cos(math.radians(angle))))

print(ans)

Measured memory_bytes: 27288
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

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

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

    sort(l.begin(), l.end(), greater<int>());

    int res = 0;
    for (int i = 0; i < k; i++) {
        res += l[i];
    }

    cout << res << endl;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << min(a+b,min(b+c, c+a));
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
#include<deque>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<list>
#include<bitset>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x,y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x,LLI y) {
//	return x / gcd(x,y) * y;
//}

//long nCr(int n,int r) {
//	long ans = 1;
//	for (int i = n; i > n - r;i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1;i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI res = 0;
	string S;
	string a;
	string A, B;
	int Am0, Am1, Bm0, Bm1;
	cin >> S;
	LLI D = S.size();
	for (int i = 0; i < S.size(); i++) {
		if (i % 2 == 0) {
			A += S[i];
		}
		else {
			B += S[i];
		}
	}
	Am0 = count(A.begin(), A.end(), '0');
	Bm0 = count(B.begin(), B.end(), '0');
	Am1 = count(A.begin(), A.end(), '1');
	Bm1 = count(B.begin(), B.end(), '1');
	if (Am0 + Bm1 > Am1 + Bm0) {
		res = D - Am0 - Bm1;
	}
	else {
		res = D - Am1 - Bm0;
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return 1;}return 0;}
//a より b の方が小さかったら、a の値を b の値に置き換える (そして true を返す)
//そうでなかったら、何もしない (そして false を返す)
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return 1;}return 0;}
const long long INF = 1LL << 60;
int main(){
    int n;
    cin >> n;
    long long dp[100100];
    for(int i = 0; i < n; i++) dp[i] = INF;
    int h[100100];
    for(int i = 0; i < n; i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2; i < n; i++){
        chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
        chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll i,j;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    ll a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    vector<ll> v;
    v.push_back(a+b+c+d);
    v.push_back(a+b+c-d);
    v.push_back(a+b-c+d);
    v.push_back(a+b-c-d);
    v.push_back(a-b+c+d);
    v.push_back(a-b+c-d);
    v.push_back(a-b-c+d);
    v.push_back(a-b-c-d);
    for(i=0;i<8;i++)
    {
        //cout<<v[i]<<" ";
        if(v[i]==7)
        {
            if(i==0)
            {
                cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==1)
            {
                cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==2)
            {
                cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==3)
            {
                cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==4)
            {
                cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==5)
            {
                cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==6)
            {
                cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
                return 0;
            }
            else if(i==7)
            {
                cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (H, W, D) = listOfInt()
    val A = Array(H) { listOfInt() }
    val No = Array(H * W + 1) { Pair(0L, 0L) }
    for (h in 0 until H) {
        for (w in 0 until W) {
            No[A[h][w]] = Pair(h.toLong(), w.toLong())
        }
    }
    val C = LongArray(H * W + 1)
    for (n in 1 .. D) {
        for (m in n + D .. H * W step D) {
            C[m] = Math.abs(No[m].first - No[m - D].first) + Math.abs(No[m].second - No[m - D].second)
            C[m] += C[m - D]
        }
    }
    val Q = nextInt()
    val ans = LongArray(Q) {
        val (L, R) = listOfInt()
        C[R] - C[L]
    }
    println(ans.joinToString("\n"))
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }
fun listOfLong() = listOfString().map { it.toLong() }

Measured memory_bytes: 75408
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}

int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}

/*--------Library Zone!--------*/

int solve(int x, int y) {
	y = min(y, x - y);
	int ans = 1;
	for (int i = x; i > x - y; i--) {
		ans *= i;
		ans /= x - i + 1;
	}
	return ans;
}
int n, a, b, v[55];
signed main() {
	cin >> n >> a >> b;
	rep(i, n)cin >> v[i];
	sort(v, v + n);
	int lo = lower_bound(v, v + n, v[n - a]) - v;
	int up = upper_bound(v, v + n, v[n - a]) - v;
	if (v[n - 1] != v[n - a]) {
		int sum = 0;
		for (int i = n - 1; i >= n - a; i--)sum += v[i];
		printf("%.12lf\n", (double)(sum) / (double)(a));
		cout << solve(up - lo, up - (n - a)) << endl;
	}
	else {
		cout << v[n - 1] << endl;
		int sum = 0;
		for (int i = a; i <= min(b, up - lo); i++) {
			sum += solve(up - lo, i);
		}
		cout << sum << endl;
	}
	endre;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int dy[8] = {1,0,-1,0,1,-1,1,-1};
//////////////////////////////////


int main() {
    string s, t; cin >> s >> t;
    int cnt = 0;
    for(int i=0; i<s.size(); i++) if(s[i]==t[i])cnt++;
    cout << cnt << endl;
    return 0;
}




// EOF


Measured memory_bytes: 256
from collections import Counter
 
w = input()
 
char_counter = Counter()
 
for c in w:
  char_counter[c] += 1
 
is_beautiful = "Yes"
for c in char_counter.most_common():
  if c[1] % 2 == 1:
    is_beautiful = "No"
 
print(is_beautiful)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;

const int mxN = 1e5+1;
int dp[mxN][3];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    // dp[i][j] == maximum points of happiness upto day i choosing jth activity
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];
    
	dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];
    for(int i = 1; i < n; i++) {
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << '\n';
}


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

int main(){
    vector<int> menu(5);
    int mini = 9;
    for (int i = 0; i < 5; i++){
        cin >> menu[i];
        if (menu[i]%10 != 0){
            mini = min(mini,menu[i]%10);
        }
    }

    int sum = 0;

    for (int i = 0; i < 5; i++){
        if (menu[i]%10 == 0){
            sum += menu[i];
        }else if (menu[i]%10 == mini && sum%10 == 0){
            sum += menu[i];
        }else{
            sum += (menu[i]/10)*10 + 10;
        }
    }

    cout << sum << endl;
}

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





int main() {
	ll mod = 1e9 + 7;
	ll n, m;
	cin >> n >> m;
	vector<ll> y(m);
	vector<ll> x(n);
	rep(i, n) {
		cin >> x.at(i);
	}
	rep(i, m) {
		cin >> y.at(i);
	}
	ll X = 0, Y = 0;
	rep(i, n) {
		X += (2 * i - n + 1) * x.at(i);
		X %= mod;
	}
	rep(i, m) {
		Y += (2 * i - m + 1) * y.at(i);
		Y %= mod;
	}
	cout << (X * Y) % mod << endl;

}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(){
  cin >> n;
  int a[n]; rep(i,n) cin >> a[i];
  int pum = 0;
  rep(i,n){
    if(a[i] == pum + 1) pum++;
  }
  if(pum == 0){
    cout << -1 << "\n";
  }else{
    cout << n-pum << "\n";
  }
  // vector<int> v = {};
  // while(t--){}
  // rep(i,v.size()) cout << v[i] << "\n";
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = []
for i in reversed(range(n)):
    if A[i]:
        ans.append(i+1)
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n%tmp == 0:
                A[tmp-1] ^= 1
                if tmp != n//tmp:
                    A[n//tmp-1]^=1
            tmp += 1
if len(ans) > 0:
    print(len(ans))
    print(*ans)
else:
    print(0)


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> s(M);
  for (int i =0; i<M; i++) {
    int k;
    cin >> k;
    for (int j =0; j<k; j++) {
      int x;
      cin >> x;
      s.at(i).push_back(x);
    }
  }
  vector<int> p(M);
  for (int i =0; i<M; i++) {
    cin >> p.at(i);
  }
 
  //ビット全検索
  int count =0;
  for (int tmp = 0; tmp < (1 << 10); tmp++) {
    if (tmp >= pow(2,N)) break;
    bitset<10> bit(tmp);
    int countK =0;
    for (int i =0; i<M; i++) {
      int countS =0;
      for (int j =0; j<s.at(i).size(); j++) {  
        if (bit[s.at(i).at(j)-1] == 1) countS++;
      }
      if (countS % 2 == p.at(i)) countK++;
    }
    if (countK == M) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 4112
/*
ACplease
　　 ●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cassert>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------------------------------------
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);
    srand((unsigned)time(NULL));
    
    string s,t;
  	cin >> s >> t;
    int ans = INF;
    int m = 0;
    rep(i,s.size() - t.size()+1){
      	m = 0;
        int x = i;
        rep(j,t.size()){
            if(t[j] != s[x]) m++;
            x++;
        }
      	ans = min(ans,m);
    }
  	ANS;

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main (void)
{
    int j,i,l[1000],a[1000],b;
    for(i=0;;i++)
    {
        if(scanf("%d",&a[i])==EOF)break;
        else if(a[i]==0)
        {
            printf("%d\n",a[i-1]);
                i--;
                i--;
        }
    }
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  int ans=800*n;
  ans-=n/15*200;
  cout<<ans<<endl;
  return 0;
  }

Measured memory_bytes: 256
while True:
  s1 = input()
  if s1==".":
    break
  s2 = input()

  s1words = []
  s2words = []
  s1split = ""
  s2split = ""

  flag = False
  string = ""
  for e in s1:
    if not flag and e=='"':
      flag = True
      s1split += e
    elif flag and e=='"':
      flag = False
      s1split += e
      s1words.append(string)
      string = ""
    elif flag:
      string += e
    else:
      s1split += e

  flag = False
  string = ""
  for e in s2:
    if not flag and e=='"':
      flag = True
      s2split += e
    elif flag and e=='"':
      flag = False
      s2split += e
      s2words.append(string)
      string = ""
    elif flag:
      string += e
    else:
      s2split += e

  wrong = 0
  if len(s1words)!=len(s2words):
    print("DIFFERENT")
  else:
    for s, t in zip(s1words, s2words):
      if s!=t:
        wrong += 1
    if wrong==0 and s1split==s2split:
      print("IDENTICAL")
    elif wrong==1 and s1split==s2split:
      print("CLOSE")
    else:
      print("DIFFERENT")



Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

int main(){
    ll a;
    cin>>a;
    string s;
    cin>>s;
    if(a>=3200)cout<<s;
    else if(a<3200)cout<<"red";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d",&n);
    if(n<10){
        printf("%d",n);
    }else if(10<=n && n<100){
        printf("9");
    }else if(100<=n && n<1000){
        printf("%d",n-90);
    }else if(1000<=n && n<10000){
        printf("909");
    }else if(10000<=n && n<100000){
        printf("%d",n-9090);
    }else if(n==100000){
        printf("90909");
    }
    return 0;
}

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

int main() {
    map<string, set<int> > index;
    string word;
    int page;
    while (cin >> word >> page) {
        index[word].insert(page);
    }
    for (map<string, set<int> >::iterator it = index.begin(); it != index.end(); it++) {
        cout << it->first << endl;
        bool insertSpace = false;
        for (set<int>::iterator sit = it->second.begin(); sit != it->second.end(); sit++) {
            if (insertSpace) {
                cout << " ";
            } else {
                insertSpace = true;
            }
            cout << *sit;
        }
        cout << endl;
    }
}

Measured memory_bytes: 0
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

A,B = map(int,input().split())

Moneys = range(1,1001)

#消費税が入力と一致したインデックス
a_index=set()
b_index=set()

for i in Moneys:
    if math.floor(i*0.08) == A:
        a_index.add(i)

for j in Moneys:
    if math.floor(j*0.1) == B:
        b_index.add(j)

Tax = a_index&b_index

if len(Tax)!=0:
    print(min(list(Tax)))
else:
    print(-1)

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long)(1e15)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}


void solve(){
    double r;
    cin >> r;
    double pi = acos(-1);
    cout << 2*pi*r << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

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

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

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

vector<int> cut(vector<int> c, int k){
	
	int i;
	vector<int> res;
	
	for(i=k; i<c.size(); i++) res.push_back(c[i]);
	for(i=0; i<k; i++) res.push_back(c[i]);

	return res;
		
}

vector<int> re(vector<int> c, int n){

	int i;
	vector<int> res,a,b;
	
	for(i=0; i<n; i++) a.push_back(c[i]);
	for(i=n; i<c.size(); i++) b.push_back(c[i]);

	rep(i,n){
		res.push_back(a[i]);
		res.push_back(b[i]);
	}
	
	return res;
}


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

	int n,m,k;
	vector<int> cards;

	cin >> n;
	rep(i,n*2) cards.push_back(i+1);

	cin >> m;
	rep(i,m){
		cin >> k;

		if(k) cards = cut(cards, k);
		else  cards = re(cards, n);		
	}

	rep(i,cards.size()) cout << cards[i] << "\n";

	return 0;
}

Measured memory_bytes: 1232
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int N=3,NN=9;
const int dx[4]={0,1,-1,0};
const int dy[4]={1,0,0,-1};
struct Puz{
	int mp[NN],space,path;
	bool operator<(const Puz &p)const{
		for(int i=0;i<NN;i++){
			if(mp[i]==p.mp[i]) continue;
			return mp[i]>p.mp[i];
		}
		return false;
	}	
};
bool solved(Puz p){
	for(int i=0;i<NN;i++) if(p.mp[i]!=(i+1)) return false;
	return true;
}
int bfs(Puz s){
	map<Puz,bool>tab;
	queue<Puz>Q;
	Puz u,v;
	s.path=0;
	tab[s]=true;
	Q.push(s);
	while(!Q.empty()){
		u=Q.front();Q.pop();
		if(solved(u)) return u.path;
		int sx=u.space/N,sy=u.space%N;
		for(int i=0;i<4;i++){
			int tx=sx+dx[i],ty=sy+dy[i];
			v=u;
			if(tx<0||ty<0||tx>=N||ty>=N) continue;
			swap(v.mp[u.space],v.mp[tx*N+ty]);
			v.space=tx*N+ty;
			if(!tab[v]){
				v.path++;
				tab[v]=true;
				Q.push(v);
			}
		}
	}
}

int main(){
	Puz src;
	for(int i=0;i<NN;i++){
		scanf("%d",&src.mp[i]);
		if(src.mp[i]==0){
			src.mp[i]=NN;
			src.space=i;
		}
	}
	printf("%d\n",bfs(src));
	return 0;
}


Measured memory_bytes: 20616
#include<bits/stdc++.h>
using namespace std;
int a[60];
vector<int>V; 
int main()
{
	int n,k,ans=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<=min(n,k);i++)//枚举左 
	{		
		for(int j=0;j<=min(n,k);j++)//枚举右 
		{
			if(i+j>k || i+j>n)
				continue;
			int kk=k-i-j;//防回去		
			V.clear();
			for(int l=0;l<i;l++)
				V.push_back(a[l]);
			for(int l=0;l<j;l++)
				V.push_back(a[n-l-1]);
		/*	cout<<i<<" "<<j<<" ###\n";
		*	for(int l=0;l<V.size();l++)
				cout<<V[l]<<" " ;
			cout<<endl;*/
			sort(V.begin(),V.end());
			int sum=0;
			for(int l=0;l<V.size();l++)
				sum+=V[l];
		//	cout<<sum<<" "<<i<<" "<<j<<" "<<kk<<endl;
			for(int l=0;l<V.size() && kk>0;l++)
			{
				if(V[l]<0)
					sum-=V[l];
				else
					break;
				kk--;
			}
			 
			ans=max(ans,sum);
		}
	} 			
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
n=int(input())

ans_tmp = sum(range(n+1)) * 2 -1

from itertools import accumulate
sum_list = list(accumulate(range(1, n)))

ans_tmp_2 = 0

for i in range(2, n+1//2+1):
    if n // i > 1:
        count_tmp = n // i
        ans_tmp_2 += i * sum_list[count_tmp - 1] - i

print(ans_tmp + ans_tmp_2)

Measured memory_bytes: 562436
# coding=utf-8
class Node():
    # About Type
    # parent = -1 ==> Root ==> 0
    # child = [] ==> Leaf ==> 1
    # others ==> Internal ==> 2
    def __init__(self, id, parent, child):
        self.id = id
        self.parent = parent
        self.child = child

    def update(self):
        self.depth = 0
        back = -1
        if self.parent == -1:
            self.Type = "root"
            back = self.id
        elif self.child == []:
            self.Type = "leaf"
        else :
            self.Type = "internal node"
        return back

    def printInfo(self):
        print("node " + str( self.id ), end = ": " )
        print("parent = " + str( self.parent ), end = ", " )
        print("depth = " + str( self.depth ), end = ", " )
        print( self.Type, end = ", " )
        print("[", end="")
        length = len( self.child )
        for i in self.child[0: length - 1]:
            print(str(i), end=", ")
        if length > 0:
            print( str(self.child[length-1]) , end="")
        print("]")


    def calcDepth(self, Tree):
        if self.parent == -1:
            self.depth = 0
        else :
            self.depth = Tree[self.parent].depth + 1
        for i in self.child:
            Tree[i].calcDepth(Tree)


def main():
    # データ入力
    n = int( input() )
    InputData = []
    Tree = {} # Nodeクラスのディクショナリ

    tmp = []
    for i in range(n):
        tmp = [int(x) for x in input().split()] # [Node, num, 子1, 子2, ...]
        InputData.append(tmp)
        # Treeの初期化
        Tree[tmp[0]] = Node(tmp[0], -1, tmp[2: 2+tmp[1]])

    for val in Tree.values():
        for i in val.child:
            Tree[i].parent = val.id

    for key in Tree.keys():
        tmp = Tree[key].update()
        if tmp != -1:
            root = tmp

    Tree[root].calcDepth(Tree)

    keys = list(Tree.keys())
    keys.sort()

    for key in keys:
        Tree[key].printInfo()

if __name__ == '__main__':
    main()



Measured memory_bytes: 54168
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

const LL mod = 998244353;

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

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  int x;
  scanf("%d", &x);

  printf("%d\n", x * 360 / gcd(x, 360) / x);



#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 3824
def main():
    S = input()
    ans = 0
    for i in range(len(S)):
        for j in range(len(S)+1):
            ans = max(ans, cal_ACGT(S[i:j]))
    print(ans)

def cal_ACGT(substr):
    if (is_ACGT(substr)):
        return len(substr)
    else:
        return 0

def is_ACGT(substr):
    flag = []
    for i in range(len(substr)):
        if(substr[i] == "A"):flag.append(True)
        elif(substr[i] == "C"):flag.append(True)
        elif(substr[i] == "G"):flag.append(True)
        elif(substr[i] == "T"):flag.append(True)
        else:flag.append(False)
    return all(flag)

main()


Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int N,C;
int D[31][31];
int c[501][501];
int sum[3][31];

int main(){
    cin>>N>>C;
    repn(i,C) repn(j,C) cin>>D[i][j];
    repn(i,N) repn(j,N) cin>>c[i][j];

    repn(i,N){
        repn(j,N){
            repn(k,C){
                sum[(i+j)%3][k]+=D[c[i][j]][k];
            }
        }
    }

    int ans=INF;
    repn(i,C){
        repn(j,C){
            if(i==j) continue;
            repn(k,C){
                if(i==k || j==k) continue;
                ans=min(ans,sum[0][i]+sum[1][j]+sum[2][k]);
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4500
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string str, order;
    int q, a, b;
    cin >> str >> q;
    for(int i=0; i<q; i++){
        cin >> order;
        if(order=="replace"){
            cin >> a >> b >> order;
            str.replace(a, b-a+1, order);
        }
        else if(order=="reverse"){
            cin >> a >> b;
            reverse(str.begin()+a, str.begin()+b+1);
        }
        else{
            cin >> a >> b;
            for (int j = a; j <= b; j++){
                cout << str[j];
            }
            cout << endl;
        }
    }
    return 0;
}

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

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;

int H,W;
char g[20][20];
bool CR[20][20];
int num1[26],num2[26],match[20];
bool visR[20],visC[20];

bool Check(){
	for(int i = 0; i < 26; ++i) if(num1[i] != num2[i])
		return false;
	return true;
}

bool Solve_col(int p,int num){
	if(p == W){
		if(num == W - W % 2) return true;
		return false;
	}
	if(Solve_col(p + 1,num)) return true;
	if(visC[p] == false){
		for(int i = p + 1; i <= W; ++i) if(!visC[i]){
			bool check = true;
			for(int j = 1; j <= H; ++j) if(match[j]){
				if(g[j][p] != g[match[j]][i] ||
				   g[j][i] != g[match[j]][p]){
					check = false;
					break;
				}
			}
			if(check){
				visC[p] = visC[i] = true;
				if(Solve_col(p + 1,num + 2)) return true;
				visC[p] = visC[i] = false;
			}
		}
	}
	return false;
}

bool Dfs1(int p,int num){
	if(p == H){
		memset(visC,false,sizeof(visC));
		if(num == H - H % 2 && Solve_col(1,0)) return true;
		return false;
	}
	if(Dfs1(p + 1,num)) return true;
	if(visR[p] == false){
		for(int i = p + 1; i <= H; ++i) if(!visR[i] && CR[p][i]){
			visR[p] = visR[i] = true;
			match[p] = i,match[i] = p;
			if(Dfs1(p + 1,num + 2)) return true;
			visR[p] = visR[i] = false;
			match[p] = match[i] = 0;
		}
	}
	return false;
}

void C1(){ memset(num1,0,sizeof(num1)); }
void C2(){ memset(num2,0,sizeof(num2)); }
void Ccnt1(int top,int id,int A[26]){ for(int i = 1; i <= top; ++i) A[g[id][i] - 'a']++; }

int main(){
	cin >> H >> W;
	for(int i = 1; i <= H; ++i) cin >> (g[i] + 1);
	for(int i = 1; i <= H; ++i){
		C1(); Ccnt1(W,i,num1);
		for(int j = i + 1; j <= H; ++j){
			C2(); Ccnt1(W,j,num2);
			if(Check()) CR[i][j] = true;
		}
	}
	if(Dfs1(1,0)) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

int main()
{
    int n, f[100][10], p[100][11], max = -2000000000;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 10; j++)
            scanf("%d", f[i] + j);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 11; j++)
            scanf("%d", p[i] + j);

    for (int i = 1; i < 1024; i++)
    {
        int tmp_max{};
        bool joisino_open[10];
        for (int j = 0; j < 10; j++)
            joisino_open[j] = (i >> j) & 1;
        for (int j = 0; j < n; j++)
        {
            int open_count{};
            for (int k = 0; k < 10; k++)
                open_count += f[j][k] && joisino_open[k];
            tmp_max += p[j][open_count];
        }
        max = std::max(max, tmp_max);
    }
    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

signed main() {
  int A = in(), B = in();
  vi a(A), b(B);
  REP(i, A) a[i] = in();
  REP(i, B) b[i] = in();
  
  int res = 0;
  REP(i, B) {
    int cnt = 0;
    int k = i;
    REP(j, A) {
      if (k >= B) break;
      if (a[j] == b[k]) {
        chmax(res, ++cnt);
        ++k;
      }
    }
  }
  print(res);

  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+') cout << A+B; else cout << A-B;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 2000000000
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];

    vector<int> dp(100001);
    rep(i,0,n+1) dp[i] = INF;

    rep(i,0,n) *lower_bound(dp.begin(), dp.begin() + n, a[i]) = a[i];

    cout << lower_bound(dp.begin(), dp.begin() + n, INF) - dp.begin() << endl;
    return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 2e5 + 100;
long long n, k;

int main() {
	
	cin >> n >> k;
	
	n = n % k;
	
	cout << min(n, k - n) << endl;
	
	return 0;	
} 

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

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  vector<int>b(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
    cin>>b[i];
  vector<int>c(n);
  int sum =0;
  for(int i=0;i<n;i++)
    c[i]=a[i]-b[i];
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  for(int i=0;i<n;i++){
    if(c[i]>0)
      sum+=c[i];
    else
      break;
  }
  cout<<sum<<endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    int n,d,c=0;
    cin>>n>>d;
    double x,y,dis;
    while(n--)
    {
        cin>>x>>y;
        dis=sqrt((x*x)+(y*y));
        if(dis<=d)
            c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3780