akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string s;
char str[1000010];
int d[1000010][2];
int res=0;
int main()
{
	scanf("%s",&str);
	s=str;
	reverse(s.begin(),s.end());
	s+='0';
	d[0][0]=s[0]-'0';
	d[0][1]=10-(s[0]-'0');
	for (int i=1;i<s.size();i++)
	{
		d[i][0]=min(d[i-1][0],d[i-1][1]+1)+s[i]-'0';
		d[i][1]=min(d[i-1][0]+(10-(s[i]-'0')),d[i-1][1]+(10-(s[i]-'0'+1)));
	}
	cout <<min(d[s.size()-1][0],d[s.size()-1][1]);
	return 0;
}

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

int main(){
  int N;
  string S;
  
  int cnt=0;
  
  cin >> N >> S;
  
  for(int i = 0; i < N; i++){
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
      cnt++;
    }
  }
  
  cout << cnt << endl;
}

      


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

const int MOD=1e9+7;
int add(int x,int y){return(x+=y)<MOD?x:x-MOD;}
int sub(int x,int y){return(x-=y)>= 0?x:x+MOD;}

int dp[1<<21];
int n,a[21][21];

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      scanf("%d",&a[i][j]);
    }
  }
  dp[0]=1;
  for(int b=1;b<(1<<n);++b){
    int bc=__builtin_popcount(b)-1;
    for(int i=0;i<n;++i){
      if((b>>i&1)&&a[bc][i]){
        dp[b]=add(dp[b],dp[b^(1<<i)]);
      }
    }
  }
  printf("%d\n",dp[(1<<n)-1]);
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(unsigned ll i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MOD 1000000007LL
#define pi 3.14159265358979323846
ll binary_power(ll a, ll n) {
    if (n==0) return 1;
    ll k=binary_power(a,n/2);
    if (n%2==0) return (k*k)%MOD;
    else return (((k*k)%MOD)*a)%MOD;
}
bool isPrime(int num){
    bool flag=true;
    for(int i = 2; i*i <= num ; i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

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

void solve()
{
    long long r; cin>>r;
    cout<<2*(pi)*r;
}

int main()
{
    SPEED;
    ll t = 1;

  // cin>>t;

    while(t--) solve();

   return 0;
}


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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k ;
  if(b==0 || c ==0) return 0;
  for(int i=1 ; i<=k ;i++){
    if(a >= b ){
      b = b * 2;
    }
    else if(b >= c){
      c = c * 2;
    }
  }
  if((a<b) && (b < c)) cout << "Yes";
  else cout << "No";
  
}



Measured memory_bytes: 3560
#include<algorithm>
#include<cmath>//切り上げceil()
#include<deque>
#include<iomanip>//setprecision()
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int n;   cin >> n;
  vi v(n),c(n);
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }
  int ans = 0;
  rep(i,n){
    if(v[i]-c[i] > 0){
      ans += v[i]-c[i];
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

auto input(size_t n) {
    return InputType2(n);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

using ll = long long;
using ull = unsigned long long;

int main() {
    string s = input();
    auto n = s.size();
    for (size_t i = 0; i < 3; ++i) {
        auto l = i == 2 ? (n + 3) / 2 : 0;
        auto r = i == 1 ? n / 2 : n;
        for (size_t i = l; i < r; ++i) {
            if (s[i] != s[r - i - 1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void exgcd(int a,int b,int &x,int &y){
	if(b==0) return (void)(x=1,y=0);
	exgcd(b,a%b,y,x);
	y-=(a/b)*x;
}
int inv(int a,int mod){
	int x,y;
	exgcd(a,mod,x,y);
	return (x%mod+mod)%mod;
}
int getY(int x,int C,int D){
	return x==0?C:(C-1ll*x*D%C)%C;
}
void solve(){
	int A,X,B,Y,C,g;
	cin>>A>>X>>B>>Y>>C;
	g=__gcd(A,B); A/=g; B/=g; C/=__gcd(g,C);
	g=__gcd(A,C); A/=g; C/=g; Y/=g;
	g=__gcd(B,C); B/=g; C/=g; X/=g;
	A%=C;B%=C;if(C==1) return (void)(cout<<X+Y<<endl);
	int D=1ll*A*inv(B,C)%C;
	int W=C,H=D,now=0,invD=inv(D,C),tmp;
	vector<int> pos,cnt; //等差数列的起始值与点的数量 
	while(W){
		H=(H-1)%W+1;tmp=W/H;
		pos.push_back(1ll*now*invD%C);
		cnt.push_back(tmp);
		now+=tmp*H;W-=tmp*H;
	}
	pos.push_back(C);
	long long ans=0;
	for(int i=0;i<cnt.size();++i){
		int lx=pos[i],ly=getY(lx,C,D);
		int rx=pos[i+1],ry=getY(rx,C,D);
		int del_x=(rx-lx)/cnt[i],del_y=(ly-ry)/cnt[i];
		long long mid,l=0,r=X+Y,res=0;
		while(l<=r){
			mid=(l+r)>>1;
			long long p=(X-mid*lx),q=(Y-mid*ry);
			if(p>=0 && q>=0 && p/del_x+q/del_y>=mid*(cnt[i])) res=mid,l=mid+1;
			else r=mid-1;
		}
		ans=max(ans,res);
	}
	cout<<ans<<endl;
}
signed main(){
	int T;cin>>T;
	while(T--) solve();
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 1020
#define inf 1000000007

using namespace std;
typedef long long ll;
ll ansp,ansq,a[maxn],b[maxn],n,p,q,s[maxn],u,d,x,y,l,r;
bool f[maxn],g[maxn];

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        if (i&1) scanf("%lld",&a[++p]);
        else scanf("%lld",&b[++q]);
    }
    for (int i=1;i<=p;i++) if (a[i]>=0) ansp+=a[i]; else f[i]=true;
    for (int i=1;i<=q;i++) if (b[i]>=0) ansq+=b[i]; else g[i]=true;
    if (ansp<=0&&ansq<=0){
        u=1; d=a[1];
        for (int i=2;i<=p;i++) if (a[i]>d) d=a[i],u=i*2-1;
        for (int i=1;i<=q;i++) if (b[i]>d) d=b[i],u=i*2;
        cout << d << endl;
        cout << n-1 << endl;
        for (int i=n;i>u;i--) cout << i << endl;
        for (int i=1;i<u;i++) cout << 1 << endl;
    }
    else if (ansp>ansq){
        y=1; for (int i=2;i<=p;i++) if (a[i]>0) y=i;
        x=p; for (int i=p-1;i;i--) if (a[i]>0) x=i;
        l=x*2-1; r=y*2-1;
        cout << ansp << endl;
        cout << (y-x)+(l-1)+(n-r) << endl;
        for (int i=n;i>r;i--) cout << i << endl;
        for (int i=1;i<l;i++) cout << 1 << endl;
        for (int i=x;i<y;i++) if (a[i+1]>0) cout << 2 << endl; else cout << 3 << endl;
    }
    else {
        y=1; for (int i=2;i<=q;i++) if (b[i]>0) y=i;
        x=q; for (int i=q-1;i;i--) if (b[i]>0) x=i;
        l=x*2; r=y*2;
        cout << ansq << endl;
        cout << (y-x)+(l-1)+(n-r) << endl;
        for (int i=n;i>r;i--) cout << i << endl;
        for (int i=1;i<l;i++) cout << 1 << endl;
        for (int i=x;i<y;i++) if (b[i+1]>0) cout << 2 << endl; else cout << 3 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    rep(i,0,n-1){
        while(a[i]%2==0){
            ans++;
            a[i]/=2;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}




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

using namespace std;

int main(int argc, char const *argv[]) {
  string t, p;  cin >> t >> p;
  int len = p.size();
  if (t.size() >= len) {
    for (int i = 0; i < t.size() - len + 1; ++i) {
      string s;
      s = t.substr(i, len);
      if (s == p) cout << i << '\n';
    }
  }

  return 0;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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


Measured memory_bytes: 3092
n = gets.chomp.to_i
w = gets.chomp.split.map(&:to_i)
sum = w.inject(:+)
min = sum
part_sum = 0
(0..(n-1)).each do |num|
  part_sum += w[num]
  tmp = (part_sum - (sum - part_sum)).abs
  min = tmp if tmp < min
end

puts min


Measured memory_bytes: 1788
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 1e3 + 5;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);
int dp[MXN][MXN];
string s[MXN];
int main()
{
    IOS;
    int h, w;
    cin >> h >> w;
    dp[0][0] = 1;
    FOR(i, 0, h) { cin >> s[i]; }
    FOR(i, 0, h)
    {
        dp[i][0] = ((!i || (s[i][0] == '.' && dp[i - 1][0])) ? 1 : 0);
    }
    FOR(j, 0, w)
    {
        dp[0][j] = ((!j || (s[0][j] == '.' && dp[0][j - 1])) ? 1 : 0);
    }
    FOR(i, 1, h) FOR(j, 1, w)
    {
        if (s[i][j] == '.')
        {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[h - 1][w - 1] << '\n';
}


Measured memory_bytes: 8564
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int area = a * b;
            int length = (a + b) * 2;

            System.out.println(area + " " + length);
         }
        }


Measured memory_bytes: 26104
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let A = parseInt(xs[0]);
   let B = parseInt(xs[1]);
   let C = parseInt(xs[2]);
   let X = parseInt(xs[3]);
   let ans = 0;
   
   for(let i=0; i<=A; i++){
      for(let j=0; j<=B; j++){
         for(let k=0; k<=C; k++){
           if(500*i+100*j+50*k==X)
             ans++
         } 
      }
   }
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 32532
n = int(input())

divs = [0] * (n + 1)
for i in range(1, (n + 1)):
    for j in range(i, (n + 1), i):
        divs[j] += 1

ans = 0

for idx, div in enumerate(divs):
    if div == 8 and idx % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 63976
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(a: int, b: int, x: int):
    A = (a - 1) // x
    B = b // x
    ret = B - A
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    solve(a, b, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//============================================================================
// Name        : Calc.cpp
// Author      : Roman
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <fstream>

using namespace std;



int main() {

	// ifstream cin ("/Users/shuffler/Documents/workspace/Calc/src/input.txt");
	// ofstream cout ("/Users/shuffler/Documents/workspace/Calc/src/output.txt");

	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	srand(179);
	int n, m;
	cin >> n >> m;
	vector < vector < char > > gr(n, vector < char > (m));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> gr[i][j];
		}
	}
	auto bl = gr;
	auto red = gr;
	for (int i = 0; i < n; ++i) {
		red[i][0] = '#';
		bl[i][m - 1] = '#';
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j + 1 < m; ++j) {
			if (i % 2 == 0) {
				red[i][j] = '#';
			} else {
				bl[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cout << red[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cout << bl[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
const ll INF=2e18;

ll N,K;
ll a[100010];
map<ll,ll> mp;
int main(){
    cin>>N>>K;
    for(ll i=0;i<N;i++){
      cin>>a[i];
    }
    ll ans=0;
    for(ll i=0;i<N;i++){
      ll cnt=0;
      for(ll j=0;j<N;j++){
        if(a[i]>a[j]){
          cnt++;
        }
      }
      ll plus=K*(K-1)/2%MOD;
      plus=cnt*plus%MOD;
      ans=(ans+plus)%MOD;
    }
    for(ll i=0;i<N;i++){
      ll cnt=0;
      for(ll j=i+1;j<N;j++){
        if(a[i]>a[j]){
          cnt++;
        }
      }
      ans=(ans+cnt*K)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#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 long double PI = acos(-1);

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

	string s, t;
	cin >> s >> t;

	map<char, char> ms, mt;
	rep(i, sz(s)) {
		if (ms.count(s[i])) {
			if (ms[s[i]] != t[i]) {
				out("No");
				return 0;
			}
		}
		if (mt.count(t[i])) {
			if (mt[t[i]] != s[i]) {
				out("No");
				return 0;
			}
		}
		ms[s[i]] = t[i];
		mt[t[i]] = s[i];
	}

	out("Yes");

	return 0;
}

Measured memory_bytes: 916
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

a = [i+1 for i in range(n)]
for i, per in enumerate(list(permutations(a))):
    if per == p:
        x = i
    if per == q:
        y = i
print(abs(x-y))

Measured memory_bytes: 8052
//
// Created by tac on 2016/10/12.
//

#include <cstdlib>
#include <iostream>

int count_divisor(int a, int b, int c) {
    int count = 0;
    for (int i = a; i <= b; ++i) {
        if (c % i == 0) {
            ++count;
        }
    }
    return count;
}

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    std::cout << count_divisor(a, b, c) << std::endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3064
A,B,C,D = map(int,input().split())
XX = C - A
YY = D - B
if XX >= 0:
  ans1 = 'R'*XX
  ans11 = 'L'*XX
elif XX < 0:
  ans1 = 'L'*abs(XX)
  ans11 = 'R'*abs(XX)
if YY >= 0:
  ans2 = 'U'*YY
  ans22 = 'D'*YY
elif YY < 0:
  ans2 = 'D'*abs(YY)
  ans22 = 'U'*abs(YY)
ans3 = ans1 + ans2
ans4 = ans11 + ans22

if XX >= 0 and YY >= 0:
  ans5 = 'L'+ ans2 +'U' +'R' + ans1 +'D'
  ans55 = 'R' + ans22 + 'D' + 'L' + ans11 + 'U'
elif XX < 0 and YY >= 0:
  ans5 = 'R' + ans2 + 'U' + 'L' + ans1 + 'D'
  ans55 = 'L' + ans22 + 'D' + 'R' + ans11 + 'U'
elif XX >=0 and YY <0:
  ans5 = 'L' + ans2 + 'D' + 'R' + ans1 +'U'
  ans55 = 'R' + ans22 + 'U' + 'L' + ans11 + 'D'
else:
  ans5 = 'R' + ans2 +'D' + 'L' + ans1 + 'U'
  ans55 = 'L' + ans22 + 'U' + 'R' + ans11 + 'D'
print(ans3+ans4+ans5+ans55)

Measured memory_bytes: 9284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define SORT(A) sort(A.begin(), A.end())

int main() {
    ll a,b;
    cin >> a >> b;

    ll g;
    for(ll i = min(a,b); i > 0; i--){
        if(a % i == 0 && b % i == 0){
            a /= i;
            b /= i;
            g = i;
            break;
        }
    }

    cout << a * b * g << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string a, b;
    cin >> a >> b;
    a += b;
    int x = atoi(a.c_str());
    int y = sqrt(x);
    cout << (x == y * y ? "Yes" : "No") << endl;
    
    return 0;
}

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


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}

int main(){
	ull n;
	cin >> n;
	ull a[n*3],ans = 0;
	
	rep(i,0,n*3){
		cin >> a[i];
	}
	
	sort(a,a+n*3,greater<ull>());
	
	rep(i,0,n){
		ans += a[i*2+1];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
   int X;
   cin>>X;
   bool a=false;
   rep(i,1007){
    if(i*100<=X&&X<=i*105){
           a=true;
           break;
       }
   }
   if(a==true){
       cout<<1<<endl;
   }
   else
   {
       cout<<0<<endl;
   }
}

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

int N;
int A[200000];

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);
    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
}

Measured memory_bytes: 1024
n = int(input())
s = list(input())
w, e = [0] * (n + 1), [0] * (n + 1)
ans = float("inf")
for i in range(n):
    if s[i] == "W":
        w[i + 1] = w[i] + 1
    else:
        w[i + 1] = w[i]

    if s[n - i - 1] == "E":
        e[i + 1] = e[i] + 1
    else:
        e[i + 1] = e[i]

for j in range(1, n + 1):
    ans = min(ans, w[j] + e[n - j + 1])

print(ans - 1)


Measured memory_bytes: 91248
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    a,b = mi()
    for i in range(2000):
        if floor(i*0.08) == a:
            if floor(i*0.1) == b:
                print(i)
                exit()
    print(-1)




main()



Measured memory_bytes: 5716
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int X = Integer.parseInt(st.nextToken());
         int Y = Integer.parseInt(st.nextToken());
         int minlegs = X*2;
         if(minlegs <= Y && (Y-minlegs)%2 == 0 && minlegs*2 >= Y)
            System.out.println("Yes");
         else
            System.out.println("No");
      }
   }

Measured memory_bytes: 32700
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

bool visited[1001];

void dfs(int current,
         int depth,
         const vector<int> edges[1001],
         const vector<string>& messages){
  for(int i = 0; i < depth; i++){
    cout << ".";
  }
  cout << messages[current] << endl;
  for(int i = 0; i < edges[current].size(); i++){
    int next = edges[current][i];
    if(visited[next]) continue;
    visited[next] = true;
    dfs(next,depth+1,edges,messages);
  }
}

int main(){
  int num_of_posts;
  while(~scanf("%d",&num_of_posts)){
    memset(visited,false,sizeof(visited));

    vector<int> edges[1001];
    vector<string> messages;
    for(int post_i = 0; post_i < num_of_posts; post_i++){
      string message;
      int reply_to;
      cin >> reply_to >> message;
      messages.push_back(message);

      if(reply_to - 1 >= 0){
        edges[reply_to - 1].push_back(post_i);
      }
    }
    dfs(0,0,edges,messages);
  }
}

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

int main() {
  string S;
  cin >> S;
  int firstA=-1, lastZ=-1;
  int n = S.size();

  for (int i=0; i < n; ++i) {
    if (S[i] == 'A') {
      firstA = i;
      break;
    }
  }
  for (int i=n-1; i >= 0; --i) {
    if (S[i] == 'Z') {
      lastZ = i;
      break;
    }
  }
  cout << lastZ - firstA + 1 << endl;

  return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>
int main()
{
  char S[3];
  scanf("%s",S);
  
  if(!strcmp(S,"RRR")){printf("3");}
  else if(!strcmp(S,"RRS") || !strcmp(S,"SRR")){printf("2");}
  else if(!strcmp(S,"SSS")){printf("0");}
  else{printf("1");}
}

Measured memory_bytes: 1608
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, Integer> scoreMap = new LinkedHashMap<>();
        scoreMap.put("AC", 0);
        scoreMap.put("WA", 0);
        scoreMap.put("TLE", 0);
        scoreMap.put("RE", 0);
        for (int i=0; i<n; i++) {
            String s = sc.next();
            scoreMap.put(s, scoreMap.get(s) + 1);
        }
        for (Map.Entry<String, Integer> entry : scoreMap.entrySet()) {
            System.out.println(entry.getKey() + " x " + entry.getValue());
        }
    }
}

Measured memory_bytes: 49304
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

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


/* mint、表示は変数名.x */
struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};


map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

/* a^n (MOD) の計算 O(log n) */
ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  map<int, int> factor;
  vector<map<int, int>> mp(N);


  rep(i, N) {
    mp[i] = prime_factor(A[i]);
    for (pair<int, int> item : mp[i]) {
      int Fi = item.fi;
      int Se = item.se;
      chmax(factor[Fi], Se);
    }
  }

  mint multi = 1;
  for (auto item : factor) {
    auto Fi = item.fi;
    auto Se = item.se;
    multi *= modpow(Fi, Se);
  }


  mint ans = 0;
  rep(i, N) {
    mint temp = multi;
    for (pair<int, int> item : mp[i]) {
      int Fi = item.fi;
      int Se = item.se;
      temp /= modpow(Fi, Se);
    }
    // for (pair<int, int> item : factor) {
    //   int Fi = item.fi;
    //   int Se = item.se;

    //   temp *= modpow(Fi, Se - mp[i][Fi]);
    // }
    ans += temp;
  }
  cout << ans.x << "\n";
}


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


int main(){
    string S;
    cin >> S;
    for(int i=0;i < 3;i++){
        if(S.at(i) == S.at(i+1)){
        cout << "Bad"<<endl;
        break;
        }
        else if(i==2)
        cout << "Good" <<endl;

    }
}


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

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

    queue<ll> Q; int n = 0;
    Q.push(0);
    while (1) {
        ll num = Q.front(); Q.pop();

        if (num == 0) {
            REP(i, 1, 10) {
                n++;
                if (n == K) {
                    cout << i << endl;
                    return 0;
                }
                // cout << "n : " << n << " i : " << i << endl;
                Q.push(i);
            }
        } else {
            string s = to_string(num);
            int last = (s.back() - '0');
            for (int i = max(last - 1, 0); i <= min(last + 1, 9); i++) {
                n++;
                if (n == K) {
                    cout << num * 10 + i << endl;
                    return 0;
                }
                // cout << "n : " << n << " i : " << num * 10 + i << endl;
                Q.push(num * 10 + i);
            }
        }
    }

    return 0;
}

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

int main(){
    int n,s;
    string str;
    cin >> n;
    getline(cin,str);
    for(int i=0;i<n;i++){
        getline(cin,str);
        s=str.size();
        for(int i=0;i<s;i++){
            if(str[i]=='H'&&str[i+1]=='o'&&str[i+2]=='s'&&
                   str[i+3]=='h'&&str[i+4]=='i'&&str[i+5]=='n'&&str[i+6]=='o'){
                str[i+6]='a';
            }
        }
        //if(str=="")cout << "HOOGE" << endl;
        cout << str << endl;
    }
    return 0;
}

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

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

 if(a > b){
  d = a;
  a = b;
  b = d;
 }
 if(b > c){
  d = b;
  b = c;
  c = d;
 }
 if(a > b){
  d = a;
  a = b;
  b = d;
 }

 cout << a << " " << b << " "<< c << endl;

}


Measured memory_bytes: 3104
#include<set>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 500500
#define ri register int
using namespace std;

int n,k;
int a[N],p[N],ans[N],ans2[N],ru[N];

set<int> s;
vector<int> to[N];
priority_queue<int> pq;

void add_edge(int u,int v) {
  to[v].push_back(u); ru[u]++;
}

inline int read() {
  int ret=0,f=0; char ch=getchar();
	while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0' && ch<='9') ret*=10,ret+=(ch-'0'),ch=getchar();
	return f?-ret:ret;
}

int main() {
  n=read(); k=read();
	for (ri i=1;i<=n;i++) a[p[i]=read()]=i;
  
	for (ri i=1;i<=n+k-1;i++) {
	  if (i<=n) s.insert(p[i]);
		if (i-k+1>=1) s.erase(p[i-k+1]);
		if (i+1<=n) {
			set<int> ::  iterator cur=s.upper_bound(p[i+1]);
			if (cur!=s.end()) add_edge(i+1,a[*cur]);
		}
		if (i-k+1>=1) {
		  set<int> :: iterator cur=s.upper_bound(p[i-k+1]);
			if (cur!=s.end()) add_edge(i-k+1,a[*cur]);
		}
	}
	
	for (ri i=1;i<=n;i++) if (!ru[i]) pq.push(i);
	int cc=0;
	while (!pq.empty()) {
	  int x=pq.top(); pq.pop();
		ans[++cc]=x;
		for (ri i=0;i<to[x].size();i++) {
		  int y=to[x][i];
			ru[y]--;
			if (!ru[y]) pq.push(y);
		}
	}
	
	for (ri i=1;i<=n;i++) ans2[ans[n-i+1]]=i;
	for (ri i=1;i<=n;i++) printf("%d\n",ans2[i]);
	return 0;
}

Measured memory_bytes: 56576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int flag;
	int x,y;
	cin>>x>>y;
	if((y-2*x)<0)
	{
		flag=0;
	}
	else if((y-2*x)%2!=0)
	{
		flag=0;
	}
	else
	{
		int b=(y-2*x)/2;
		if(0<=b&&b<=x)
		{
			flag=1;
		}
		else
		{
			flag=0;
		}
	}
	if(flag)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}

Measured memory_bytes: 3604
import java.io.*;
import java.util.StringTokenizer;

class DroppingMat {
    int mat[][] = new int[10][10];

    DroppingMat() {
	for (int i=0;i<10;i++) {
	    for (int j=0;j<10;j++) this.mat[i][j] = 0;
	}
    }

    void Drop(int x,int y) {
	if (0<=x && x<=9 && 0<=y && y<=9) this.mat[x][y]++;
    }

    void DropSmallInk(int x,int y) {
	Drop(x,y);
	Drop(x-1,y);
	Drop(x+1,y);
	Drop(x,y-1);
	Drop(x,y+1);
    }

    void DropMidiumInk(int x,int y) {
	Drop(x-1,y-1);
	Drop(x+1,y-1);
	Drop(x-1,y+1);
	Drop(x+1,y+1);
	DropSmallInk(x,y);
    }

    void DropLargeInk(int x,int y) {
	Drop(x-2,y);
	Drop(x+2,y);
	Drop(x,y-2);
	Drop(x,y+2);
	DropMidiumInk(x,y);
    }

    int NumberofZero() {
	int count = 0;
	for (int i=0;i<10;i++)
	    for (int j=0;j<10;j++)
		if (this.mat[i][j]==0) count++;
	return count;
    }

    int MaxValue() {
	int max = 0;
	for (int i=0;i<10;i++)
	    for (int j=0;j<10;j++)
		if (this.mat[i][j]>max) max = this.mat[i][j];
	return max;
    }

    //テスト用
    void PrintMat() {
	for (int i=0;i<10;i++) {
	    for (int j=0;j<10;j++) System.out.print(this.mat[i][j]+" ");
	    System.out.println(" ");
	}
    }
}

class Main {
    public static void main(String args[]) {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String buf;
	DroppingMat dm = new DroppingMat();

	try {
	    while ((buf = br.readLine())!=null) {
		StringTokenizer st = new StringTokenizer(buf,",");
		int x = Integer.parseInt(st.nextToken());
		int y = Integer.parseInt(st.nextToken());
		int size = Integer.parseInt(st.nextToken());

	        switch (size) {
		case 1: dm.DropSmallInk(x,y); break;
		case 2: dm.DropMidiumInk(x,y); break;
		case 3: dm.DropLargeInk(x,y); break;
		}
		//dm.PrintMat();
	    }
	    System.out.println(dm.NumberofZero());
	    System.out.println(dm.MaxValue());
	} catch (Exception e) {
	    e.printStackTrace();
	}
    } 
}

Measured memory_bytes: 16852
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

for i in range(N):
    b = int(input())
    if b in A1:
        A1[A1.index(b)] = 0
    elif b in A2:
        A2[A2.index(b)] = 0
    elif b in A3:
        A3[A3.index(b)] = 0

if all([x == 0 for x in A1]):
    print('Yes')
    exit()
if all([y == 0 for y in A2]):
    print('Yes')
    exit()
if all([z == 0 for z in A3]):
    print('Yes')
    exit()

for t in range(3):
    if A1[t] == A2[t] == A3[t]:
        print('Yes')
        exit()

if A1[0] == A2[1] == A3[2]:
    print('Yes')
    exit()

if A1[2] == A2[1] == A3[0] == 0:
    print('Yes')
    exit()

print('No')

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

const int mod = 1e9 + 7;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  a.erase(unique(a.begin(), a.end()), a.end());
  n = (int) a.size();
  vector<int> dp((int) 2e5, 0);
  dp[a[0]] = 1;
  for (int i = 1; i < n; i++) {
    add(dp[a[i]], dp[a[i - 1]]);
  }
  cout << dp[a[n - 1]] << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
  int A= *(int *)a;
  int B= *(int *)b;
  return A-B;
}
int main(){
  int n,m,ans=0;
  scanf("%d %d",&n,&m);

  int a[m],i;
 
   for(i=0;i<m;i++){
  scanf("%d",&a[i]);
  }
  qsort(a,m,sizeof(int),cmp);
  int b[m-1];
  for(i=0;i<m-1;i++){
  b[i]=a[i+1]-a[i];
  }
  qsort(b,m-1,sizeof(int),cmp);
  int d,e,f;
    if(n>=m){
    printf("0\n");
  }
  else{
  for(i=0;i<(m-n);i++){
    ans+=b[i];
  }
      printf("%d\n",ans);
  }
}

Measured memory_bytes: 1396
#include "stdio.h"
#include "string.h"

char a[100],b[100];
int next[100];

void Next(char str[],int len)
{
    next[0] = -1;
    for(int j = 1 ; j < len ; j++)
    {
        int i = next[j-1];
        while(str[j] != str[i+1] && i >= 0)
        {
            i = next[i];
        }
        if(str[j] == str[i+1])
        {
            next[j] = i+1;
        }
        else
        {
            next[j] = -1;
        }
    }
}
int kmp(char des[],int len1,char pat[],int len2)
{
    Next(pat,len2);
    int p=0,s=0,x=0;
    while(p < len2  && s < len1)
    {
        if(pat[p] == des[s])
        {
            p++;s++; x++;
        }
        else
        {
            if(p==0)
            {
                s++;
                x=0;
            }
            else
            {
                p = next[p-1]+1;
                x=0;
            }
        }
    }
    return x;
}

int main()
{
   int n;
   while (scanf ("%d",&n) != EOF)
   {
       scanf ("%s%s",a,b);
       memset(next,0,sizeof(next));
       printf ("%d\n",2*n-kmp(a,n,b,n));
   }
    return 0;
}




Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,ch[2000005][26],vis[2000005],cnt=1,sum[105];
char tmp[10000005],*s[1000005],*f=tmp;
ll ans=0;
void ins(const char *s)
{
	int len=strlen(s),p=1;
	for(int i=len-1;i>=0;i--)
	{
		int c=s[i]-'a';
		if(!ch[p][c]) ch[p][c]=++cnt;
		p=ch[p][c];
	}
	vis[p]=1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		s[i]=f;
		scanf("%s",s[i]);
		int len=strlen(s[i]);
		f+=len+1;
		ins(s[i]);
	}
	for(int i=1;i<=n;i++)
	{
		int p=1,len=strlen(s[i]);
		for(int j=0;j<26;j++)
			sum[j]=0;
		for(int j=0;s[i][j];j++)
			sum[s[i][j]-'a']++;
		for(int j=len-1;j>=0;j--)
		{
			for(int k=0;k<26;k++)
			{
				int v=ch[p][k];
				if(v&&vis[v]&&sum[k])
				{
		//			printf("j=%d,p=%d,v=%d,k=%d\n",j,p,v,k);
					ans++;
				}
			}
			p=ch[p][s[i][j]-'a'];
			sum[s[i][j]-'a']--;
			if(!p) break;
		}
	}
	ans-=n;
	printf("%lld",ans);
	return 0;
}

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

int main(void){
	int s, m=1;
	cin >> s;
	if(s==1||s==2){
		cout << 4 << endl;
		return 0;
	}
	while(s!=4){
		m++;
		if(s%2==0) s /= 2;
		else s = 3*s + 1;
	}
	cout << m+3 << endl;
	return 0;
}

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

int main() {

  int n ; cin >> n ;
  vector<int> v1(n) ; for ( int i = 0 ; i < n ; i++ ) cin >> v1[i] ;
  vector<int> v2 ;
  
  for ( int i = 0 ; i < n-1 ; i++ )
  {
     for ( int j = i+1 ; j < n ; j ++ )
     {
         v2.push_back( abs( v1[i] - v1[j] )) ;
     } 
  }
  
  //for ( int x : v2 ) cout << x << ' ' ;
  int ans = *max_element(v2.begin(),v2.end() ) ;
  cout << ans ;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

ll n,m;

ll f(int x, vector<vector<ll>> val){
        vector<ll> v(n);
        rep(i,0,3){
                if((x>>i)&1){
                        rep(j,0,n){
                                v[j]+=val[j][i];
                        }
                }else{
                        rep(j,0,n){
                                v[j]-=val[j][i];
                        }
                }
        }
        sort(all(v));
        reverse(all(v));
        ll sum=0;
        rep(i,0,m){
                sum+=v[i];
        }
        return sum;
}

int main(){
        cin>>n>>m;
        vector<vector<ll>> val(n, vector<ll>(3,0));
        rep(i,0,n){
                rep(j,0,3){
                        cin>>val[i][j];
                }
        }
        ll ans=0;
        rep(bit,0,8){
                ans=max(ans,f(bit,val));
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();

			int n = vs[0];
			int m = vs[1];

			int[] sum = new int[m];
			for (int i = 0; i < n; i++) {
				vs = Console.ReadLine().Split().Select(int.Parse).Skip(1).ToArray();
				for (int j = 0; j < m; j++) {
					if (vs.Contains(j + 1)) {
						sum[j]++;
					}
				}
			}

			int ans = 0;
			for (int i = 0; i < m; i++) {
				if (sum[i] == n) {
					ans++;
				}
			}
			Console.WriteLine(ans);

		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main()
{
	ll H, W; cin >> H >> W;
	ll ans = INF;
	for(int h = 1; h < H; h++) {
		ll h2 = (H - h) / 2;
		if(h2 > 0) {
			ll S1 = W * h;
			ll S2 = W * h2;
			ll S3 = W * (H - h - h2);
			ll Smax = max(S1, max(S2, S3));
			ll Smin = min(S1, min(S2, S3));
			ans = min(ans, Smax-Smin);
		}
		ll w2 = W / 2;
		if(w2 > 0) {
			ll S1 = W * h;
			ll S2 = (H-h) * w2;
			ll S3 = (H-h) * (W - w2);
			ll Smax = max(S1, max(S2, S3));
			ll Smin = min(S1, min(S2, S3));
			ans = min(ans, Smax-Smin);
		}
	}
	for(int w = 0; w < W; w++) {
		ll w2 = (W - w) / 2;
		if(w2 > 0) {
			ll S1 = H * w;
			ll S2 = H * w2;
			ll S3 = H * (W - w - w2);
			ll Smax = max(S1, max(S2, S3));
			ll Smin = min(S1, min(S2, S3));
			ans = min(ans, Smax-Smin);
		}
		ll h2 = H / 2;
		if(h2 > 0) {
			ll S1 = H * w;
			ll S2 = (W-w) * h2;
			ll S3 = (W-w) * (H - h2);
			ll Smax = max(S1, max(S2, S3));
			ll Smin = min(S1, min(S2, S3));
			ans = min(ans, Smax-Smin);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;
/*******\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\*     */

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].f>>a[i].s;
    }
    for(int i=2;i<n;i++){
        if(a[i].f != a[i].s)continue;
        if(a[i-1].f != a[i-1].s)continue;
        if(a[i-2].f != a[i-2].s)continue;
        cout<<"Yes\n";
        exit(0);
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	#ifdef PIYUSH_AASHIRWAAD
		I_O;
	#else
	#define print(...) 0
	#endif
	int n, c;
	cin >> n >> c;
	std::map<int, int> m[3];
	std::vector<std::vector<int> > grid(n, std::vector<int> (n));
	std::vector<std::vector<int> > G(c, std::vector<int> (c));
	for (int i = 0; i < c; ++i)
	{
		for (int j = 0; j < c; ++j)
		{
			cin >> G[i][j];
		}
	}
	int y;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin >> grid[i][j];
			grid[i][j]--;
			y = (i+j)%3;
			m[y][grid[i][j]]++;
		}
	}
	priority_queue<std::pair<int, int> > pq[3];
	for (int i = 0; i < 3; ++i)
	{
		pq[i].push(mp(1000000000, -1));
	}
	for (int i = 0; i < c; ++i)
	{
		for (int o = 0; o < 3; ++o)
		{
			int t = 0;
			for (auto j = m[o].begin(); j != m[o].end(); ++j)
			{
				t+=((j->second)*(G[j->first][i]));
			}
			pq[o].push(mp(t, i));
			if(pq[o].size() > 3){
				pq[o].pop();
			}
		}
	}
	std::vector<std::vector<std::pair<int, int> > > v(3);
	std::pair<int, int> p;
	for (int i = 0; i < 3; ++i)
	{
		while(!pq[i].empty()){
			p = pq[i].top();
			pq[i].pop();
			if(p.second!=-1)
				v[i].pb(p);
		}
	}
	int c1, c2, c3;
	int mmmm = 1000000000;
	print(v);
	for (int i = 0; i < v[0].size(); ++i)
	{
		c1 = v[0][i].second;
		for (int j = 0; j < v[1].size(); ++j)
		{
			c2 = v[1][j].second;
			for (int k = 0; k < v[2].size(); ++k)
			{
				c3 = v[2][k].second;
				if(c1 == c2 || c2 == c3 || c3 == c1){
				}
				else {
					if(mmmm > (v[0][i].first+v[1][j].first+v[2][k].first)){
						mmmm = v[0][i].first+v[1][j].first+v[2][k].first;
					}
				}
			}
		}
	}
	cout<<mmmm;
}

Measured memory_bytes: 1280
import java.util.*;
import static java.lang.Math.abs;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        int[] t = new int[N+1];
        int[] x = new int[N+1];
        int[] y = new int[N+1];


        t[0]=0;
        x[0]=0;
        y[0]=0;
        for(int i = 1; i <= N; i++){

            t[i] = scan.nextInt();;
            x[i] = scan.nextInt();
            y[i] = scan.nextInt();
        }

        int times = 0;
        int min_times_for_dst  = 0;
        int rest_times = 0;
        for(int i = 0; i < N; i++){

            times     = t[i+1] -t[i];
            min_times_for_dst = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
            rest_times = times - min_times_for_dst;

            if(times < min_times_for_dst){
                System.out.println("No");
                return;
            }

            if(rest_times% 2 != 0){
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }
}


Measured memory_bytes: 90484
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,k,c=MI()
    s=SI()
    ll=[0]*n
    rr=[0]*n
    for i,m in enumerate(s):
        if m == "o":
            if i-c-1>=0:ll[i] = ll[i - c - 1] + 1
            else:ll[i]=1
        else:ll[i]=ll[i-1]
    #print(ll)
    for i in range(n-1,-1,-1):
        m=s[i]
        if m == "o":
            if i + c + 1 < n:rr[i]=rr[i+c+1]+1
            else:rr[i]=1
        else:rr[i]=rr[(i+1)%n]
    #print(rr)
    ans=[]
    if n==1:ans.append(1)
    if n>1 and rr[1]<k:ans.append(1)
    for i in range(1,n-1):
        if ll[i-1]+rr[i+1]<k:ans.append(i+1)
    if n>1 and ll[n-2]<k:ans.append(n)
    print(*ans,sep="\n")

main()

Measured memory_bytes: 31712