akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #pragma comment(linker, "/STACK:2000000")
  #pragma comment(linker, "/HEAP:2000000")
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  int32_t main()
  {        
    IOS
    int n,d;
    cin>>n>>d;
    int ans=n/(2*d+1);
    if(n%(2*d+1)!=0)
    {
      ans++;
    }
    cout<<ans;
    return 0;      
} 

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

using namespace std;

#define forn(i, s, f) for(int i = (s); i <= (f); ++i)
#define for1(i, f, s) for(int i = (f); i >= (s); --i)
#define fora(i, x) for (auto i : x)
#define show(x) cout << #x << " = " << x << " ";
#define skip continue;
#define pb push_back
#define _1 first
#define _2 second

typedef long long ll;

const int N3 = 1e3 + 5;
const int N4 = 1e4 + 5;
const int N5 = 1e5 + 5;
const int N6 = 1e6 + 5;
const int N7 = 1e7 + 5;
const int N8 = 1e8 + 5;
const int N9 = 1e9 + 5;

map < pair < int, int >, int > used;

int color[N5];

int n, m, x, q, y, v[N5], d[N5], c[N5];

int clr;

vector < int > g[N5];

void dfs(int v, int d)
{
    used[{v, d}] = 1;
    if (!color[v])
        color[v] = clr;
    if (d == 0)
    return;
    if (!used[{v, d - 1}])
        dfs(v, d - 1);
    fora (to, g[v])
    {
        if (!used[{to, d - 1}])
            dfs(to, d - 1);
    }
}

int main()
{
    cin >> n >> m;
    forn (i, 1, m)
    {
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    cin >> q;
    forn (i, 1, q)
    {
        cin >> v[i] >> d[i] >> c[i];
    }
    for1 (i, q, 1)
    {
        clr = c[i];
        if (!used[{v[i], d[i]}])
            dfs(v[i], d[i]);
    }
    forn (i, 1, n)
    {
        cout << color[i] << "\n";
    }
}


Measured memory_bytes: 65972
#include<bits/stdc++.h>
using namespace std;
struct item{
    int a;
    int b;
    int c;
};

int main()
{
    int n;
    cin>>n;
    vector<item> dp(n);
    for(int i=0;i<n;i++){
       int a1,b1,c1;
      cin>>a1>>b1>>c1;
        if(i==0){
            dp[0].a=a1;
            dp[0].b=b1;
            dp[0].c=c1;
        }
        else{
            dp[i].a=max(dp[i-1].b+a1,dp[i-1].c+a1);
            dp[i].b=max(dp[i-1].a+b1,dp[i-1].c+b1);
            dp[i].c=max(dp[i-1].b+c1,dp[i-1].a+c1);
        }
    }
    int ans=max(dp[n-1].a,max(dp[n-1].b,dp[n-1].c));
    cout<<ans<<"\n";
}


Measured memory_bytes: 4316
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int K,N;
	cin >> K >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int AAA = 0;
	for (int i = 0; i < N; ++i) {
		int res = 0;
		if (A[i] > A[(i + 1) % N]) {
			res = (K - A[i]) + A[(i + 1) % N];
		}
		else {
			res = A[i + 1] - A[i];
		}
		if (AAA < res) {
			AAA = res;
		}
	}
	cout << K - AAA << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1024
from collections import defaultdict as ddict
def cal_interval(Num):
	interval = ddict(int)
	dp = [0 for i in range(Num)]
	for i in range(Num):
		tmp = int(raw_input())
		for j in range(i+1):
			dp[j] += tmp
			interval[dp[j]] += 1
	return interval
while 1:
	N, M = map(int,raw_input().split(" "))
	if (N, M) == (0,0):
		break
	Lon = cal_interval(N)
	Lat = cal_interval(M)
	print sum(Lon[k] * Lat[k] for k in Lon if k in Lat)

Measured memory_bytes: 54360
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  pr((n+1)/2);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

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

    vector<lint> p(n);
    for(lint i=1; i<=n; i++) {
        lint a;
        cin >> a;
        a--;
        p[a] = i;
    }

    for(auto& e : p)  cout << e << " ";
}

Measured memory_bytes: 1536
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (k, s) = listOfInt()
    var count = 0

    for(i in 0..k) {
        for(j in 0..k) {
            if (i + j <= s && i + j + k >= s) count++
        }
    }

    println(count)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37944
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		sc.close();
		int a = T / A;
		int ans = 0;
		for (int i = 0; i < a; i++) {
			ans += B;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long MOD = 1000000007;
constexpr long long INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long N,K;cin >> N >> K;
    long long A[N],B[N];
    REP(i,N){
        cin >> A[i];
        B[i] = A[i];
    }
    long long ans = 0;
    for(long long i = 0;i<N-1;i++){
        if(A[i] > K){
            ans += A[i] - K;
            A[i] = K;
        }
        if(A[i] + A[i+1] > K){
            ans += A[i+1] - (K - A[i]);
            A[i+1] = (K - A[i]);
        }
    }
    long long ANS = 0;
    for(long long i = 0;i < N-1;i++){
        if(B[i+1] > K){
            ANS += B[i+1] - K;
            B[i+1] = K;
        }
        if(B[i] + B[i+1] > K){
            ANS += B[i] - (K - B[i+1]);
            B[i] = (K - B[i+1]);
        }
    }
    cout << min(ANS,ans) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  rep(i, n) if(s[i] == '0') cnt++;
  n -= cnt;
  cout << min(n, cnt) * 2 << endl;
}

Measured memory_bytes: 512
k,n = map(int, input().split())
a = list(map(int, input().split()))
a_t = []
a_t.append(a[0]+k-a[n-1])

a_before = a[0]
for i in a[1:]:
    tmp = i - a_before
    a_t.append(tmp)
    a_before = i
print(k-max(a_t))

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
using Graph = vector<vector<int>>;

int MOD=1000000007;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int Gcd(int x,int y)              //最大公約数
{
  int large = max(x,y);
  int small = min(x,y);

  while(small!=0){
      int amari =large%small;
      large = small;
      small = amari;  
  }
  return large;
}


// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 全頂点が訪問済みになるまで探索
    int count = -1;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
  
    cout << count << endl;
}


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

using namespace std;

int main() {
  int N, A, B;
  string s;
  cin >> N >> A >> B >> s;
  int f = 1;
  int passed = 0;
  for (char c : s) {
    if (c == 'a') {
      if (passed < A + B) {
        passed++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (c == 'b') {
      if (passed < A + B && f <= B) {
        passed++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
      f++;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 896
from collections import deque
#import numpy as np

h, w = map(int, input().split())
S = [input() for _ in range(h)] # #.のグリッドの場合

starts = []
for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            starts.append((i,j))

step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for si in starts:
    maxlen = 0
    seen = [[0] * w for _ in range(h)]
    que = deque()
    que.append(si)
    #seen[si[0]][si[1]] = 1
    while len(que) > 0:
        x, y = que.popleft()
        for xs, ys in step:
            xi, yi = x + xs, y + ys
            if xi < 0 or yi < 0 or xi >= h or yi >= w:
                continue
            if xi == si[0] and yi == si[1]:
                continue
            if S[xi][yi] == '#':
                continue
            if seen[xi][yi] != 0:
                continue
            else:
                seen[xi][yi] = seen[x][y] + 1
                que.append((xi, yi))
                maxlen = max(maxlen, seen[xi][yi])
    #print(np.array(seen))
    ans = max(ans, maxlen)
print(ans)

Measured memory_bytes: 45936
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i,j;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> a(55);
  ll MAX=0,tag=1;
  repl(i,1,n+1) {
    cin>>a[i];
    if(abs(MAX) < abs(a[i])){
      MAX = a[i];
      tag = i;
    }
}
  cout<<2*n-1<<endl;
  rep(i,n) cout<<tag<<' '<<i+1<<endl;
  if(MAX < 0) {
    for(int j = n-1;j > 0;j--) cout<<j+1<<" "<<j<<endl;
  } else {
    for(int j = 2;j <= n;j++) cout<<j-1<<" "<<j<<endl;
  }
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;

namespace TestField
{
    class Program
    {

        static void Main()
        {
            var input = new int[6];
            for (int i = 0; i < 6; i++)
                input[i] = int.Parse(ReadLine());

            bool isCan = true;
            int dist = input[4] - input[0];
            if (input[5] < dist)
                isCan = false;

            if (isCan == true)
                WriteLine("Yay!");
            else
                WriteLine(":(");
        }
    }
}


Measured memory_bytes: 13140
import math

a, b, h, m = map(int,input().split())
d = abs(0.5*(60*h+m) - 6*m)
if d > 180:
  d = 360 - d
c = math.cos(math.radians(d))
e = a*a + b*b - 2*a*b*c
f = math.sqrt(e)
print(f)


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

#define pb push_back
#define all(a) a.begin(), a.end()

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

const int N = 3e5 + 10;
int a[N];
vector<int> c, pref;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        ++a[x];
    }
    for (int i = 1; i <= n; ++i) {
        if (a[i] > 0)
            c.pb(a[i]);
    }
    sort(all(c));
    pref.pb(c.front());
    // c = {1, 3}
    // pref = {1, 4}
    for (int i = 1; i < c.size(); ++i)
        pref.pb(pref.back() + c[i]);
    for (int k = 1; k <= n; ++k) {
        int lo = 0, hi = n / k;
        int ans = lo;
        while (lo <= hi) {
            // can perform mid operation for current k?
            int mid = lo + hi >> 1;
            int p = lower_bound(all(c), mid) - c.begin();
            int mink = c.size() - p;
            if (p > 0) mink += pref[p - 1] / mid;
            if (mink >= k) {
                ans = mid;
                lo = mid + 1;
            }
            else 
                hi = mid - 1;
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 5616
#include <stdio.h>
#include <string.h>
char s[20],t[20];
int main(){
	int i,len;
	scanf("%s%s",s,t);
	len=strlen(s);
	for(i=0;i<len;i++)
		if(s[i]!=t[i])return 0*printf("No\n");
	return 0*printf("Yes\n");
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;

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

  int cnt = 1;
  int min;
  cin >> min;
  for (int i = 1; i < N; i++) {
    int n;
    cin >> n;
    if (min >= n) {
      min = n;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
sa = input()
s = list(sa)
a = [chr(ord('a') + i) for i in range(26)]
if sa == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    for i in range(len(a)):
        if a[i] not in s:
            s.append(a[i])
            print("".join(s))
            exit()
else:
    used = [s[25]]
    for i in range(25, 0, -1):
        if a.index(s[i-1]) > a.index(s[i]):
            used.append(s[i-1])
        else:
            for j in range(a.index(s[i-1])+1, 26):
                if a[j] in used:
                    s[i-1] = a[j]
                    print("".join(s[:i]))
                    exit()






Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A,B,C;
    std::string S[200],T[200];
    bool F=true;
    ll ans=0;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>A>>B;
    REP(i,A)cin>>S[i];
    REP(i,B){REP(j,A){
        DEB(S[j][i])
        if(S[j][i]=='#'){
            DEB(i)DEB(j)END
            REP(k,A)T[k]+=S[k][i];
            break;
        }
    }END}
    REP(i,A){
        bool f=false;
        REP(j,(signed)T[i].size()){
            if(T[i][j]=='#')f=true;
        }
        if(f)cout<<T[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

ll s[100][100];

int main() {
  ll n, m; cin >> n >> m;
  vector<ll> k(m);
  rep(i, 0, m){
    cin >> k[i];
    rep(j, 0, k[i]) cin >> s[i][j];
  }
  vector<ll> p(m);
  rep(i, 0, m) cin >> p[i];

  ll ans = 0;
  for(int tmp = 0; tmp < (1 << n); tmp++){
    bitset<12> t(tmp);
    bool f = true;
    //全ての電球に対して
    rep(i, 0, m){
      ll cnt = 0;
      rep(j, 0, k[i]){
        if(t[s[i][j]-1]) cnt++;
      }
      if(cnt%2 != p[i]) f = false;
    }
    if(f) ans++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
	int n;
	std::cin >> n;
	std::vector<ll> d(n);
	rep(i,n)std::cin >> d[i];
	if(d[0]!=0){
		std::cout << 0 << std::endl;
		exit(0);
	}
	sort(all(d));
	std::vector<int> a(d[n-1]+1,0);
	rep(i,n)a[d[i]]++;
	//rep(i,d[n-1]+1)std::cout << a[i] << std::endl;
	ll m=d[n-1]+1;
	ll ans=1;
	if(a[0]>=2){
		std::cout << 0 << std::endl;
		exit(0);
		
	}
	for (int i = 0; i < m-1; i++) {
		/* code */
		ans*=modpow(a[i],a[i+1],MOD);
		ans%=MOD;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 1408
from itertools import product

n = int(input())
s = input()

nums = [str(i) for i in range(10)]

ans = 0
for pat in product(nums, repeat=3):
    i = 0
    for e in s:
        if e == pat[i]:
            i += 1

        if i == 3:
            break

    if i == 3:
        ans += 1

print(ans)


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

int main(void){
    int N;
    cin >> N;
    
    vector<int> D(N);
    string answer = "No";
    for (int i = 0; i < N; i++) {
        int d_1, d_2;
        cin >> d_1 >> d_2;
        if (d_1 == d_2) {
            D[i] = 1;
        } else {
            D[i] = 0;
        }
        if ((i >= 2) && (D[i] == 1) && (D[i-1] == 1) && (D[i-2] == 1)) {
            answer = "Yes";
            break;
        }
    }
    
    cout << answer;
}


Measured memory_bytes: 3616
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A, B, C := ReadInt(), ReadInt(), ReadInt()
	for i := 1; i <= B; i++ {
		if A*i%B == C {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1840
function Main(input) {
    var N = input[0].split('');

    if (N[0] === '7' || N[1] === '7' || N[2] === '7') {
        console.log('Yes');
    } else {
        console.log('No');
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 29620
#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 reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  u64 n, x;
  cin >> n >> x;
  vu64 a(n);
  rep(i, n) cin >> a[i];
  vvu64 dp(n, vu64(n, 0));
  rep(i, n) dp[0][i] = a[i];
  rep(k, n - 1) rep(i, n) {
    i32 j = (i - k - 1 + n) % n;
    dp[k + 1][i] = min(dp[k][i], a[j]);
  }
  u64 ans = 1e18;
  rep(k, n) {
    u64 ret = k * x;
    rep(i, n) {
      ret += dp[k][i];
    }
    amin(ans, ret);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)


//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);



void solve()
{
    int n, a;
    cin >> n >> a;
    if(n % 500 <= a){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" << "\n";
    }
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    D = read_ints()
    S = sum(D)
    answer = 0
    for d in D:
        S -= d
        answer += d*S
    return answer


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 80044
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M, C;
  cin >> N >> M >> C;
  vll B(M);
  REP(i, 0, M) {
    ll b;
    cin >> b;
    B[i] = b;
  }
  vvll A(N);
  REP(i, 0, N) {
    vll _A(M);
    REP(j, 0, M) {
      ll a;
      cin >> a;
      _A[j] = a;
    }
    A[i] = _A;
  }

  ll result = 0;
  REP(i, 0, N) {
    ll sum = C;
    REP(j, 0, M) {
      sum += A[i][j] * B[j];
    }
    if (sum > 0) {
      result++;
    }
  }
  cout << result << endl;

  return 0;
}


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

string O, E;

int main() {
    cin >> O >> E;
    
    for (int i = 0; i < E.length(); i++) {
        cout << O[i] << E[i];
    }
    if (O.length() > E.length()) {
        cout << O[O.length() - 1] << endl;
    }
    else {
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int k;
    cin >> k;
    cout << (k / 2) * (k - k / 2) << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    string s;
    bool flag=false;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='A'&&s[i+1]=='C'){
            flag=true;
        }
    }
    if(flag){
        o("Yes");
    }else{
        o("No");
    }
}


Measured memory_bytes: 256
import math
S = input()
N = len(S)
ans = [complex(0) for _ in range(N)]

for i in range(0,N-1): # 0,1,,,,N-2
    if S[i] == S[i+1] and S[i]=='R':
        ans[i+1] += 1j +ans[i]
        ans[i] = 0j
    elif S[i] != S[i+1] and S[i]=='R':
        ans[i] += 1+0j

for i in range(N-1,0,-1): # N-1,N-2,,,,1
    if S[i] == S[i-1] and S[i]=='L':
        ans[i-1] += 1j +ans[i]
        ans[i] = 0j
    elif S[i] != S[i-1] and S[i]=='L':
        ans[i] += 1+0j

for i in range(N):
    if S[i] =='R' and ans[i].imag != 0:
        ans[i] += math.floor(ans[i].imag /2)
        ans[i+1] += math.ceil(ans[i].imag /2)
    elif S[i] =='L' and ans[i].imag != 0:
        ans[i] += math.floor(ans[i].imag /2)
        ans[i-1] += math.ceil(ans[i].imag /2)
sum = 0
for i in range(N):
    sum += ans[i]
for i in range(N):
    ans[i] = int(ans[i].real)


print(' '.join(map(str, ans)))

Measured memory_bytes: 10612
import sys
from collections import deque
def input():return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    to = [[] for _ in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
    
    # bfs
    visited = [False] * N
    par = [-1] * N 

    def bfs(s):
        q = deque()
        q.append(s)
        visited[s] = True
        par[s] = s

        while q:
            now = q.popleft()
            for nv in to[now]:
                if visited[nv]: continue
                else:
                    visited[nv] = True
                    par[nv] = now+1
                    q.append(nv)
    bfs(0)

    if -1 in par:
        print("No")
    else:
        print("Yes")
        print(*par[1:], sep="\n")

    

if __name__ == "__main__":
    main()

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N+1,0);
    int tmp = 1;
    bool flag = false;
    int ans =0;

    for(int i = 0; i < N; i++){
        cin >> a[i+1];
    }

    for(int i = 1; i <= N;i++){
        tmp = a[tmp];
        if(tmp == 2){
            ans++;
            flag = true;
            break;
        } else {
            ans++;
        }
    }
cout <<(flag? ans: -1) << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 29996224275833
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
// int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};



int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> v(n,vector<int> (m,0));
    vector<int> cost(n);
    
    fo(i,n){
        cin >> cost[i];
        fo(j,m){
            cin >> v[i][j];
        }
    }
    int ans = 1e15;
    fo(i,(1<<n)){
        vector<int> val(m, 0);
        int c = 0;
        fo(j,n){
            if(((1<<j)&i)>0){
                c += cost[j];
                fo(k,m){
                    val[k] += v[j][k];
                }
            }
        }
        int g = 1;
        fo(k,m){
            if(val[k]<x){
                g = 0;
            }
        }
        if(g==1){
            ans = min(ans, c);
        }
    }
    if(ans==1e15)
        cout << -1;
    else
    {
        cout << ans;
    }
    
}
    


Measured memory_bytes: 3660
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# low, high それぞれ取りうる最小の値と最大の値
low, high = 0, 0
ans = 0
# x: 任意の数をx個取った時を想定してループを回すための変数
for x in range(1, N + 2):
    # lowは 0 + 1 +... K-1までの値を足すことになる(そうすればK個任意の数を選んだ時の最小値となる)
    # highは K + K+1 + ... + Nまでの値を足すことになる(そうすればK個任意の数を選んだ時の最大値となる)
    low += x - 1
    high += N - x + 1
    if x >= K:
        ans += (high - low + 1)
        ans %= MOD

print(ans)

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

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

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(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));

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

const string OK  = "Possible\n";
const string BAD = "Impossible\n";

void solve() {
	int H = fetch<int>();
	int W = fetch<int>();

	auto M = fetch_vec<string>(H);
	int i = 0, j = 0;

	vector<vector<int>> visited(H, vector<int>(W, 0));

	while(i < H - 1 || j < W - 1) {
		visited[i][j] = 1;

		if(i < H - 1 && j < W - 1) {
			int cnt = (M[i + 1][j] == '#') + (M[i][j + 1] == '#');

			if(cnt == 1) {
				if(M[i + 1][j] == '#') {
					++i;
				} else {
					++j;
				}
			} else {
				cout << BAD;
				return;
			}
		} else if(i < H - 1) {
			if(M[i + 1][j] == '#') {
				++i;
			} else {
				cout << BAD;
				return;
			}
		} else { // (j < W)
			if(M[i][j + 1] == '#') {
				++j;
			} else {
				cout << BAD;
				return;
			}
		}
	}

	visited[i][j] = 1;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			if(!visited[i][j] && M[i][j] == '#') {
				cout << BAD;
				return;
			}
		}
	}

	cout << OK;
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B;
    vector<int> array(3);

    cin >> A >> B;

    array[0] = A + B;
    array[1] = A - B;
    array[2] = A * B;

    sort(array.begin(), array.end());
    cout << array[2] << endl;
}

Measured memory_bytes: 256
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 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};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

LL n,m;

int main()
{
  scanf("%lld %lld",&n,&m);
  LL risan = 0;
  if (n == 1 && m == 1) risan = 1;
  else if (n > 2 && m > 2) risan = (n - 2) * (m - 2);
  else
  {
    if (n == 1) risan = m - 2;
    else if (m == 1) risan = n - 2;
    else risan = 0;
  }
  printf("%lld\n",risan);
  return 0;
}











Measured memory_bytes: 256
#include<iostream>
#include<cstdint>
#include<algorithm>

int main() {
  int64_t A, B, K; std::cin >> A >> B >> K;
  int64_t eA = std::min(A, K);
  A -= eA; K -= eA;
  int64_t eB = std::min(B, K);
  B -= eB;
  std::cout << A << " " << B << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

ll now = 1000, pv = 1000, cnt = 0;
vector<int> a;
int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) {
        int x; cin >> x;
        a.pb(x);
    }
    a.resize(unique(a.begin(), a.end())-a.begin());
    n = a.size();
    if (n==1) {
        cout << 1000 << endl;
        return 0;
    }

    if (a[0]<a[1]) {
        cnt = now/a[0];
        now -= a[0]*cnt;
    }
    for (int i=1;i<n-1;i++) {
        if (a[i-1]>a[i]&&a[i+1]>a[i]) {
            pv = now;
            cnt = now/a[i];
            now -= a[i]*cnt;
        }
        if (a[i-1]<a[i]&&a[i+1]<a[i]) {
            now += a[i]*cnt;
            cnt = 0;
        }
    }
    if (a[n-2]<a[n-1]) {
        now += a[n-1]*cnt;
        cnt = 0;
    }

    cout << max(pv, now) << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    while(cin>>x)
    {
        if(x>= 400 && x<=599)
            cout<<8<<endl;
        else if(x>=600 && x<=799)
            cout<<7<<endl;
        else if(x>=800 && x<=999)
            cout<<6<<endl;
        else if(x>=1000 && x<=1199)
            cout<<5<<endl;
        else if(x>=1200 && x<=1399)
            cout<<4<<endl;
        else if(x>=1400 && x<=1599)
            cout<<3<<endl;
        else if(x>=1600 && x<=1799)
            cout<<2<<endl;
        else if(x>=1800 && x<=1999)
            cout<<1<<endl;


    }
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    LL a, b, x;
    cin >> a >> b >> x;
    cout << b/x - (0 < a ? a - 1 : -x)/x << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        int x = sc.nextInt();
        int y = sc.nextInt();
        String c = sc.next();
        HashMap<String, Integer> map = new HashMap<>();
        map.put(a, x);
        map.put(b, y);
        map.put(c, map.get(c) - 1);
        
        System.out.println(map.get(a) + " " + map.get(b));
    }
}


Measured memory_bytes: 21844
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;


public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int a;
        int b;
        ArrayList<Integer> A = new ArrayList<Integer>();
        ArrayList<Integer> B = new ArrayList<Integer>();
        for(int i = 0;i <= n * m - 1;i++){
            a = scan.nextInt();
            A.add(a);
        }
        for(int i = 0;i <= m - 1;i++){
            b = scan.nextInt();
            B.add(b);
        }
        for(int i = 0;i <= n - 1;i++){
            cOut(i,m,A,B);
        }
    }

    
    //行列cの生成・出力
    public static void cOut(int x,int m,ArrayList<Integer> A,ArrayList<Integer> B){
        int a;
        int b;
        int cSum = 0;
        for(int i = 0;i <= m - 1;i++){
            a = A.get(i + m * x);
            b = B.get(i);
            cSum += a * b;
        }
        System.out.println(cSum);
    }
}


Measured memory_bytes: 41148
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

vector<int> p,c,index;
int d,g;
int ans=INT_MAX;
int main()
{
	cin >> d >> g;
	g/=100;
	p.resize(d);
	c.resize(d);
	index.resize(d);
	
	rep(i,d)index[i]=i;

	rep(i,d)
	{
		cin >> p[i] >> c[i];
		c[i]/=100;
	}
	
	//rep(i,d)cout<<index[i]<<endl;

	
	do
	{
		int nows=0;
		int nown=0;
		
		
		for(int i=0;i<d;i++)
		{
			int ind = p[index[i]];
			for(int j=0;j<ind;j++)
			{
				
				if(nows+ind*(index[i]+1)<=g)
				{
					nows+=ind*(index[i]+1);
					nown+=ind;
					//if(nows>=g)break;
					break;
				}
				
				nown++;
				nows+=index[i]+1;
				if(nows>=g)break;
			}
			nows+=c[index[i]];
			if(nows>=g)break;
		}
		//cout<<' '<<nown<<endl;
		ans = min (ans,nown);
		
	} while (next_permutation(index.begin(),index.end() ) );
	
	cout<<ans<<endl;

	return 0;
}

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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  vi A{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int K;
  cin >> K;
  K--;
  cout << A[K] << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 256
def main():
    n = int(input())
    s = []
    if n==0:
        print(0)
        return
    while n!=1:
        if n%(-2)==-1:
            n = n//(-2)+1
            s.append(1)
        else:
            s.append(0)
            n = n//(-2)
    s.append(n)
    s.reverse()
    print(''.join([str(x) for x in s]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0,5) << " " << s.substr(6, 7) << " " << s.substr(14,5) << endl;
    return 0;
}


Measured memory_bytes: 3604