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

int main() {
    int h, w, cnt = 0;
    std::cin >> h >> w;
    std::vector<std::vector<int>> v(h, std::vector<int>(w));
    std::stringstream ss;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) std::cin >> v[i][j];

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            if (v[i][j] > 0 && v[i][j] % 2) {
                ss << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << "\n";
                v[i][j + 1]++;
                v[i][j]--;
                cnt++;
            }
        }
        if (i == h - 1) continue;
        if (v[i][w - 1] % 2) {
            ss << i + 1 << " " << w << " " << i + 2 << " " << w << "\n";
            v[i][w - 1]--;
            v[i + 1][w - 1]++;
            cnt++;
        }
    }
    
    std::cout << cnt << std::endl;
    std::cout << ss.str() << std::flush;

    return 0;
}

Measured memory_bytes: 6920
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    A_sum = 0
    
    for i, v in enumerate(A):
        A_sum = A_sum + (1 / v)
        
    print(1 / A_sum)
    
        
if __name__ == '__main__':
    main()

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

using namespace std;
#define ll long long
#define dbug prllf("I am here\n");
const ll maxn = 2e5+100;

const ll inf = 1e18;
ll dp[maxn];
ll arr[maxn];
ll cum[maxn];
ll n;
ll index(ll ind , ll val){
    ll lo = ind , hi = n;
    ll ans = -1;
    while(lo <= hi){
        ll mid = (lo + hi)/2;
        if(cum[mid] == val){
            ans = mid;
            lo = mid + 1;
        }
        else hi = mid - 1;
    }
    return ans;
}

int main()
{
    cin >> n;
    for(ll i = 1; i<=n; i++)cin >> arr[i];
    for(ll i = 1; i<=n; i++)cum[i] = cum[i-1] + arr[i];
    arr[n+1] = (1 << 25)-1;
    ll ans = 0;
    for(ll i = 1; i<=n; i++){
        ll cur = i;
        ll Or = arr[i];
        for(cur = i+1; cur <= n; cur++){
            if((Or & arr[cur]) > 0)break;
            Or |= arr[cur];
            if(arr[cur] == 0)cur = index(cur , cum[cur]);
            Or |= arr[cur];
        }
        ans += (cur - i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4352
use proconio::input;

fn main() {
    input! {
        n: usize,
        aa: [i64; n],
        bb: [i64; n]
    }

    let diff = aa.iter().zip(bb.iter())
        .map(|(&a, &b)| b - a).collect::<Vec<_>>();
    
    let sum_diff = diff.iter().sum::<i64>();
    if sum_diff < 0 {
        println!("No");
        return;
    }

    let mut count = sum_diff;
    for x in diff {
        if x > 0 {
            count -= (x + 1) / 2;
        }
    }

    if count >= 0 {
        println!("Yes");
    } else {
        println!("No");
    }
    
}


Measured memory_bytes: 2588
#include<stdio.h>
#include<string.h>



int char_swich_search(char *a, int len,int index);
// array and length, current_index. output is swiching index.


int main()
{
  int N,Q;



  scanf("%d %d", &N,&Q);
  char S[N+1];
  scanf("%s",S);
  int a[N],i,a0=0;
  a[0]=0;
  for(i=1;i<N;i++)
    {
      if(S[i-1]=='A' && S[i]=='C') a0++;
      a[i]=a0;
    }

  int l[Q],r[Q];
  for(i=0;i<Q;i++)
    {
      scanf("%d %d",&l[i],&r[i]);
    }
  for(i=0;i<Q;i++)
    {
      printf("%d\n",a[r[i]-1]-a[l[i]-1]);
    }
  
  return 0;

}

int char_swich_search(char *a, int len,int index)
{
  int i;
  for(i=index;i<=len;i++)
    {
      if(a[i]!=a[index])break;
    }
  return i;
}


Measured memory_bytes: 2048
def resolve():
    N, M = [int(i) for i in input().split()]
    if min(N, M) > 1:
        print((N - 2) * (M - 2))
    else:
        if max(N, M) == 1:
            print(1)
        else:
            print(max(N, M) - 2)


resolve()


Measured memory_bytes: 8944
#include <stdio.h>
int main(void)
{
    int i,j;
    for(i = 1; i <=10000 ; i++)
    {
        scanf("%d",&j);
        if(j == 0)
        {
            break;
        }
        printf("Case %d: %d\n", i, j);
    }
    return 0;
}


Measured memory_bytes: 2608
def get_divisor(n):
    a,b = [],[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N,M = map(int,input().split())
print(max(n for n in get_divisor(M) if n<=M//N))

Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, n, m, L, R;
long long int N, M, K, T, n, m, L, R;


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

	cin >> n >> m;
	int sy, sx, ny, nx;
    cin >> sy >> sx >> ny >> nx;
	sy--, sx--, ny--, nx--;
	vector<string>s(n);
	for (auto &i : s)cin >> i;
	vector<vector<int>>dis(n, vector<int>(m,MOD));
	deque<pair<int, int>>q;
	q.push_back({ sy,sx });
	dis[sy][sx] = 0;
    int dir[] = { 1,0,-1,0,1 };
    while (!q.empty()) {
        int cy, cx;
        tie(cy, cx) = q.front();
        q.pop_front();
        for (int i = 0; i < 4; i++) {
            int ny = cy + dir[i], nx = cx + dir[i + 1];
            if(unsigned(nx)<m&&unsigned(ny)<n&&s[ny][nx]=='.'){
                if (dis[ny][nx] > dis[cy][cx]) {
                    dis[ny][nx] = dis[cy][cx];
                    q.push_front({ ny,nx });
                }
            }
        }
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                int ny = cy + i, nx = cx + j;
                if(unsigned(nx)<m&&unsigned(ny)<n&&s[ny][nx]=='.'){
                    if (dis[ny][nx] > dis[cy][cx] + 1) {
                        dis[ny][nx] = dis[cy][cx] + 1;
                        q.push_back({ ny,nx });
                    }
                }
            }
        }
    }
    if (dis[ny][nx] == MOD)dis[ny][nx] = -1;
    cout << dis[ny][nx] << endl;
}


Measured memory_bytes: 8728
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
    char s[131072]={};
    scanf("%s", s);
    size_t ub=strlen(s);
    s[ub] = '$';

    for (size_t i=0; i<ub; ++i)
        for (size_t j=i+1; j<=i+2; ++j)
            if (s[i] == s[j]) {
                printf("%llu %llu\n", i+1, j+1);
                return 0;
            }

    printf("-1 -1\n");
    return 0;
}


Measured memory_bytes: 256
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

# from numba import jit
# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    w = list(map(int, readline().split()))

    ans = INF
    for i in range(n - 1):
        left = sum(w[:i + 1])
        right = sum(w[i + 1:])
        ans = min(ans, abs(left-right))

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int i = 0;
		int n[] = new int[100000];
		Scanner scan = new Scanner(System.in);
		while (true) {
			n[i] = scan.nextInt();
			if (n[i] == 0) {
				break;
			}
			i++;
		}
		for (int j = 0; j < i; j++) {
			System.out.println("Case " + (j+1) + ": " + n[j]);
		}
	}

}



Measured memory_bytes: 43596
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

  VAR(int, n);
  VEC(int, a, n);

  int sm = 0;
  REP(i, n) sm += a[i];

  // dp[i]:=i番目までの要素を使って要素をjに出来る時は下j桁目が1になって居るビット列
  bitset< 2020 * 2020 > dp;
  dp.set(0);
  REP(i, n) {
    bitset< 2020 * 2020 > pd;
    // 前の要素をもらってくる
    pd |= dp;
    // 前の要素のA[i]ずらしたものを上書き
    pd |= dp << a[i];
    // dpの遷移
    swap(dp, pd);
  }

  // 半分以上の要素から選んで最小のものが答え
  FOR(i, (sm + 1) / 2, 2020 * 2020) {
    // bitsetのアクセスは配列のように行える
    if (dp[i]) {
      OUT(i)BR;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
int n,i,j,flag=1,a[100],b,c=0;
int main () {

  scanf("%d",&n);
  for (i=0;i<n;i++)
     scanf("%d",&a[i]);

     
  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(a[j]<a[j-1])
      {
        b=a[j];
        a[j]=a[j-1];
        a[j-1]=b;
	flag=1;
	c++;
      }
    }
  }
 
  for (i=0;i<n;i++){
     printf("%d",a[i]);
     if (i<n-1)
       printf(" ");
  }
  printf("\n%d\n",c);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  double R;
  cin>>R;
  cout<<R*2.0*3.14159265358979<<endl;
  return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(){
#define int ll
  int n; cin >> n;
  int a = 1, b = 1;
  rep(i,n){    
    int x,y; cin >> x >> y;
    int n = max((a + x -1)/ x, (b + y - 1) / y);
    a = n * x;
    b = n * y;
    dump(a,b);    
  }
  cout << a + b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    string s;
    cin>>s;
    if(s=="ABC"){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    ll n, prev, now;
    cin >> n;
    vector<ll> h(n);
    rep(i, n){
        cin >> h[i];
    }
    for(ll i = 1; i < n; i++){
        if(h[i] > h[i - 1]){
            h[i]--;
        }
        if(h[i - 1] > h[i]){
            print("No");
            return 0;
        }
    }
    print("Yes");
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int Rank[300];

signed main()
{
  Rank[1] = 300000; Rank[2] = 200000; Rank[3] = 100000;
  int X, Y;
  cin >> X >> Y;

  int ans = 0;
  if(X == 1 && Y == 1) ans = 400000;

  cout << ans + Rank[X] + Rank[Y] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int f=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            f=1;
            break;
        }
    }
    if(!f)
        cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

long long int mod=1e9+9;
const int N=100000;
int t,i,j,cs=0,n,a,b;
string s;

int main()
{
    cin>>a>>b;
    if(a<=b) cout<<"unsafe";
    else cout<<"safe";
    cout<<endl;

}



Measured memory_bytes: 3636
import sys
from fractions import gcd

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = gcd(A[0], A[1])
    for i in range(2, N):
        ans = gcd(ans, A[i])

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d==1)
    {
        cout<<1;
    }
    else
    {
        cout<<0;
    }

}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
ans = 0
p = 0

for i in range(N-1):
  if H[i] < H[i+1]:
    if ans < p:
      ans = p
    p = 0
  else:
    p += 1

if ans < p:
  ans = p

print(ans)

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

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

	int IntStrNum = StrInput.length();

	int FlagNo = 0;

	for (int i = 0; i < IntStrNum; i = i + 2) {
		if (StrInput[i] == 'L') {
			FlagNo = 1;
		}
	}

	for (int i = 1; i < IntStrNum; i = i + 2) {
		if (StrInput[i] == 'R') {
			FlagNo = 1;
		}
	}

	if (FlagNo == 1) {
		cout << "No";

	}
	else {
		cout << "Yes";
	}
	return 0;
}



// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int x, y;
    cin >> x >> y;
    if (y % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (2 * x <= y && y <= 4 * x)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	int ans=0;
	for(int i=0;i<3;i++)
	{
		cin>>a[i];
	}
	sort(a,a+3);
	for(int i=0;i<3;i++)
	{
		if(i==0)
		{
			continue;
		}
		else
		{
			ans+=a[i]-a[i-1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    s[3] = '8';
    PRINT(s);
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    // ABC152D
    static final long MOD = 1_000_000_007;
    // 10^9+7
    //static final int MAX = 2_147_483_646;
    static final int MAX = 10_000_000;
    // intの最大値
    static final int INF = 1_000_000_000;
    // 10^9

  
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        long[] ary = new long[a];
        for(int i = 0;i < a;i++){
            ary[i] = sc.nextInt();
        }
        Arrays.sort(ary);
        long min = ary[0];
        for(int i = 1;i < a;i++){
            if(min==ary[i]){
                System.out.println("NO");
                return;
            }
          	min = ary[i];
        }
        System.out.println("YES");
    }
    
}




Measured memory_bytes: 65160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0;
	int i=0,j=0;
	int n=s.length();
	while(i<=j&&j<n)
	{
		if(s[i]==s[j]&&s[i]=='R')
		{
			j++;
		}
		if(s[i]==s[j]&&s[j]=='S')
		{
			i++;
			j++;
		}
		if(s[i]!=s[j])
		{
			ans=max(ans,j-i);
			i=j;
		}
	}
	if(i<j)
	{
		ans=max(ans,j-i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

struct UnionFind {
    //自身が親であれば，その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;

    UnionFind(int n) {
        r = vector<int>(n, -1);
    }

    int root(int x) { //木の根を調べる（どのグループに属しているか）
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) { //xとyの属する集合を併合
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) { //xが属する集合の頂点数を調べる
        return -r[root(x)];
    }

    bool same(int x, int y) { //xとyが同じ集合に属するか否か
        return root(x) == root(y);
    }
};
 
int main() {
    int n,m; cin >> n >> m;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    UnionFind UF(n);
    rep(i,m) {
        int x,y; cin >> x >> y;
        x--; y--;
        UF.unite(x,y);
    }
    int ans = 0;
    rep(i,n) {
        if (i+1==p[i] || UF.same(i,p[i]-1)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3980
function main(input) {
	var res = 0;
 	input = input.split(' ');
  	const max = parseInt(input[0]);
  	const total = parseInt(input[1]);
	for (var X = 0;X <= max;X++) {
    	for (var Y = 0;Y <= max;Y++) {
            var Z = (total - parseInt(X) - parseInt(Y));
           	if (0 <= Z && Z <= max) {
              res++;
            }
        }
    }
	console.log(res);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7488
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int D = Integer.parseInt(sc.get());
		int[] C = new int[26];
		Arrays.setAll(C, $ -> Integer.parseInt(sc.get()));
		var S = new int[D][26];
		for (int i = 0; i < D; i++) {
			int[] row = S[i];
			Arrays.setAll(row, $ -> Integer.parseInt(sc.get()));
		}

		int[] result = new int[D];
		for (int i = 0; i < D; i++) {
			int max = -1;
			for (int j = 0; j < S[i].length; j++) {
				if (max < S[i][j]) {
					max = S[i][j];
					result[i] = j;
				}
			}
		}

		for (int value : result) {
			System.out.println(value + 1);
		}
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

int N, a[100001], d[100001], counter = 0;

int main(){
	
	cin >> N; 
	for (int i = 1; i <= N; i ++){
		cin >> a[i];
		if (a[i] > 100000) counter ++;
	}
	for (int i = 1; i <= 100000; i ++){
		if (a[i] < 100001) d[a[i]] ++;
	}
	for (int i = 1; i < 100001; i ++){
		if (d[i] != 0){
			if (d[i] > i) counter = counter + d[i] - i;
			else if (d[i] < i) counter = counter + d[i];
		}
	}
	cout << counter;
	
}

Measured memory_bytes: 640
#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<double> v(n);
  rep(i,n) cin >> v.at(i);
  sort(v.begin(), v.end());
  double ans = 0;
  if(n==2) ans = (v.at(0)+v.at(1)) / 2;
  else {
    rep(i,n-1) {
      ans = (v.at(i) + v.at(i+1)) / 2;
      v.at(i+1) = ans;
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
signed main(void){
    int n; cin>>n;
    vector <int> a(n); 
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int ans = 0;
    //偶数の時 
    if(n%2 ==0){
        for(int i=0;i<n/2;i++){
            if(i == n/2-1) ans -=a[i];
            else ans -= a[i]*2;
        }
        for(int i=n-1; i>=n/2; i--){
            if(i==n/2) ans += a[i];
            else ans += a[i]*2;
        }
        cout<<ans<<endl; return 0;
    }else{//奇数の時
        int ans1 = 0, ans2 = 0;
        int mid = n/2;
        //大から
        for(int i=0;i<n;i++){
            //cout<<a[i]<<'*'<<endl;
            if(mid > i) ans1 -= a[i]*2;
            else if(i == mid|| i == mid+1) ans1 += a[i];
            else ans1 += a[i]*2;
        }
        //cout<<ans1<<endl;
        //小から
        for(int i=0;i<n;i++){
            if(i==mid||mid-1==i) ans2-=a[i];
            else if(i<mid-1) ans2 -= a[i]*2;
            else ans2 += a[i]*2;
        } 
        cout<<max(ans1, ans2)<<endl;
    }
   
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

void solve()
{
    int n;
    cin>>n;
    int a[n], b[n], cnt[n+1] = {};
    f(i, 0, n) cin>>a[i], cnt[a[i]]++;
    f(i, 0, n) cin>>b[i], cnt[b[i]]++;
    f(i, 0, n+1)
    {
    	if(cnt[i] > n)
    	{
    		cout<<"No\n";
    		return;
    	}
    }
    cout<<"Yes\n";
    reverse(b, b+n);
    int s = 0, e = n-1;
    f(i, 0, n)
    {
    	if(b[i] == a[i])
    	{
    		if(b[e] != b[i] && b[i] != a[e]) swap(b[i], b[e--]);
    		else swap(b[i], b[s++]);
    	}
    }
    f(i, 0, n) cout<<b[i]<<' ';
    cout<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 8324
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

ans = 0
commands = [''] * N
# enumerateでインデックスと要素を同時に取得
# iがインデックス(0,1,2...)、tが手(r or s or p)
for i, t in enumerate(T):
    if t == 'r':
        command = 'p'
        point = P

    elif t == 's':
        command = 'r'
        point = R

    elif t == 'p':
        command = 's'
        point = S

 # 制限がかかり始めるK回目以降で、K個前の手と同じになってしまう場合
 # 更にK回後の邪魔にならない手は必ず存在する、ここで「何も出さず0ポイント」と解釈してよい
    if (i - K >= 0) and (commands[i - K] == command):
        command = '-'
        point = 0

    ans += point
    commands[i] = command

print(ans)
#print(commands)


Measured memory_bytes: 10324
import math

if __name__ == '__main__':
    n = int(input())
    ans = 0
    is_honest = [-1] * n
    evidence = []
    for i in range(n):
        a = int(input())
        tmp = []
        for j in range(a):
            x, y = map(int, input().split())
            tmp.append((x - 1, y))
        evidence.append(tmp)

    # 1 -> Honest, 0 -> Liar
    for i in range(2 ** n):
        flag = True
        for j in range(n):
            # j is Liar
            if not (i & (1 << j)):
                continue
            for x, y in evidence[j]:
                if y == 1 and not (i & (1 << x)):
                    flag = False
                elif y == 0 and (i & (1 << x)):
                    flag = False
        if flag:
            count = 0
            for k in range(n):
                if i & (1 << k):
                    count += 1
            ans = max(ans, count)

    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
#include <atcoder/segtree>

int op(int a, int b)
{
    return max(a, b);
}

int e()
{
    return 0;
}

int main()
{
    int N, K;
    io >> N >> K;
    vi A(N);

    for (int i = 0; i < N; i++)
        io >> A[i];

    int ST_SIZE = 300004;
    atcoder::segtree<int, op, e>  B(ST_SIZE);
    vi dp(N);

    for (int i = 0; i < N; i++)
    {
        int l = max(0, A[i] - K);
        int r = min(ST_SIZE, A[i] + K + 1);
        dp[i] = B.prod(l, r) + 1;

        B.set(A[i], dp[i]);
    }

    io << B.all_prod() << BR;
}

Measured memory_bytes: 9692
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X;
	cin >> X;

	if (X == 3 || X == 5 || X == 7)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}

	return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
pii Log(int t)
{
    int ans = 0;
    while (t >> ans) ++ans;--ans;
    return mp(ans,ans + ((1 << ans) != t));
}
const int N = (int)(1e6) + 5;
int dp[N][2];
pii s[N];
int main(void)
{
    int ans = 0;
    int n;
    cin>>n;
    for (int i = 1;i <= n;++i)
    {
        int v;
        cin>>v;
        s[i] = Log(v);
        ans += max(s[i].fi,s[i].se);
    }
    for (int i = 2;i <= n;++i)
    {
        dp[i][0] = max(dp[i - 1][0] + min(s[i - 1].se,s[i].fi),dp[i - 1][1] + min(s[i - 1].fi,s[i].fi));
        dp[i][1] = max(dp[i - 1][0] + min(s[i - 1].se,s[i].se),dp[i - 1][1] + min(s[i - 1].fi,s[i].se));
    }
    cout << (ans - max(dp[n][0],dp[n][1])) << '\n';
    return 0;
}


Measured memory_bytes: 5120
import sys
H,W = map(int,input().split())
array = []
for I in range(H):
    array.append(list(map(str,input())))

if not (1 <= H <= 50 and 1 <= W <= 50):
    sys.exit()

result = [[0]*(W+2) for i in range((H+2))]
# test_result = [[0,1,2,3,4,5],[6,7,8,9,10,11],[12,13,14,15,16,17],[18,19,20,21,22,23]]
def input_result_array(x,y,result):
    result[x-1][y-1] += 1
    result[x-1][y] += 1
    result[x-1][y+1] += 1
    result[x][y-1] += 1
    result[x][y+1] += 1
    result[x+1][y-1] += 1
    result[x+1][y] += 1
    result[x+1][y+1] += 1
    return result

bomb_point = []
for I in range(H):
    for J in range(W):
        if array[I][J] == '#':
            bomb_point.append([I,J])
            result = input_result_array(I+1,J+1,result)

for I in range(len(bomb_point)):
    x,y=bomb_point[I]
    result[x+1][y+1] = '#'

str_result = ''
for I in [I[1:-1] for I in result[1:-1]]:
    for J in I:
        str_result += str(J)
    str_result += '\n'
print(str_result)

Measured memory_bytes: 9228
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
 int n;
  cin >> n;
  long a[3*n];
  for(int i=0;i<3*n;i++) cin >> a[i];
  
  sort(a,a+3*n);
  
  long res=0;
  for(int i=n;i<3*n;i+=2) res+=a[i];

  cout << res << endl;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N , Q;
    cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int n, m, nn, edge[16][16], tmpx, tmpy, tmpz, sums;
int blocks[1 << 16], len, f[1 << 16][16];
int main() {
    cin >> n >> m;
    nn= 1 << n;
    for(int i= 1; i <= m; i++) {
        cin >> tmpx >> tmpy >> tmpz;
        sums+= edge[tmpx][tmpy]= edge[tmpy][tmpx]= tmpz;
    }
    for(int i= 0; i < nn; i++) {
        for(int j= 1; j <= n; j++) {
            if(!(i & (1 << (j - 1))) && !(blocks[i | (1 << (j - 1))])) {
                blocks[i | (1 << (j - 1))]= blocks[i];
                for(int k= 1; k <= n; k++)
                    if((i & (1 << (k - 1)))) blocks[i | (1 << (j - 1))]+= edge[j][k];
            }
        }
    }
    memset(f, -1, sizeof(f));
    f[1][1]= 0;
    for(int i= 0; i < nn; i++) {
        for(int j= 1; j <= n; j++) {
            if(f[i][j] != -1 && (i & (1 << (j - 1)))) {
                for(int k= 1; k <= n; k++)
                    if(!(i & (1 << (k - 1))) && edge[j][k]) f[i | (1 << (k - 1))][k]= max(f[i | (1 << (k - 1))][k], f[i][j] + edge[j][k]);
                tmpx= ((nn - 1) ^ i) | (1 << (j - 1));
                for(int k= tmpx; k; k= (k - 1) & tmpx)
                    if(k & (1 << (j - 1))) f[i | k][j]= max(f[i | k][j], f[i][j] + blocks[k]);
            }
        }
    }
    cout << sums - f[nn - 1][n] << endl;
    return 0;
}

Measured memory_bytes: 4480
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W, K;
  cin >> H >> W >> K;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1--; y1--; x2--; y2--;
  vector<string> cs(H);
  F0R(i, H) {
    cin >> cs[i];
  }

  int inf = 10000000;
  vector<vector<int>> dp(H, vector<int>(W, inf + 1));

  queue<tuple<int, int, int>> qu;
  qu.emplace(x1, y1, 0);
  dp[x1][y1] = 0;

  while (qu.size()) {
    auto [r, c, d] = qu.front();
    qu.pop();

    if (r == x2 && c == y2) break;
    d++;

    FOR(i, 1, min(K + 1, r + 1)) {
      if (cs[r - i][c] == '@') break;
      if (dp[r - i][c] < d) break;
      if (dp[r - i][c] > d) {
        dp[r - i][c] = d;
        qu.emplace(r - i, c, d);
      }
    }
    FOR(i, 1, min(K + 1, c + 1)) {
      if (cs[r][c - i] == '@') break;
      if (dp[r][c - i] < d) break;
      if (dp[r][c - i] > d) {
        dp[r][c - i] = d;
        qu.emplace(r, c - i, d);
      }
    }
    FOR(i, 1, min(K + 1, H - r)) {
      if (cs[r + i][c] == '@') break;
      if (dp[r + i][c] < d) break;
      if (dp[r + i][c] > d) {
        dp[r + i][c] = d;
        qu.emplace(r + i, c, d);
      }
    }
    FOR(i, 1, min(K + 1, W - c)) {
      if (cs[r][c + i] == '@') break;
      if (dp[r][c + i] < d) break;
      if (dp[r][c + i] > d) {
        dp[r][c + i] = d;
        qu.emplace(r, c + i, d);
      }
    }
  }

  /*
  F0R(r, H) {
    F0R(c, W) {
      if (dp[r][c] > inf) {
        cout << "* ";
      }
      else cout << dp[r][c] << ' ';
    }
    cout << newl;
  }
  //*/


  cout << (dp[x2][y2] > inf ? -1 : dp[x2][y2]);
}
#endif


Measured memory_bytes: 12168
#include <iostream>
#include <cstring>
using namespace std;
const int M = 5e2 + 10;
int mmp[M][M] , ans[M][M];
int main() {
    int H , W , h , w;
    cin >> H >> W >> h >> w;
    for(int i = 1 ; i <= H ; i++) {
        for(int j = 1 ; j <= W ; j++) {
            ans[i][j] = 1;
        }
    }
    for(int i = 1 ; i <= H ; i++) {
        if(i % h == 0) {
            for(int j = 1 ; j <= W ; j++) {
                if(j % w == 0) {
                    ans[i][j] = -(h * w);
                }
            }
        }
    }
    int count = 0 , cnt = 0;
    for(int i = 1 ; i <= H ; i++) {
        for(int j = 1 ; j <= W ; j++) {
            if(ans[i][j] > 0) count++;
            cnt += ans[i][j];
        }
    }
    if(cnt+H*W-count<=0 && cnt <= 0) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        int sum = 0;
        for(int i = 1 ; i <= H ; i++) {
            for(int j = 1 ; j <= W ; j++) {
                sum += ans[i][j];
            }
        }
        int num1 = count , num2 = H * W - count;
        int dif = num1 - num2 * (h * w - 1);
        if(sum <= 0) {
            int gg = -sum;
            int ad = gg / dif + 1;
            for(int i = 1 ; i <= H ; i++) {
                for(int j = 1 ; j <= W ; j++) {
                    if(ans[i][j] > 0) ans[i][j] += ad;
                    else ans[i][j] -= ad * (h * w - 1);
                }
            }
        }
        for(int i = 1 ; i <= H ; i++) {
            for(int j = 1 ; j <= W ; j++) {
                cout << ans[i][j] << ' ';
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2304
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = 0;

	void doIt() {
		char[] s = sc.next().toCharArray();
		int cnt = 0;
		for(int i = 0; i < s.length / 2; i++) {
			if(s[i] != s[s.length - 1 - i]) cnt++;
		}
		System.out.println(cnt);
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll U=1e10;
map<ll,int> cnt;
map<ll,ll> inv;
const int N=1e5+10;
int n,size,ans;ll q[N];
int prime[N],num;
void init(){
	static bool isp[N];
	for (int i=2;i<=10000;i++)
	if (!isp[i]){
		prime[++num]=i;
		for (int j=i+i;j<=10000;j+=i) isp[j]=1;
	}
}
void insert(){
	ll x,v=1,I=1;
	scanf("%lld",&x);
	for (int i=1;i<=num&&(ll)prime[i]*prime[i]<=x;i++)
	if (x%prime[i]==0){
		int cnt=0,p=prime[i];
		while (x%p==0) cnt++,x/=p;
		cnt%=3;
		ll sqr=(ll)p*p;
		if (cnt==1){
			v*=p;
			if (I>U/sqr) I=U+1;else I*=sqr;
		}
		if (cnt==2){
			v*=sqr;
			if (I>U/p) I=U+1;else I*=p;
		}
	}
	v*=x;
	if (I>U/(x*x)) I=U+1;else I*=x*x;
	if (x<=1e8) inv[v]=I,inv[I]=v;else
	if (!inv.count(v)) inv[v]=I;
	cnt[q[++size]=v]++;
}
int main()
{
	init();
	scanf("%d",&n);
	for (int i=1;i<=n;i++) insert();
	int ans=0;
	if (cnt[1]) ans++,cnt[1]=0;
	for (int i=1;i<=size;i++){
		ll v=q[i];
		ans+=max(cnt[v],cnt[inv[v]]);
		cnt[v]=cnt[inv[v]]=0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 21632
#include<bits/stdc++.h>
using namespace std;
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
        int ans[n+1];
    ans[0]=0;
    for(int i=1;i<=n;i++){
        ans[i]=1000000000;
    }

    for(int i=0;i<n;i++){
        if(i+1<n){
            ans[i+1]=min(ans[i+1],+ans[i]+abs(a[i]-a[i+1]));
        }
        if(i+2<n){
            ans[i+2]=min(ans[i+2],ans[i]+abs(a[i]-a[i+2]));
        }
    }
    cout<<ans[n-1];

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, M, C;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];
                C = line[2];

            }

            int[] B = Input.ReadIntArray();

            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                int[] A = Input.ReadIntArray();
                int x = 0;
                for (int j = 0; j < A.Length; j++)
                {
                    x += A[j] * B[j];
                }

                x += C;
                if (x > 0) ret++;
            }

            Console.WriteLine(ret);

        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		for (int i = 0;; i++) {
			String line = sc.nextLine();
			String[] x = line.split(" ");
			int a = Integer.parseInt(x[0]);
			int b = Integer.parseInt(x[2]);
			if (x[1].equals("+")) {
				System.out.println(a + b);

			} else if (x[1].equals("-")) {
				System.out.println(a - b);

			} else if (x[1].equals("*")) {
				System.out.println(a * b);
			} else if (x[1].equals("/")) {
				System.out.println(a / b);
			} else if (x[1].equals("?")) {
				break;
			}

		}

	}

}



Measured memory_bytes: 26216
#include<bits/stdc++.h>
using namespace std;
 
int gcd(int a, int b) {  
    if (b == 0)  
        return a;  
    return gcd(b, a%b);  
}  
 
int main(){
  int A, B, K, c, i;
  cin >> A >> B >> K;
  
  c = gcd(A, B);
  
  for (i = c; i >= 1; i--){
    if(c%i == 0){
      K--;
    }
    if(K == 0){
      break;
    }
  }
  
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
Num = 1000000007 
N,M = map(int,input().split())
a = set([int(input()) for i in range(M)])

now = 0
if 1 in a:
    prev1 = 0
else:
    now = 1
    prev1 = 1
prev2 = 1

for i in range(2,N+1):
    if i in a:
        now = 0
        prev2 = prev1
        prev1 = now 
    else:
        now = prev1 +prev2
        prev2 = prev1
        prev1 = now

print(now%Num)

Measured memory_bytes: 13192
#include<bits/stdc++.h>
using namespace std;
int d[100];

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

 for(int i = 1; i <= sqrt(a); i++){
        if(a % i == 0){
            if(a/i == i){
                d[i]++;
            }
            else{
                d[i]++;
                d[a/i]++;
            }
        }
    }

     for(int i = 1; i <= sqrt(b); i++){
        if(b % i == 0){
            if(b/i == i){
                d[i]++;
            }
            else{
                d[i]++;
                d[b/i]++;
            }
        }
    }

    int n = min(a,b);
    vector<int>v;
    for(int i = n; i >= 0; i--){
        if(d[i] >= 2){
            v.push_back(i);
        }
    }

    cout << v[k-1]<<endl;
    return 0;
}


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

int main() {
    string A, B;
    cin >> A >> B;
    int n = A.size();
    int m = B.size();

    if(n > m) {
        cout << "GREATER" << endl;
        return 0;
    }
    else if(n < m) {
        cout << "LESS" << endl;
        return 0;
    }
    else {
        rep(i, n) {
            if( (A[i] - '0') > (B[i] - '0') ) {
                cout << "GREATER" << endl;
                return 0;
            }
            else if( (A[i] - '0') < (B[i] - '0') ) {
                cout << "LESS" << endl;
                return 0;
            }
            else {
                cout << "EQUAL" << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256