akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using pdd = pair<double,double>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

const int MAX = 2100000;
//const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long n, long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  long x,y;
  cin >> x >> y;
  if((x+y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  long z = (x+y)/3;
  long n = x - z;
  long m = y - z;
  long ans = 1;
  /*for(long i=1;i<=n;i++){
    long down = n + m - i;
    long up = i;
    ans *= down;
    ans /= up;
  }*/
  COMinit();
  cout << COM(n+m,n) << endl;
}


Measured memory_bytes: 49408
L,R = list(map(int,input().split()))
if R-L+1 >= 2019:
    ans = 0
else:
    ans = 2019
    lis = [i%2019 for i in range(L,R+1)]
    for i in range(R-L):
        for j in range(i+1,R-L+1):
            s = (lis[i]*lis[j])%2019
            ans = min(s,ans)
print(ans)


Measured memory_bytes: 9108
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

bool black[500][500];
bool isvisit[500][500];
int H,W;


void dfs(int i, int j, ll* b, ll* w){
    isvisit[i][j] = true; 
    if(i+1 < H){
        if(!isvisit[i+1][j] && (black[i+1][j] != black[i][j])) {
            dfs(i+1, j, b, w);
        }
    }
    if(i-1 >= 0){
        if(!isvisit[i-1][j] && (black[i-1][j] != black[i][j])) {
            dfs(i-1, j, b, w);
        }
    }
    if(j-1 >= 0){
        if(!isvisit[i][j-1] && (black[i][j-1] != black[i][j])) {
            dfs(i, j-1, b, w);
        }
    }
    if(j+1 < W){
        if(!isvisit[i][j+1] && (black[i][j+1] != black[i][j])) {
            dfs(i, j+1, b, w);
        }
    }
    if(black[i][j]) *b += 1;
    else *w += 1;
}

int main(){
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            char c;
            cin >> c;
            if(c == '#')
                black[i][j] = true;
            else
                black[i][j] = false;
        }
    }

    ll ans = 0;
    REP(i,H){
        REP(j,W){
            if(!isvisit[i][j]){
                ll b=0, w=0;
                dfs(i,j,&b,&w);
                //printf("b:%lld, w=%lld\n", b, w);
                ans += b*w;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int X;
    cin >> X;
    for(int i = 1; i*100 <= X; i++){
        int n = X-i*100;
        if(n <= 5*i){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
import math


def tri(x1, y1, x2, y2, x3, y3):
    return math.fabs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2

while True:
    try:
        x1, y1, x2, y2, x3, y3, x, y = map(float, input().split())
    except:
        break
    abc = tri(x1, y1, x2, y2, x3, y3)
    abp = tri(x1, y1, x2, y2, x, y)
    acp = tri(x1, y1, x3, y3, x, y)
    bcp = tri(x2, y2, x3, y3, x, y)
    x, y = int(abc * pow(10, 5)), int((abp + acp + bcp) * pow(10, 5))
    print("YES" if x >= y else "NO")

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

int main() {
    int N;
    cin >> N;
    vector<int> A1(N + 1);
    vector<int> B1(N);
    vector<int> A2(N + 1);
    vector<int> B2(N);
    int64_t sum = 0;
    int64_t max = 0;
    for(int i = 0;i < N + 1;i++) {
        cin >> A1.at(i);
        A2.at(i) = A1.at(i);
    }
    for(int i = 0;i < N;i++) {
        cin >> B1.at(i);
        B2.at(i) = B1.at(i);
    }
    for(int i = N;i > 0;i--) {
        if(B1.at(i - 1) - A1.at(i) > 0) {
            sum += A1.at(i);
            B1.at(i - 1) -= A1.at(i);
            A1.at(i) = 0;
        }else {
            sum += B1.at(i - 1);
            A1.at(i) -= B1.at(i - 1);
            B1.at(i - 1) = 0;
        }
        if(B1.at(i - 1) - A1.at(i - 1) > 0) {
            sum += A1.at(i - 1);
            B1.at(i - 1) -= A1.at(i - 1);
            A1.at(i - 1) = 0;
        }else {
            sum += B1.at(i - 1);
            A1.at(i - 1) -= B1.at(i - 1);
            B1.at(i - 1) = 0;
        }
    }
    max = sum;
    sum = 0;
    for(int i = 0;i < N;i++) {
        if(B2.at(i) - A2.at(i) > 0) {
            sum += A2.at(i);
            B2.at(i) -= A2.at(i);
            A2.at(i) = 0;
        }else {
            sum += B2.at(i);
            A2.at(i) -= B2.at(i);
            B2.at(i) = 0;
        }
        if(B2.at(i) - A2.at(i + 1) > 0) {
            sum += A2.at(i + 1);
            B2.at(i) -= A2.at(i + 1);
            A2.at(i + 1) = 0;
        }else {
            sum += B2.at(i);
            A2.at(i + 1) -= B2.at(i);
            B2.at(i) = 0;
        }
    }
    if(sum > max) {
        cout << sum << endl;
    }else {
        cout << max << endl;
    }
}


Measured memory_bytes: 1792
//a.insert(a.end(),b.begin(),b.end()); ／aの末尾にbの全範囲を追加するわけね。ググってすぐに出てこなくて頭に来たのでここに書いておく
#include <iostream>
#include <vector>
using namespace std;
void makeHanafuda(vector<int> &vec){
  for(int i = 0;i < vec.size();i++){
    vec[i] = vec.size()-i;
  }
}
vector<int> shuffle(int p,int c,vector<int> &vec,int n){//pからcぬきとる
  //  cout << vec[2] << endl;
  vector<int> f(p-1,0);
  vector<int> s(c,0);
  vector<int> t(n - (p-1+c),0); 

  for(int i = 0;i < n;i++){
    if(i < p-1)f[i] = vec[i];
    else if(i < p-1+c)s[i-(p-1)] = vec[i];
    else t[i-(p-1+c)] = vec[i];
  
  }

  s.insert(s.end(),f.begin(),f.end());
  s.insert(s.end(),t.begin(),t.end());

  return s;
}
int main(){

  while(1){
    int n,r;
    cin >> n >> r;
    if(n == 0 && r == 0)break;
    vector<int> hanafuda(n,10);
    makeHanafuda(hanafuda);
    for(int i = 0;i < r;i++){
      int p,c;
      cin >> p >> c;
      hanafuda = vector<int>(shuffle(p,c,hanafuda,n));

    }
    cout << hanafuda[0] << endl;
    /*    cout << "0----------------" << endl;
    for(int i = 0;i < n;i++){
      cout << hanafuda[i] << endl;
      }*/

  }
  return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
int main(){
  int N,A[100],i,j,a,min,count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  for(i=0;i<N-1;i++){
    min = i;
    for(j=i+1;j<N;j++){
      if(A[j]<A[min]) min = j;
    }
    if(A[i]!=A[min]) count++;
      a = A[i];
      A[i] = A[min];
      A[min] = a;
  }
  for(i=0;i<N;i++){
    if(i==0) printf("%d",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC137 B
int main() {
	int k, x;
	cin >> k >> x;

	int w = k - 1;
	for (int i=w; i>0; i--) {
		cout << x - i << endl;
	}
	cout << x << endl;
	for (int i=0; i<w; i++) {
		cout << x + i + 1 << endl;
	}
}

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

using namespace std;

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

  long long n, W; cin >> n >> W;
  long long w[n], v[n];
  for(long long i = 0; i<n; ++i) cin >> w[i] >> v[i];

  vector<long long> dp(100001, W+1);
  dp[0] = 0;
  long long ret = 0;
  for(long long i = 0; i<n; ++i) {
    for(long long j = 100000; j>=0; --j) {
      if(dp[j]+w[i] <= W) {
        dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
        ret = max(ret, j+v[i]);
      }
    }
  }

  cout << ret << endl;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqA = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

        var xs = new long[seqA.Length + 1];
        for (int i = 1; i < xs.Length; ++i)
        {
            xs[i] = xs[i - 1] + seqA[i - 1];
        }

        var p = (xs.Last() + 1) / 2;
        var ok = xs.Length - 1;
        var ng = -1;
        while (Math.Abs(ok - ng) > 1)
        {
            var m = (ng - ok) / 2 + ok;
            if (xs[m] < p)
            {
                ng = m;
            }
            else
            {
                ok = m;
            }
        }

        var cost = Math.Min(xs.Last() - xs[ok - 1] * 2, xs[ok] * 2 - xs.Last());
        Console.WriteLine(cost);
    }
}


Measured memory_bytes: 38784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
 
int d[105];

int main(){
	
	int n;cin>>n;
	rep(i,n) cin>>d[i];
	sort(d,d+n);
	int ans = 1;
	FOR(i,1,n-1)
	{
		if(d[i] == d[i-1]) continue;
		ans++;
	}
	cout << ans << endl;
}

//cout << ans << endl;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    Yes(a == b && b == c && c == a);

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
//#define mpr make_pair
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod 1000000007
#define inf 1e9
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    //cin>>tc;
    int cs=0;
    while(tc--)
    {
      int n;
      cin>>n;
      ll a[n];
      for(int i=0;i<n;i++)
        cin>>a[i];
        ll sum=0LL;
        ll mx=a[0];
      for(int i=1;i<n;i++)
      {
          mx=max(mx,a[i]);
          if(a[i]<mx) sum+=(mx-a[i]);
      }
      cout<<sum;
    }
}


Measured memory_bytes: 5216
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

void Calc() {
  string s = in;
  auto p = s.find("ST");
  while (p != s.npos) {
    int a = p, b = 2;
    err(a - 1, a + b);
    while (0 < a && a + b < size(s) && s[a - 1] == 'S' && s[a + b] == 'T') {
      a--;
      b += 2;
    }
    s.erase(a, b);
    err(s);
    p = s.find("ST");
  }
  cout << (size(s)) << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef string str;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

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



//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k ;
  cin >> n >> k ;
  vll sum(n+1) ;
  sum[0] = 0 ;
  for(int i=1;i<=n;i++){
    sum[i] = sum[i-1]+i ;
    sum[i] = sum[i]%MOD ;
  }
  ll i=k ;
  ll ans = 0 ;
  while(1){
    //cout << i*n-2*sum[i-1]+1 <<endl ;
    ans += (i*n-2*sum[i-1]+1) ;
    ans = ans%MOD ;
    i++ ;
    if(i==n+2){
      break ;
    }
  }
  cout << ans <<endl ;
  
  
  
  
  
  return 0 ;
}




Measured memory_bytes: 4748
L = input()
length = len(L)
a = 2
b = 1
c = 4
for l in L[1:]:
	if l  == '1':
		a = (a * 3) % 1000000007
		b = (b * 3) % 1000000007
		c = (c * 2) % 1000000007
	else:
		a = (a * 3 - c) % 1000000007
		b = (b * 3) % 1000000007
print((a + b)%1000000007)

Measured memory_bytes: 3188
while 1:
    n = int(input())
    if n == 0:
        break
    ans = []
    for i in range(n):
        l,p,a,b,c,d,e,f,s,m = input().split()
        p,a,b,c,d,e,f,s,m = map(int,[p,a,b,c,d,e,f,s,m])
        sum = s*f*m-p
        sum /= (a+b+c+d+e+(m-1)*(d+e))
        ans.append([l,sum])
    ans.sort(key = lambda x: x[0])
    ans.sort(key = lambda x: -x[1])
    for i in ans:
        print(i[0])
    print("#")


Measured memory_bytes: 5624
#include<stdio.h>
int main(void){
   int a, b, c, C = 0, H = 0;
   while ( scanf("%d,%d,%d", &a, &b, &c) != EOF ) {
      if ( c * c == a * a + b * b ) C++;
      else if ( a == b ) H++;
   }
   printf("%d\n%d\n", C, H);
   return 0;
}

Measured memory_bytes: 1696
s = input()
ans = 0
temp = 0
for i in range(len(s)):
  if s[i]=="A" or s[i]=="G"or s[i]=="T" or s[i]=="C":
    temp += 1
  else:
    ans = max(temp, ans)
    temp=0
ans = max(ans, temp)
print(ans)

Measured memory_bytes: 61312
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll n, x, ans;
vector <ll> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    a.resize(n+2, 0);
    for(int i = 1 ; i <= n ; i++)
        cin >> a[i];
    for(int i = 1 ; i < a.size() ; i++)
        ans += abs(a[i]-a[i-1]);
    for(int i = 1 ; i < a.size()-1 ; i++)
        cout << ans-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ll a, b, k;
    while(cin>>k>>a>>b){
        ll ans=0;
        if(b<=a+2){
            ans=1+k;
        }
        else{
            k-=a-1;
            ans=a;
            ans+=(k/2)*(b-a);
            ans+=k%2;
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll n;
string s;
 
int main() {
  cin >> n;
  cin >> s;
  string ans = "No";
  if(n%2==0){
    string s1 = s.substr(0,n/2);
    string s2 = s.substr(n/2,n/2);
    if(s1==s2){
      ans = "Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
// // // // // // // // // // // // // // // // // // //
int64 q;
int64 rs = -1;
int n,m,x;
int mat[15][15];
int price[15];
int used[15];
void solve(){
    vec v (15,0);
    int64 prices = 0;
    for (int i = 0; i < n; i++){
        if (used[i]){
            prices+=price[i];
            for (int j = 0; j < m; j++){
                v[j] += mat[i][j];
            }
        }
    }
    // nn;
    bool f = 0;
    for (int i = 0; i < m; i++){
        if (v[i] < x){
            return;
        }
    }
    if (rs == -1)
        rs = prices;
    else{
        rs = min(rs, prices);
    }
    return;
}

void backtrack(int step){
    if (step == n){
        solve();
        return;
    }
    used[step] = 1;
    backtrack(step+1);
    used[step] = 0;
    backtrack(step+1);
}
int main(){
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++){
        cin >> price[i];
        for (int j = 0; j < m; j++){
            cin >> mat[i][j];
        }
    }
    backtrack(0);
    ctn(rs);
    return 0;
}


Measured memory_bytes: 3632
S = input()
T = input()
ls = len(S)
lt = len(T)
for i in range(ls-lt,-1,-1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j] :
            break
    else:
        #置換処理
        S = [c if c != "?" else "a" for c in S]
        S[i:i+lt] = list(T)
        S = "".join(S)
        break
else:
    S = "UNRESTORABLE"
print(S)

Measured memory_bytes: 3064
#include <iostream>

int main() {
  int n;
  bool can = true;
  std::cin >> n;
  for (int i = 0, a; i < n; ++i) {
    std::cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) can = false;
  }
  if (can) std::cout << "APPROVED" << std::endl;
  else std::cout << "DENIED" << std::endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
 
class Program {
  static void Main() {
    int acCount = 0,
        waCount = 0,
        tleCount = 0,
        reCount = 0;
    
    int caseCount = int.Parse(Console.ReadLine());
    for(int i = 0; i < caseCount; i++) {
      string errorType = Console.ReadLine();
      switch(errorType) {
         case "AC":
          acCount++;
          break;
         case "WA":
          waCount++;
          break;
         case "TLE":
          tleCount++;
          break;
         case "RE":
          reCount++;
          break;
      }
    }
    
    StringBuilder result = new StringBuilder();
    result.AppendLine($"AC x {acCount}").
      AppendLine($"WA x {waCount}").
      AppendLine($"TLE x {tleCount}").
      AppendLine($"RE x {reCount}");
    Console.WriteLine(result);
  }
}


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

const int N = 510;

int n, cntx[N], cnty[N];
char s[N][N];

int main(){
	scanf("%d", &n);
	int min = INT_MAX;
	bool flag = false;
	for (int i = 0; i < n; ++ i){
		scanf("%s", s[i]);
		for (int j = 0; j < n; ++ j){
			if (s[i][j] == '#'){
				flag = true;
				++ cntx[i];
				++ cnty[j];
			}
		}
	}
	if (!flag){
		return printf("-1\n"), 0;
	}
	for (int i = 0; i < n; ++ i){
		min = std::min(n - cntx[i] + !cnty[i], min);
	}
	int ans = n + min;
	for (int j = 0; j < n; ++ j){
		if (cnty[j] == n){
			-- ans;
		}
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 512
/// [Amberjack] CUT BEGIN
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define __GET_REP_MACRO(_1,_2,_3,NAME,...) NAME
#define __REP0(i,n) for(_loop_int i=0;i<(n);++i)
#define __REP1(i,a,b) for(_loop_int i=(a);i<(b);++i)
#define __REPR0(i,n) for(_loop_int i=(n)-1;i>=0;--i)
#define __REPR1(i,a,b) for(_loop_int i=(b)-1;i>=(a);--i)
#define REP(...) __GET_REP_MACRO(__VA_ARGS__,__REP1,__REP0)(__VA_ARGS__)
#define REPR(...) __GET_REP_MACRO(__VA_ARGS__,__REPR1,__REPR0)(__VA_ARGS__)

#ifdef BURI
#define __DEBUG0() "Hello"
#define __DEBUG1(x) #x"("<<(x)<<")"
#define __DEBUG2(x,...) #x"("<<(x)<<"), " __DEBUG1(__VA_ARGS__)
#define __DEBUG3(x,...) #x"("<<(x)<<"), " __DEBUG2(__VA_ARGS__)
#define __DEBUG4(x,...) #x"("<<(x)<<"), " __DEBUG3(__VA_ARGS__)
#define __DEBUG5(x,...) #x"("<<(x)<<"), " __DEBUG4(__VA_ARGS__)
#define __GET_DEBUG_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define __DEBUG(...) __GET_DEBUG_MACRO(__VA_ARGS__,__DEBUG5,__DEBUG4,__DEBUG3,__DEBUG2,__DEBUG1,__DEBUG0)(__VA_ARGS__)
#define DEBUG(...) cerr<<__DEBUG(__VA_ARGS__)<<endl
#else
#define DEBUG(...)
#endif

inline void getll(ll &x){
  int sgn=1;x=0;
  char c=getchar();
  while(c!='-'&&(c<'0'||c>'9'))c=getchar();
  if(c=='-') sgn=-1; else x=c-'0';
  c=getchar();
  while('0'<=c&&c<='9'){
    x*=10;
    x+=c-'0';
    c=getchar();
  }
  x*=sgn;
}
inline void read(ll &x){getll(x);}
inline void read(int &x){ll y;getll(y);x=y;}
inline void read(float &x){scanf("%f",&x);}
inline void read(double &x){scanf("%lf",&x);}
inline void read(long double &x){scanf("%Lf",&x);}
inline void read(char *s){scanf("%s",s);}
inline void read(string &s){int len=s.size();char *buf=(char*)malloc(len*sizeof(char));scanf("%s",buf);s=string(buf);free(buf);}
inline void read(char &c){char *buf=(char*)malloc(5*sizeof(char));scanf("%s",buf);c=buf[0];free(buf);}
inline void read(){}
template<typename S,typename ...T>
inline void read(S& first, T&... rest){
  read(first);
  read(rest...);
}
/// [/Amberjack] CUT END

int w,h;
ll p[125252],q[125252];
int main(){
  read(w,h);
  REP(i,w)read(p[i]);
  REP(i,h)read(q[i]);
  sort(p,p+w);
  sort(q,q+h);
  int j=0,k=0;
  ll ans=0;
  REP(i,w+h){
    if((j<w&&k<h&&p[j]<q[k]) || k==h){
      ans += (ll)(h+1-k)*p[j++];
    }else{
      ans += (ll)(w+1-j)*q[k++];
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = input()
list1 = list(map(int,a.split()))

dp = [0]*n
dp[1] = abs(list1[1]-list1[0])

for i in range(1,n-1):
    dp[i+1] = min(dp[i-1]+abs(list1[i+1]-list1[i-1]),dp[i]+abs(list1[i+1]-list1[i]))

print(dp[-1])





Measured memory_bytes: 14400
def rec(m,i,j)
  m[i][j]=0
  rec(m,i,j+1) if j<11 and m[i][j+1]==1
  rec(m,i,j-1) if j>0 and m[i][j-1]==1
  rec(m,i+1,j) if i<11 and m[i+1][j]==1
  rec(m,i-1,j) if i>0 and m[i-1][j]==1
  return m
end
loop do
  m,c,t=[],0,12
  t.times{m<<gets.split("").map(&:to_i)}
  t.times{|i|
    t.times{|j|
      if m[i][j]==1
        m=rec(m,i,j)
        c+=1
      end
    }
  }
  p c
  break if !gets
end

Measured memory_bytes: 8812
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=5005;
bitset<MAXN> pre[MAXN],suf[MAXN],now;
int n,K,a[MAXN]; 
int main()
{
	n=read();K=read();
	for(int i=1;i<=n;i++)a[i]=read();
	pre[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		int x=min(K,a[i]);
		pre[i]=pre[i-1]|(pre[i-1]<<x);
	}
	suf[n+1][0]=1;
	for(int i=n;i>=1;i--)
	{
		int x=min(K,a[i]);
		suf[i]=suf[i+1]|(suf[i+1]<<x);
	}int ans=n;
	for(int i=1;i<=n;i++)
	{
		int mx=0;
		for(int j=0,u=K-1;j<K;j++)if(pre[i-1][j])
		{
			while(j+u>=K)--u;
			while(u&&!suf[i+1][u])--u;
			chkmax(mx,u+j);
		}
		if(mx+a[i]>=K)--ans;
	}pr2(ans);
	return 0;
}



Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1000000007; 
//動画解答写し
int main() {
  int n,m;
  cin>>n>>m;
  vector<int>broken(n+1);
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    broken[a]=1;
  }
  vector<int>dp(n+2);
  dp[n]=1;
  for(int i=n-1;i>=0;i--){
    if(broken[i]){
      dp[i]=0;
      continue;
    }
    dp[i]=(dp[i+1]+dp[i+2])%MOD; 
  }
  cout<<dp[0]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

  int n;
  cin >> n;
  if(n % 2 == 0) {
    int m = (n - 2) * n / 2;
    cout << m << endl;
    for(int i = 1;i <= n; i++) {
      for(int j = i + 1; j <= n; j++) {
        if(i + j == n + 1) continue;
        cout << i << " " << j << endl;
      }
    }
  }
  else{
    int n2 = n - 1;
    int m = (n2 - 2) * n2 / 2;
    m += n2;
    cout << m << endl;
    for(int i = 1;i <= n2; i++) {
      for(int j = i + 1; j <= n2; j++) {
        if(i + j == n2 + 1) continue;
        cout << i << " " << j << endl;
      }
    }
    for(int i = 1; i < n; i++) {
      cout << i << " " << n << endl;
    }
  }
}

Measured memory_bytes: 256
print("YES" if input() in ['KIHBR', 'KIHBRA', 'KIHBAR', 'KIHBARA', 'KIHABR', 'KIHABRA', 'KIHABAR', 'KIHABARA', 'AKIHBR', 'AKIHBRA', 'AKIHBAR', 'AKIHBARA', 'AKIHABR', 'AKIHABRA', 'AKIHABAR', 'AKIHABARA'] else "NO")

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void){
    int N;
    scanf("%d",&N);
    int M;
    if(N%2==0){
        M=N/2;
    }
    else{
        M=N/2+1;
    }
    printf("%d",M);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,n;
	scanf("%d%d",&m,&n);
	if(m>0 && n>0)
	{
		if(n>m) printf("%d",n-m);
		else if(n<m) printf("%d",m-n+2);
		else printf("0");
	}
	if(m<0 && n<0)
	{
		if(n>m) printf("%d",n-m);
		else if(n<m) printf("%d",m-n+2);
		else printf("0");
	}
	if(m>0 && n<0)
	{
		if(-n>m) printf("%d",-n-m+1);
		else if(-n<m) printf("%d",m+n+1);
		else printf("1");
	}
	if(m<0 && n>0)
	{
		if(n>-m) printf("%d",m+n+1);
		else if(n<-m) printf("%d",-m-n+1);
		else printf("1");
	}
	if(m==0)
	{
		if(n>0) printf("%d",n);
		else if(n<0) printf("%d",-n+1);
		else printf("0");
	}
	if(n==0)
	{
		if(m<0) printf("%d",-m);
		if(m>0) printf("%d",m+1);
	}
	return 0;
} 

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

int main(int argc,char *argv[])
{
	int n;
	std::cin >> n;

	std::vector<int> x(n,0);
	for(int i = 0;i < n;++i) std::cin >> x[i];

	int min = 99999999;
	for(int i = 0;i < 100;++i)
	{
		int tmp = i+1;
		int ans = 0;
		for(int j = 0;j < n;++j) ans += (x[j]-tmp)*(x[j]-tmp);
		if (ans < min) min = ans;
	}

	std::cout << min << std::endl;

	return 0;
}


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

#define ll long long
#define pb push_back

using namespace std;

int main()
{
    int n;
    string s;

    set <string> item;

    cin >> n;

    while(n--) {
        cin >> s;
        item.insert(s);
    }

    cout << item.size() << "\n";

    return 0;
}




Measured memory_bytes: 19152
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL a,b,c,d,e,n,m,l,r,x,y,z,ans=0,ans2=0;
string s,S,t;
int main() {
ios_base::sync_with_stdio(false);
  cin >> l>>r>>d;
for(int i=l;i<=r;i++)if(i%d==0)ans2++;
cout << ans2;
}

Measured memory_bytes: 3648
function Main(arg)
{
  var N = arg.split("\n")[0] - 0;
  var S = arg.split("\n").slice(1);

  var tmp = new Set(S[0]);
  tmp = Array.from(tmp).join("").toString();

  var a = [];
  for (var s = 0; s < tmp.length; s++){

    var f = true;
    for (var i = 1; i < N; i++){
      if (S[i].indexOf(tmp[s]) === -1) {
        f = false;
        break;
      }
    }

    if (f) a.push(tmp[s]);
  }

  var len = {};

  for (var i = 0; i < a.length; i++){
    var b = S[0].split("");
    b = b.filter( v => v===a[i] );
    len[a[i]] = b.length;
  }

  for (var j = 1; j < N; j++) {

    for (var i = 0; i < a.length; i++){
      var b = S[j].split("");
      b = b.filter( v => v===a[i] );
      len[a[i]] = Math.min(len[a[i]], b.length);
    }
  }

  var ans = "";
  Object.keys(len).forEach(function (key) {
    var rep = len[key] - 0;
    ans += key.repeat(rep);
  });

  console.log(ans.split("").sort().join(""));
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, k;
	cin >> n >> k;

	vector<int> v(n, 0);

	rep(i, k) {
		int d;
		cin >> d;
		rep(j, d) {
			int a;
			cin >> a;
			a--;
			v[a]++;
		}
	}

	int cnt = 0;
	rep(i, sz(v)) {
		if (v[i] == 0) {
			cnt++;
		}
	}

	out(cnt);

	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int k,s;
    cin >> k >> s;
    int cnt = 0;
    for(int i = 0;i<=k;++i){
        for(int j = 0;j<=k;++j){
            if(i + j <= s && s - (i + j) <= k) ++cnt;
        }
    }   
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}else if(a<b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    double n, m;
    cin >> n >> m;
    double a[ll(n)];
    rp(i, 0, n) cin >> a[i];
    double sum = 0;
    rp(i, 0, n) sum += a[i];
    ll ans = 0;
    rp(i, 0, n)
    {
        if (a[i] >= sum / 4 / m)
        {
            ans++;
        }
    }
    if (ans >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = s[0];
        int m = s[1];
        int c = s[2];
        int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int count = 0;
        for (int i = 0; i < n; i ++) {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int sum = 0;
            for (int j = 0; j < m; j ++) {
                sum += a[j]*b[j];
                if (j == m-1) {
                    if (sum + c > 0) count ++;
                }
            } 
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13396
// Wrong solution :-(

/* Fix https://www.youtube.com/watch?v=iYS8l9_A-vY

for each word, compress it to one of three forms:
1:  (((((
2:  )))
3:  ))))((((

place compressed strings of the first form at the beginning sequence

place compressed strings of the second form at the end of sequence

divide the compressed strings of the third form into two groups:
3a:  those with at least as many openning brackets as closing brackets
3b:  those with more closing brackets than openning brackets

First place groups 3a and then group 3b.

For group 3a, place them in the order of increasing number of closing brackets

For group 3b, place them in the order of decreasing balance (opening - closing)

While processing groups 3a and 3b, check whether balance becomes negative.

*/

// Correct solution: https://codeforces.com/blog/entry/77148?#comment-619728

//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(x...) cerr << __LINE__ << ": " << #x << " = "; DBG::_print(x)
#else
#define DEBUG(x...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;

#define MAXN 1000000
int N;
string S[MAXN];

bool solve() {
   int nopen = 0, nclose = 0;
   vector<II> mixed_pos, mixed_neg;
   REP(i, N) {
      int bal = 0, min_bal = 0;
      for (char c : S[i]) {
         if (c == '(')
            ++bal;
         else {
            --bal;
            min_bal = min(min_bal, bal);
         }
      }
      int deficit = -min_bal;
      if (deficit == 0)
         nopen += bal;
      else if (-bal == deficit)
         nclose += deficit;
      else if (bal >= 0)
         mixed_pos.push_back({deficit, bal});
      else
         mixed_neg.push_back({deficit, bal});
   }

   int cur_bal = 0;
   cur_bal += nopen;

   sort(mixed_pos.begin(), mixed_pos.end());
   for (II p : mixed_pos) {
      if (cur_bal - p.first < 0)
         return false;
      cur_bal += p.second;
   }
   
   sort(mixed_neg.begin(), mixed_neg.end(),
   [&] (II a, II b) -> bool {
      return a.second > b.second;
   });
   for (II p : mixed_neg) {
      if (cur_bal - p.first < 0)
         return false;
      cur_bal += p.second;
   }

   cur_bal -= nclose;

   return cur_bal == 0;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> N;
   REP(i, N)
      cin >> S[i];

   bool res = solve();
   cout << (res ? "Yes" : "No") << '\n';

   return 0;
}


Measured memory_bytes: 36724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll ret = modpow(x, n/2);
    if(n%2 == 0) return ret*ret%mod;
    else return ret*ret%mod*x%mod;
}

int main(){
    string L; cin >> L;
    int N = L.size();
    L = 'x' + L;
    ll ans = 0;

    vector<ll> cum1(N+5, 0);
    for(int i=1; i<=N; ++i){
        if(L[i] == '0') cum1[i] = cum1[i-1];
        else cum1[i] = cum1[i-1]+1;
    }
    
    // Lと左から比べた時に初めてLと違うビットが出てくる位置で全探索する
    // !!注意!! この全探索の仕方だとLより小さい数しか見ないので、L自体は別にチェックする必要がある
    for(int i=1; i<=N; ++i){
        if(L[i] == '0') continue;

        ll tmp = 1;
        tmp *= modpow(2, cum1[i-1]);
        tmp %= mod;
        tmp *= modpow(3, N-i);
        tmp %= mod;
    
        ans += tmp;
        ans %= mod;
    }

    ll tmp = 1;
    for(int i=1; i<=N; ++i){
        if(L[i] == '1') tmp = tmp*2%mod;
    }

    ans += tmp;
    ans %= mod;

    cout << ans << endl;    

    return 0;
}

Measured memory_bytes: 1276
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

typedef unsigned long long ull;

ull b=1000000007;

int main()
{
  string s, p;
  int n, m;
  ull t = 1, sh = 0, ph = 0;

  cin >> s >> p;

  n = s.length();
  m = p.length();

  if(n < m) {
    return 0;
  }

  for(int i = 0; i < m; i++) {
    t *= b;
  }
  for(int i = 0; i < m; i++) {
    sh = sh * b + s[i];
  }
  for(int i=0;i<m;i++) {
    ph = ph * b + p[i];
  }

  for(int i = 0; i + m <= n; i++) {
    if(sh == ph) {
      printf("%d\n",i);
    }
    if(i + m < n) {
      sh = sh * b + s[i + m] - s[i] * t;
    }
  }
 
  return 0;
}


Measured memory_bytes: 3996
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
using namespace std;

int main(){
  int n;  cin >> n;
  vector<int> o(50000), e(50000);
  map<int, int> mp_o, mp_e;

  rep(i, 0, n){
    cin >> ((i%2==0) ? e[i/2] : o[i/2]);
  }
  mp_o[0] = 0;
  mp_e[0] = 0;
  rep(i, 0, n/2){
    mp_o[o[i]]++;
    mp_e[e[i]]++;
  }

  int ans;
  int O, OM1 = 0, OM2 = -1;
  int E, EM1 = 0, EM2 = -1;

  for(auto it = mp_o.begin(); it != mp_o.end(); it++){
    if(OM1 <= it->second){
      O = it->first;
      OM2 = OM1;
      OM1 = it->second;
    }else if(OM2 <= it->second){
      OM2 = it->second;
    }
  }
  for(auto it = mp_e.begin(); it != mp_e.end(); it++){
    if(EM1 <= it->second){
      E = it->first;
      EM2 = EM1;
      EM1 = it->second;
    }else if(EM2 <= it->second){
      EM2 = it->second;
    }
  }

  if(O == E){
    ans = n - max(OM1 + EM2, OM2 + EM1);
  }
  else{
    ans = n - OM1 - EM1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

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

  int m = n*(n-1)/2 - n/2;
  cout << m << endl;
  for(int i = 1; i < n+1; i++) {
    for(int j = i+1; j < n+1; j++) {
      if(n%2 == 1){
        if(i+j == n) continue;
      }
      else{
        if(i+j == n+1) continue;
      }
      cout << i << " " << j << endl;
    }
  }

}

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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  // 初期状態
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index にしておく

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 4780
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    else {
        return gcd(y, x%y);
    }
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll g = gcd(c, d);
    ll c1 = c/g;
    ll d1 = d/g;
    ll e = g*c1*d1;
    ll s = b/c + b/d - b/e;
    ll t = (a-1)/c + (a-1)/d - (a-1)/e;
    ll ans = (b - a + 1) - (s - t);

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long n = in.nextLong();

			if (n % 2 == 0) {
				out.println(n);
			} else {
				out.println((long)2*n);
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int h,w;
  cin >> h >> w;
  set<pair<int,int>> s;
  int n;
  cin >> n;
  rep(i,n){
    int x,y;
    cin >> x >> y;
    s.insert(make_pair(x,y));
  }
  int k[h];
  k[0]=1;
  rep(i,h-1){
    if(k[i]==h)k[i+1]=h;
    else{
      if(s.count(make_pair(i+2,k[i]+1))){
        k[i+1]=k[i];
      }
      else{
        k[i+1]=k[i]+1;
      }
    }
  }
  int ans=h;
  for(pair<int,int>p: s){
    int x=p.first,y=p.second;
    if(x==1)continue;
    if(k[x-2]>=y)ans=min(ans,x-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 13784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  string a[100];
  for (int i = 0; i < H; i++) cin >> a[i];
  
  for (int i = 0; i < H + 2; i++)
  {
  	for (int j = 0; j < W + 2; j++)
    {
    	if (i == 0) cout << '#';
      	else if (i == H + 1) cout << '#';
      	else if (j == 0) cout << '#';
      	else if (j == W + 1) cout << '#';
      	else cout << a[i-1][j-1];
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 256