akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int solve(vector<int> h)
{
	const int N = h.size();
	int ans = 0;
	for (;;) {
		int l = max_element(h.begin(), h.end()) - h.begin();
		int r = l;
		for (; r < N; ++r) {
			if (h[r] != h[l]) {
				break;
			}
		}
		if (l == 0 && r == N) {
			ans += h[l];
			break;
		}
		int t = 0;
		if (l > 0) {
			t = max(t, h[l - 1]);
		}
		if (r < N) {
			t = max(t, h[r]);
		}
		ans += h[l] - t;
		for (int i = l; i < r; ++i) {
			h[i] = t;
		}
	}
	return ans;
}


int main()
{
	int N;
	cin >> N;
	vector<int> h(N);
	for (auto &x : h) cin >> x;
	cout << solve(h) << endl;
}


Measured memory_bytes: 256
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(5, 2), 18)

    def test_2(self):
        self.assertEqual(think(3, -1), 0)

    def test_3(self):
        self.assertEqual(think(30, -50), -1044)


def solve():
    n, l = read()
    result = think(n, l)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, l):
    a = [l + i - 1 for i in range(1, n + 1)]
    original_sum = sum(a)
    buf = []
    for i, e in enumerate(a):
        buf.append((abs(e), i))
    buf.sort(key=lambda x: x[0])
    return original_sum - a[buf[0][1]]


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 5696
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
};

int main() {
	ll n, m;
	cin >> n >> m;
	ll a[N], b[N];
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}

	UnionFind uf(n);
	int cnt[N];
	rep(i, n) cnt[i] = 1;

	ll ans[N];
	ans[m - 1] = n * (n - 1) / 2;
	for(int i = m - 1; i >= 1; i--) {
		if(!uf.issame(a[i], b[i])) {
			ans[i - 1] = ans[i] - cnt[uf.root(a[i])] * cnt[uf.root(b[i])];
			cnt[uf.root(a[i])] += cnt[uf.root(b[i])];
			uf.merge(b[i], a[i]);
		}
		else {
			ans[i - 1] = ans[i];
		}
	}
	rep(i, m) cout << ans[i] << endl;
}


Measured memory_bytes: 4480
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N, K; cin >> N >> K;

	int ans = 1;
	REP(i,N){
		ans = min(ans*2, ans+K);
	}
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;cin>>n;
  vector<int>sum(n,0);
  cin>>sum[0];
  
  for(int i=1;i<n;i++){
    int x;cin>>x;
    sum[i]=sum[i-1]+x;
  }
  int min1=sum[n-1];
  for(int i=1;i<n;i++){
    min1=min(min1,abs(sum[n-1]-2*sum[i]));
  }
  cout<<min1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const int mod = 1e5;
const int MAX = 1e7;

int main() {
    int d, g; cin >> d >> g;
    g /= 100;
    vector<P> a(d);
    rep(i,d) {
        int p, c; cin >> p >> c;
        c /= 100;
        a[i] = P(p,c);
    }
    int ans = inf;
    for (int i = 0; i < 1<<d; i++) {
        // cout << i << endl;
        int sum = 0;
        int ct = 0;
        rep(j,d) {
            if (i >> j & 1) {
                sum += a[j].first*(j+1) + a[j].second;
                ct += a[j].first;
            }
        }
        // cout << sum << endl;
        if (sum >= g) {ans = min(ans,ct); continue;}
        // cout << sum << endl;
        for (int j = d-1; j >= 0; j--) {
            if (!(i >> j & 1)) {
                int x = (g-sum+j)/(j+1);
                // cout << ct << x << sum << endl;
                if (x <= a[j].first-1) {
                    ct += x; 
                    ans = min(ans,ct);
                    break;
                }
                else {
                    ct += a[j].first-1;
                    sum += (a[j].first-1) * (j+1);
                }
            }
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include <vector>
#include <queue>

using namespace std;

int main(void){
  int i,N;
  int input;

  int card[1000];
  int Alice=0,Bob=0;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    cin>>card[i];
  }

  for(int i=0;i<N;i++){
    sort(card,card+N);
  }

  for(i=N-1;i>=0;i=i-2){
    Alice=Alice+card[i];
  }

  for(i=N-2;i>=0;i=i-2){
    Bob=Bob+card[i];
  }

  printf("%d\n",Alice-Bob);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[100100], sum, res;
bool ans = true;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    a[0] = a[n];
    if (sum % ((1 + n) * n / 2) != 0) ans = false;
    sum /= ((1 + n) * n / 2);
    for (ll i = 0; i < n; i++){
        if ((sum - (a[i + 1] - a[i])) % n != 0 || sum < a[i + 1] - a[i]) ans = false;
        res += (sum - (a[i + 1] - a[i])) / n;
    }
    if (res != sum) ans = false;
    cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const long long int INF = 1000000000000000000;
int main(){
    int N, K;
    cin >> N >> K;
    long long int a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }


    long long int ans = INF;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        int v = 0;
        long long int t = 0;
        long long int sum = 0;
        for (int i = 0; i < N; i++)
        {
            if(t < a[i]){
                t = a[i];
                v++;
            }
            else if(bit & (1 << i)){
                sum += t - a[i] + 1;
                v++;
                t++;
            }
        }
        if(v >= K) ans = min(ans, sum);
    }
    cout << ans << endl;
}

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

int main() {
   ll n;
   cin>>n;
   
   ll arr[n];
   map<ll,ll> m;
   ll sum = 0;
   for(int i = 0;i<n;i++){
   cin>>arr[i];
   m[arr[i]]++;
   sum += arr[i];
   }
   
   ll queries;
   cin>>queries;
   while(queries--)
   {
       ll b,c;
       cin>>b>>c;
       if(m.find(b)==m.end())
       {
           cout<<sum<<"\n";
       }
       else
       {
           sum = sum - m[b]*b + m[b]*c;
           ll temp = m[b];
           m.erase(b);
           m[c] = m[c] + temp;
           cout<<sum<<"\n";
           
       }
       
   }
  
    
	return 0;
}

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

main() {
    int n, k;
    cin >> n;
    for (k = 1; k * (k - 1) / 2 < n; ++k);
    if (k * (k - 1) / 2 != n) {
        puts("No");
        return 0;
    }
    vector <vector <int>> S(k);
    int x = 1;
    rep(i, 0, k) rep(j, i + 1, k) {
        S[i].push_back(x);
        S[j].push_back(x);
        x++;
    }
    puts("Yes");
    printf("%d\n", k);
    for (auto i : S) {
        printf("%d ", i.size());
        for (int j : i) printf("%d ", j);
        printf("\n");
    }
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

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

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = 998244353;

int H,W,N;
int sx, sy;
string S, T;
vector<pii> yseq, xseq;

int encode(char c) {
	if (c == 'L' or c == 'U') return -1;
	else return 1;
}

bool inside(int y, int x)
{
	return 1 <= y and y <= H and 1 <= x and x <= W;
}

signed main()
{
	cin >> H >> W >> N;
	cin >> sy >> sx;
	cin >> S >> T;

	rep(i, N) {
		if (S[i] == 'L' or S[i] == 'R') xseq.PB(0, encode(S[i]));
		else yseq.PB(0, encode(S[i]));
		if (T[i] == 'L' or T[i] == 'R') xseq.PB(1, encode(T[i]));
		else yseq.PB(1, encode(T[i]));
	}

	bool f = true; // YES

	{
		// x > W ?
		int curx = sx;
		rep(i, xseq.size()) {
			pii op = xseq[i];
			if (op.fst == 0) {
				if (op.scd > 0) {
					curx++;
				}
			} else {
				if (op.scd < 0 and curx - 1 >= 1) {
					curx--;
				}
			}

			if (curx > W) {
				f = false;
				//puts("1");
			}
		}
	}


	{
		// x < 1 ?
		int curx = sx;
		rep(i, xseq.size()) {
			pii op = xseq[i];
			if (op.fst == 0) {
				if (op.scd < 0) {
					curx--;
				}
			} else {
				if (op.scd > 0 and curx + 1 <= W) {
					curx++;
				}
			}

			if (curx < 1) {
				f = false;
				//puts("2");
			}
		}
	}

	{
		// y > H ?
		int cury = sy;
		rep(i, yseq.size()) {
			pii op = yseq[i];
			if (op.fst == 0) {
				if (op.scd > 0) {
					cury++;
				}
			} else {
				if (op.scd < 0 and cury - 1 >= 1) {
					cury--;
				}
			}

			if (cury > H) {
				f = false;
				//puts("3");
			}
		}
	}

	{
		// y < 1 ?
		int cury = sy;
		rep(i, yseq.size()) {
			pii op = yseq[i];
			if (op.fst == 0) {
				if (op.scd < 0) {
					cury--;
				}
			} else {
				if (op.scd > 0 and cury + 1 <= H) {
					cury++;
				}
			}

			if (cury < 1) {
				f = false;
				//puts("4");
			}
		}
	}

	cout << (f ? "YES" : "NO") << endl;
}




Measured memory_bytes: 10856
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;

typedef long long ll;
ll INF = 1LL << 60;

int 
main() {

  ll N; cin >> N;
  vector<int> arr(N);
  rep(i, 0, N) cin >> arr[i];

  sort(arr.begin(), arr.end());
  while(arr.size() >= 2){
    for(ll i = 1; i < arr.size(); i++){
      arr[i] = arr[i] % arr[0];
    }
    sort(arr.begin(), arr.end());
    arr.erase(remove(arr.begin(), arr.end(), 0), arr.end());
  }

  cout << arr[0] << endl;


}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)

typedef long long ll;

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

    double ret = 0;
    rep(i, N){
        double x;
        cin >> x;
        string type;
        cin >> type;

        if (type == "JPY"){
            ret += x;
        } else {
            ret += (x*380000.0);
        }
    }

    cout << ret << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

s = input()
t = input()

resultdiff = len(t)

# print(s)
# print(t)
# print("---")
for i in range(len(s)):
  # print(i)
  if len(s) < len(t) + i:
    # print("break")
    break
  subs = s[i:len(t) + i]
  # print(subs)

  diff = 0
  for j in range(len(t)):
    if t[j] != subs[j]:
      diff += 1
  if diff < resultdiff:
    resultdiff = diff

# print("***")
print(resultdiff)


Measured memory_bytes: 8940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define call(a) (a).cbegin(), (a).cend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define mt make_tuple
#define fs first
#define se second
#define loop(i,a,b) for(int i=(a);i<ull(b);i++)
#define rloop(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
#define set(a,c) memset(a,c,sizeof a)
#define clr(a) memset(a,0,sizeof a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define in scanf
#define out printf
#define f(i,j,k) fill(i[0],i[0]+j*j,k)
#define p(p) cout<<(p)<<endl;
#define exit(s,e) ((s).find(e)!=(s).end())
#define gcd(a,b) __gcd(a,b)
#define np(v) next_permutation(all(v))
#define pp(v) prev_permutation(all(v))
#define SORT(a) stable_sort(all(a))
#define RSORT(a) stable_sort(all(a),greater<int>())
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE() freopen("out0.txt","w",stdout)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<char, int> pci;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-14;
const double pi  = 2*acos(0.0);
const double inf = INT_MAX/3;
int lcm(int a, int b) {return a*b/__gcd(a,b);}
bool is_leapyear(int y){return y%4==0&&(y%100!=0||y%400==0);}

int solved(int n, int a, int b){
	if(a>b) return 0;
	else if (a==b||n==2) return 1;
	else if (n==1) return 0;
	else return (b-a)*(n-2)+1;
}

signed main(){
	int n, a, b;
	std::cin >> n >> a >> b;
	std::cout << solved(n,a,b) << std::endl;
}


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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> d(N);
    for(int i=0; i<N; ++i){
        cin>>d[i];
    }
    long sum = 0;
    for(int i=0; i<N; ++i){
        for(int j=i+1; j<N; ++j){
            sum+=d[i]*d[j];
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

int a,b,h,m,s;
 int main ()
 {
	 cin >> a;
	h = a / 3600;
	b = a - h * 3600;
	m =  b / 60;
	s = b % 60;
	 cout << h << ":" << m << ":" << s << endl;
 }

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

int main() {
    int n;
    cin >> n;
    vector<ll> a;

    rep(i, n) {
        ll x;
        cin >> x;
        if (i % 2 == 0)
            a.push_back(x);
        else
            a.insert(a.begin(), x);
    }
    if (n % 2 == 1) reverse(a.begin(), a.end());

    rep(i, n) {
        cout << a[i];
        if (i == n - 1)
            cout << endl;
        else
            cout << ' ';
    }
    return 0;
}


Measured memory_bytes: 5308
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>

using namespace std;

int xm[4] = {-1, 0, 1, 0};
int ym[4] = {0, 1, 0, -1};

int main(void)
{
    int h,w;
    cin >>h >>w;

    vector<string> maze_org;
    for(int i = 0; i < h; i++){
        string tmp;
        cin >>tmp;
        maze_org.push_back(tmp);
    }

    int longest = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            vector<string> maze = maze_org;
            if(maze[i][j] == '#'){
                continue;
            }else{
                queue<pair<int, pair<int, int> > > q;
                maze[i][j] = '#';
                q.push(make_pair(0, make_pair(i, j)));
                while(!q.empty()){
                    pair<int, pair<int, int> > current = q.front(); q.pop();
                    longest = max(longest, current.first);
                    for(int k = 0; k < 4; k++){
                        int nx = current.second.first + xm[k];
                        int ny = current.second.second + ym[k];
                        if(nx >= 0 && nx < h && ny >= 0 && ny < w){
                            if(maze[nx][ny] == '.'){
                                maze[nx][ny] = '#';
                                q.push(make_pair(current.first + 1, make_pair(nx, ny)));
                            }
                        }
                    }
                }
            }

        }
    }

    printf("%d\n", longest);

    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = []
y = []
for _ in range(n):
    line = list(map(int, input().split()))
    x.append(line[0])
    y.append(line[1])
if n >= 2:
    slope = []
    for i in range(n):
        for j in range(i+1, n):
            X = x[j] - x[i]
            Y = y[j] - y[i]
            if X != 0:
                if X < 0:
                    X = -X
                    Y = -Y
            slope.append([X, Y])
            if X == 0:
                slope.append([X, -Y])
    cnt = []
    for i in slope:
        cnt.append(slope.count(i))
    print(n - max(cnt))
else:
    print(1)

Measured memory_bytes: 40976
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
constexpr int INF = 0x3f3f3f3f;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  int x = a[0];
  int y = INF;
  int z = 0;
  rep(i, 1, n) {
    int w = abs(a[i] - a[0] / 2);
    if (w < y) {
      y = w;
      z = a[i];
    }
  }
  cout << x << " " << z << endl;
  return 0;
}

Measured memory_bytes: 3692
from time import time
from random import random

limit_secs = 2
start_time = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

def calc_score():
    score = 0
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        score += max(10 ** 6 + S, 0)
    return score

def calc_satisfaction():
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
    return S

def solution():
    return [i % 26 for i in range(D)]

t = solution()
S = calc_satisfaction()
while time() - start_time < limit_secs * 0.9:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_S = calc_satisfaction()
    if new_S < S:
        t[d] = old
        S = new_S

for e in t:
    if 0 <= e <= 25:
        print(e + 1)
    else:
        print(0)


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

using namespace std;

int main(){
  int a, b, ans;
  cin >> a >> b;
  int sum = a + b;
  int dif = a - b;
  int prod = a * b;

  ans = max(sum, dif);
  ans = max(ans, prod);
  cout << ans << '\n';
  return 0;
}

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

int calc(int p, int x, map<int, int> mp){
  	int sum = 0;
	mp[p-1] = x;
  	rep(i, mp.size()) {
    	sum += mp.at(i);
    }
  	return sum;
}

int main() {
    int n, t; // 問題数, 時間
  	cin >> n;
  	map<int, int> mp; // 時間
  	rep(i, n) {
    	cin >> t;
      	mp.insert(make_pair(i, t));
    }
  	int m; // ドリンク数
  	cin >> m;
  	int p, x; // 問題, 時間
  	while(m--){
    	cin >> p >> x;
     	cout << calc(p, x, mp) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int x,n; cin >> x >> n;
    map<int,int> mp;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        mp[a] = 1;
    }
    if (!mp[x]) {
        cout << x; return 0;
    }
    int i = x + 1;
    int j = x - 1;
    bool ok = true;
    while(ok) {
        if (!mp[j]) {
            cout << j; return 0;
        }
        if (!mp[i]) {
            cout << i; return 0;
        }
        i++;
        j--;
    }
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char [][] ch = new char[H][W];
		for (int i=0;i<H;i++) {
			String temp = sc.next();
			for (int j=0;j<W;j++) {
				ch[i][j] = temp.charAt(j);
			}
		}
		int up =-1;
		int down = 1;
		int left = -1;
		int right =1;
		for (int i=0;i<H;i++) {
			for (int j=0;j<W;j++) {
				if (ch[i][j]=='#') {
					if (i+up>=0) {
						if (ch[i+up][j]=='#') {
							continue;
						}
					}
					if (i+down<H) {
						if (ch[i+down][j]=='#') {
							continue;
						}
					}
					if (j+left>=0) {
						if (ch[i][j+left]=='#') {
							continue;
						}
					}
					if (j+right<W) {
						if (ch[i][j+right]=='#') {
							continue;
						}
					}
					System.out.println("No");
					return ;
				}
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23380
class cumulative_sum:
    def __init__(self,A):
        N = len(A)
        self.S = [0]*(N+1)
        for i in range(N):
            self.S[i+1] = self.S[i] + A[i]
    def get(self,i,j=None):
        if j==None:j=len(self.S)-1
        if j<=i:return 0
        return self.S[j]-self.S[i]

N,K = map(int,input().split())
*S, = map(int,input())

A = []
Aa = A.append
c = 0
b = 1
for s in S:
    if s!=b:Aa(c);b=s;c=0
    c+=1
Aa(c)
if len(A)%2==0:Aa(0)

SA = cumulative_sum(A)

ans = 0
ul = len(A)
for i in range(N):
    r = min(2*(i+K)+1,ul)
    ans = max(ans,SA.get(2*i,r))
    if r==ul:break
print(ans)

Measured memory_bytes: 8688
function Main(input: string) {
  const lines = input.split('\n');
  const params1 = lines[0].split(' ');

  const n = parseInt(params1[0]);
  const x = parseInt(params1[1]);
  const xs = lines[1].split(' ').map(x => parseInt(x));

  const euclid: (m: number, n: number) => number = (m, n) => {
    if (m < n) return euclid(n, m);
    if (n === 0) return m;
    return euclid(n, m % n);
  };

  const d = xs
    .map(a => Math.abs(a - x))
    .reduce(euclid);

  console.log(d);
}

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

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<pair<int, int>> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        c[i] = make_pair(a[i] + b[i], i);
    }

    sort(c.rbegin(), c.rend());

    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        if (i%2) ans -= b[c[i].second];
        else ans += a[c[i].second];
    }
    cout << ans << endl;

}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
using namespace std;

typedef long long LL;
const int INF =2147483647;
int qread(){
	int w=1,c,ret;
	while((c=getchar())> '9'||c< '0')
	w=(c=='-'?-1:1); ret=c-'0';
	while((c=getchar())>='0'&&c<='9')
	ret=ret*10+c-'0';
	return ret*w;
}
const int MAXN =1e5+3;
struct Node{
	int l,r,ID;
	Node(int _l,int _r,int _ID){
		l=_l,r=_r,ID=_ID;
	}
	Node(){}
}P[MAXN];
bool vis[MAXN];
struct cmp1{
	bool operator ()(Node a,Node b){
		return a.l<b.l;
	}
};
struct cmp2{
	bool operator ()(Node a,Node b){
		return a.r>b.r;
	}
};
priority_queue <Node,vector<Node>,cmp1> pq1;
priority_queue <Node,vector<Node>,cmp2> pq2;
int n,L[MAXN],R[MAXN];
LL calc(bool type){
	LL ret=0,pos=0,_pos;
	memset(vis,0,sizeof(vis));
	up(1,n,i) pq1.push(Node(L[i],R[i],i)),
			  pq2.push(Node(L[i],R[i],i));
	up(1,n,i){
		Node t=(type?pq1.top():pq2.top());
		type?pq1.pop():pq2.pop();
		if(vis[t.ID]) continue; else vis[t.ID]=true;
		if(pos<t.l) _pos=t.l; else
		if(pos>t.r) _pos=t.r; else _pos=pos;
		ret+=(LL)abs(pos-_pos),type=!type,pos=_pos;
	}
	return (ret+=(LL)abs(pos));
}
int main(){
	n=qread();
	up(1,n,i) L[i]=qread(),R[i]=qread();
	printf("%lld\n",max(calc(true),calc(false)));
	return 0;
}
/*
2
2147483647 2147483647
-2147483647 -2147483647
*/

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    double radc = c*M_PI/180;
    double S,L,h;
    S = 0.5*a*b*sin(radc);
    L = a+b+pow(a*a+b*b-2*a*b*cos(radc), 0.5);
    h = 2.0*S/a;
    cout<<fixed<<setprecision(10)<<S<<endl<<L<<endl<<h<<endl;
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  if (S=="SUN") cout << 7 << endl;
  if (S=="MON") cout << 6 << endl;
  if (S=="TUE") cout << 5 << endl;
  if (S=="WED") cout << 4 << endl;
  if (S=="THU") cout << 3 << endl;
  if (S=="FRI") cout << 2 << endl;
  if (S=="SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

w, h, x, y, r = map(int, raw_input().split())
if -100 <= x <= 100 and -100 <= y <= 100 and \
   0 < w <= 100 and 0 < h <= 100 and 0 < r <= 100:
    if x + r <= w and y + r <= h and x - r >= 0 and y - r >= 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 6436
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n;
double dp[3005][3005];
double a[3005];
signed main() {
	cin>>n;
	rep(i,n)cin>>a[i];
	dp[0][0]=1;
	rep(i,n){
		rep(j,i+1){
			dp[i+1][j+1]+=dp[i][j]*a[i];
			dp[i+1][j]+=dp[i][j]*(1-a[i]);
		}
	}
	double ans=0;
	for(int i=n/2+1;i<=n;i++)ans+=dp[n][i];
	printf("%.12lf\n",ans);
}


Measured memory_bytes: 69120
package main

import "fmt"

func main() {
	var (
		N, M int
	)

	fmt.Scanf("%d %d\n", &N, &M)
	foods := make([]bool, M+1)
	for i := 1; i <= M; i++ {
		foods[i] = true
	}

	for i := 0; i < N; i++ {
		var K int
		fmt.Scanf("%d", &K)
		f := make([]bool, M+1)
		for j := 0; j < K; j++ {
			var A int
			fmt.Scanf("%d", &A)
			f[A] = true
		}

		for j := 1; j <= M; j++ {
			foods[j] = foods[j] && f[j]
		}
	}

	var res int
	for _, food := range foods {
		if food {
			res++
		}
	}
	fmt.Println(res)
}


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

int main(){
  string S,H;
  cin >> S >> H;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=H.at(i)){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
//#define INF 2e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    int a=0,b=0;
    int n=0,x,t;

    cin >> n >> x >> t;
    a = n/x;
    if(n%x>0) a++;
    cout << t*a;
}

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

//var 
string s,t;
bool g = 1;

int main(){
	cin >> s >> t;
	for(int i = 0; i<s.size(); i++){
		g &= (s[i] == t[i]);
	}cout << (g?"Yes":"No") << endl;
}

Measured memory_bytes: 3620
n = gets.to_i
suits = ["S", "H", "C", "D"]
# rubyで２次元配列初期化するときこんな感じ
cards = Array.new(suits.size).map { Array.new((1..13).to_a) }
n.times do
    # pythonでいうところのisnumericで分ける的なやつ pythonと違って漢数字とかには使えないけど
    # suit, score = gets.chomp.split.map { |s| s=~ /^\d$/ ? s.to_i : s }
    suit, score = gets.chomp.split.map { |s| s.match?(/^\d+$/) ? s.to_i : s }
    # puts "suit: #{suit} score: #{score}"
    if cards[suits.index(suit)].include?(score)
        cards[suits.index(suit)].delete(score)
        # print cards
        # puts
    end
end

cards.each_with_index do |s, idx|
    s.each do |num|
        puts "#{suits[idx]} #{num}"
    end
end


Measured memory_bytes: 6876
n=int(input())
a=list(map(int,input().split()))
num2=0
num4=0
num0=0
for i in a:
    if i%4==0:
        num4+=1
    elif i%2==0:
        num2+=1
    else:
        num0+=1
if num2==0:
    if num0<=num4+1:
        print("Yes")
    else:
        print("No")
else:
    if num0<=num4:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 15020
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
static const int num = 1001;
int lcs(string ch1, string ch2) {
	int s = ch1.size();
	int t = ch2.size();
	ch1.insert(0, " ");
	ch2.insert(0, " ");
	int c[num][num];
	for (int i = 0; i <= s; i++) c[i][0] = 0;
	for (int i = 0; i <= t; i++) c[0][i] = 0;
	for (int i = 1; i <= s; i++) {
		for (int j = 1; j <= t; j++) {
			if (ch1[i] == ch2[j]) c[i][j] = c[i - 1][j - 1] + 1;
			else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
		}
	}
	return c[s][t];
}
int main() {
	int q;
	cin >> q;
	string a, b;
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		cout << lcs(a, b) << endl;
	}
	return 0;
}

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

using Int = long long int;
template <class T>
using Vector = std::vector<T>;

int main() {
    Int n;
    std::cin >> n;
    Int m = (1 << n);

    Vector<Int> a(m);
    for (auto& x : a) std::cin >> x;

    Vector<Vector<Int>> max(m);
    // kの部分bit全体で、aが大きい方から2つ(0だけ1つ)
    max[0] = {0};

    Int ans = 0;
    for (Int k = 1; k < m; ++k) {
        auto& idx = max[k];
        idx.push_back(k);

        for (Int i = 0; i < n; ++i) {
            if ((k >> i) & 1) {
                for (auto x : max[k ^ (1 << i)]) {
                    idx.push_back(x);
                }
            }
        }

        std::sort(idx.begin(), idx.end(), [&](Int i, Int j) {
            return (a[i] == a[j] ? i < j : a[i] > a[j]);
        });
        idx.erase(std::unique(idx.begin(), idx.end()), idx.end());
        idx.resize(2);

        ans = std::max(ans, a[idx[0]] + a[idx[1]]);
        std::cout << ans << std::endl;
    }
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N;
vpint G[111111];

int ans[111111];

void dfs(int v,int p,int cp){
	int nex=0;
	for(auto &e:G[v]){
		if(e.fi==p)continue;
		if(nex==cp)nex++;
		ans[e.se]=nex;
		dfs(e.fi,v,nex++);
	}
}
signed main(){
	cin>>N;
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].eb(b,i);
		G[b].eb(a,i);
	}

	dfs(0,-1,-1);

	cout<<*max_element(ans,ans+N-1)+1<<endl;
	rep(i,N-1)cout<<ans[i]+1<<endl;
	return 0;
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int mod = 1000000007;

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

    string s; cin >> s;

    int answer = 0;

    string last = "";

    for (int i = 0; i < (int)s.length();){
        string t = s.substr(i, 1);

        if (t == last){
            if (i + 2 <= (int)s.length()){
                last = s.substr(i, 2);
                i += 2;
            } else {
                break;
            }
        } else {
            last = t;
            i += 1;
        }

        answer++;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 720
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    len_S = len(S)
    dp = [[0] * 13 for _ in range(len_S + 1)]
    dp[0][0] = 1

    for i in range(len_S):
        S_i = S[i]
        for j in range(13):
            if S_i == '?':
                for k in range(10):
                    dp[i+1][(j*10+k)%13] += dp[i][j]
                    dp[i+1][(j*10+k)%13] %= MOD
            else:
                dp[i+1][(j*10+int(S_i))%13] += dp[i][j]
                dp[i+1][(j*10+int(S_i))%13] %= MOD

    # for i in dp:
    #     print(i)
    print(dp[-1][5])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 94700
#include <stdio.h>

int change(int *m, int *n);

int main(void){

  int a, b, c;

  scanf("%d %d %d\n", &a, &b, &c);

  if(a > b)
    change(&a, &b);
  if(b > c)
    change(&b, &c);
  if(a > b)
    change(&a, &b);

  printf("%d %d %d\n", a, b, c);

  return 0;
}

int change(int *m, int *n){
  int l;

  l = *m;
  *m = *n;
  *n = l;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] != S[i + 1]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 078 C / Link: http://abc078.contest.atcoder.jp/tasks/abc078_c  ----- */


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

	LL N, M; cin >> N >> M;


	LL ans = pow(2,M)*(1900*M+100*(N-M));
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
import sys
N, Y = map(int, input().split())
for a in range(N+1):
    for b in range(N+1):
        c = N - a - b
        if c < 0:
            continue
        if (10000*a + 5000*b + 1000*c) == Y:
            print(str(a)+" "+str(b)+" "+str(c))
            sys.exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
#define endl '\n'
 
// void print_vi(vi a){
//     for (auto i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }
 
void solve(){

    int l , r , d;
    cin >> l >> r >> d;
    int temp1 = l/d;
    int temp2 = r/d;
    int ans = 0;
    if (l %d == 0)
    ans ++;
    ans += temp2 - temp1;
    cout << ans;

}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    int t = 1;
    // cin >> t;
    
    while(t--){ 
        solve();
        cout << endl;
    }
}

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

const int mod = 1000000007;
int n;

int DP[101][256];
bool valid(int s) {
  int a[4] = { s >> 6, (s >> 4) & 3, (s >> 2) & 3, s & 3 };
  
  if (a[0] == 1 && a[1] == 2 && a[2] == 3) return false;
  if (a[1] == 1 && a[2] == 2 && a[3] == 3) return false;
  for (int i = 1; i < 4; ++i) {
    int b[4];
    for (int k = 0; k < 4; ++k) b[k] = a[k];
    swap(b[i - 1], b[i]);
    if (b[0] == 1 && b[1] == 2 && b[2] == 3) return false;
    if (b[1] == 1 && b[2] == 2 && b[3] == 3) return false;
  }
  return true;
}

int main() {
  cin >> n;
  
  DP[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int s = 0; s < 256; ++s) {
      for (int k = 0; k < 4; ++k) {
        int t = ((s << 2) | k) & 255;
        if (!valid(t)) continue;
        DP[i + 1][t] += DP[i][s];
        DP[i + 1][t] %= mod;
      }
    }
  }
  
  int sum = 0;
  for (int s = 0; s < 256; ++s) {
    sum = (sum + DP[n][s]) % mod;
  }
  cout << sum << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template<typename tn> void read(tn &a){
    tn x=0,f=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
    a=x*f;
}
template<typename tn> void print(tn a){
    if(a<0) putchar('-'),a=-a;
    if(a>9) print(a/10);
    putchar(a%10+'0');
}
int a;
string s;
int main(){
	read(a);
	cin>>s;
	if(a>=3200)
	   cout<<s<<endl;
	else
	   puts("red");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
bool solve(const int dt, const int dx, const int dy) {
  int d	= abs(dx) + abs(dy);
  if(d > dt) return false;
  return (dt-d) % 2	== 0;
}

int main() {
  int n; cin>>n;
  vector<int> t(n+1, 0), x(n+1, 0), y(n+1, 0);
  for(int i = 1; i <= n; i++) {
    cin>>t[i]>>x[i]>>y[i];
    bool res = solve(t[i]-t[i-1], x[i]-x[i-1], y[i]-y[i-1]);
    if(!res) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N - 1];
		for (int i = 0; i < B.length; i++)
			B[i] = sc.nextInt();

		for (int i = 0; i < A.length; i++) {
			if (i == 0)
				A[i] = B[i];
			else if (i != A.length - 1)
				A[i] = B[i - 1] < B[i] ? B[i - 1] : B[i];
			else
				A[i] = B[i - 1];
		}
		int ans = 0;
		for (int i = 0; i < A.length; i++) {
			ans += A[i];
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21844
#
# abc053 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1000"""
        output = """ABC"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2000"""
        output = """ARC"""
        self.assertIO(input, output)


def resolve():
    x = int(input())

    if x < 1200:
        print("ABC")
    else:
        print("ARC")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16108
#!/usr/bin/python3

import heapq
import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, S):
    bt = [0] * (2 ** (N + 1) - 1)
    M = len(bt)
    pq = []
    heapq.heappush(pq, (0, 0))

    S.sort(reverse=True)

    i = 0
    while i < len(S):
        v = S[i]
        j = i
        while j < len(S) and v == S[j]:
            j += 1
        c = j - i
        i = j

        if len(pq) < c:
            return False

        pl = [heapq.heappop(pq) for _ in range(c)]
        for level, idx in pl:
            ll = level
            while True:
                assert bt[idx] == 0
                bt[idx] = v
                s = 2 * idx + 1
                t = s + 1
                if s >= M:
                    break
                idx = s
                ll += 1
                heapq.heappush(pq, (ll, t))

    return True


def main():
    N = int(inp())
    S = [int(e) for e in inp().split()]
    print('Yes' if solve(N, S) else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 120820
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  lint K;
  cin >> K;
  lint ans[50];
  rep(i,50) ans[i]=K/50+49;
  lint remain=K%50;
  rep(i,50){
    if(i<remain) ans[i]+=51-remain;
    else ans[i]-=remain;
  }
  cout << 50 << endl;
  rep(i,50) cout << ans[i] << " ";
  cout << endl;
}

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

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

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

  ll sum = 0;

  ll ans1 = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 0 && sum <= 0) {
      ans1 += -1 * sum + 1;
      sum = 1;
    } else if (i % 2 != 0 && sum >= 0) {
      ans1 += sum + 1;
      sum = -1;
    }
  }
  sum = 0;

  ll ans2 = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 != 0 && sum <= 0) {
      ans2 += sum * -1 + 1;
      sum = 1;
    } else if (i % 2 == 0 && sum >= 0) {
      ans2 += sum + 1;
      sum = -1;
    }
  }

  ll ans = min(ans1, ans2);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int s[205000];
vector<int>v[205000];
int main()
{
   	int n,m;
   	memset(s,-1,sizeof(s));
   	cin>>n>>m;
  	while(m--){
  		int u,v1;
  		cin>>u>>v1;
  		v[u].push_back(v1);
  		v[v1].push_back(u);
	} 
	queue<int>que;
	s[1]=0;
	for(int i=0;i<v[1].size();i++)
	{
		que.push(v[1][i]);
		s[v[1][i]]=1;	
	}
	while(!que.empty()){
		int p=que.front();
		que.pop();
		for(int i=0;i<v[p].size();i++)
		{
			int g=v[p][i];
			if(s[g]==-1)
			{
				s[g]=p;
				que.push(g);
			}
		}
	}
	int flag=1;
	for(int i=2;i<=n;i++)
	{
		if(s[i]==-1){
			flag=0;
			break;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++){
			cout<<s[i]<<endl;
		}
	}else{
		cout<<"No"<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 13364