akhauriyash/Code-Regression huggingface dataset:
#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() {
    ll N, M, Q, L, R;
    cin >> N >> M >> Q;
    vector<vector<ll>> sum(N+1, vector<ll>(N+1));
    rep(i,M) {
        cin >> L >> R;
        ++sum[L][R];
    }
    rep(i,N) rep(j,N) sum[i+1][j+1] += sum[i+1][j];
    for (int i = 1; i <= N; ++i) {
        for (int j = N - 1; j > 0; --j) {
            sum[j][i] += sum[j+1][i];
        }
    }

    vector<ll> p(Q), q(Q);
    rep(i,Q) cin >> p[i] >> q[i];

    rep(i,Q) cout << sum[p[i]][q[i]] << endl;
}



Measured memory_bytes: 6948
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

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

    ll n;
    cin>>n;

    ll a[n+1][4];

    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=3;j++){
            cin>>a[i][j];
        }
    }

    ll dp[n+1][4];

    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];
    dp[1][3] = a[1][3];

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

    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<"\n";

    return 0;
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	str st;
	cin >> st;
	for(i=0;i<st.size();i++)
	{
		if(st[i]=='?')
			st[i]='D';
	}
	cout << st << "\n";
	return 0;
}

Measured memory_bytes: 3756
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int_least64_t INF = 10000000;

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    string s;
    cin >> s;

    if ("ABC" == s) cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}



Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main(void){
    char a[1];
    scanf("%s", a);
    if(a[0] == 'A')printf("T");
    if(a[0] == 'C')printf("G");
    if(a[0] == 'G')printf("C");
    if(a[0] == 'T')printf("A");
    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec C(N, 0);
    REP(i,0,M) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        ++C[a]; ++C[b];
    }

    bool f = true;
    REP(i,0,N) {
        if(C[i] % 2 == 1) f = false;
    }
    if(f) PR("YES");
    else PR("NO");
    
    return 0;
}

/*



*/

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,i,j;
	cin>>n;
	while(n)
	{
		if(n%10==7)
		{
			cout<<"Yes";
			return 0;
		}
		n/=10;
	}
	cout<<"No";	
	return 0;
}

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

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> waters;
  for (int i = 0; i <= 30; i++) {
    for (int j = 0; j <= 30; j++) {
      int water = 100 * A * i + 100 * B * j;
      if (water <= F) {
        waters.push_back(water);
      }
    }
  }

  vector<int> sugars;
  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      int sugar = C * i + D * j;
      if (sugar <= F) {
        sugars.push_back(sugar);
      }
    }
  }

  int ans_w = 0;
  int ans_s = 0;
  double percent = -1.0;

  for (auto w : waters) {
    for (auto s : sugars) {
      int total = w + s;
      if (total > F) {
        continue;
      }

      int sugar_upper_limit = (w / 100) * E;

      double p = double(100 * s) / double(w + s);
      if (s <= sugar_upper_limit && p > percent) {
        ans_w = w;
        ans_s = s;
        percent = p;
      }
    }
  }

  cout << (ans_w + ans_s) << " " << ans_s << endl;
  return 0;
}

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

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

    int n, m;
    cin >> n >> m;

    int A[n][n];
    REP(i, n){
        REP(j, n){
            A[i][j] = (i == j ? 0 : 1e9);
        }
    }

    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        A[a][b] = 1;
        A[b][a] = 1;
    }

    REP(i, n){
        REP(j, n){
            REP(k, n){
                A[j][k] = min(A[j][k], A[j][i] + A[i][k]);
            }
        }
    }

    vector<int> B(n - 1);
    REP(i, n - 1) B[i] = i + 1;
    sort(B.begin(), B.end());

    int ans = 0;
    do{
        int tmp = 0;
        bool f = true;
        REP(i, n - 1){
            if(A[tmp][B[i]] != 1){
                f = false;
                break;
            }
            tmp = B[i];
        }
        if(f == true) ans++;
    }while(next_permutation(B.begin(), B.end()));

    cout << ans << endl;

    return 0;
}


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

namespace org
{
    template <class T>
    T make_value()
    {
        T tmp;
        return tmp;
    }

    template <class T>
    T VALUE()
    {
        T tmp;
        std::cin >> tmp;
        return tmp;
    }

    template <class T>
    std::vector<T> make_vector(long long size)
    {
        std::vector<T> tmp(size);
        return tmp;
    }

    template <class T>
    std::vector<T> VECTOR(long long size)
    {
        auto tmp = make_vector<T>(size);
        for (long long i = 0; i < tmp.size(); i++)
        {
            std::cin >> tmp.at(i);
        }
        return tmp;
    }

    template <class T>
    std::vector<std::vector<T>> make_matrix(long long line, long long row)
    {
        std::vector<std::vector<T>> tmp;
        tmp.resize(line);
        for (long long i = 0; i < tmp.size(); i++)
        {
            tmp.at(i).resize(row);
        }
        return tmp;
    }

    template <class T>
    std::vector<std::vector<T>> MATRIX(long long line, long long row)
    {
        auto tmp = make_matrix<T>(line, row);
        for (long long i = 0; i < tmp.size(); i++)
        {
            for (long long j = 0; j < tmp.at(0).size(); j++)
            {
                std::cin >> tmp.at(i).at(j);
            }
        }
        return tmp;
    }

    template <class T>
    bool find(std::vector<T> vec, T value)
    {
        for (long long i = 0; i < vec.size(); i++)
        {
            if (vec.at(i) == value)
            {
                return 1;
            }
        }
        return 0;
    }

} // namespace org

std::ostream &operator<<(std::ostream &os, const std::vector<long long> vec)
{
    for (long long i = 0; i < vec.size(); i++)
    {
        os << vec.at(i) << " ";
    }
    return os;
}

std::ostream &operator<<(std::ostream &os, const std::vector<std::vector<long long>> vec)
{
    for (long long i = 0; i < vec.size(); i++)
    {
        for (long long j = 0; j < vec.at(0).size(); j++)
        {
            os << vec.at(i).at(j) << " ";
        }
        os << std::endl;
    }
    return os;
}

using ll = long long;
using namespace std;

using org::MATRIX;
using org::VECTOR;
#define VEC(name, size, type) auto name = org::VECTOR<type>(size)
#define MAT(name, line, row, type) auto name = org::MATRIX<type>(line, row)
#define llV(name, size) VEC(name, size, long long)
#define stV(name, size) VEC(name, size, std::string)
#define llM(name, line, row) MAT(name, line, row, long long)
#define stM(name, line, row) MAT(name, line, row, std::string)
#define ll(name) auto name = org::VALUE<long long>()

#define rep1(max1) for (long long i = 0; i < max1; i++)
#define rep2(max1, max2)                 \
    for (long long i = 0; i < max1; i++) \
        for (long long j = 0; j < max1; j++)

int main()
{
    ll(N);
    ll(K);
    llV(A,N);
    
    for(ll i=K;i<N;i++){
        if(A[i-K]<A[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll x, y;
  cin >> x >> y;
  ll count = 1000000000000;
  ll count1 = (x <= y) ? y-x : -1;
  ll count2 = (-x <= y) ? y+x+1 : -1;
  ll count3 = (x <= -y) ? -y-x+1 : -1;
  ll count4 = (-x <= -y) ? -y+x+2 : -1;
  count = 0 < count1 ? count1 : count;
  count = 0 < count2 ? min(count, count2) : count;
  count = 0 < count3 ? min(count, count3) : count;
  count = 0 < count4 ? min(count, count4) : count;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
stu=[0 for i in range(N)]
che=[0 for j in range(M)]

for i in range(N):
    stu[i]=list(map(int,input().split()))

for j in range(M):
    che[j]=list(map(int,input().split()))

for s in range(N):
    x=[]
    a,b=stu[s]
    for t in range(M):
        c,d=che[t]
        x.append(abs(a-c)+abs(b-d))
    num=x.index(min(x))
    print(num+1)

Measured memory_bytes: 9224
#include <iostream>

int main(){
  int N;
  std::cin >> N;

  long long A[300][300];
  for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) std::cin >> A[i][j];

  bool min_path = true;
  long long path_length = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      long long k_min = A[i][j];
      for(int k = 0; k < N; k++){
        if(k == i || k == j) continue;
        if(A[i][j] > A[i][k]+A[k][j]) min_path = false;
        else if(A[i][j] == A[i][k]+A[k][j]) k_min = 0;
      }
      path_length += k_min;
    }
  }
  if(min_path == false) std::cout << -1 << std::endl;
  else std::cout << path_length << std::endl;

  return 0;
}



Measured memory_bytes: 896
#include<stdio.h>
#define size 1000000

        struct process{
                char name[10];
                int time;
        };
        struct process p[size],now_process;
        int head,tail;

        void enqueue(struct process new_process){
                p[tail]=new_process;
                tail=tail+1;
        }

        struct process dequeue(){
                struct process out_process=p[head];
                head=head+1;
                return out_process;
        }



int main(void){
        int n,q;
        int clock=0;
        scanf("%d",&n);
        scanf("%d",&q);
        int i;
        for(i=0;i<n;i++){
                scanf("%s",p[i].name);
                scanf("%d",&p[i].time);
        }
        head=0;
        tail=n;
        while(head!=tail){
                now_process=dequeue();
                if(now_process.time<=q){
                        clock=clock+now_process.time;
                        printf("%s %d\n",now_process.name,clock);
                }else{
                        now_process.time=now_process.time-q;
                        clock=clock+q;
                        enqueue(now_process);
                }
        }

        return 0;
}

Measured memory_bytes: 4672
#include <iostream>
#include <string>

using namespace std;

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

    bool good = false;
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
        good = true;
    
    cout << (good ? "Yes" : "No") << endl;
}

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

double dp[301][301][301];

double solve(int x,int y,int z,int n)
{
	if(x==0&&y==0&&z==0)
	{
		return(0);
	}
	if(x<0||y<0||z<0)
	{
		return(0);
	}
	if(dp[x][y][z]>-0.9)
	{
		return(dp[x][y][z]);
	}
	double exp=n+x*(solve(x-1,y,z,n))+y*solve(x+1,y-1,z,n)+z*solve(x,y+1,z-1,n);
	return(dp[x][y][z]=exp/(x+y+z));
}
int main()
{
	long long int n,i,j,k;
	cin>>n;
	int x;
	int one=0,two=0,three=0;
	for(i=0;i<n;i++)
	{
		cin>>x;
		if(x==1)
		{
			one++;
		}
		if(x==2)
		{
			two++;
		}
		if(x==3)
		{
			three++;
		}
	}
	for(i=0;i<301;i++)
	{
		for(j=0;j<301;j++)
		{
			for(k=0;k<301;k++)
			{
				dp[i][j][k]=-2.0;
			}
		}
	}
	cout<<fixed<<setprecision(9)<<solve(one,two,three,n);
}




Measured memory_bytes: 213376
#include<stdio.h>
int main(){
int a,b,c,d,i;
scanf("%d\n",&d);
for(i=0;i<d;i++){
scanf("%d %d %d\n",&a,&b,&c);
if(a>=b && a>=c){
if(a*a==b*b+c*c){
printf("YES\n");
}
else{
printf("NO\n");
}
}
else if(b>=a && b>=c){
if(b*b==a*a+c*c){
printf("YES\n");
}
else{
printf("NO\n");
}
}
else if(c>=a && c>=b){
if(c*c==b*b+a*a){
printf("YES\n");
}
else{
printf("NO\n");
}
}
}
return 0;
}



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

using namespace std;

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

	string rev = S;
	reverse(rev.begin(), rev.end());

	int totalHug = 0;
	for (int i = 0; i < S.length() / 2; i++) {
		if (S.at(i) != rev.at(i)) {
			totalHug++;
		}
	}

	cout << totalHug << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


// void subaux(int n, int tmp, int digit) {
//     if (n == 0) {
//         pattern.push_back(tmp);
//     } else {
//         for (int i = 1; i < n; i++)
//         {
//             subaux(n-1, tmp*10+digit, i);
//         }
//     }
// }

// void aux(int n) {
//     for (int i = 1; i < n; i++)
//     {
//         subaux(n, 0, i);
//     }
// }



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

    int n;
    cin >> n;
    int p=0;
    int q=0;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        p = p*10 + tmp;
    }
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        q = q * 10 + tmp;

    }
    // aux(n);
    vector<int> x;
    for (int i = 1; i <= n; i++)
    {
        x.push_back(i);
    }
    vector<int> pattern;
    {
        int tmp = 0;
        for (int i = 0; i < n; i++)
        {
            tmp = tmp * 10 + x[i];
        }
        pattern.push_back(tmp);
    }
    
    while ((next_permutation(x.begin(), x.end())))
    {
        int tmp = 0;
        for (int i = 0; i < n; i++)
        {
            tmp = tmp * 10 + x[i];
        }
        pattern.push_back(tmp);
    }
    
    
    sort(pattern.begin(), pattern.end());
    // for (int i = 0; i < pattern.size(); i++)
    // {
    //     cout << pattern[i] << "\n";
    // }
    
    auto position = lower_bound(pattern.begin(), pattern.end(), p);
    int idx_a = distance(pattern.begin(), position);
    position =lower_bound(pattern.begin(), pattern.end(), q);
    int idx_b = distance(pattern.begin(), position);

    cout << abs(idx_a - idx_b) << "\n";
}

Measured memory_bytes: 640
N,M,X,Y= [int(i) for i in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A.append(X)
B.append(Y)
A = sorted(A)
B = sorted(B)
print("War"if A[N] >= B[0] else "No War")

Measured memory_bytes: 3064
import java.util.ArrayList;

import java.util.Scanner;

public class Main {



    public static void main(String[] args){

    	Scanner sc = new Scanner(System.in);



    	// 入力

    	int s = sc.nextInt();

    	ArrayList<Integer> arg = new ArrayList<>();
      	arg.add(s);

    	int i;



    	for (i = 0; i < 1000002; i++ ){

        	if(s % 2 == 0){

        		s = s / 2;

        	} else {

        		s = 3 * s + 1;

        	}



        	if (arg.contains(s)){

        		break;



        	}

        	arg.add(s);



    	}



    	// 出力

    	System.out.println(i+2);

    }

}

Measured memory_bytes: 23124
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int ans,x;

int32_t main(){_
	//freopen("input","r",stdin);
	string s;
	cin >> s;
	for(int i = 0;i < sz(s);i++)
	{
		if(s[i] == 'A') x++;
		else if(s[i] == 'B' && i < sz(s) - 1 && s[i + 1] == 'C')
		{
			i++;
			ans += x;
		}
		else x = 0;
	}
	rc(ans);
	return 0;
}


Measured memory_bytes: 720
function getKeta(x)
    local keta = 1
    while(10 <= x) do
        keta, x = keta + 1, math.floor(x / 10)
    end
    return keta
end
local n = io.read("*n")
local sqn = math.ceil(math.sqrt(n))
local k = 100
min = math.min
for i = 1, sqn do
    if(n % i == 0) then
    k = min(k, getKeta(n / i))
    end
end
print(k)

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    l, r = map(int, input().split())
    if r - l >= 2019:
        print(0)
        return
    ans = 2019
    for i in range(l, r + 1):
        for j in range(l, r + 1):
            if i == j:
                continue
            ans = min(ans, (i * j) % 2019)
    print(ans)

if __name__=="__main__":
    solve()


Measured memory_bytes: 39024
def solve():
    n = int(input())
    d = {}
    mod = 10**9+7
    for i in range(1, n+1):
        d[i] = 0
    
    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a
    
    for i in range(1, n+1):
        ps = prime_factorize(i)
        for p in ps:
            d[p] += 1
    
    ans = 1
    for i in range(1, n+1):
        if d[i] >= 1:
            ans *= (d[i]+1)
        
    
    print(ans%mod)
        
        
if __name__ == '__main__':
    solve()

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1123456;
int v[444];
int main() {
    int n, m, k;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 0; i<n; ++i) {
        scanf("%d", v+i);
    }
    for (int i = 0, x; i<n; ++i) {
        scanf("%d" ,&x);
        v[i]-=x;
        if (v[i] >0) ans += v[i];
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; i++)  cin >> v[i];
    vector<int> m(N);
    for(int i = 0; i < N; i++){
        m[v[i]-1] = i+1;
    }
    for(int i = 0; i < N; i++){
        cout << m[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <climits>
#include <functional>
#include <map>
#define endl '\n'
#define ll long long
#define NCONS 16001

using namespace std;
int x, y;
string str;

bool check(vector<int> d, int a, bool flag)
{
    auto d_size = d.size();
    auto dp = new int*[d_size + 1]();
    for(int i = 0; i <= d_size; i++)
        dp[i] = new int[NCONS]();
    dp[0][8000] = 1;
    
    for(int i = 1; i <= d_size; i++)
    {
        for(int j = 0; j < NCONS; j++)
        {
            auto coin = d[i-1];
            if(j - coin >= 0)
            {
                dp[i][j] += dp[i-1][j-coin];
 //               cout << "i: " << i << ", j: " << j - 8000 << endl;
            }
            if(j + coin < NCONS)
            {
                if(i == 1 && flag) continue;
                dp[i][j] += dp[i-1][j+coin];
 //               cout << "i: " << i << ", j: " << j - 8000 << endl;
            }
        }
    }
    
    if(dp[d_size][a])
        return true;
    else
        return false;
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> str >> x >> y;
    x += 8000; y += 8000;
    
    vector<int> vec_x, vec_y;
    bool flag = true;
    bool jebal = true;
    if(str[0] != 'F')
        jebal = false;
    int dis = 0;
    for(int i = 0; i < str.length(); i++)
    {
        if(str[i] == 'T')
        {
            if(flag)
            {
                if(dis)
                    vec_x.push_back(dis);
                flag = false;
            }
            else
            {
                if(dis)
                    vec_y.push_back(dis);
                flag = true;
            }
            dis = 0;
        }
        else
        {
            dis += 1;
        }
    }
    if(flag)
    {
        if(dis)
            vec_x.push_back(dis);
    }
    else
    {
        if(dis)
            vec_y.push_back(dis);
    }
    
    if(check(vec_x, x, jebal) && check(vec_y, y, false))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    

    return 0;
}


Measured memory_bytes: 250496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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(b<a){a=b;return 1;}return 0;}

void solve(ll n){
    cout<<((n+1)/2)<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    solve(n);
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    int arr[3][3];
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            std::cin >> arr[i][j];
        }
    }
    bool seen[3][3] = { false };
    int n;
    std::cin >> n;
    while (n--) {
        int num;
        std::cin >> num;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (arr[i][j] == num) {
                    seen[i][j] = true;
                }
            }
        }
    }
    bool bingo = false;
    for (int i = 0; i < 3; ++i) {
        bool allRow = true, allCol = true;
        for (int j = 0; j < 3; ++j) {
            if (!seen[i][j]) {
                allRow = false;
            }
            if (!seen[j][i]) {
                allCol = false;
            }
        }
        if (allRow || allCol) {
            bingo = true;
        }
    }
    if (!bingo) {
        bingo = (seen[0][0] && seen[1][1] && seen[2][2]) ||
                (seen[0][2] && seen[1][1] && seen[2][0]);
    }
    std::cout << (bingo ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

while True:
    try:
        A, B = input().split(), input().split()
        hit = sum([ 1 for i in range(len(A)) if A[i]==B[i] ])
        blow = sum([ 1 for i in range(len(A)) if B[i] in A ]) - hit
        print(str(hit) + ' ' +str(blow))
    except:
        break


Measured memory_bytes: 5572
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"

using namespace std;
typedef long long ll;

int dp[1010][1010] = {
  {0}
};

int main()
{
  int h, w;
  cin >> h >> w;
  char a[1010][1010];
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cin >> a[i][j];
    }
  }

  dp[0][0] = 1;

  for (int x = 1; x < h + w - 1; x++)	//x=i+j
  {
    for (int i = 0; i < h; i++)
    {
      if (0 <= x - i && x - i < w && a[i][x - i] == '.')
      {
        if (i != 0)
        {
          dp[i][x - i] += dp[i - 1][x - i];
          dp[i][x - i] %= 1000000007;
        }
        if (x - i != 0)
        {
          dp[i][x - i] += dp[i][x - i - 1];
          dp[i][x - i] %= 1000000007;
        }
      }
    }
  }

  cout << dp[h - 1][w - 1] << "\n";
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstring>
#include<cmath>

using namespace std;
const int maxM = 10;
int N, M;
int Q[maxM][2];


int main(){
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> Q[i][0] >> Q[i][1];
    }
    int start = pow(10,N-1);
    int end = pow(10,N);
    if(N==1) start = 0;
    //cout << start << end << endl;

    for(int x=start;x<end;x++){
        /*
        if(x<=702){
            cout << "now processing : " << x << endl;
        }
        */
        bool chk=true;
        
        for(int i=0;i<M;i++){
            /*
            if(x<=702){
                cout << "now query : " << i << endl;
            }
            */
            int y=x;
            int s,c;
            s = Q[i][0];
            c = Q[i][1];
            //Nに応じて指し示す桁を変える。
            s = N-s+1;
            /*
            if(x<=702){
                cout << "now query : " << s << endl;
            }
            */

            if(s==3){
                y /= 100;
                if(y!=c) chk=false;
            }
            else if(s==2){
                y /=10;
                y %= 10;
                if(y!=c) chk=false;
            }
            else if(s==1){
                y%=10;
                if(y!=c) chk=false;

            }
            /*
            if(x<=702){
                cout << "chk: " << chk << endl;
            }
            */
        }
        if(chk){
            cout << x << endl;
            return 0;

        }
    }
    cout << -1 << endl;
    return 0;
    
}

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

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

  int i;
  for (i = 0; i < str.size(); i++){
    if (str[i] == 'C') {
      for (int j = i; j < str.size(); j++){
        if (str[j] == 'F'){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

  cout << "No" << endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		Arrays.sort(a);

		int check=0;
		for(int i=0;i<n;i++) {
			for(int j=i+1;j<n;j++) {
				if(i!=j) {
					if(a[i]==a[j]) {
						check=1;
						break;
					}else {
						break;
					}
				}
			}
			if(check==1)break;
		}
		System.out.println((check==1)? "NO":"YES");
	}
}

Measured memory_bytes: 86556
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;
vl a;

int main(){
	cin>>n;
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<n;i++) a[i]+=a[i-1];
	ll ans=0,sum=a[n-1];
	for(int i=0;i<n;i++){
		int Im=lower_bound(a.begin(),a.end(),(a[i]+sum/3)%sum)-a.begin();
		int IM=lower_bound(a.begin(),a.end(),(a[i]+sum/3*2)%sum)-a.begin();
		for(int j=Im-5;j<Im+5;j++) for(int k=IM-5;k<IM+5;k++){
			ll A=(a[(j+n)%n]-a[i]+sum)%sum;
			ll B=(a[(k+n)%n]-a[(j+n)%n]+sum)%sum;
			ans=max(ans,min(A,min(B,sum-A-B)));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4460
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
vector<int> a, b, c, d;
signed main() {
	int n, w; cin >> n >> w;
	int w0 = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		int wi, v; cin >> wi >> v;
		if (!i)w0 = wi;
		if (wi - w0 == 0)a.push_back(v);
		if (wi - w0 == 1)b.push_back(v);
		if (wi - w0 == 2)c.push_back(v);
		if (wi - w0 == 3)d.push_back(v);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	sort(d.begin(), d.end());
	for (int i = 0; i <= a.size() && i*w0 <= w; i++) {
		for (int j = 0; j <= b.size() && i*w0 + j * (w0 + 1) <= w; j++) {
			for (int k = 0; k <= c.size() && i*w0 + j * (w0 + 1) + k * (w0 + 2) <= w; k++) {
				for (int l = 0; l <= d.size() && i*w0 + j * (w0 + 1) + k * (w0 + 2) + l * (w0 + 3) <= w; l++) {
					int p, sum = 0;
					for (p = 0; p < i; p++)sum += a[a.size() - 1 - p];
					for (p = 0; p < j; p++)sum += b[b.size() - 1 - p];
					for (p = 0; p < k; p++)sum += c[c.size() - 1 - p];
					for (p = 0; p < l; p++)sum += d[d.size() - 1 - p];
					ans = max(ans, sum);
				}
			}
		}
	}
	cout << ans << endl;
}

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

#define pii pair<int,int>
#define ll long long
#define IMAX 1000000007
#define in2d(i,j,H,W)(0<=i&&i<H&&0<=j&&j<W)

using namespace std;

int main(){
	int H,W;cin>>H>>W;
	vector<vector<char> >A(H,vector<char>(W));
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>A[i][j];
	vector<vector<int> >dp(H,vector<int>(W,0));
	for(int i=0;i<H;i++){
		if(A[i][0]=='.'){
			dp[i][0]=1;
		}else{
			break;
		}
	}
	for(int j=0;j<W;j++){
		if(A[0][j]=='.'){
			dp[0][j]=1;
		}else{
			break;
		}
	}
	for(int i=1;i<H;i++)for(int j=1;j<W;j++)if(A[i][j]=='.'){
		dp[i][j]=(dp[i-1][j]+dp[i][j-1])%IMAX;
	}
	cout<<dp[H-1][W-1]<<endl;

	return 0;
}



Measured memory_bytes: 5248
import sys
import math
import bisect

def solve(a, b, c):
    for i in range(b):
        val = a * (i + 1)
        if val % b == c:
            return True
    return False

def main():
    a, b, c = map(int, input().split())
    if solve(a, b, c):
        print('YES')
    else:
        print('NO')

if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
h,w=map(int,input().split())
s=[[] for j in range(h)]
t=[[0]*w for k in range(h)]
t[0][0]=1
q=0
u=[]
for i in range(h):
    s[i]+=list(input())
    q+=s[i].count("#")
u.append((0,0))
while u!=[]:
    (x,y)=u[0]
    if x!=h-1:
        if t[x+1][y]==0 and s[x+1][y]==".":
            t[x+1][y]=t[x][y]+1
            u.append((x+1,y))
    if y!=w-1:        
        if t[x][y+1]==0 and s[x][y+1]==".":
            t[x][y+1]=t[x][y]+1
            u.append((x,y+1))
    if x!=0:        
        if t[x-1][y]==0 and s[x-1][y]==".":
            t[x-1][y]=t[x][y]+1
            u.append((x-1,y))
    if y!=0:        
        if t[x][y-1]==0 and s[x][y-1]==".":
            t[x][y-1]=t[x][y]+1
            u.append((x,y-1))
    u.pop(0)
if t[h-1][w-1]==0:
    print(-1)
else:    
    print((h*w-t[h-1][w-1])-q)    
        
        
    
    


Measured memory_bytes: 3188
#756
import numpy as np
N = int(input())
 
pf = np.zeros(N+1, dtype=int)
 
def prime_fact(N):
    for i in range(2, int(N**0.5)+1):
        if N%i == 0:
            cnt = 0
            while N%i==0:
                cnt += 1
                N //= i
            pf[i] += cnt
    if N != 1:
        pf[N] += 1

for n in range(1, N+1):
    prime_fact(n)
pf = pf[np.nonzero(pf)]
 
ans = 0
x74 = np.count_nonzero(pf >= 74)
x24 = np.count_nonzero(pf >= 24)
x14 = np.count_nonzero(pf >= 14)
x4 = np.count_nonzero(pf >= 4)
x2 = np.count_nonzero(pf >= 2)
 
if x74:
    ans += x74
if x24 and x2:
    ans += x24*(x2-1)
if x14 and x4:
    ans += x14*(x4-1)
if x2 and x4>=2:
    tmp = x4*(x4-1)//2
    ans += tmp*(x2-2)

print(ans)


Measured memory_bytes: 12500
import java.util.*;
import java.awt.geom.*;
public class Main {
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String [] a = sc.next().split(",");
			double w = Double.parseDouble(a[1]);
			double h = Double.parseDouble(a[2]);
			double res = w / (h * h);
			if(res >= 25){
				System.out.println(a[0]);
			}
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
let readInt () = Scanf.scanf " %d" (fun x -> x)
let readInt64 () = Scanf.scanf " %Ld" (fun x -> x)

let (++) = Int64.add
let (--) = Int64.sub
let ( ** ) = Int64.mul
let (//) = Int64.div
let (%%) = Int64.rem

let solve n a b =
  let rec go i best left =
    (*Printf.eprintf "%d %Ld %Ld\n" i best left;*)
    if i = n then best ++ min a.(i) left
    else go (i+1) (best ++ min a.(i) (b.(i) ++ left)) (max 0L (min b.(i) (b.(i) ++ left -- a.(i))))
  in go 0 0L 0L

let main () =
  let n = readInt () in
  let a = Array.init (n+1) (fun _ -> readInt64 ()) in
  let b = Array.init n (fun _ -> readInt64 ()) in
  Printf.printf "%Ld\n" (solve n a b)

let () = main ()


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

struct edge { int to, rev; int cap; };
void add_edge(V<V<edge>>& G, int u, int v, int c) {
   G[u].PB((edge){ v, SZ(G[v])  , c });
   G[v].PB((edge){ u, SZ(G[u])-1, 0 });
}
int dfs(vector< vector<edge> >& G, vector<bool>& used, int v, int t, int flow)
{
   if (v == t) return flow;
   used[v] = true;
   for(int i = 0; i < G[v].size(); ++i) {
      edge& e = G[v][i];
      if (used[e.to] || e.cap == 0) continue;
      int d = dfs(G, used, e.to, t, min(e.cap, flow));
      if (d > 0) {
         e.cap -= d;
         G[e.to][e.rev].cap += d;
         return d;
      }
   }
   return 0;
}
int max_flow(vector< vector<edge> >& G, int s, int t)
{
   int flow = 0;
   vector<bool> used(G.size());
   for (;;) {
      fill(used.begin(), used.end(), false);
      int f = dfs(G, used, s, t, INF);
      if (f == 0) return flow;
      flow += f;
   }
}

signed main()
{
   int N; cin >> N;
   V<int> a(N); REP(i, N) cin >> a[i];

   V<V<edge>> G(N+2);
   REP(i, N) {
      if (a[i] < 0) {
         add_edge(G,   0, i+1, -a[i]);
      } else {
         add_edge(G, i+1, N+1,  a[i]);
      }
   }
   FORE(i, 1, N) {
      for (int j = 2; i*j <= N; j++) {
         add_edge(G, i, i*j, INF);
      }
   }

   int ans = 0;
   REP(i, N) {
      if (a[i] > 0) {
         ans += a[i];
      }
   }
   ans -= max_flow(G, 0, N+1);

   cout << ans << endl;

   return 0;
}


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

int main(){
  const int INF = 100000000;
  int h,w; cin >> h >> w;

  vector<string> meiro;
  string tmp;
  for(int i=0; i<h; i++){
    cin >> tmp;
    meiro.push_back(tmp);
  }
  vector<vector<int>> d(h,vector<int>(w));
  vector<int> ofst = {0,0,1,-1};
  

  int ans =0;
  //cout << "hoge" <<endl;
  for(int k=0; k<h; k++){
    for(int j=0; j<w; j++){
      if(meiro.at(k).at(j)=='.'){
          for (int l=0; l<h; l++){
    for (int b=0; b<w; b++){
      d[l][b] = INF;
    }
  }
        queue<pair<int,int>> que;
        que.push(make_pair(k,j));
        d.at(k).at(j) = 0;
        //cout << "hoge" <<endl;
  		while(que.size()){
          pair<int,int> p = que.front(); que.pop();
          	for (int i=0; i<4; i++){
          	int ny = p.first + ofst.at(i);
            int nx = p.second + ofst.at(3-i);
          		if(0<=nx && nx<w && 0<=ny && ny<h){
           		if(meiro[ny].at(nx)=='.' && d[ny][nx]==INF ){
            	que.push(make_pair(ny,nx));

            d[ny][nx] = d[p.first][p.second] + 1;
             ans = max(ans,d[ny][nx]);

          }
          }
        }
      }     
          }
        }
  }
  cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


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

  int Q;
  cin >> Q;

  int cnt_1=0;
  vector<char> c1, c2;
  REP(i,Q){
    int t,f;
    char c;

    cin >> t;
    if(t==1){
      cnt_1++;
    }else{
      cin >> f >> c;
      if(f==1){
        if(cnt_1 % 2 == 0){
          c1.push_back(c);
        }else{
          c2.push_back(c);
        }
      }else{
        if(cnt_1 % 2 != 0){
          c1.push_back(c);
        }else{
          c2.push_back(c);
        }
      }
    }
  }

  if(cnt_1%2==0){
    reverse(ALL(c1));
    REP(i,c1.size()){
      cout << c1[i];
    }
    cout << s;
    REP(i,c2.size()){
      cout << c2[i];
    }
    cout << endl;
  }else{
    reverse(ALL(c2));
    REP(i,c2.size()){
      cout << c2[i];
    }
    reverse(ALL(s));
    cout << s;
    REP(i,c1.size()){
      cout << c1[i];
    }
    cout << endl;

  }


}



Measured memory_bytes: 1148
def resolve():
    '''
    code here
    '''
    import collections
    H, W = [int(item) for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]

    fp = [[-1 for _ in range(W)] for _ in range(H)]

    que = collections.deque([[0, 0, 1]])
    fp[0][0] = 1
    next_y_x = [[0, 1], [1, 0], [-1, 0], [0, -1]]
    is_found = False

    while que:
        temp = que.popleft()

        if temp[0] == H-1 and temp[1] == W-1:
            pass_num = temp[2]
            que = False
            is_found = True
        else:
            for dy, dx in next_y_x:
                ny = temp[0] + dy
                nx = temp[1] + dx

                if 0 <= ny <= H-1 and 0 <= nx <= W-1:
                    if grid[ny][nx] == '.' and fp[ny][nx] == -1:
                        que.append([ny, nx, temp[2]+1])
                        fp[ny][nx] = temp[2] + 1

    black_cnt = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == '#':
                black_cnt += 1

    if is_found:
        print(H*W - black_cnt - pass_num)
    else:
        print(-1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3316
#クラスカル法を使った最小全域木の問題。2次元平面上という点に工夫の必要がある。
#全頂点と全頂点を結ぶパスを張ることが許されれば解決するがN<=10**5なので、TLE。
#簡単のために1次元上の頂点の場合を考える。
#この場合は頂点位置をソートして隣り合う頂点にパスを張れば充分と分かる。
#なぜならV0,V2=(V0,V1)+(V1,V2)なので改めて(V0,V2)を張る必要がない。
#さてここで、条件より2頂点間のパスは最終的にはx軸かy軸の1次平面上の距離となることを思い出す。
#つまり全頂点をx軸上の位置でソートしたもの、y軸上でソートしたものの2種類でそれぞれN-1個のパスがあれば充分と分かる。
#では、2*(N-1)個のパスに含まれる(N-1)個の「最短ではない」パスをどう扱えば良いか？
#少し考えれば、これは無視してそのままクラスカル法にかけても結果は変わらないと分かる。
#以上、パス構築O(N log N),クラスカル法O(2N log N)でおそらく間に合うはず。

from collections import defaultdict

#UnionFind
class UnionFind(object):
  def __init__(self,n):
    self.table=[-1]*n
 
  def find(self,x):
    parent=self.table[x]
    if parent<0:
      return x
    else:
      root=self.find(parent)
      self.table[x]=root
      return root
 
  def union(self,a,b):
    root1=self.find(a)
    root2=self.find(b)
    if root1 != root2:
      if self.table[root1] != self.table[root2]:
        if self.table[root1] < self.table[root2]:
          self.table[root2]=root1
        else:
          self.table[root1]=root2
      else:
        self.table[root1]+=(-1)
        self.table[root2]=root1

#入力読込
N=int(input())
Vx=[]
Vy=[]
for i in range(N):
  x,y=map(int,input().split())
  Vx.append([i,x])
  Vy.append([i,y])

E=[]
#x軸をベースにパスを作る準備
Vx=sorted(Vx, key=lambda x:x[1])
#y軸をベースにパスを作る準備
Vy=sorted(Vy, key=lambda x:x[1])

#パスを作る
for i in range(N-1):
  a,b=Vx[i]
  c,d=Vx[i+1]
  e,f=Vy[i]
  g,h=Vy[i+1]
  E.append((d-b,a,c))
  E.append((h-f,e,g))
  
#クラスカル法
E=sorted(E,key = lambda x:x[0])
UF=UnionFind(N)
ans=0
for a,b,c in E:
  if UF.find(b)!=UF.find(c):
    ans+=a
    UF.union(b,c)

print(ans)

Measured memory_bytes: 61728
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 998244353
#define maxn 200010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static char buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10+'0';
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
struct Data{
    int x,id;
}num[maxn];
struct point{
    int x,y,rk;
}a[maxn];
int n;
bool cmp1(Data a,Data b){return a.x<b.x;}
bool cmp2(point a,point b){return a.x<b.x;}
inline ll power(ll a,ll b)
{
    ll ans=1;
    for(;b;b>>=1,a=a*a%mod)
        if(b&1)ans=ans*a%mod;
    return ans;
}
int bit1[maxn],bit2[maxn];
void add1(int x,int k){for(;x<=n;x+=x&(-x))bit1[x]+=k;}
int getsum1(int x){int sum=0; for(;x;x-=x&(-x))sum+=bit1[x]; return sum;}
void add2(int x,int k){for(;x<=n;x+=x&(-x))bit2[x]+=k;}
int getsum2(int x){int sum=0; for(;x;x-=x&(-x))sum+=bit2[x]; return sum;}
int main()
{
    n=read();
    for(int i=1;i<=n;i++){
        a[i].x=read(); a[i].y=read();
        num[i].x=a[i].y; num[i].id=i;
    }
    std::sort(num+1,num+n+1,cmp1);
    for(int i=1;i<=n;i++)
        a[num[i].id].rk=i;
    std::sort(a+1,a+n+1,cmp2);
    for(int i=1;i<=n;i++)
        bit1[i]=0,bit2[i]=i&(-i);
    ll ans=0;
    for(int i=1;i<=n;i++){
        add2(a[i].rk,-1);
        int A=getsum1(a[i].rk),B=getsum1(n)-getsum1(a[i].rk),C=getsum2(a[i].rk),D=getsum2(n)-getsum2(a[i].rk);
        ll totA=power(2,A),totB=power(2,B),totC=power(2,C),totD=power(2,D);
        ans=(ans+(totA-1)*totB%mod*totC%mod*(totD-1))%mod;
        ans=(ans+totA*(totB-1)%mod*(totC-1)%mod*totD)%mod;
        ans=(ans-(totA-1)*(totB-1)%mod*(totC-1)%mod*(totD-1)%mod+mod)%mod;
        ans=(ans+power(2,n-1))%mod;
        add1(a[i].rk,1);
    }
    writeln(ans);
    return 0;
}


Measured memory_bytes: 5632
import java.util.Scanner;
//0555
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        int n=sc.nextInt();
        int c=0;
        while(n-->0) {
            String t=sc.next();
            t+=t.substring(0,s.length()-1);
            if(t.indexOf(s)>=0) {
                c++;
            }
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 26256
def resolve():
    n = int(input())
    f = list(int("".join(input().split()), 2) for _ in range(n))
    p = list(list(map(int, input().split())) for _ in range(n))
    INF = 10 ** 18
    ans = -INF
    for i in range(1, 2 ** 10):
        profit = 0
        for j, fi in enumerate(f):
            same = bin(i & fi)[2:].count("1")
            profit += p[j][same]
        ans = max(ans, profit)
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3188