akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

/*
2つの整数K,Sが与えられます。
3つの変数X,Y,Zがあり、0≦X,Y,Z≦Kを満たす整数の値を取ります。
X+Y+Z=Sを満たすX,Y,Zへの値の割り当ては何通りありますか。
*/

int main() {
  int K, S, count = 0;
  cin >> K >> S;

  for (int x = 0; x <= K; x++) {
    if(x > S) { break; }
    for (int y = 0; y <= K; y++) {
      if(x + y > S) { break; }
      if ((x + y) <= S && (x + y + K) >= S ) {
        count++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    string s;
    cin >> s;
    map<char ,int> mp;
    rep(i,s.size()){
        mp[s[i]]++;
    }
    if(mp.size()==2){
        Yes
    }
    No
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
const int NUM = 3;

int main(int argc, char const *argv[]) {
  unsigned int c[NUM][NUM], b[3];
  unsigned int tmax , max=100, index=0;
  for(int i=0; i<NUM; i++){
    tmax = 0;
    for(int j=0; j<NUM; j++){
      cin >> c[i][j];
      if(tmax < c[i][j])
        tmax = c[i][j];
    }
    if(tmax < max){
      max = tmax;
      index = i;
    }
  }

  for(int i = 0; i<=max; i++){
    b[0] = c[index][0] - i;
    b[1] = c[index][1] - i;
    b[2] = c[index][2] - i;
    bool flag = true;
    for(int j=0; j < NUM; j++){
      if( !( ((c[j][0] - b[0]) == (c[j][1] - b[1])) && ((c[j][0] - b[0]) == (c[j][2] - b[2])) ) ){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";
  return 0;
}


Measured memory_bytes: 256
# frozen_string_literal: true

h, _ = gets.split.map(&:to_i)
a = Array.new(h) { gets.chomp.chars }

a.delete_if { |row| row.uniq == ['.'] }
a = a.transpose
a.delete_if { |col| col.uniq == ['.'] }

a.transpose.each { |e| puts e.join('') }

Measured memory_bytes: 2300
import java.util.Scanner;
import java.util.Arrays;
public class Main {
  
    public static void main(String args[]){
        Scanner obj=new Scanner(System.in);
        int N=obj.nextInt();
        int[] arr=new int[2*N];

        for(int i=0;i<2*N;i++){
            arr[i]=obj.nextInt();}
        Arrays.sort(arr);
        int sum=0;
        for(int i=0;i<2*N;i+=2){
            //System.out.println(i+" "+arr[i]+" "+arr[i+1]);
            int add=(arr[i]<arr[i+1])?arr[i]:arr[i+1];
            sum=sum+add;
        }
        System.out.println(sum);

    }  
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

vector<P> g[100005];
vector<int> ans(100005);

void dfs(int a, int d = -1, int p = -1) {
	int tmp = 1;
	for (auto& c : g[a]) {
		int land = c.first, bridge = c.second;
		if (land == p) continue;
		if (tmp == d) tmp++;
		ans[bridge] = tmp;
		tmp++;
		dfs(land, ans[bridge], a);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b, i);
		g[b].emplace_back(a, i);
	}
	int res = 0;
	rep(i, n - 1) res = max(res, (int)g[i].size());
	rep(i, n - 1) ans[i] = -1;
	dfs(0);
	cout << res << endl;
	rep(i, n - 1) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 9472
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    int k;
    cin >> k;

    string str;
    std::cin >> str;

    if (str.size() <= k)
        cout << str << endl;
    else
        cout << str.substr(0, k) << "..." << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

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

int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
string ans = "No";
if(abs(c-a) <= d){
  ans = "Yes";
}else if(abs(b-a) <= d && abs(c-b) <= d){
  ans = "Yes";
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;

int GCD(int max, int min){
    if(max % min == 0) { return min; }
    else return GCD(min, max % min);
}
 
int main(){
    long long int a, b;
    while(cin >> a >> b){
        long long int gcd = GCD(max(a, b), min(a, b));
        long long int lcm = a * b / gcd;
        cout << GCD(max(a, b), min(a, b)) << " " << lcm << endl;
    }
    return 0;
}

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

int main(){
	string a;
	int n;
	cin>>n;
	cin>>a;
	int s=a.size();
	for(int i=0;i<s;i++){
		a[i]+=n;
		if(int(a[i])>90){
			a[i]=a[i]-26;
			}
		}
	cout<<a;
	
	}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    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 main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    string s;
    bool ok = false;
    cin >> s;
    if (s[0] == 'B' && s[1] == 'B' && s[2] == 'B') {
        ok = false;
    }else if (s[0] == 'A' && s[1] == 'A' && s[2] == 'A') {
        ok = false;
    }else ok = true;
    if (ok) puts("Yes");
    else puts("No");
    return 0;
}

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

using namespace std;

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

const int MAX_V = 360000;

vector<int> G[MAX_V];
int color[MAX_V];

void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

void bfs(int v, vector<int>& used) {
    queue<P> q;
    q.emplace(v, 0);
    while (!q.empty()) {
        P p = q.front();
        q.pop();
        if (used[p.first]) continue;
        used[p.first] = true;
        color[p.first] |= p.second;
        for (int nex : G[p.first]) {
            if (used[nex]) continue;
            q.emplace(nex, 1 - p.second);
        }
    }
}

bool is_square(int x2, int& x) {
    int ok = 0, ng = 10000;
    while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if (mid * mid <= x2) ok = mid;
        else ng = mid;
    }
    x = ok;
    return x * x == x2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d1, d2;
    cin >> n >> d1 >> d2;
    vector<P> v;
    for (int i = 0; i * i <= d1; i++) {
        if (i >= 2 * n) break;
        int j = 0;
        if (is_square(d1 - i * i, j)) {
            if (j >= 2 * n) continue;
            v.emplace_back(i, j);
            v.emplace_back(i, -j);
        }
    }
    
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            for (P& p : v) {
                int h = i + p.first, w = j + p.second;
                if (h < 0 || h >= 2 * n || w < 0 || w >= 2 * n) continue;
                int src = i * 2 * n + j, dst = h * 2 * n + w;
                if (src < dst) {
                    add_edge(src, dst);
                }
            }
        }
    }

    vector<int> used(4 * n * n, false);
    for (int i = 0; i < 4 * n * n; i++) {
        if (used[i]) continue;
        bfs(i, used);
    }

    v.clear();
    for (int i = 0; i < 4 * n * n; i++) {
        G[i].clear();
        color[i] <<= 1;
    }
    used.assign(4 * n * n, false);
    for (int i = 0; i * i <= d2; i++) {
        if (i >= 2 * n) break;
        int j = 0;
        if (is_square(d2 - i * i, j)) {
            if (j >= 2 * n) continue;
            v.emplace_back(i, j);
            v.emplace_back(i, -j);
        }
    }

    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            for (P& p : v) {
                int h = i + p.first, w = j + p.second;
                if (h < 0 || h >= 2 * n || w < 0 || w >= 2 * n) continue;
                int src = i * 2 * n + j, dst = h * 2 * n + w;
                if (src < dst) {
                    add_edge(src, dst);
                }
            }
        }
    }

    for (int i = 0; i < 4 * n * n; i++) {
        if (used[i]) continue;
        bfs(i, used);
    }

    vector<int> ans[4];
    for (int i = 0; i < 4 * n * n; i++) {
        ans[color[i]].push_back(i);
    }

    int tar = 0;
    for (int i = 0; i < 4; i++) {
        if (ans[tar].size() < ans[i].size()) tar = i;
    }

    for (int i = 0; i < n * n; i++) {
        cout << ans[tar][i] / (2 * n) << " " << ans[tar][i] % (2 * n) << endl;
    }
    return 0;
}

Measured memory_bytes: 62064
N, K = map(int, input().split())
def nCr(n, r):
    if n<r :
      return 0
    else:
      """
      Calculate the number of combination (nCr = nPr/r!).
      The parameters need to meet the condition of n >= r >= 0.
      It returns 1 if r == 0, which means there is one pattern
      to choice 0 items out of the number of n.
      """
  
      # 10C7 = 10C3
      r = min(r, n-r)
  
      # Calculate the numerator.
      numerator = 1
      for i in range(n, n-r, -1):
          numerator *= i
  
      # Calculate the denominator. Should use math.factorial?
      denominator = 1
      for i in range(r, 1, -1):
          denominator *= i
  
      return numerator // denominator
for i in range(K):
  a=nCr(N-K+1,i+1)*nCr(K-1,i)
  print(a%1000000007)


Measured memory_bytes: 3316
from operator import itemgetter
n,m = map(int,input().split())

p = [list(map(int,input().split())) for i in range(m)]

b=[[i] for i in range(m)]

for i in range(m):
  p[i].extend(b[i])
  
p = sorted(sorted(p, key=itemgetter(1)))

old_p=0
for i in range(m):
  if p[i][0] != old_p :
    old_p = p[i][0]
    count = 1
  else:
    count +=1
  p[i][0] = "0"*(6-len(str(p[i][0])))+str(p[i][0])+"0"*(6-len(str(count)))+str(count)

p = sorted(p, key=itemgetter(2))

for i in range(m):
  print(p[i][0])
  

Measured memory_bytes: 103896
#include<bits/stdc++.h>
using namespace std;
const int N=705;
int n,m,k,a[N][N],c[N],s[N][2],dp[N][N],ans=1e9;
void dfs(int u)
{
	s[k][c[u]]++;
	for(int v=1;v<=n;v++)
	{
		if(v==u||!a[u][v])
			continue;
		if(c[v]==-1)
		{
			c[v]=c[u]^1;
			dfs(v);
		}
		else if(c[u]==c[v])
		{
			puts("-1");
			exit(0);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			a[i][j]=1;
		c[i]=-1;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		a[u][v]=a[v][u]=0;
	}
	for(int i=1;i<=n;i++)
	{
		if(c[i]==-1)
		{
			k++;
			c[i]=0;
			dfs(i);
		}
	}
	dp[0][0]=1;
	for(int i=1;i<=k;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(j>=s[i][0]) dp[i][j]|=dp[i-1][j-s[i][0]];
			if(j>=s[i][1]) dp[i][j]|=dp[i-1][j-s[i][1]]; 
		}
	}
	for(int i=0;i<=n;i++)
		if(dp[k][i])
			ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7572
#include <stdio.h>
const int N=1e3+10;
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int main(){
    int n=1,dp[N][N],big;
    char c[N];
    while(n!=0){
        scanf("%d",&n);
        if(n==0)continue;
        big=0;
        for(int i=0;i<n;i++){
            scanf("%s",c);
            for(int j=0;j<n;j++)dp[i][j]=c[j]=='*'?0:1;
        }
        for(int i=0;i<n;i++)big=max(big,max(dp[i][0],dp[0][i]));
        for(int i=1;i<n;i++)for(int j=1;j<n;j++)if(dp[i][j]==1)big=max(big,dp[i][j]+=min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]));
        printf("%d\n",big);
    }
    return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("inout.txt", "w", stdout);
    int a, b;
    cin >> a >> b;
    if (a > b)
        swap(a, b);
    if (a <= 0 && b >= 0)
        cout << "Zero" << endl;
    else if (a < 0) {
        if ((b - a) % 2 != 0)
            cout << "Positive" << endl;
        else
            cout << "Negative" << endl;
    }
    else
        cout << "Positive" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define EPS 1e-10
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

double dig(ll n) {
	double ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

int main() {
	int k;
	cin >> k;
	vector<ll> ans;
	double c = LINF;
	for (ll i = 999999999999999; i > 999999999999; i -= 1000000000) {
		double d = (double)i / dig(i);
		if (c + EPS >= d) {
			ans.push_back(i);
			c = d;
		}
	}
	for (ll i = 999999999999; i > 999999999; i -= 1000000) {
		double d = (double)i / dig(i);
		if (c + EPS >= d) {
			ans.push_back(i);
			c = d;
		}
	}
	for (ll i = 999999999; i > 999999; i -= 1000) {
		double d = (double)i / dig(i);
		if (c + EPS >= d) {
			ans.push_back(i);
			c = d;
		}
	}
	for (ll i = 999999; i >= 1; i--) {
		double d = (double)i / dig(i);
		if (c + EPS >= d) {
			ans.push_back(i);
			c = d;
		}
	}
	reverse(all(ans));
	for (int i = 0; i < k; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e6,MOD=1e9+7,MAX_H=1e6;
ll N,H,D,dp[MAX_H+1],fact[MAX_N+1];
ll mpw(ll n,ll m){
	ll r=1;
	while(m){
		if(m&1){
			r*=n;
			r%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return r;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>H>>D;
	fact[0]=1;
	REP(i,N){
		fact[i+1]=(i+1)*fact[i]%MOD;
	}
	dp[0]=1;
	ll sm=1,x=0;
	REP(i,N){
		x+=fact[i+1];
		x%=MOD;
	}
	REP(i,H){
		dp[i+1]=sm*x%MOD;
		sm+=dp[i+1];
		sm%=MOD;
		if(i+1-D>=0){
			sm-=dp[i+1-D];
			sm+=MOD;
			sm%=MOD;
		}
	}
	ll ans=dp[H]*fact[N]%MOD;
	ans*=minv(x);
	ans%=MOD;
	cout<<ans<<endl;
		
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
struct edge{int to,cost;};
using P=pair<int,int>;
const int INF=1<<29;
const int MAX_V=100010;
vector<edge> G[MAX_V];
int d[MAX_V];
int V,E;
void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+V,INF);
  d[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    REP(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
	d[e.to]=d[v]+e.cost;
	que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){_;
  int n,f,t,c;cin>>n;
  REP(i,n-1){
    cin>>f>>t>>c;
    G[f].push_back(edge{t,c});
    G[t].push_back(edge{f,c});
  }
  V=n;
  E=(n-1)*2;
  dijkstra(0);
  int maxIdx=distance(d,max_element(d,d+n));
  dijkstra(maxIdx);
  cout<<(*max_element(d,d+n))<<endl;
}

Measured memory_bytes: 9904
s=input()
k=int(input())
cnt=1
temp=[]
for i in range(len(s)-1):
    if s[i]==s[i+1]: cnt+=1
    else:
        temp.append([s[i],cnt])
        cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
    print(k*len(s)//2)
    exit()
ans=0
if temp[0][0]!=temp[-1][0]:
    for pair in temp:
        if pair[1]!=1: ans+=pair[1]//2
    print(ans*k)
else:
    for pair in temp[1:-1]:
        if pair[1]!=1: ans+=pair[1]//2
    ans*=k
    ans+=(k-1)*((temp[0][1]+temp[-1][1])//2)
    ans+=temp[0][1]//2+temp[-1][1]//2
    print(ans)

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

int main() {
	int n, m;
	int l, r;
	int l_max, r_min;
	
	cin >> n >> m;
	l_max = 0;
	r_min = n;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;

		if (l > l_max) {
			l_max = l;
		}

		if (r < r_min) {
			r_min = r;
		}
	}

	if (r_min < l_max) {
		cout << 0 << endl;
	}
	else {
		cout << r_min - l_max + 1 << endl;
	}
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long [] height = new long[n + 1];

        long [] cost = new long[n + 1];
        height[0] = 0;
        for (int i = 1; i <= n; ++i) {
            height[i] = scanner.nextLong();
        }
        cost[0] = 0L;
        cost[1] = 0L;
        cost[2] = Math.abs(height[2] - height[1]);
        for (int i = 3; i <= n; ++i) {
            cost[i] = Math.min(cost[i - 1] + Math.abs(height[i] - height[i - 1]),
                    cost[i - 2] + Math.abs(height[i] - height[i - 2])
                    );
        }
        System.out.println(cost[n]);

    }
}


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

const int MAX = 100000+5;
const int nil = -1;

struct Node{
    int parent, left, right; // 親、左の子、同じ深さの右
};

Node T[MAX];
int n, D[MAX]; // D[i]: 深さi

// 節点uについて出力する関数
void print(int u){
    int i, c;

    printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, D[u]);
    if(T[u].parent == nil) printf("root, ");
    else if(T[u].left == nil) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    for(i=0, c=T[u].left; c!=nil; i++, c=T[c].right){
        if(i>0) printf(", ");
        cout << c;
    }

    printf("]\n");
}

void rec(int u, int p){
    D[u] = p;
    if(T[u].right != nil) rec(T[u].right, p);
    if(T[u].left != nil) rec(T[u].left, p+1);
}

int main(){
    cin >> n;
    for(int i=0; i<n; ++i) T[i].parent = T[i].left = T[i].right = nil;

    int l;
    for(int i=0; i<n; ++i){
        int id, k;
        scanf("%d %d", &id, &k);
        for(int j=0; j<k; ++j){
            int c; scanf("%d", &c);
            if(j==0) T[id].left =  c;
            else T[l].right = c;
            l = c;
            T[c].parent = id;
        }
    }

    int root;
    for(int i=0; i<n; ++i) if(T[i].parent == nil)root = i;

    rec(root, 0);

    for(int i=0; i<n; ++i) print(i);
}


Measured memory_bytes: 7892
// まじでRustわからん
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    let mut N: usize;

    let mut V: Vec<i32> = Vec::new();
    let mut C: Vec<i32> = Vec::new();
    input! {
        N: usize,
        V: [i32; N],
        C: [i32; N],
    }
    let mut ans = 0;
    for i in 0..N {
    	
        let tmp = V[i] - C[i];
        
        if tmp > 0 {
            ans = ans + tmp;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
ans, s = "Yes", ''
d = {}
for _ in range(int(input())):
    t = [str(x) for x in ''.join(input())]
    if d.get(''.join(t)) != None or (_ > 0 and t[0] != s[-1]):
        ans = "No"
        break
    d.setdefault(''.join(t), 1)
    s = t
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int ton(string s){
  return atoi(s.c_str());
}
string tos(int n){
  stringstream ss;
  ss<<n;
  return ss.str();
}

int main(){
  int N;
  while(cin>>N && N){
    int cnt[10010] = {};
    vector<string> a;
    REP(i, N){
      int t; scanf("%d", &t);
      if(cnt[t] < 2){
        a.push_back(tos(t));
        cnt[t] ++;
      }
    }
    int ans[4] = {};
    REP(i, 3) ans[i] = 1000000009;
    REP(i, a.size())REP(j, a.size()) if(i != j){
      int n = ton(a[i] + a[j]);
      ans[3] = n;
      for(int i = 3; i > 0; i--){
        if(ans[i] < ans[i - 1]) swap(ans[i], ans[i - 1]);
      }
    }
    cout<<ans[2]<<endl;
  }

  return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i=0;i<n;i++){
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			int c = stdIn.nextInt();
			
			if(a<b){
				if(b<c){
					func(c,a,b);
				}
				else{
					func(b,a,c);
				}
			}
			else{
				if(a<c){
					func(c,a,b);
				}
				else{
					func(a,b,c);
				}
			}
		}
	}
	
	static void func(int a,int b,int c){
		if(Math.pow(a,2) == (Math.pow(b,2)+Math.pow(c,2))){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23384
n, k = gets.split.map(&:to_i)

if k.odd?
  c = 0
  (1..n).each do |i|
    if i % k == 0
      c += 1
    end
  end
  puts c ** 3
else
  c1 = 0
  c2 = 0
  (1..n).each do |i|
    if i % k == 0
      c1 += 1
    end
    if i % k == k/2
      c2 += 1
    end
  end
  puts c1 ** 3 + c2 ** 3
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>

int getMinRewrite(const int k, const std::vector<int> &ball_numbers) {
  std::vector<int> number_counts(ball_numbers.size(), 0);
  for (const auto &ball_number : ball_numbers) {
    ++number_counts[ball_number - 1];
  }
  std::sort(number_counts.begin(), number_counts.end());
  const int n = static_cast<int>(number_counts.size());
  int result = 0;
  for (int i = 0 ; i < n; ++i) {
    const int rest = n - i;
    if (rest <= k) {
      break;
    }
    result += number_counts[i];
  }
  return result;
}

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> ball_numbers(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> ball_numbers[i];
  }
  std::cout << getMinRewrite(k, ball_numbers) << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for (int i = 1; i < 180; ++i)
    {
        if((i*360) % t == 0){
            cout<<(i*360) / t;
            return 0;
        }
    }
    //cout<<floor((double)360/t);
    //return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int sol = 0;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        while (x % 2 == 0)
            sol++, x /= 2;
    }
    cout << sol;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	while(m--){
		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			int t;
			cin>>t;
			a[t]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define V vector<int>
#define COUT(x) cout<<(x)<<endl
#define M map<int,int>
#define S set<int>
#define PQ priority_queue


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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


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

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	V a(n); rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	double ma = a[n - 1];
	double tmp = ma / 2.0;
	int now = INF;
	int ans = 0;
	rep(i, n - 1) {
		if (abs(tmp - a[i]) < now) {
			now = abs(tmp - a[i]);
			ans = a[i];
		}
	}
	cout << (int)ma << " " << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
typedef long long ll;
ll min(ll x, ll y) {
	return x > y ? y : x;
}
ll max(ll x, ll y) {
	return x < y ? y : x;
}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	if (k == 0) {
		printf("%lld\n", (ll)n * n);
		return 0;
	}
	ll ans = 0;
	for (int b = k; b <= n; b++) {
		ans += (ll)(n + 1) / b * (b - k);
		ans += max(0, (n + 1) % b - k);
		// printf("%lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1708
h, w = map(int, input().split())
s=[list(input()) for i in range(h)]
ans = 'Yes'
for i in range(1,h-1):
  for j in range(1,w-1):
    if s[i][j]=='#' and s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j+1]=='.' and s[i][j-1]=='.':
      ans='No'
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define maxn 100000
using namespace std;

int n,ans;
int ar[maxn][3];
int dp[maxn][3];

int main() {
	scanf("%d",&n);
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < 3 ; j++ )
			scanf("%d",&ar[i][j]);
	for( int i = 0 ; i < 3 ; i++ )
		dp[0][i] = ar[0][i];
	for( int i = 1 ; i < n ; i++ )
		for( int j = 0 ; j < 3 ; j++ )
			for( int k = 0 ; k < 3 ; k++ )
				if( j != k )
					dp[i][j] = max( dp[i][j] , dp[i-1][k] + ar[i][j] );
	for( int i = 0 ; i < 3 ; i++ )
		ans = max( ans , dp[n-1][i] );
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2560
from bisect import bisect_left

def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    b = [a[i] + i + 1  for i in range(n)]
    c = {}
    for i in range(n):
        cc = a[i] - i - 1
        if cc not in c:
            c[cc] = []
        c[cc].append(i)
    ans = 0

    for i in range(n):
        bb = -b[i]
        if bb not in c:
            continue
        idx = bisect_left(c[bb], i)
        ans += len(c[bb]) - idx
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 70652
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a<c&&c<b) || (b<c&&c<a)){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  for (int i = 0; i < N; ++i) {
    int num;
    cin >> num;
    for (int j = 0; j < num; ++j) {
      int v; cin >> v; --v;
      a[v]++;
    }
  }
  int res = 0;
  for (int i = 0; i < M; ++i) if (a[i] >= N) ++res;
  cout << res << endl;
}

Measured memory_bytes: 3572
from functools import lru_cache
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]

memo=[-1]*2005
def solve(s):
    if s<3:return 0
    if s<6:return 1
    if memo[s]!=-1:return memo[s]
    res=1
    for d in range(3,s+1):
        if s-d<3:break
        res+=solve(s-d)
        res%=md
    memo[s]=res
    return res

md=10**9+7
s=II()
print(solve(s))


Measured memory_bytes: 9612
N, W = map(int, input().split())

weights = []
values = []
for i in range(N):
    lst = [int(e) for e in input().split()]
    weights.append(lst[0])
    values.append(lst[1])


dp = [{} for j in range(N+1)]

def rec(i, j):
    if j in dp[i]:
        return dp[i][j]

    res = 0
    if i == N:
        res = 0
    elif j < weights[i]:
        res = rec(i+1, j)
    else:
        res = max(
            rec(i+1, j),
            rec(i+1, j-weights[i]) + values[i]
        )

    dp[i][j] = res
    return res


print(rec(0, W))

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

int main() {
  int n, x[100], min = 100, max = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] < min) min = x[i];
    if (x[i] > max) max = x[i];
  }
  int min_d = n * max * max, min_p;
  for (int p = min; p <= max; p++) {
	int d = 0;
    for (int i = 0; i < n; i++)
      d += (x[i] - p) * (x[i] - p);
    if (d < min_d) {
      min_d = d;
      min_p = p;
    }
  }
  cout << min_d << endl;   
  return 0;
}

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


int main() {
    int  a, b, c;
    cin >> c >> a>>b;
    if (a >= b)cout << "delicious" << endl;
    else if (a + c >= b)cout << "safe" << endl;
    else cout << "dangerous" << endl;
 
    
    return 0;
}

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

typedef long long ll;
const int maxn = 1e5 + 10;
int n, h, x[maxn];
ll arr[3][maxn], r[maxn];

int prefix_rect(int l, int v){
	arr[1][1] += v;
	arr[1][l + 1] -= v;
	arr[0][l + 1] += ll(v) * l;
}

int rect(int l, int r, int v){
	prefix_rect(r, v);
	prefix_rect(l - 1, -v);
}

int prefix_tria(int l, int v){
	arr[2][1] += v;
	arr[2][l + 1] -= v;
	arr[0][l + 1] += ll(l) * (l + 1) * v / 2;
}

int tria(int l, int r, int v){
	prefix_tria(r, v);
	prefix_tria(l - 1, -v);
	rect(l, r, -l + 1);
}

void flatten(){
	ll s0 = 0, s1 = 0, s2 = 0;
	for(int i = 1; i < maxn; i++){
		s0 += arr[0][i], s1 += arr[1][i], s2 += arr[2][i];
		r[i] = ll(s0) + ll(i) * s1 + ll(i) * (i + 1) * s2 / 2;
	}

//	for(int i = 1; i <= h; i++){
//		cout << r[i] - r[i - 1] << ' ';
//	}
//	cout << endl;
}

void process(int i){
	int cut = x[i] - x[i - 1];
	if(cut < 0){
		cut += h;
	}
//	}cout << cut << endl;

	if(cut > x[i]){
		rect(1, h - x[i], x[i]);
		tria(1, cut - x[i], 1);
		rect(cut - x[i] + 1, h - x[i], cut - x[i]);
		tria(h - x[i] + 1, h + 1, 1);
	}else{
//		cout << "yup\n";
		rect(1, h - x[i], cut);
		tria(h - x[i] + 1, h - x[i] + cut, 1);
		rect(h - x[i] + cut + 1, h + 1, cut);
	}
}

int main(){
	ios_base::sync_with_stdio(false);

	cin >> n >> h;

	for(int i = 0; i < n; i++){
		cin >> x[i];

		if(i > 0){
			process(i);
		}
	}

	flatten();

	ll mn = 1e18;
	for(int i = 1; i <= h; i++){
		mn = min(mn, r[i] - r[i - 1]);
	}

	cout << mn << endl;

	return 0;
}


Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		String s=sc.next();
		char[]a=s.toCharArray();
		//int size=s.length();
		
		for(int i=0;i<s.length();i++) {
			if(i%2==0) {
				if(a[i]=='L') {
					System.out.println("No");
					 return;
				}
			}else {
				if(a[i]=='R') {
					System.out.println("No");
					 return; 
				}
			}
		}
		System.out.println("Yes");
		 return; 
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <complex>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define REPS(i, n) for(int i=1;i<=(int)n;i++)
#define RREP(i, n) for(int i=n-1;i>=0;i--)
#define RREPS(i, n) for(int i=n;i>0;i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

string s;
ll k;
string ans;
string ansrev;

ll memo[2001][2001];
ll mini[2001][2001];

ll minimum(int l, int r){
	ll &res = mini[l][r];
	if(res >= 0) return res;
	if(r <= l) return res = 0;
	if(l+1 == r) return res = 1;
	if(s[l] == s[r-1]) return res = minimum(l+1, r-1) + 2;
	return res = min(minimum(l+1, r), minimum(l, r-1)) + 2;
}

ll count(int l, int r){
	ll &res = memo[l][r];
	if(res >= 0) return res;
	if(r <= l) return res = 1;
	if(s[l] == s[r-1]) return res = count(l+1, r-1);
	ll mi = min(minimum(l+1, r), minimum(l, r-1));
	res = 0;
	if(minimum(l+1, r) == mi) res += count(l+1, r);
	if(minimum(l, r-1) == mi) res += count(l, r-1);
	if(res > 1e18 + 10) res = 1e18 + 10;
	return res;
}

void dfs(int l, int r, ll k){
	if(l == r){
		reverse(ALL(ansrev));
		if(k) cout << "NONE" << endl;
		else cout << ans << ansrev << endl;
	}else if(l+1 == r){
		ans.pb(s[l]);
		dfs(l+1, r, k);
	}else if(s[l] == s[r-1]){
		ans.pb(s[l]);
		ansrev.pb(s[l]);
		dfs(l+1, r-1, k);
	}else{
		ll minl = minimum(l+1, r);
		ll minr = minimum(l, r-1);
		if(minr < minl){
			ans.pb(s[r-1]);
			ansrev.pb(s[r-1]);
			dfs(l, r-1, k);
		}else if(minl < minr){
			ans.pb(s[l]);
			ansrev.pb(s[l]);
			dfs(l+1, r, k);
		}else if(s[l] < s[r-1]){ // x[...]y
			ll res = count(l+1, r);
			if(k < res){
				ans.pb(s[l]);
				ansrev.pb(s[l]);
				dfs(l+1, r, k);
			}else{
				ans.pb(s[r-1]);
				ansrev.pb(s[r-1]);
				dfs(l, r-1, k - res);
			}
		}else{ // y[...]x
			ll res = count(l, r-1);
			if(k < res){
				ans.pb(s[r-1]);
				ansrev.pb(s[r-1]);
				dfs(l, r-1, k);
			}else{
				ans.pb(s[l]);
				ansrev.pb(s[l]);
				dfs(l+1, r, k - res);
			}
		}
	}
}
int main(){
	cin >> s >> k;
	memset(memo, -1, sizeof(memo));
	memset(mini, -1, sizeof(mini));
	dfs(0, s.size(), k - 1);
	return 0;
}

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

int main(){
	int arr[3];
	cin>>arr[0]>>arr[1]>>arr[2];
	swap(arr[0],arr[1]);
	swap(arr[0],arr[2]);
	for (int i = 0; i<3; i++){
		cout<<arr[i]<<" ";
	}
	return 0;
}

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

int c[32] = {0};

int main(){
    int w, n;
    cin >> w >> n;
    for(int i=1;i<=w;++i)
        c[i] = i;
    for(int i=0;i<n;++i){
        int a, b;
        scanf("%d,%d",&a,&b);
        int tmp;
        tmp = c[a];
        c[a] = c[b];
        c[b] = tmp;
    }
    for(int i=1;i<=w;++i)
        cout << c[i] << endl;

    return 0;
}


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

const int INF = (int)1e9;

struct Edge {
  int src, dst, cost;
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) { }
};

typedef vector<vector<Edge>> Graph;

int main() {
  ios::sync_with_stdio(false);

  int V, E, r; cin >> V >> E >> r;
  Graph G(V);
  for(int i = 0; i < E; i++) {
    int s, t, d; cin >> s >> t >> d;
    G[s].push_back(Edge(s, t, d));
  }

  bool negative_loop = false;
  vector<int> d(V, INF);
  d[r] = 0;
  for(int v = 0; v < V; v++) {
    for(int i = 0; i < (int)G.size(); i++) {
      if(d[i] == INF) continue;
      for(int j = 0; j < (int)G[i].size(); j++) {
        if(d[G[i][j].dst] > d[G[i][j].src] + G[i][j].cost) {
          d[G[i][j].dst] = d[G[i][j].src] + G[i][j].cost;
          if(v == V - 1) {
            negative_loop = true;
          }
        }
      }
    }
  }
  if(negative_loop) {
    cout << "NEGATIVE CYCLE" << endl;
  }
  else {
    for(int i = 0; i < V; i++) {
      if(d[i] == INF) cout << "INF" << endl;
      else cout << d[i] << endl;
    }
  }
}

Measured memory_bytes: 1272
#include <cstdio>
#include <iostream>
using namespace std;
struct Node{
	struct Node *p;
	struct Node *cl;
	struct Node *cr;
	int key;
};
typedef struct Node *node;
node root;
int cnt;
void insert(int v){
	node y = NULL;
	node x = root;
	node z;
	z = (node)malloc(sizeof(Node));
	z->cl= NULL;
	z->cr= NULL;
	z->key = v;
	while(x!=NULL){
		y = x;
		if(z->key < x->key) x = x->cl;
		else x = x->cr;
	}
	z->p = y;
	if(y== NULL){
		root = z;
	}
	else if(z->key < y->key) y->cl = z;
	else y->cr = z;
}
bool find_node(int x, node t){
	if(t == NULL) return false;
	if(t->key == x) return true;
	if(x < t->key){ 
		if(find_node(x, t->cl) == true) return true;
	}
	else {
		if(find_node(x, t->cr) == true) return true;
	}
	return false;

}
void print_preorder(node x){
	if(x == NULL) return;
	printf(" %d", x->key);
	print_preorder(x->cl);
	print_preorder(x->cr);
}
void print_inorder(node x){
	if(x == NULL) return;
	print_inorder(x->cl);
	printf(" %d", x->key);
	print_inorder(x->cr);
}
int main(){
	int n;
	int tmp;
	string t;
	scanf("%d", &n);
	for(int i=0; i<n;i++){
		cin >> t;
		if(t=="insert"){
			cin >> tmp;
			insert(tmp);
		}else if(t=="print"){
			cnt = 0;
			print_inorder(root);
			printf("\n");
			cnt = 0;
			print_preorder(root);
			printf("\n");
		}else if(t=="find"){
			cin >> tmp;
			if(find_node(tmp, root) ==true) cout <<"yes" <<endl;
			else cout <<"no"<<endl;
		}
	}
}







Measured memory_bytes: 22100
#include<stdio.h>
 
int main()
{
    int i=1,j=1;
    while(i<=9)
    {
        j=1;
        while(j<=9)
        {
            printf("%dx%d=%d\n",i,j,i*j);
            j++;
        }
        i++;
    }
    return 0;
}

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

using namespace std;

const int INF = 200000000;

int dp[2][2][5002], n, cost[10000];

main(){
  cin >> n;
  for(int i=0;i<n-1;++i) cin >> cost[i];
  fill(dp[0][0], dp[2][0], INF);
  dp[0][1][1] = dp[0][0][0] = 0;
  for(int i=0;i<n-1;++i){
    for(int j=0;j<=n/2;++j) dp[1-i%2][0][j] = dp[1-i%2][1][j] = INF;
    for(int j=0;j<=n/2;++j){
      dp[1-i%2][1][j+1] = min(dp[1-i%2][1][j+1], min(dp[i%2][1][j], dp[i%2][0][j] + cost[i]));
      dp[1-i%2][0][j] = min(dp[1-i%2][0][j], min(dp[i%2][0][j], dp[i%2][1][j] + cost[i]));
    }
  }
  cout << min(dp[1][0][n/2], dp[1][1][n/2]) << endl;
  return 0;
}

Measured memory_bytes: 944
n, x, m = gets.chomp.split.map(&:to_i)

h = {}
v = []

si = ei = nil

a = x
n.times do |i|
  v.push(a)
  if h.key?(a)
    si = h[a]
    ei = i
    break
  end
  h[a] = i

  a = (a * a) % m
end

if si.nil?
  puts v.sum
else
  v0 = v[0...ei]
  s0 = v0.sum
  v1 = v[si...ei]
  x = n - ei
  y = v1.size

  c = x / y
  d = x % y

  s1 = v1.sum * c
  s2 = v1[0...d].sum

  puts s0 + s1 + s2
end

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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

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


Measured memory_bytes: 256
#include<iostream>
#define INF 99999999
using namespace std;
int n,s,cnt;

int dp[(1<<10)+1][1000][11];

int rec(int S,int sum,int cnt){
  if(sum<0||sum>1000||cnt<0||cnt>10)return 0;
  if(dp[S][sum][cnt]!=INF)return dp[S][sum][cnt];

  if(cnt==0){
    if(sum==0)return 1;
    else return 0;
  }

  int res=0,x=0;
  for(int i=0;i<10;i++){
    if((S>>i)&1)x++;
  }

  for(int i=0;i<10;i++){
    if((S>>i)&1)continue;
    res+=rec(S+(1<<i),sum-(x+1)*i,cnt-1);
  }
  return dp[S][sum][cnt]=res;
}

int main(){
  for(int i=0;i<(1<<10)+1;i++){
    for(int j=0;j<1000;j++)
      for(int k=0;k<11;k++)dp[i][j][k]=INF;
  }
  while(cin>>n>>s){
    cout<<rec(0,s,n)<<endl;
  }
  return 0;
}

Measured memory_bytes: 45204