akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF 100
int main(){
  int n;
  cin >> n;
  int alp = 'z'-'a'+1;
  int mn[alp];
  for(int i=0;i<alp;i++) mn[i] = INF;
  string s; 
  for(int i=0;i<n;i++){
	int cnt[alp] = {};
    cin >> s;
    for(int j=0;j<s.size();j++){
      cnt[s[j]-'a']++;
    }
	for(int j=0;j<alp;j++) mn[j] = min(mn[j], cnt[j]);
  }
  for(int i=0;i<alp;i++){
    while(mn[i]!=0){
	  cout << (char)('a' + i);
      mn[i]--;
    }
  }
  cout << endl;
}


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

int main() {
	string s,t,u;
  int a,b,c;
  cin>>s>>t;
  cin>>a>>b;
  cin>>u;
  
  if(u==s){
  	a=a-1;
  }
  else{
  	b=b-1;
  }
  cout<<a<<" "<<b<<endl;
}

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

const int64_t MOD = 1e+09 + 7;

vector<int64_t> pow2(1e+5 + 10);
vector<int64_t> pow3(1e+5 + 10);
void pow () {
    int64_t num = 1,num2 = 1;
    for ( int64_t i = 0; i < 1e+5 + 10; ++i){
        pow2[i] = num2;
        pow3[i] = num;
        num2 = num2 * 2 % MOD;
        num = num * 3 % MOD;
    }
    return;
}

int main() {
    string L;
    cin >> L;
    
    pow();
    
    int64_t ans = 0;
    int64_t num1 = 0;
    for ( int64_t i = 0; i < L.size(); ++i){
        int64_t x =  L.at(i) - '0';
        if ( x == 1 ){
            int64_t restsize = L.size() - (i+1);
            ++num1;
            //cout << restsize << " " << pow3[restsize] << " " << num1 << " " << pow2[num1] << endl;
            ans = ( ans + pow3[restsize] * pow2[num1-1] ) % MOD;
        } /*else if ( i == L.size() - 1 ){
            ans = ( ans + pow2[num1] ) % MOD;
        }*/
    }
    
    cout << ( ans + pow2[num1] ) % MOD << endl;
    return 0;
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto n = load<int>();
    auto height = loadMany<int>(n);
    int r = height[-12391243];
    auto dyn = vector<int>(n);
    dyn[0] = 0;
    for (auto i=1; i<n; ++i) {
        dyn[i] = dyn[i-1] + abs(height[i-1] - height[i]);
        if (i >= 2)
            dyn[i] = min(dyn[i], dyn[i-2] + abs(height[i] - height[i-2]));
    }

    cout << dyn[n-1] << '\n';
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int a, b;cin >> a >> b;
    cout << (a+b+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

ll calc(string s) {
    int n = int(s.size());
    ll ans = 0;
    int l = 0;
    while (l < n) {
        int r = l;
        while (r < n && s[l] == s[r]) r++;
        ans += (r - l) / 2;
        l = r;
    }
    return ans;
}

string rep(string s, int k) {
    string t;
    for (int i = 0; i < k; i++) {
        t += s;
    }
    return t;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s;
    int k;
    cin >> s >> k;

    if (k < 1000) {
        cout << calc(rep(s, k)) << endl;
    } else {
        int u = (k - 900) / 2;
        k -= 2 * u;
        ll a = calc(rep(s, k));
        ll b = calc(rep(s, k + 2));
        cout << a + (b - a) * u << endl;
    }
    return 0;
}


Measured memory_bytes: 512
n,m = gets.split.map!(&:to_i)

a = []
n.times {a << gets.chomp!}

b = []
m.times {b << gets.chomp!}

(n-m+1).times do |i|
    (n-m+1).times do |j|
        x = a[i,m].map{|s| s[j,m]}
        #p x
        if x == b
            puts "Yes"
            exit
        end
    end
end

puts "No"

Measured memory_bytes: 2044
#include <iostream>

void printSort(int * A, int N) {
    for (int i = 0; i < N - 1; i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A[N - 1] << std::endl;
}

void insertionSort(int * A, int N) {
    for (int i = 0; i < N; i++) {
        int v = A[i];
        for (int j = i - 1; j >= 0; j--) {
            if (v > A[j]) break;
            A[j + 1] = A[j];
            A[j] = v;
        }
        printSort(A, N);
    }
}

int main() {
    int N;
    std::cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    insertionSort(A, N);
}



Measured memory_bytes: 3116
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <string.h>
#include <vector>




int main() {
	long long N, C;

	scanf("%lld %lld", &N,&C);
	
	std::vector<std::pair<long long, long long>> sushi;

	long long tmp,tmp2;
	for (int i = 0; i < N; i++) {
		scanf("%lld %lld", &tmp, &tmp2);
		sushi.push_back(std::make_pair(tmp,tmp2));
	}
	std::sort(sushi.begin(), sushi.end());

	long long ans = 0;
	long long ans2 = 0;
	long long ans3 = 0;
	long long ans4 = 0;

	long long ir = -1;
	long long jl = N;



	//1.Go R
	std::vector<std::pair<long long, long long>> ir_max;;
	long long max = 0;
	long long dist = 0;
	long long sum = 0;
	for (long long i = 0; i < N; i++) {
		dist = sushi[i].first;
		sum += sushi[i].second;
		if (sum - dist >= max) {
			max = sum - dist;
			ans = max;
			ir = i;
		}
		ir_max.push_back(std::make_pair(ir,max));
	}

//	printf("%lld\n", ans);

	std::vector<std::pair<long long, long long>> jl_max;;
	//2.Go L
	sum = 0; max = 0;
	for (long long j = N-1; j >= 0; j--) {
		dist = C - sushi[j].first;
		sum += sushi[j].second;
		if (sum - dist >= max) {
			max = sum - dist;
			ans2 = max;
			jl = j;
		}
		jl_max.push_back(std::make_pair(jl, max));
	}
//	printf("%lld\n", ans2);

	//3.Go L then R
	long long i;
	sum = 0;
	max = 0;
	for (long long j = N - 1; j > 0; j--) {
		i = ir_max[j-1].first;
		sum += sushi[j].second;
		if (i != -1) {
			dist = 2 * (C - sushi[j].first);
			if (max <= sum + ir_max[j-1].second - dist) {
				max = sum + ir_max[j-1].second - dist;
				ans3 = max;
			}
		}
	}

	//4.Go R then L

	long long j;
	sum = 0;
	max = 0;
	for (long long i = 0; i < N-1; i++) {
		j = jl_max[N-2-i].first;
		sum += sushi[i].second;
		if (j != N) {
			dist = 2 * sushi[i].first;
			if (max <= sum + jl_max[N-2-i].second - dist) {
				max = sum + jl_max[N-2-i].second - dist;
				ans4 = max;
			}
		}
	}




	printf("%lld", std::max(std::max(ans,ans2), std::max(ans3, ans4)));




	return 0;
}

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

int main() {
  vector<vector<int>> A(3,vector<int>(3,0)); // ビンゴカード
  int N;  // 引いた回数≦１０
  vector<int> B(N,0); // 引いた値
  string Ans="No";     // ビンゴ成立

  // ビンゴカードを作る
  rep(i,3){
    rep(j,3){
      cin >> A.at(i).at(j);
    }
  }
  // 引いた数
  cin >> N;
  rep(k,N){  // 引いてく
    cin >> B.at(k);

    // 穴あけ
    rep(i,3){
      rep(j,3){
        if ( A.at(i).at(j) == B.at(k) ) {  // ヒット
          A.at(i).at(j) = 1000;
          // 縦チェック：行番号違い・列番号同じ
          if ( A.at(0).at(j) == 1000 && A.at(1).at(j) == 1000 && A.at(2).at(j) == 1000 ) {
            Ans="Yes";
            break;
          }
          // 横チェック：行番号同じ・列番号違い
          if ( A.at(i).at(0) == 1000 && A.at(i).at(1) == 1000 && A.at(i).at(2) == 1000 ) {
            Ans="Yes";
            break;
          }
          // 斜めチェック：左上から右下
          if ( A.at(0).at(0) == 1000 && A.at(1).at(1) == 1000 && A.at(2).at(2) == 1000 ) {
            Ans="Yes";
            break;
          }
          // 斜めチェック：右上から左下
          if ( A.at(0).at(2) == 1000 && A.at(1).at(1) == 1000 && A.at(2).at(0) == 1000 ) {
            Ans="Yes";
            break;
          }
        }
      }
      if (Ans =="Yes") { break;}
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 384
#include <cstdio>

const int maxn = 2e6 + 100, mod = 1e9 + 7;

int fac[maxn], ifac[maxn], x[6], y[6];

int pow_mod(int x, int n) {
	int y = 1;
	while(n) {
		if(n & 1) {
			y = 1ll * y * x % mod;
		}
		x = 1ll * x * x % mod;
		n >>= 1;
	}
	return y;
}

void pre() {
	int n = maxn - 1;
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
	}
	ifac[n] = pow_mod(fac[n], mod - 2);
	for (int i = n; i >= 1; --i) {
		ifac[i - 1] = 1ll * ifac[i] * i % mod;
	}
	return;
}

int C(int n, int m) {
	return n < m || m < 0 ? 0 : 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int F(int x, int y) {
	return C(x + y, x);
}

int solve(int x1, int y1, int x2, int y2, int x3, int y3) {
/*
	int ret = 0;
	for (int x = x1; x <= x2; ++x) {
		for (int y = y1; y <= y2; ++y) {
			ret = (1ll * F(x, y) * F(x3 - x, y3 - y) + ret) % mod;
		}
	}
	return ret;
*/
	
	int ret = 0, cur = 1ll * F(x1, y1) * F(x3 - x1, y3 - y1) % mod;
	for (int i = x1 + y1; i < x1 + y2; ++i) {
		(ret += cur) %= mod;
		int x, y;
		y = y1;
		x = i + 1 - y;
		cur = (1ll * F(x, y - 1) * F(x3 - x, y3 - y) + cur) % mod;
		x = x1;
		y = i + 1 - x;
		cur = (1ll * F(x - 1, y) * F(x3 - x, y3 - y) + cur) % mod;
	}
	for (int i = x1 + y2; i < x2 + y1; ++i) {
		(ret += cur) %= mod;
		int x, y;
		y = y2 + 1;
		x = i + 1 - y;
		cur = (-1ll * F(x, y - 1) * F(x3 - x, y3 - y) + cur) % mod;
		y = y1;
		x = i + 1 - y;
		cur = (1ll * F(x, y - 1) * F(x3 - x, y3 - y) + cur) % mod;
	}
	for (int i = x2 + y1; i < x2 + y2; ++i) {
		(ret += cur) %= mod;
		int x, y;
		y = y2 + 1;
		x = i + 1 - y;
		cur = (-1ll * F(x, y - 1) * F(x3 - x, y3 - y) + cur) % mod;
		x = x2 + 1;
		y = i + 1 - x;
		cur = (-1ll * F(x - 1, y) * F(x3 - x, y3 - y) + cur) % mod;
	}
	//printf("solve(%d, %d, %d, %d, %d, %d) = %d\n", x1, y1, x2, y2, x3, y3, ((ret + cur) % mod + mod) % mod);
	return (ret + cur) % mod;
	
}

int main() {
	pre();
	for (int i = 0; i < 6; ++i) {
		scanf("%d", x + i);
	}
	for (int i = 0; i < 6; ++i) {
		scanf("%d", y + i);
	}
	if(x[3] - x[2] < y[3] - y[2]) {
		for (int i = 0; i < 6; ++i) {
			x[i] ^= y[i];
			y[i] ^= x[i];
			x[i] ^= y[i];
		}
	}
	int ans = 0;
	for (int s = 0; s < 16; ++s) {
		int f = 1, t = s & 3, a, b, c, d;
		if(t == 0) {
			a = x[1], b = y[1];
		}
		else if(t == 1) {
			a = x[1], b = y[0] - 1;
			f = -f;
		}
		else if(t == 2) {
			a = x[0] - 1, b = y[1];
			f = -f;
		}
		else {
			a = x[0] - 1, b = y[0] - 1;
		}
		t = s >> 2 & 3;
		if(t == 0) {
			c = x[5] + 1, d = y[5] + 1;
		}
		else if(t == 1) {
			c = x[5] + 1, d = y[4];
			f = -f;
		}
		else if(t == 2) {
			c = x[4], d = y[5] + 1;
			f = -f;
		}
		else {
			c = x[4], d = y[4];
		}
		(ans += f * solve(x[2] - a, y[2] - b, x[3] - a, y[3] - b, c - a, d - b)) %= mod;
	}
	return !printf("%d\n", (ans + mod) % mod);
}

Measured memory_bytes: 15872
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>

#define REP(i,n) for(i=0; i < (n); i++)
#define REPONE(i, n) for(i=1; i <= (n); i++)
#define LOOP(n) for(int loopCount=1; loopCount <= (n); loopCount++)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define SUM(c) accumulate(ALL(c), 0)
#define EXIST(c,v) (find(ALL(c), (v)) != (c).end())
#define PB push_back
#define MP make_pair

using namespace std;
static const double EPS = 1e-9;
static const double PI = 3.141592653589793238462643383279;
typedef long long ll;

vector<int> primetable(int n){
  vector<int> ps;
  vector<int> table(n+1, 0);
  for(int i=2; i<=n; i++){
    if(!table[i]){
      ps.push_back(i);
      if(i <= sqrt(n)) table[i*i] = i;
    }
    else{
      int j = i, step = table[i];
      while(j+step<=n){
	if(!table[j+step]) {
	  table[j+step] = step;
	  break;
	}
	else {
	  int tmp = step;
	  step = table[j+step];
	  table[j+tmp] = tmp;
	  j += tmp;
	}
      }
    }
  }
  return ps;

}

int main(){
	vector<int> ps = primetable(1299710);
	int n, a, b;
	ITER(ps) it;
	while(cin >> n){
		if(n==0) break;
		if(binary_search(ALL(ps), n)){
			cout << 0 << endl;
			continue;
		}
		it = lower_bound(ALL(ps),n);
		cout << *it - *(it-1) << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MOD = 1000000007;

class BIT {
public:
    /* [1, n] */
    vector<long long> bit;

    BIT(int M) :
            bit(vector<long long>(M + 1, 0)) {}

    /* [1, a], a is 1-indexed */
    long long sum(int a) {
        long long res = 0;
        for (int i = a; i > 0; i -= (i & -i)) {
            res += bit[i];
        }
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    long long sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    /* a is 1-indexed */
    void add(int a, long long x) {
        for (int i = a; i < bit.size(); i += (i & -i)) {
            bit[i] += x;
        }
    }
};

int main() {
    long long N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    int low = 0, high = 1 << 30;
    const int geta = N + 1;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        long long num = 0;
        BIT bit(N * 2 + 10);
        int sum = 0;
        bit.add(sum + geta, 1);
        for (int i = 0; i < N; ++i) {
            int val;
            if (a[i] <= mid) val = 1; else val = -1;
            sum += val;
            num += bit.sum(1, sum + geta);
            bit.add(sum + geta, 1);
        }
        if (num > (N + 1) * N / 2 / 2) high = mid;
        else low = mid;
    }
    cout << high << endl;
}

Measured memory_bytes: 2176
A, B = map(int, input().strip().split())

def is_palind(x):
  sx = str(x)
  if sx[0]==sx[-1] and sx[1]==sx[-2]:
    return True
  else:
    return False

c = 0
for a in range(A, B+1):
  if is_palind(a):
    c+=1

print(c)


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 13
#define pi M_PI

int main(){
    int n;
    scanf("%d",&n);
    int a[100];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int min,count;
   for(int i=0;i<n;i++){
       min=i;
        for(int j=i;j<n;j++){
            if(a[j]<a[min]){
                min=j;
            }
        }
if(min!=i){
        int tmp=a[i];
        a[i]=a[min];
        a[min]=tmp;
        count++;
        }
    }
    for(int i=0;i<n;i++){
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",count);
}


Measured memory_bytes: 2104
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
long long a,b,c,d,p[100000],q[100000],r[100000],i,j,k,n,f;
int main(){
	cin>>a>>b;
	long long u,v;
	cin>>u;
	for(i=1;i<a;i++){
		cin>>v;
		auto x=max(0ll,u+v-b);
		n+=x;
		u=max(0ll,v-x);
	}
	cout<<n<<endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        sc.nextLine();
        String S = sc.nextLine();
        String T = sc.nextLine();

        if (S.charAt(0) != T.charAt(0)) {
            System.out.println(-1);
            return;
        }

        long G = lcm(N, M);
        long n = G / N;
        long m = G / M;

        while ((n - G/N <= M - 1) && (m - G/M)<= N - 1) {
            if (S.charAt((int)(m - G/M)) == T.charAt((int)(n - G/N))) {
                n = n + G/N;
                m = m + G/M;
            } else {
                System.out.println(-1);
                return;
            }
        }

        System.out.println(G);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 27452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                       \
  ifstream in("atcoder-problems/agc018_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

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

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<ll> c(N);
  ll m = 0;
  rep(i, N) {
    cin >> c[i];
    m = max(m, c[i]);
  }

  ll _gcd = c[0];
  rep(i, N) { _gcd = gcd(_gcd, c[i]); }

  bool ret = K <= m && K % _gcd == 0;

  cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int A[1000][1000]={{}};
int b[1000]={};
int main(void){
   int n, m, i, j;
   int sum;
   cin >> n >> m;
   for(i=0; i<n; i++){
       for(j=0;j<m;j++){
           cin >> A[i][j];
       }
   }
   for(i=0; i<m; i++){
       cin >>b[i];
   }
   
   for(i=0; i<n; i++){
       sum = 0;
       for(j=0; j<m; j++){
           sum += A[i][j] * b[j];
       }
       cout << sum << endl;
   }
}


Measured memory_bytes: 3428
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 510000+50

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, char *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %c", a1, a2, a3);
#else
#error
#endif
  return 0;
}

#define OFFSET 210000

enum COMMAND {
    NONE,
    REVERSE,
    ADD,
};

enum {
    UNDEF,
    HEAD,
    TAIL
};

int main(void) {
    static char buf[BUF_SIZE];
    get_str(&buf[OFFSET], BUF_SIZE-OFFSET);
    char *s = &buf[OFFSET];
    size_t len = strlen(s) - 1;
    int pos[3];
    int inc[3] = {0, -1, +1};
    pos[1] = OFFSET-1;
    pos[2] = OFFSET+len;

    int queries = get_int();
    int i;
    int dist = 1;
    for(i = 0; i < queries; i++) {
        int type, where; char ch;
        int idx;
        get_int3(&type, &where, &ch);
        where = (where == 1) ? 1 : -1;
        switch(type) {
            case REVERSE:
                dist = -dist;
                break;
            case ADD:
                idx = (where*dist==1) ? HEAD : TAIL;
                buf[pos[idx]] = ch;
                len++;
                pos[idx] += inc[idx];
                break;
            default:
                break;
        }
#ifdef DEBUG
        printf("%s\n", &buf[pos[1]+1]);
        printf("[%d] dist:%d -> len: %lu (%d, %d)\n", type, dist, len, pos[1], pos[2]);
#endif
    }
//     int start = (dist==1) ? pos[1]+1 : pos[2]-1;
// #ifdef DEBUG
//     printf("start: %d\n", start);
// #endif
//     for(i = start; i > start-len && i < start+len; i=i+(dist)) {
//         putchar(buf[i]);
//     }
//     putchar('\n');
    if(dist==1) {
        int start = pos[1]+1;
        for(i = start; i < start+len; i=i+dist) {
            putchar(buf[i]);
        }
    } else {
        int start = pos[2]-1;
        for(i = start; i > start-len; i=i+dist) {
            putchar(buf[i]);
        }
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 768
using System;
using System.Linq;

namespace question3
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run()
        {
            var n = int.Parse(Console.ReadLine());
            var alist = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            var boobie = alist.OrderBy(a=>a).ToArray()[1];

            for (int i = boobie; i > 0; i--)
            {
                var num = 0;
                for (int j = 0; j < n; j++)
                {
                    if (alist[j] % i == 0)
                    {
                        num++;
                    }
                }

                if (num >= n - 1)
                {
                    Console.WriteLine(i);
                    break;
                }
            }

        }
    }
}


Measured memory_bytes: 29532
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N, A, B;

	cin >> N >> A >> B;

	long ans = 0;
	for (int i = 1; i <= N; i++) {
		int sum = 0;
		sum += i % 10;
		sum += (i / 10) % 10;
		sum += (i / 100) % 10;
		sum += (i / 1000) % 10;
		sum += (i / 10000) % 10;
		if (A <= sum && sum <= B) ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int h[10]= {2, 1, 2, 4, 2, 1, 13, 19, 46, 47 };
int main()
{
    int i,k=0,N,X,Y;
    while(scanf("%d%d",&i,&i)&&i)
    {
        scanf("%d",&N);
        for(i=0; i<N; i++)
            scanf("%d%d%d%d",&X,&Y,&X,&Y);
        printf("%d\n",h[k++]);
    }
    return 0;
}

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

int g[55][55] = {};
int v[55] = {};
vector<pair<int,int>> r;

int dfs(int x){
  v[x] = 1;
  for(int i=0; i<55; i++){
    if(g[x][i] == 1 && v[i] == 0)
      dfs(i);
  }
}

int count(){
  int n=0;
  for(int i=0; i<55; i++)
    if(v[i]) n++;

  return n;
}

int init(){
  for(int i=0; i<55; i++)
    v[i] = 0;
}

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

  int x,y;
  
  for(int i=0; i<m; i++){
    cin >> x >> y;
    x--, y--;
    r.push_back(make_pair(x,y));
    g[x][y] = g[y][x] = 1;
  }
  
  int ans = 0;
  init();
    
  for(int i=0; i<m; i++){
    g[r[i].first][r[i].second] = g[r[i].second][r[i].first] = 0;
    dfs(0);
    if(n != count()) ans++;
    for(int j=0; j<n; j++) v[j] = 0;
    g[r[i].first][r[i].second] = g[r[i].second][r[i].first] = 1;
    init();
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
a=[0]*(N+1)
for i in range(N):
    a[i+1]=a[i]+A[i]
d=[[0]*(N+1) for i in range(N+1)]
for w in range(2,N+1):
    for l in range(N+1-w):
        d[l][l+w]=min([d[l][m]+d[m][l+w] for m in range(l+1,l+w)])+a[l+w]-a[l]
print(d[0][N])

Measured memory_bytes: 43996
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  string s; cin >> s;
  int n = s.size();
  int ans = 0;
  for(int i=0; i<n; i++) {
    if(s[i]-'0' == i%2) ans++;
  }
  int cnt = 0;
  for(int i=0; i<n; i++) {
    if(s[i]-'0' != i%2) cnt++;
  }

  cout << n - max(ans, cnt) << endl;

  return 0;
}


//EOF


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repl(i,n) for(int64_t i=0;i<(int64_t)(n);i++)
#define MAX_N 10000000 //10^7
#define ll int64_t
#define all(v) (v).begin(),(v).end()
using namespace std;

int main() {
    int x,maxx=0; cin>>x;
    for(int i=1;i<=35;i++){
        for(int j=2;j<=9;j++){
            int po=pow(i,j);
            int ab=max(maxx,po);
            if(ab<=x) maxx=ab;
        }
    }
    cout<<maxx<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int n, w;
vector<vector<ll>> cache(101, vector<ll>(100001, -1));
ll dp(int index, int weight, vector<ll>& v, vector<int>& we) {
  if (index == n) { 
    return 0;
  }
  if (cache[index][weight] != -1) {
    return cache[index][weight];
  }
  if (weight - we[index] >= 0) {
    return cache[index][weight] = max(dp(index+1, weight, v, we), v[index] + dp(index+1, weight-we[index], v, we));
  }
  return cache[index][weight] = dp(index+1, weight, v, we);
}
int main() {
  cin >> n >> w;
  vector<ll> v(n); vector<int> we(n);
  for (int i = 0; i < n; i++) {
    cin >> we[i] >> v[i];
  }
  cout << dp(0, w, v, we);
}

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

int main()
{
    int S, h, m, s;

    cin >> S;
    h = S / 3600;
    m = S % 3600 / 60;
    s = S % 60;
    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3100
// Vicfred
// https://atcoder.jp/contests/abl/tasks/abl_c
// graph, dsu, dfs, bfs
#include <iostream>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

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

    dsu uf(n);

    int a, b;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        a -= 1;
        b -= 1;
        uf.merge(a, b);
    }

    auto cities = uf.groups();

    cout << cities.size() - 1 << endl;

    return 0;
}



Measured memory_bytes: 9080
N,K,Q = input().split()
N,K,Q = int(N),int(K),int(Q)
A = []
for i in range(Q):
    A.append(int(input()))
    
Ns=[0 for i in range(N)]

for i in range(Q):
    Ns[A[i]-1] += 1
    
for i in range(N):
    if(K-Q+Ns[i]>0):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8624
N, W = map(int, input().split())
w_list = [0]
v_list = [0]
ans = 0

for i in range(N):
    w, v = map(int, input().split())
    w_list.append(w)
    v_list.append(v)

INF = float("INF")
dp = [[INF] * (10 ** 5 + 1) for i in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    for j in range(100001):
        if j - v_list[i] >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v_list[i]] + w_list[i])
        else:
            dp[i][j] = dp[i - 1][j]

for i in range(100001):
    if dp[N][i] != INF and dp[N][i] <= W:
        ans = max(ans, i)

print(ans)

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


int main() {
  ll n;
  cin>>n;
  vector<P>w;
  rep(i,n){
    ll a,b;
    cin>>a>>b;
    P p(b,a);
    w.emplace_back(p);
  }
  sort(w.begin(),w.end());
  reverse(w.begin(),w.end());
  ll cnt=0;
  string ans="Yes";
  rep(i,n){
    P pnow=w.back();
    w.pop_back();
    cnt+=pnow.second;
    //cout<<cnt<<endl;
    if (pnow.first<cnt) {ans="No"; break;}
  }
  cout<<ans;
}


Measured memory_bytes: 2420
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // tmp0 = input[0].split(" ");
    tmp1 = input[1].split(" ");
    N = Number(input[0])
    H = []
    for(var i=0; i < N; i++)
    {
      H.push(Number(tmp1[i]))
    }

    beforeH = H[0]

    for(var i=1; i < N; i++)
    {
      if(beforeH < H[i])
      {
        H[i]--
      }
      else if(beforeH > H[i])
      {
        console.log("No")
        return;
      }
      beforeH = H[i]
    }
    console.log("Yes")
}
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("5\n1 2 1 1 3\n");

Measured memory_bytes: 28096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int payment = 0;
		for (int i = 0; i < n; i+=1000) {
			payment += 1000;
		}
		int exa = payment - n;
		System.out.println(exa);
	}
}


Measured memory_bytes: 35792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var S = ReadLine();

            var ans = 0;
            var buf = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] != 'A' && S[i] != 'C' && S[i] != 'G' && S[i] != 'T')
                {
                    ans = Math.Max(ans, buf);
                    buf = 0;
                }
                else buf++;
            }
            if (buf > ans) ans = buf;
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp
// 選択ソート
static void printArray(vector<int> vector) {
    int size = vector.size();
    for (int i = 0; i < size; ++i) {
        if (i == size - 1) {
            cout << vector[i] << endl;
        } else {
            cout << vector[i] << " ";
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);

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

    int counter = 0;
    for (int i = 0; i < N; ++i) {
        int minj = i;
        for (int j = i; j < N; ++j) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        
        if(i != minj) {
            swap(A[i], A[minj]);
            ++counter;
        }
    }

    printArray(A);
    cout << counter << endl;

    return 0;
}




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

long long GCD(long long former, long long latter){
    if(former % latter == 0)return latter;
    if(latter % former == 0)return former;
    return(GCD(latter, former%latter));
}

int main(void){

    long long A, B;

    cin >> A >> B;

    cout << A*B/GCD(A,B) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,k,max,i,n=0;
  scanf("%d %d %d", &a,&b,&k);
  if(a>b){
    max=b;
  } else{
    max=a;
  }
  for(i=max;i>=1;i--){
    if(a%i==0 & b%i==0){
      n++;
        if(n==k){
          break;
        }
    }
  }

  printf("%d",i);

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;

int kakuketanosum(int n) {
	int s = 0;
	while (n > 0) {
		s += n % 10;
		n = n / 10;
	}
	/*if (s >= 10)
		s = kakuketanosum(s);
	else*/
		return s;
}
int main(void) {
	int n, k;
	cin >> n >> k;
	int s = 1;
	for (int i = 0; i < n; i++) {
		s = min(s + k, 2 * s);
	}
	cout << s << endl;
}

Measured memory_bytes: 256
class Triangle():
    def __init__(self, A, B, C):
        # 3点の座標
        self.A = A
        self.B = B
        self.C = C
        Ax, Ay = A
        Bx, By = B
        Cx, Cy = C
        a = ((Bx-Cx)**2+(By-Cy)**2)**0.5
        b = ((Cx-Ax)**2+(Cy-Ay)**2)**0.5
        c = ((Ax-Bx)**2+(Ay-By)**2)**0.5
        # 3辺の長さ
        self.a = a
        self.b = b
        self.c = c
        # 外心の座標
        s = a**2*(b**2+c**2-a**2)
        t = b**2*(c**2+a**2-b**2)
        u = c**2*(a**2+b**2-c**2)
        Ux = (s*Ax+t*Bx+u*Cx)/(s+t+u)
        Uy = (s*Ay+t*By+u*Cy)/(s+t+u)
        self.U = (Ux, Uy)
        # 重心の座標
        self.G = ((Ax+Bx+Cx)/3, (Ay+By+Cy)/3)


class Circle():
    # 中心p、半径rの円
    def __init__(self, p, r):
        self.p = p
        self.r = r

    def contain(self, q):
        # 点qを含むか判定
        px, py = self.p
        qx, qy = q
        return (px-qx)**2+(py-qy)**2 <= self.r**2 + 10**(-7)


def distance(a, b):
    ax, ay = a
    bx, by = b
    return ((ax-bx)**2+(ay-by)**2)**0.5


def enclose(P):
    n = len(P)
    if n == 2:
        ax, ay = P[0]
        bx, by = P[1]
        p = ((ax+bx)/2, (ay+by)/2)
        r = distance(P[0], p)
        return Circle(p, r)
    if n == 3:
        circle = enclose([P[0], P[1]])
        if circle.contain(P[2]):
            return circle
        circle = enclose([P[1], P[2]])
        if circle.contain(P[0]):
            return circle
        circle = enclose([P[2], P[0]])
        if circle.contain(P[1]):
            return circle
        triangle = Triangle(P[0], P[1], P[2])
        u = triangle.U
        r = distance(u, P[0])
        return Circle(u, r)
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                circle = enclose([P[i], P[j], P[k]])
                if all([circle.contain(q) for q in P]):
                    return circle


n = int(input())
P = []
for i in range(n):
    x, y = map(int, input().split())
    P.append((x, y))
circle = enclose(P)
print(circle.r)


Measured memory_bytes: 3192
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200005;
int n;
int a[N];
long long sum[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+a[i];
	long long ans=1e18;
	for(int i=1;i<n;i++)
		ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
    cout<<x2+(y1-y2)<<' '<<y2-(x1-x2)<<' '<<x1+(y1-y2)<<' '<<y1-(x1-x2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// https://beta.atcoder.jp/contests/arc065/tasks/arc065_b

fn bfs(
    size: usize,
    //cmap: &[(usize, usize, i64)]
    cmap: &Vec<Vec<(usize, i64)>>
) -> bool {
    let mut q: VecDeque<usize> = VecDeque::new();
    let mut visited: [bool; 100005] = [false; 100005];
    let mut node: [i64; 100005] = [0; 100005];
    for n in 0..100000 {
        if visited[n] { continue; }
        visited[n] = true;
        node[n] = 0;
        q.push_back(n);
        while !q.is_empty() {
            let &c = q.front().unwrap();
            for &(r, d) in &cmap[c] {
                let (c_to_i, to) = (d, r);//if c == l { (d, r) } else { (-d, l) };
                if visited[to] { // 既に決めた場所なのでチェック
                    if node[c] + c_to_i == node[to] { continue; } //OK
                    else { return false; }
                }
                // きたことないのでNodeの値を決める
                node[to] = node[c] + c_to_i;
                visited[to] = true;
                q.push_back(to);
            }
            q.pop_front();
        }
    }
    return true;
}

fn main() {
    let cin = stdin(); let cin = cin.lock(); let mut sc = Scanner::new(cin);

    let (n, m): (usize, usize) = (sc.read(), sc.read());
    // NxNの２次元配列
    //let mut lrd: [(usize, usize, i64); 200005] = [(0, 0, 0); 200005];
    let mut lrd: Vec<Vec<(usize, i64)>> = vec![Vec::new(); 100000];

    for i in 0..m {
        let (l, r, d): (usize, usize, i64) = (sc.read(), sc.read(), sc.read());
        let l = l - 1; let r = r - 1;
        lrd[l].push((r, d));
        lrd[r].push((l, -d));
        //lrd[i] = (l, r, d);
    }

    if !bfs(m, &lrd) { println!("No"); }
    else { println!("Yes"); }
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

Measured memory_bytes: 19580
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const ll INF = (ll)1 << 60;

int main() {
    int N, M;
    cin >> N >> M;
    int a[N], b[N];
    rep(i, N) {
        cin >> a[i] >> b[i];
    }
    int c[M], d[M];
    rep(i, M) {
        cin >> c[i] >> d[i];
    }
    rep(i, N){
        int min_len = 2000000000;
        int min_id = 2000000000;
        for(int j=M-1; j >=0; j--) {
            int kyori = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if (kyori <= min_len) {
                min_len = kyori;
                min_id = j;
            }
        }
        cout << min_id+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, K;
bool has[105];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1, D, tmp; i <= K; i++) {
		cin >> D;
		for (int j = 1; j <= D; j++) {
			cin >> tmp;
			has[tmp] = 1;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= N; i++) cnt += !has[i];
	cout << cnt << '\n';
}


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

int main(){
    string n;
    cin >> n;

    for (auto i = 0; i < n.size(); i++) {
        if(n[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << ("No") << endl;
    return 0;
}

Measured memory_bytes: 3624
#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>;

int main(){
    int n;
    cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll lcm=a[0];
    for(int i=1; i<n; ++i){
        lcm=lcm/__gcd(lcm,a[i])*a[i];
    }
    cout<<lcm<<endl;
}

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

public class Main {
    static int[][] a = new int[100010][3];
    static int[][] dp = new int[100010][3];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (j == k)
                        continue;
                    dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
                }

            }
        }
        int ans = 0;
        for (int i = 0; i < 3; i++) {
            ans = chmax(ans, dp[n][i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 101796
s = input()

s_len = len(s)
acgt_len = 0
chg_flag = 0
cnt_buf = 0
cnt = 0
for i in range(len(s)):
    if s[i] in ["A", "C", "G", "T"]:
        cnt += 1
    elif cnt_buf <= cnt:
        cnt_buf = cnt
        cnt = 0
    else:
        cnt = 0

if cnt_buf <= cnt:
    acgt_len = cnt
else:
    acgt_len = cnt_buf

print(acgt_len)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Here your code !
    int h,w;
    int i,j;
    while(1){
        scanf("%d %d\n", &h, &w);
        if( h == 0 && w == 0){
            break;
        }
        for( i = 0; i < h; ++i){
            for( j = 0; j < w; ++j){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt = 0;
  long long c;
  cin >> n ;
  for(int i=0;i<n;i++){
    c = 0;
    cin >> c ;
    while(c % 2 == 0){
      c = c / 2;
      cnt++;
    }
  }
  
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const ll N = 2e5 + 2;
const ll Mod = 2520;



int main()
{
	GO;
	for (int i = 1; i <= 5; i++)
	{
		int x; cin >> x;
		if (!x)
		{
			cout << i << '\n'; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3640
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    static int cnt = 0;
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++){
		    h[i] = sc.nextInt();
		}

		// 計算
		int result = 0;
		dfs(h);
		result = cnt;
		// 出力
		System.out.println(result);
        
	}
	
	static void dfs(int[] a){
	    //System.out.println(Arrays.toString(a));
	    ArrayList<Integer> list = new ArrayList<Integer>();
	    int min = 1000;
	    for(int i = 0; i < a.length; i++){
	        if(a[i] < min) min = a[i];
	    }
	    cnt += min;
	    for(int i = 0; i < a.length; i++){
	        if(a[i] == min) list.add(i);
	    }
	    list.add(a.length);
	    int l = 0;
	    for(int i = 0; i < list.size(); i++){
	        int r = list.get(i);
	        int len = r - l;
	        if(len > 0){
	            int[] next = new int[len];
	            for(int j = l; j < l + len; j++){
	                next[j - l] = a[j] - min;
	            }
	            dfs(next);
	        }
	        l = r + 1;
	    }
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  int n; cin >> n;
  Vi v(100000);
  int ans = 0;
  rep(i,n) {
    int a; cin >> a;
    v[a]++;
  }
  rep(i,100000) {
    int sum = 0;
    if ( i - 1 >= 0 ) sum += v[i-1];
    sum += v[i];
    if ( i + 1 < 100000 ) sum += v[i+1];
    chmax(ans,sum);
  }
  pl(ans)
  return 0;
}


Measured memory_bytes: 3724
N = gets.to_i

data = N.times.map { gets.split.map(&:to_i) }

except_zero = data.select { |_, _, h| h != 0 }
zero_only = data.select { |_, _, h| h == 0 }
cand = []

(0..100).each do |cy|
  (0..100).each do |cx|
    x, y, h = except_zero.first
    eh = h + (cy - y).abs + (cx - x).abs

    if except_zero[1..-1].all? { |x, y, h| eh == h + (cy - y).abs + (cx - x).abs }
      cand << [cx, cy, eh]
    end
  end
end

if cand.size == 1
  puts cand.first.join(' ')
else
  ans = cand.find do |cx, cy, eh| 
    zero_only.all? { |x, y, h| h == [eh - (cy - y).abs - (cx - x).abs, 0].max }
  end

  puts ans.join(' ')
end


Measured memory_bytes: 2684
#include <iostream>
#include <vector>
#include <string>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

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

Measured memory_bytes: 3920
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        s: chars
    }
    let abcd: Vec<_> = s.iter().flat_map(|&c| c.to_digit(10u32)).map(|x| x as i32).collect();
    let mut answer = String::new();
    for i in 0..1<<3 {
        let mut part = abcd[0];
        let mut ops: Vec<char> = vec![];
        for j in 0..3 {
            if i & 1 << j == 0 {
                part += abcd[j+1];
                ops.push('+');
            } else {
                part -= abcd[j+1];
                ops.push('-');
            }
        }
        if part == 7 {
            for i in 0..s.len() {
                answer.push(s[i]);
                if i < ops.len() {
                    answer.push(ops[i]);
                }
            }
            answer.push('=');
            answer.push('7');
            break;
        }
        ops.clear();
    }
    println!("{}", answer);
}


Measured memory_bytes: 4352