akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)

int main() {
	int N, D, ans = 0;
	cin >> N >> D;
	int i, j, k;
	int x[10][10];

	rep(i, N) {
		rep(j, D) {
			cin >> x[i][j];
		}
	}
	rep(i, N) {
		rep(j, i)//j<i　ダブルカウントしないように
		{
			int s = 0;
			int t = 0;
			rep(k, D) {
				s = x[i][k] - x[j][k];
				t += s * s;

                // cout << k  << ' ' <<  i  << ' ' << j << ' ' <<  sqrt(t)  << ' ' << s << endl;
				// if (sqrt(t) == (int)s) {
				// 	ans++;
				// }
			}
            if(ceil(sqrt(t)) == floor(sqrt(t))) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def bubble_sort(data, n):
    end_of_line = 0
    change_num = 0

    while end_of_line < n-1:
        for i in reversed(range(end_of_line,n)):
            if data[i-1] > data[i]:
                v = data[i]
                data[i] = data[i-1]
                data[i-1] = v
                change_num += 1
                break
            if end_of_line >= i-1:
                end_of_line += 1
                break
    
    return data, change_num


num = int(input())
data = list(map(int, input().split()))

sorted_data, chage_num = bubble_sort(data,num)

print(' '.join(map(str,sorted_data)))
print("%d"%chage_num)



Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; i++)
		sum += i;
	cout << sum << endl;
} 

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

int keta( int k ){
    int j = 1 ;
    while( k >= 10 ){
        k/=10 ;
        j++   ;
    } 
    return j ;
}

int main() {
    int N ;
    int A[10][10] ;// A[i][j] 最高数i 末尾の数j
    fill(A[0],A[10],0) ;
    cin >> N ;
    for(int i = 1 ; i <= N ; i++ ){
        int I = keta(i)-1 ;
        int K = pow(10,keta(i)-1) ;
        A[i/K][i%10]++ ;
    } 
    ll ans = 0 ;
    rep(i,10){
        rep(j,10){
            ans += A[i][j] * A[j][i] ;
        }
    }
    cout << ans << endl ;
}

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

int main() {
  int d,n;cin>>d>>n;
  int ans=1;
  rep(i,d)ans*=100;
  if(n==100)n++;
  cout<<ans*n<<endl;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    map<ll, ll> cnt;
    rep(i, N) { cnt[a[i]]++; }

    if (SZ(cnt) == 1) {
        auto it = cnt.begin();
        if (it->first != 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
        return 0;
    } else if (SZ(cnt) == 2) {
        bool flg = true;
        for (auto e : cnt) {
            if (!((e.second == N / 3 && e.first == 0) ||
                  (e.second == 2 * N / 3)))
                flg = false;
        }

        if (flg) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        return 0;
    } else if (SZ(cnt) == 3) {
        vector<ll> b(3);
        ll i = 0;

        bool flg = true;
        for (auto e : cnt) {
            if (e.second == N / 3) {
                b[i] = e.first;
            } else {
                cout << "No" << endl;
                return 0;
            }
            i++;
        }
        // cout << b[0] << "," << b[1] << "," << b[2] << endl;
        // cout << (b[0] ^ b[1] ^ b[2]) << endl;
        // cout << (b[0] ^ b[1] ^ b[2] == 0) << endl;

        if ((b[0] ^ b[1] ^ b[2]) == 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else if (SZ(cnt) > 3) {
        cout << "No" << endl;
        return 0;
    }

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];

  for (int i = 0; i < n; i++) cin >> a[i];
  int min = a[0], max = a[0];
  long sum = 0;
  for (auto e : a) {
    sum += e;

    if (e > max) {
      max = e;
    } else if (e < min) {
      min = e;
    }
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}



Measured memory_bytes: 3136
n,x,y=map(int,input().split())
min_dist=[0]*(n-1)
for i in range(n):
  for j in range(i+1,n):
    min_dist[min(j-i-1,abs(x-1-i)+abs(y-1-j))]+=1
for ans in min_dist:
  print(ans)

Measured memory_bytes: 3444
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	char a=0,b=0;
	int aa=0,bb=0;
	cin>>s;
	for(int i=0;i<4;i++)
	if(a==0) a=s[i];
	else if(s[i]==a) aa++;
	else if(b==0) b=s[i];
	else if(s[i]==b) bb++;
	else
	{
		cout<<"No";
		return 0;
	}
	if(aa!=2||bb!=2)
	{
		cout<<"No";
		return 0; 
	}
	cout<<"Yes";
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int f[10010];
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>f[i];
	int ans=0;
	for(int i=2;i<=n-1;i++)
	if(f[i-1]<f[i]&&f[i]<f[i+1]||f[i+1]<f[i]&&f[i]<f[i-1]) ans++;
	cout<<ans<<endl;
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int f[100010];
	for(int i=1;i<=n;i++) cin>>f[i];
	sort(f+1,f+n+1);
	if(n%2!=0)
	{
		cout<<0;
		return 0;
	}
	cout<<f[n/2+1]-f[n/2];
}*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1000000007;
ll c[2005][2005];
int n,k;
long long pow_mod(long long b,long long p,long long k)
{
	if(p==1) return b;
	if(p==0) return 1;
	long long x=pow_mod(b,p/2,k);
	x*=x;x%=k;
	if(p%2!=0) x*=b;x%=k;
	return x;
}
int main()
{
	cin>>n>>k;
	int a=k,b=n-k;
	for(int i=0;i<=2000;i++)
	for(int j=0;j<=i;j++)
	if(j==0||j==i) c[i][j]=1;
	else c[i][j]=c[i-1][j-1]+c[i-1][j],c[i][j]%=p;
	for(int i=1;i<=k;i++)
	{
		ll ans=1;
		ans*=c[n-k+1][i];
		ans*=c[k-1][i-1];
		ans%=p;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 30208
#include <bits/stdc++.h>
using namespace std;
int main(){
int h,w; 
cin>>h>>w;
int bx[8] = {-1,-1,-1,0,0,1,1,1};
int by[8] = {0,1,-1,1,-1,1,0,-1};
char buf[55][55] = {};
for(int i = 0; i<h; i++){
    for(int j = 0 ; j<w; j++){
        cin>>buf[i][j];
    }
}
int count = 0;
for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
        if(buf[i][j]=='.'){
            for(int k = 0; k<8; k++){
                int x = bx[k] + i;
                int y = by[k] + j;
                if(buf[x][y]=='#'){
                    count++;
                }
                buf[i][j] = count+'0';
                
            }
            count = 0;
        }
    }
}

for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
        if(j%w==0){
            cout<<endl;
        }
        cout<<buf[i][j];
    }
}
return 0;
}
    



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

int W,H;
int field[10][10] = {0};
int num = 0;
bool dfs(int x, int y, int d){
	if(d == 0 && x == W && y == H) return true;
	bool ans = false;
	if(field[y+1][x] == 1){
		if(dfs(x, y+1, d-1))
			ans = true;
	}
	if(field[y][x+1] == 1){
		if(dfs(x+1, y, d-1))
			ans = true;
	}
	field[y][x] = 0;
	return ans;
}

int main()
{
	cin >> H >> W;
	for(int i=1;i<=H;i++){
		string str;
		cin >> str;
		for(int j=1;j<=W;j++){
			if(str[j-1] == '#'){
				field[i][j] = 1;
				num++;
			}
		}
	}
	if(dfs(1,1,num-1))
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[] cnt = new int[26];
        for(int i=0;i<H;i++){
            String s = sc.next();
            for(char w:s.toCharArray()) cnt[w-'a']++;
        }
        int[] rec= new int[4];
        for(int w:cnt) rec[w%4]++;
        String ans = help(W,H,rec);
        System.out.println(ans);
    }
    static String help(int W, int H, int[] rec){
        boolean flag = false;
        if(W%2==0&&H%2==0){
            flag = rec[0]==26;
        } else if(W%2==1&&H%2==1){
            if(rec[1]>=2) return "No";
            if(rec[1]+rec[3]>=2||rec[1]+rec[3]<1) return "No";
            if(rec[1]==1) flag = rec[2]<=(H+W-2)/2&&rec[2]>=(H+W-2)%4/2;
            else flag = rec[2]<=(H+W-4)/2&&rec[2]>=(Math.max(0,H+W-4))%4/2;
        } else{
            int n = W%2==1?H:W;
            flag = rec[1]==0&&rec[3]==0&&rec[2]<=n/2;
        }
        return flag?"Yes":"No";
    }
}


Measured memory_bytes: 24148
n = list(map(int, input().split()))
a = list(str(input()))

b = []
ans = 0
for i in range((len(a) - 1)):
    if a[i] != a[i+1]:
        b.append(i)
    else:
        ans += 1

c = len(b)
if n[1]*2 >= c:
    ans += c
else:
    ans += min(c, n[1]*2)

print(ans)

Measured memory_bytes: 7796
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int x; cin >> x;
	cout << lcm(x, 360)/x << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
int have[MAXN];
int main(){
    cin>>n>>t;
    REP(i,1,t){
        int tmp;
        cin>>tmp;
        REP(j,1,tmp){
            int a;
            cin>>a;
            have[a]=1;
        }
    }
    int ans=0;
    REP(i,1,n)if(!have[i])ans++;
    cout<<ans;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;



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

	int N; cin >> N;
	int k; cin >> k;

	int h[110000];
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		if (h[i] >= k)cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n;
      cin >> n;
      char s;
      bool flag = false;
      for (int i = 0; i < n; i++) {
        cin >> s; 
        if (s == 'Y') flag = true;
      }
      if (flag) cout << "Four" << endl;
      else cout << "Three" << endl;
    }

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int r = nextInt();
  int D = nextInt();
  int x = nextInt();
  for (int i = 1; i <= 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(X, A, B):
    X -= A
    n = X // B
    return X - n * B


def main():
    X = int(input())
    A = int(input())
    B = int(input())
    print(solve(X, A, B))


if __name__ == '__main__':
    main()


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

int n,m;
void rec(int a, int b, string s){
  if(a==n && b==m){
    cout << s << endl;
  }
  if( (a<=3 && b==5) || (a==5 && b<=3) )return;
  if( (a==4 && b==6) || (a==6 && b==4) )return;
  if( a==5 && b==5 )return;

  rec(a+1,b,s+"A"); rec(a,b+1,s+"B");
}
  
int main(){
  cin >> n >> m;
  rec(0,0,"");
}

Measured memory_bytes: 1208
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var input = Reads();
        var H = input[0];
        var W = input[1];
        var input0 = Reads();
        var h = input0[0];
        var w = input0[1];
        Console.WriteLine(H*W-(h * W + w * H - h * w));

        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define no_of_test(x)        int x; cin>>x; while(x--)
#define fo(i,n)    for(int i=0;i<n;i++)
#define Maximum(x,y,z) max(x,max(y,z))
#define Minimum(x,y,z) min(x,min(y,z))
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}

int32_t main()
{
	very_fast();
	//no_of_test(x)
	{
		int n, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
		cin >> n;
		for (int i = 1; i <= n; i++)
		{
			string s;
			cin >> s;
			if (s == "AC")
			{
				cnt1++;
			}
			else if (s == "WA")
			{
				cnt2++;
			}
			else if (s == "TLE")
			{
				cnt3++;
			}
			else
				cnt4++;
		}
		cout << "AC" << " " << "x" << " " << cnt1 << endl;
		cout << "WA" << " " << "x" << " " << cnt2 << endl;
		cout << "TLE" << " " << "x" << " " << cnt3 << endl;
		cout << "RE" << " " << "x" << " " << cnt4 << endl;


	}
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<utility>
#include<deque>
#include<algorithm>
#include <iomanip>
#include<cmath>
#include<numeric>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);
int n, m=0;
ll tmp = -pow(10, 9) - 1;
vector<ll> a;


int main(void) {
	cin >> n;
	a = vector<ll>(n);
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 0)
			m++;
		ret += abs(a[i]);
		if (abs(a[i]) < abs(tmp))
			tmp = a[i];
	}
	if (m % 2 != 0)
		ret -= 2 * abs(tmp);
	cout << ret << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll H,W;
  ll ans=0;
  cin>>H>>W;
  if(H==1 || W==1){
    cout<<1<<endl;
  }
  else{
    ans+=H*W/2;
    ans+=H*W%2;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
N=int(input())
S =[]
for n in range(N):
    S.append(input())
from collections import Counter
S_C = Counter(S)
S_C =sorted(S_C.items(),key = lambda x:(-x[1],x[0]) )
m = S_C[0][1]
for s in S_C:
    if m==s[1]:
        print(s[0])

Measured memory_bytes: 59396
#include <stdio.h>

int N ;
int a ;
int b ;
int point[2] ;

void init ( ) ;

int main ( )
{
	while ( scanf ( "%d" , &N ) == 1 && N ) {
		init ( ) ;
		for ( int i = 0 ; i < N ; i++ ) {
			scanf ( "%d %d" , &a , &b ) ;
			if ( a > b ) {
				point[0] += ( a + b ) ;
			}
			else if ( a == b ) {
				point[0] += a ;
				point[1] += b ;
			}
			else {
				point[1] += ( a + b ) ;
			}
		}
		printf ( "%d %d\n" , point[0] , point[1] ) ;
	}
	return 0 ;
}

void init ( )
{
	point[0] = point[1] = 0 ;
}

Measured memory_bytes: 1028
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(){
    unsigned long long n;
    cin >> n;
    unsigned long long i_max = sqrt(n) + 1e6;
    if(i_max > n-1) i_max = n-1;
    vector<int> primes;
    unsigned long long c1, c2, count = 0;
    
    for(long long i=2; i<=i_max && n>= i; i++){
        c1 = 0;
        c2 = 1;
        while(n % i == 0){
            n /= i;
            c1++;
            if(c1 == c2){
                c1 =0;
                c2++;
                count++;
            }
        }
        primes.push_back(c2);
    }
    if(n != 1) count++;
    //for(auto pi:primes) cout << pi;
    cout << count << endl;
    return 0; 
}

Measured memory_bytes: 11656
module.exports=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){"use strict";var n=e(1);e(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,r){t.exports=require("fs")},function(t,r,e){"use strict";var n=e(3),i=e(5);t.exports=function(t){var r=new n(t);i(r)}},function(t,r,e){"use strict";var n=e(4);t.exports=class{constructor(t){var r=t.trim().split(/\s+/g);this.inp=new n(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,r,e){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,r,e){"use strict";var n=e(6);t.exports=function(t){for(var r=t.in(),e=t.in(),i=t.in(),s=new Array(e),o=new Array(r),u=0;u<r;u++)o[u]=[];for(var c=0;c<e;c++){var a=t.in(),f=t.in(),l=t.in();s[c]={s:a,t:f,c:l},o[a].push(f)}var v=99999999999999,p=n(r,s,i,v),d=p.D;if(p.P,-1==p.ncv)for(var h=0;h<r;h++)d[h]==v?console.log("INF"):console.log(d[h]);else console.log("NEGATIVE CYCLE")}},function(t,r,e){"use strict";t.exports=function(t,r,e){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:99999999999,i=new Array(t).fill(n),s=new Array(t).fill(-1);i[e]=0;for(var o=r.length,u=0;u<t-1;u++)for(var c=0;c<o;c++){var a=r[c],f=i[a.s]==n?n:i[a.s]+a.c;i[a.t]>f&&(i[a.t]=f,s[a.t]=a.s)}for(var l=-1,v=0;v<o;v++){var p=r[v];if(i[p.s]!=n&&i[p.s]+p.c<i[p.t]){l=p.s;break}}return{D:i,P:s,ncv:l}}}]);


Measured memory_bytes: 21612
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = I
        self.seg = [I]*(N*2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = gcd(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k //= 2
            self.seg[k] = gcd(self.seg[2 * k], self.seg[2 * k + 1])
 
    def query(self, a, b):
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                R = gcd(R, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = gcd(self.seg[b], R)
            a //= 2
            b //= 2
        return R

def main():
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 81340
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
 
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
 
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;
 
const int INF = MOD;
 
int n,m,q;
vector<pii> g[4001];             // グラフ
int depth[4001];        // 根付き木の深さ
int par[4001];
int query[4001];

int data[4001];
int init(){
  REP(i,4001)data[i]=-1;
}
int root(int x){
  return data[x]<0?x:data[x]=root(data[x]);
}
void unite(int a,int b){
  a=root(a);b=root(b);
  if(a!=b){
    if(data[a]>data[b])swap(a,b);
    data[a] += data[b];
    data[b] = a;
  }
}
int size(int x){
  return -data[root(x)];
}
 
int main(){
  scanf("%d%d",&n,&m);
  ll ans = 0;
  {
    set< pair<int,pii> > S;
    init();
    REP(i,m){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      --a;
      --b;
      S.insert(make_pair(c,pii(a,b)));
    }
    while(size(0)!=n){
      pair<int,pii> P = *S.begin(); S.erase(S.begin());
      int c = P.first;
      int a = P.second.first;
      int b = P.second.second;
      if(root(a)!=root(b)){
        unite(a,b);
        g[a].push_back(pii(b,c));
        g[b].push_back(pii(a,c));
        ans += c;
      }
    }
  }

  queue<int> Q;

  REP(i,n) depth[i]=INF;
  depth[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int pos = Q.front(); Q.pop();
    int d = depth[pos];
    REP(i,g[pos].size()){
      int to = g[pos][i].first;
      int c = -g[pos][i].second;
      if(depth[to]!=INF)continue;
      depth[to] = d+1;
      par[to] = pos;
      Q.push(to);
      query[to] = c;
    }
  }
  scanf("%d",&q);
 
  while(q--){
    int s,t;
    scanf("%d%d",&s,&t);
    --s; --t;
    ll x = INF;

    int a,b;
    a = s;
    b = t;
    if(depth[a]>depth[b])swap(a,b);
    while(depth[b]!=depth[a]){
      CHMIN(x,(ll)query[b]);
      b = par[b];
    }
    while(par[a]!=par[b]){
      CHMIN(x,(ll)query[a]);
      CHMIN(x,(ll)query[b]);
      a=par[a];b=par[b];
    }
    if(a!=b){
      CHMIN(x,(ll)query[a]);
      CHMIN(x,(ll)query[b]);
    }
    printf("%lld\n",ans+x);
  }
  return 0;
}


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

int main()
{
	string s;
    cin>>s;
    int cnt=0,maxi=0;
    for(int i=0;i<3;i++)
    {
    	if(s[i]=='R')
        	cnt++;
        else
        	cnt=0;
        maxi=max(cnt,maxi);
    }
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[2000005];
ll k, vis[2000005], step[2000005], r1, r2;
int st;
void dfs(int now, ll s);
void solve(int now, ll rem);
void work() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    dfs(1, 0);
    if (k >= r1) {
        k = (k - r1) % r2;
        solve(st, k);
    } else
        solve(1, k);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    work();
    return 0;
}

void solve(int now, ll rem) {
    if (rem == 0) { cout << now; return;
    }
    solve(a[now], rem - 1);
}

void dfs(int now, ll s) {
    if (vis[now]) {
        st = now;
        r2 = s - step[now];
        r1 = step[now];
        return;
    }
    vis[now]++;
    step[now] = s;
    dfs(a[now], s + 1);
}

Measured memory_bytes: 7520
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    set<ll> a;
    for(int i = 0; i < n; i++) {
        ll inp;
        cin >> inp;
        a.insert(inp);
    }
    if(a.size() == n) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 9728
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = int(input())
da = [[0 for i in range(50)] for j in range(50)]
ans = 0
for i in range(n):
    now = round(float(input())*1000000000)
    # print(now)
    a, b = 0, 0
    while(now%5 == 0):
        now //= 5
        a += 1
    while(now%2 == 0):
        now //= 2
        b += 1
    da[a][b] += 1
    # print(a, b)
    if a >= 9 and b >= 9: ans -= 1


for i in range(50):
    for j in range(50):
        for k in range(50):
            for l in range(50):
                if i+k >= 18 and j+l>= 18:
                    ans += da[i][j]*da[k][l]

print(ans//2)


Measured memory_bytes: 72596
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    lint sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    //候補を列挙
    vector<int> factor;
    for (lint i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            factor.push_back(i);
            if (i * i != sum) {
                factor.push_back(sum / i);
            }
        }
    }
    sort(all(factor), greater<int>());
    lint ans = 1;
    for (int i = 0; i < factor.size(); i++) {
        vector<int> mod(n);
        lint dist = 0;
        for (int j = 0; j < n; j++) {
            mod[j] = a[j] % factor[i];
            dist += mod[j];
        }
        sort(all(mod), greater<int>());
        // fac,...fac,0,...,0にしたい
        // block:facの数
        lint block = dist / factor[i];
        lint s = 0;
        for (int j = 0; j < block; j++) {
            s += mod[j];
        }
        if (block * factor[i] - s <= k) {
            ans = factor[i];
            break;
        }
    }
    cout << ans << endl;
}

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

const int N = 1e5 + 8;
long long a[N];
int main()
{
	cin.sync_with_stdio(0);
	a[0] = 2; a[1] = 1;
	for (int i = 2; i <= 86; ++i) a[i] = a[i - 1] + a[i - 2];
	int n; cin >> n;
	cout << a[n] << endl;
}


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

int main()
{
    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, l = map(int, input().split())

A = []
B = []

for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    B.append([int(j) for j in input().split()])

# ??????????????????????????????B?????¢??????????????¨???????????????
B_T = list(map(list, zip(*B)))

C = [[0 for j in range(l)] for i in range(n)]

for i in range(n):
    for j in range(l):
        C[i][j] = sum([a * b for (a, b) in zip(A[i], B_T[j])])

for i in range(n):
    print(*C[i])

Measured memory_bytes: 9172
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(g,b):
        left = bisect.bisect_left(g,j)
        right = len(b)-bisect.bisect_left(b,j)
        res = left*right
        for i in range(len(g)):
            li = g[i]
            k = bisect.bisect_left(b,j2-li)
            if k < len(b) and b[k]+li == j2 and b[k] > li:
                res -= 1
        return res

    n = I()
    s = input()
    r = []
    g = []
    b = []
    for i in range(n):
        if s[i] == "R":
            r.append(i)
        elif s[i] == "G":
            g.append(i)
        else:
            b.append(i)
    ans = 0
    for j in range(1,n-1):
        sj = s[j]
        j2 = 2*j
        if sj == "R":
            ans += f(g,b)+f(b,g)
        elif sj == "G":
            ans += f(r,b)+f(b,r)
        else:
            ans += f(r,g)+f(g,r)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 74552
#include <bits/stdc++.h>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)

using namespace std;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int tam = 100010;
int parent[tam], ta[tam];

int find(int n)
{
	if(parent[n] == -1) return n;
	return parent[n] = find(parent[n]);
}

int main()
{
	//ios::sync_with_stdio(false); cin.tie(0);
	//freopen("asd1.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, m;
	cin>>n>>m;
	pair<int,int> ar[m];
	fore(i, 0, m)
	{
		cin>>ar[i].f>>ar[i].s;
	}
	ll res = ((ll)n * (n-1)) / 2ll;
	vector<ll> rere;
	rere.pb(res);
	reverse(ar, ar + m);
	mem(parent, -1);
	fore(i, 0, n+1)
		ta[i] = 1;
	fore(i, 0, m-1)
	{
		int a = find(ar[i].f), b = find(ar[i].s);
		if(a != b)
		{
			res -= 1ll * ta[a] * ta[b];
			ta[a] += ta[b];
			parent[b] = a;
		}
		rere.pb(res);
	}
	fore(i, 0, rere.size())
		cout<<rere[rere.size()-1-i]<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 3828
N = int(input())
S = input()

res = 0
for k in range(1, N):
    cnt = 0
    for i in range(N - k):
        if i + k < N and S[i + k] == S[i]:
            cnt += 1
        else:
            cnt = 0
        cnt = min(k, cnt)
        res = max(cnt, res)

print(res)

Measured memory_bytes: 41964
import heapq

X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
P = sorted(P[:X])
Q = sorted(Q[:Y])
R.sort()
while R and (P[0] < R[-1] or Q[0] < R[-1]):
    if P[0] < Q[0]:
        heapq.heappush(P, R.pop())
        heapq.heappop(P)
    else:
        heapq.heappush(Q, R.pop())
        heapq.heappop(Q)
print(sum(P) + sum(Q))

Measured memory_bytes: 111952
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn brute_force(N: i64) -> i64 {
    let mut sum = 0;
    for m in 1..N {
        if N / m == N % m {
            sum += m;
        }
    }
    sum
}

fn solve(N: i64) -> i64 {
    let mut sum = 0;

    let mut Q = 1;
    while Q * Q < N {
        if N / Q > 0 && N % Q == 0 {
            let m = N / Q - 1;
            if N / m == N % m {
                debug!(m);
                sum += m;
            }
        }
        Q += 1;
    }

    sum
}

fn main() {
    // for N in 1..1000 {
    //     debug!(N);
    //     debug_assert_eq!(solve(N), brute_force(N), "N={}", N);
    // }

    let N = read!(i64);
    println!("{}", solve(N))
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
    int d, i;
    int sum;

    while (scanf("%d", &d) != EOF) {
        sum = 0;
        for (i = 0; i < 600; i += d) {
            sum += d * i * i;
        }
        printf("%d\n", sum);
    }

    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 0 && 0 <= b) {
		puts("Zero");
	}
	else if (a >= 0 || (b-a+1)%2==0) {
		puts("Positive");
	}
	else {
		puts("Negative");
	}
}

Measured memory_bytes: 256
N,K=map(int,input().split())
S=input()

ans=0
history=[0]*(2*K+1)
sum_recent=0
idx=0
c=1
for i in range(1,N+1):
    #print(ans,sum_recent,history,idx,c)
    if i<N and S[i]==S[i-1]:
        c+=1
        continue
    sum_recent=sum_recent+c-history[idx]
    history[idx]=c
    idx=(idx+1)%(2*K+1)
    c=1
    if S[i-1]=='1':
        ans=max(ans,sum_recent)
    elif i==N:
        sum_recent-=history[idx]
        ans=max(ans,sum_recent)

print(ans)


Measured memory_bytes: 4724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			double x = Double.parseDouble(br.readLine());
			double h = Double.parseDouble(br.readLine());
			
			if(x == 0 && h == 0){
				break;
			}
			
			double result;
			//??´??¢???????§???¢?????????
			double h2 = Math.pow((h*h+x*x/4), 0.5);
			
			result = x*x + 4*(x*h2/2);
			
			System.out.printf("%.6f\n",result);
		}
	}

}

Measured memory_bytes: 24664
#!/usr/bin/env python3
import bisect

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    S = list(input())
    Q = int(input())

    L = [[] for x in range(26)] # i番目のリストは、アルファベットが現れるインデックスのリストを持つ。

    for idx, s in enumerate(S):
        L[ord(s)-ord("a")].append(idx)

    for _ in range(Q):
        row = input().split()
        if row[0] == '1':
            y, z = int(row[1])-1, row[2]
            if S[y] != z:
                idx_target = ord(S[y]) - ord("a")
                idx_del = bisect.bisect_left(L[idx_target], y)
                if idx_del < len(L[idx_target]):
                    L[idx_target].pop(idx_del)
                bisect.insort(L[ord(z) - ord("a")], y)
                S[y] = z

        elif row[0] == '2':
            y, z = int(row[1]) - 1, int(row[2]) - 1
            answer = 0
            for idx_alphabet in range(26):
                left = bisect.bisect_left(L[idx_alphabet], y)
                if left < len(L[idx_alphabet]) and y <= L[idx_alphabet][left] <= z:
                    answer += 1
            print(answer)

    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 30216
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int result = 0;
		for (; A <= B; A++) {
			int digit1 = A / 10000;
			int digit2 = A / 1000 % 10;
			int digit4 = A / 10 % 10;
			int digit5 = A % 10;
			if (digit1 == digit5 && digit2 == digit4) {
				result++;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 26960
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int f(int X){
    int s = 0;
    while(X > 0){
        s += X % 10;
        X /= 10;
    }
    return s;
}

int main(void){

    int N;

    scanf("%d", &N);

    if(N % f(N) == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1636
#include<iostream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
using namespace std;

int main() {
	char str[250000];
	cin >> str;
	stack<char>q;
	q.push('1');
	char bt;
	int j = 0;
	while (str[j] != '\0') {
		//cout << 233 << endl;
		if (str[j] == 'S') q.push('S');
		if (str[j] == 'T') {
			bt = q.top();
			//cout << bt << endl;
			if ( bt=='T'|| bt=='1') q.push('T');
			else if (bt == 'S') {
				q.pop();
			}
		}
		j++;
	}
	cout << q.size()-1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF  2e15
#define mINF -2e15
#define MOD  10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



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

    int n;
    int cnt = 0;
    ll  end = mINF;
    cin >> n;

    pair <ll, ll> itv[200000];

    ll rbuf;
    ll lbuf;

    rep(i, n) {
        cin >> rbuf >> lbuf;
        itv[i].first  = rbuf + lbuf;
        itv[i].second = rbuf - lbuf;
    }
    sort(itv, itv + n);

    rep(i, n) {
        if (end <= itv[i].second) {
            cnt++;
            end = itv[i].first;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;
using ll = long long;

class Osa_k {
private:
	int n;
	vector<int> factor;

	void dfs(int val, int idx ,vector<int>& ans, map<int,int>& mp,const vector<int> &facts) {
		if(idx == (int)facts.size()) {
			ans.push_back(val);
			return;
		}
		int v = facts[idx];
		for(int i = 0; i <= mp[v]; i++) {
			dfs(val, idx+1, ans, mp, facts);
			val *= v;
		}
	}

public:

	//O(NloglogN)
	Osa_k(int _n):n(_n) {
		factor.assign(n, 0);
		iota(factor.begin(), factor.end(), 0);
		for(int i = 2; i*i < n; i++) {
			if(factor[i] < i)continue;
			for(int j = i * i; j < n; j += i) {
				if(factor[j] == j)factor[j] = i;
			}
		}
	}

	//O(logV)
	map<int, int> sieve(int v) {
		map<int, int> ret;
		while(v != factor[v]) {
			ret[factor[v]]++;
			v /= factor[v];
		}
		if(v != 1)ret[v]++;
		return ret;
	}


	vector<int> divisor(int v) {
		map<int,int> mp = sieve(v);
		vector<int> factors;
		for(auto i : mp)factors.emplace_back(i.first);
		vector<int> ans;
		dfs(1, 0, ans, mp, factors);
		sort(ans.begin(), ans.end());
		return ans;
	}


	//O(N)
	vector<int> get_list() {
		vector<int> prime;
		for(int i = 2; i < n; i++)if(factor[i] == i)prime.emplace_back(i);
		return prime;
	}

	//O(1)
	bool is_prime(int v) {
		if(v <= 1)return false;
		return (factor[v] == v);
	}

}fact(1000001);


int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    map<int,int> mp;
    for(int i = 0; i < n; i++)mp[a[i]]++;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        vector<int> s = fact.divisor(a[i]);
        int m = s.size();
        int cnt = 0;
        for(int j = 0; j < m; j++) {
            cnt += mp[s[j]];
        }
        if(cnt == 1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 36680
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int ans = INF;
  REP(i,s.length()-2){
    int num = stoi(s.substr(i,3));
    ans = min(ans, abs(num - 753));
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

struct Req{
	int Ai;
	int Bi;
	int ans;
	int point;
};

int N,M,Q;
int answer=0;
vector<int> A;
vector<Req> given;

int dfs(vector<int> A){ 
/*
	for(auto itr:A)
		cout << itr << " ";
	cout << endl;
*/

	if(A.size() == N+1){ int counter=0;
		for(auto g:given)
			if(A[g.Bi] - A[g.Ai] == g.ans) counter+=g.point;

		return counter;
	}

	A.push_back(A.back());
	while(A.back()<=M){
		answer=max(answer,dfs(A));
		A.back()++;
		//cout << "ANS>>>>>>>>>>>>>>>>>>>>>>>>>" << answer << endl;
	}

	return answer;
}

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

	int i;
	struct Req tmp;

	cin >> N >> M >> Q;

	for(i=0;i<Q;i++){
		cin >> tmp.Ai >> tmp.Bi >> tmp.ans >> tmp.point;
		given.push_back(tmp);
	}

	A.resize(1,1);
	dfs(A);

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3656
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
ans=0
if N % 2 == 0:
    ans = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) + A[N // 2] - A[N // 2 - 1]
else:
    x = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) - A[N // 2] - A[N // 2 - 1]
    y = 2 * (sum(A[N // 2 + 2:]) - sum(A[:N // 2])) + A[N // 2] + A[N // 2 + 1]
    ans = max(x, y)
print(ans)

Measured memory_bytes: 7512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
  int n; cin >> n;
  int ans = 0;
  rep(i,n){
    int a; cin >> a;
    if(i % 2 == 0 && a % 2 == 1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#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]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)){
        print("A");
    }else{
        print("B");
    }
}


Measured memory_bytes: 256