akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
//[const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

void sim(vector<vi> &fld, int x, int y)
{
	fld[x][y] = 0;
	vector<pair<pii, int>> v;
	REP(i, 4) v.emplace_back(pii(x, y), i);
	while (!v.empty())
	{
		decltype(v) w;
		for (auto i : v)
		{
			int dir = i.second;
			int tx = i.first.first + dx[dir], ty = i.first.second + dy[dir];
			if (!valid(tx, ty, 4, 4)) continue;
			if (fld[tx][ty] == 0) w.emplace_back(pii(tx, ty), dir);
			else fld[tx][ty]++;
		}
		REP(i, 4)REP(j, 4)
		{
			if (fld[i][j] >= 5)
			{
				fld[i][j] = 0;
				REP(k, 4) w.emplace_back(pii(i, j), k);
			}
		}
		v = w;
	}
}

int check(vector<vi>& fld)
{
	int res = 0;
	REP(i, 4)REP(j, 4)
	{
		chmax(res, fld[i][j]);
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	vector<vi> v(4, vi(4));
	REP(i, 4)REP(j, 4) cin >> v[i][j];
	set<vector<vi>> st;
	st.insert(v);
	queue<pair<vector<vi>, int>> que;
	que.emplace(v, 0);
	while (!que.empty())
	{
		vector<vi> fld = que.front().first;
		int cnt = que.front().second;
		que.pop();
		int mx = check(fld);
		if (mx == 0)
		{
			cout << cnt << endl;
			return 0;
		}
		if (5 - mx > 5 - cnt) continue;
		REP(i, 4)REP(j, 4)
		{
			if (fld[i][j] == 0) continue;
			vector<vi> nx = fld;
			if (nx[i][j] == 4) sim(nx, i, j);
			else nx[i][j]++;
			if (st.count(nx)) continue;
			st.insert(nx);
			int f = check(fld);
			if (f == 0)
			{
				cout << cnt + 1 << endl;
				return 0;
			}
			que.emplace(nx, cnt + 1);
		}
	}
	cout << -1 << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  long double q,h,s,d;cin>>q>>h>>s>>d;
  ll n;cin>>n;

  vector<long double> a(4);
  a[0] = q/0.25;
  a[1] = h/0.5;
  a[2] = s;
  a[3] = d/2;
  sort(a.begin(), a.end());
//  rep(i,4)cout<<a[i]<<' ';cout<<endl;

  ll result=0;
  rep(i, 4){
    if(a[i]==d/2){result += (n/2)*d;n%=2;}
    if(a[i]==s){result += n*s;n=0;}
    if(a[i]==h/0.5){result += (n/0.5)*h;n=0;}
    if(a[i]==q/0.25){result += (n/0.25)*q;n=0;}
//cout<<result<<endl;
  }

  cout<<result;  

  return 0;
}

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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long dpN = 1UL << N;
    vector<unsigned long> dp(dpN, static_cast<unsigned int>(~0));
    dp[0] = 0;
    unsigned long M;
    cin >> M;
    for(unsigned long i = 0, a, b; i < M; ++i){
        cin >> a >> b;
        unsigned long mask{0};
        for(unsigned long j = 0, c; j < b; ++j){
            cin >> c;
            mask |= 1UL << (c - 1);
        }
        for(unsigned long j = 0; j < dpN; ++j)dp[j | mask] = min(dp[j | mask], dp[j] + a);
    }
    cout << static_cast<int>(dp.back()) << endl;
    return 0;
}

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

int main() {
  int m, f, r;

  while (true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      break;
    else if (m == -1 || f == -1)
      cout << 'F' << endl;
    else if (m + f >= 80)
      cout << 'A' << endl;
    else if (m + f >= 65 && m + f < 80)
      cout << 'B' << endl;
    else if (m + f >= 50 && m + f < 65)
      cout << 'C' << endl;
    else if (m + f >= 30 && m + f < 50 && r >= 50)
      cout << 'C' << endl;
    else if (m + f >= 30 && m + f < 50)
      cout << 'D' << endl;
    else if (m + f < 30)
      cout << 'F' << endl;
  }
}


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

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n,cnt = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a % 4 == 0) cnt += 2;
        else if(a % 2 == 0) cnt += 1;
    }
    
    cout << (n/2 <= cnt/2 ? "Yes" : "No") << endl;
    
    return 0;
}

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

int main(){
    int H,W,K; cin>>H>>W>>K;
    vector<vector<char>> c(H,vector<char>(W));
    rep(i,H){
        rep(j,W){
            cin >> c[i][j];
        }
    }

    // ビット全探索１のところを赤で塗ったとして０のところだけカウントする
    int ans=0;
    for (int i = 0; i < (1 << H); i++) {
        bitset<6> s(i);
        for(int j = 0; j < (1 << W); j++) {
        bitset<6> t(j);

        int k_count=0;
        rep(a,H){
            rep(b,W){
                if(s.test(a)==false && t.test(b)==false){
                    if(c[a][b]=='#'){
                        k_count++;
                    }
                }
            }
        }
        // cout << "s:" << s << endl;
        // cout << "t:" << t << endl;
        //cout << "j;" << j <<endl;
        if(k_count == K){
            ans++;
            // cout << "-----------"<< endl;
            // cout << "s:" << s << endl;
            // cout << "t:" << t << endl;
        }

        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
	int max;
	int kosu;
	
	scanf("%d",&max);
	if(max % 2 == 0){
		kosu = (max / 2) * (max / 2);
	}else{
		kosu = (max / 2 + 1) * (max / 2);
	}
	printf("%d",kosu);
	return 0;
}

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

int main() {
	int N;
  	cin >> N;
  	vector<int> T(N);
  	int total = 0;
  	for(int i=0; i < N; i++) {
      cin >> T.at(i);
      total += T.at(i);
    }
  
  	int M;
  	cin >> M;
  	vector<pair<int, int>> D(M);
  	for(int i=0; i < M; i++){
      int a;
      int b;
      cin >> a >> b;
      D.at(i) = make_pair(a, b);
    }
  
  	for(int i=0; i < M; i++){
      int a;
      int b;
      tie(a, b) = D.at(i);
      int ans = 0;
      ans = total - T.at(a-1) + b;
      cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int x;
	cin >> x;
	cout << x/500*1000 + (x%500)/5*5 << endl;
 	return 0;
 }


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <math.h>

using namespace std;

int main(){
   long long a,b,k,z,y,sama,i;
   scanf("%lld", &a);
   getchar();
   sama=0;
   if(a%2!=0){
      while(sama==0){
         b=sqrt(a);
         for(i=2;i<=b;i++){
            if(a%i==0){
               sama=1;
            }
         }
         
         if(sama==1){
            a=a+2;
            sama=0;
         }
         else{
            sama=1;
         }
      }
      cout<<a<<endl;
   }
   else{
       while(sama==0){
         b=sqrt(a);
         for(i=2;i<=b;i++){
            if(a%i==0){
               sama=1;
            }
         }
         
         if(sama==1){
            a=a+1;
            sama=0;
         }
         else{
            sama=1;
         }
      }
      cout<<a<<endl;
      
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a,b;
    cin >> a >> b;
    if(a%2==b%2) cout << (a+b)/2 << endl;
    else cout << (a+b)/2+1 << endl;
}


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

map< char , bool > used;
string s;

void solve(){
  string res="";
  for(int i=0;i<(int)s.size();i++){
    for(int j=0;j<(int)i;j++){
      string tmp=s;
      swap(tmp[j],tmp[i]);
      tmp=tmp.substr(0,j+1);
      if( s < tmp ){
        if( res=="" || res>tmp){
          res=tmp;
        }
      }
    }
  }

  if(res=="")res="-1";
  cout<<res<<endl;
}

int main(){

  cin>>s;

  for(char ch:s){
    used[ch]=true;
  }

  if(s.size()==26){
    solve();
    return 0;
  }
  
  for(char ch='a';ch<='z';ch++){
    if(!used[ch]){
      cout<<s<<ch<<endl;
      break;
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	int l = 0, r = 0;

	l = a + b;
	r = c + d;

	if (l == r)
		cout << "Balanced" << endl;
	else if(l<r)
		cout << "Right" << endl;
	else
		cout << "Left" << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <math.h>
#include <cstring>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;


int main(void) {
	int R;cin>>R;

	if(R<1200)
		cout << "ABC" << endl;
	else if(R<2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;

}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
heights = [0] + gets.split.map(&:to_i)

f = Array.new(n + 1, 1)
f[0] = 0

m.times do
  a, b = gets.split.map(&:to_i)
  f[a] = 0 if heights[a] <= heights[b]
  f[b] = 0 if heights[b] <= heights[a]
end

puts f.sum

Measured memory_bytes: 23348
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using u16 = uint16_t;

u16 n;
uint ans;
u16 a[2000];
int main(){
  scanf("%hu", &n);
  for(uint i = 0; i < n; i++) scanf("%hu", &a[i]);
  sort(a, a + n);
  for(uint i = 0; i < n; i++) for(uint j = i + 1; j < n; j++) for(uint k = j + 1; k < n; k++) if(a[i] + a[j] > a[k]) ans++;
  printf("%u", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int count_5=0,count_7=0;
void check(int word);
int main(void)
{
  int word[4],i;
  char str[16];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d%d",&word[0],&word[1],&word[2]);
  for (i=0;i<3;i++)
  {
    check(word[i]);
  }
  if((count_5 == 2)&&(count_7 == 1))
  {
    puts("YES");
  }
  else
  {
    puts("NO");
  }
  return 0;
}

void check(int word)
{
  switch (word)
  {
    case 5:
      count_5++;
      break;
    case 7:
      count_7++;
      break;
    default:
      break;
  }
}

Measured memory_bytes: 256
require 'prime'

MAX = 10**6
MOD = 10**9 + 7

@fac = []
@faci = []
@inv = []

@fac[0] = @fac[1] = 1
@faci[0] = @faci[1] = 1
@inv[1] = 1

2.upto(MAX) do |i|
  @fac[i] = @fac[i - 1] * i % MOD
  @inv[i] = MOD - @inv[MOD % i] * (MOD / i) % MOD
  @faci[i] = @faci[i - 1] * @inv[i] % MOD
end

def comb(n, k)
  return 0 if n < k
  return 0 if n < 0 || k < 0
  return @fac[n] * (@faci[k] * @faci[n - k] % MOD) % MOD
end

n, m = gets.chomp.split(" ").map(&:to_i)

pmd = Prime.prime_division(m)

ans = 1

pmd.each do |pm, e|
  ans *= comb(e + n - 1, e)
  ans %= MOD
end
puts ans

Measured memory_bytes: 30436
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vP c(N);
    rep(i,N){
        cin >> c[i].first;
        c[i].second=i;
    }
    sort(c.begin(),c.end());
    vl before(N,-1);
    rep(i,N){
        if(c[i].first==c[i+1].first){
            before[c[i+1].second]=c[i].second;
        }
    }
    ll dp[N];
    rep(i,N){
        dp[i]=0;
    }
    dp[0]=1;
    rep(i,N-1){
        dp[i+1]=dp[i];
        if(before[i+1]!=-1&&before[i+1]!=i){
            dp[i+1]+=dp[before[i+1]];
        }
        dp[i+1]%=MOD;
    }
    /*rep(i,N){
        cout << i << ' ' << dp[i] << endl;
    }*/
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 9516
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e12;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  ll i = 1;
  vector<ll> candidates;
  while (i * i <= N) {
    if ((N % i) == 0) {
      candidates.push_back(i);
    }
    ++i;
  }

  // For Debug
  // for (auto x : candidates) {
  //   cout << x << endl;
  // }
  ll ans = INF;
  for (auto i : candidates) {
    ll cand = 0;
    cand += i-1;
    cand += (N/i) - 1;
    if (cand < ans) {
      ans = cand;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int i, j, count;
  string S;
  vector<string> s;
  bool isOK = true;
  cin >> S;
  
  for(i = 0; i < 4; i++) {
    s.push_back(S.substr(i, 1));
  }
  
  for(i = 0; i < 4; i++) {
    count = 0;
    for(j = 0; j < 4; j++) {
      if(s[i] == s[j]) count++;
    }
    if(count != 2) {
      isOK = false;
    }
  }

  if(isOK) {
  	cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
int max;

Node root,NIL;

/*Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  while( u != NIL && k != u ->key){
    if(k < u->key)u = u->left;
    else u = u->right;
  }
  return u;

}
/*
Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  int H;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if( y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}





void inorder( Node u){
  if( u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder( Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
 }


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  max = 0;
  /* for(i = 0; i < n; i++){
    scanf("%s",com);
    if( strcmp(com, "insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if( strcmp(com, "print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    }*/
   for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
   }

  return 0;
}



Measured memory_bytes: 25296
import math
a,b,c = map(int, input().split())
rad = math.radians(c)

S=0.5*a*b*math.sin(rad)
d=math.sqrt(a*a+b*b-2*a*b*math.cos(rad))
L=a+b+d
h=2*S/a
print('{:.8f}'.format(S))
print( '{:.8f}'.format(L))
print( '{:.8f}'.format(h))


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

int main() {
  string s; cin >> s;
  bool flag = true;

  if(s[0] != 'A') flag = false;
  if(count(s.begin()+2, s.end()-1, 'C') != 1) flag = false;
  int cnt;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] < 'a') cnt++;
  }
  if(cnt != 2) flag = false;

  cout << (flag ? "AC" : "WA") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#include<iostream>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=505;
const int dx[4]={0,-1,0,1};
const int dy[4]={-1,0,1,0};
int f[MAXN][MAXN],p[MAXN*MAXN],n;
int vis[MAXN][MAXN],tim;
bool a[MAXN][MAXN];
bool in(int x,int y){return x>=1&&x<=n&&y>=1&&y<=n;}
deque<pii> li;
void rollback(int x,int y)
{
	++tim;
	a[x][y]=0;li.push_front(mp(x,y));
	while(!li.empty())
	{
		pii T=li.front();li.pop_front();
		int u=T.first,v=T.second;
		if(vis[u][v]==tim)continue;vis[u][v]=tim;
		for(int k=0;k<4;k++)if(in(u+dx[k],v+dy[k]))
		{
			int p=u+dx[k],q=v+dy[k];
			if(f[p][q]>f[u][v]+a[u][v])
			{
				f[p][q]=f[u][v]+a[u][v];
				if(!a[u][v])li.push_front(mp(p,q));
				else li.push_back(mp(p,q));
			}
		}
	}
}
int main()
{
	#ifdef Rose
		double BeginJudgeTime=clock();
	#endif
	memset(a,true,sizeof(a));
	n=read();LL ans=0;
	for(int i=1;i<=n*n;i++)p[i]=read();
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
	{
		f[i][j]=i-1;chkmin(f[i][j],n-i);chkmin(f[i][j],j-1);chkmin(f[i][j],n-j);
	}
	for(int i=1;i<=n*n;i++)
	{
		int x=(p[i]-1)/n+1,y=(p[i]-1)%n+1;
		ans+=f[x][y];
		rollback(x,y);
	}
	pr2(ans);
	#ifdef Rose
		double EndJudgeTime=clock();
		cerr<<"JudgeTime is"<<" ";
		cerr<<(EndJudgeTime-BeginJudgeTime)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}


Measured memory_bytes: 7860
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
int a, b, c;

int main(void)
{
	cin>>a>>b>>c;
	if(a==b && b==c) cout<<1;
	else if(a==b || b==c || c==a) cout<<2;
	else cout<<3; return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int A, B;
	cin >> A >> B; A--; B--;
	cout << A * B << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 892
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    val S = (0 until x).map{readLine()!!.split(" ").map { it.toInt() }}
    val P =  (0 until y).map{readLine()!!.split(" ").map { it.toInt() }}
    var md = mutableListOf<Int>()
    var a = -1
    S.forEachIndexed{si,z ->
        md = emptyList<Int>().toMutableList()
        P.forEachIndexed {pi,zz ->
            md.add(Math.abs(S[si][0] - P[pi][0]) + Math.abs(S[si][1] - P[pi][1]))
        }
        a = md.min()!!
        println(md.indexOfFirst{ it == a} + 1)
    }
}

Measured memory_bytes: 36108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] map = new int[H][W];
        int N = sc.nextInt();
        int index_x = 0;
        int index_y = 0;
        int drc = 1;
        for(int i = 1; i <= N; i++){
            int temp = sc.nextInt();
            for(int j = 0; j < temp; j++){
                map[index_x][index_y] = i;
                index_x += drc;
                if(index_x < 0 || index_x > H-1){
                    drc *= -1;
                    index_y++;
                    index_x += drc;
                }
            }
        }
        sc.close();
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                System.out.print(map[i][j]+" ");
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 34400
#include<iostream>
void Insertionsort(int A[],int N)
{
	int v;
	int j;
	for(int i=0;i<=N-1;i++){
		v = A[i];
		j = i-1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(int k=0;k<=N-2;k++){
			std::cout << A[k] << " " ;
		}
		std::cout << A[N-1] << "\n";
	}
}
int main()
{
	int N;
	std::cin >> N;
	int A[N];
	for(int i=0;i<=N-1;i++){
		std::cin >> A[i];
	}
	Insertionsort(A,N);
	return 0;
}


Measured memory_bytes: 3088
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

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

  ll n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << endl;
  } else if (n == 1 || m == 1) {
    cout << max(n, m) - 2 << endl;
  } else {
    cout << n * m - 2 * n - 2 * m + 4 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
var mod = 1e9+7;

console.log(main());
function main(){
  var n = o.a();
  var c = o.r(n);
  var a = Array(2e5).fill(0).map(a=>[]);
  for(var i = 0; i < n; i++){
    a[c[i]-1].push(i);
  }
  for(var i = 0; i < 2e5; i++){
    a[i].reverse();
    a[i].pop();
  }
  var dp = Array(n).fill(0);
  dp[0] = 1;
  var t = a[c[0]-1].pop();
  if(t > 1)dp[t] = 1;
  for(i = 1; i < n; i++){
    dp[i] += dp[i-1];
    dp[i] %= mod;
    t = a[c[i]-1].pop();
    if(t > i+1)dp[t] = dp[i];
  }
  return dp[n-1];
}

Measured memory_bytes: 83020
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
  int A, B;
  cin >> A >> B;

  if (A < 10 && B < 10) cout << A * B << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
    int a; cin >> a;
    int ans = a + (a * a) + (a * a * a);
    cout << ans <<"\n";
  }
}



Measured memory_bytes: 3636
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let mut coord = Vec::with_capacity(n);
	for i in 0..n {
		let x: i64 = s.next().unwrap().parse().unwrap();
		let y: i64 = s.next().unwrap().parse().unwrap();
		coord.push((x, y, i as u32));
	}
	let mut graph = Graph::new(n);
	coord.sort_by_key(|a| a.0);
	for w in coord.windows(2) {
		let a = w[0];
		let b = w[1];
		let d = b.0 - a.0;
		graph.add_edge(a.2 as usize, b.2 as usize, d);
		graph.add_edge(b.2 as usize, a.2 as usize, d);
	}
	coord.sort_by_key(|a| a.1);
	for w in coord.windows(2) {
		let a = w[0];
		let b = w[1];
		let d = b.1 - a.1;
		graph.add_edge(a.2 as usize, b.2 as usize, d);
		graph.add_edge(b.2 as usize, a.2 as usize, d);
	}
	println!("{}", graph.kruskal());
}

pub mod mst {
	use super::*;

	impl<T> Graph<T>
	where
		T: Clone + Ord + num::Zero,
	{
		pub fn kruskal(&self) -> T {
			let mut r = T::zero();
			let mut edges = vec![];
			for i in 0..self.size() {
				for e in self.edges[i].iter() {
					edges.push((e.cost.clone(), i as u32, e.dst));
				}
			}
			edges.sort_by_key(|a| a.0.clone());
			let mut uf = super::UnionFind::new(self.size());
			for (cost, src, dst) in edges {
				if uf.unite(src as usize, dst as usize) {
					r = r + cost;
				}
			}
			r
		}
	}
}

#[derive(Clone, Copy)]
pub struct Edge<T> {
	dst: u32,
	cost: T,
}

impl<T> Edge<T> {
	pub fn new(dst: u32, cost: T) -> Self {
		Self { dst, cost }
	}
}

pub struct Graph<T> {
	edges: Vec<Vec<Edge<T>>>,
}

impl<T> Graph<T>
where
	T: Clone,
{
	pub fn new(n: usize) -> Self {
		Self {
			edges: vec![vec![]; n],
		}
	}

	pub fn size(&self) -> usize {
		self.edges.len()
	}

	pub fn add_edge(&mut self, src: usize, dst: usize, cost: T) {
		self.edges[src].push(Edge {
			dst: dst as u32,
			cost,
		});
	}
}

pub struct UnionFind {
	data: Vec<i32>,
}

impl UnionFind {
	pub fn new(n: usize) -> UnionFind {
		UnionFind { data: vec![-1; n] }
	}

	pub fn unite(&mut self, x: usize, y: usize) -> bool {
		let x = self.find(x);
		let y = self.find(y);
		if x == y {
			false
		} else {
			let (x, y) = if self.data[x] > self.data[y] {
				(y, x)
			} else {
				(x, y)
			};
			self.data[x] += self.data[y];
			self.data[y] = x as i32;
			true
		}
	}

	pub fn find(&mut self, i: usize) -> usize {
		if self.data[i] < 0 {
			i
		} else {
			let p = self.data[i] as usize;
			self.data[i] = self.find(p) as i32;
			self.data[i] as usize
		}
	}

	pub fn size(&mut self, i: usize) -> usize {
		let i = self.find(i);
		(-self.data[i]) as usize
	}
}


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

int main(void){
  string A, B;
  cin >> A >> B;
  if(A.length() != B.length()){
    if(A.length() > B.length()) cout << "GREATER" << endl;
  	else if (A.length() < B.length()) cout << "LESS" << endl;
  }
  else if(A == B) cout << "EQUAL" << endl;
  else{
   for(int i = 0; i < A.length(); i++){
    if(A[i] > B[i]){
      cout << "GREATER" << endl;
      break;
    }
    else if(A[i] < B[i]){
      cout << "LESS" << endl;
      break;
    }
   }
   
    
  }  
}

Measured memory_bytes: 256
# Aizu Problem 0112: A Milk Shop

#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    N = int(input())
    if N == 0:
        break
    waits = sorted([int(input()) for _ in range(N)])
    latence = 0
    for k in range(N - 1):
        latence += waits[k] * (N - 1 - k)
    print(latence)

Measured memory_bytes: 7964
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    char S[100];
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }

    S[K-1] = S[K-1] + 0x20;

    for (int j = 0; j < N; j++){
        cout << S[j]; 
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fastio        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll            long long
#define fl            long double
#define pll           pair<ll,ll>
#define onebits(x)    __builtin_popcountll(x)
#define fbo(x)        find_by_order(x)
#define ook(x)        order_of_key(x)
#define pb            push_back
#define mk            make_pair
#define endl          "\n"
#define ff            first
#define ss            second
#define mt            make_tuple
#define np            next_permutation
#define pi            3.141592653589793238
#define deb(x)        cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define vll           vector<ll>
#define vp            vector<pair<ll,ll>>
#define all(x)        x.begin(),x.end()
#define rall(x)       x.rbegin(),x.rend()
#define revpq         priority_queue <int, vector<int>, greater<int>>
#define pq            priority_queue<ll>
#define ps(x,y)       fixed<<setprecision(y)<<x
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll MAXN = 200005;
ll power(ll a, ll b) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod % mod; a = a * a % mod;} return res;}

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
    fastio;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll i, j, t, k, l, r, tp, n, m;
    string s;
    cin >> s;
    ll ss = 0;
    for (i = 0; i < s.size(); i++)
    {
        ss += (s[i] - '0');
    }
    if (ss % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

struct fenwick_tree {
  int n;
  vector<ll> data;

  fenwick_tree() {
    init(0);
  }

  fenwick_tree(int s) {
    init(s);
  }

  fenwick_tree(vector<ll> &v) {
    int s = v.size();
    init(s);
    for (int i = 0; i < s; i++) add(i, v[i]);
  }

  void init(int s) {
    n = s;
    data = vector<ll>(s);
  }

  void add(int p, ll v) {
    p++;
    while (p <= n) {
      data[p-1] += v;
      p += p & -p;
    }
  }

  ll sum(int l, int r) {
    return sum(r) - sum(l);
  }

  ll sum(int r) {
    ll s = 0;
    while (r > 0) {
      s += data[r-1];
      r -= r & -r;
    }
    return s;
  }
};

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

  int n, q;
  cin >> n >> q;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;
  vector<vector<int> > query(q, vector<int>(3));
  for (auto &x: query) cin >> x[0] >> x[1] >> x[2];

  fenwick_tree ft(a);

  vector<ll> ans;
  for (int i = 0; i < q; i++) {
    if      (query[i][0] == 0) ft.add(query[i][1], query[i][2]);
    else if (query[i][0] == 1) ans.push_back(ft.sum(query[i][1], query[i][2]));
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 41648
S = list(input())
for x in range(len(S) - 2):
  if len(S) % 2 != 0 or x == 0:
    S.pop(-1)
    continue
  i = len(S) // 2
  if S[:i] * 2 == S:
    break
  else: S.pop(-1)
print(len(S))

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static long[] list=new long[87];

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

   String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();
 
   String[] s=sc.nextLine().split(" ");
   //  String[] e=sc.nextLine().split(" ");

int num[]=new int[s.length];

int N=Integer.parseInt(nyuA);

//int Y=Integer.parseInt(e[1]);
//int Z=Integer.parseInt(e[2]);

for(int i=0;i<num.length;i++){
num[i]=Integer.parseInt(s[i]);
}
int count=0;
oun:
while(true){
for(int i=0;i<num.length;i++){
if(num[i]%2==0){num[i]/=2;}else{break oun;}
}
count++;
}


System.out.println(count);


}

}



Measured memory_bytes: 22356
h, w, m = map(int, input().split())
boms = set()
Hs = [0] * h
Ws = [0] * w
for i in range(m):
  _h, _w = map(int, input().split())
  boms.add((_h - 1, _w - 1))
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1
Hmax = max(Hs)
Hcount = Hs.count(Hmax)
Wmax = max(Ws)
Wcount = Ws.count(Wmax)
Hindexs = [0] * Hcount
Windexs = [0] * Wcount
hcount = 0
wcount = 0
for i in range(h):
  if Hs[i] == Hmax:
    Hindexs[hcount] = i
    hcount += 1
for i in range(w):
  if Ws[i] == Wmax:
    Windexs[wcount] = i
    wcount += 1
if m < len(Hindexs) * len(Windexs):
  print(Hmax + Wmax)
  exit()
for hindex in Hindexs:
  for windex in Windexs:
    if (hindex,windex) not in boms: 
      print(Hmax + Wmax)
      exit()
print(Hmax + Wmax -1)

Measured memory_bytes: 137124
#include<stdio.h>

int prime(int x){
    int i;

    if(x==1) return 0;
    if(x==2) return 1;
    if(x!=2&&x%2==0) return 0;

    for(i=3;i*i<=x;i+=2){
        if(x%i==0) return 0;
    }
    return 1;
}

int main(){
    int i,n,r,count=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&r);
        if(prime(r))count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int a, b;
    cin >> a >> b;
    int m_ab = min(a, b);
    int M_ab = max(a, b);

    string s = "";
    rep(i, M_ab){
        s += (char)(m_ab + '0');
    }

    cout << s << endl;
}



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

using namespace std;
using ll = long long;
using P = pair <int, int>;


int main() {
  int r;
  cin >> r ;
  
  cout << r*r<<endl;
  
  return 0;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
string str,ans="",ans2="";
map < string,int > tab;
int main(){
  while(cin>>str){
    if(str.size()>ans2.size())ans2=str;
    tab[str]++;
    if(tab[ans]<tab[str])ans=str;
  }
  cout<<ans<<' '<<ans2<<endl;
  return 0;
}

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

using namespace std;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)

int dp[300][300], W[300];

int main() {
  while (true) {
    int N; scanf("%d", &N);
    if (not N) break;
    REP(i, N) scanf("%d", W + i);
    memset(dp, 0, sizeof(dp));
    FOR(w, 2, N + 1) REP(left, N - w + 1) {
      // [left, right]
      int right = left + w - 1;
      if (dp[left + 1][right - 1] == w - 2 and abs(W[left] - W[right]) <= 1) {
        dp[left][right] = w;
      } else {
        FOR(mid, left, right) {
          dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid + 1][right]);
        }
      }
    }
    printf("%d\n", dp[0][N - 1]);
  }

  return 0;
}

Measured memory_bytes: 3544
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define            bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int a , b , n;


void go()
{
       cin >> n;

       fo(i,0,3985)
       {
              for(int j = i; j >= -3985; j--)
              {
                     int a = i , b = j;

                     fo(k,0,4)
                     {
                            b = b*j;
                            a = a*i;
                     }

                     int diff = ( a - b );

                     if( diff == n ) 
                     {
                         cout << i << ' '  << j << endl;
                         return;
                     }
              }
       }
}


int32_t main()
{
     FAST;     
     int t=1; 
     // cin>>t;
     test(t) go();
}



Measured memory_bytes: 3648
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split())) + [0]
    
    B = []
    left, right = 0, 1
    while right != N + 2:
        if A[left:right] == list(sorted(A[left:right])):
            right += 1
        else:
            B.append(A[left:right - 1])
            left = right - 1
    
    score = 1000
    for a_lr in B:
        if len(a_lr) == 1:
            continue
        stock, score = divmod(score, a_lr[0])
        score += stock * a_lr[-1]
    print(score)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62348
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    unordered_map<string, int> mp;
    int n; cin >> n;
    FOR(i,1,n) {
        string s; cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3680
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0;
        int data[] = new int[10001];
        while(true){
            int n = sc.nextInt();
            data[i] = n;
            if(n == 0)break;
            i++;
            sc.nextLine();
        }

        for(i = 0; data[i] != 0; i++){
            System.out.print("Case "+(i+1)+": "+data[i]+"\n");
        }
        //System.out.println();
    }
}


Measured memory_bytes: 68768
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e2+5, M=2e4+5, oo=0x3f3f3f3f;

int main()
{
    string s;
    cin >> s;
    if(s[0] == 'R')
        cout << "Sunny";
    else if(s[0] == 'S')
        cout << "Cloudy";
    else
        cout << "Rainy";
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    string s,t; cin >> s >> t;
    ve_vei c1(26), c2(26);

    rep(i,s.size()) {
        c1.at( s.at(i) - 'a' ).pub(i);
        c2.at( t.at(i) - 'a' ).pub(i);
    }
    sort(all(c1)); sort(all(c2));

    rep(i,26) {
        rep( j, min( c1[i].size(), c2[i].size() ) ) {
            if( c1[i][j] != c2[i][j] ) {cout << "No" << endl; return 0;}
        }
    }
    cout << "Yes" << endl;
    return 0;

}



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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  set<int> s;
  int n; cin >> n;
  for(int i = 0; i < n; ++i) {
    int x; cin >> x;
    if(s.count(x)) {
      cout << "NO\n";
      return 0;
    }
    s.insert(x);
  }
  cout << "YES\n";
  return 0;
}


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

int N, a, qwq, now, ans;

int main(){
    scanf("%d", &N);
    for(int i=1; i<=N; i++){
        scanf("%d", &qwq);
        a=log2(qwq);
        if((1<<a)<qwq){
            if(now>a)   now=a;
            else        a++;

        }
        if(a>now)   ans+=a-now, now=a;
        if(a<now)   now=a;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 384