akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int first = 0, second = 0, third = 0;

//for sort
void sort(){
	int buf = third;
	if(third > first){
	//3rd > 1st ,1->2 2->3 3->1
		third = second;
		second = first;
		first = buf;
	}else if(third > second){
	//3rd > 2nd ,2->3 3->2
		third = second;
		second = buf;
	}
}

int main(){
int buf;

for(int i = 0; i < 10; i++){
	cin >> buf;
	if(buf > third){
		third = buf;
		sort();
	}
}

//show
cout << first << "\n";
cout << second << "\n";
cout << third << "\n";

return 0;
}

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

int w, h;
int map[91][91];
bool visited[91][91];

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

int dfs(int x, int y, int n) {
	int result = n;
	// 到達した時の処理： count を増やす
	for (int i = 0; i < 4; i++) {
		int nextX = dx[i] + x;
		int nextY = dy[i] + y;
		// point: 範囲外と'.'で無い場合は外す
		if (0 <= nextX && nextX < w && 0 <= nextY && nextY < h
				&& !visited[nextY][nextX] && map[nextY][nextX] == 1) {
			visited[nextY][nextX] = true;
			result = max(result, dfs(nextX, nextY, n + 1));
			visited[nextY][nextX] = false;
		}
	}
	return result;
}

int main() {
	
	while (cin >> w >> h, w || h) {
		// 前回の文字列の入力を参照
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> map[i][j];
			}
		}
		int maxBreak = 0;
		for (int i = 0; i < h; i++) {
			fill(visited[i], visited[i] + w, false);
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == 1) {
					maxBreak = max(maxBreak, dfs(j, i, 0));
				}
			}
		}
		cout << maxBreak << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 202;

int n, m, r;
int R[10];
int dist[N][N];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> r;
	for (int i = 0; i < r; i++)
		cin >> R[i], R[i]--;
	MMS(dist, 0x3f);
	for (int i = 0; i < m; i++) {
		int f, t, c;
		cin >> f >> t >> c;
		f--, t--;
		dist[f][t] = dist[t][f] = c;
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (dist[i][k] + dist[k][j] < dist[i][j]) {
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
	sort(R, R + r);
	int res = OO;
	do {
		int cur = 0;
		for (int i = 1; i < r; i++) {
			cur += dist[R[i - 1]][R[i]];
		}
		res = min(res, cur);
	} while (next_permutation(R, R + r));
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
N, Y = map(int, input().split())

for a in range(N+1):
    for b in range(N+1-a):
        c = N-a-b
        if 10000*a + 5000*b + 1000*c == Y:
            print(a, b, c)
            exit(0)

print(-1, -1, -1)

Measured memory_bytes: 3060
import java.io.*;
public class Main {
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader((System.in)));
        try{
            while(true) {
                String line = reader.readLine();
                if(line.equals("0")) break;
                int sum = 0;
                for (int i = 0; i < line.length(); i++) {
                    char c = line.charAt(i);
                    sum += c - '0';
                }
                System.out.println(sum);
            }
        }
        catch(IOException e){
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 24332
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { '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' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int solv(string s,int n)
{
	if (stol(s) > n)return 0;
	int ans = 0;
	if ((find(s.begin(), s.end(), '3') != s.end() && find(s.begin(), s.end(), '5') != s.end() && find(s.begin(), s.end(), '7') != s.end()))
		ans++;
	ans += solv(s + "3", n);
	ans += solv(s + "5", n);
	ans += solv(s + "7", n);
	return ans;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n;
	cin >> n;
	cout << solv("0", n) << endl;
	return 0;
}

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

#define MAX 52

using namespace std;

int main(void)
{
	int h,w;
	string temp;
	int dp[MAX][MAX];
	int f[MAX][MAX];
	int i1,i2;

	cin>>h>>w;
	for(i1=0;i1<MAX;i1++){
		for(i2=0;i2<MAX;i2++){
			dp[i1][i2]=10000;
		}
	}
	memset(f,0,sizeof(f));


	for(i1=1;i1<=h;i1++){
		cin>>temp;
		for(i2=1;i2<=w;i2++){
			f[i1][i2]=temp[i2-1]-48;
			dp[i1][i2]=0;
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(i1==1 && i2==1) continue;
			dp[i1][i2]=min(dp[i1-1][i2],dp[i1][i2-1])+f[i1][i2];
		}
	}

	/*for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			cout<<dp[i1][i2]<<" ";
		}
		cout<<endl;
	}*/

	cout<<dp[h][w]<<endl;

	return 0;
}

Measured memory_bytes: 1228
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
x, y = map(int, input().split())

ans = 'Yes'
if x in a and y in a:
    pass
elif x in b and y in b:
    pass
elif x in c and y in c:
    pass
else:
    ans = 'No'
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

int main(){

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

    sort(a, a+n);

    int b[n];
    if(n % 2 == 0){
        for(int i=0; i<n; i++){
            if(i % 2 == 0){
                b[i] = i+1;
            }
            else{
                b[i] = i;
            }
        }
    }
    else if(n % 2 == 1){
        for(int i=0; i<n; i++){
            if(i % 2 == 0){
                b[i] = i;
            }
            else{
                b[i] = i+1;
            }
        }
    }

    bool same = true;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            same = false;
            break;
        }
    }

    if(!same){
        cout << 0;
    }
    else{
        int pow = n / 2;
        ll ans = 1;
        for(int i=0; i<pow; i++){
            ans = (ans * 2)%MOD;
        }

        cout << ans;
    }


    

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define L(X,Y) ((X)<(Y)?(X):(Y))
#define G(X,Y) ((X)>(Y)?(X):(Y))

#define MAX 100
int rect[MAX][MAX];

int main(void){
	int w,h,n,l,r,u,d,x,y,a;
	
	scanf("%d%d%d",&w,&h,&n);
	l = d = 0;
	u = h;
	r = w;
	for (int i=0;i<n;i++){
		scanf("%d%d%d",&x,&y,&a);
		switch (a){
		case 1:
			l = G(l,x);
			break;
		case 2:
			r = L(r,x);
			break;
		case 3:
			d = G(d,y);
			break;
		case 4:
			u = L(u,y);
			break;
		default:
			break;
		}
//		printf("(%d,%d,%d,%d)\n",l,r,u,d);
	}
	
	printf("%d\n",(r<l||u<d)?0:(r-l)*(u-d));
	return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut m = n;
    let mut sum = 0;
    while m > 0 {
        sum += m % 10;
        m /= 10;
    }
    println!("{}", if n % sum == 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
n = gets.chomp.to_i
a = []
n.times { a << gets.to_i }
 
max = a.max
index = a.find_index(max)
b = a.dup
b.delete_at(index)
max2 = b.max
 
n.times do |i|
  if i == index
    print("#{max2}\n")
  else
    print("#{max}\n")
  end
end

Measured memory_bytes: 7476
n = int(input())
for i in range(n):
    a, b = map(int, input().split(":"))
    a = a + (b/60)
    b = b / 5
    a = abs(a - b)
    if a > 6:
        a = 12 - a
    if a < 1:
        print("alert")
    elif 3 <= a <= 6:
        print("safe")
    else:
        print("warning")


Measured memory_bytes: 5600
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'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'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v[505];

int main(){
  string s, t;
  cin >> s >> t;
  vector<ll> v[26];
  for (int i=0;i<s.length();i++){
    for (int j=0;j<26;j++){
      if (albt[j] == s[i]){
        v[j].push_back(i+1);
        break;
      }
    }
  }
  
  ll count1 = 0;
  ll count2 = 1;
  for (int i=0;i<t.length();i++){
    for (int j=0;j<26;j++){
      if (albt[j] == t[i]){
        //cout << albt[j] << endl;
        auto position = lower_bound(v[j].begin(), v[j].end(), count2);
        if (position == v[j].end()){
          //cout << "up" << endl;
          count1 += 1;
          position = lower_bound(v[j].begin(), v[j].end(), 1);
          if (position == v[j].end()){
            cout << -1 << endl;
            exit(0);
          }
        }
        ll idx = distance(v[j].begin(), position);
        //cout << "dis" << distance(v[j].begin(), v[j].end()) << endl; 
        //cout << idx << " " << *position << endl;
        count2 = *position+1;
      }
    }
  }
  cout << s.length()*count1 + count2 - 1 << endl;
  
  //cout << ans << endl;
}

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

const int BITS = 31;

vector<long long int> memo(BITS);
long long int power(int i) {return memo[i] = (i == 0 ? 1 : 2 * power(i - 1));}

int greedy(long long int s, long long int d) {
  int result = 0;
  while(s != d) {
    for(int i = BITS - 1; 0 <= i; --i) {
      if(s != 0 && (s % power(i)) != 0) continue;
      if(d < s + power(i)) continue;
      s += power(i);
      break;
    }
    ++result;
  }
  return result;
};

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; ++i) {
    long long int s, d;
    cin >> s >> d;

    cout << greedy(s, d) << endl;
  }
}

Measured memory_bytes: 1204
#include <cstdio>

#define int long long

const int MAXN = 1e9 + 7;

int n, ans;

bool flag;

int base[4] = {0, 3, 5, 7};

bool check(int k) {
    bool flag3 = 0, flag5 = 0, flag7 = 0, other = 0;
    while (k) {
        int tmp = k % 10;
        if (tmp == 3) flag3 = true;
        else if (tmp == 5) flag5 = true;
        else if (tmp == 7) flag7 = true;
        else other = true;
        k /= 10;
    }
    if (flag3 && flag5 && flag7 && (!other)) {
        return true;
    }
    else return false;
}

void dfs(int u, int sum) {
    if (sum <= n && check(sum)) ans++;
    if (sum > n || sum * 10 + 3 > n) {
        return;
    }
    for (int i = 1; i <= 3; i++) {
        if (flag) return;
        dfs(u + 1, sum * 10 + base[i]);
    }
}

signed main(int argc, char *argv[]) {
    scanf("%lld", &n);
    dfs(1, 0);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <string>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
#define MAX_V 100000
#define MAX_E 500000
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
const int INF = 1e9 + 7;

#define MAX_H 10
#define MAX_W 10000

bool A[26];

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b)) cout << "B" << endl;
	else cout << "A" << endl;


	return 0;
}


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

int main(int argc, char const *argv[])
{
	int x,y,s;
	while(cin>>x>>y>>s,x)
	{
		int ans=0;
		for (int i = 1; i <= 1000; ++i)
		{
			for (int j = 1; j <= 1000; ++j)
			{
				if(i*(100+x)/100+j*(100+x)/100==s)
				{
					ans=max(ans,i*(100+y)/100+j*(100+y)/100);
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

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

    int sum = 0;

    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s-x-y;
            if(0<=z && z <= k){
                sum++;
            }
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector< std::pair<ll, ll> > vp(N);
  std::map< std::pair<ll, ll>, bool > mc;
  for (ll i = 0; i < N; i++) {
    std::cin >> vp[i].first >> vp[i].second;
    mc[vp[i]] = true;
  }

  ll ans = N;
  std::sort(vp.begin(), vp.end());
  for (ll i = 0; i < N; i++) {
    for (ll j = i+1; j < N; j++) {
      ll p = vp[j].first  - vp[i].first;
      ll q = vp[j].second - vp[i].second;
      ll cost = N;
      for (ll k = 0; k < N; k++) {
	if (k == i) continue;
	if (mc[{(vp[k].first - p), (vp[k].second - q)}] == true) {
	  cost--;
	}
      }
      ans = std::min(ans, cost);
    }
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 2688
N,M=map(int,input().split())
graph=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited=[False]*N
visited[0]=True

def dfs(v,N,visited):
    if all(visited):
        return 1
    
    ret=0
    for new_v in graph[v]:
        if visited[new_v]:
            continue
        
        visited[new_v]=True
        ret+=dfs(new_v,N,visited)
        visited[new_v]=False
    
    return ret

print(dfs(0,N,visited))

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll N = S.length();

    ll start;
    ll end;

    REP(i, N){
        if(S[i] == 'A'){
            start = i;
            break;
        }
    }
    
    for(ll i=N-1; i>=0; i--){
        if(S[i] == 'Z'){
            end = i;
            break;
        }
    }
    cout << end-start+1 << endl;
    return 0;
}

Measured memory_bytes: 3712
num = int(input())
arr = []
d = {}

for i in range(num):
    s = sorted(list(input()))
    ss = ''.join(s)
    arr.append(ss)

#print(arr)
ans = 0

for i in range(num):
    if arr[i] in d:
        ans += d[arr[i]] 
        d[arr[i]] += 1
    else:
        d[arr[i]] = 1

print(ans)


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

char mat[110][110];

void solve() {
    int h, w;
    cin >> h >> w;

    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)cin >> mat[i][j];

    vector<bool> rows(h + 1), col(w + 1);
    for (int i = 0; i < h; i++) {
        bool f = true;
        for (int j = 0; j < w; j++) {
            if (mat[i][j] == '#') {
                f = false;
                break;
            }
        }
        rows[i] = f;
    }
    for (int i = 0; i < w; i++) {
        bool f = true;
        for (int j = 0; j < h; j++) {
            if (mat[j][i] == '#') {
                f = false;
                break;
            }
        }
        col[i] = f;
    }
    for (int i = 0; i < h; i++) {
        if(rows[i])continue;
        for (int j = 0; j < w; j++) {
            if (col[j])continue;
            cout << mat[i][j];
        }
        cout << endl;
    }
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
class ModInt
	@@mod = 1_000_000_007

	def initialize(n)
		@n = n.to_i % @@mod
	end

	def self.zero
		ModInt.new(0)
	end

	def self.mod=(m)
		@@mod = m.to_i
	end

	def +@
		self
	end

	def -@
		ModInt.new(n != 0 ? @@mod - @n : 0)
	end

	def +(m)
		ModInt.new(@n + m.to_i % @@mod)
	end

	def -(m)
		ModInt.new(@n - m.to_i % @@mod)
	end

	def *(m)
		ModInt.new(@n * m.to_i % @@mod)
	end

	def /(m)
		raise DivisionByZeroError.new if m == 0
		a, b, u, v = m.to_i, @@mod, 1, 0
		while b != 0
			t = a / b
			a -= t * b
			a, b = b, a
			u -= t * v
			u, v = v, u
		end
		ModInt.new(@n * u)
	end

	def **(m)
		t, res = self, ModInt.new(1)
		while m > 0
			res *= t if m.odd?
			t *= t
			m >>= 1
		end
		res
	end

	def ==(m)
		@n == m.to_i
	end

	def !=(m)
		@n != m.to_i
	end

	def succ
		self + 1
	end

	def pred
		self - 1
	end

	def to_i
		@n
	end

	def to_s
		@n.to_s
	end
end

n = gets.to_i
puts ModInt.new(10)**n - ModInt.new(9)**n * 2 + ModInt.new(8)**n

Measured memory_bytes: 14304
#include<bits/stdc++.h>
using namespace std;
#define Max 500100

int n,S[Max],c;
void merge(int A[], int left, int mid, int right);
void mergeSort(int A[], int left, int right);

int main(){
    //
    cin >> n;
    for(int i = 0; i < n; i++) cin >> S[i];
    c = 0;
    mergeSort(S, 0, n);
    for(int i = 0; i < n; i++){
        cout << S[i];
        if(i != n-1) cout << " ";
        else cout << endl;
    }
    cout << c << endl;
}

void merge(int A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;

    int L[n1+10], R[n2+10];

    // 右側と左側に分割
    for(int i = 0; i < n1; i++){
        L[i] = A[left+i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid+i];
    }
    L[n1] = INT_MAX; R[n2] = INT_MAX;

    // 右側と左側の小さい方を取ってきて並べ替え
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        c++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}


void mergeSort(int A[], int left, int right){
    if(left+1 < right){
        int mid = (left + right) /2;
        // 左側整頓
        mergeSort(A, left, mid);
        // 右側整頓
        mergeSort(A,mid, right);
        // まとめる
        merge(A,left, mid, right);
    }
}


Measured memory_bytes: 6996
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int mas[16][17];
    int n;
    while(scanf("%d",&n),n){
        for(int i=0;i<n;i++){
            for(int j=0;j<n+1;j++){
                scanf("%d",&mas[i][j]);
            }
        }

        int dp[1<<17];fill_n(dp,1<<17,1<<25);
        dp[0]=0;
        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<n;j++){
                if((i>>j)&1)continue;
                int mi=mas[j][0];
                for(int k=0;k<n;k++){
                    if((i>>k)&1)mi=min(mi,mas[j][k+1]);
                }
                dp[i|(1<<j)]=min(dp[i|(1<<j)],dp[i]+mi);
            }
        }
        printf("%d\n",dp[(1<<n)-1]);
    }
    return 0;
}

Measured memory_bytes: 1540
#include <cstdio>

int main(int argc, char *argv[])
{
  long long int N;
  int A[100000];
  scanf("%lld",&N);
  int flag =0;
  int sum =1;
  for (int i = 0; i < N; i++) {
    scanf("%d",&A[i]);
  }
  
  for(int i =0;i<N-1;i++){
    if(flag == 0){
      if(A[i+1]>A[i]){
	flag=1;
      }else if(A[i+1]<A[i]){
	flag=-1;
      }
    }
    else if(flag==1){
      if(A[i+1]>=A[i]){
      }else{
	sum++;
	flag = 0;
      }
    }
    else {
      if(A[i+1]<=A[i]){
      }else{
	sum++;
	flag =0;
      }      
    }
  }
  printf("%d\n",sum);
  return 0;
}


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

using namespace std;

int main(void){

    int n;
    cin >> n;
    
    int sum = 0;

    int m = n;
    while(m > 0) {
        sum += m % 10;
        m /= 10;
    }

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

    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

// thanks to https://beet-aizu.github.io/library/library/segtree/basic/dual.cpp.html
template <typename E>
struct SegmentTree{
  using H = function<E(E,E)>;
  int n,height;
  H h;
  E ei;
  vector<E> laz;

  SegmentTree(H h,E ei):h(h),ei(ei){}

  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    laz.assign(2*n,ei);
  }

  inline void propagate(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    laz[k]=ei;
  }

  inline void thrust(int k){
    for(int i=height;i;i--) propagate(k>>i);
  }

  void update(int a,int b,E x){
    if(a>=b) return;
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
  }

  E get_val(int a){
    thrust(a+=n);
    return laz[a];
  }

  void set_val(int a,E x){
    thrust(a+=n);
    laz[a]=x;
  }
};

using seg = SegmentTree<ll>;

ll n, q;
string s;

void print(vector<seg> &v) {
  rep(i, 26) {
    cerr << (char)('a'+i) << " " ;
    rep(j, n) {
      cerr << v[i].get_val(j) << " ";
    }
    cerr << endl;
  }
}

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

  cin >> n >> s >> q;

  auto f = [](ll l, ll r) {
    return l+r;
  };
  vector<seg> sum(26, seg(f, 0));
  rep(i, 26) {
    sum[i].init(n);
  }

  vector<vl> ss(26, vl(n));
  rep(i, n) {
    ss[s[i]-'a'][i] = 1;
  }
  rep(i, 26) {
    rep(j, n-1) {
      ss[i][j+1] += ss[i][j];
    }
  }
  rep(i, 26) {
    rep(j, n) {
      sum[i].set_val(j, ss[i][j]);
    }
  }

  //print(sum);


  rep(_, q) {
    ll m;
    cin >> m;
    if (m == 1) {
      ll i; char c;
      cin >> i >> c;
      i--;

      sum[s[i]-'a'].update(i, n, -1);
      sum[c-'a'].update(i, n, 1);

      s[i] = c;
      //print(sum);
      //cerr << endl;
    } else {
      ll l, r;
      cin >> l >> r;
      l--;
      r--;
      ll ans = 0;
      rep(i, 26) {
        //cerr << (char)(i+'a') << " ";
        ll cnt = sum[i].get_val(r) - (l == 0 ? 0 : (sum[i].get_val(l-1)));
        //cerr << cnt << endl;
        if (cnt > 0) ans++;
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 319516
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
x = 0
y = 0
z = 0
for i in range(n):
    if p[i] <= a:
        x += 1
    elif p[i] <= b:
        y += 1
    else:
        z += 1
print(min(x, y, z))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    int N, M;
    cin >> N >> M;

    int mininum = 0;
    int maximam = 1e6;
    for (int i = 0; i < M; ++i) {
        int L, R;
        cin >> L >> R;

        if (L > mininum) mininum = L;
        if (R < maximam) maximam = R;
    }

    cout << max(0, maximam - mininum + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

count = 0

if n%2 == 0:
    for i in range(int(n/2)):
        if s[i] != s[-i-1]:
            count += 1
else:
    for i in range(int(n//2+1)):
        if s[i] != s[-i-1]:
            count += 1

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  deque<int> A;
  rep(i,0,N){
    int X; cin>>X;
    if(i%2==N%2){
      A.push_back(X);
    }
    else{
      A.push_front(X);
    }
  }
  rep(i,0,N) cout<<A[i]<<" ";
  cout<<endl;
  }



Measured memory_bytes: 3840
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc2(n,m);
	f1(i,n)A[i]=-1;
	if(m==0 and n==1){
		rpr(0);
	}
	while(m--){
		sc2(x,y);
		if(A[x]!=-1 and A[x]!=y)ans=-1;
		A[x]=y;		
	}
	if(ans==-1){
		rpr(-1);
	}
	if(A[1]==0 and n==1)rpr(0);
	if(A[1]==0 or ans==-1){
		rpr(-1);
	}
	
	f1(i,n){
		if(A[i]==-1){
			if(i==1)A[i]=1;
			else A[i]=0;
		}
	}
	f1(i,n)cout<<A[i];
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    ll ans = 0;
    rep2(i,N){
        if((i%3) != 0 && (i%5) !=0){
            ans+=i;
            
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int isPrime(int x){
  for(int i=2;i*i<=x;i++) if(x%i==0) return 0;
  return 1;
}
int main(){
  int m,n;
  int st[1005][1005]={{}};
  int p[1000005]={};
  int x=501,y=501;
  int idx,idy;
  int i=1,j,k=1;
  st[x][y]=i;
  i++;
  while(1){
    for(j=0;j<2*k;j++){
      st[x+1][y-j]=i;
      i++;
    }
    for(j=0;j<2*k;j++){
      st[x-j][y-(k-1)*2-1]=i;
      i++;
    }
    for(j=0;j<2*k;j++){
      st[x-(k-1)*2-1][y-(k-1)*2+j]=i;
      i++;
    }
    for(j=0;j<2*k;j++){
      st[x-(k-1)*2+j][y+1]=i;
      i++;
    }
    if(i>1000005) break;
    k++;x++;y++;
  }
  for(i=2;i<1000005;i++) p[i]=isPrime(i);
  
  
  while(cin >> m >> n,m||n){
    int ans=0,id=0;
    int dp[2][1005]={};
    for(i=0;i<1005;i++){
      for(j=0;j<1005;j++){
	if(st[i][j]==n){
	  idx=i;idy=j;
	  if(p[n]){
	    ans=1;id=n;
	    dp[0][i]=1;
	  }
	  break;
	}
      }
    }
    //cout << n << ":" << p[n] << endl;
    for(i=0;i+idy<1005;i++){
      for(j=-i;j<=i;j++){
	if(idx+j<0||idx+j>1004) continue;
	if(st[idx+j][idy+i]>m) continue;
	if(idx+j-1>=0&&idx+j-1<1005){
	  if(st[idx+j-1][idy+i+1]<=m){
	    dp[(i+1)%2][idx+j-1]=
	      max(dp[(i+1)%2][idx+j-1],dp[i%2][idx+j]+p[st[idx+j-1][idy+i+1]]);
	    if(p[st[idx+j-1][idy+i+1]]){
	      if(ans<dp[(i+1)%2][idx+j-1]||
		 (ans==dp[(i+1)%2][idx+j-1]&&id<st[idx+j-1][idy+i+1])){
		ans=dp[(i+1)%2][idx+j-1];
		id=st[idx+j-1][idy+i+1];
	      }
	    }
	  }
	}
	if(idx+j>=0&&idx+j<1005){
	  if(st[idx+j][idy+i+1]<=m){
	    dp[(i+1)%2][idx+j]=
	      max(dp[(i+1)%2][idx+j],dp[i%2][idx+j]+p[st[idx+j][idy+i+1]]);
	    if(p[st[idx+j][idy+i+1]]){
	      if(ans<dp[(i+1)%2][idx+j]||
		 (ans==dp[(i+1)%2][idx+j]&&id<st[idx+j][idy+i+1])){
		ans=dp[(i+1)%2][idx+j];
		id=st[idx+j][idy+i+1];
	      }
	    }
	  }
	}
	if(idx+j+1>=0&&idx+j+1<1005){
	  if(st[idx+j+1][idy+i+1]<=m){
	    dp[(i+1)%2][idx+j+1]=
	      max(dp[(i+1)%2][idx+j+1],dp[i%2][idx+j]+p[st[idx+j+1][idy+i+1]]);
	    if(p[st[idx+j+1][idy+i+1]]){
	      if(ans<dp[(i+1)%2][idx+j+1]||
		 (ans==dp[(i+1)%2][idx+j+1]&&id<st[idx+j+1][idy+i+1])){
		ans=dp[(i+1)%2][idx+j+1];
		id=st[idx+j+1][idy+i+1];
	      }
	    }
	  }
	}
      }    
    }
    cout << ans << " " << id << endl;
  }
  return 0;
}

Measured memory_bytes: 9028
import sys
input = sys.stdin.readline
from collections import deque

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
inv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod
for i in range(1, nn)[::-1]:
    inv[i] = fainv[i] * fa[i-1]

N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv[SI[i]] % mod
g_td = lambda a, i=-1: a * inv[N - SI[i]] % mod

SI = [1] * N
for i in R[1:][::-1]:
    SI[P[i]] += SI[i]

BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
    BU[i] = g_bu(BU[i], i)
    p = P[i]
    BU[p] = f(BU[p], BU[i])
BU[0] = g_bu(BU[0], 0)

AX = [1] * N
for i in R:
    ac = unit
    for j in X[i]:
        AX[j] = ac
        ac = f(ac, BU[j])
    ac = unit
    for j in X[i][::-1]:
        AX[j] = f(AX[j], ac)
        TD[j] = g_td(f(TD[i], AX[j]), j)
        ac = f(ac, BU[j])

print(*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep = "\n")

Measured memory_bytes: 136484
n=int(input())
f=[[[0for i in range(2)]for j in range(5)]for k in range(n)]
p=[[0for i in range(11)]for j in range(n)]
opn=[[0for i in range(2)]for j in range(5)]
maxi=-10**9
for i in range(n):
  l=list(map(int,input().split()))
  for j in range(5):
    f[i][j][0]=l[j*2]
    f[i][j][1]=l[j*2+1]
for i in range(n):
  p[i]=list(map(int,input().split()))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10)
  for j in range(10):opn[j//2][j%2]=int(s[j])
  ben=0
  for j in range(n):
    same=0
    for k in range(10):
      same+=opn[k//2][k%2]*f[j][k//2][k%2]
    ben+=p[j][same]
  maxi=max([maxi,ben])
print(maxi)


Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  int n;
  cin >> n;
  int f[n][10];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> f[i][j];
    }
  }
  long p[n][11];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 11; j++){
      cin >> p[i][j];
    }
  }
  long maxprofit;
  for(int i = 1; i < 1<<10; i++){
    int cnt[n] = {};
    for(int j = 0; j < 10; j++){
      for(int k = 0; k < n; k++){
        if(f[k][j]==1 && (1 & i>>j)){
          cnt[k]++;
        }
      }
    }
    long profit = 0;
    for(int k = 0; k < n; k++){
      profit += p[k][cnt[k]];
    }
    if(i==1||profit>maxprofit) maxprofit = profit;
  }
  cout << maxprofit << endl;
}


Measured memory_bytes: 256
io = STDIN
s=io.gets.chomp.split(//)
sz=s.size
if sz.even?
  pre=s[0,sz/2]
  post=s[sz/2,sz/2].reverse
else
  pre=s[0,sz/2]
  post=s[sz/2+1,sz/2].reverse
end
puts pre.zip(post).select{|a,b|a!=b}.size


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

using namespace std;

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

    int n, m;
    cin >> n;
    int arr[n], med[n];

    for (int i = 0; i < n; i++)
        cin >> arr[i], med[i] = arr[i];

    sort(med, med + n);
    m = med[n / 2];

    for (int i = 0; i < n; i++)
        if (arr[i] < m)
            cout << m << '\n';
        else
            cout << med[n / 2 - 1] << '\n';

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){

  int n, i, x;
  vector<int> h;

  cin >> n ;
  for ( int i = 0; i < n; i++ ){
    cin >> x;
    h.push_back(x);
  }

  vector <int> rasp (n + 1);

  rasp[n - 1] = 0;
  rasp [n - 2] = abs( h[n - 2] - h[n - 1] );
  for ( int i = n - 3; i >= 0; i-- ){
    rasp [i] =  min ( rasp[i + 1] + abs(h[i + 1] - h[i]), rasp[i + 2] + abs( h[i + 2] - h[i]));
  }
  cout << rasp[0];

  return 0;
}


Measured memory_bytes: 1144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() throws NumberFormatException, IOException {
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(sc.readLine());
		char[] str = sc.readLine().toCharArray();
		int q = Integer.parseInt(sc.readLine());
		
		ArrayList<TreeSet<Integer>> treeSetList = new ArrayList<>();
		for(int i = 0; i < 26; i++) {
			treeSetList.add(new TreeSet<>());
		}
		for(int i = 0; i < n; i++) {
			char ichar = str[i];
			int charVal = ichar - 97;
			treeSetList.get(charVal).add(i);
		}
		
		
		for(int i = 0; i < q; i++) {
			String[] queryArr = sc.readLine().split(" ");
			int queryNo = Integer.parseInt(queryArr[0]);
			if(queryNo == 1) {
				int pos = Integer.parseInt(queryArr[1]) - 1;
				char inputChar = queryArr[2].charAt(0);
				char nowChar = str[pos];
				str[pos] = inputChar;
				treeSetList.get(nowChar-97).remove(pos);
				treeSetList.get(inputChar-97).add(pos);
			}else if(queryNo == 2){
				
				int left = Integer.parseInt(queryArr[1]) - 1;
				int right = Integer.parseInt(queryArr[2]) - 1;
				int ans = 0;
				for(TreeSet<Integer> treeSet : treeSetList) {
					Integer ceilPos = treeSet.ceiling(left);
					
					if(ceilPos != null && ceilPos <= right) {
						ans++;
					}
				}
				System.out.println(ans);
			}
		}
		
		sc.close();
	}
}


Measured memory_bytes: 99696
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] res = new String[n];
		for(int i=0;i<n;i++) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();

			if(a < b || d < b) {
				res[i] = "No";
			}else if(c >= b){
				res[i] = "Yes";
			}else {
				long tmp;
				long x = Math.max(b, d);
				long y = Math.min(b, d);
		        while ((tmp = x % y) != 0) {
		            x = y;
		            y = tmp;
		        }
		        if(b + a%y - y <= c) {
		        	res[i] = "Yes";
		        }else {
		        	res[i] = "No";
		        }
			}
		}
		for(int i=0;i<n;i++) {
			System.out.println(res[i]);
		}


	}
}

Measured memory_bytes: 22704
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

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

int N;

int main() {
  cin >> N;
  vector<int> A(N);
  rep(i,N) {
    cin >> A.at(i);
  }
  int ans = 0;
  rep(i,N-1) {
    if (A.at(i) == A.at(i+1)) {
      ans++;
      i++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
c=0
b=0
wi=0
x=[-1,0,1,0]
y=[0,-1,0,1]
buf=[]
def one():
    return -1
def count(h,w,S,table,H,W,index):
    global buf,x,y,b,wi
    if index==1:
        b+=1
    else:
        wi+=1
    if index==1:
        S[h][w]='@'
    for i in range(4):
        if h+y[i]>=0 and h+y[i]<H and w+x[i]>=0 and w+x[i]<W:
            if table[h+y[i]][w+x[i]]==-1:
                if index==0 and S[h+y[i]][w+x[i]]=='#':
                    table[h+y[i]][w+x[i]]=1
                    buf.append([h+y[i],w+x[i],1])
                elif index==1 and S[h+y[i]][w+x[i]]=='.':
                    table[h+y[i]][w+x[i]]=1
                    buf.append([h+y[i],w+x[i],0])
    if buf:
        a=buf.pop(0)
        count(a[0],a[1],S,table,H,W,a[2])
sys.setrecursionlimit(10000000)
H,W=map(int,input().split())
T=[]
table=[[-1 for j in range(W)] for i in range(H)]
for i in range(H):
    T.append(input())
S=[['' for j in range(W)]for i in range(H)]
for h in range(H):
    for w in range(W):
        S[h][w]=T[h][w]
for h in range(H):
    for w in range(W):
        if S[h][w]=='#':
            table[h][w]=0
            count(h,w,S,table,H,W,1)
            c+=b*wi
            b=0
            wi=0
print(c)




Measured memory_bytes: 164468
import java.io.*;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		scan.useDelimiter("\\D+");
		
		Stack<Integer> a = new Stack<Integer>();
		
		while (scan.hasNext()) {
			int data = scan.nextInt();
			
			if(data != 0){
				a.push(data);
			}else
			{
				System.out.println(a.pop());
			}
		}
		scan.close();
	}
}

Measured memory_bytes: 26076
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int n;
main()
{
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int q;cin>>q;
  for(int i=0;i<q;i++)
  {
    int k;cin>>k;
    cout<<distance(a.begin(),lower_bound(a.begin(),a.end(),k))<<endl;
  }
}



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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int deltaX = abs(x1 - x2);
    int deltaY = abs(y1 - y2);
    int x3, y3, x4, y4;
    if (x1 <= x2 && y1 > y2) {
        x3 = x2 + deltaY;
        y3 = y2 + deltaX;
        x4 = x1 + deltaY;
        y4 = y1 + deltaX;
    }
    else if (x1 <= x2 && y1 < y2) {
        x3 = x2 - deltaY;
        y3 = y2 + deltaX;
        x4 = x1 - deltaY;
        y4 = y1 + deltaX;
    }
    else if (x1 > x2 && y1 <= y2) {
        x3 = x2 - deltaY;
        y3 = y2 - deltaX;
        x4 = x1 - deltaY;
        y4 = y1 - deltaX;
    }
    else if (x1 > x2 && y1 >= y2) {
        x3 = x2 + deltaY;
        y3 = y2 - deltaX;
        x4 = x1 + deltaY;
        y4 = y1 - deltaX;
    }

    cout << x3 << " " << y3 << " " << x4 << " " << y4 <<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Point struct {
	x, y int
}

func MakeNextInt(n int) <-chan int {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	ch := make(chan int, n)
	go func(ch chan int) {
		for {
			sc.Scan()
			num, err := strconv.Atoi(sc.Text())
			if err != nil {
				break
			}
			ch <- num
		}
		close(ch)
	}(ch)

	return ch
}

func main() {
	ch := MakeNextInt(1000)

	n := <-ch
	a := make([]Point, n)
	for i := 0; i < n; i++ {
		a[i] = Point{<-ch, <-ch}
	}

	sort.Slice(a, func(i, j int) bool {
		if a[i].x != a[j].x {
			return a[i].x < a[j].x
		}
		return a[i].y < a[j].y
	})

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprintln(w, a[i].x, a[i].y)
	}
	w.Flush()
}



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

int main()
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int xmax=x,ymin=y;
    rep(i,n)
    {
        int l;
        cin>>l;
        if(xmax<l)xmax=l;
    }
    rep(i,m)
    {
        int l;
        cin>>l;
        if(ymin>l)ymin=l;
    }
    if(ymin-xmax>0)
    {
        cout<<"No War"<<endl;
    }
    else
    {
        cout<<"War"<<endl;
    }
    
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
like = [0] * (M + 1)

for i in range(N):
  for j in range(1, len(A[i])):
    like[A[i][j]] += 1

#print(like)
count = 0
for i in range(M+1):
  if like[i] == N:
    count += 1

print(count)


Measured memory_bytes: 38384