akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

void inorder(Node);
void preorder(Node);
void insert(int);
void find(int,Node);

Node root;
int f;

int main(){
  int n, i, x;
  char com[20];
  
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    if(com[0] == 'f'){
      scanf("%d",&x);
      f = 0;
      find(x,root);
      if(f == 1) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  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){ // T が空の場合
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }// z を y の左の子にする
  else{
    y->right = z;
  }// z を y の右の子にする
}

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

  if(u->right != NIL) inorder(u->right);
}

void preorder(Node u){
  printf(" %d",u->key);

  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}

void find(int k, Node n){
  if(n->key == k) f++;
  
  if(n->left != NIL && f == 0) find(k, n->left);

  if(n->right != NIL && f == 0) find(k,n->right);
}


Measured memory_bytes: 25152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int f(string a,string b){
    set<char> p,q;
    REP(i,a.size()){
        p.insert(a[i]);
    }
    REP(i,b.size()){
        if(p.count(b[i])){
            q.insert(b[i]);
        }
    }
    return q.size();
}
int main(){
    int n;
    cin>>n;
    string st;
    cin>>st;
    int ans=0;
    FOR(i,1,n){
        string a=st.substr(0,i);
        string b=st.substr(i,n-i);
        chmax(ans,f(a,b));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	ints := []int{a, b, c}
	sort.Ints(ints)
	if ints[0]+ints[1] == ints[2] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
K = int(input())
a = []
def dfs(x):
    if x > 3234566667:
        return
    a.append(x)
    for i in range(10):
        if abs(x%10-i) <= 1:
            dfs(x*10+i)

for i in range(1,10):
    dfs(i)
a = sorted(a)
print(a[K-1])

Measured memory_bytes: 8512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n;
    cin >> n;
    vector<ll> a(n + 1), b(n + 1);
    a[0] = 0;
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        a[i + 1] = a[i] + tmp;
    }
    b[0] = 0;
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        b[i + 1] = b[i] + tmp;
    }
    ll sum = 0;
    rep(i, n) { sum = max(sum, a[i + 1] + (b[n] - b[i])); }
    cout << sum << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    REP(i, 0, N){
        cin >> C[i];
        REP(j, 0, M){
            cin >> A[i][j];
        }
    }

    int min_cost = 1e8;
    REP(bit, 0, (1<<N)){
        int cost = 0;
        vector<int> skill(M);

        REP(i, 0, N){
            if (bit & (1<<i)){
                cost += C[i];
                REP(j, 0, M){
                    skill[j] += A[i][j];
                }
            }
        }

        bool skill_ok_flag = true;
        for (auto s: skill){
            if (s < X){
                skill_ok_flag = false;
                break;
            }
        }
        if (skill_ok_flag){
            chmin(min_cost, cost);
        }
    }

    if (min_cost == 1e8){
        cout << -1 << endl;
    } else{
        cout << min_cost << endl;
    }


    return 0;
}


Measured memory_bytes: 3644
if __name__ == '__main__':

	DI = [[0 for _ in range(10)] for _ in range(10)]

	while True:
		try:
			x,y,s = map(int,input().split(","))
			if s == 0:
				break
			if s == 1:
				#自身
				DI[x][y] += 1
				#up
				if y >= 1 :
					DI[x][y-1] += 1
				#down
				if y <= 8:
					DI[x][y+1] += 1
				#left
				if x >= 1:
					DI[x-1][y] += 1
				#right
				if x <= 8:
					DI[x+1][y] += 1

			elif s == 2:
				#自身
				DI[x][y] += 1
				#up
				if y >= 1 :
					DI[x][y-1] += 1
				#up left
				if x >= 1 and y >= 1:
					DI[x-1][y-1] += 1
				#up right
				if x <= 8 and y >= 1 :
					DI[x+1][y-1] += 1
				#down
				if y <= 8:
					DI[x][y+1] += 1
				#down left
				if x >= 1 and y <= 8:
					DI[x-1][y+1] += 1
				#down right
				if x <= 8 and y <= 8 :
					DI[x+1][y+1] += 1
				#left
				if x >= 1:
					DI[x-1][y] += 1
				#right
				if x <= 8:
					DI[x+1][y] += 1

			else:
				#自身
				DI[x][y] += 1
				#up
				if y >= 1 :
					DI[x][y-1] += 1
				#up left
				if x >= 1 and y >= 1:
					DI[x-1][y-1] += 1
				#up right
				if x <= 8 and y >= 1 :
					DI[x+1][y-1] += 1
				#up +1
				if y >= 2 :
					DI[x][y-2] += 1
				#down
				if y <= 8:
					DI[x][y+1] += 1
				#down left
				if x >= 1 and y <= 8:
					DI[x-1][y+1] += 1
				#down right
				if x <= 8 and y <= 8 :
					DI[x+1][y+1] += 1
				#down + 1
				if y <= 7:
					DI[x][y+2] += 1
				#left
				if x >= 1:
					DI[x-1][y] += 1
				#left + 1
				if x >= 2:
					DI[x-2][y] += 1
				#right
				if x <= 8:
					DI[x+1][y] += 1
				#right + 1
				if x <= 7:
					DI[x+2][y] += 1



		except EOFError:
			break

#	for j in DI:
#		print(j)

	cnt = 0
	maxcnt = 0
	for k in DI:
		cnt += k.count(0)
		if maxcnt < max(k):
			maxcnt = max(k)
	print(cnt)
	print(maxcnt)




Measured memory_bytes: 5616
#include <bits/stdc++.h>
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++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

//---------------------------

int main(){
    string s;
    cin >> s;
    ll ans = 0;
    int n = s.size();
    
    rep(bit,1<<(n-1)){
        ll add = s[0] - '0';
        rep(i,n-1){
            if(bit & (1 << i)){
                ans += add;
                add = s[i+1] - '0';
            }else{
                add = 10 * add + (s[i+1] - '0');
            }
        }
        ans += add;
    }

    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

class Cake {
  public:
  i64 sum, a, b, c;
  bool operator<(const Cake &that) const {
    #define cmp(a) if (a != that.a) return a < that.a;
      cmp(sum) cmp(a) cmp(b) cmp(c)
    #undef cmp
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i32 x, y, z, k;
  cin >> x >> y >> z >> k;
  vi64 a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(all(a), greater<i64>());
  sort(all(b), greater<i64>());
  sort(all(c), greater<i64>());
  priority_queue<Cake> que;
  set<Cake> s;
  que.push({a[0] + b[0] + c[0], 0, 0, 0});
  rep(_, k) {
    auto q = que.top();
    que.pop();
    cout << q.sum << endl;
    if (q.a < x - 1) {
      Cake d = {a[q.a + 1] + b[q.b] + c[q.c], q.a + 1, q.b, q.c};
      if (s.find(d) == s.end()) { que.push(d); s.insert(d); }
    }
    if (q.b < y - 1) {
      Cake d = {a[q.a] + b[q.b + 1] + c[q.c], q.a, q.b + 1, q.c};
      if (s.find(d) == s.end()) { que.push(d); s.insert(d); }
    }
    if (q.c < z - 1) {
      Cake d = {a[q.a] + b[q.b] + c[q.c + 1], q.a, q.b, q.c + 1};
      if (s.find(d) == s.end()) { que.push(d); s.insert(d); }
    }
  }
  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
 
int main(){
  string s;
  cin >> s;
 
  int n = s.size();
  if(s[0] == 'o' && s[n-1] == 'o'){
    int a=0, b=0;
    for(int i=0;i<n;i++){
      if(s[i] == 'o')a++;
      else b++;
    }
    if(a>b)cout << 'o' << endl;
    else cout << 'x' << endl;
  }else{
    if(s[0] == s[n-1])cout << 'x' << endl;
    else cout << 'o' << endl;
  }
}

Measured memory_bytes: 0
MOD = 10**9 + 7

def factorial(num)
  (1..num).inject (1){ |sum, x| (x*sum) % MOD }
end

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




if (n - m).abs >= 2
  p 0
elsif (n-m).abs == 1
  p factorial(n)*factorial(m) % MOD
else
  p 2*factorial(n)*factorial(m) % MOD
end



Measured memory_bytes: 1788
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{

	int N,i;
	cin>>N;
	vector<LL> H(N);
	for (i=0;i<N;i++){
		cin>>H[i];
	}
	if (N==1){
		cout<<"Yes"<<endl;
		return 0;
	}
	for (i=N-1;i>0;i--){
		if (H[i]>=H[i-1]){
			continue;
		}else{
			if (H[i-1]-H[i]==1){
				H[i-1]--;
				continue;
			}else{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static List<string> cons = new List<string>();
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            double[] elm = new double[n];
            for (int i=0; i<n; i++)
            {
                elm[i] = double.Parse(str[i]);
            }

            double result = 0.0;
            for (int i = 0; i < n; i++)
            {
                result += 1 / elm[i];
            }
            Console.WriteLine(1 / result);
        }
    }
}

Measured memory_bytes: 11220
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1e5 + 5;

int a[maxn][4];
int dp[maxn][4];//d[i][j] i day choose j thing 's max happy

int main(){
	int n;scanf("%d",&n);
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= 3 ; j++){
			scanf("%d",&a[i][j]);
		}
	}

	memset(dp, 0, sizeof dp);

	for(int i = 1 ; i <= 3 ; i++) dp[1][i] = a[1][i];

	for(int i = 2 ; i <= n ; i++){
		dp[i][1] = max(dp[i - 1][2] ,dp[i - 1][3]) + a[i][1];
		dp[i][2] = max(dp[i - 1][1] ,dp[i - 1][3]) + a[i][2];
		dp[i][3] = max(dp[i - 1][2] ,dp[i - 1][1]) + a[i][3];
	}

	int ans = 0;
	for(int i = 1 ; i <= 3 ; i++)ans = max(dp[n][i],ans);
	printf("%d\n",ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans=0;
  bool f = (s[0] == '0');

  for (int i=1; i<n; i++) {
    if (f) {
      if (s[i] == '0') ans++;
    } else {
      if (s[i] == '1') ans++;
    }
    f = !f;
  }

  cout << ans << endl;
}

Measured memory_bytes: 888
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n;
	cin>>n;
	n++;
	ll i = 1;
	while(i<=n) i<<=1;
	i >>= 2;
	vector<int> res1, res2;
	//r.push_back(1);
	//r.push_back(1);
	int c = 1;
	while(i){
		if(true){
			res1.push_back(c);
			res2.push_back(c);
			c++;
		}
		if(n&i){
			res1.push_back(c);
			res2.insert(res2.begin(), c);
			c++;
		}
		i>>=1;

	}
	res1.insert(res1.end(), res2.begin(), res2.end());
	cout<<res1.size()<<endl;
	for(auto x: res1) cout<<x<<" "; cout<<endl;
	return 0;
}


Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/problems/1193
def delete(M):
    point = 0
    for row in M:
        for l in range(len(row)-1):
            for r in range(l + 1, len(row)):
                if row[l] != row[r]:
                    break
            if r - l >= 3:
                point += (r - l) * row[l]
                for i in range(l, r):
                    row[i] = 0
                break

    return point


def drop(M):
    for c in range(5):
        nums = []
        for i in range(len(M)-1, -1, -1):
            if M[i][c] != 0:
                nums.append(M[i][c])
            M[i][c] = 0

        for i in range(len(nums)):
            M[len(M)-1-i][c] = nums[i]


def solve(h, M):
    result = 0
    while True:
        point = delete(M)
        if point == 0:
            break
        result += point
        # print('-------')
        # for row in M:
        #     print(*row)
        # print('--drop-----')
        drop(M)
        # for row in M:
        # print(*row)
        # print('-------')
    print(result)


if __name__ == "__main__":
    while True:
        h = int(input())
        if h == 0:
            break
        M = [list(map(int, input().split())) + [0] for _ in range(h)]
        solve(h, M)



Measured memory_bytes: 5628
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define LL long long



int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((abs(a - c) <= d) || (abs(a - b) <= d && abs(b - c) <= d))
		cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
input_array = input().split()
result = []
while (len(input_array) >=3 and input_array[1] != '?'):
    op = input_array[1]
    a = int(input_array[0])
    b = int(input_array[2])
    if (op == '+'):
        result.append(a + b) 
    elif (op == '-'):
        result.append(a - b) 
    elif (op == '*'):
        result.append(a * b)
    else:
        result.append(a // b) 
    input_array = input().split()

for i in result:
    print(i)


Measured memory_bytes: 5600
import sys
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
a = LI()
dp = [0 for _ in range(K+1)]

for i in range(K,-1,-1):
    if dp[i]: continue
    for x in a:
        if i-x >= 0: dp[i-x] = 1
if dp[0] == 1:
    print('First')
else:
    print('Second')

Measured memory_bytes: 44912
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    for(int i=1;i<=B;i++){
        if((A*i)%B==C){
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}


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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> H(N, 0);
	rep (i, N){
		cin >> H[i];
	} // end rep

	int res = 1, currH = H[0];
	for (int i = 1; i < N; ++i){
		if (currH <= H[i]){
			++res;
			currH = H[i];
		} // end if
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N,M,A[100000+10]={};
pair<int,int> Q[100000+10];

signed main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<M;i++){
    cin >> Q[i].second >> Q[i].first;
  }
  sort(Q,Q+M);
  reverse(Q,Q+M);
  sort(A,A+N);
  //  for(int i=0;i<N;i++){

  int k=0,i;
  for(int j=0;j<M;j++){
    if(k>=N) break;
    //if(A[k]>Q[j].first) break;
    for(i=k;i<k+Q[j].second;i++){
      if(A[i]>Q[j].first) break;
      if(i>=N) break;
      A[i]=Q[j].first;
    }
    k=i;
  }
  //  }
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    VI s(N);

    LL ans = 0;

    REP(i,N)
    {
        cin >> s[i];
        ans += s[i];
    }
    sort(s.begin(), s.end());
    if(ans % 10 != 0) 
    {
        cout << ans << endl;
        return 0;
    }

    for(auto p : s)
    {
        if(p % 10 != 0)
        {
            cout << ans - p << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
# coding: utf-8
from collections import defaultdict
import sys

H, W = (int(x) for x in input().split())

freq = defaultdict(int)

for i in range(H):
    for c in input():
        freq[c] += 1

nDiv4 = 0
nDiv2 = 0
nDiv1 = 0
for c in freq:
    num = freq[c]

    d4 = num // 4
    nDiv4 += d4
    num -= d4 * 4

    d2 = num // 2
    nDiv2 += d2
    num -= d2 * 2

    nDiv1 += num 

canDiv2 = 0
if H % 2 != 0:
    canDiv2 += W // 2
if W % 2 != 0:
    canDiv2 += H // 2

if H % 2 != 0 and W % 2 != 0:
    if nDiv1 != 1:
        print("No")
        sys.exit(0)
else:
    if nDiv1 != 0:
        print("No")
        sys.exit(0)

if nDiv2 <= canDiv2:
    print("Yes")
else:
    print("No")

#print(nDiv1, nDiv2, nDiv4)
#print(nDiv2, canDiv2)

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

#define fi first
#define se second

const int N = 110;
const long long mod = 1e9 + 7;

using namespace std;

int k;
int d[N];
int f[N];

int add(int x, int y)
{
        x += y;
        if(x >= mod){
                x -= mod;
        }
        return x;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        string s;
        cin >> s >> k;
        for(int i = 0; i < s.size(); i++){
                s[i] -= '0';
        }
        for(int i = 0; i < s[0]; i++){
                d[i % k] = add(d[i % k], 1);
        }
        int eq = s[0] % k;
        for(int i = 1; i < s.size(); i++){
                for(int j = 0; j < k; j++){
                        for(int h = 0; h < 10; h++){
                                int nj = (j + h) % k;
                                f[nj] = add(f[nj], d[j]);
                        }
                }
                for(int h = 0; h < s[i]; h++){
                        int nj = (eq + h) % k;
                        f[nj] = add(f[nj], 1);
                }
                for(int j = 0; j < k; j++){
                        d[j] = f[j];
                        f[j] = 0;
                }
                eq = (eq + s[i]) % k;
        }
        int res = (eq == 0);
        res = add(res, d[0]);
        res -= 1;
        if(res < 0){
                res += mod;
        }
        cout << res << "\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	string s;
	cin >> s;
	ll k;
	cin >> k;

	string s2 = s + s;

	ll counter = 0;
	if (k == 1) {
		rep(i, s.length() - 1) {
			if (s[i] == s[i + 1]) {
				++counter;
				s[i + 1] = '!';
				++i;
			}
		}
	}
	else {
		ll counter1 = 0;
		rep(i, s.length() - 1) {
			if (s[i] == s[i + 1]) {
				++counter1;
				s[i + 1] = '!';
				++i;
			}
		}

		rep(i, s2.length() - 1) {
			if (s2[i] == s2[i + 1]) {
				++counter;
				s2[i + 1] = '!';
				++i;
			}
		}

		if (s2[s2.length() - 1] != '!' && s2[s2.length()-1] == s2[0]) {
			counter += (counter - counter1)*(k - 2);
		}
		else{
			counter *= k / 2;
			if (k & 1) {
				counter += counter1;
			}
		}
	}

	cout << counter << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long x; cin >> x;
  for(long long a = -1000; a <= 1000; a++) {
    for(long long b = -1000; b <= 1000; b++) {
      if(a * a * a * a * a - b * b * b * b * b == x) {
        cout << a << ' ' << b << '\n';
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3608
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int x;
int main(){
    I(x);
    x /= 100;
    printf("ai1333");
    REP(i,x) printf("3");
    printf("\n");

}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll n,k; cin>>n>>k;
	ll ans=0;
	while(n){
		ans++;
		n/=k;
	}
	cout<<ans;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
    	solve();
    }
}

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

int n, a, mx, mn = 105, cnt[105];
int main()
{
	int i;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a);
		cnt[a]++;
		mx = max(mx, a);
		mn = min(mn, a);
	}
	if (mn == (mx + 1) / 2 && (mx % 2 == 0 && cnt[mn] == 1 || mx % 2 == 1 && cnt[mn] == 2)) {
		for (i= mn + 1; i <= mx; i++) {
			if (cnt[i] < 2) break;
		}
		if (i > mx)cout << "Possible";
		else cout << "Impossible";
	} else {
		cout << "Impossible";
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main(void) {
  char c;
  cin >> c;
  c = c + 1;
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int linerSearch(int A[], int n, int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)
    i++;
  return i;
}

int main(){
  int i=0, n, A[10000], q, key, sum=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if((linerSearch(A,n,key))!=n)
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int h, w;cin>>h>>w;
  for(int i=0;i<h;i++){
  	for(int j=0;j<w;j++){
      string s;cin>>s;
      if(s=="snuke")cout<<char('A'+j)<<i+1<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, A[maxn];
vector<pii>v;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> A[i];
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v.pb({b, a});
    }
    sort(all(v), greater<pii>());
    sort(A, A + n);
    int cur = 0;
    for(pii &p : v)
    {
        while(cur < n && p.y > 0 && p.x > A[cur])
        {
            A[cur] = p.x;
            ++cur;
            --p.y;
        }
    }
    ll sum = 0;
    for(int i = 0; i < n; i++)
        sum += A[i];
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
    int a, b, c, i, count;
    cin >> a >> b >> c;
    count = 0;
    for (i = 0; i <= c; i++) {
        if (i == 0){
            continue;
        }
        if (c % i == 0 and i >= a and i <= b) {
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


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


const int MAX_N = 100010;
bool ok[200010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<P>tmp;
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		tmp.push_back(make_pair(a, b));
	}
	sort(ALL(tmp));
	rep(i, m) {
		if (tmp[i].first == 0) {
			ok[tmp[i].second] = true;
		}
		if (ok[tmp[i].first]) {
			if (tmp[i].second == n - 1) {
				cout << "POSSIBLE" << endl; return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 6000
import math
S = int(input())
L = 10**9

def search():
    p = int(math.sqrt(S))
    q = p
    i = 0
    while p*q < S:
        if i % 2 == 0 or q == L: p += 1
        if i % 2 == 1 or p == L: q += 1
        i += 1
    assert p <= L and q <= L
    target = p*q - S
    divisor = 1
    #assert target < L
    return (0, 0, p, divisor, target, q)

print(*search())

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

int main() {
    int N; cin>>N;
    vector<int>odd(100001,0);
    vector<int>even(100001,0);
    int od=0,ev=0;
    rep(i,N){
        int t; cin>>t;
        if(i%2==0){
            odd[t]++;
            if(odd[t]>odd[od])od=t;
        }
        else {
            even[t]++;
            if(even[t]>even[ev])ev=t;
        }
    }
    sort(odd.begin(),odd.end());
    reverse(odd.begin(),odd.end());
    sort(even.begin(),even.end());
    reverse(even.begin(),even.end());
    if(od==ev){
        cout<<N-max(even[0]+odd[1],even[1]+odd[0])<<endl;
    }
    else cout<<N-even[0]-odd[0]<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#define LL long long
#define  INF 0x7fffffff;
using namespace std;
const int maxn=500010;
int a[maxn];
int L[maxn/2+2],R[maxn/2+2];
int n;
LL merge(int left,int mid ,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)L[i]=a[left+i];
	for(int i=0;i<n2;i++)R[i]=a[mid+i];
	int i=0,j=0;
	L[n1]=R[n2]=INF;
	LL s=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j])
			a[k]=L[i++];
		else{
			a[k]=R[j++];
			s+=n1-i;
		}
	}
	return s;
}
LL mergesort(int left,int right ){//[left,right)
	LL c1,c2,c3;
	if(left+1<right){//避免死循? 
		int mid=(left+right)/2;
		c1=mergesort(left,mid);
		c2=mergesort(mid,right);
		c3=merge(left,mid,right);
		return c1+c2+c3;
	}
	else 
		return 0;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	cout<<mergesort(0,n)<<endl;
	return 0;
}

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

int N;
int A[210];

int main()
{
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    int res = 0;
    while (true)
    {
        bool end_flag = false;
        for (int i = 0; i < N; ++i)
            if (A[i] % 2)
            {
                end_flag = true;
            }
            else
            {
                A[i] /= 2;
            }
        if (end_flag)
            break;
        ++res;
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long
using namespace std;

int ans = 0;
void dfs(ll x, int a, int b, int c, int n){
    if(a == 1 && b == 1 && c == 1 && x <= n)
        ans++;
    if(x <= n){
        dfs(x*10+3, 1, b, c, n);
        dfs(x*10+5, a, 1, c, n);
        dfs(x*10+7, a, b, 1, n);
    }
    if(x > n)
       return;
}

int main(void){
    ll n; cin >> n;
    int count;
    dfs(0,0,0,0,n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> ff(n),ss(n);
   int c1,c2;
   f(i,0,n){
      cin >> ff[i];
   }
   f(i,0,n){
      cin >> ss[i];
   }
   vector<int> a;
   f(i,1,n+1){
      a.pb(i);
   }
   int c = 0;
   do{
      c++;
      if(a == ff){
         c1 = c;
      }
      if(a == ss){
         c2 = c;
      }
   }while(next_permutation(all(a)));
   cout << abs(c1-c2) << '\n';
   return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  print(100)
  exit()
old_diff = 10000
for i in range(-110, 110):
  if i in p:
    continue
  else:
    diff = abs(x-i)
    if diff < old_diff:
      ans = i
      old_diff = abs(x-i)

try:
  print(ans)
except:
  print()


Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  string ans="NO";
  for(int i=1;i<B+3;i++){
    if(A*i%B==C){
      ans="YES";
    }
  }

  cout<< ans <<endl;
}


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

using Lint=long long;

template<typename T> class SegmentTree
{
 public:
    using Func=function<T(T,T)>;
    int sz;
    vector<T> data;
    Func func;
    T e;

    SegmentTree(int n,Func func,T e):func(func),e(e){
        sz=1;
        while(sz<n) sz*=2;
        data.assign(2*sz-1,e);
    }
    void update(int k,T x){
        k+=sz-1; data[k]=x;
        while(k>0){
            k=(k-1)/2;
            data[k]=func(data[2*k+1],data[2*k+2]);
        }
    }
    T get(int l,int r){
        // [l,r)
        T resL=e,resR=e;
        for(l+=sz-1,r+=sz-1;l<r;l/=2,r/=2){
            if((l&1)==0) resL=func(resL,data[l]);
            if((r&1)==0) resR=func(resR,data[--r]);
        }
        return func(resL,resR);
    }
    T operator[](int k){ return data[k+sz-1]; }
};

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

   SegmentTree<Lint> dp(N,[](Lint a,Lint b){return max(a,b);},0LL);
   for(int i=0;i<N;i++){
      Lint x=dp.get(0,h[i]);
      dp.update(h[i],x+a[i]);
   }
   cout<<dp.get(0,N)<<endl;
   return 0;
}


Measured memory_bytes: 5888
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main() {

	string s;
	cin >> s;

	size_t size = s.length();

	int ans = 0;

	for (int i = 0; i < size / 2 ; i++) {
		if (s[i] != s[size - 1 - i]) {
			ans += 1;
		}
	}

	cout << ans << endl;

	return 0;
}


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

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

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int n;
    cin >> n;

    char c[4] = {'S', 'H', 'C', 'D'};
    vector<vector<bool>> t(4, vector<bool>(13, false));

    roop(i, n){
        char a;
        int x;
        cin >> a >> x;

        switch(a){
            case 'S':
            t[0][x-1] = true;
            break;

            case 'H':
            t[1][x-1] = true;
            break;

            case 'C':
            t[2][x-1] = true;
            break;

            case 'D':
            t[3][x-1] = true;
            break;

        }
    }

    roop(i, 4){
        roop(j, 13){
            if(t[i][j] == false) cout << c[i] << " " << j+1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int N, T, A;
  vector<int> H(2000);
  cin >> N >> T >> A;
  for(int i=0;i<N;i++)cin >> H[i];
  int x=1000000000, y;
  int id=-1;
  for(int i=0;i<N;i++){
    if(x>abs(T*1000-6*H[i]-A*1000)){
      x=abs(T*1000-6*H[i]-A*1000);
      id=i+1;
    }
  }
  cout << id << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,q,ans,er=1;
const int N=3010,mod=1000000007,inv2=(mod+1)/2;
int a[N],pos1[N],pos2[N],dp[N][N],tmp[N][N];
int main()
{
	cin>>n>>q;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=q;++i)scanf("%d%d",&pos1[i],&pos2[i]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			dp[i][j]=a[i]>a[j];
	for(int i=1;i<=q;++i)
	{
		for(int j=1;j<=n;++j)
			if(j!=pos1[i]&&j!=pos2[i])
			{
				tmp[j][pos1[i]]=tmp[j][pos2[i]]=(LL)inv2*(dp[j][pos1[i]]+dp[j][pos2[i]])%mod;
				tmp[pos1[i]][j]=tmp[pos2[i]][j]=(LL)inv2*(dp[pos1[i]][j]+dp[pos2[i]][j])%mod;
			}
		for(int j=1;j<=n;++j)
			if(j!=pos1[i]&&j!=pos2[i])
			{
				dp[j][pos1[i]]=dp[j][pos2[i]]=tmp[j][pos1[i]];
				dp[pos1[i]][j]=dp[pos2[i]][j]=tmp[pos1[i]][j];
			}
		dp[pos1[i]][pos2[i]]=dp[pos2[i]][pos1[i]]=(LL)inv2*(dp[pos1[i]][pos2[i]]+dp[pos2[i]][pos1[i]])%mod;
		er=(er<<1)%mod;
	}
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			(ans+=dp[i][j])%=mod;
	cout<<(LL)ans*er%mod;;
	return 0;
}

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

int main() {
  for (int n; cin >> n, n;) {
    vector<string> t(n);
    int m = 0;
    REP(i, n) {
      cin >> t[i];
      m = max(m, (int)t[i].length());
    }
    vector<string> ss(n, string(m, ' '));
    REP(i, n) REP(j, t[i].length()) ss[i][j] = t[i][j];
    REP(i, n) REP(j, ss[i].length() - 1) {
      if (i == 0) continue;
      string& s = ss[i];
      if (s[j + 1] != '.') {
        s[j] = '+';
        break;
      }
    }
    REP(l, n) {
      REP(i, ss[l].length()) {
        if (ss[l][i] != '+') continue;
        int r = l + 1;
        while (r < n) {
          if (ss[r][i] != '.') break;
          r++;
        }
        if (r == n || ss[r][i] != '+') continue;
        REP(k, n) {
          if (k <= l || r <= k) continue;
          ss[k][i] = '|';
        }
        break;
      }
    }
    for (auto&& s : ss) {
      REP(i, s.length()) {
        if (s[i] == '.') cout << ' ';
        else if (s[i] == ' ') break;
        else cout << s[i];
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 4704
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007

map<string, int> m;




int main()
{
	FAST;
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll m;
	cin >> m;
	for(ll i = 0; i < s.size(); i ++){
		if(s[i] != s[m-1]){
			s[i] = '*';
		}
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
	ll n,a,b;
    cin>>n>>a>>b;
    if(a>b)cout<<0<<endl;
    else if(n==1&&a==b)cout<<1<<endl;
    else if(n<2)cout<<0<<endl;
    else cout<<(b-a)*(n-2)+1<<endl;
}

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

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

struct UnionFind {
  vector<int> par, siz;
  UnionFind (int n) {
    par.resize(n), siz.resize(n);
    for (int i = 0; i < n; i++) {
      par.at(i) = i, siz.at(i) = 1;
    }
  }
  int root(int x) {
    if (par.at(x) == x) return x;
    return par.at(x) = root(par.at(x));
  }
  int size(int x) {
    return siz.at(root(x));
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unit(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz.at(x) > siz.at(y)) {
      par.at(y) = x, siz.at(x) += siz.at(y);
    } else {
      par.at(x) = y, siz.at(y) += siz.at(x);
    }
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> AB(M);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    AB.at(i) = {--a, --b};
  }
  reverse(AB.begin(), AB.end());
  
  UnionFind UF(N);
  vector<long> ans;
  long tmp = (long) N * (N - 1) / 2;

  for (int i = 0; i < M; i++) {
    ans.push_back(tmp);
    int A = AB.at(i).first;
    int B = AB.at(i).second;
    if (!UF.same(A, B)) {
      tmp -= (long) UF.size(A) * UF.size(B);
    }
    UF.unit(A, B);
  }
  reverse(ans.begin(), ans.end());
  for (auto a : ans) cout << a << "\n"; 
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 5000+10;
const ll mod =   1e9+7;

int main()
{  fast
int x,n;
cin>>x>>n;
set<int> sett;
for(int i=0;i<n;i++){
	int y;
	cin>>y;
	sett.insert(y);
}
int mx=50000;int ans;
for(int i=-100;i<=200;i++){
	if(sett.find(i)==sett.end()){
		if(abs(i-x)<mx)
		{
			mx=abs(i-x);ans=i;
		}
	}
}
cout<<ans<<endl;



}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] nums = sc.nextLine().split(" ");
    if (Integer.parseInt(nums[0]) * Integer.parseInt(nums[1]) % 2 == 0) {
      System.out.println("Even");
    }  else {
      System.out.println("Odd");
    }
  }
}


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

using namespace std;

int check[10][1000001];

int main()
{
  int x, y;
  while(cin >> x >> y, x || y) {
    memset(check, -1, sizeof(check));
    int cnt = 0;
    x *= 10;
    bool flag = false;
    while(!~check[x/y][x%y]) {
      check[x/y][x%y] = cnt;
      if(x%y == 0) { flag = true; break; }
      cnt++;
      x %= y; x *= 10;
    }
    cout << check[x/y][x%y]+(int)flag << " " << cnt-check[x/y][x%y] << endl;
  }
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, X, T;
	cin >> N >> X >> T;
	cout << (N + X - 1) / X * T << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int k, s;
    int ans = 0;

    cin >> k >> s;

    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if (s - (i+j) >= 0 && s - (i+j) <= k) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(open(0).read().rstrip())

exes = {1}

for i in range(2,1001):
    if not i in exes:
        to_add = i
        while to_add * i <= 1000:
            to_add *= i
            exes.add(to_add)

print(max(filter(lambda x:x<=n, exes)))

Measured memory_bytes: 61760