akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  [itmo] enot.1.10
 *    created: 10.10.2016 07:02:14       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e6 + 10;

char s[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    scanf("%s", s);
    int ca = 0, cb = 0;
    forn(i, n)
    {
        int ok = 0;
        if (s[i] == 'a')
        {
            if (ca + cb < a + b)
            {
                ok = 1;
                ca++;
            }
        }
        if (s[i] == 'b')
        {
            if (ca + cb < a + b && cb < b)
            {
                ok = 1;
                cb++;
            }
        }
        if (ok) printf("Yes\n");
        else printf("No\n");
    }
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 768
// https://atcoder.jp/contests/abc106/tasks/abc106_d
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// https://github.com/drken1215/algorithm/blob/master/DataStructure/binary_indexed_tree_2D.cpp
template <class Abel> struct BIT2D {
    const Abel UNITY_SUM = 0; // to be set
    vector<vector<Abel>> dat;

    BIT2D(int n = 1, int m = 1) : dat(n + 1, vector<Abel>(m + 1, UNITY_SUM)) {}
    void init(int n, int m) {
        dat.assign(n + 1, vector<Abel>(m + 1, UNITY_SUM));
    }

    /* add x on the point (a, b) */
    inline void add(int a, int b, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            for (int j = b; j < (int)dat[0].size(); j += j & -j)
                dat[i][j] = dat[i][j] + x;
    }

    inline Abel sum(int p, int q) {
        Abel res = UNITY_SUM;
        for (int i = p; i > 0; i -= i & -i)
            for (int j = q; j > 0; j -= j & -j)
                res = res + dat[i][j];
        return res;
    }

    /* a1 <= x < b1, a2 <= y < b2, 1-indexd */
    inline Abel sum(int a1, int a2, int b1, int b2) {
        return sum(b1 - 1, b2 - 1) - sum(a1 - 1, b2 - 1) - sum(b1 - 1, a2 - 1) +
               sum(a1 - 1, a2 - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) {
            for (int j = 1; j < (int)dat[0].size(); ++j)
                cout << sum(i, j, i + 1, j + 1) << ",";
            cout << endl;
        }
    }
};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    BIT2D<int> ft(N, N);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        ft.add(l, r, 1);
    }
    while (Q--) {
        int l, r;
        cin >> l >> r;
        // [l, r)の半開区間なので右側は+1する
        cout << ft.sum(l, l, r + 1, r + 1) << "\n";
    }

    return 0;
}


Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define erep(i, n) for (int i = 0; i <= (n); i++)
#define erep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;


int main() {
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
}

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

typedef long long ll;

struct Edge {
    ll t,w;
};

struct State {
    ll v;
    ll score;
    bool operator < (const State& tgt) const {
	return score > tgt.score;
    }
};

vector<ll> dijkstra(vector<vector<Edge>>& G, const int start) {
    const ll V = G.size();

    vector<ll>res(V,INT_MAX);
    priority_queue<State> q;
    q.push( State{0,0} );
    while( q.size() ) {
	State s = q.top(); q.pop();
	if( res[s.v] != INT_MAX ) continue;
	res[s.v] = s.score;
	for(auto& e : G[s.v]) {
	    if( res[e.t] != INT_MAX ) continue;
	    q.push( State{e.t, s.score + e.w} );
	}
    }
    return res;
}


int main () {

    ll V; cin >> V;
    vector<vector<Edge>> G(V);
    for(int i=0; i<V; i++) {
	ll u,k; cin >> u >> k;
	for(int j=0; j<k; j++) {
	    ll v,w; cin >> v >> w;
	    G[i].push_back( Edge{v,w} );
	}
    }
    vector<ll> res = dijkstra(G,0);
    for(int i=0; i<V; i++) {
	cout << i << " " << res[i] << endl;
    }    
    return 0;
}

Measured memory_bytes: 15772
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(){
    int a,b,h,m;
    long double kaku_h,kaku_m,rad,ans = 0;
    long double pi = acos(-1);
    cin >> a >> b >> h >> m;
    kaku_h = (h * 30 / 360.0) * 360 + m * 0.5;
    kaku_m = (m * 6 / 360.0) * 360;
    rad = min(abs(kaku_h - kaku_m),abs(360 - abs(kaku_h - kaku_m)));
    ans = sqrt(a * a + b * b - 2 * a * b * cos(rad * pi / 180.0 ));
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int n,ara[52],flag=0;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>ara[i];
    }

    for(int i=1;i<=n;i++)
    {
        if(ara[i]!=i)
        {
            flag++;
        }
    }

    if(flag==0 || flag==2)
    {
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

vector<vector<ll> > table;
vector<P> roads;
vector<P> qs;

int main() {
  ll N, D, X;

  cin >> N >> D >> X;

  ll consume = 0;
  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    consume += (D-1)/tmp + 1;
  }

  ll ans = X + consume;
  cout << ans << endl;

  return 0;
}


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

int main(){
  int n,x,sum=0,num=0;
  cin >> n >> x;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  for(int i=0; i<n; i++){
    sum += vec.at(i);
    if(sum == x){
      num++;
      break;
    }else if(sum > x){
      break;
    }else{
      num++;
    }
  }
  
  if(sum < x){
    cout << num-1 << endl;
  }else{
    cout << num << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  vector<string> vs;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    string tmp;
    getline(cin, tmp);
    int j = 0;
    while ((j = tmp.find("Hoshino", j)) != string::npos) {
      tmp[j+6] = 'a';
      j += 7;
    }
    vs.push_back(tmp);
  }

  for (int i = 0; i < vs.size(); i++)
    cout << vs[i] << endl;
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

int main(){

   int n, element;
   int ans = 0;

   cin >> n;

   for(int i = 0; i < n; i++){
      int f_prime = 1;
      cin >> element;
      for(int j = 2; j * j <= element; j++){
         if(element % j == 0){
            f_prime = 0;
            break;
         }
      }
      if(f_prime){
         ans++;
      }
   }

   cout << ans << endl;

   return 0;
}


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

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

    if (a < b && a <= c && c <= b) {
        cout << "Yes" << endl;
    } else if (b <= a && b <= c && c <= a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int x, y, z, e, m;
    while (1) {
        scanf("%d", &e);
        if (e==0) break;
        m=1000000;
        for (z=0; z*z*z<=e; z++) {
            for (y=0; y*y+z*z*z<=e; y++) {
                x=e-y*y-z*z*z;
                if (x+y+z<m) m=x+y+z;
            }
        }
        printf("%d\n", m);
    }
    return 0;
}



Measured memory_bytes: 1984
stdin.ReadLine()
let nums = stdin.ReadLine().Split(" ") |> Array.map double
let point = 
  nums 
  |> Array.reduce (+) 
  |> fun x -> x / (Array.length nums |> double)
  |> System.Math.Round

nums 
|> Array.map (fun x -> (x - point) * (x - point))
|> Array.reduce (+)
|> int
|> printfn "%d"

Measured memory_bytes: 30048
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

struct union_find {
    vector<int> d;
    union_find(int n) : d(n, -1) {}
    int find(int x) {
        if (is_root(x)) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (size(x) < size(y)) return unite(y, x);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
    bool is_root(int x) { return d[x] < 0; }
};


int main() {
    int n, m;
    cin >> n >> m;
    union_find uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        uf.unite(a, b);
    }
    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int n,m;

int dp[111][111][2][2];
string plan[111];

int calc(int r, int c, int invLastR, int invLastC) {
	int& ans = dp[r][c][invLastR][invLastC];
	if(ans == -1) {
		if(r == n-1 && c == m-1)
			return ans=0;
		int bestAns = 1<<30;
		if(r < n) {
			if(plan[r+1][c] == '#') {
				bestAns = min(
					bestAns,
					1+calc(r+1, c, 1, 1)
				);
				if(invLastR) {
					bestAns = min(
						bestAns,
						calc(r+1, c, 1, invLastC)
					);
				}
			} else {
				bestAns = min(
					bestAns,
					calc(r+1, c, 0, 0)
				);
				bestAns = min(
					bestAns,
					1+calc(r+1, c, 1, 1)
				);
			}
		}
		if(c < m) {
			if(plan[r][c+1] == '#') {
				bestAns = min(
					bestAns,
					1+calc(r, c+1, 1, 1)
				);
				if(invLastC) {
					bestAns = min(
						bestAns,
						calc(r, c+1, invLastR, 1)
					);
				}
			} else {
				bestAns = min(
					bestAns,
					calc(r, c+1, 0, 0)
				);
				bestAns = min(
					bestAns,
					1+calc(r, c+1, 1, 1)
				);
			}
		}
		ans = bestAns;
	}
	return ans;
}

void solve(istream& cin, ostream& cout) {
	cin >> n >> m;
	memset(dp, -1, sizeof(dp));
	REP(i, n) {
		string cstr;
		cin >> cstr;
		plan[i] = cstr;
	}
	if(plan[0][0] == '#')
		cout <<(1+calc(0, 0, 1, 1)) << endl;
	else 
		cout <<(calc(0, 0, 0, 0)) << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int ans = 1e9 + 1;
  for (int i=0; i<s.size(); ++i) {
    string tmp = s.substr(i, 3);
    ans = min(ans, abs(stoi(tmp) - 753));
  }
  cout << ans << endl;
  return 0;
}

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

int n, k, ans;
int main()
{
    int i;
    cin >> n >> k;
    ans = k;
    for (i = 0; i < n - 1; i++) {
        ans *= k - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k, i, a[200005], l, r, m, _k;
int main()
{
    scanf("%d%d", &n, &k);
    for (i = 1; i <= n; ++i)
    {
        scanf("%d", &a[i]);
        r = max(r, a[i]);
    }
    l = 1;
    while (l < r)
    {
        m = (l + r) >> 1;
        _k = 0;
        for (i = 1; i <= n; ++i)
            _k += (a[i] - 1) / m;
        if (_k <= k)
            r = m;
        else
            l = m + 1;
    }
    printf("%d", l);
}

Measured memory_bytes: 4492
class UnionFind:
    def __init__(self, size):
        self.data = [i for i in range(size)]
    def find(self, x):
        if self.data[x] != x:
            self.data[x] = self.find(self.data[x])
        return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            self.data[x] = min(x, y)
            self.data[y] = self.data[x]

N, K, L = [int(i) for i in input().split()]

uf1 = UnionFind(N)
for _ in range(K):
    p, q = [int(i) - 1 for i in input().split()]
    uf1.union(p, q)

uf2 = UnionFind(N)
for _ in range(L):
    r, s = [int(i) - 1 for i in input().split()]
    uf2.union(r, s)

from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    d[(uf1.find(i), uf2.find(i))] += 1

l = ""
for i in range(N):
    l += str(d[(uf1.find(i), uf2.find(i))]) + " "
print(l[:-1])

Measured memory_bytes: 47780
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

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

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 100000;
ll A[MAX_N];

// return x^n % p  O(log n)

ll mod_pow(ll x, ll n, ll p) {
  if(n == 0) return 1;
  ll res = mod_pow(x * x % p, n / 2, p);
  if(n & 1) res = res * x % p;
  return res;
}

int main(){
  cin >> N;
  REP(i, N) cin >> A[i];
  map<int, int> mp;
  REP(i, N) mp[A[i]]++;
  if(N % 2 == 0) {
    REP(i, N / 2) {
      if(mp[i * 2 + 1] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << mod_pow(2, N / 2, MOD) << endl;
  } else {
    REP(i, N / 2) {
      if(mp[i * 2 + 2] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    if(mp[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    cout << mod_pow(2, N / 2, MOD) << endl; 
  }



  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    int before = 0, after[n];
    fill(after, after + n, 0);
    after[1] = 1;
    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (after[a] || after[b])
            swap(after[a], after[b]);
        if (before == a || before == b) {
            before = (before == a) ? b : a;
        }
        if (0 < before) after[before - 1] = 1;
        if (before < n - 1) after[before + 1] = 1;
    }
    after[before] = 1;
    int res = accumulate(after, after + n, 0);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 768
# Problem A - Security

# input process
S = input()
S_len = len(S)

# initialization
is_ok = True

# count process
for i in range(S_len-1):
    if S[i]==S[i+1]:
        is_ok = False
        break

# output process
if is_ok:
    print("Good")
else:
    print("Bad")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

ll mod=1e9+7;

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b) {
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=mod; if(u<0) u+=mod;
  return u;
}

ll com(ll n, ll k) {
  ll a=1,b=1;
  rep(i,k) {
    a=(a*(n-i))%mod;
    b=(b*(i+1))%mod;
  }
  return (a*modinv(b))%mod;
}

ll solve(ll n) {
  n-=5;
  ll ret=0,m;
  rep(i,12) {
    m=n-i;
    if(m<0||m%2!=0) continue;
    ret=(ret+com(m/2+15,15)*com(11,i))%mod;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll T,n;cin>>T;
  rep(i,T) {
    cin>>n;
    print(solve(n));
  }
  return 0;
}

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

// change minimum
// aよりbが小さかったら、aの値をbの値に置き換えて、trueを返す
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

long long int dp[100010];

int main()
{
    dp[0] = 0;
    for (int n = 1; n <= 100000; n++)
    {
        dp[n] = INT_MAX;
        int power = 1;
        while (power <= n)
        {
            chmin(dp[n], dp[n - power] + 1);
            power *= 6;
        }
        power = 1;
        while (power <= n)
        {
            chmin(dp[n], dp[n - power] + 1);
            power *= 9;
        }
    }
    int n;
    cin >> n;

    cout << dp[n] << endl;
}

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

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

using namespace std;

int main()
{
  int n;
  int cnt = 0;
  cin >> n;
  int a;
  
  for(int i=1; i<=n; i++){
    cin >> a;
    if(i&1){
      if(a&1) cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
public class Main {

    final static boolean fileIO = false;
    final static boolean DEBUG = false;
    final static String input = "input.txt";
    final static String output = "output.txt";
    
    public static void main(String args[]) throws Exception {

		InputStream is = null;
		OutputStream os = null;
		if (fileIO) {
			is = new FileInputStream("input.txt");
			os = new FileOutputStream("output.txt");
		} else {
			is = System.in;
			os = System.out;
		}
		InputReader in = new InputReader(is);
		PrintWriter out = new PrintWriter(os);
		new Task_A().solve(in, out);
		out.close();	

	}

static class Task_A {
	
	public void solve(InputReader in, PrintWriter out) {
		char a[] = in.nextString("\n").toCharArray();
		boolean ans = false;
		if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3])){
			ans = true;
		}
		out.println(ans ? "Yes" : "No");
	}
}


static class InputReader {
	
	private StringTokenizer tokenizer;
	private BufferedReader reader;

	public InputReader(InputStream is) {
		tokenizer = null;
		reader = new BufferedReader(new InputStreamReader(is), 32768);
	}

	public String nextString(String delim) {
		String ans = null;
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				String line = reader.readLine();
				if (line != null) {
					tokenizer = new StringTokenizer(line, delim);
					ans = tokenizer.nextToken();
				} else {
					ans = null;
				}
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		} else {
			ans = tokenizer.nextToken();
		}
		return ans;
	}
}
}




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

int main()
{
    string str;
    int q;

    cin >> str >> q;
    for (int i = 0; i < q; i++) {
        string od;
        int a, b;
        cin >> od >> a >> b;
        if (od == "print") {
            cout << str.substr(a, b - a + 1) << endl;
        } else if (od == "reverse") {
            string tmp = str.substr(a, b - a + 1);
            int n = tmp.size();
            for (int j = 0; j < n; j++)
                str[j + a] = tmp[n - j - 1];
        } else if (od == "replace") {
            char p[b - a + 1];
            cin >> p;
            str.replace(a, b - a + 1, p);
        }
    }
}


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

#define N 1000001
#define IN 200000
#define mod 998244353
#define ll long long

int add(int x,int y) {
    int ret = (x+y);
    if(ret>=mod) {
        ret -= mod;
    }
    if(ret<0) {
        ret += mod;
    }
    return ret;
}
int mul(int x,int y) {
    return (ll)x*y%mod;
}
int mypow(int x,int c) {
    int ret = 1;
    while(c>0) {
        if(c&1) {
            ret = mul(ret,x);
        }
        x = mul(x,x);
        c/=2;
    }
    return ret;
}
int sum[N], dp[N], d[N];
bool numPrimeParity[N];
void solve() {
    int x,n;scanf("%d",&n);
    int i,ret = 0,j;
    for(i=1;i<N;++i) d[i] = 1;
    for(i=0;i<n;++i) {
        scanf("%d",&x);
        sum[x] =add(sum[x], x);
        ret = add(ret, -x);
    }
    for(i=2;i<N;++i) {
        if(d[i]==1) {
            for(j = i;j<N;j+=i) {
                d[j] *= i;
                numPrimeParity[j] ^= 1;
            }
        }
    }
    for(i=N-1;i>=1;--i) {
        int x = 2;
        int r = sum[i],R = 0;
        for(j = i+i;j<N;j+=i,++x) {
            r = add(r, sum[j]);
            if(d[x]!=x) {
                continue;
            }
            if(numPrimeParity[x]) {
                R = add(R,-dp[j]);
            } else {
                R = add(R,dp[j]);
            }
        }
        r = mul(r,r);
        dp[i] = r;
        R = add(R,r);
        ret = add(ret, mul(R,mypow(i,mod-2)));
    }
    ret = mul(ret, mypow(2,mod-2));
    printf("%d\n",ret);
}
int main()
{
    solve();
    return 0;
}


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

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

    int k, result = 0, ans = 0;
    int v[5];
    for(int i = 0; i < 5; i++){
        cin >> v[i];
    }

    cin >> k;

    for(int i = 0; i < 4; i++){
        for(int j = i+1; j < 5; j++){
            if(v[i] > v[j]){
                result = v[i] - v[j];
                if(result <= k)
                    ans++;
            }
            else{
                result = v[j] - v[i];
                if(result <= k)
                    ans++;
            }
            
        }
    }

    if(ans == 10) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
    
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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;
}

void Main()
{
    LL n,p;cin>>n>>p;
    if(n==1){
        cout<<p<<endl;
        return;
    }

    LL result = 1;
    LL p2=p;

    for(LL i=2; i*i <= p2+100; i++){
        LL sum=0;
        while(p%i == 0){
            sum++;
            p/=i;
        }
        if(sum >= n){
            result *= modpow(i,(LL)(sum/n));
        }
    }
    cout<<result<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

using namespace std;

int n;

const int N = 300;
const int K = N;
const int H = 1e9;
const long long LLINF = N * 1LL * H + 7;

long long dp[N + 7][K + 7];
int h[N + 7];

long long dpf (int i, int k) {
	long long &d = dp[i][k];

	if (d != -1) {
		return d;
	}

	if (i > n) {
		return d = 0;
	}

	d = LLINF;

	for (int j = i; j <= min(n, i + k); j++) {
		d = min(d, max(0, h[j + 1] - h[i]) + dpf(j + 1, k - (j - i)));
	}

	return d;
}

int main () {
	memset(dp, -1, sizeof dp);

	int k;
	cin >> n >> k;

	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}

	cout << dpf(0, k) << "\n";

	return 0;
}

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

int nxt[20][100000], rev[20][100000];

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++)  cin >> x[i];
    vector<int> y(n);
    for(int i = 0; i < n; i++)  y[i] = 1e9-x[n-1-i];
    int l;
    cin >> l;
    for(int i = 0; i+1 < n; i++){
        nxt[0][i] = upper_bound(x.begin(),x.end(),x[i]+l)-x.begin()-1;
        rev[0][i] = upper_bound(y.begin(),y.end(),y[i]+l)-y.begin()-1;
    }
    nxt[0][n-1] = -1;
    rev[0][n-1] = -1;
    for(int k = 0; k+1 < 20; k++){
        for(int i = 0; i < n; i++){
            if(nxt[k][i] < 0)  nxt[k+1][i] = -1;
            else               nxt[k+1][i] = nxt[k][nxt[k][i]];
            if(rev[k][i] < 0)  rev[k+1][i] = -1;
            else               rev[k+1][i] = rev[k][rev[k][i]];
        }
    }
    auto f = [&](int a, int b, int c[20][100000])->int{
        int ret = 0, tmp = a;
        for(int k = 19; k >= 0; k--){
            int to = c[k][tmp];
            if(to >= 0 && to < b){
                tmp = to;
                ret += 1<<k;
            }
        }
        return ret+1;
    };
    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        a--, b--;
        if(a < b)   cout << f(a, b, nxt) << endl;
        else        cout << f(n-1-a, n-1-b, rev) << endl;
    }
    return 0;
}

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

struct Shop
{
    long long price;
    long long number;
};


bool cmp(const Shop &a, const Shop &b){
    return a.price < b.price;
}

int main(){

    long long n;
    long long m;
    cin >> n;
    cin >> m;

    long long sum = 0;
    long long pSum = 0;
    vector<Shop> shops(n);
    for(long long i = 0; i < n; i++){
        cin >> shops[i].price;
        cin >> shops[i].number;
    }
    sort(shops.begin(), shops.end(),cmp);

    for(long long i = 0; i < n; i++){
        if(sum + shops[i].number >= m){
            pSum += (m - sum) * shops[i].price;
            cout << pSum << endl;
            return 0;
        }
        else{
            pSum += shops[i].price * shops[i].number;
            sum += shops[i].number;
        }
    }

}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b;
  cin >> a >> b;

  int p = a + b;
  int m = a - b;
  int f = a * b;

  cout << max({p, m, f}) << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));

typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
map< ll, int > prime_factor(ll n) {//素因数分解
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
int main(){
    ll n,p;
    std::cin >> n>>p;
    std::map<ll, int> m=prime_factor(p);
    ll ans=1;
    if(n==1ll){
        std::cout << p << std::endl;
        exit(0);
    }
    rep(i,sqrt(p)+1){
        if(m[i]>=n)ans*=pow(i,(m[i]/n));
    //    if(i==2)std::cout << m[i]/n << std::endl;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 62720
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n=10
warshall_floyd(c)


ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        else:
            ans+=c[a[i][j]][1]
print(ans)


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		String result = "Yes";

		if(A==B && B==C && A==C) {
			result="No";

		}else if(A!=B && B!=C && A!=C) {
			result="No";
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23380
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)cout<<(n-2)*(b-a)+1<<endl;
    else
    cout<<0<<endl; 
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    int a,b,q;
    cin >> a >> b >> q;
    vector<ll> s(a),t(b);
    rep(i,a) cin >> s[i];
    rep(i,b) cin >> t[i];
    rep(i,q) {
        ll ans;
        ll x;
        cin >> x;
        auto sit = lower_bound(all(s),x);
        auto tit = lower_bound(all(t),x);
        if(sit == s.begin()) {
            if(tit == t.begin()) {
                ans = max(*sit,*tit)-x;
            } else if(tit == t.end()){
                tit--;
                ans = *sit-*tit+min(*sit-x,x-*tit);
            } else {
                auto titb = tit-1;
                ans = min(*sit-*titb+min(*sit-x,x-*titb),max(*sit,*tit)-x);
            }
        } else if(sit == s.end()) {
            sit--;
            if(tit == t.begin()) {
                ans = *tit-*sit+min(*tit-x,x-*sit);
            } else if(tit == t.end()) {
                tit--;
                ans = x-min(*sit,*tit);
            } else {
                auto titb = tit-1;
                ans = min(*tit-*sit+min(*tit-x,x-*sit),x-min(*sit,*titb));
            }
        } else {
            auto sitb = sit-1;
            if(tit == t.begin()) {
                ans = min(max(*sit,*tit)-x,*tit-*sitb+min(*tit-x,x-*sitb));
            } else if(tit == t.end()) {
                tit--;
                ans = min(x-min(*tit,*sitb),*sit-*tit+min(*sit-x,x-*tit));
            } else {
                auto titb = tit-1;
                ans = min(max(*sit,*tit)-x,*tit-*sitb+min(*tit-x,x-*sitb));
                chmin(ans,min(x-min(*titb,*sitb),*sit-*titb+min(*sit-x,x-*titb)));
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

struct Edge{int to,weight; Edge(int t, int w) : to(t), weight(w) {}};
using DirectedGraph = vector<vector<Edge>>;
using UndirectedGraph = vector<vector<int>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int>ps(N);
    REP(i,N){
        cin>>ps[i];
        --ps[i];
    }

    int MAX=30000;
    vector<int> A(N),B(N);
    REP(i,N){
        A[i] = B[N-1-i] = MAX*i+1;
    }

    REP(i,N) A[ps[i]]+=i;
    REP(i,N){
        cout<<A[i]<<" \n"[i==N-1];
    }
    REP(i,N){
        cout<<B[i]<<" \n"[i==N-1];
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
                            
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
#define int ll

using namespace std;
 
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int a[N],b[N],c[N];

 main(){
		
	NFS
	
	int n,ans=0;
	cin >> n;
	
	for(int i=1;i<=n+1;i++)cin >> a[i];
	
	if(n==0){
		if(a[1]!=1){
			cout << -1 << endl;
		}
		else cout << 1 << endl;
		ioi
	}
	
	b[1]=1;
	
	for(int i=2;i<=n+1;i++){
		b[i]=b[i-1]*2;
		b[i]=min(b[i],(ll)2e18);
	}
	
	if(a[n+1]>b[n+1]){
		cout << -1 << endl;
		ioi
	}
	
	c[1]=1;
	
	if(a[1]!=0){
		cout << -1 << endl;
		ioi
	}
	
	for(int i=2;i<=n+1;i++){
		c[i]=c[i-1]*2;
		c[i]-=a[i];
		c[i]=min(c[i],(ll)2e18);
	}
	
	int cur=a[n+1];
	
	for(int i=n+1;i>1;i--){
		ans+=cur;
		//cout << cur << endl;
		if((cur+1)/2>c[i-1]){
			cout << -1 << endl;
			ioi
		}
		cur=min(c[i-1],cur)+a[i-1];
	}
	ans++;
	
	cout << ans << endl;

	ioi
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int g[3010][3010];
int ans[3010][3010][4];
signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int R, C, K;
  cin >> R >> C >> K;
  rep(i, 0, K) {
    int r, c, v;
    cin >> r >> c >> v;
    g[r][c] = v;
  }

  rep(i, 1, R + 1) {
    rep(j, 1, C + 1) {
      ans[i][j][0] = max(ans[i - 1][j][3], ans[i][j - 1][0]);
      ans[i][j][1] = max(ans[i - 1][j][3] + g[i][j],
                         max(ans[i][j - 1][1], ans[i][j - 1][0] + g[i][j]));
      ans[i][j][2] = max(max(ans[i - 1][j][3], ans[i][j - 1][1]) + g[i][j],
                         ans[i][j - 1][2]);
      ans[i][j][3] = max(max(ans[i - 1][j][3], ans[i][j - 1][2]) + g[i][j],
                         ans[i][j - 1][3]);
    }
  }
  cout << ans[R][C][3] << '\n';
  return 0;
}

Measured memory_bytes: 356268
import math
 
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

prime = [0 for i in range(11000)]
j = 0
for i in range(len(p)):
    if p[i]:
        prime[j] = i+1
        j += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print sum(prime[:n])

Measured memory_bytes: 8808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a;

int main(){
	cin >> n;
	REP(i, n){
		cin >> a;
		cout << "Case " << i + 1 << ":" << endl;
		REP(i, 10){
			a = a*a / 100;
			a %= 10000;
			cout << a << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c){
    cout<<1<<endl;
  }else if(a==b || b==c || c==a){
    cout<<2<<endl;
  }else{
    cout<<3<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  string s;cin>>s;
  int a=(s[0]-'0')*10+s[1]-'0';
  int b=(s[2]-'0')*10+s[3]-'0';
  if(0<a&&a<=12&&0<b&&b<=12)cout<<"AMBIGUOUS"<<endl;
  else if(0<a&&a<=12)cout<<"MMYY"<<endl;
  else if(0<b&&b<=12)cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
}

Measured memory_bytes: 3424
#include<stdio.h>
#include<math.h>
int main()
{
	long long int n;
	scanf("%lld",&n);
	long long int i,g=2,m=0;
	for(i=2;i<sqrt(n)+0.5;i++)
	{
		if(n%i==0)
		{
			m=i;
			g=1;
		}
	}
	if(g==1)
	{
		long long int c=n/m;
		printf("%lld",c+m-2);
	}
	else
	{
		printf("%lld",n-1);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int day;
  int cost[30];
  int satisfied[370][30];
  int i,j;

  scanf("%d",&day);

  for(i=0;i<26;i++){
    scanf("%d ",&cost[i]);
  }

  for(i=0;i<day;i++){
    for(j=0;j<26;j++){
      scanf("%d ",&satisfied[i][j]);
    }
  }

  for(i=0;i<day;i++){
    printf("%d\n",i%26+1);
  }
  return(0);
}


Measured memory_bytes: 3868
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;



int main() {
	int a, b;
	cin >> a >> b;
	for (int c = 1; c <= 3; c++) {
		if ((a * b * c) % 2 == 1) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    int t = n;
    int tmp = 0;
    while(n){
        tmp += n % 10;
        n /= 10;
    }
    if(t % tmp == 0){
        cout << "Yes" << endl;
    }else{

        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
N, L = [int(i) for i in input().split(' ')]

min_ = L
max_ = L + N -1

def eat_apple(N, L):
    if L < 0:
        if max_<0:
            return max_ 
        return 0
    return L

print(int((min_+max_)*(max_-min_+1)/2 - eat_apple(N, L)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define M 998244353
#define MOD 1000000007
signed main()
{
    SPEED;
    int n,k,cnt=0;
    cin>>n>>k;
    int mn=0,mx=0;
    for(int i=0;i<k-1;i++)
    {
        mn+=i;
    }
    for(int i=n;i>n-k+1;i--)
    {
        mx+=i;
    }
    for(int i=k;i<=n+1;i++)
    {
        mn+=i-1;
        mx+=n+1-i;
        cnt+=(mx-mn+1)%MOD;
        cnt%=MOD;
    }
    cout<<cnt;
}

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	ll i,q=0,w=0;
	cin>>s;
	for(i=0;i<s.length();i++) {
		if(s[i]=='A') q=1;
		else w=1;
	}
	if(q==1 && w==1) cout<<"Yes";
	else cout<<"No";
	
}

Measured memory_bytes: 256
// ２つの整数の最大公約数を求める
#include<iostream>
using namespace std;

int main()
{
    int x, y, r, N;
    int gcd = 0;
    cin >> x >> y;
    if (x > y) 
    {
        r = x % y;
        N = y;
    }
    if (x < y)
    {
        r = y % x;
        N = x;
    }
    if ( x == y)
    {
        r = x;
        N = x;
    }
    
    for (int i = 1; i <= r; i++)
    {
        if( r % i == 0 &&  N % i == 0)
        {
            gcd = i;
        }
    }
    cout << gcd << endl;

    return 0;
}


Measured memory_bytes: 3104