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

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

  int n;
  cin >> n;
  vector<int> v(n);
  int L=INT_MAX;
  int R=-1;
  for(int i=0; i<n; i++) {
    cin >> v[i];
    L = min(L, v[i]);
    R = max(R, v[i]);
  }
  int ans=INT_MAX;
  for(int i=L; i<=R; i++) {
		int cost=0;
	  for(int j=0; j<n; j++) {
	    cost+= (v[j]-i)*(v[j]-i);
    }
    ans=min(cost, ans);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
def digits_sum(n)
  sum = 0
  until n.zero?
    n, q = n.divmod(10)
    sum += q
  end
  sum
end

# main
n, a, b = gets.split.map(&:to_i)

ns = 1..n
r = a..b

p ns.select { |n| r.include?(digits_sum(n)) }.reduce(:+)


Measured memory_bytes: 1916
import java.util.*;

class Main {
    public static void main(String[] args) {
        String[] str = { "AC", "WA", "TLE", "RE" };
        int n;
        int count[] = new int[4];
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String s = sc.next();

            if (s.equals(str[0])) {
                count[0]++;
            } else if (s.equals(str[1])) {
                count[1]++;
            } else if (s.equals(str[2])) {
                count[2]++;
            } else {
                count[3]++;
            }
        }

        for (int i = 0; i < 4; i++) {
            System.out.printf("%s x %d\n", str[i], count[i]);
        }
    }
}

Measured memory_bytes: 57884
#include <bits/stdc++.h>
using namespace std;
#define maxn -20000000000 //negative value to break code and force you to put right constraint
#define mod 1073741824
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 100000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main()
{
	ll n;
	cin>>n;
	vector<long double> v(n+1);
	for(ll i=1;i<=n;i++)
		cin>>v[i];
	long double dp[3005][3005]={0};
	dp[0][0]=1;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=n;j++)
		{
			if(j==0)
				dp[i][j]=dp[i-1][j]*(1-v[i]);
			else
				dp[i][j]=dp[i-1][j]*(1-v[i])+dp[i-1][j-1]*v[i];
		}
	}
	long double ans=0;
	for(ll i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	cout<<setprecision(10)<<ans;
}


Measured memory_bytes: 141440
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    // cout << s;

    // o oxx o xox xx o xox x o
    // o o xxo x o xxx o xox x o
    // oo xx o xoxxx o xox x o

    // ooxxoxox xxo xoxxo

    int pre[n];
    pre[0] = s[0] == 'o' ? 1 : 0;
    rep(i, 1, n)
    {
        pre[i] = pre[i - 1]; // don't work
        if (s[i] == 'o')     // work
        {
            if (i - c - 1 >= 0)
            {
                pre[i] = max(pre[i], pre[i - c - 1] + 1);
            }
            else
            {
                pre[i] = max(pre[i], 1);
            }
        }
        // if (i - c >= 0)
        // {
        //     pre[i] = max(pre[i], pre[i - c]);
        // }
    }
    // rep(i, 0, n)
    // {
    //     printf("pre[%d]=%d\n", i, pre[i]);
    // }
    int suf[n];
    suf[n - 1] = s[n - 1] == 'o' ? 1 : 0;
    repi(i, n - 2, 0)
    {
        suf[i] = suf[i + 1];
        if (s[i] == 'o')
        {
            if (i + c + 1 < n)
            {
                suf[i] = max(suf[i], suf[i + c + 1] + 1);
            }
            else
            {
                suf[i] = max(suf[i], 1);
            }
        }
        // if (i + c < n)
        // {
        //     suf[i] = max(suf[i], suf[i + c]);
        // }
    }
    // rep(i, 0, n)
    // {
    //     printf("suf[%d]=%d\n", i, suf[i]);
    // }

    // iterate days to determine
    rep(i, 0, n)
    {
        if (s[i] == 'x')
        {
            continue;
        }
        bool ok = false;
        // int work = 0;
        // if (i > 0) {
        //     work += pre[i-1];
        // }
        // if (i < n-1) {
        //     work += suf[i+1];
        // }
        // if (work <k) {
        //     cout << i + 1 << el;
        // }
        rep(begin, min(i, i - c + 1), i + 1)
        {
            int end = max(i, begin + c - 1);
            int work = 0;
            if (begin > 0)
            {
                work += pre[begin - 1];
            }
            if (end < n - 1)
            {
                work += suf[end + 1];
            }
            // cout << "work" << work;
            if (work >= k)
            {
                ok = true;
                break;
            }
        }
        if (!ok)
        {
            cout << i + 1 << el;
        }
    }
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    int n, k ;
    cin >> n >> k ;
    string s ;
    cin >> s ;
    int ans = 0 ;
    int cnt = 0 ;
    REP(i,n-1){
        if(s[i]==s[i+1]){
            ans++ ;
        }
        else{
            cnt++ ;
        }
    }
    while(k>0){
        k-- ;
        if(cnt>=2){
            ans += 2 ;
            cnt -= 2  ;
        }
        else if(cnt==1){
            ans += 1  ;
            cnt -= 1 ;
        }
        else{
            continue ;
        }
    }
    cout << ans <<endl;





    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3728
import java.util.*;
public class Main{
    public static void main(String [] args){
        Scanner sc= new Scanner(System.in);
        String s= sc.next();
        int count=0;
        for(int i=0; i<s.length(); i++){
            if(i%2==1){
                if(s.charAt(i)=='0') count++;
            }else 
            if(s.charAt(i)=='1') count++;
        }
        if(s.length()-count<count){
            System.out.println(s.length()-count);
        }else System.out.println(count);
        
        
    }
}

Measured memory_bytes: 25740
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n;
vpll a;

int main(){
	cin>>n;
	a=vpll(n);
	for(int i=0;i<n;i++) cin>>a[i].second>>a[i].first;
	sort(a.begin(),a.end());
	ll S=0;
	bool B=1;
	for(int i=0;i<n;i++){
		S+=a[i].second;
		if(S>a[i].first) B=0;
	}
	cout<<(B?"Yes":"No")<<endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll
 
ll dp[101010][2][100];
int d[33][33];
int t[3][33];
signed main(){
    int n,C;
    cin>>n>>C;
    
    rep(i,0,C)rep(j,0,C)cin>>d[i][j];
    rep(i,0,n)rep(j,0,n){
        int a;cin>>a;
        t[(i+j)%3][a-1]++;
    }
    int ans=1<<30;
    rep(i,0,C)rep(j,0,C)rep(k,0,C)if(i!=j&&j!=k&&k!=i){
        
        int x=0;
        rep(h,0,C)x+=d[h][i]*t[0][h];
        rep(h,0,C)x+=d[h][j]*t[1][h];
        rep(h,0,C)x+=d[h][k]*t[2][h];
        ans=min(ans,x);
    }
    cout<<ans<<endl;
}

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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str;
int K;
int N;
int main(){
  cin >> str >> K;
  N = str.size();
  int pos = 0;
  while (K > 0 and pos < N){
    int x = str[pos] - 'a';
    if (x == 0){//a
      pos++;
      continue;
    }else{
      int diff = (26 - x);
      if (diff <= K){
	str[pos] = 'a';
	K -= diff;
	continue;
      }
      pos++;
    }
  }
  pos = N - 1;
  int x = str[pos] - 'a';
  x += K;
  x %= 26;
  str[pos] = x + 'a';
  cout << str << endl;
  return 0;
}


Measured memory_bytes: 640
# ABC162c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    # 最大公約数,最大公約数
    # from fractions import gcd
    from functools import reduce
    from math import gcd

    def lcm_base(a, b):
        return a * b // gcd(a, b)

    def lcm(*numbers):
        return reduce(lcm_base, numbers, 1)

    def gcds(*numbers):
        return reduce(gcd, numbers)

    k = int(input())
    ans = 0
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for l in range(1, k + 1):
                ans += gcds(i, j, l)
    print(ans)


if __name__ == '__main__':
    main()


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

#define M 1000000
#define NIL  (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
    if(ch ==   'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0,p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) {return key % M; }
int h2(int key) {return 1 + (key % (M - 1));}

int find(char str[]) {
    long long key,i,h;
    key = getKey(str);
    for (i = 0;; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h],str) == 0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key,i,h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h],str) == 0) return 1;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i,n = 0;
    char str[L],com[9];
    for (i = 0; i < n; i++) H[i][0] = '\0';
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%s %s",com,str);
        //printf("com: %s str: %s\n",com,str);
        if (com[0] == 'i') {
            insert(str);
        } else {
            if( find(str) ) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 15256
package main

import (
	"fmt"
	"strconv"
)

func main(){
	for{
		var x , y int
		fmt.Scan(&x , &y)
		if int(y) < int(x){
			fmt.Println(strconv.Itoa(y) + " " + strconv.Itoa(x))
		}else if int(y) > int(x){
			fmt.Println(strconv.Itoa(x) + " " + strconv.Itoa(y))
		}else if int(x) == 0 && int(y) == 0{
			break
		}else{
			fmt.Println(strconv.Itoa(x) + " " + strconv.Itoa(x))
		}
	}

}


Measured memory_bytes: 1316
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1,l,r;i<=n;++i)
	{
		scanf("%d%d",&l,&r);
		ans+=r-l+1;
	}
	printf("%d",ans);
	return 0;
}

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

int det(int a00, int a01, int a10, int a11)
{
	return a00*a11 - a01*a10;
}

int main()
{
	int a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f)
	{
		int t = det(a, b, d, e);
		double x = (double)det(c, b, f, e) / t;
		double y = (double)det(a, c, d, f) / t;
		if (x == 0)
			x = 0;
		if (y == 0)
			y = 0;
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 1192
main = do
    [n,m] <- map read.words<$>getLine
    print $ case (n,m) of
        (n,m) | n==2 || m==2 -> 0
        (n,m) | n==1 && m==1 -> 1
        (n,m) | n==1 -> m-2
        (n,m) | m==1 -> n-2
        (n,m) | True -> (n-2) * (m-2)

Measured memory_bytes: 508
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans = 0;
  for(int i = 1; i < n+1; i++){
    int sum = 0;
    int x = i;
    while(x>0){
      sum+=x%10;
      x/=10;
    }
    if(sum>=a&&sum<=b) ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}




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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3648
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt(), X = sc.nextInt();
		int[] day = new int[N];
		int[] count = new int[N];
		for (int i=0; i<N; i++){
			day[i] = sc.nextInt();
			for (int j=1; j<=D; j+=day[i]){
				count[i]++;
			}
		}
		int ans = X;
		for (int i:count){
			ans += i;
		}
		System.out.println(ans);
		

	}

}

Measured memory_bytes: 35860
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <climits>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    vector<int> X(N);
    int ans;
    ans = INT_MAX;
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }
    
    for(int i = 1; i <= 100; i++){
        int sum = 0;
        for(int j = 0; j < N; j++){
            sum += pow(X[j]-i,2);
            //cout << X[j] << " " << X[i] << " " << X[j]-X[i] << endl;
        }
        //cout << sum << endl;
        ans = min(ans,sum);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[0]);
        int n = int.Parse(input[1]);

        int[] p = new int[n];
        input = Console.ReadLine().Split(' ');

        for (int i = 0; i < n; i++)
        {
            p[i] = int.Parse(input[i]);
        }

        List<int> list = new List<int>(p);

        for (int i = 0; i <= 100; i++)
        {
            if (!list.Contains(x - i))
            {
                Console.WriteLine(x - i);
                return;
            }
            else if (!list.Contains(x + i))
            {
                Console.WriteLine(x + i);
                return;
            }
        }
    }
}


Measured memory_bytes: 27516
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, A, B; cin >> N >> A >> B;
  cout << min(A, B) << " " << max(0, (A + B) - N) << endl;
}


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

double minDiagonal(int a, int b, int c) {
    if (a >= b && a >= c) {
        return sqrt(b * b + c * c);
    } else if (b >= a && b >= c) {
        return sqrt(a * a + c * c);
    } else {
        return sqrt(a * a + b * b);
    }
}

int main() {
    while (true) {
        int a, b, c;
        cin >> a >> b >> c;
        if (a == 0 && b == 0 && c == 0) {
            break;
        }
        double diagonal = minDiagonal(a, b, c);
        int n;
        cin >> n;
        for (int i = 0; i < n; i++) {
            int radius;
            cin >> radius;
            if (diagonal < radius * 2) {
                cout << "OK" << endl;
            } else {
                cout << "NA" << endl;
            }
        }
    }
}

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

namespace C
{
	class Program
	{
		static void Main()
		{
			var line = Console.ReadLine();
			var lineSplited = line.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

			var N = int.Parse(lineSplited[0]);
			var Q = int.Parse(lineSplited[1]);

			var S = Console.ReadLine().ToList();

			var L = new List<int>();
			var R = new List<int>();
			for (int i = 0; i < Q; i++) {
				var line2 = Console.ReadLine();
				var lineSplited2 = line2.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

				L.Add(int.Parse(lineSplited2[0]) - 1);
				R.Add(int.Parse(lineSplited2[1]) - 1);
			}

			var acTable = new List<int>();
			acTable.Add(0);
			
			var count = 0;
			for (int i = 1; i < N; i++) {
				if (S[i - 1] == 'A' && S[i] == 'C') {
					count++;
				}
				acTable.Add(count);
			}

			for (int i = 0; i < Q; i++) {
				Console.WriteLine(acTable[R[i]] - acTable[L[i]]);
			}
		}
	}
}


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

int main(){ 
  string s;
  cin >> s;
  if(s == "abc") cout << "Yes" << endl;
  else if(s == "acb") cout << "Yes" << endl;
  else if(s == "bac") cout << "Yes" << endl;
  else if(s == "bca") cout << "Yes" << endl;
  else if(s == "cab") cout << "Yes" << endl;
  else if(s == "cba") cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
//rock//
#include <iostream>

using namespace std;

int main(){
	int hand[5];
	bool handbe[3];
	bool isdraw;
	while (1){
		isdraw = false;
		handbe[0] = false;
		handbe[1] = false;
		handbe[2] = false;

		cin >> hand[0];
		if (hand[0] == 0)break;
		handbe[hand[0]-1] = true;
		for (int i = 1; i < 5; ++i){
			cin >> hand[i];
			handbe[hand[i]-1] = true;
		}

		if (handbe[0]){//あいこ判定
			if (handbe[1] == handbe[2])isdraw = true;
		} else{
			if (handbe[1] != handbe[2])isdraw = true;
		}

		if (isdraw){
			for (int i = 0; i < 5; ++i){
				cout << "3" << endl;
			}
			continue;
		}

		for (int j = 0; j < 3; ++j){
			if (handbe[j] && handbe[(j+1)%3]){
				for (int i = 0; i < 5; ++i){
					cout << (hand[i] == j+1 ? 1 : 2) << endl;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
    int a[100] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d",&k);
    printf("%d",a[k-1]);
    return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	(ll)(1e9 + 7)

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct UnionFind
{
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> childN;
	ll r = 0;

	UnionFind(int N) : par(N), childN(N)
	{
		//最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++)
			par[i] = i, childN[i] = 1;
	}

	int root(int x)
	{
		// データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y)
	{
		// xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		r -= childN[rx] * (childN[rx] - 1) / 2;
		r -= childN[ry] * (childN[ry] - 1) / 2;
		childN[ry] += childN[rx];
		childN[rx] = 0;
		r += childN[ry] * (childN[ry] - 1) / 2;
	}

	bool same(int x, int y)
	{
		// 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

using xpair = pair<int, int>;
bool operator>(const xpair &a, const xpair &b) { return a.second > b.second || (a.second == b.second && a.first > b.first); };
bool operator<(const xpair &a, const xpair &b) { return a.second < b.second || (a.second == b.second && a.first > b.first); };
bool operator==(const xpair &a, const xpair &b) { return a.first == b.first; };

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

	printf("%d", n + n * n + n * n*n);

	return 0;
}


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

typedef long long ll;

int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  
  int n = s.length();
  bool prev = false;
  int cnt = 0;
  for(int i = 1;i < n; i++){
    if(s[i]==s[i-1] && !prev){
      cnt++;
      prev = true;
    }else{
      prev = false;
    }
  }
  ll ret = 0;
  if(prev||s[0]!=s[n-1]){
    ret = (ll)cnt * k;
  }else{
    char c = s[0];
    int i = 0;
    while(s[i] == s[0]){
      i++;
      if(i==n)break;
    }
    if(i==n) ret = (ll)n*k/2;
    else if(i%2==0)ret = (ll)cnt*k;
    else ret = (ll)(cnt+1)*(k-1)+cnt;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  vector<i64> primes;
  vector<int> is(50505, true);
  rep(i,2,50505) {
    if(is[i]) {
      primes.push_back(i);
      for(int j = i + i; j < 50505; j += i) {
        is[j] = false;
      }
    }
  }
  i64 n;
  while((cin >> n), n != 0) {
    i64 i = 0;
    i64 j = primes.size();
    i64 cnt = 0;
    for(int i = 0;i < primes.size();i++) {
      i64 p = primes[i];
      if(p <= n - p && is[n - p]) {
        cnt++;
      }
    }
    cout << cnt << "\n";
  }
}



Measured memory_bytes: 3092
using System;

class Program
{
    static void Main(string[] args)
    {
        var i = Console.ReadLine();
        var c = 0;
        if (i[0] == '1') ++c;
        if (i[1] == '1') ++c;
        if (i[2] == '1') ++c;
        Console.WriteLine(c);
    }
}

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

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

int a[200000];
vector<int> v;
int main(){
  int n,k,l;
  cin>>n>>k;
  REP(i,n)
    a[i]=0;
  REP(i,n){
    cin>>l;
    a[l-1]++;
  }
  REP(i,n){
    if(a[i]!=0)
      v.push_back(a[i]);
  }
  sort(v.begin(),v.end(),greater<int>());
  int ret=0;
  for(auto it=v.begin();it!=v.end();it++){
    if(distance(v.begin(),it)>=k)
      ret+=*it;
  }
  cout<<ret<<endl;
  return 0;
}


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

using namespace std;

int main()
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long mx = max({ a * c, a * d, b * c, b * d });
	if (a <= 0 && 0 <= b) {
		mx = max(mx, 0LL);
	}
	if (c <= 0 && 0 <= d) {
		mx = max(mx, 0LL);
	}
	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  smatch m;
  regex_search(s, m, regex("A[A-Z]*Z"));
  cout << m.str().length() << endl;
  return 0;
}


Measured memory_bytes: 60132
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int H = in.nextInt() + 2;
		int W = in.nextInt() + 2;
		for(int i = 0; i < H; i++){
			String line = "";
			if(i != 0 && i != H - 1) line = "#" + in.next() + "#";
			for(int j = 0; j < W; j++){
				if(i == 0 || i == H -1) System.out.print("#");
				else System.out.print(line.charAt(j));
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 25084
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    ll sum = 0LL;
    vl a(n);
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        sum += x;
        a[i] = x + y;
    }
    sort(rall(a));
    for(int i = 1; i < n; i += 2) sum -= a[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(1000000)

n = int(input())
ab = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = [int(i)-1 for i in input().split()]
    ab[a].append([b, i])
    ab[b].append([a, i])
re = [False] * n
ed = [0]*(n-1)


def c(i=0, used=-1):
    global re, ed
    if re[i]:
        return 0
    re[i] = True
    k = 1
    for j in ab[i]:
        if re[j[0]]:
            continue
        if k == used:
            k += 1
        ed[j[1]] = k
        c(j[0], k)
        k += 1


c()
print(max(ed))
print(" ".join([str(i) for i in ed]))

Measured memory_bytes: 89716
#include <vector>
#include <stack>
#include <iostream>

using namespace std;

bool used[100010];
int dp[100010];
vector<pair<int,int> > g[100010];
bool flag;

void dfs(int x) {
  // cout << "x:" << x << endl;
  used[x] = true;
  for(pair<int,int> i: g[x]) {
    // cout << "i:" << i.first << endl;
    if(!used[i.first]) {
      dp[i.first] = dp[x] + i.second;
      // cout << "dp:" << dp[i.first] << endl;
      if(dp[i.first] > 1e9) {
        flag = false;
        break;
      }
      dfs(i.first);
    } else {
      if(dp[i.first] != dp[x] + i.second) {
        flag = false;
        break;
      }
    }
  }
}

vector<int> G[100010];
int h[100010];
int main(void)
{
  int n, m;
  cin >> n >> m;
  for(int i;i<m;i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    g[l].push_back({r, d});
    G[l].push_back(r);
    h[r]++;
  }

  int v = n;
  stack<int> st;

  for(int i=0;i<n;i++) if(h[i] == 0) st.push(i);

  vector<int> ans;
  while(st.size()) {
    int i = st.top(); st.pop();
    ans.push_back(i);
    for(auto& j: G[i]) {
      h[j]--;
      if(h[j] == 0) st.push(j);
    }
  }

  if(ans.size() != n) {
    cout << "No" << endl;
    return 0;
  }

  for(int i=0;i<n;i++){
    if(!used[ans[i]]) {
      flag = true;
      dp[ans[i]] = 0;
      dfs(ans[i]);
      if(!flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 15740
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	char S[27]={};
	cin >> S;

	size_t lng = strlen(S);
	vector<char> str;
	for(size_t i=0;i<lng;i++){
		str.push_back(S[i]);
	}

	stable_sort(str.begin(),str.end());
	const char *ans="yes";
	for(size_t i=1;i<lng;i++){
		if (str[i-1]==str[i]){ans="no";break;}
	}
	printf("%s\n",ans);

	return 0;
}


Measured memory_bytes: 256
import sys


def _s(): return sys.stdin.readline().strip()


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    s = _s()
    m = s.count("1")
    arr = list(range(max(1, m-1), m+2))
    d1 = {}
    for ai in arr:
        d1[ai] = [1 % ai]
        for i in range(n-1):
            d1[ai].append((2*d1[ai][-1]) % ai)

    d2 = {ai: 0 for ai in arr}
    for ai in arr:
        for i, c in enumerate(reversed(s)):
            if c == "1":
                d2[ai] = (d2[ai] + d1[ai][i]) % ai

    lst = [0] * (n+1)
    for i in range(1, n+1):
        t = i % bin(i)[2:].count("1")
        lst[i] = 1 + lst[t]

    i = n
    for c in s:
        i -= 1
        if c == "1":
            m1 = m - 1
            if m1 == 0:
                print(0)
                continue
            else:
                t = (d2[m1] - d1[m1][i]) % m1
        else:
            m1 = m + 1
            t = (d2[m1] + d1[m1][i]) % m1
        print(lst[t] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 96740
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int s=0,t=n;
	while(t){
		s+=t%10;
		t=t/10;
	}
	if(n%s==0)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

using namespace std;


void solve(long long N, std::vector<long long> P){
  long long m = N+1;
  long long ret = 0;
  for (int i = 0; i < N; ++i) {
    if (m > P[i]) {
      ret += 1;
      m = P[i];
    }
  }
  std::cout << ret << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> P(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&P[i]);
  }
  solve(N, std::move(P));
  return 0;
}


Measured memory_bytes: 1792
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class CTree {
public:
	long long int h;
	long long int dis;
	long long int n;
	CTree() {
		h = 0;
		dis = LLONG_MAX;
	}
	bool operator < (const CTree& t)const {
		return dis < t.dis;
	}
	bool operator > (const CTree& t)const {
		return dis > t.dis;
	}
};


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

	cin >> N >> M >> K;
	vector<long long int>height(N+1);
	vector<vector<pair<long long int, long long int>>>edge(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> height[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> H;
		if (height[L] >= H) {
			edge[L].push_back({ R,H });
		}
		if (height[R] >= H) {
			edge[R].push_back({ L,H });
		}
	}
	vector<CTree>tree(N+1);
	for (int i = 1; i <= N; i++) {
		tree[i].n = i;
	}
	tree[1].dis = 0;
	tree[1].h = K;
	priority_queue<CTree, vector<CTree>, greater<CTree>>PQ;
	PQ.push(tree[1]);
	
	while (!PQ.empty()) {
		int cn = PQ.top().n;
		long long int h = PQ.top().h;
		long long int c = PQ.top().dis;
	//	cout << cn << " " << h << " " << c << endl;
		PQ.pop();
		if (tree[cn].dis < c) {
			continue;
		}
		for (auto i : edge[cn]) {
			if (h < i.second) {
				if (tree[i.first].dis > c + i.second * 2 - h) {
					tree[i.first].dis = c + i.second * 2 - h;
					tree[i.first].h = 0;
					PQ.push(tree[i.first]);
				}
			}
			else if (h - i.second > height[i.first]) {
				if (tree[i.first].dis > c+h - height[i.first]) {
					tree[i.first].dis = c+h - height[i.first];
					tree[i.first].h = height[i.first];
					PQ.push(tree[i.first]);
				}
			}
			else {
				if (tree[i.first].dis > c + i.second) {
					tree[i.first].dis = c + i.second;
					tree[i.first].h = h - i.second;
					PQ.push(tree[i.first]);
				}
			}
		}
	}
	if (tree[N].dis == LLONG_MAX) {
		cout << "-1\n";
		return 0;
	}
	cout << tree[N].dis + height[N] - tree[N].h << endl;
	return 0;
}

Measured memory_bytes: 22920
/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll MOD = 1e9 + 7;
bool cmp(pair<ll, ll>a, pair<ll, ll>b)
{
  return a.se < b.se;
}
void  icchhipadey()
{

  ll n;
  cin >> n;
  vector<ll>v1;
  vector<ll>v2;
  for (int i = 0; i < n; i++)
  {
    ll a, b;
    cin >> a >> b;
    v1.pb(a + b);
    v2.pb(a - b);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());

  ll ans = max(v1.back() - v1[0], v2.back() - v2[0]);
  cout << ans;


}
int main()
{


#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  icchhipadey();




}









Measured memory_bytes: 6636
import bisect

N = int(input())
A = list(map(int, input().split()))
A_n = []

for n in range(N):
    A_n.append(A[n]-(n+1))

A_n = sorted(A_n, reverse=True)

can_f = A_n[N//2]
ans_f = 0
for n in range(N):
    ans_f += abs(A_n[n]-can_f)


if N > 1:
    ans_s = 0
    can_s = A_n[N//2+1]
    for n in range(N):
        ans_s += abs(A_n[n]-can_s)
else:
    ans_s = 10**10

ans = min(ans_f, ans_s)
print(ans)

Measured memory_bytes: 25708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define ff first
#define ss second

int main()
{
	ios::sync_with_stdio(false);

	int N, L;
	cin >> N >> L;

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

	int minEl = A[0];
	for (int i = 0; i < N; ++i) {
		if (abs(A[i]) < abs(minEl)) {
			minEl = A[i];
		}
	}

	cout << (sum - minEl) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<string> grid(N);
	for (int i = 0; i < N; i++) cin >> grid[i];

	// A=0のときのBを全探索し、対称だったらそこを軸とする*N個は全部対称 O(N^3)

	int ans = 0;
	for (int b = 0; b < N; b++) {
		bool symm = true;
		for (int row = 0; row < N; row++) {
			for (int col = 0; col < N; col++) {
				if (grid[row][(col + b) % N] != grid[col][(row + b) % N]) symm = false;
			}
		}
		if (symm) ans += N;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long>data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  long x1 = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0)x1 += data.at(i);
    else x1 -= data.at(i);
  }
  x1 /= 2;
  cout << x1 * 2 << ' ';
  long xn = x1;
  for(int i = 0; i < N - 1; i++){
    xn = data.at(i) - xn;
    if(i != N - 2)cout << xn * 2<< ' ';
  }
  cout << xn * 2<< endl;
  return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int n; cin >> n;
	vi v(50, 0);
	v[0] = v[1] = 1;
	rep(i, 2, n + 1) {
		v[i] = v[i - 2] + v[i - 1];
	}
	P(v[n]);
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int s, w; cin >> s >> w;
    if(w>=s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }

    return 0;
}


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

int main() {
    int s;
    cin >> s;
    int a[1000000];
    a[0] = s;
    //i+1項を生成する
    for (int i=0;i<=1000000;i++) {
        if (a[i]%2==0) a[i+1] = a[i]/2;
        else a[i+1] = 3* a[i] + 1;

        //これまでの項と比較する
        for (int j=0;j<i;j++) {
            if (a[j] == a[i+1]) {
                cout << i+2 << endl;    //a[i+1]はa_(i+2)に対応
                i = 1000001;  //終了条件
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int cnt = 0;
      for(int i = 0; i < 3; i++) {
        if((n >> i & 1) == 1) cnt++;
      }
      System.out.println(cnt);
  }
}

Measured memory_bytes: 21712
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    As = [isRaw() for _ in range(3)]
    N = iRaw()
    bs = [iRaw() for _ in range(N)]
    for b in bs:
        for ridx,arow in enumerate(As):
            for cidx,a in enumerate(arow):
                if a==b:
                    As[ridx][cidx] = 0
    for ridx in range(3):
        if sum(As[ridx])==0:
            return "Yes"
        if sum([As[i][ridx] for i in range(3)])==0:
            return "Yes"
    if sum([As[i][i] for i in range(3)])==0:
        return "Yes"
    if sum([As[2-i][i] for i in range(3)])==0:
        return "Yes"
    return "No"
                    

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
R, G, B, N = map(int,input().split())

cnt = 0
for i in range(N+1):
  for j in range(N+1):
    k = N - R*i - G*j
    if k >= 0:
      if k%B == 0:
        cnt += 1
    else:
      break
print(cnt)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main()
{
  ll n,b,r;
  cin>>n>>b>>r;
  ll val=(n/(b+r));
  ll v=n%(b+r);
  ll ans=val*b+min(b,v);
  cout<<ans<<endl;
  return 0;
}

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

p=list(map(int,input().split()))
b=0b0000000000
cnt=0
while b < 0b1<<N:
    s = str(bin(b))[2:].zfill(N)
    for i in range(M):
        sum = 0
        for j in k[i]:
            if s[N-j]=="1":
                sum += 1
        if sum%2!=p[i]:
            break
    else:
        cnt+=1
    b+=1
print(cnt)


Measured memory_bytes: 3064
a = input()
if a.count("00") > 0:
    print("Bad")
elif a.count("11") > 0:
    print("Bad")
elif a.count("22") > 0:
    print("Bad")
elif a.count("33") > 0:
    print("Bad")
elif a.count("44") > 0:
    print("Bad")
elif a.count("55") > 0:
    print("Bad")
elif a.count("66") > 0:
    print("Bad")
elif a.count("77") > 0:
    print("Bad")
elif a.count("88") > 0:
    print("Bad")
elif a.count("99") > 0:
    print("Bad")
else:
    print("Good")

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

int main(){
   int h, a;
   cin >> h >> a;
   if(h % a == 0){
       cout << h / a << endl;
       return 0;
   }
   else{
       cout << (h/a + 1) << endl;
       return 0;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int a[n][m],b[m];
    int ans[n];
    for(int i=0;i<n;i++) ans[i]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<m;i++) cin>>b[i];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans[i]+=a[i][j]*b[j];
        }
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3108