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

using namespace std;

typedef pair<int,int> P;

const int MAX = 1001;
char field[MAX][MAX];
bool come[MAX][MAX];
vector<P> V;
int W,H,gh,gw;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

void print(){
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++) cout << come[i][j];
    cout << endl;
  }
  cout << endl;
}
void input(){
  cin >> W >> H;

  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++){
      cin >> field[i][j];
      if(field[i][j] == 't'){
	gh = i;
	gw = j;
      }
    }

  int N;
  cin >> N;
  V.resize(N);
  for(int i = 0; i < N; i++) cin >> V[i].first >> V[i].second;
}

bool isInside(int x, int y){return 0<=x&&x<W&&0<=y&&y<H;}
/*
void dfs(int row, int col){
  //  cout << row << " " << col << endl;
  if(come[row][col]) return;
  come[row][col] = true;

  for(int i = 0; i < 4; i++){
    int nr = row+dy[i];
    int nc = col+dx[i];
    if(!isInside(nc,nr)) continue;
    if(field[nr][nc] == '#') continue;
    dfs(nr,nc);
  }
}
*/
void bfs(int row, int col){
  queue<P> Q;
  Q.push(P(row,col));

  while(!Q.empty()){
    P p = Q.front(); Q.pop();
    if(come[p.first][p.second]) continue;
    come[p.first][p.second] = true;

    for(int i = 0; i < 4; i++){
      P nex;
      nex.first = p.first + dy[i];
      nex.second = p.second + dx[i];
      if(!isInside(nex.second,nex.first)) continue;
      if(field[nex.first][nex.second] == '#') continue;
      Q.push(nex);
    }
  }
}

int solve(){
  bfs(0,0);
  if(come[gh][gw]) return 0;

  //  print();

  for(int i = 0; i < (int)V.size(); i++){
    bool reach = false;
    field[V[i].second][V[i].first] = '.';
    for(int j = 0; j < 4; j++){
      int pr = V[i].second-dy[j];
      int pc = V[i].first-dx[j];
      
      if(!isInside(pc,pr)) continue;
      
      reach = reach||come[pr][pc];
    }
    if(reach) bfs(V[i].second,V[i].first);
    if(come[gh][gw]) return i+1;

    //   print();
  }
  return -1;
}

int main(){
  input();
  cout << solve() << endl;
  return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);
  long double r;
  cin >> r;
  cout << r * 3.1415926535  * 2<< endl;
  return 0;
}



Measured memory_bytes: 3808
"use strict"
function main(arg) {
    var m = arg.trim().split("\n")[0].split(' ').map(Number)[1]
    var ai = arg.trim().split("\n")[1].split(' ').map(Number).sort((a,b) => b - a)
    var sum = 0
    var sum_m = 0
    for (var i = m - 1; i < ai.length; i++) {
        sum_m += ai[i]
    }
    for (var i = 0; i < ai.length; i++) {
        sum += ai[i]
    }
    // console.log(sum)
    for (var i = 0;i < m;i ++) {
        if (ai[i] < sum / (4 * m)) {
            console.log('No')
            return
        } 
    }
    console.log('Yes')
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
/*
a[i]+a[j]=j-i
a[i]+i=j-a[j]
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N];
map<ll,int> m;
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
	    cin>>a[i];
	    m[a[i]+i]++;
	}
	ll ans=0;
	for(int j=1;j<=n;j++){
	    ans+=m[j-a[j]];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 26964
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int bitcnt(long bits){
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<char>> grid(H, vector<char>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> grid[i][j];
	
	int ans = INF;
	for (int bit = 0b0; bit < (1 << (H - 1)); bit++) {

		int cnt = bitcnt(bit);

		vector<int> id(H);
		for (int i = 0; i < H - 1; i++) {
			if (bit & (1 << i)) id[i + 1] = id[i] + 1;
			else id[i + 1] = id[i];
		}

		vector<int> sum(H);
		for (int w = 0; w < W; w++) {

			bool reset = false;
			for (int h = 0; h < H; h++) {

				sum[id[h]] += grid[h][w] - '0';

				if (sum[id[h]] > K) {
					if (reset) {
						cnt = w = h = INF;
					}
					else {
						reset = true;
						cnt++;
						fill(sum.begin(), sum.end(), 0);
						h = -1;
					}
				}

			}
		}

		chmin(ans, cnt);

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a+b+1)/2<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prac
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var an = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            for (var i = 0; i < n; i++)
            {
                if (i != 0)
                    Console.Write(" ");
                Console.Write(an[n - 1 - i]);
            }
   Console.WriteLine();

        }
    }
}

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

int main() {
  int N;
  cin >> N;
  int X = sqrt(N) + 1;
  int F;

  for (int l = 1; l<=N ; l++){
  F =0;
  for (int i = 1; i<=X ; i++){
    for (int j = i; j<=X ; j++){
      for (int k = j; k<=X ; k++){
        if ( i*i + j*j + k*k + i*j + j*k + k*i == l ){
          if ( i == j && j == k){
            F++;
          }
          else if ( i!=j && j!=k && k!=i ){
            F+=6;
          }
          else {
            F+=3;
          }
        }
      }
    }
  }
  cout << F << endl;
  }
}

Measured memory_bytes: 3520
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<deque>
using namespace std;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

int main(){
    int n,k;
    cin>>n>>k;
    vector<long>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    long ans=0;
    int right=min(k,n);
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k-i;j++){
            if(i+j>n){
                continue;
            }
            vector<long> vec;
            vec.insert(vec.end(),v.begin(),v.begin()+i);
            vec.insert(vec.end(),v.begin()+n-j,v.end());
        //    copy(v.begin(),v.begin()+i,vec.begin());
        //    copy(v.begin()+n-j,v.end(),back_inserter(vec));
        //    cout<<i+j<<" "<<endl;
            sort(vec.begin(),vec.end());
            int nokori=k-i-j;
            long tmp=0;
            for(int l=0;l<i+j;l++){
        //        cout<<vec[l]<<" ";
                if(vec[l]<0&&l<nokori){
                    continue;
                }
                tmp+=vec[l];
            }
    //        cout<<endl;
            ans=max(ans,tmp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			
			if(a == 0 && b == 0){
				break;
			}
			
			int[][] count = new int[b][a];
			
			final int n = sc.nextInt();
			
			for(int i = 0; i < n; i++){
				final int x = sc.nextInt() - 1;
				final int y = sc.nextInt() - 1;
				count[y][x] = -1;
			}
			
			for(int i = 0; i < b; i++){
				for(int j = 0; j < a; j++){
					if(i == 0 && j == 0){
						count[i][j] = count[i][j] != -1 ? 1 : -1;
					}else if(i == 0){
						count[i][j] = count[i][j] != -1 ? count[i][j-1] : -1;
					}else if(j == 0){
						count[i][j] = count[i][j] != -1 ? count[i-1][j] : -1;
					}else{
						if(count[i][j] == -1){
							count[i][j] = -1;
						}else if(count[i][j-1] == -1 && count[i-1][j] == -1){
							count[i][j] = -1;
						}else if(count[i][j-1] == -1){
							count[i][j] = count[i-1][j];
						}else if(count[i-1][j] == -1){
							count[i][j] = count[i][j-1];
						}else{
							count[i][j] = count[i][j-1] + count[i-1][j];
						}
					}
				}
			}
			/*
			for(int i = 0; i < b; i++){
				for(int j = 0; j < a; j++){
					System.out.print(count[i][j] + " ");
				}
				System.out.println();
			}
			*/
			
			System.out.println(count[b-1][a-1]);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#define N 44 
void makeFibonacci(void);

int n;
int F[N+1];
int main(){
  

  scanf("%d",&n);

  makeFibonacci();

  printf("%d\n",F[n]);

  return 0;
}

void makeFibonacci(){
  int i;
  F[0] = F[1] = 1;
  for (i = 2;i<= n;i++)
  F[i] = F[i-2] + F[i-1];

}


  

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t
using Graph = vector<vector<int> >;
typedef pair<int, int> P;

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

const int MAX_N = 210000;
int fact[MAX_N], revfact[MAX_N];

int powmod(int a, int p){
  int res = 1, tmp = a;
  while(p != 0){
    if(p % 2) res = (res*tmp) % MOD;
    tmp = (tmp*tmp) % MOD;
    p /= 2;
  }
  return res;
}
 
void factmod(){
  fact[0] = revfact[0] = 1;
  for(int i = 1; i < MAX_N; i++){
    fact[i] = (fact[i-1] * i) % MOD;
    revfact[i] = (revfact[i-1] * powmod(i, MOD-2)) % MOD;
  }
}
 
int nCrmod(int n, int r){ // nCr % MOD
  return (((fact[n] * revfact[r]) % MOD) * revfact[n-r]) % MOD;
}

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

  int N, M, K; cin >> N >> M >> K;
  factmod();
  int ans = 0;
  for(int d = 1; d < N; d++){
    int num = d*(N-d)*M*M % MOD;
    ans += num; ans %= MOD;
  }
  for(int d = 1; d < M; d++){
    int num = d*(M-d)*N*N % MOD;
    ans += num; ans %= MOD;
  }
  cout << (ans*nCrmod(N*M-2, K-2)) % MOD << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define L 100001
long q;
vector < long> prim(L,0),tmp(L,1);;
void init()
{
    long i,j;
    for (i=2;i<=sqrt(L);i++)
        if (tmp[i])
            for (j=2*i;j<L;j+=i)
                tmp[j]=0;
    tmp[0]=tmp[1]=0;
    for (i=1;i<L;i+=2)
        if (tmp[i]&&tmp[(i+1)/2]) prim[i]=1;
    for (i=1;i<L;i++)
        prim[i]+=prim[i-1];
}
void solve()
{
    while(q--)
    {
        long l,r;
        scanf("%ld%ld",&l,&r);
        if (l==r)
        {
            if (tmp[l]&&tmp[(l+1)/2]) printf("1\n");
            else printf("0\n");
        }
        else printf("%ld\n",prim[r]-prim[l-1]);
    }
}
int main()
{
    init();
    while(~scanf("%ld",&q))
        solve();
}

Measured memory_bytes: 2176
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 = """000"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10010010"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """0"""
        output = """0"""
        self.assertIO(input, output)
def resolve():
    S=[int(i) for i in input()]
    X=sum([1 if i%2 != S[i] else 0 for i in range(len(S))])
    Y=sum([1 if S[i] != (i+1)%2 else 0 for i in range(len(S))])
    print(min(X,Y))
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 62808
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod



/************************************


 
*************************************/

vector<vector<ll>>v;
ll T=0;
ll cnt1=0,cnt0=0;
vector<ll>dep;
bool visited[MAX];
vector<ll>par;
vector<ll>tin,tout;
vector<ll>col;

int countDivisibles(int A, int B, int M) 
{ 
    
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
} 







signed main(){
    int t=1;
    // cin>>t;
    while(t--){
        int a,b,k;
        cin>>k>>a>>b;
        int v = countDivisibles(a,b,k);
        if(v)
            cout<<"OK\n";
        else cout<<"NG\n";
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
typedef long long LL;
using namespace std;
LL a[100001];
LL b[100000];
int n;
int main()
{
    LL sum = 0;
    cin >> n;
    for (int i = 0;i < n + 1;i++)
    {
        cin >> a[i];
    }
    for (int i = 0;i < n;i++)
    {
        cin >> b[i];
    }
    for (int i = 0;i < n;i++)
    {
        if (a[i] + a[i + 1] <= b[i])
        {
            sum += a[i] + a[i + 1];
            a[i + 1] = 0;
        }
        else if (a[i] >= b[i])
        {
            sum += b[i];
        }
        else if ((a[i] < b[i]))
        {
            sum += b[i];
            a[i + 1] = a[i] + a[i + 1] - b[i];
        }
    }
    cout << sum << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 1792
h, w, k = map(int, input().split())
c = []
for i in range(h):
  c.append(input())

ans = 0
for ht in range(1 << h):
  for wt in range(1 << w):
    b = 0
    for i in range(h):
      # ht の bit = 1 は赤の行
      if ht & 1 << i:
        continue
      for j in range(w):
        # wt の bit = 1 は赤の列
        if wt & 1 << j:
          continue
        if c[i][j] == '#':
          b += 1
    if (b == k):
      ans += 1
print(ans)

Measured memory_bytes: 68424
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int H, W;
  while (cin >> H >> W) {
    vector<string> A(H);
    for (int i = 0; i < H; i++) {
      cin >> A[i];
    }
    vector<int> perm(W);
    vector<vector<int>> cands;
    function<void(int, int, int)> dfs = [&](int l, int r, int mask) {
      if (l >= r) {
        cands.push_back(perm);
        return;
      }
      int a;
      for (int i = 0; i < W; i++) {
        if ((mask >> i) & 1) {
          a = i;
          break;
        }
      }
      for (int i = a + 1; i < W; i++) {
        if ((mask >> i) & 1) {
          perm[l] = a;
          perm[r] = i;
          dfs(l + 1, r - 1, mask ^ (1 << a) ^ (1 << i));
        }
      }
    };
    if (W % 2 == 0) {
      dfs(0, W - 1, (1 << W) - 1);
    } else {
      for (int i = 0; i < W; i++) {
        perm[W / 2] = i;
        dfs(0, W - 1, ((1 << W) - 1) ^ (1 << i));
      }
    }
    bool res = false;
    for (auto &perm : cands) {
      map<string, int> mp;
      for (int i = 0; i < H; i++) {
        string s = A[i], t(W, '-');
        for (int j = 0; j < perm.size(); j++) {
          t[j] = s[perm[j]];
        }
        ++mp[t];
      }
      bool ok = true;
      int oddPalindrome = 0;
      for (auto &e : mp) {
        string s = e.first;
        string t = string(s.rbegin(), s.rend());
        if (s != t) {
          ok &= mp[s] == mp[t];
        } else {
          if (mp[s] % 2 != 0) {
            ++oddPalindrome;
          }
        }
      }
      if (ok && oddPalindrome <= 1) {
        res = true;
        break;
      }
    }
    cout << (res ? "YES" : "NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
/*                  ___
               :                
               ;                
              :                 
              ;                 
             /                  
           o/                   
         ._/\___,                
             \                  
             /                   
             `      
	bug
*/
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

int n;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

	cin >> n;

	if(n<1200)
		cout << "ABC";
	else if(n>=1200 && n<2800)
		cout << "ARC";
	else
		cout << "AGC";

    //cerr << tick();

	return 0;
	
}


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

int N;
vector<vector<int>> G(101010);
int C[101010], era[101010], d[101010], deg[101010];
// bad:白なのに偶数回通る or 黒なのに奇数回通る
int bad[101010];

void dfs(int v,int p,int sum){
  if(era[v]) return;
  sum+=bad[v];
  d[v]=sum;
  for(int u:G[v]) if(u!=p) dfs(u,v,sum);
}

int solve(int v){
  rep(i,N) d[i]=0;
  dfs(v,-1,0);
  int ma=0;
  rep(i,N) if(d[i]>d[ma]) ma=i;
  return ma;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  cin>>N;
  rep(i,N-1){
    int x,y; cin>>x>>y; x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  string S; cin>>S;
  int W=0;
  rep(i,N){
    C[i]=(S[i]=='W');
    deg[i]=G[i].size();
    W+=C[i];
  }
  if(W<=1){
    cout<<W<<endl;
    return 0;
  }
  
  queue<int> que;
  rep(i,N){
    if(deg[i]==1&&C[i]==0) que.push(i);
  }
  while(que.size()){
    int v=que.front(); que.pop();
    if(era[v]) continue;
    era[v]=1;
    deg[v]=0;
    for(int u:G[v]){
      deg[u]--;
      if(C[u]==0&&deg[u]<=1) que.push(u);
    }
  }
  
  int ans=-2;
  rep(i,N) if(era[i]==0){
    ans+=2;
    bool flag=C[i]^(deg[i]%2==1);
    if(flag) ans++;
    bad[i]=flag;
  }
  int s,t;
  rep(i,N) if(era[i]==0){
    s=solve(i);
    break;
  }
  t=solve(s);
  int B=0;
  rep(i,N) if(era[i]==0){
    B+=(C[i]==0);
  }
  cout<<ans-2*d[t]<<endl;
  return 0;
}


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

using namespace std;

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;

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

    int vcnt[N + 1][M + 1];
    fill(vcnt[0], vcnt[N + 1], 0);
    // vcnt[i][j] = (1, 1)~(i, j)中の青マスの数
    // vcnt[i][0] = vcnt[0][j] = 0

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            // indexのズレに注意
            vcnt[i + 1][j + 1] = vcnt[i][j + 1] + vcnt[i + 1][j] - vcnt[i][j] + (S[i][j] == '1');
        }
    }

    int ercnt[N + 1][M + 1];
    fill(ercnt[0], ercnt[N + 1], 0);
    // ercnt[i][j] = (1, 1)~(i, j)中での青マスの横連結箇所数(row)

    int eccnt[N + 1][M + 1];
    fill(eccnt[0], ercnt[N + 1], 0);
    // eccnt[i][j] = (1, 1)~(i, j)中での青マスの縦連結箇所数(column)

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            ercnt[i + 1][j + 1] = ercnt[i][j + 1] + ercnt[i + 1][j] - ercnt[i][j];
            ercnt[i + 1][j + 1] += (j > 0 && S[i][j] == '1' && S[i][j - 1] == '1');

            eccnt[i + 1][j + 1] = eccnt[i][j + 1] + eccnt[i + 1][j] - eccnt[i][j];
            eccnt[i + 1][j + 1] += (i > 0 && S[i][j] == '1' && S[i - 1][j] == '1');
        }
    }

    for (int q = 0; q < Q; ++q) {
        int x[2], y[2];
        for (int i = 0; i < 2; ++i) {
            cin >> x[i] >> y[i];
        }

        int v = vcnt[x[1]][y[1]] - vcnt[x[0] - 1][y[1]] - vcnt[x[1]][y[0] - 1] + vcnt[x[0] - 1][y[0] - 1];

        int e = ercnt[x[1]][y[1]] - ercnt[x[1]][y[0]] - ercnt[x[0] - 1][y[1]] + ercnt[x[0] - 1][y[0]];

        e += eccnt[x[1]][y[1]] - eccnt[x[0]][y[1]] - eccnt[x[1]][y[0] - 1] + eccnt[x[0]][y[0] - 1];

        cout << v - e << endl;
    }

    return 0;
}


Measured memory_bytes: 52864
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
ll INF = (1 << 30);
ll MOD = 1e9 + 7;

int main() {
    int n, m, x; cin >> n >> m >> x;
    vector<int> a(m);
    rep(i,m) cin >> a[i];

    auto itr = lower_bound(a.begin(),a.end(),x);
    int dis = abs(distance(itr, a.end()));

    cout << min(dis,(m - dis)) << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int a, b;
  cin >> a >> b;
  if(b % a) cout << b - a << endl;
  else cout << a + b << endl;
}

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

struct Node {
  int key;
  Node *p, *l, *r;
};

Node *null, *root;

void Print_P(Node *T) {
  if (T == null)
    return;
  printf(" %d", T->key);
  Print_P(T->l);
  Print_P(T->r);
}

void Print_M(Node *T) {
  if (T == null)
    return;
  Print_M(T->l);
  printf(" %d", T->key);
  Print_M(T->r);
}

void Insert(int k) {
  Node *y = null, *x = root, *z = (Node *)malloc(sizeof(Node));
  z->key = k, z->l = null, z->r = null;
  while (x != null) {
    y = x;
    if (z->key < x->key)
      x = x->l;
    else
      x = x->r;
  }
  z->p = y;

  if (y == null)
    root = z;
  else if (z->key < y->key)
    y->l = z;
  else
    y->r = z;
}

int main() {
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    char o[7];
    scanf("%s", o);
    if (strcmp(o, "insert") == 0) {
      int k;
      scanf("%d", &k);
      Insert(k);
    } else {
      Print_M(root);
      printf("\n");
      Print_P(root);
      printf("\n");
    }
  }
}


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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	
	int count=0;
	vector<pair<int,int>> ans;
	if(N%2==0){
		for(int i=1;i<=N;i++){
			for(int j=i+1;j<=N;j++){
				if(i+j==N+1)	continue;
				count++;
				ans.push_back(make_pair(i,j));
			}
		}
	}
	else{
		for(int i=1;i<=N;i++){
			for(int j=i+1;j<=N;j++){
				if(i+j==N)	continue;
				count++;
				ans.push_back(make_pair(i,j));
			}
		}
	}
	
	cout << count << endl;
	for(int i=0;i<count;i++){
		cout << ans.at(i).first << " " << ans.at(i).second << endl;
	}
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  for (int i=0; i<N; i++) cin >> x[i] >> y[i] >> a[i];
  int x1=0, x2=INT_MAX, y1=0, y2=INT_MAX;
  for (int i=0; i<N; i++) {
    if (a[i]==1) x1 = max(x1, x[i]);
    else if (a[i]==2) x2 = min(x2, x[i]);
    else if (a[i]==3) y1 = max(y1, y[i]);
    else y2 = min(y2, y[i]);
  }
  int ans;
  if (x2<=x1||y2<=y1) ans = 0;
  else ans = (min(x2, W)-x1)*(min(y2, H)-y1);
  cout << ans << endl;
}

Measured memory_bytes: 256
a, b, c = sorted([ int(v) for v in input().split() ])

if a % 2 == b % 2 and c % 2 == b % 2:
  print((c-a)//2+(c-b)//2)
else:
  if a % 2 == b % 2:
    a += 1
    b += 1
  elif b % 2 == c % 2:
    b += 1
    c += 1
  else:
    c += 1
    a += 1
  print((c-a)//2+(c-b)//2+1)

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();

    int ans = 0;
    if (A >= K) {
      ans = K;
      K = 0;
    } else {
      ans = A;
      K = K - A;
    }
    if (B >= K) {
      K = 0;
    } else {
      K = K - B;
    }
    if (C >= K) {
      ans -= K;
    }

    System.out.println(ans);

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 25332
#include <stdio.h>
long int get(int cc[],int ss[],int ff[],int mas,int n)
{
    long int time=0;
    int a=0;
    while(mas!=n-1)
    {
        if(time<ss[mas])time=ss[mas]+cc[mas];
        else
        {
            a=time/ff[mas];
            if(time%ff[mas]!=0)a++;
            time=a*ff[mas];
            time+=cc[mas];
        }
        mas++;
    }
    return time;
}



int main(void)
{
    int n;
    scanf("%d",&n);
    int c[n-1];
    int s[n-1];
    int f[n-1];
    long int ans=0;
    for(int p=0;p<n-1;p++)scanf("%d%d%d",&c[p],&s[p],&f[p]);
    for(int q=0;q<n;q++)
    {
        ans=get(c,s,f,q,n);
        printf("%ld\n",ans);
    }
}

Measured memory_bytes: 128
//Reconciled?

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,m;cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<nnn;
        return 0;
    }
    int ans = 1;
    rep(i,1,n+1)ans=(ans*i)%1000000007;
    rep(i,1,m+1)ans=(ans*i)%1000000007;
    if((n+m)%2==0)ans=(ans*2)%1000000007;
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long n, long long mod = numeric_limits<long long>::max()) {
  assert(n >= 0);
  if (n == 0) return 1;
  return power(x * x % mod, n / 2, mod) * (n % 2 ? x : 1) % mod;
}
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int x; cin >> x;
  vector<int> c;
  for (int b = 1; b < 32; b++) {
    for (int p = 2; p < 10; p++) {
      long long n = power(b, p);
      if (n > 1000) break;
      else c.push_back(n);
    }
  }
  sort(c.begin(), c.end());
  cout << *(upper_bound(c.begin(), c.end(), x) - 1) << '\n';
  return 0;
}

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

using namespace std;

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> as(n), bs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i] >> bs[i];
    }
    long ans = 0;
    for (int x = 0; x < n; x++)
    {
        bool f = 1;
        for (int i = 30; i >= 0; i--)
        {
            if ((k >> i & 1) < (as[x] >> i & 1))
                f = 0;
        }
        if (f)
            ans += bs[x];
    }
    for (int i = 30; i >= 0; i--)
    {
        if (!(k >> i & 1))
            continue;
        long res = 0;
        for (int x = 0; x < n; x++)
        {
            if (as[x] >> i & 1)
                continue;
            bool f = 1;
            for (int j = 30; j > i; j--)
            {
                if ((k >> j & 1) < (as[x] >> j & 1))
                    f = 0;
            }
            if (f)
                res += bs[x];
            //cout << i << ' ' << as[x] << ' ' << f << endl;
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define mll map<ll, ll>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, t;
  cin >> n >> t;
  vi v(n);
  rep(i, n) cin >> v[i];
  ll ans = t;
  rep(i, n - 1) {
    if (v[i + 1] - v[i] > t)
      ans += t;
    else
      ans += v[i + 1] - v[i];
  }
  out(ans);
}
int main(void) { solve(); }


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    string s; cin >> s;
    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));

    if(0 < a && a <= 12){
        if(0 < b && b <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(0 < b && b <= 12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3552
N = int(input())
A =[0]*N
for i in range(N):
    A[i] = int(input())
A.sort(reverse=True)
X=0
Y=0
if N % 2 == 0:
    for i in range(N//2-1):
        X = X + 2*A[i] -2*A[-i-1]
    X = X + A[N//2-1] -A[N//2]
    print(X)    

if N % 2 == 1:
        for i in range(N//2):
            X = X + 2 * A[i]
            Y = Y - 2 * A[-i-1]
        for i in range (N//2-1):
            X = X - 2 * A[-i-1]
            Y = Y + 2 * A[i]
        X = X - A[N//2] - A[N//2+1]
        Y = Y + A[N//2-1] + A[N//2]
        print(max(X,Y))

Measured memory_bytes: 7472
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <iostream>
using namespace std;

int deg[100010];
vector<int> G[100010];
int ans[110][110], used[100010];
// set<int> adj[110];

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

int main() {
  int N; cin >> N;
  for(int i=0; i<2*N*N - 2*N; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
    deg[a]++; deg[b]++;

    if(a > b) swap(a, b);
    // adj[a].insert(b);
    // adj[b].insert(a);
  }

  
  for(int i=0; i<N*N; i++) {
    // search deg[i] == 2
    if(deg[i] == 2) {
      // start
      for(int r=0; r<N; r++) {
        for(int c=0; c<N; c++) {
          if(r == 0 and c == 0) {
            ans[r][c] = i;
            used[i] = true;
          }
          else {
            map<int, int> cnt;
            int neighbor = 0;
            for(int k=0; k<2; k++) {
              int x = r + dx[k], y = c + dy[k];
              if(x < 0 or y < 0 or x >= N or y >= N) continue;
              int id = ans[x][y];
              neighbor++;
              for(auto to : G[id]) {
                cnt[to]++;
              }
            }

            for(auto x : cnt) {
              if(x.second != neighbor) continue;
              int target = -1;
              if     (r == 0 and c == N-1) target = 2;
              else if(r == 0 and c == 0  ) target = 2;
              else if(r == N-1 and c == 0  ) target = 2;
              else if(r == N-1 and c == N-1) target = 2;
              else if(r == 0 or r == N-1) target = 3;
              else if(c == 0 or c == N-1) target = 3;
              else target = 4;

              // fprintf(stderr, "(x, y) = (%d, %d), target = %d, deg = %d\n", r, c, target, deg[x.first]);
              if(deg[x.first] != target) continue;
              if(used[x.first]) continue;
              ans[r][c] = x.first;
              used[x.first] = true;
              break;
            }
          }
        }
      }
      break;
    }
  }

  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      cout << ans[i][j] + 1 << " \n"[j+1==N];
    }
  }
  return 0;
}



Measured memory_bytes: 5904
"""
Discount Fare
"""
#入力処理
def simple_input():
    temp_input = input().rstrip().split(' ')
    if len(temp_input) > 1:
        return temp_input
    return temp_input[0]

#メイン処理
if __name__ == '__main__':
    #入力
    x,y = simple_input()
    x = int(x)
    y = int(y)

    val = int(x + y / 2)

    #出力
    print("{0}".format(val))


Measured memory_bytes: 3060
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    ll sum=0;
    vector<vector<ll>> a(500,vector<ll>(500));
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            cin>>a[i][t];
            sum+=a[i][t];
        }
    }
    bool j=true;
    for(int k=0;k<n && j;k++){
        for(int i=0;i<n && j;i++){
            for(int t=0;t<n && j;t++){
                if(a[i][t]>a[i][k]+a[k][t]){j=false;}
            }
        }
    }
    if(!j){cout<<-1<<endl; return 0;}
    
    for(int k=0;k<n && j;k++){
        for(int i=0;i<n && j;i++){
            bool judge=false;
            for(int t=0;t<n && j;t++){
                if(i!=k && k!=t && i!=t && a[i][k]==a[i][t]+a[t][k]){judge=true;}
            }
            if(judge){sum-=a[i][k];}
        }
    }
    
    
    
    cout<<sum/2<<endl;
    
    
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
     
int main() {
     
int r, D, x0;
  cin >> r >> D >> x0;
  vector<int> x(11);
  x.at(0) = x0;
  for(int i = 1; i < 11; i++) {
    x.at(i) = r * x.at(i - 1) - D;
  }
  for(int i = 1; i < 11; i++) {
    cout << x.at(i) << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(bool a) {
  return a ? "T" : "F";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;

const int N = 1e5 + 10;

ll n, c;
ll x[N];
ll v[N];
ll d[N];

ll getsum(int l, int r) {
  if (l > r) return 0;
  return d[r] - (l > 0 ? d[l - 1] : 0);
}

void run() {
  cin >> n;
  cin >> c;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> v[i];
  }

  partial_sum(v, v + n + 1, d);

  ll ans = 0;
  vector <ll> ans0(1, 0);
  for (int i = 1; i <= n; ++i) {
    ll tmp = getsum(1, i) - x[i];
    ans0.push_back(max(ans0.back(), tmp));
  }

  vector <ll> ans1(1, 0);
  for (int i = 1; i <= n; ++i) {
    ll tmp = getsum(i, n) - (c - x[i]);
    ans1.push_back(tmp);
  }
  ans1.push_back(0);
  for (int i = n; i >= 1; --i) {
    maxi(ans1[i], ans1[i + 1]);
  }

  vector <ll> mx0(1, 0);
  for (int i = 1; i <= n; ++i) {
    ll tmp = getsum(1, i) - x[i] * 2;
    mx0.push_back(tmp);
  }

  for (int i = 0; i <= n; ++i) {
    maxi(ans, mx0[i] + ans1[i + 1]);
  }
  
  vector <ll> mx1(1, 0);
  for (int i = 1; i <= n; ++i) {
    ll tmp = getsum(i, n) - (c - x[i]) * 2;
    mx1.push_back(tmp);
  }
  mx1.push_back(0);

  for (int i = 1; i <= n + 1; ++i) {
    maxi(ans, mx1[i] + ans0[i - 1]);
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 6516
N, M = map(int, input().split())
P = [0] * N  # 正解済みは1
wa = [0] * N  # WA の回数を記録
ac, penalty = 0, 0

for _ in range(M):
    # 読み込み
    p, S = input().split()
    p = int(p)
    if P[p-1] == 1:
        # すでに正解済みの場合は何もしない
        continue
    elif S == "WA":
        # 未正解で WA
        wa[p-1] += 1
    else:
        # 未正解で AC
        ac += 1
        penalty += wa[p-1]
        P[p-1] = 1
print(ac, penalty)


Measured memory_bytes: 4596
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int i = 0;
  int counter1 = 0, counter2 = 0;
  int tmp1 = 0, tmp2 = 0;
  int cap_num = 0, train_num = 0, question_num = 0;
  int map[501][501] = {{0}};
  cin >> cap_num >> train_num >> question_num;
  for(i = 0; i < train_num; ++i)
  {
    cin >> tmp1 >> tmp2;
    map[tmp1][tmp2]++;
  }
  for(i = 0; i <= cap_num; ++i)
  {
    for(counter1 = 1; counter1 <= cap_num; ++counter1)
    {
      map[counter1][i] += map[counter1 - 1][i];
    }
  }
  for(i = 0; i < question_num; ++i)
  {
    cap_num = 0;
    cin >> tmp1 >> tmp2;
    for(counter1 = tmp1; counter1 <= tmp2; ++counter1)
    {
      cap_num += map[tmp2][counter1] - map[tmp1-1][counter1];
    }
    cout << cap_num << endl;
  }
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    ll a,p;
    cin>>a>>p;
    ll total = 3*a + p;
    ll ans = total/2;

    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	int n = in.nextInt();
	int[] R = new int[n];
	for(int i = 0; i < n; i++) {
	    R[i] = in.nextInt();
	}
	int[] min = new int[n];
	for(int i = 0; i < n; i++) {
	    min[i] = i == 0 ? R[i] : Math.min(min[i - 1], R[i]);
	}
	int max = Integer.MIN_VALUE;
	for(int i = 1; i < n; i++) {
	    max = Math.max(max, R[i] - min[i - 1]);
	}
	System.out.println(max);
    }
}



Measured memory_bytes: 101828
n, k = map(int, input().split())
check = [False] * n
d = []
a = []
for i in range(k):
  d = int(input())
  a.append(list(map(int, input().split())))
for i in range(k):
  for j in range(len(a[i])):
    check[a[i][j]-1] = True
print(check.count(False))

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S;
  string T;
  cin >> S >> T;

  int N = SZ(S), M = SZ(T);
  string ans;
  REP(i,SZ(S)){
	int j = 0;
	for(;j<M&&i+j<N;++j){
	  if(S[i+j] != T[j] && S[i+j] != '?')
		break;
	}
	if(j < M) continue;

	string tmp;
	REP(k,i)
	  tmp += (S[k] == '?'? string(1,'a'): string(1,S[k]));
	tmp += T;
	FOR(k,i+M,N) tmp += (S[k] == '?'? string(1,'a'): string(1,S[k]));

	if(ans == "") ans = tmp;
	else mini(ans, tmp);
  }
  cout << (ans==""? "UNRESTORABLE": ans) << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  string input;
  int shift;
  cin >> shift;
  cin >> input;
  for(int i=0;i<input.length();i++){
    int idk = input.at(i);
    cout << (char)(((input.at(i)-'A'+shift)%26)+'A');
  }
}

Measured memory_bytes: 256