akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,q;
  string s;
  vector<set<int> > pos(30);

  cin>>n>>s>>q;
  rep(i,n){
    pos[s[i]-'a'].insert(i);
  }
  rep(j,q){
    int t;
    cin>>t;
    if(t==1){
      int i;
      char c;
      cin>>i>>c;
      i--;
      pos[s[i]-'a'].erase(i);
      s[i]=c;
      pos[c-'a'].insert(i);
    }
    else{
      int l,r;
      cin>>l>>r;
      int count=0;
      rep(i,26){
        auto it=pos[i].lower_bound(l-1);
        if(*it<r&&it!=pos[i].end())count++;
      }
      cout<<count<<endl;
    }
  }

  return 0;
}


Measured memory_bytes: 24196
#include<stdio.h>
long long int a[500050];
int main(){
	int n;
	while(~scanf("%d",&n)){
	for(int i = 1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	if(n%2==0){//为偶数 
		if(n==2){
			printf("%lld %lld\n",a[2],a[1]);
		}
		else{
		for(int i = n;i>=2;i--){//偶数从左往右从大到小输出 
			if(i%2==0){
				printf("%lld ",a[i]);
			}
		}
		printf("%lld",a[1]);//输出a【1】 
		for(int i = 2;i<=n;i++){
			if(i%2==1){
				printf(" %lld",a[i]);
			}
		}
		printf("\n");
		}
	}
	else if(n%2==1){
		for(int i = n;i>=2;i--){
			if(i%2==1){
				printf("%lld ",a[i]);
			}
		}
		printf("%lld",a[1]);
		for(int i = 2;i<=n;i++){
			if(i%2==0){
				printf(" %lld",a[i]);
			}
		}
		printf("\n");
	}
}
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;

const int MOD = 1000000007;

int ans[1000][1000];
bool vis[1000][1000];

int main()
{
    int h, w;
    cin >> h >> w;
    string arr[h];
    for (int i = 0; i != h; ++i) cin >> arr[i];
    
    queue<ii> bfs;
    bfs.push({0, 0});
    ans[0][0] = 1;
    
    while (!bfs.empty())
    {
        int i = bfs.front().first;
        int j = bfs.front().second;
        bfs.pop();
        
        if (i + 1 != h && arr[i + 1][j] == '.')
        {
            (ans[i + 1][j] += ans[i][j]) %= MOD;
            if (!vis[i + 1][j])
            {
                vis[i + 1][j] = 1;
                bfs.push({i + 1, j});
            }
        }
        if (j + 1 != w && arr[i][j + 1] == '.')
        {
            (ans[i][j + 1] += ans[i][j]) %= MOD;
            if (!vis[i][j + 1])
            {
                vis[i][j + 1] = 1;
                bfs.push({i, j + 1});
            }
        }
    }
    
    cout << ans[h - 1][w - 1];
}

Measured memory_bytes: 6144
#pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma") 
 
#include<bits/stdc++.h>
 
#define CFOR(i, str) for(int i = 0; (str)[i]!='\0'; (i)++)
#define FOR(i, s, r) for(int i = (s); i < (r); i++)
#define INF 1e9
#define NINF -1e9
#define SUM(a) accumulate(a.begin(), a.end(), 0)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.rbegin(), v.rend())
#define vmax(v) *max_element(v.begin(), v.end())
#define vmin(v) *min_element(v.begin(), v.end())
#define cnt(v, n) count(v.begin(), v.end(), (n))
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vpic vector<pair<int, char>>
#define mp make_pair
#define rot(s, k) rotate(s.begin(), s.begin()+ s.size()-(k%s.size()), s.end()); //+ve = right, -ve = left
#define lld long long int
#define ulld unsigned long long int
typedef long long ll;
using namespace std;
 
ll binpow(ll a, ll b) { 
ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res;
}
 
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
 
bool isPrime(ll n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n % 2 == 0 || n % 3 == 0) return false; 
    for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; 
    return true; 
}
void solve(){
      lld n;
    cin>>n;
    lld count=0,ans=0;
    while(n>0)
    {
       ans+=pow(2,count);
       n=n/2;
       count++;
    }
    cout<<ans;
}
int main(){
   ios::sync_with_stdio(0);
   cin.tie(0);
   ll t;
   t=1;
   while(t--)
   { 
   solve();
   }
   return 0;
}

Measured memory_bytes: 4100
//Friends 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int>par;
    UnionFind(int n){par=vector<int>(n,-1);}
    int root(int x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    bool unite(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)];}
};

signed main(){
    int n,m;cin>>n>>m;
    UnionFind uf(n);
    rep(i,0,m){
        int a,b;cin>>a>>b;
        a--;b--;
        uf.unite(a,b);
    }
    int ans=0;
    rep(i,0,n)ans=max(ans,uf.size(i));
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 4852
N = gets.to_i
VS = Array.new(N + 1)
(1 .. N).each do |i|
  VS[i] = gets.split.map(&:to_i)
end

used = Array.new(N + 1, false)
days = 0
next_queue = (1 .. N).to_a

loop do
  found = false
  used.fill(false)
  current_queue = next_queue.uniq
  next_queue = []
  
  until current_queue.empty?
    i = current_queue.shift
    
    next if used[i] || VS[i].empty?
    
    j = VS[i][0]
    
    if !used[j] && VS[j][0] == i
      used[i] = used[j] = true
      VS[i].shift
      VS[j].shift
      
      next_queue << i
      next_queue << j
      next_queue << VS[i][0] unless VS[i].empty?
      next_queue << VS[j][0] unless VS[j].empty?
      
      found = true
    end
  end
  
  if found
    days += 1
  else
    break
  end
end

if (1 .. N).all?{|i| VS[i].empty? }
  puts days
else
  puts -1
end


Measured memory_bytes: 36348
point = [0, 0]
n = int(input())
for _ in range(n):
    cards = input().split()
    if cards[0] > cards[1]:
        point[0] += 3
    elif cards[0] < cards[1]:
        point[1] += 3
    else:
        point = [n + 1 for n in point]
print(*point)


Measured memory_bytes: 5608
#abc097c

s=raw_input()
K=int(raw_input())
r=[]
for i in xrange(len(s)):
 for j in xrange(i+1,i+K+1):
  r.append(s[i:j])
#print r
r.sort()
l=list(set(r))
l.sort()
print l[K-1]


Measured memory_bytes: 4456
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 200000 + 5;
const long long int MINN = 2e5 + 5;
const long long int inf = 1e6;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 10050;
const int MAXN = 105;
int binsearch(int lo, int hi){
	while(lo<hi){
		int mid=(lo+hi)/2;
		if((mid))   // check(mid)
			hi=mid;
		else
			lo=mid+1;
	}
	return lo;
}
ll power(ll x,ll y){
    ll res=1;
    while(y>0){
      if(y&1) res=((res*x)%MOD);

      y/=2;
      x=((x*x)%MOD);
    }
    return res%MOD;
}


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

    return 0;
}


Measured memory_bytes: 3640
s = list(input())
t = list(input())
ans=len(t)

for i in range(len(s)-len(t)+1) :
  check = len(t)
  for j in range(len(t)) :
    if s[i+j]==t[j] :
      check -= 1
  if ans > check :
    ans = check
print(ans)

Measured memory_bytes: 9128
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    S=input()
    a=int(S[:2])
    b=int(S[2:])
    if 1<=a<=12 and 1<=b<=12:
        print('AMBIGUOUS')
    elif 1<=a<=12:
        print('MMYY')
    elif 1<=b<=12:
        print('YYMM')
    else:
        print('NA')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
 
int main() {
  int h,w,k,f=0;
  bool flag;cin>>h>>w>>k;
  vector<vector<int>> sss(h,vector<int>(w));
  vector<int> a(k),b(k);
  char x;
  rep(i,h){flag=false;rep(j,w){
    cin >>x;if(x=='#'){a[f]=i;b[f]=j;f++;
    if(!flag){rep(t,j)sss[i][t]=f;}
    flag=true;}
    if(flag){sss[i][j]=f;}
  }
  }
  for (int i=a[0]+1;i<h;i++){rep(j,w){if(sss[i][j]==0)sss[i][j]=sss[i-1][j];}}
  for (int i=a[0]-1;i>=0;i--){rep(j,w){if(sss[i][j]==0)sss[i][j]=sss[i+1][j];}}
rep(i,h){
  rep(j,w)cout<<sss[i][j]<<' ';
  cout<<endl;}
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

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

  ll n;
  cin >> n;
  ll a = lcm(2, n);
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = [[0]*2 for _ in range(n + 1)]
ac = 0
wa = 0

for i in range(m):
    p, s = input().split()
    p = int(p)
    if l[p][0] == 0: #ACが0の場合
        if s == "AC":
            l[p][0] = 1
        else:
            l[p][1] += 1

for i in range(1, n + 1):
    ac += int(l[i][0])
    if int(l[i][0]) != 0:
        wa += int(l[i][1])
print(ac, wa)

Measured memory_bytes: 13172
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<memory.h>
using namespace std;
typedef long long ll;
const int Max = 4e5 + 5;

int lst[Max];

int main()
{
	int n, x;
	cin >> n >> x;
	for (int i = 1;i <= n;i++)
	{
		scanf("%d", &lst[i]);
	}
	ll sum = 0;
	if (lst[1] > x)
	{
		sum = lst[1] - x;
		lst[1] = x;
	}
	for (int i = 2;i <= n;i++)
	{
		if (lst[i - 1] + lst[i] > x)
		{
			int t = lst[i] + lst[i - 1] - x;
			lst[i] -= t;
			sum += t;
		}
	}
	cout << sum << endl;
}

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

int main(){
  int k,s;cin >> k >> s;
  int ans = 0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(s-(i+j) <= k && s-(i+j) >= 0)ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from fractions import gcd
from collections import deque

a, b = map(int, input().split())
x = gcd(a, b)
y = int(x ** 0.5)
cd = deque([])
if x ** 0.5 % 1 == 0:
    cd.append(y)
    y -= 1
prime = []
for i in range(y, 0, -1):
    if x % i == 0:
        cd.appendleft(i)
        cd.append(x // i)

def prime_check(x, prime):
    for y in prime:
        if x % y == 0:
            return False
    return True

for x in cd:
    if prime_check(x, prime) and x != 1:
        prime.append(x)
print(len(prime) + 1)

Measured memory_bytes: 5304
#include<iostream>
#include<string>
using namespace std;
string s;

bool check( char ch ){
  if ( s[0] == ch && s[1] == ch && s[2] == ch ) return true;
  if ( s[3] == ch && s[4] == ch && s[5] == ch ) return true;
  if ( s[6] == ch && s[7] == ch && s[8] == ch ) return true;
  if ( s[0] == ch && s[3] == ch && s[6] == ch ) return true;
  if ( s[1] == ch && s[4] == ch && s[7] == ch ) return true;
  if ( s[2] == ch && s[5] == ch && s[8] == ch ) return true;
  if ( s[0] == ch && s[4] == ch && s[8] == ch ) return true;
  if ( s[2] == ch && s[4] == ch && s[6] == ch ) return true;
  return false;
}

main(){
  while( cin >> s ){
    if ( check('o') ) cout << 'o' << endl;
    else if ( check('x') ) cout << 'x' << endl;
    else cout << 'd' << endl;
  }
}

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

int main(){
  vector<vector<int> > cave(2000,vector<int>(2000,1e6+1));
  vector<int> xp(1e6+1);
  vector<int> yp(1e6+1);
  int l=1;
  int x=1000;
  int y=1000;
  xp[1]=x;
  yp[1]=y;
  cave[x][y]=1;

  for(int i=2;i<1e6+1;i++){
    for(int j=0;j<l;j++){
      x++;
      cave[x][y]=i;
      xp[i]=x;
      yp[i]=y;
      i++;
      if(i>1e6+1)break;
    }
    if(i>1e6+1)break;
    for(int j=0;j<l;j++){
      y--;
      cave[x][y]=i;
      xp[i]=x;
      yp[i]=y;
      i++;
      if(i>1e6+1)break;
    }
    if(i>1e6+1)break;
    l++;
    for(int j=0;j<l;j++){
      x--;
      cave[x][y]=i;
      xp[i]=x;
      yp[i]=y;
      i++;
      if(i>1e6+1)break;
    }
    if(i>1e6+1)break;
    for(int j=0;j<l;j++){
      y++;
      cave[x][y]=i;
      xp[i]=x;
      yp[i]=y;
      if(j!=l-1)i++;
      if(i>1e6+1)break;
    }
    if(i>1e6+1)break;
    l++;
  }

  /*
  for(int i=1490;i<1510;i++){
    for(int j=1490;j<1510;j++){
      cout<<cave[j][i]<<" ";
    }
    cout<<endl;
  }
  */

  vector<int> prime(1e6+2,1);
  prime[1e6+1]=0;
  prime[1]=0;
  for(int i=2;i<prime.size();i++){
    if(prime[i]){
      for(int j=i+i;j<prime.size();j+=i)prime[j]=0;
    }
  }

  //for(int i=0;i<1e6;i++)if(prime[i])cout<<i<<" ";


  while(1){
    int m,n;
    cin>>m>>n;
    if(m==0&&n==0)break;
    vector<vector<int> > bfs(2000,vector<int>(2000,0));
    vector<int> used(1e6+1,1);
    queue<int> q;
    q.push(n);
    while(!q.empty()){
      int np=q.front();
      //cout<<np<<endl;
      q.pop();
      if(used[cave[xp[np]-1][yp[np]+1]]&&cave[xp[np]-1][yp[np]+1]<=m){
        q.push(cave[xp[np]-1][yp[np]+1]);
        used[cave[xp[np]-1][yp[np]+1]]=0;
      }
      if(used[cave[xp[np]][yp[np]+1]]&&cave[xp[np]][yp[np]+1]<=m){
        q.push(cave[xp[np]][yp[np]+1]);
        used[cave[xp[np]][yp[np]+1]]=0;
      }
      if(used[cave[xp[np]+1][yp[np]+1]]&&cave[xp[np]+1][yp[np]+1]<=m){
        q.push(cave[xp[np]+1][yp[np]+1]);
        used[cave[xp[np]+1][yp[np]+1]]=0;
      }
      bfs[xp[np]][yp[np]]=max(bfs[xp[np]-1][yp[np]-1],max(bfs[xp[np]][yp[np]-1],bfs[xp[np]+1][yp[np]-1]))+prime[np];
      //if(prime[np])bfs[xp[np]][yp[np]]++;
    }

    /*
    for(int i=995;i<1005;i++){
      for(int j=995;j<1005;j++){
        cout<<bfs[j][i]<<" ";
      }
      cout<<endl;
    }
    */

    int ans=0;
    int id=0;
    for(int i=0;i<=m;i++){
      //cout<<i<<" "<<bfs[xp[i]][yp[i]]<<endl;
      if(ans<bfs[xp[i]][yp[i]]&&prime[i]){
        ans=bfs[xp[i]][yp[i]];
        id=cave[xp[i]][yp[i]];
      }
      if(ans!=0&&ans==bfs[xp[i]][yp[i]]&&prime[i]){
        ans=bfs[xp[i]][yp[i]];
        id=max(id,cave[xp[i]][yp[i]]);
      }
    }
    cout<<ans<<" "<<id<<endl;
  }

}



Measured memory_bytes: 49896
import           Control.Monad
import           Data.Array
import qualified Data.ByteString.Char8         as BS
import           Data.List
import           Data.Maybe
import           Data.Ord

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main :: IO ()
main = do
  (p : q : r : _) <- readInts
  print $ solve p q r

solve :: (Ord a, Num a) => a -> a -> a -> a
solve p q r = min (p + q) (min (p + r) (r + q))



Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int k,n;cin>>k>>n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	int ans = k;
	sort(ALL(a));
	for(int i = 0; i < n; i++) {
		if (i == 0){
			ans = min(ans,a[n - 1] - a[i]);
			ans = min(ans,k - (a[1] - a[0]));
		}
		else if (i != n - 1){
			ans = min(ans,k - (a[i] - a[i - 1]));
			ans = min(ans,k - (a[i + 1] - a[i]));

		}
		else{
			ans = min(ans,k - a[i] + a[i - 1]);
			ans = min(ans,a[i] - a[0]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

bool compare_by_a(pair<int, int> a, pair<int, int> b)
{
    if (a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < a.second;
    }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N, K;
    cin >> N >> K;

    LD ans = 0.0l;

    if (N >= K) {
        int m = 0;
        for (int k = K-1; k >= 1; k--) {
            for (; k*pow(2, m) < K; m++) {
                ;
            }
            ans += (LD)pow(0.5l, m)/N;
        }
        ans += (LD)(N-K+1)/N;
    } else {
        int m = 0;
        for (int k = N; k >= 1; k--) {
            for (; k*pow(2, m) < K; m++) {
                ;
            }
            ans += (LD)pow(0.5l, m)/N;
        }
    }

    printf("%.12Lf\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
//string S[N];


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  string s[N];
  rep(i,N) cin >> s[i];
  int x=0;
  int y=0;
  ll ans=0;
  int flag=0;
  rep(x,N){
  rep(i,N){
    rep(j,N){
      if(s[(x+i)%N][(y+j)%N] == s[(x+j)%N][(y+i)%N]){
	if(i==N-1 && j==N-1){
	  ans++;
	}	
      }
      else{
	flag=1;
	break;
      }
    }
    if(flag==1){
      flag=0;
      break;
    }
  }
  }
  /*  x = y =0;
  flag=0;
  rep(y,N){
  rep(i,N){
    rep(j,N){
      if(s[(x+i)%N][(y+j)%N] == s[(x+j)%N][(x+i)%N]){
	if(i==N-1 && j==N-1){
          ans++;
	}	
      }
      else{
	flag=1;
        break;
      }
    }
    if(flag==1){
      flag=0;
      break;
    }
  }
  }
  */
  cout << ans * (N*1LL) << endl;
  return 0;
    

}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <stack>
#include <string>
#include <cmath>
#include <map>
#define SIZE 205
#define MOD 1000000007
#define B1 89793

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
typedef unsigned long long int ull;

ll A[SIZE];
map < vector <ll>,vector <P> > mp;
map < vector <ll>,vector <P> >::iterator it;

int get(ll a,ll b)
{
	int ret=0;
	for(int i=62;i>=0;i--)
	{
		if(!(a>>i&1)&&(b>>i&1))
		{
			if(a!=0) ret++;
			break;
		}
		else if(a>>i&1)
		{
			a-=1LL<<i;
			b-=1LL<<i;
			ret++;
		}
	}
	return ret;
}
int main()
{
	int n;
	ll K;
	scanf("%d %lld",&n,&K);
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	ll ret=0;
	for(int i=0;i<63;i++)
	{
		vector <ll> vt;
		for(int j=0;j<n;j++) vt.push_back(A[j]%(1LL<<i)+1);
		vt.push_back(0);
		vt.push_back(1LL<<i);
		sort(vt.begin(),vt.end());
		vt.erase(unique(vt.begin(),vt.end()),vt.end());
		for(int j=0;j+1<vt.size();j++)
		{
			ll g=vt[j];
			vector <ll> now;
			bool up=true;
			for(int k=0;k<n;k++)
			{
				ll zan=A[k]%(1LL<<i);
				ll gn=A[k]>>i;
				if(zan<g) gn--;
				if(gn<0) up=false;
				now.push_back(gn);
			}
			ll nd=0;
			ll a=vt[j],b=vt[j+1]-1;
			if(a>b) continue;
			//a～bでbitcount最小求める
			int t=get(a,b)+i;
			if(up&&t<=K)
			{
				//puts("");
				//printf("%d %lld %lld : %d\n",i,a,b,t);
				//for(int k=0;k<n;k++) printf("%d ",now[k]);puts("");
				ll mn=now[0];
				for(int k=0;k<n;k++) mn=min(mn,now[k]);
				for(int k=0;k<n;k++) now[k]-=mn;
				ll low=max(0LL,mn-(K-t));/*
				ull gh=0;
				for(int k=0;k<n;k++)
				{
					gh=gh*B1+(ll) (now[k]+1);
				}*/
				mp[now].push_back(P(low,mn));
			}
		}
	}
	for(it=mp.begin();it!=mp.end();it++)
	{
		vector <P> vx=it->second;
		sort(vx.begin(),vx.end());
		P now=vx[0];
		for(int i=0;i<vx.size();i++)
		{
			P p=vx[i];
			if(now.second<p.first)
			{
				ret+=now.second-now.first+1;
				ret%=MOD;
				now=p;
			}
			now.second=max(now.second,p.second);
		}
		ret+=now.second-now.first+1;
		ret%=MOD;
	}
	printf("%lld\n",ret%MOD);
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    rep(i,10){
        rep(j,10){
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    int n;
    cin>>n;
    cout<<n+(n*n)+(n*n*n)<<endl;
    
}       
  
main()
{
    int t=1;
    //cin>>t;
    while(t)
    {
        t--;
        solve();
   }         
   return 0;
}

Measured memory_bytes: 3596
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,B,C=get_i
puts yn_judge(C.between?(A,B))

Measured memory_bytes: 1788
import math
I=int
q=I(input())
while q:
	a,b=map(I,input().split())
	c=I(math.sqrt(a*b))
	if c*(c+1)<a*b:print(2*c-1)
	elif (a*b==c*c)*(a!=b):print(2*c-3)
	else:print(2*c-2)
	q-=1


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

int main() {
  int N, sum=0, c, t;
  cin >> N;
  t = N;
  while (t > 0) {
    c = t % 10;
    t /= 10;
    sum += c;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;

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

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(x);

    int ans = 1, p = x;
    while (p % 360) {
        p += x;
        ans++;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int A, V, B, W, T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    if(V <= W) {
        cout << "NO" << endl;
    }
    else {
        if(((double)abs(A - B)) / T <= (V - W)) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	map<string, int> s;
	int n, m;
	cin >> n;
	for (int i = 0;i < n;i++) {
		string v;
		cin >> v;
		auto itr = s.find(v);
		if (itr != s.end()) {
			s[v] += 1;
		}
		else {
			s[v] = 1;
		}
	}

	cin >> m;
	for (int i = 0;i < m;i++) {
		string v;
		cin >> v;
		auto itr = s.find(v);
		if (itr != s.end()) {
			s[v] -= 1;
		}
	}
	int ans = 0;
	for (map<string, int>::iterator i = s.begin();i != s.end();i++) {
		ans = max(ans, i->second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x = min(n,b-1);
    cout<<(a*(x%b) - a*(x%b)%b)/b<<endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> V(N),C(N);

    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
    }

    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
    }

    vector<int> gap(N);

    for (int i = 0; i < N; i++) {
        gap.at(i) = V.at(i) - C.at(i);
    }

    int S = 0;

    sort(gap.begin(), gap.end());

    reverse(gap.begin(),gap.end());

    for (int i = 0; i < N; i++) {
            S += gap.at(i);

        if (gap.at(i) < 0) {
            S -=gap.at(i);
            break;
        }
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

string chengeWord(int n){
    string str;
    if(n >= 1000){
        if(n / 1000 > 1) str+= ('0' + n / 1000);
        str+= 'm';
        n%=1000;
    }
    if(n >= 100){
        if(n / 100 > 1) str+= ('0' + n / 100);
        str+= 'c';
        n%=100;
    }
    if(n >= 10){
        if(n / 10 > 1) str+= ('0' + n / 10);
        str+= 'x';
        n%=10;
    }
    if(n >= 1){
        if(n > 1) str+= ('0' + n);
        str+= 'i';
    }
    return str;
}

int chengeNum(string a){
    int num = 0;
    rep(i,a.size()){
        if(a[i] >= '1' && a[i] <= '9'){
            if(a[i + 1] == 'm') num+= (a[i] - '0') * 1000;
            else if(a[i + 1] == 'c') num+= (a[i] - '0') * 100;
            else if(a[i + 1] == 'x') num+= (a[i] - '0') * 10;
            else num+= (a[i] - '0') * 1;
            i++;
        }else{
            if(a[i] == 'm') num+= 1000;
            else if(a[i] == 'c') num+= 100;
            else if(a[i] == 'x') num+= 10;
            else num+= 1;
        }
    }
    return num;
}

int main(){
    int n;
    string a, b;
    cin >> n;
    rep(i,n){
        cin >> a >> b;
        int sum = chengeNum(a) + chengeNum(b);
        cout << chengeWord(sum) << endl;
    }
}

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

int main()
{
  int64_t H, N, a, sum = 0;
  cin >> H >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    sum += a;
  }
  if (sum >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 char C;
  cin >> C;
  if( C == 'a') cout << 'b' << endl; 
  if( C == 'b') cout << 'c' << endl;
  if( C == 'c') cout << 'd' << endl;
  if( C == 'd') cout << 'e' << endl;
  if( C == 'e') cout << 'f' << endl;
  if( C == 'f') cout << 'g' << endl;
  if( C == 'g') cout << 'h' << endl;
  if( C == 'h') cout << 'i' << endl;
  if( C == 'i') cout << 'j' << endl;
  if( C == 'j') cout << 'k' << endl;
  if( C == 'k') cout << 'l' << endl;
  if( C == 'l') cout << 'm' << endl;
  if( C == 'm') cout << 'n' << endl;
  if( C == 'n') cout << 'o' << endl;
  if( C == 'o') cout << 'p' << endl;
  if( C == 'p') cout << 'q' << endl;
  if( C == 'q') cout << 'r' << endl;
  if( C == 'r') cout << 's' << endl;
  if( C == 's') cout << 't' << endl;
  if( C == 't') cout << 'u' << endl;
  if( C == 'u') cout << 'v' << endl;
  if( C == 'v') cout << 'w' << endl;
  if( C == 'w') cout << 'x' << endl;
  if( C == 'x') cout << 'y' << endl;
  if( C == 'y') cout << 'z' << endl;
  if( C == 'z') cout << 'a' << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m)){
		if(n>=0&&n<=9&&m>=0&&m<=9){
		if(n>=m){
			printf("10\n");
			//printf("%d is not less than %d, so we should print 10.\n",n,m);
		}else{
			printf("0\n");
			//printf("%d is less than %d, so we should print 0.\n",n,m);
		}
		}
	}
}

Measured memory_bytes: 128
n,w = map(int,input().split())
dp = [[0]*(w+1) for j in range(n+1)] # DPテーブルの作成
v = []
W = []
for i in range(n):
    v_,w_ = map(int,input().split())
    v.append(v_)
    W.append(w_)
for i in range(n):
    for j in range(w+1):
        if j >= W[i]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-W[i]]+v[i])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[n][w])




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


int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i=0; i<N; i++) cin >> L[i];
    
    int sum = 0;
    int cnt = 0;
    
    while (sum <= X) {
        sum += L[cnt];
        cnt++;
        if (cnt == N+1) break;
    }
    
    cout << cnt << endl;
}

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

int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i, n) rep(j, d) {
		cin >> x[i][j];
	}
	int ans = 0;
	for(int i = 0; i < n-1; i++) {
		for(int j = i+1; j < n; j++) {
			int now = 0;
			rep(k, d) {
				now += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			bool ok = false;
			rep(i, 10000) {
				if(i*i == now) ok = true;
			}
			if(ok) ans++;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main(){

  int q; cin >> q;
  while(q--){

    ll ans = 0;
    ll a, b; cin >> a >> b;
    ll t = a*b;
    if( b > a )  swap(a, b);

    if( a == b ) cout << 2*b - 2 << endl;
    else if( a == b+1 ) cout << 2*b - 2 << endl;
    else {

      ll m = (ll)sqrt(t);
      if( m*m == t ) m--;
      if( m*(m+1) >= t ) cout << 2*m-2 << endl;
      else cout << 2*m-1 << endl;

    }

  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int dy[4]={0,-1,0,1};
int dx[4]={-1,0,1,0};
int main(void){
    int n;
    while(1){
        cin>>n;
       if(n==0) break;
        int a,b;
        int x[300],y[300];
x[0]=0;
y[0]=0;
int maxx=0,maxy=0,minx=0,miny=0;
        for(int i=1;i<n;i++){
            cin>>a>>b;
            x[i]=x[a]+dx[b];
            y[i]=y[a]+dy[b];
            maxx=max(maxx,x[i]);
            maxy=max(maxy,y[i]);
            minx=min(minx,x[i]);
            miny=min(miny,y[i]);
        }
cout<<maxx-minx+1<<" "<<maxy-miny+1<<endl;

    }
    return 0;
}

Measured memory_bytes: 3024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextLong();
			}
			Arrays.sort(arr);
			long ans = 0;
			for (int i = 0; i < n - 2; i++) {
				for (int j = i + 1; j < n - 1; j++) {
					if (arr[i] == arr[j]) {
						continue;
					}
					long hen = arr[i] + arr[j];
					for (int k = j + 1; k < n; k++) {
						if (arr[k] >= hen) {
							break;
						}
						if (arr[j] == arr[k]) {
							continue;
						}
						ans++;
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 36200
N = int(input())
# = str(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

counter = [0]*100001

for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            check = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if check > 0 and check % 1 == 0:
                counter[check-1] += 1

answer = counter[:N]

for i in answer:
    print(i)


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

using namespace std;

typedef long long ll;

int main(){
 

  int N,K; cin >> N >> K;
  
  vector<int> P(N);
  
  for(int i = 0; i < N; i++){ cin >> P[i];}
  
  vector<int> a(N,0);
  vector<int> sum(N,0);
  
  set<int> se;
  
  for(int i = 0; i < N; i++){ 
    if(i){ 
     if( P[i-1] < P[i] ){ a[i]++;}
    }
    
    if( i < K ){ se.insert(P[i]); }
    
  }
  
  
  sum[0] = a[0];
  
  for(int i = 1; i < N; i++){ 
    
   sum[i] += sum[i-1]+a[i];
    
  }
  
  // sum,aはP全体について累積和を作っておく
  // setに入れておくのは頭のK個だけ。
  
  
  bool ascend = (sum[K-1] == K-1);
  
  int ans = !ascend;
  
  for(int i = 0; i < N-K; i++){ 
    // iとi+1が分離しているかどうかを調べる
    // iとi+1が両方ともascendでない場合さえ考えればいい
    
    // 一番小さな値が出て、一番大きな値が入ればいい。
    
    bool l = (*se.begin() == P[i]);
    // 一番小さな値が出るか
    
    se.erase(P[i]);
    
    se.insert(P[i+K]);
    
    bool r = (*se.rbegin() == P[i+K]);
    // 一番大きな値が入るか
    
    
    if( sum[i+K] - sum[i+1] == K-1 ){ 
      //このとき、i+1はascend
      ascend = true;
    }
    else if( !(l && r) ){
      // i+1がascendではなく、かつiとi+1が連結でない
      ans++;
    }
    
  }
  
  cout << ans + ascend << endl;
  
  return 0;
}
      
      
      

Measured memory_bytes: 12032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int N;
	cin >> N;
	string s;
	cin >> s;
	deque<char> str;
	rep(i, N) str.push_back(s.at(i));
	deque<int> check;
	rep(i, N) {
		if (s.at(i) == '(') {
			check.push_back(1);
		}
		else {
			check.push_back(-1);
		}
	}
	// left_append : number of times str.push_front('(')
	// right_append : number of times str.push_back(')')
	int left_append = 0;
	int right_append = 0;
	int cnt = 0;

	rep(i, N) {
		if (s.at(i) == '(') cnt++;
		else if (s.at(i) == ')' && i == 0) {
			left_append++;
		}
		else if (s.at(i) == ')' && cnt == 0) {
			left_append++;
		}
		else if (s.at(i) == ')' && cnt > 0) {
			cnt--;
		}
	}
	cnt = 0;
	for(int i = (N - 1); i > -1; i--) {
		if (s.at(i) == ')') cnt++;
		else if (s.at(i) == '(' && i == N - 1) {
			right_append++;
		}
		else if (s.at(i) == '(' && cnt == 0) {
			right_append++;
		}
		else if (s.at(i) == '(' && cnt > 0) {
			cnt--;
		}
	}
	rep(i, left_append) {
		str.push_front('(');
	}
	rep(i, right_append) {
		str.push_back(')');
	}
	rep(i, str.size()) {
		cout << str.at(i);
	}

	return 0;
}



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

int main(){
    ll n, h;
    cin >> n >> h;

    vector<ll> a(n);
    vector<ll> b(n);
    ll max_a = 0;
    ll idx = 0;

    rep(i,n){
        cin >> a[i] >> b[i];
        if(max_a < a[i]){
            max_a = a[i];
            idx = i;
        }
    }

    sort(b.begin(), b.end(), greater<ll>());
    ll ans = 0;
    rep(i,n){
        if(b[i] > max_a){
            h -= b[i];
            ans ++;
            if(h <= 0){
                cout << ans << endl;
                return 0;
            }
        }
    }

    if(h%max_a==0){
        cout << ans+h/max_a << endl;
    }else{
        cout << ans+h/max_a+1 << endl;
    }
    return 0;
}

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

bool is_ok(string before, int before_value, string rest);

int char2int(char c) {
  return int(c) - int('0');
}

int calc(int before, char op, int after) {
  if ( op == '+' ) {
    return before + after;
  }
  else if ( op == '-' ) {
    return before - after;
  }
  return -100;
}

bool can_seven(string before, int before_value, char op, string rest) {
  int n_rest = rest.size();
  if ( n_rest == 1 ) {
    int after_value = char2int(rest.at(0));
    if ( calc(before_value, op, after_value) == 7 ) {
      cout << before << op << after_value << "=7" << endl;
      return true;
    }
    return false;
  }
 
  string rest_before = rest.substr(0,1);
  int rest_before_value = char2int(rest.at(0));
  string rest_rest = rest.substr(1, n_rest-1);
  return is_ok(before + op + rest_before
               ,calc(before_value, op, rest_before_value)
               ,rest_rest);
}

bool is_ok(string before, int before_value, string rest) {
  if ( can_seven(before, before_value, '+', rest) ) {
    return true;
  }
  if ( can_seven(before, before_value, '-', rest) ) {
    return true;
  }
  return false;
}

void solve(string S) {
  string before = S.substr(0,1);
  int before_value = char2int(S.at(0));
  string rest = S.substr(1);
  is_ok(before, before_value, rest);
}

int main() {
  //input
  string S;
  cin >> S;
  solve(S);
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

//N,M<=1500

int main(){
    int task;
    scanf("%d",&task);
    rep(t,task){
        int n,k;
        scanf("%d %d",&n,&k);
        vector<int> s;
        int bx=0;
        rep(i,n){
            int x;
            scanf("%d",&x);
            if(i>0){
                s.push_back(x-bx);
            }
            bx=x;
        }
        if(k>s.size()){
            printf("0\n");
        }else{
            sort(s.begin(),s.end());
            int ans=0;
            rep(i,s.size()-k+1){
                ans+=s[i];
            }
            printf("%d\n",ans);
        }
    }
}


Measured memory_bytes: 3312
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a<=c&&a+b>=c)printf("YES");
  else printf("NO");
}

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

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> X(N), Y(N);
  vector<char> C(N);
  REP(i, 0, N) cin >> X[i] >> Y[i] >> C[i];

  ll L = K * 2;
  vector< vector<ll> > black(L + 1, vector<ll>(L + 1, 0));
  vector< vector<ll> > white(L + 1, vector<ll>(L + 1, 0));
  REP(i, 0, N) {
    if(C[i] == 'B') black[Y[i] % L + 1][X[i] % L + 1]++;
    if(C[i] == 'W') white[Y[i] % L + 1][X[i] % L + 1]++;
  }
  REP(i, 1, L + 1) REP(j, 1, L + 1) {
    black[i][j] += black[i - 1][j];
    black[i][j] += black[i][j - 1];
    black[i][j] -= black[i - 1][j - 1];
    white[i][j] += white[i - 1][j];
    white[i][j] += white[i][j - 1];
    white[i][j] -= white[i - 1][j - 1];
  }

  ll ans = 0;
  REP(y, 0, L) REP(x, 0, L) {
    ll sum = 0;
    REP(i, -2, 2) REP(j, -2, 2) {
      ll ly = max(0LL, min(L, y + i * K));
      ll lx = max(0LL, min(L, x + j * K));
      ll ry = max(0LL, min(L, y + i * K + K));
      ll rx = max(0LL, min(L, x + j * K + K));
      if(abs(i + j) % 2 == 0) sum += black[ry][rx] - black[ly][rx] - black[ry][lx] + black[ly][lx];
      if(abs(i + j) % 2 == 1) sum += white[ry][rx] - white[ly][rx] - white[ry][lx] + white[ly][lx];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 64640
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def run():
    N, M = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    queue = []
    for a in A:
        heappush(queue, (-a, 1))

    for i in range(M):
        B, C = map(int, sysread().split())
        heappush(queue, (-C, B))
    total = 0
    ans = 0
    while True:
        c, b = heappop(queue)
        c *= -1
        total += b
        if total > N:
            total -= b
            break
        ans += c * b
    ans += (N - total) * c
    print(ans)

if __name__ == "__main__":
    run()

Measured memory_bytes: 37872
import sys
input = sys.stdin.readline

n = int(input())
H = list(map(int,input().split()))
A = list(map(int,input().split()))

HHtoIND = [[H[i], i] for i in range(n)]
HHtoIND.sort()

INDtoHH = [0] * n
for i in range(n):
    INDtoHH[HHtoIND[i][1]] = i

class segtree_max:  # 最大値を求める用
    def __init__(self, n, f = 0):  # sizeは最初に定めたサイズ、size2は2の累乗の値をとるサイズ(>=size)、fは初期値
        self.size = n
        i = 1
        while i < n:
            i *= 2
        self.tree = [f] * (2*i-1)
        self.size2 = i
        self.f = f
        
    def update(self, i, x):  # i番目の値をxに更新(xは更新前の値より小さくなければならない)
        j = self.size2 + i - 1
        self.tree[j] = x
        while j > 0:
            j = (j-1) // 2
            self.tree[j] = max(self.tree[2*j+1], self.tree[2*j+2])
            # print(self.tree)
    
    def get(self, a, b, k=0, l=0, r=None):  # 区間[a, b)の最小値を返す
        if r == None:
            r = self.size2
        if r <= a or b <= l:
            return self.f
        elif a <= l and r <= b:
            return self.tree[k]
        else:
            # print(2*k+1, 2*k+2,l, (l+r)//2,r)
            vl = self.get(a, b, 2*k+1, l, (l+r)//2)
            vr = self.get(a, b, 2*k+2, (l+r)//2, r)
            return max(vl, vr)

T = segtree_max(n)

for i in range(n):
    hh = INDtoHH[i]
    T.update(hh, T.get(0, hh) + A[i])
    # print(T.get(0, hh), A[i])

print(T.get(0, n))

Measured memory_bytes: 131336
A, B = map(int, input().split())
S = input()
s = S.split("-")
ans = "No"
if len(s) == 2 and len(s[0]) == A and len(s[1]) == B:
    t = "".join(s)
    if all([v in "0123456789" for v in t]):
        ans = "Yes"
print(ans)


Measured memory_bytes: 61928
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define psi std::pair<string,int>
#define pli std::pair<ll,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%I64d",&x)
#define prll(x) printf("%I64d ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vli std::vector<std::list<int>>
#define vlpi vector<list<pii>>
#define li std::list<int>
#define Endl printf("\n")
#define ma 1000000
#define mod 786433
#define FOR(i,a) for(int i=0; i<a; i++)
#define FORL(i,a) for(ll i=0; i<a; i++)


using namespace std;


int main()
{
    int n ; cin >> n ;
    vi a ;
    FOR(i,n){
        int x ;
        cin >> x ;
        a.pb(x) ;
    }
    double  inv =0  ;
    FOR(i,n) {
        inv += (double) 1/a[i] ;
        }
    double res = float (1/inv ) ;
    cout << res ;

}









Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int count = 0;
    for (int i=0; i<s.length()-2; i++) {
      if (s.charAt(i) == 'A' && s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C') {
        count++;
      }
    }
    sc.close();
    System.out.println(count);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(void){
   char X,Y;
   cin >> X >> Y;
   if(X-'0' > Y-'0') cout << '>' << endl;
   else if(X-'0' == Y-'0') cout << '=' << endl;
   else cout << '<' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int main(){
  ll n; cin >>n; ll ans=0,b=10;
  if(n%2){cout <<0; return 0;}
  else while(n>=b){ans+=n/b; b*=5;}
  cout <<ans;
return 0;}

Measured memory_bytes: 256
"""
1~Nまでを素因数分解して、素因数の数を足し合わせればよい。
計算量としては、O(N*√N)
"""
from collections import Counter
N = int(input())
count = Counter([])
for i in range(1,N+1):
    tmp = []
    d = 2
    while d**2 <= i:
        if i%d == 0:
            i //= d
            tmp.append(d)
        else:
            d += 1
    if i != 1:
        tmp.append(i)
    count += Counter(tmp)

mod = 10**9 +7
ans = 1
for v in count.values():
    ans *= (v+1)
ans %= mod
print(ans)

Measured memory_bytes: 75488