akhauriyash/Code-Regression huggingface dataset:
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    #A, B = [int(x) for x in raw_input().split()]
    n = int(raw_input())
    
    arr = [int(x) for x in raw_input().split()]
    
    ans = [-1] * n
    
    total_xor = 0
    
    for num in arr:
        total_xor ^= num
    
    for i in range(n):
        ans[i] = total_xor ^ arr[i]
        ans[i] = str(ans[i])
    
    print(' '.join(ans))
    

main()

Measured memory_bytes: 101224
/*
AizuOnline A0130
Train
*/
#include <stdio.h>
#include <string.h>

char cars[54];
char records[1025];

void analys(char * rec,int pos)
{
  if(rec[0] == '\0')
    return;
  cars[pos] = rec[0];
  if(rec[1]=='-' && rec[2]=='>')
      analys(rec+3,pos+1);
  else if(rec[1]=='<' && rec[2]=='-')
      analys(rec+3,pos-1);
}

void display_car(char * cars)
{
  int i;
  
  i= 0;
  while(i++,cars[i]=='\0')
    {}
  printf("%s\n",cars+i);
    
}
main()
{
  int cnt;
  int i;

  scanf("%d",&cnt);
  while(cnt--)
    {

      for(i=0;i<54;i++)
        cars[i]='\0';

      scanf(" %s",records);

      analys(records,26);

      display_car(cars);

    }


return(0);
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int N;
ll K, A[101010];
ll dp[50][2];


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

  for(long long i=0; i<N; i++)
    cin >> A[i];

  for(int i=0; i<50; i++)
      dp[i][0] = dp[i][1] = -1;
    


  long long Amax=0;
  for(int i=0; i<N; i++)
    chmax(Amax, A[i]);

  dp[0][0]=0;
  for(int digit=0; digit<44; digit++)
    {
      long long mask = 1LL << 43-digit;
      int num = 0;

      for(int i=0; i<N; i++)
	{
	  if(mask & A[i])//下からdigit目の桁が1ならnum++
	    num++;
	}

      //XORだから，1のほうが多いときはXのdigitは0
      long long diff0 = mask * num;   //diff0の0はnumが1である．Xのdigitは0
      long long diff1 = mask * (N-num);   //

      //dp[digit][smaller]


	  //smaller->smaller : smallerが存在する場合に限る
	  if(dp[digit][1]>=0)
	    {
	      dp[digit+1][1] = max(dp[digit][1] + diff1, dp[digit][1] + diff0);
	    }

	  if(dp[digit][0]>=0)
	    {
	      if(K&mask)  //1が立ってる
		{
		  //limit->smaller
		  chmax(dp[digit+1][1], dp[digit][0]+diff0);
		  
		  //limit->limit
		  chmax(dp[digit+1][0], dp[digit][0]+diff1);
		}
	      else
		{
		  //limit->limit
		  chmax(dp[digit+1][0], dp[digit][0]+diff0);
		}
	    }
    }

  cout << max(dp[44][0], dp[44][1]) << endl;
  


  return 0;
}


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

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

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1;
	while (b) {
		while (!(b & 1))
			b >>= 1, a = (a * a) % MOD;
		--b;
		ans = (ans * a) % MOD;
	}
	return ans;
}
*/

ll q, h, s, d, n;

int main() {
	cin >> q >> h >> s >> d;
	h = min(h, q * 2);
	s = min(s, h * 2);
	d = min(d, s * 2);
	cin >> n;
	int k = n / 2;
	int l = n % 2;
	cout << k * d + l * s << "\n";
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

ll mod;
constexpr ll modsize = 3010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

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

ll modpow(ll a, ll b, ll m) {
	ll ans = 1;
	a %= m;
	while (b) {
		if (b & 1) ans = ans * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

ll dp[3010][3010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n;
	cin >> n >> mod;
	modcalc();
	dp[0][0] = 1;
	for (ll i = 1; i <= n + 1; i++) {
		for (ll j = 1; j <= i; j++) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * j;
			dp[i][j] %= mod;
		}
	}
	ll ans = modpow(2, modpow(2, n, mod - 1), mod);
	for (ll i = 1; i <= n; i++) {
		ll sign = 1;
		if (i & 1) sign = -1;
		ll sum = 0;
		for (ll j = 1; j <= i + 1; j++) {
			sum += dp[i + 1][j] * modpow(2, (n - i)*j, mod) % mod;
			sum %= mod;
		}
		sum *= modinv(modpow(2, (n - i), mod), mod); sum %= mod;
		sum *= modpow(2, modpow(2, (n - i), mod - 1), mod); sum %= mod;
		sum *= modcomb(n, i); sum %= mod;
		sum *= sign; if (sum < 0) sum += mod;
		ans += sum; if (ans >= mod) ans -= mod;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 69248
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().ToCharArray();

            var result = Array.ConvertAll(input, x =>
            {
                if (char.IsUpper(x)) return char.ToLower(x);
                else if (char.IsLower(x)) return char.ToUpper(x);
                else return x;
            });

            Console.WriteLine(new string(result));
        }
    }
}

Measured memory_bytes: 9708
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <numeric>

using namespace std;

using ll = long long;

ll mod = 1000000007;

int n;

map<pair<int, string>, ll> memo;

ll dfs(int i, string s) {
    if (i == n) {
        return 1;
    }

    auto cur = make_pair(i, s);

    if (memo.count(cur)) {
        return memo[cur];
    }

    ll ret = 0;

    string t = s.substr(1);
    ret = (ret + dfs(i + 1, t + 'A')) % mod;
    ret = (ret + dfs(i + 1, t + 'T')) % mod;

    if (t != "AC") {
        ret = (ret + dfs(i + 1, t + 'G')) % mod;
    }

    if (t != "AG" && t != "GA" && !(s[0] == 'A' && s[1] == 'G') && !(s[0] == 'A' && s[2] == 'G')) {
        ret = (ret + dfs(i + 1, t + 'C')) % mod;
    }

    return memo[cur] = ret;
}

int main() {
    cin >> n;

    cout << dfs(0, "TTT") << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string K;
  ll P = 1000000007;
  ll D, ans=0;
  std::cin >> K;
  std::cin >> D;
  if(D==1&&K.size()<16){
    std::cout << stol(K) % P << '\n';
    return 0;
  }
  if(K.size()==10&&D==2){
    std::cout << (stol(K)/2 - 1)%P << '\n';
    return 0;
  }
  vvl dp = vv(K.size(), D, 0, ll);
  for(int i=0;i<K.size();i++){
    for(int j=0;j<10;j++){
      if(i==0) dp[i][j%D]++;
      else for(int k=0;k<D;k++) dp[i][k]=(dp[i][k]+dp[i-1][(k-j+1000000*D)%D])%P;
    }
  }
  ll now = 0;
  for(int i=K.size()-1;i>=0;i--){
    if(i!=0){
      for(int j=0;j<(K[K.size()-1-i]-'0');j++) ans =  (ans + dp[i-1][(0-j-now+1000000*D)%D])%P;
      now += K[K.size()-1-i] - '0';
    }else for(int j=0;j<=K[K.size()-1]-'0';j++) if((now+j)%D==0) ans = (ans + 1)%P;
  }
  std::cout << (ans!=0?ans-1:D-1) << '\n';
  return 0;
}


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

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

    multiset<int> s;
    for(int i=0;i<n;i++){
        auto it=s.lower_bound(a[i]);
        if(it==s.begin()){
            s.insert(a[i]);
        }
        else{
            s.erase(s.find(*prev(it)));
            s.insert(a[i]);
        }
    }
    cout<<s.size()<<endl;
    return 0;
}

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

using namespace std;

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

  int h, w, sz, ip, jp;
  cin >> h >> w;
  vector<string> grid(h);
  vector<vector<bool>> seen(h, vector<bool>(w, false));
  vector<int> di{1, 0, -1, 0};
  vector<int> dj{0, 1, 0, -1};
  pair<int, int> v;
  for (auto &s : grid) cin >> s;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (grid[i][j] == '.' || seen[i][j]) continue;
      sz = 0;
      grid[i][j] = true;
      vector<pair<int, int>> q(1, {i, j});
      while (!q.empty()) {
        ++sz;
        v = q.back();
        q.pop_back();
        for (int k = 0; k < di.size(); ++k) {
          ip = v.first + di[k];
          jp = v.second + dj[k];
          if (ip >= 0 && ip < h && jp >= 0 && jp < w) {
            if (grid[ip][jp] == '#' && !seen[ip][jp]) {
              seen[ip][jp] = true;
              q.push_back({ip, jp});
            }
          }
        }
      }
      if (sz == 1) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
import math
import bisect
from collections import deque
def input():
    return sys.stdin.readline()[:-1]

s = input()
t = input()
ans = 0

for i in range(len(s)):
    if s[i]!=t[i]:
        ans+=1

print(ans)


Measured memory_bytes: 9716
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;cin>>a>>b>>c;
	for(int i=a;;i--)
	{
		if(a%i==0&&b%i==0)c--;
		if(c==0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
'use strict';
(function(stdin) {
  var lines  = stdin.toString().split('\n');
  var params = lines[0].split(' ').map(Number);
  var result = (function(a,b) {

    return [
      a * b
      , (a + b) * 2
    ].join(' ');

  }(params[0],params[1]
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7384
# n,m = map(int,input().split())
n = int(input())
# n = input()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
left = 0
for i in range(n):
    a1,b1 = a[i],b[i]
    if a1 <= b1 + left:
        cnt += a1
        left = min(b1 - a1 + left,b1)
    else:
        cnt += b1 + left
        left = 0
if a[n] <= left:
    cnt += a[n]
else:
    cnt += left
print(cnt)


Measured memory_bytes: 19156
#include<bits/stdc++.h>
using namespace std;
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long

void solve() {
	int n;
	cin >> n;
	int dig = n%10;
	if(dig == 3) cout << "bon";
	else if(dig == 0 || dig == 1 || dig == 6 || dig == 8) cout << "pon";
	else cout << "hon";
}

int main(){
	FAST(); 
	int t; 
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n; cin >> n;
  vector<int> v(n);
  for(auto &x: v) cin >> x;
  sort(v.begin(), v.end());
  cout << (v[n / 2] - v[n / 2 - 1]) << "\n";
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 2e5;

string s;
int n;
int a[N];

void done() {
	for (int i = 0; i < n; ++i) {
		cout << (a[i]?'W':'S');
	}
}

bool correct(int i) {
	if (!a[i]) {
		if (s[i] == 'o' && a[(i-1+n)%n] == a[(i+1)%n]) {
			return true;
		}
		if (s[i] == 'x' && a[(i-1+n)%n] != a[(i+1)%n]) {
			return true;
		}
	} else {
		if (s[i] == 'x' && a[(i-1+n)%n] == a[(i+1)%n]) {
			return true;
		}
		if (s[i] == 'o' && a[(i-1+n)%n] != a[(i+1)%n]) {
			return true;
		}
	}
	return false;
}

void solve() {
	cin >> n;
	cin >> s;
	for (a[0] = 0; a[0] < 2; ++a[0]) {
		for (a[1] = 0; a[1] < 2; ++a[1]) {
			for (int i = 2; i < n; ++i) {
				if (!a[i-1]) {
					if (s[i-1] == 'o') a[i] = a[i-2];
					else a[i] = !a[i-2];
				} else {
					if (s[i-1] == 'x') a[i] = a[i-2];
					else a[i] = !a[i-2];
				}
			}
			bool good = true;
			for (int i = 0; i < n; ++i) {
				if (!correct(i)) {
					good = false;
					break;
				}
			}
			if (good) {
				done();
				return;
			}
				
		}
	}
	cout << -1;
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

vector<int> v(303030);
int n,k,m,a,b,c,d;
string s,t;

int main() {
  cin >> a >> b >> c >> d;
  cin >> n;
  int mi=min({a*4,b*2,c});
  if(mi*2<d)
  cout << (ll)mi*n << endl;
  else if(n&1)
  cout << (ll)n/2*d+mi << endl;
  else 
  cout << (ll)n/2*d << endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<ll,ll> P;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};



int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    
    rep(i,n) cin >> p[i];
    int ans = 0;
    
    int max = 1001001001;
    rep(i,n){
        if (p[i] <= max){
            ans++;
            max = p[i];
        }
    }
    cout << ans;
    
    
}


Measured memory_bytes: 1024
use text_io::*;
use std::process::exit;
use im_rc::HashMap;
use std::cmp::min;

fn main(){
    let mut a:String = read!();
    let mut v:Vec<char> = a.chars().collect();
    let mut n:usize = 0;
    for i in 0..v.len()/2 {
        if v[i]!=v[v.len()-i-1] {
            n += 1;
        }
    }
    println!("{}",n);
}

Measured memory_bytes: 2124
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll k, s;
	cin >> k >> s;

	ll ans = 0;
	REP(i, k+1) {
		REP(j, k+1) {
			ll m = s - (i + j);
			if (m >= 0&&m<=k) {
				ans++;
			}
		}
	}

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

Measured memory_bytes: 256
mod = 10 ** 6 + 3


class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod

    def powe(self, K):
        return self.power[K]

    def rev_powe(self, K):
        return self.rev[K]


combi = Combi(mod-1, mod)


def rev(X):
    return pow(X, mod-2, mod)


def count_div(L, R, D):
    return not bool(R//D - (L-1)//D)


def solve():
    x, d, n = map(int, input().split())
    if d % (mod) == 0:
        print(pow(x,n,mod))
        return
    elif d % (mod) != 0:
        y = rev(d)*x
        if count_div(y, y+n-1, mod):
            y = y % mod
            ans = pow(d, n, mod)*combi.powe(y+n-1) * combi.rev_powe(y)*y
            print(ans % mod)
            return
        else:
            ans = 0
            print(ans % mod)
            return


def main():
    Q = int(input())
    for i in range(Q):
        solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 88116
#include <bits/stdc++.h>
using namespace std;
const int N=100010,Mod=998244353;
const double pi=acos(-1.0);
typedef long long int ll;
typedef pair<int,int> pii;
map<string,int> m;
ll ans;
int main()
{
  int n;
  string s;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  for(auto i:m)
  {
    int s=i.second;
    ans+=(1ll*s*(s-1)/2);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include<string.h>
int main(void){
char a[101],b[101],c[201];
scanf("%s%s",a,b);
strcat(c,a);
strcat(c,a);
if(strstr(c,b)==NULL)
puts("No");
else
puts("Yes");

    return 0;
}

Measured memory_bytes: 2752
H, N = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

dp = [float("inf")] * (H+1)
dp[H] = 0

for i in range(H, 0, -1):
  for j in range(N):
    a, b = M[j]
    dp[i-a if i-a >= 0 else 0] = min(dp[i-a if i-a >= 0 else 0], dp[i] + b)
print(dp[0])

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int n,m;
    cin>>n;
    vector<int> t(n);
    rep(i,n){
        cin>>t[i];
    }
    cin >> m;
    int p,x,ans;
    rep(i,m){
        cin>>p>>x;
        ans = 0;
        rep(j,n){
            if(j == p-1) ans += x;
            else ans += t[j];
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 3628
N = int(input())
S = []
for i in range(N):
    S.append(input())
M = int(input())
T = []
for i in range(M):
    T.append(input())

str2count1 = {}
for s in S:
    if s not in str2count1:
        str2count1[s] = 0
    str2count1[s] += 1

str2count2 = {}
for t in T:
    if t not in str2count2:
        str2count2[t] = 0
    str2count2[t] += 1

max_diff = 0
for key, value in str2count1.items():
    diff = value - str2count2[key] if key in str2count2 else value
    if max_diff < diff:
        max_diff = diff
print(max_diff)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int par[1000010];

void init(int n) {
    for ( int i = 1; i <= n; i++ ) {
        par[i] = i;
    }
}

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

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

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

int main() {
   int n, m;
   cin >> n >> m;
   init(n);
   vector<int> p(n+1);
   for( int i = 1; i <= n; i++ ) cin >> p[i];
   for( int i = 0; i < m; i++ ) {
       int a, b;
       cin >> a >> b;
       unite(a, b);
   }
   int cnt = 0;
   for( int i = 1; i <= n; i++ ) {
       if( same(i, p[i]) ) cnt++;
   }
   dump(cnt);
   return 0;  
}

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

int main() {
  int N;
  cin >> N;
  int H[N];
  
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 1; i < N; i++) {
    if (H[i - 1] > H[i]) {
      cout << "No" << endl;
      return 0;
    } else {
      if (H[i] != H[i - 1]) {
        H[i] = H[i] - 1;
      }
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 640
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans)
if __name__=='__main__':
    main()


Measured memory_bytes: 5220
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}


func nextLine() string {
    sc.Scan()
    return sc.Text()
}


func main(){
	var res string
	var N, M int
	fmt.Scan(&N)
	fmt.Scan(&M)

	if N==M {
		res="Yes"
	}else {
		res="No"
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k,n;
cin>>k>>n;
int A[n+1],i,sm=0;
for(i=0;i<n;i++)
{
	cin>>A[i];
}
A[n]=k+A[0];
int max=0;
for(i=0;i<n;i++)
{
	if(max<(A[i+1]-A[i]))
	{
		max=A[i+1]-A[i];
	}
	sm=sm+A[i+1]-A[i];
//	cout<<"sm="<<sm<<endl;
}
//cout<<"max= "<<max<<endl;
sm=sm-max;
cout<<sm<<endl;
return 0;
}

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

using namespace std;

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

    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main()
{
 long long int a,b,c;
  
  scanf("%lld",&a);
  
  b=a/500;
  
  c=a % 500;
  
  b=(b*1000)+((c/5)*5);
  
  printf("%lld",b);
  
  return 0;
  
}

Measured memory_bytes: 128
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
int toInt(string x){
	stringstream ss ; 
	ss << x ; 
	int c ; 
	ss >> c ; 
	return c ; 
}
int main(){
	string s ; 
	cin >> s ; 
	string first = s.substr(0,2) ; 
	string second = s.substr(2) ; 
	stringstream ss ; 
	int x = toInt(first) ; 
	int y = toInt(second) ; 
	debug() << imie(first) imie(second) ; 
	debug() << imie(x) imie(y) ; 
	if ( x == 0 ) {
		if ( y <= 12 && y != 0 ){
			cout << "YYMM" << endl;
		}
		else cout << "NA" << endl;
	}
	else if ( y == 0 ){
		if ( x <= 12 && x != 0 ){
			cout << "MMYY" << endl;
		}
		else cout << "NA" << endl;
	}
	else if ( x > 12 && y > 12 ){
		cout << "NA" << endl;
	}
	else if ( x <= 12 && y <= 12 ){
		cout << "AMBIGUOUS" << endl;
	}
	else if ( x <= 12 ){
		cout << "MMYY" << endl;
	}
	else {
		cout << "YYMM" << endl;
	}
    return 0 ;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0, mx = 0;
    rep(i,n){
        ll a;
        cin >> a;
        if(a >= mx) mx = a;
        else{
            ans += mx - a;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
typedef long long int lld;

int main(void) {
  lld n, b, s = 0;
  scanf("%lld", &n);
  b = n % 15;
  s = (n / 15) * (n / 15) * 60;
  for (int i = n - b; i <= n; i++) {
    if (i % 3 * i % 5 != 0) {
      s += i;
    }
  }
  printf("%lld\n", s);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

void YN(bool x){
  if(x) cout<<"Yes";
  else cout<<"No";
}

int main() {
  int A,B,C,D; cin>>A>>B>>C>>D;
  cout<<A*(A-1)/2+B*(B-1)/2;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

int main(int argc, char const *argv[]) {
  int n,ans=0;
  string s;
  cin >> n >> s;
  rep(i,1000){
    int c[3]={i/100,(i/10)%10,i%10};
    int cnt=0;
    for(int j=0; j<n; j++){
      if(s[j]==(c[cnt]+'0')) cnt++;
      if(cnt==3) break;
    }
    if(cnt==3) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int prime(int x){
  	if(x == 2) return 1;
  	if(x % 2 == 0) return 0;
  	for(int i = 3; i * i <= x; i += 2){
    	if(x % i == 0) return 0;
    }
  	return 1;
}

int main(){
	int x;
  	cin >> x;
  
  	for(int i = x; i < 200000; i++){
    	if(prime(i)){
          cout << i << endl;
          break;
        }
    }
}

Measured memory_bytes: 256
def sum_n(n,N):
  kosu = int(N/n)
  result = (2*n+n*(kosu-1))*kosu/2
  return result

def main():
  N = int(input())

  S = N*(N+1)/2

  sum_3  = sum_n(3,N)
  sum_5  = sum_n(5,N)
  sum_15 = sum_n(15,N)
  print(int(S-sum_3-sum_5+sum_15))

  return 0
 
if __name__ == "__main__":
  main()

Measured memory_bytes: 9184
def insertion_sort(array, debug=False):
    """ AOJ??¬??¶?????¬???
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_A

    :param array: ?????????????±??????????
    :param debug: ??????????????????????????????????????????????????°
    :return: ?????????????????????
    """
    for i in range(0, len(array)):  # i????¬??????????????????????????????????
        v = array[i]  # ?????¨?????\???????????¨????????????????????????????????´???
        j = i - 1
        while j >= 0 and array[j] > v:
            array[j + 1] = array[j]
            j -= 1
        array[j + 1] = v
        if debug is True:
            print(' '.join(map(str, array)))
    return array


if __name__ == '__main__':
    # ??????????????¬?????¨
    # start_time = datetime.now()
    # print('>>> {0}'.format(start_time))

    # ??????????????\???
    num = int(input())
    data = [int(x) for x in input().split(' ')]
    # data = [5, 2, 4, 6, 1, 3]

    # ?????\??????????????????
    result = insertion_sort(data, debug=True)

    # ???????????????
    # print('result: {0}'.format(result))

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

constexpr int B = 330;

inline void chmin (int &a, int b) {
    if (a > b) a = b;
}

int main() {
    int n, q, op, x, y;
    cin >> n >> q;
    vector<int> a(B * B, INT_MAX), b(B, INT_MAX);
    
    auto update = [&] (int i, const int &x) -> void {
        const int id = i / B, k = id * B;
        a[i] = x; b[id] = INT_MAX;
        for (int j = k; j < k + B; j++) chmin(b[id], a[j]);
    };
    
    auto find_min = [&] (int l, int r) -> int {
        int res = INT_MAX;
        for (int i = l / B + 1; i < r / B; i++) chmin(res, b[i]);
        int vl = min(r, l / B * B + B), vr = max(l, r / B * B);
        for (int i = l; i < vl; i++) chmin(res, a[i]);
        for (int i = vr; i < r; i++) chmin(res, a[i]);
        return res;
    };

    while (q--) {
        cin >> op >> x >> y;
        if (op == 0) update(x, y);
        else cout << find_min(x, y + 1) << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 3372
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define	PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vbl vector<bool>
#define vpll vector<pll>
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(),x.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define mod 1000000007
#define INF 1000000000000000
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pll;
#define ook order_of_key
#define fbo find_by_order
/*  
	Query 1 - order_of_key(k) : Number of items strictly smaller than k.
	Query 2 - find_by_order(k) : K-th element in the set (counting from zero).
	less<ll> means Query 1 will return numbers strictly less than k.
	greater<ll> means Query 1 will return numbers strictly greater than k.
*/
ll powmod(ll x, ll n){
	ll res = 1;
	while(n){
		if(n & 1){
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		n >>= 1;
	}
	return res;
}
ll invmod(ll a){
	return powmod(a, mod - 2);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a, b, k;
	cin >> a >> b >> k;
	ll mn = min(a, k);
	a -= mn;
	k -= mn;
	mn = min(b, k);
	b -= mn;
	k -= mn;
	cout << a << ' ' << b << '\n';
}

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

int main(){
  int n,c;
  int tgt = 1;
  int a[200000];
  int i,j;
  
  cin >> n;
  for(i=0;i<=n-1;i++){
    cin >> a[i];
  }

  for(i=0;i<=n-1;i++){
      if(a[i] == tgt){
        tgt = tgt + 1;
      }
  }

  if(tgt == 1){
    cout << -1 << '\n';
  }else{
    cout << n - tgt + 1 << '\n';
  }
  
  return 0;
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using AR2 = array<int, 2>;
constexpr int MOD{1000000000 + 7};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int dx[4]{1, 0, -1, 0};
constexpr int dy[4]{0, 1, 0, -1};
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}
// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(0);

    string s;
    cin >> s;

    bool can = true;
    rep(i,3){
        if(s[i]==s[i+1])
            can = false;
    }

    if(can){
        cout << "Good" << endl;
    }else{
        cout << "Bad" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;

int main() {
ll n;
cin>>n;
vector<pair<int,int>  > v;
rep(i,1,n+1)
{
	ll x;
	cin>>x;
	v.push_back({x,i});
}
sort(v.begin(),v.end());
ll ans=0;
rep(i,0,n)
{
	if(abs(i+1-v[i].second)%2!=0)
	ans++;


}
cout<<ans/2;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  
  int A, B, C;
  bool ans = false;
  
  cin >> A >> B >> C;
  
  if (A == 7 && B == 5 && C == 5)
    ans = true;
  if (A == 5 && B == 7 && C == 5)
    ans = true;
  if (A == 5 && B == 5 && C == 7)
    ans = true;
  
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
}

Measured memory_bytes: 256
package main

// Solution for https://atcoder.jp/contests/abc069/tasks/arc080_b

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var h, w, n int
	con.Scan(&h, &w, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		con.Scan(&a[i])
	}
	k := 0
	for i := 0; i < h; i++ {
		l := make([]string, w)
		for j := 0; j < w; j++ {
			x := strconv.Itoa(k + 1)
			a[k]--
			if a[k] == 0 {
				k++
			}
			if i%2 == 0 {
				l[j] = x
			} else {
				l[w-j-1] = x
			}
		}
		con.Println(strings.Join(l, " "))

	}
	return nil
}


Measured memory_bytes: 1024
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 20;

int x[N],y[N],p[N];
int dis[N];
LL ans[N];
int vis[N];

int main()
{
	int n;scanf("%d",&n); 
	for(int i=1;i<=n;i++) scanf("%d%d%d",&x[i],&y[i],&p[i]),ans[i]=1e18;
	ans[0] = 1e18;
	
	for(int i=0;i<(1<<n);i++){
		int num=0;
		for(int j=0;j<n;j++) if((i>>j)&1) vis[++num] = j+1;  //此次建num个road 
		
		for(int j=0;j<(1<<num);j++){
			
			for(int k=1;k<=n;k++) dis[k] = min(abs(x[k]),abs(y[k]));
			
			for(int k=0;k<num;k++){
				if((j>>k)&1){	//在num个road里选x方向建road 
					for(int t=1;t<=n;t++) dis[t] = min(dis[t],abs(x[t]-x[vis[k+1]]));
				}	//维护每个站到新road的最短距离 
				else{
					for(int t=1;t<=n;t++) dis[t] = min(dis[t],abs(y[t]-y[vis[k+1]]));
				} 
			}
			LL s=0;
			for(int k=1;k<=n;k++) s += (LL)dis[k]*p[k];
			ans[num] = min(ans[num],s);
		}
	}
	for(int i=0;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod 1e9+7
#define P(a,b) pair<a,b>
#define CIN(V,s,n) for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}

using namespace std;
bool sortBylen(string &a,string &b)
{
    if(a.size()>b.size())
        return true;
    else if(a.size()==b.size())
    {
        if(a>b)
        {
            return true;
        }
        else
            false;
    }
    else
        return false;
}
int main()
{
ll t=1;
//cin >> t;
while(t--)
{
    ll n,i,j,k=2,l,m;
    cin >> n;
    vector<vector<ll> > D(n,vector<ll>(3)),DP(n,vector<ll>(3));
    for(i =0;i<n;i++)
    {
        cin >> D[i][0] >> D[i][1] >> D[i][2];
    }
    DP[0][0] = D[0][0];
    DP[0][1] = D[0][1];
    DP[0][2] = D[0][2];
    for(i=1;i<n;i++)
    {
        DP[i][0] = max(DP[i-1][1],DP[i-1][2]) + D[i][0];
        DP[i][1] = max(DP[i-1][0],DP[i-1][2]) + D[i][1];
        DP[i][2] = max(DP[i-1][0],DP[i-1][1]) + D[i][2];
    }

    cout << max(DP[n-1][0],max(DP[n-1][1],DP[n-1][2])) << endl;


}

	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
// #define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

int n,k;
int a[105];

int dp[100005][2];
int calc(int k,bool p){
	int &ans=dp[k][p];
	if(ans!=-1)return ans;
	if(p==0){
		ans=-5;
		rep(i,0,n){
			if(k>=a[i]){
				ans=max(ans,calc(k-a[i],!p));
			}
		}
	}
	else{
		ans=5;
		rep(i,0,n){
			if(k>=a[i]){
				ans=min(ans,calc(k-a[i],!p));
			}
		}
	}
	return ans;
}

void solve(){
	// mem1(dp);
	cin>>n>>k;
	rep(i,0,n)cin>>a[i];
	rep(i,0,k+1){
		dp[i][0]=-5;
		dp[i][1]=+5;
	}
	rep(i,0,k+1){
		rep(j,0,n){
			if(i>=a[j]){
				dp[i][0]=max(dp[i][0],dp[i-a[j]][1]);
				dp[i][1]=min(dp[i][1],dp[i-a[j]][0]);
			}
		}
	}
	
	cout<< ((dp[k][0]>0)?"First":"Second");
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
    int n,k;
    int a[1000];
    int i,j;
    int min,t,sum=0;
    scanf("%d",&n);
    scanf("%d",&k);
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    

    
    for(i=0;i<n-1;i++){
        for(j=0; j<n-1-i;j++){
            if(a[j+1]<a[j]){
                t=a[j];a[j]=a[j+1];a[j+1]=t;
            }
        }
    }
    for(i=0; i<k; i++){
        sum+=a[i];
    }
    printf("%d",sum);
return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,a=0,b=0;
    cin >> n;
    vector<int> num(n);
    for(int i=0;i<n;i++)
        cin >> num.at(i);
    sort(num.begin(),num.end(),greater<>());
    for(int i=0;i<n;i++){
        if(i%2==0)
            a+=num.at(i);
        else
            b+=num.at(i);
    }
    cout << a-b << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    ll N, k;
    cin >> N >> k;

    map<ll, ll> mp;
    vector<ll> v(N);
    for (int i = 0; i < N; i++) {
        ll a,b;
        cin >> a >> b;
        v[i] = a;
        mp[a] += b;
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    ll count=0;
    for (int i = 0; i < (int)v.size(); i++) {
        count += mp[v[i]];
        if (count >= k) {
            cout << v[i] << endl;
            return;
        }
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

using namespace std;


int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int sum = 0;
    for (int i = 0; i < N; ++i){
        cin >> A[i];
        sum += A[i];
    }
    double ave = (double)(sum) / N;

    int ans = 0;
    double def1 = abs(ave - A[0]), def2;
    for (int i = 1; i < N; ++i) {
        def2 = abs(ave - A[i]);
        if(def1 > def2){
            ans = i;
            def1 = abs(ave - A[i]);
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

struct info{
	int x;
	bool y;
};

int counter(int x){
	if(x==0)return 0;
	return counter(x>>1)+(x&1);
}

int main() {
	int n;
	cin>>n;
	info inf[20][20];
	int a[20];
	for(int i=1;i<=n;++i){
		cin>>a[i];
		for(int j=1;j<=a[i];++j){
			int hoge;
			cin>>inf[i][j].x>>hoge;
			inf[i][j].y=hoge==1;
		}
	}
	int ans=0;
	for(int bit=1;bit<(1<<n);++bit){
		bool f=true;
		for(int i=1;i<=n;++i){
			if(!(bit&(1<<i-1)))continue;//不親切なのでこの人の証言の真偽を確かめる必要がない
			for(int j=1;j<=a[i];++j){
				if(((bit>>(inf[i][j].x-1))&1)^inf[i][j].y)f=false;
			}
		}
		if(f)ans=max(ans,counter(bit));
	}
	cout<<ans;
}

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

using namespace std;

#define ll long long

int main() {

    int A, B, M; cin >> A >> B >> M;
    vector<pair<int, int>> a(A), b(B);
    for(int i=0; i<A; i++) {
        int ai; cin >> ai;
        a[i] = make_pair(ai, i); 
    }
    for(int i=0; i<B; i++) {
        int bi; cin >> bi;
        b[i] = make_pair(bi, i); 
    }
    set<pair<int,int>> c;
    vector<pair<pair<int, int>, int>> m(M);
    for(int i=0; i<M; i++) {
        int xi, yi, ci; cin >> xi >> yi >> ci;
        m[i] = make_pair(make_pair(xi-1, yi-1), ci);
        c.insert(make_pair(xi-1, yi-1));
    }

    int ans = 10000000;
    for(int i=0; i<M; i++) {
        ans = min(a[m[i].first.first].first + b[m[i].first.second].first - m[i].second, ans);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if(c.count(make_pair(a[0].second, b[0].second))==0) {
        ans = min(a[0].first+b[0].first, ans);
    } 

    if(b.size()>1) {
        if(c.count(make_pair(a[0].second, b[1].second))==0) {
            ans = min(a[0].first+b[1].first, ans);
        } 
    }
    
    if(a.size()>1) {
        if(c.count(make_pair(a[1].second, b[0].second))==0) {
            ans = min(a[1].first+b[0].first, ans);
        } 
    }

    if(a.size()>1 & b.size() >1) {
        if(c.count(make_pair(a[1].second, b[1].second))==0) {
            ans = min(a[1].first+b[1].first, ans);
        } 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>k>>a>>b;
    x=a/k;
    x++;
    x*=k;
    if(x<=b&&x>=a)cout<<"OK"<<endl;
    else if(a%k==0)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}


Measured memory_bytes: 3656
#include <stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d\n",&a,&b);
    int s[a][b], t[b];
    int i,j;
    for (i=0;i<a;i++)
    {
        for(j=0;j<b;j++)
        {
            scanf("%d",&s[i][j]);
        }
    }
    for(j=0;j<b;j++)
    {
        scanf("%d",&t[j]);
    }
    int ans[a];
    for (i=0;i<a;i++)
    {
        ans[i] = 0;
        for (j=0;j<b;j++)
        {
            ans[i] += s[i][j]*t[j];
        }
    }
    for (i=0;i<a;i++)
    {
        printf("%d\n",ans[i]);
    }
    return 0;
}



Measured memory_bytes: 2140
#include <cstdio>
int main(){	for(int m,n,i,j,k,a;a=1,scanf("%d",&m),m;puts(a?"OK":"NG")){int d[300]={0},g[300][300]={0};scanf("%d",&n);for(i=1;i<=n;)scanf("%d",d+i++);for(i=0;i<=n;i++)for(j=1;j<=m;j++)k=i+j+d[i+j],(k=k<0?0:n+1<k?n+1:k),g[i][k]=1;for(k=0;k<n+2;k++)for(i=0;i<n+2;i++)for(j=0;j<n+2;j++)if(g[i][k]&&g[k][j])g[i][j]=1;for(i=0;i<=n;i++)if(g[0][i]&&!g[i][n+1])a=0;}}

Measured memory_bytes: 1372