akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int N,M,C,B[30],A[30][30],ans=0;
    cin>>N>>M>>C;
    for(int i=0;i<M;++i)cin>>B[i];
    for(int i=0;i<N;++i){
        int S=C;
        for(int j=0;j<M;++j){
            cin>>A[i][j];
            S+=A[i][j]*B[j];
        }
        if(S>0)++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
N,K,S = [int(x) for x in stdin.readline().rstrip().split()]

if S == 10**9:
    ans = [S]*K + [1]*(N-K)
else:
    ans = [S]*K + [S+1]*(N-K)
for i in ans:
    print(i,end=" ")

Measured memory_bytes: 4964
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> height(n);
  for(int i = 0; i < n; ++i) cin >> height[i];
  int cnt = 0;
  int ans = 0;
  for(int i = 0; i < n - 1; ++i){
    if(height[i] >= height[i + 1]) cnt++;
    else{
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << endl;
}

Measured memory_bytes: 640
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e6 + 6, mod = (int) 0;
vector<int> adj[N];
int dp[N][2];
void dfs(int v, int p = -1) {
	int sum = 0;
	for (int u : adj[v]) if (u != p) {
		dfs(u, v);
		dp[v][0] += dp[u][1];
		sum += dp[u][1];
	}
	dp[v][1] = dp[v][0];
	for (int u : adj[v]) if (u != p) {
		dp[v][1] = max(dp[v][1], sum - dp[u][1] + 1 + dp[u][0]);
	}
	
	
}
int main() {
	int n;
	cin >> n;
	if (n & 1) {
		cout << "First" << endl;
		return 0;
	}
	for (int j = 1; j < n; ++j) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0);
	if (max(dp[0][0], dp[0][1]) < n / 2) {
		cout << "First" << endl;	
	} else {
		cout << "Second" << endl;
	}
}


Measured memory_bytes: 29440
#include <stdio.h>

int main(void)
{
     int i, j, n;
     
     double x1=0, y1=0, x2=0, y2=0, x3=0, y3=0, x4=0, y4=0, ab, cd, t;

     scanf("%d", &n);
     

     for(i=1; i<=n; i++){
	  for(j=1; j<=8; j++){
	       
	       scanf("%lf", &t);
	       x1 = y1;
	       y1 = x2;
	       x2 = y2;
	       y2 = x3;
	       x3 = y3;
	       y3 = x4;
	       x4 = y4;
	       y4 = t;
	  }
	  ab = (y2 - y1) / (x2 - x1);
	  if(x2-x1==0) ab = 0;
	  else if(y2-y1==0) ab = 101;
	  cd = (y4 - y3) / (x4 - x3);
	  if(x4-x3==0) cd = 0;
	  else if(y4-y3==0) cd = 101;
	  
	  if(ab==cd) printf("YES\n");
	  else printf("NO\n");
     }

     return 0;
}

Measured memory_bytes: 620
lines = STDIN.read.split("\n")
word = lines.shift
n = lines.shift.to_i
lines.each do |line|
  op, *args = line.split(" ")
  case op
  when "print" then
    a, b = args.map(&:to_i)
    puts word[a..b]
  when "reverse" then
    a, b = args.map(&:to_i)
    word[a..b] = word[a..b].reverse
  when "replace" then
    a, b, p = args[0].to_i, args[1].to_i, args[2]
    word[a..b] = p
  end
end

Measured memory_bytes: 8716
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;

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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;

    int l = 1, r = n;

    while(l < r){
        int m = (l + r)/2;
        if(m*108/100 == n){
            cout<<m<<endl;
            return 0;
        }else if(m*108/100 < n){
            l = m + 1;
        }else{
            r = m - 1;
        }
    }
    if(l*108/100 == n){
        cout<<l<<endl;
    }else{
        cout<<":("<<endl;
    }
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				cout<<"Yes"<<"\n";
				return 0;
			}
		}
	}
	cout<<"No"<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector

using namespace std;
int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> Ans(Q), Score(N);
	
	for (size_t i = 0; i < Q; i++)
	{
		cin >> Ans.at(i);
		Ans.at(i)--;


	}

	for (size_t i = 0; i < N; i++)
	{
		Score.at(i) = (K - Q);
	}
	for (size_t i = 0; i < Q; i++)
	{
		Score.at(Ans.at(i))++;
	}
	for (size_t i = 0; i < N; i++)
	{
		if (Score.at(i) > 0)
		{
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    int w, h;
    char c;
    cin >> w >> h >> c;
    vector<vector<char>> hata(h,vector<char>(w));
    rep(i,h){
      rep(j,w){
        hata.at(i).at(j) ='.';
      }
    }
    rep(i,h) {
      hata.at(i).at(0) = '|';
      hata.at(i).at(w-1) = '|';
    }
    rep(i,w){
      hata.at(0).at(i) = '-';
      hata.at(h-1).at(i) = '-';
    }
    hata.at(0).at(0) = '+';
    hata.at(0).at(w-1) = '+';
    hata.at(h-1).at(0) = '+';
    hata.at(h-1).at(w-1) = '+';
    hata.at((h+1)/2-1).at((w+1)/2-1) = c;
    rep(i,h){
      rep(j,w){
        cout << hata.at(i).at(j);
      }
      cout << endl;
    }
}


Measured memory_bytes: 3152
#include <stdio.h>

int main(void) {
  int a,b,c;
  int i, j;
  int asc[3];
  int v, m, n;
  
  scanf("%d %d %d", &asc[0], &asc[1], &asc[2]);

  for (i = 0; i < 3; i++) {
    v = asc[0];
    m = 0;
    for (j =1; j < 3-i; j++) {
      if (v < asc[j]) {
	v = asc[j];
	m = j;
      }
    }
    n = asc[2 - i];
    asc[2 - i] = asc[m];
    asc[m] = n;
    
  }

  for (i = 0; i < 3; i++) {
    if(i < 2)
    printf("%d ", asc[i]);
    else
      printf("%d", asc[i]);
  }
  puts("");
  return 0;
}


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

int main(){
    long long N,M,ans,sub;
ans=10000000000000;
    cin>>N>>M;
  vector<long long>a(N);
    for(int i = 0; i < N; i++){
        cin>>a[i];
      }
  if(N!=M){
  for(int i=0;i<N-M+1;i++){
    sub=abs(a[i])+a[M+i-1]-a[i];
    ans=min(sub,ans);
  }
      for(int i=0;i<N-M+1;i++){
    sub=abs(a[N-i-1])+a[N-i-1]-a[N-i-M];
    ans=min(sub,ans);
  }
      cout<<ans<<endl;
  }
  else{
    ans=min(abs(a[0]),abs(a[N-1]))+a[N-1]-a[0];
        cout<<ans<<endl;
}
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var R = input[2];
            var r = ReadArrayInt();
            var roads = new long[N + 1, N + 1];
            for (int i = 0; i < N + 1; i++) for (int j = 0; j < N + 1; j++) if (!(i == j)) roads[i, j] = int.MaxValue;
            for (int i = 0; i < M; i++)
            {
                input = ReadArrayInt();
                roads[input[0], input[1]] = input[2];
                roads[input[1], input[0]] = input[2];
            }
            for (int i = 1; i < N + 1; i++)
            {
                for (int j = 1; j < N + 1; j++)
                {
                    for (int k = 1; k < N + 1; k++)
                    {
                        roads[j, k] = Math.Min(roads[j, k], roads[j, i] + roads[i, k]);
                    }
                }
            }

            var pl = new PermList(R);
            var list = pl.List();
            var ans = long.MaxValue;

            for (int i = 0; i < pl.Idx(); i++)
            {
                var tmp = 0L;
                for (int j = 0; j < R - 1; j++)
                {
                    tmp += roads[r[list[i, j]], r[list[i, j + 1]]];
                }
                if (tmp < ans) ans = tmp;
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }

    class PermList
    {
        int[,] list;
        int num;
        int idx = 0;

        public PermList(int num)
        {
            list = new int[Factorial(num), num];
            this.num = num;
            for (int i = 0; i < num; i++)
            {
                int[] pat = new int[num];
                pat[0] = i;
                bool[] used = new bool[num];
                used[i] = true;
                int cnt = 1;
                Perm(pat, used, cnt);
            }
        }

        void Perm(int[] pat, bool[] used, int cnt)
        {
            for (int i = 0; i < num; i++)
            {
                if (used[i]) continue;
                pat[cnt] = i;
                used[i] = true;
                cnt++;                
                if (cnt == num) {
                    for (int j = 0; j < num; j++) list[idx, j] = pat[j];
                    idx++;
                }
                else Perm(pat, used, cnt);
                used[i] = false;
                cnt--;
            }
        }

        public int[,] List() { return list; }
        public int Idx() { return idx; }

        int Factorial(int num) { if (num == 0) return 1; return num * Factorial(num - 1); }
    }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int v[MAXN];

void solve(){
	int n, ans = INF, cur, lim = 100;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%d", &v[i]);
	}
	REPN(i, -lim, lim){
		cur = 0;
		REP(j, 0, n){
			cur += (i - v[j]) * (i - v[j]);
		}
		ans = min(ans, cur);
	}
	printf("%d\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

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

using namespace std;

int main() {
    string s; cin >> s;
    int n = s.size();
    int k = n;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) {
            k--;
            i += 2;
        }
    }
    cout << k;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm

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

    int3(n, m, k);
    vb used(n*m+1, false);
    rep(i, n+1) {
        rep(j, m+1) {
            used[i*m+j*n-i*j*2] = true;
        }
    }

    if (used[k]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


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

int N;
void solve() {
    vector<int> own(N * 2);
    vector<int> used(N * 2, false);
    int count_h = 0, count_t = 0;

    for (int i = 0, input = 0; i < N; i++) {
        cin >> input; input--; own[input] = true;
    }
    int curr = true;
    while (count_t != N && count_h != N) {
        for (int i = 0; i < N * 2; i++) {
            if (curr == own[i] && !used[i]) {
                used[i] = true;
                if (curr) count_t++;
                else count_h++;
                curr = !curr;
            }
        }
        curr = !curr;
    }

    cout << N - count_h << endl << N - count_t << endl;
}

int main() {
    while (cin >> N, N) solve();

    return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	vector<char> v1,v2;
	for(int i=0;i<s.length();i++)
	v1.push_back(s[i]); 
	for(int i=0;i<t.length();i++)
	v2.push_back(t[i]);
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	for(int i=0;i<s.length();i++)
	s[i]=v1[i];
	for(int i=0;i<t.length();i++)
	t[i]=v2[t.length()-1-i];
	if(s<t)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>

#define rep(i, initial_value, max_value) for (uint64_t i{initial_value}; i < max_value; ++i)
#define fore(i, a) for(auto &i:a)
#define each(i, c) \
    for( \
        __typeof((c).begin()) i{(c).begin()}, __typeof((c).end()) end{(c).end()}; \
        i != end; \
        ++i \
    )
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using i64 = int64_t; using i32 = int32_t; using u64 = unsigned long long; using u32 = unsigned long;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<class T>bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }

// ===

void _main() {
  int n;
  int m;

  cin >> n >> m;

  int L[m];
  int R[m];

  rep(i, 0, m) cin >> L[i] >> R[i];

  sort(L, L + m, greater<int>());
  sort(R, R + m);

//  int maxL{1};
//  int minR{n};
//
//  rep(i, 0, m) {
//    maxL = max(maxL, L[i]);
//    minR = min(minR, R[i]);
//  }

  int r = R[0];
  chmin(r, n);

  int ans = r - L[0] + 1;
  chmax(ans, (int)0);

//  int ans = minR - maxL + 1;
//  ans = max(ans, 0);

  cout << ans << endl;
}

Measured memory_bytes: 1024
def main():
    n, k = map(int, input().split())

    l = []

    for i in range(n):
        a, b = map(int, input().split())
        l.append((a, b))

    l.sort()

    prev = 0
    for i in range(n):
        prev += l[i][1]
        if k <= prev:
            print(l[i][0])
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 16956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b, s;
  cin >> a >> b;
  s = a + b;
  
  int x;
  x = stoi(s);
  
  vector<int> square;
  for (int i = 1; i*i < 100101; i++) {
    square.push_back(i*i);
  }
  
  bool fin = false;
  for (int i = 0; i < square.size(); i++) {
    if (x == square[i]) {
      cout << "Yes" << endl;
      fin = true;
      break;
    }
  }
  
  if (!fin)
    cout << "No"; 
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

int main()
{
	int N,K;
	cin>>N>>K;
	string S;
	cin>>S;
	FOR(i,0,S.length()){
		if(S[K-1]=='A') S[K-1]='a';
		else if(S[K-1]=='B') S[K-1]='b';
		else if(S[K-1]=='C') S[K-1]='c';
	}
	cout<<S<<endl;
	return 0;
}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define rep2(n) for(ll j=0 ; j<n ; ++j )
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define pii pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
typedef vector<vector<ll> > mat;
#define nl "\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size() 


void solve() {
	ll n,k; cin >> k >> n ;
	ll a[n]; rep(n) cin>>a[i];
	sort(a,a+n);
	ll mx = -1;
	rep(n-1) {
		mx = max(mx,a[i+1]-a[i]);
	}
	cout << k - max(mx,a[0]-a[n-1]+k) ;
}


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

	ll t=1;
	// cin>>t;
	rep(t) {
		solve() ; 
	}
	return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return nCr(n-1,r-1)*n/r;
}

int main(){
  ll m,d; cin >> m >> d; ll ans = 0;
  
  for(ll i=1; i <= m; i++){
    for(ll j=1; j <= d; j++){
      ll d1,d2; ll day = j;
      
      d1 = day % 10;
      day /= 10;
      d2 = day;
      
      if(d1 >= 2 and d2 >= 2 and d1*d2 == i) ans++;
      
    }
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int num = i;
        int sum = 0;
        while (num != 0)
        {
            sum += num % 10;
            num /= 10;
        }

        if (sum >= a && sum <= b)
        {
            ans += i;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(9):
        if b == a[i // 3][i % 3]:
            a[i // 3][i % 3] = 0
flag = True
if a[0][0] == a[0][1] == a[0][2] == 0:
    flag = False
if a[1][0] == a[1][1] == a[1][2] == 0:
    flag = False
if a[2][0] == a[2][1] == a[2][2] == 0:
    flag = False
if a[0][0] == a[1][0] == a[2][0] == 0:
    flag = False
if a[0][1] == a[1][1] == a[2][1] == 0:
    flag = False
if a[0][2] == a[1][2] == a[2][2] == 0:
    flag = False
if a[0][0] == a[1][1] == a[2][2] == 0:
    flag = False
if a[0][2] == a[1][1] == a[2][0] == 0:
    flag = False
print('YNeos' [flag::2])


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, T;
    cin >> N >> T;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<vector<ll>> dp1(N + 1, vector<ll>(T, 0));
    vector<vector<ll>> dp2(N + 1, vector<ll>(T, 0));

    rep(i, N) {
        P p = items[i];
        ll a = p.first;
        ll b = p.second;
        rep(j, T) {
            if (j + a < T) {
                dp1[i + 1][j + a] = max(dp1[i + 1][j + a], dp1[i][j] + b);
            }
            dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j]);
        }
    }
    rep(i, N) {
        P p = items[N - 1 - i];
        ll a = p.first;
        ll b = p.second;
        rep(j, T) {
            if (j + a < T) {
                dp2[i + 1][j + a] = max(dp2[i + 1][j + a], dp2[i][j] + b);
            }
            dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i][j]);
        }
    }
    ll ans = 0;
    rep(i, N) {
        P p = items[i];
        ll x = p.second;
        ll y = 0;
        rep(t, T) {
            ll d1 = dp1[i][t];
            ll d2 = dp2[N - 1 - i][T - 1 - t];
            y = max(y, d1 + d2);
        }
        ans = max(ans, x + y);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 141184
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
 
int main() {
    int end = 0;
    int i1, i2, i3;
    int i;
    cin >> i1 >> i2 >> i3;
    for (i=min(i1, i2);max(i1, i2)>i;i++) {
        if (i == i3) {
            cout << "Yes" << endl;
            end = 1;
        }
    }
    if (end == 0) {
        cout << "No" << endl;
    }
}

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

static const int N = 3;
static const int N2 = 9;

static const int dx[4] = {-1, 0, 1, 0}; //??£??\???{}
static const int dy[4] = {0, -1, 0, 1};
static const int dir[4] = {'u', 'l', 'd', 'r'};

struct Puzzle {
	int p[N2], space;
	string path;

	bool operator < (const Puzzle &p1) const { //????????§?????????
		for (int i = 0; i < N2; i++) {
			if (p[i] == p1.p[i]) continue;
			return p[i] > p1.p[i];
		}
		return false;
	}
};

bool isTarget(Puzzle u) {
	for (int i = 0; i < N2; i++) {
		if (u.p[i] != i + 1) return false; 
	}
	return true;
}

string bfs(Puzzle s) {
	queue<Puzzle> Q;
	map<Puzzle, bool> V; //????????´???Puzzle??§????????????????????§ < ????????????????????¨????????????

	Puzzle u, v;
	s.path = "";
	Q.push(s);
	V[s] = true;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (isTarget(u)) return u.path; //????????????????????????????????§??????
		int sx = u.space / N; //space??????
		int sy = u.space % N; //space??????
		for (int r = 0; r < 4; r++)	{
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			v = u;
			swap(v.p[u.space], v.p[tx * N + ty]);
			v.space = tx * N + ty;
			if (!V[v]) {
				V[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}
	return "unsolvable";
}


int main() {
	Puzzle in;
	for (int i = 0; i < N2; i++) {
		cin >> in.p[i];
		if (!in.p[i]) {
			in.p[i] = N2; //isTarget?????????
			in.space = i;
		}
	}

	string ans = bfs(in);
	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 28676
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main() {
	string S;
	cin >> S;
	char f = S[0];
	if (f == S[1] && f == S[2] && f == S[3]) {
		cout << "No" << endl;
		return 0;
	}
	if (f == S[1]) {
		if (S[2] == S[3]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (f == S[2]) {
		if (S[1] == S[3]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (f == S[3]) {
		if (S[1] == S[2]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;


	return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    string S;
    cin >> N >> K >> S;
    rep(i,0,N){
        if(i+1 == K){
            ll v = S[i] - 'A';
            char c = 'a' + v;
            cout << c;
        }else{
            cout << S[i];
        }
    }
    cout << endl;



    
}

Measured memory_bytes: 256
ln = input()
output = ''
a = ''
for i in ln:
    if i == 'A' or i == 'T' or i == 'C' or i == 'G' :
        a += i
    else:
        if len(output) < len(a):
            output = a
        a = ''
if len(output) < len(a):
        output = a
a = ''        
print(len(output))    
    


Measured memory_bytes: 3060
//'main' method must be in a class 'Rextester'.
//openjdk version '11.0.5' 

import java.util.*;
import java.lang.*;

public class Main
{  
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    }
}


Measured memory_bytes: 35716
#
# 9a
#

def main():
    W = input().lower()
    T = []
    while True:
        t = input()
        if t == "END_OF_TEXT":
            break
        T += list(t.lower().split())

    ret = 0
    for i in range(len(T)):
        if T[i] == W:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()



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

int pre[100005],suf[100005],ar[100005],maxn;

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ar[i],pre[i]=__gcd(pre[i-1],ar[i]);
    for(int i=n;i>-1;i--)
        suf[i]=__gcd(suf[i+1],ar[i]);
    for(int i=1;i<=n;i++)
        maxn=max(maxn,__gcd(pre[i-1],suf[i+1]));//,cout<<i<<' '<<__gcd(pre[i-1],suf[i+1])<<'\n';
    cout<<maxn<<'\n';
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll n; cin >> n;

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

    if (n == 1){
        cout << t[0] << endl;
        return 0;
    }

    ll gcd = __gcd(t[1], t[0]);
    ll ans = t[1] / gcd * t[0];

    for (ll i = 2; i < n; ++i) {
        gcd = __gcd(ans, t[i]);
        ans = ans / gcd * t[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <math.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const int inf = 1000000000;
const double eps = 1e-7;

void solve() {
	int n, r;
	cin >> n >> r;
	if (n >= 10)
		cout << r << endl;
	else
		cout << r + 100 * (10 - n) << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	for (int i = 0; i < t; ++i)
		solve();
	return 0;
}

Measured memory_bytes: 256
import collections

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

mod=10**9+7
n=int(input())
dic=collections.defaultdict(int)
cnt=0
for _ in range(n):
  a,b=map(int,input().split())
  if a!=0 and b!=0:
    g=gcd(abs(a),abs(b))
    if a*b>0:
      dic[(abs(a)//g,abs(b)//g)]+=1
    else:
      dic[(-abs(a)//g,abs(b)//g)]+=1
  else:
    if a==0 and b==0:
      cnt+=1
    elif a==0:
      dic[(0,1)]+=1
    elif b==0:
      dic[(1,0)]+=1
ans=1
s=set()
for a,b in dic.keys():
  if (a,b) in s:
    continue
  s.add((a,b))
  if a!=0 and b!=0:
    if a>0:
      s.add((-b,a))
      cnt1=dic[(a,b)]
      if (-b,a) in dic:
        cnt2=dic[(-b,a)]
      else:
        cnt2=0
      ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
      ans%=mod
    elif a<0:
      s.add((b,-a))
      cnt1=dic[(a,b)]
      if (b,-a) in dic:
        cnt2=dic[(b,-a)]
      else:
        cnt2=0
      ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
      ans%=mod
  else:
    s.add((b,a))
    cnt1=dic[(a,b)]
    if (b,a) in dic:
      cnt2=dic[(b,a)]
    else:
      cnt2=0
    ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
    ans%=mod
print((ans+cnt-1)%mod)

Measured memory_bytes: 167080
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
using namespace std;
const int INF=2147483647;
struct Edge
{
	int to,nxt;
	int flow;
	ll cost;
}e[100005];
int n,m,s,t,edgenum,head[1005],f[1005],pre[1005],x[85],y[85],a[325],b[325],l1[85],r1[85],l2[85],r2[85];
ll dis[1005],val[85];
bool flag[1005];
char ti[325];
queue<int>q;
void add(int u,int v,int f,ll c)
{
	e[++edgenum].cost=c;
	e[edgenum].flow=f;
	e[edgenum].to=v;
	e[edgenum].nxt=head[u];
	head[u]=edgenum;
}
bool SPFA()
{
	for(int i=1;i<=t;i++)
	  dis[i]=1e18,flag[i]=0,f[i]=0;
	dis[s]=0;
	f[s]=INF;
	flag[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int node=q.front();
		q.pop();
		flag[node]=0;
		for(int hd=head[node];hd;hd=e[hd].nxt)
		{
			int to=e[hd].to;
			if(flag[to])continue;
			if(e[hd].flow==0)continue;
			if(dis[to]>dis[node]+e[hd].cost)
			{
				dis[to]=dis[node]+e[hd].cost;
				f[to]=min(f[node],e[hd].flow);
				pre[to]=hd;
				q.push(to);
			}
		}
	}
	return dis[t]<0;
}
ll EK()
{
	ll ans=0;
	while(SPFA())
	{
		ans+=f[t]*dis[t];
		int x=t;
		while(x)
		{
			e[pre[x]].flow-=f[t];
			e[pre[x]^1].flow+=f[t];
			x=e[pre[x]^1].to;
		}
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d%d%lld",&x[i],&y[i],&val[i]);
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		while(ti[i]<'A'||ti[i]>'Z')ti[i]=(char)getchar();
		scanf("%d%d",&b[i],&a[i]);
	}
	ll ans=0;
	for(int c=1;c<=n;c++)
	{
		for(int i=1;i<=c;i++)l1[i]=l2[i]=1,r1[i]=r2[i]=100;
		for(int i=1;i<=m;i++)
		{
			if(ti[i]=='L')if(a[i]+1<=c)l1[a[i]+1]=max(l1[a[i]+1],b[i]+1);
			if(ti[i]=='R')if(a[i]+1<=c)r1[c-a[i]]=min(r1[c-a[i]],b[i]-1);
			if(ti[i]=='D')if(a[i]+1<=c)l2[a[i]+1]=max(l2[a[i]+1],b[i]+1);
			if(ti[i]=='U')if(a[i]+1<=c)r2[c-a[i]]=min(r2[c-a[i]],b[i]-1);
		}
		for(int i=2;i<=c;i++)
		{
			l1[i]=max(l1[i],l1[i-1]);
			l2[i]=max(l2[i],l2[i-1]);
		}
		for(int i=c-1;i>=1;i--)
		{
			r1[i]=min(r1[i],r1[i+1]);
			r2[i]=min(r2[i],r2[i+1]);
		}
		bool flag=1;
		for(int i=1;i<=c;i++)
		{
			if(l1[i]>r1[i])flag=0;
			if(l2[i]>r2[i])flag=0;
		}
		if(!flag)continue;
		s=2*c+2*n+1,t=2*c+2*n+2;
		edgenum=1;
		for(int i=1;i<=t;i++)head[i]=0;
		for(int i=1;i<=c;i++)
		{
			add(s,i+2*n,1,0);
			add(i+2*n,s,0,0);
			add(i+2*n+c,t,1,0);
			add(t,i+2*n+c,0,0);
			for(int j=1;j<=n;j++)
			{
				if(x[j]>=l1[i]&&x[j]<=r1[i])
				{
					add(i+2*n,j,1,0);
					add(j,i+2*n,0,0);
				}
				if(y[j]>=l2[i]&&y[j]<=r2[i])
				{
					add(j+n,i+2*n+c,1,0);
					add(i+2*n+c,j+n,0,0);
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			add(i,i+n,1,-val[i]);
			add(i+n,i,0,val[i]);
		}
		ans=max(ans,-EK());
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
N,M = map(int, input().split())
S = [0]*M; C = [0]*M
for i in range(M):
    S[i], C[i] = map(int, input().split())

for i in range(M):
    s,c = S[i],C[i]

if N == 1:
    Range = range(0,10)
else:
    Range = range(10**(N-1), 10**N)
for x in Range:
    z = str(x)
    flag = True
    for i in range(M):
        s,c = S[i],C[i]
        if s <= len(z):
            if z[s-1] != str(c):
                flag = False
                break
        else:
            flag = False
            break
    if flag:
        print(z)
        exit()
print(-1)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] arr = new int[n];

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

		for (int i = n-1; i >= 0; i--) {
			System.out.print(arr[i]);
			if (!(i == 0)) {
				System.out.print(" ");
			}
		}
		System.out.println();

	}

}



Measured memory_bytes: 26188
import itertools
N, M, Q = map(int, input().split())

lst = []
for i in range(Q):
    tmp = list(map(int, input().split()))
    lst.append(tmp)

seq = list(itertools.combinations_with_replacement([i for i in range(1, M+1)], N))

max_num = 0

for s in seq:
    cnt = 0
    for l in lst:
        if s[l[1]-1] - s[l[0]-1] == l[2]:
            cnt += l[3]

    if max_num < cnt:
        max_num = cnt

print (max_num)


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

using namespace std;


#define MAXN 101
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a[MAXN];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i-1]>0 && a[i-1]==a[i]) {
      ans++;
      a[i] = -1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;


const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
   




int main() {
    ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';     //Avoid flushing with endl.
    cout.precision(16);

    string s;
    cin >> s;

    int left = 0;
    int right = len(s)-1;
    LL rr = 0;
    while (left < right) {
        int ldelta = 0;
        int rdelta = 0;
        while (left < len(s) && s[left] == 'x')
            ++left, ++ldelta;
        while (right >= 0 && s[right] == 'x')
            --right, ++rdelta;
        if (left >= len(s) || right < 0)
            break;
        if (left < right
        && s[left] != s[right]) {
            cout << (-1) << '\n';
            return 0;
        }
        if (left <= right) {
            rr += abs(ldelta - rdelta);
        }
        ++left;
        --right;
    }

    cout << rr << '\n';
    

    return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int a,b,c,max;

	scanf("%d %d %d",&a,&b,&c);


	if(a>b){
		max=a;
		a=b;
		b=max;
	}
	if(b>c){
		max=b;
		b=c;
		c=max;
	}

	if(a>b){
		max=a;
		a=b;
		b=max;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}



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

int main() {
  int H,W;
  cin >> H>> W;



  string str;
  vector<std::string> strList; 

  for(int i=0;i<H;i++){
        cin >> str;
    strList.push_back(str);
  }


  for(int i=0;i<H;i++) {

    if(i==0){
      //cout << "" <<endl;
      for(int j=0;j<W+2;j++){
      cout << "#";
      }
      cout << "" <<endl;
    }

    cout << "#" << strList.at(i)<<"#"<<endl;
  }

  for(int i=0;i<W+2;i++){
    cout << "#";
  }
  cout << "" <<endl;


}

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.collection.mutable.{HashMap => MMap}
import java.io.PrintWriter
object Main extends App {
  val Mod = 1000000007L
  val map = new MMap[(Int, Int), Long]
  val Array(n, b) = readLine.split(" ").map(_.toInt)

  val invs = new Array[Long](n + 1)
  invs(1) = 1
  (2 to n).foreach {i =>
    invs(i) = Mod - (Mod / i) * invs((Mod % i).toInt) % Mod
  }

  val r = n - b
  def nCk(n: Int, k: Int): Long = {
    map.getOrElse((n, k), {
      val numer = (n - k + 1 to n).foldLeft(1L)((z, i) => z * i % Mod)
      (2 to k).foldLeft(numer)((z, i) => invs(i) * z % Mod)
    })
  }

  val pw = new PrintWriter(System.out)
  for (i <- 1 to b) {
    pw.println(nCk(r + 1, i) * nCk(b - 1, i - 1) % Mod)
  }
  pw.flush()
}

Measured memory_bytes: 100340
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;

template <class T>
std::vector<std::vector<T>> imos_2d(const std::vector<std::vector<T>>& a) {
    int h = a.size(), w = a[0].size();
    std::vector<std::vector<T>> s(h + 1, std::vector<T>(w + 1, 0));
    rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
    rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
    rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
    
    // std::cout << "array s is like following:" << std::endl;
    
    // for (int i = 0; i < h+1; i++) {
    //     for (int j = 0; j < w+1; j++) {
    //         if (j!=w) {
    //             std::cout << s[i][j] << ", ";
    //         } else {
    //             std::cout << s[i][j];
    //         }
    //     }
    //     std::cout << "" << std::endl;
    // }
    
    return s;
}

template <class T>
int sum(const std::vector<std::vector<T>>& s, int i, int j, int h, int w) {
    return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
}

int main(){
    std::ios_base::sync_with_stdio(false);

    int n,m,Q; cin >> n >> m >> Q;

    std::vector<std::vector<int>> grid(n, std::vector<int>(n));

    rep(i,m){
        int l,r; cin >> l >> r; l--; r--;
        grid[l][r]++;
    }

    auto s = imos_2d(grid);
    rep(i,Q){
        int p,q; cin >> p >> q; p--;
        cout << sum(s,p,p,q-p,q-p) << '\n';
    }


    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int xh,xm,yh,ym,k;
	cin>>xh>>xm>>yh>>ym>>k;
	int mmm=60*(yh-xh)+(ym-xm)-k;
	if(mmm<0)mmm=0;
	cout<<mmm<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

int main() {
	IO;
	string a,b;
	cin>>a>>b;
	int ans=0;
	for(int i=0;i<sz(a);++i) {
		ans+=a[i]==b[i];
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			int k = stdIn.nextInt();
			int s = stdIn.nextInt();
			if(n == 0 && k == 0 && s == 0) break;
			int ans =  solve(n,k,s);
			System.out.println(ans);
		}
	}
	
	public static int solve(int n, int k, int s) {
		int ret = 0;
		for(int i = n; i > 0; i--) {
			ret += solv(n,k-1,s-i,i);
		}
		return ret;
	}
	
	public static int solv(int n, int k, int s,int l) {
		if(s < 0) return 0;
		if(s == 0 && k == 0) return 1;
		if(s == 0 && k > 0) return 0;
		if(s != 0 && k < 0) return 0;
		int ret = 0;
		for(int i = l-1; i > 0; i--) {
			ret += solv(n,k-1,s-i,i);
		}
		return ret;
	}
}

Measured memory_bytes: 20472
s = input()
t = input()
s_ = s[:]
cnt = 0
tlen = len(t)
ans = 0
flag = True

while cnt < tlen:
    
    num = s_.find(t[cnt])
    
    if num != -1:
        ans += (num+1)
        s_ = s_[(num+1):]
        cnt += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)

Measured memory_bytes: 3520
// program luogu.AT2168 Shik and Stone
#include <iostream>
#include <cstdio>
using namespace std;

int m,n;
char s[101][101];

void init() {
	scanf("%d %d",&m,&n);
	for(int i = 1; i <= m; ++i)
		scanf("%s",s[i]+1);
	s[0][1] = s[1][0] = '#';// ÌØÅÐÆðµã 
}

bool check(int x, int y) {
	if( s[x][y] == '.' ) return false;
	if( s[x+1][y] == '#' && s[x][y+1] == '#' ) return true;
	if( s[x-1][y] != '#' && s[x][y-1] != '#' ) return true;
	return false;
}

int main() {
	init();
	for(int i = 1; i <= m; ++i) {
		for(int j = 1; j <= n; ++j) {
			if( check(i,j) ) {
				printf("Impossible\n");
				return 0;
			}
		}
	}
	printf("Possible\n");
	return 0;
}

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

int main(){
  string S;
  cin>>S;
  int ans=100000;
  int cou=0;
  int fcou=0;
  for(int i=0;i<26;i++){
    fcou=0;
    cou=0;
    for(int j=0;j<S.size();j++){
      if((char)S[j]==i+97){
        fcou=max(fcou,cou);
        cou=0;
      }
      else cou++;
    }
    fcou=max(fcou,cou);
    ans=min(fcou,ans);
  }
  cout<<ans<<endl;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  bool can = true;
  for(int i = n-1;i>=1;--i){
    if(h[i]-h[i-1]==-1) h[i-1]--;
    else if(h[i]-h[i-1]<-1) can = false;
  }
	
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3760
/**
 * ???????????£??????????????? 2?¬?????????????
 */

// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using s64 = int64_t;
// }}}

constexpr s64 INF = numeric_limits<s64>::max();

s64 V;
s64 E;
vector<vector<s64>> D;

void warshallfloyd()
{
    FOR(k, 0, V) {
        REP(i, V) {
            if(D[i][k] == INF) continue;
            REP(j, V) {
                if(D[k][j] == INF) continue;
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
            }
        }
    }
}

void solve()
{
    warshallfloyd();

    bool ok = true;
    REP(v, V) {
        if(D[v][v] < 0) ok = false;
    }

    if(!ok) {
        cout << "NEGATIVE CYCLE" << "\n";
    }
    else {
        REP(i, V) {
            REP(j, V) {
                s64 d = D[i][j];
                if(d == INF) {
                    cout << "INF";
                }
                else {
                    cout << d;
                }
                cout << (j == V-1 ? "\n" : " ");
            }
        }
    }
}

int main()
{
    cin >> V >> E;
    D.resize(V);
    for(auto& row : D) {
        row.resize(V);
    }

    REP(from, V) {
        REP(to, V) {
            D[from][to] = (from == to ? 0 : INF);
        }
    }

    REP(_, E) {
        s64 s, t, d;
        cin >> s >> t >> d;
        D[s][t] = d;
    }

    solve();

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  int ca=0;
  int cb=0;
  int cba=0;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    for(int j=0;j<s.size()-1;j++){
      if(s.substr(j,2)=="AB"){
        ans++;
      }
    }
    if((s.front()=='B')&&(s.back()=='A')){
      cba++;
    }else if(s.front()=='B'){
      cb++;
    }else if(s.back()=='A'){
      ca++;
    }
  }
  ans+=min(ca,cb);
  if(max(ca,cb)>0){
    ans+=cba;
  }else{
    ans+=max(0,(cba-1));
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  int ans=0;
  if(S=="RRR") ans=3;
  else if(S=="RRS" or S=="SRR") ans=2;
  else if(S=="RSR" or S=="RSS" or S=="SSR" or S=="SRS") ans=1;
  else if(S=="SSS") ans=0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3548