akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define F first
#define S second
#define int long long
#define pb push_back
#define endl '\n'

using namespace std;

int n , dp[100001][3] , a[100001][3] ;

int32_t main()
{
	ios_base :: sync_with_stdio(false) ;
	cin.tie(0); cout.tie(0) ; 
	cin >> n ; 
	for(int i = 1 ; i <= n ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> a[i][j] ; 
			for(int k = 0 ; k < 3 ; k++){
				if(j != k){
					dp[i][j] = max(dp[i][j] , dp[i - 1][k] + a[i][j]) ; 
				}
			}
		}
	}
	cout << max(dp[n][0] , max(dp[n][1] , dp[n][2])) << endl ;
	return 0 ;
}



Measured memory_bytes: 4992
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, m, X, Y; cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    rep(i, n) {
        cin >> x[i];
    }
    rep(i, m) {
        cin >> y[i];
    }
    for(int Z = X + 1; Z <= Y; ++ Z) {
        bool flag = 1;
        rep(i, n) {
            if(x[i] >= Z) flag = 0;
        }
        rep(i, m) {
            if(y[i] < Z) flag = 0;
        }
        if(flag) {
            cout << "No War" << endl;
            return;
        }
    }
    cout << "War" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int a[100010];
int n, k, q; 
vector<int> v;
map<int, int> mp; 
int main(void) 
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
	cin >> n >> k >> q;
	for (int i=1; i<=n; i++) a[i] = k-q;
	for (int i=1; i<=q; i++) 
	{
		int x; 
		cin >> x; 
		a[x]++;
	}
	for (int i=1; i<=n; i++) 
	{
		if (a[i]>0) cout << "Yes\n";
		else cout << "No\n";
	}



	

	
	return false; 
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean hasNextInt = scanner.hasNextInt();
        int x = scanner.nextInt();
        if(hasNextInt) {
            while(x > 0) {
                if(x % 10 == 7) {
                    System.out.println("Yes");
                    break;
                } else {
                    x /= 10;
                }
                if(x == 0) {
                    System.out.println("No");
                }
            }
        }
        scanner.close();
    }
}

Measured memory_bytes: 35560
import java.util.*;


public class Main{
	public static void main( String args[] ) {

		int counter  = 0;
		int n;
		int h;
		int w;
		
		
		Scanner scan = new Scanner( System.in );
		n = scan.nextInt();
		h = scan.nextInt();
		w = scan.nextInt();
		
		counter = 0;
		
		int temp1,temp2;
		
		if( h > w ) {
			temp1 = h;
			temp2 = w;
		}
		else {
		
			temp1 = w;
			temp2 = h;
 		}
		
		counter = ( n - temp1 + 1 ) * ( n - temp2 + 1 );
		
		
		
		System.out.println( counter );
		
		scan.close();
		
	}
}

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

using namespace std;

int main()
{
	vector<string> s_list = { "SUN","MON","TUE","WED","THU","FRI","SAT" };

	string S;
	cin >> S;

	int res_index = 7;
	for (int i = 0; i < 7; i++)
	{
		if (S == s_list.at(i))
		{
			res_index = 7 - i;
		}
	}

	cout << res_index << endl;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var n, w int
var items []item
var dp [][]int64

type item struct {
	w int
	v int64
}

func main() {
	n = readInt()
	w = readInt()
	items = make([]item, n)
	for i := range items {
		items[i] = item{
			w: readInt(),
			v: readInt64(),
		}
	}
	dp = make([][]int64, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int64, w+1)
	}

	for i := 1; i <= n; i++ {
		for j := 0; j <= w; j++ {
			if j-items[i-1].w >= 0 {
				dp[i][j] = maxInt64(dp[i-1][j], dp[i-1][j-items[i-1].w]+items[i-1].v)
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}

	fmt.Println(dp[n][w])
}


Measured memory_bytes: 81792
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n;
	scanf("%lld",&n);
	int a[n+1];
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	int sum=0,Xor=0,j=0,ans=0;
	for(int i=1;i<=n;i++){
		while(j<n&&((sum+a[j+1])==(Xor^a[j+1]))){
			sum+=a[j+1];
			Xor^=a[j+1];
			j++;
		}
		if(sum==Xor){
			ans+=j-i+1;
		}
		sum-=a[i];
		Xor^=a[i];
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1792
a,b,c,x,y=map(int,input().split())
cost=a*x+b*y
if a+b>2*c:
  cost-=(a+b-2*c)*min(x,y)
  if x>y and a>2*c:
      cost-=(a-2*c)*(x-y)
  elif y>x and b>2*c:
      cost-=(b-2*c)*(y-x)
print(cost)

Measured memory_bytes: 3064
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())

    if k==0:
        print(n**2)
    else:
        res=0
        for b in range(1,n+1):
            if b<=k:
                continue
            else:
                m=n//b
                l=n%b
                res+=(b-k)*m
                res+=max(0,l-k+1)

        print(res)

if __name__=="__main__":
    main()

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

using namespace std;

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

    int flag = 2;

    while(n--){
        int a;
        cin >> a;

        if(flag == 2 && a % 2 == 0 && a % 3 != 0 && a % 5 != 0)
            flag = 3;
    }

    if(flag == 3) cout << "DENIED" << endl;
    else cout << "APPROVED" << endl;
}

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

int main()
{
  int n;
  scanf("%d",&n);
  static long long A[100000],B[100000];
  for(int i=0;i<n;i++){
    scanf("%d%d",A+i,B+i);
  }
  long long c=0;
  for(int i=n-1;i>=0;i--){
    long long d=(A[i]+c)%B[i];
    c+=(d==0?0:B[i]-d);
  }
  printf("%lld\n",c);
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    // Your code here!
    int i,N;
    scanf("%d",&N);
    //printf("%d",N);
    int v[N],big=0,sum=0;
    for (i=0;i<N;i++){
        scanf("%d",&v[N]);
        //printf("%d\n",big);
        if (v[N]>big){
            sum+=big;
            big=v[N];
            
        }
        else
            sum+=v[N];
        
    }
    //printf("%d,%d,%d",sum,big,N);
    (big<sum) ? printf("Yes") : printf("No") ;
}

Measured memory_bytes: 128
fn main() {
    proconio::input! {
        x: i64,
        y: i64,
    }
    for i in 0..500 {
        for j in 0..500 {
            if i * 2 + j * 4 == y && i + j == x {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 2180
#include <iostream>
#include <string>
#include <vector>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main() {
	string s1,s,s2;
    cin>>s1>>s>>s2;
    cout<<s1[0]<<s[0]<<s2[0];
	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;
typedef long long ll;

typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.1415926535897932384626;
long long int mod = 1000000007;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}

ll i,j,k,ii,jj;
ll n,m,num;
ll a,b,c,d,e,g,h,r;
ll f[500005],x[500005],y[500005],z[500005];
bool dame;
bool check[500005];
char s[500005],t[500005];




int main(){
    cin>>n;
	for(i=1;i<=n;i++)cin>>x[i];
	a = 1;
	for(i=1;i<=n;i++){
		a *= i;
		a %= mod;
	}
	b = a;
	for(i=1;i<=n;i++){
		a = b;
		a *= rui(i,mod-2);
		a %= mod;
		f[i] = a;
	}
	//for(i=1;i<=n;i++)p(f[i]);
	ll sum = 0;
	for(i=1;i<=n;i++){
		sum += f[i];
		sum %= mod;
	}
	
	ll ans = 0;
	for(i=1;i<=n;i++){
		//p(sum);
		ans += (x[i] * sum)%mod;
		ans %= mod;
		//if(i==n)break;
		sum += (mod - f[n-i+1]);
		sum += f[i+1];
		sum %= mod;
	}
	
	p(ans);
	
    return 0;
}


Measured memory_bytes: 28544
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  void run() {
    int n = ni();
    int m = ni();
    int a = ni(), b = ni(), c = ni();
    int[] abc = { a, b, c };
    boolean[][] link = new boolean[n][n];
    for ( int i = 0; i < m; ++i ) {
      int u = ni() - 1;
      int v = ni() - 1;
      link[ u ][ v ] = true;
    }

    int[] goals = new int[n];
    int inf = 1 << 28;
    Arrays.fill( goals, inf );
    goals[ n - 1 ] = 0; // ??´???????????´??????
    // ????????§???n?????????????????´??????????¢?????????????
    for ( int g = 0; g < n; ++g ) {
      ArrayList<Integer> additional_goal = new ArrayList<>();
      for ( int i = 0; i < n; ++i ) {
        if ( goals[ i ] != inf ) {
          // ??´???????????£??????????????????
          continue;
        }
        boolean flag = true;
        for ( int j = 0; j < 3; ++j ) {
          int MAX_STEP = abc[ j ];
          Queue<Integer> queue = new LinkedList<>();
          Queue<Integer> qstep = new LinkedList<>();
          boolean[][] done = new boolean[MAX_STEP + 1][n];
          queue.add( i );
          qstep.add( 0 );
          done[ 0 ][ i ] = true;
          boolean subf = false;
          // ?????????goals????????????????????°??????????????????
          while (queue.size() > 0) {
            int e = queue.poll();
            int s = qstep.poll();
            if ( s == MAX_STEP ) {
              if ( goals[ e ] != inf ) {
                subf |= true;
              }
              continue;
            }
            for ( int next = 0; next < n; ++next ) {
              if ( !link[ e ][ next ] )
                continue;
              int ns = s + 1;
              if ( done[ ns ][ next ] )
                continue;
              queue.add( next );
              qstep.add( ns );
              done[ ns ][ next ] = true;
            }
          }
          // abc ??¨????????????????????°??????????????´?????????????????????????????????????????????????????????
          flag &= subf;
        }
        // ??´???????????????
        if ( flag ) {
          additional_goal.add( i );
          // debug( i + 1, g + 1 );
          // goals[ i ] = g + 1; // ???????????????????????????
        }
      }
      for ( int i : additional_goal ) {
        goals[ i ] = g + 1;
      }
    }

    System.out.println( goals[ 0 ] != inf ? goals[ 0 ] : "IMPOSSIBLE" );
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 95260
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }





int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;
    cout << (n - 1) / 2;

    print_time();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int a, b;
	cin >> a >> b;
	if (5 < a && a < 13) {
		cout << b / 2 << endl;
	}
	else  if (a > 12){
		cout << b << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
# import sys


# fin = sys.stdin.readline
MOD = 10 ** 9 + 7
S = input()[::-1]
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
for i, c in enumerate(S, start=1):
    base = pow(10, i - 1, 13)
    if c != '?':
        d = int(c) * base % 13
        for r in range(13):
            c = (d + r) % 13
            dp[i][c] += dp[i - 1][r]
            dp[i][c] %= MOD
    else:
        for d in range(10):
            d = d * base % 13
            for r in range(13):
                c = (d + r) % 13
                dp[i][c] += dp[i - 1][r]
                dp[i][c] %= MOD
print(dp[-1][5])


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = (ll)1e18;

struct PrefixSum {
    vector<ll> p;

    PrefixSum(const vector<ll>& a): p(a.begin(), a.end()) {
        for (size_t i = 1; i < p.size(); ++i)
            p[i] += p[i - 1];
    }

    ll get(int l, int r) const {
        assert(l <= r);
        assert(l >= 0);
        assert(r < p.size());
        ll ans = p[r];
        if (l > 0)
            ans -= p[l - 1];
        return ans;
    }
};

ll get_ans(ll a, ll b, ll c, ll d) {
    ll mx = max(max(a, b), max(c, d));
    ll mn = min(min(a, b), min(c, d));
    if (mn == 0)
        return INF;
    return mx - mn;
}

int get_pos(const PrefixSum& ps, int lo, int hi) {
    assert(hi - lo >= 1);
    int l = lo;
    int r = hi;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (ps.get(lo, m) < ps.get(m + 1, hi))
            l = m;
        else
            r = m;
    }
    return l;
}

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

    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto& x : a) {
        cin >> x;
    }
    ll ans = INF;
    PrefixSum ps(a);
    for (int i = 2; i + 2 <= n; i++) {
         int p1 = get_pos(ps, 0, i - 1);
         int p2 = get_pos(ps, i, n - 1);
         for (int d1 = -5; d1 <= 5; d1++)
             for (int d2 = -5; d2 <= 5; d2++) {
                int l = p1 + d1;
                int m = i;
                int r = p2 + d2;
                if (l <= 0)
                    continue;
                if (r >= n)
                    continue;
                if (m <= l)
                    continue;
                if (r <= m)
                    continue;
                ans = min(ans, get_ans(ps.get(0, l - 1), ps.get(l, m - 1), ps.get(m, r - 1), ps.get(r, n - 1)));
             }
    }
    cout << ans << endl;
}

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

int main() {
    int count2, count1;
    count1 = count2 = 0;
    bool s = true;

    string line;
    cin >> line;

    for(int i = 0; i < line.size(); i++) {
        if(s) {
            if(line[i] == '0') {
                count1++;
            } else {
                count2++;
            }
        } else {
            if(line[i] == '1') {
                count1++;
            } else {
                count2++;
            }
        }
        s = !s;
    }

    cout << min(count2, count1) << endl;

}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<bool> primes(1005, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i <= 1000; ++i) {
    if (not primes[i]) { continue; }
    for (int j = i * i; j <= 1000; j += i) {
      primes[j] = false;
    }
  }

  vector<int> factors(N + 1, 0);
  for (int i = 2; i <= N; ++i) {
    int val = i;
    for (int j = 2; j <= N and val > 1; ++j) {
      if (not primes[j]) { continue; }
      int cnt = 0;
      while (val > 1 and val % j == 0) {
        val /= j;
        ++cnt;
      }
      factors[j] += cnt;
    }
  }
  ll ans = 1;
  for (int i = 2; i <= N; ++i) {
    if (not primes[i]) { continue; }
    ans = (ans * (factors[i] + 1)) % MOD;
  }
  printf("%lld\n", ans);
  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);
        String S = sc.next();
        long K = sc.nextLong();
        int n = S.length();

        int i = 0;
        while (i + 1 < n && S.charAt(i + 1) == S.charAt(0)) i++;

        long firstPart = (i + 1) / 2;

        if (i == n - 1) {
            System.out.println((K * n) / 2);
            return;
        }

        int j = n - 1;
        while (j - 1 >= 0 && S.charAt(j - 1) == S.charAt(n - 1)) j--;
        long lastPart = (n - j) / 2;

        long middle = 0;
        for (int k = i + 1; k < j; k++) {
            int l = k;
            while (l + 1 < j && S.charAt(l + 1) == S.charAt(k)) l++;
            middle += (l - k + 1) / 2;
            k = l;
        }

        long overlap = 0;
        if (S.charAt(0) == S.charAt(n - 1)) {
            overlap = (n - j + i + 1) / 2;
        }

        long sol = 0;
        if (overlap > 0) {
            sol = (K - 1) * overlap + K * middle + firstPart + lastPart;
        } else {
            sol = K * (firstPart + middle + lastPart);
        }

        System.out.println(sol);
    }
}


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

int main(){
    int h,w;
    while(cin >> h >> w){
        char g[200][200];
        int ans = 0;
        rep(i,h) cin >> g[i];
        rep(i,h)rep(j,w){
            bool ok = true;
            if(i == 0) ok = false;
            if(g[i][j] != '-') ok = false;
            if(j-1 >= 0 && g[i][j-1] == 'o') ok = false;
            if(j+1 <  w && g[i][j+1] == 'o') ok = false;
            for(int di = -1; di <= 1; ++di){
                for(int dj = -1; dj <= 1; ++dj){
                    if(di == 0 && dj == 0) continue;
                    int ni = i+di;
                    int nj = j+dj;
                    if(ni >= h || nj >= w) continue;
                    if(ni < 0 || nj < 0) continue;
                    if(g[ni][nj] == 'x') ok = false;
                }
            }
            ans += ok;
        }
        cout << ans << endl;
    }
}

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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	vector<int> A1(N);
	vector<int> A2(N);
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A1[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> A2[i];
	}

	int sum1 = 0;
	for (int i = 0; i < N; ++i) {
		sum1 += A1[i];
		int sumTotal = sum1;
		for (int j = i; j < N; ++j) {
			sumTotal += A2[j];
		}
		ans = max(ans, sumTotal);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3604
N,Q=map(int,input().split()) 
S=input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);++i)
using vertex = struct vertex {ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}};
using AdjList = vector<vector<vertex>>;
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using Edges = vector<edge>;

AdjList adj;
ll ans;

void dfs(ll now_v,vector<bool> visited){
  if(visited[now_v])return;
  visited[now_v]=true;
  bool goal=true;
  for(const auto& element:visited)goal&=element;
  if(goal){
    ans++;
    return;
  }
  for(const auto& next_v:adj[now_v]){
    dfs(next_v.to,visited);
  }
}

main(){

  ll n,m;
  cin>>n>>m;
  adj.resize(n);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    adj[a].emplace_back(b,1);
    adj[b].emplace_back(a,1);
  }
  vector<bool> visited(n,false);
  dfs(0,visited);
  cout<<(ans)<<endl;


}

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

int main(){
    vector <int> S(3);
    rep(i,3){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    string tmp = to_string(S[2]) + to_string(S[1]);
    int ans = stoi(tmp) + S[0];
    cout << ans << endl; 
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)

using namespace std;
using card=pair<int,char>;

bool check(const vector<card> &ary){
	rep(i,3){
		// color
		if(ary[3*i].second!=ary[3*i+1].second) return false;
		if(ary[3*i].second!=ary[3*i+2].second) return false;
		
		// number
		if(ary[3*i].first==ary[3*i+1].first&&ary[3*i+1].first==ary[3*i+2].first) continue;;
		if(ary[3*i+1].first-ary[3*i].first==1 && ary[3*i+2].first-ary[3*i+1].first ==1) continue;
		return false;
	}
	return true;
}

int main(void){
	int t;
	cin >> t;
	while(t--){
		vector<card> ary(9);
		rep(i,9) cin >> ary[i].first;
		rep(i,9) cin >> ary[i].second;
		
		sort(_all(ary));
		bool ok=false;
		do{
			if(check(ary)) ok=true;
		}while(next_permutation(_all(ary)));
		cout << int(ok) << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

vector<int> a,b,c;
int f[112345];int s[112345];
int memo[112345];
int d[112345];
int main(){
  int n;

  cin>>n;
  rep(i,n){
    int x;
    cin>>x;
    a.push_back(x);
  }
  rep(i,n){
    int x;
    cin>>x;
    b.push_back(x);
  }
  rep(i,n){
    int x;
    cin>>x;
    c.push_back(x);
  }


  sort(a.begin(),a.end());
  // a.erase(unique(all(a)),a.end());
  sort(b.begin(),b.end());
  // b.erase(unique(all(b)),b.end());
  sort(c.begin(),c.end());
  // c.erase(unique(all(c)),c.end());

  for(int i=0;i<(int)b.size();i++){
    int lb = lower_bound(a.begin(),a.end(),b[i])-a.begin();
    dump(lb);
    d[i]=lb;
  }
  // for(int i=(int)b.size()-2;i>=0;i--){
  //   d[i]+=d[i+1];
  // }
  for(int i=0;i<(int)b.size();i++){
    int ub = upper_bound(all(c),b[i])-c.begin();
    s[i]=n-ub;
  }
  ll ans=0;
  rep(i,n){
    // dump(d[i]);
    // dump(s[i]);
    ans+=(ll)((ll)d[i]*(ll)s[i]);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 2296
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int n=sc.nextInt();
		int[] a=new int[2*n];
		int[] b=new int[2*n];
		for(int i=0; i<2*n; i++){
			a[i]=i+1;
		}
		int m=sc.nextInt();
		for(int j=0; j<m; j++){
			int k=sc.nextInt();
			if(k==0){
				for(int i=0; i<n; i++){
					b[2*i]=a[i];
					b[2*i+1]=a[i+n];
				}
			}else{
				for(int i=0; i<k; i++){
					b[2*n-k+i]=a[i];
				}
				for(int i=0; i<2*n-k; i++){
					b[i]=a[k+i];
				}
			}
			System.arraycopy(b, 0, a, 0, 2*n);
		}
		for(int i=0; i<2*n; i++){
			println(a[i]+"");
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    string s;
    cin >> s;
    string dic[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    auto itr = find(dic, dic + 7, s);
    OUT(7 - (itr - dic));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,temp,dp[100004];
	cin>>n;
	vector<int>v;
	for(i=0;i<n;i++)
		{
			cin>>temp;
			v.push_back(temp);
		}
	
	dp[0]=0;
	dp[1]=abs(v[0] - v[1]);
	for(i=2;i<n;i++)
		{
			dp[i] = min(  (dp[i-1] + abs(v[i] - v[i-1]) )  , ( dp[i-2] + abs(v[i] - v[i-2])  )       );
		}
	
	cout<<dp[n-1]<<endl;	
	
}

Measured memory_bytes: 1144
#明日の入学試験に合格するために、太郎くんはあと T 時間の勉強をする必要があります。
#幸いにも、彼は今いる世界(世界A)の X 倍の速度で時間が進む世界Bへ世界跳躍(ワールドリープ)することができます。
#世界Bで (X×t) 時間進むと、世界Aでは t 時間進みます。
#世界Bで T 時間勉強したとき、世界Aでは何時間進んでいるでしょうか。

T, X = map(int, input().split())
print(T/X)

Measured memory_bytes: 38484
using System;
using System.Linq;

public class AtCoderD
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int[] nums = new int[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                nums[i] = int.Parse(words[i]);
            }
        }

        Array.Sort(nums);

        int answer = 0;
        for (int i = 0; i < n - 2; i++)
        {
            int a = nums[i];
            for (int j = i + 1; j < n - 1; j++)
            {
                int b = nums[j];
                int sum = a + b;
                if(sum > nums[n - 1])
                {
                    answer += n - j - 1; 
                    continue;
                }
                for (int k = j + 1; k < n; k++)
                {
                    int c = nums[k];
                    if (sum <= c)
                    {
                        break;
                    }
                    else
                    {
                        answer++;
                    }
                }
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11128
#include "stdio.h"
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
   ll possibilities[2], temp;
   possibilities[0] = 1;
   possibilities[1] = 0;
   int N, P, biscuits;
   cin >> N >> P;
   while (N--) {
      cin >> biscuits;
      if (biscuits % 2 == 0) {
         possibilities[0] *= 2;
         possibilities[1] *= 2;
      }//if
      else {
         temp = possibilities[0];
         possibilities[0] += possibilities[1];
         possibilities[1] += temp;
      }//else
   }//while
   cout << possibilities[P % 2] << endl;
   return 0;
}//main


Measured memory_bytes: 256
r,g,b,n=gets.chomp.split(" ").map(&:to_i)
result=0
    ((n/r)+1).times do |i|
      (((n-r*i)/g)+1).times do |j|
        if (n-r*i-g*j)%b == 0
          result+=1
        end
      end
    end
puts result

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;

int main() {
	string A, B, C;
	cin >> A >> B >> C;
	queue<int> a;
	queue<int> b;
	queue<int> c;
	for (int i = 0; i < A.size(); ++i) {
		a.push(A[i] - 'a');
	}
	for (int i = 0; i < B.size(); ++i) {
		b.push(B[i] - 'a');
	}
	for (int i = 0; i < C.size(); ++i) {
		c.push(C[i] - 'a');
	}
	int now = 0;
	while (true) {
		if (0 == now) {
			if (0 == a.size()) {
				break;
			}
			now = a.front();
			a.pop();
		}
		else if (1 ==now) {
			if (0 == b.size()) {
				break;
			}
			now = b.front();
			b.pop();
		}
		else {
			if (0 == c.size()) {
				break;
			}
			now = c.front();
			c.pop();
		}
	}
	cout << (char)('A'+now)<< endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    string str;
    cin>>str;
    for(unsigned i = 0;i < str.size();i++)
    {
        if(str[i] == 'C')
        {
            for(unsigned j = i + 1;j < str.size();j++)
            {
                if(str[j] == 'F')
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

#define PRINT(s) cout << (s);
#define PRINTLN(s) cout << (s) << endl;

using namespace std;

void run(int *a,int *b,int *c){
    int tmpa = *a,tmpb = *b,tmpc = *c;
    *a = (tmpa + tmpb)/2;
    *b = (tmpa + tmpc)/2;
    *c = (tmpb + tmpc)/2;

}

int main(){
    int a,b,c;
    int n = 0;
    cin >> a >> b >> c;
    while(true){
        if( a % 2 != 0 || b % 2 != 0 || c % 2 != 0 ){
            break;
        }else if( a == b && b == c){
            n = -1;
            break;
        }else{
            run(&a,&b,&c);
            n++;
        }
    }
    PRINTLN(n);
}


Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}


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

    int A, B, C;
    cin >> A >> B >> C;

    if(A==B) cout << C << endl;
    else if(A==C) cout << B << endl;
    else cout << A << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
num1, num2 = 0, 0
s = 0
for i in range(n):
    s += a[i]
    if i % 2 == 0 and s <= 0:
        num1 += 1 - s
        s = 1
    elif i % 2 == 1 and s >= 0:
        num1 += s + 1
        s = -1

s = 0
for i in range(n):
    s += a[i]
    if i % 2 == 1 and s <= 0:
        num2 += 1 - s
        s = 1
    elif i % 2 == 0 and s >= 0:
        num2 += s + 1
        s = -1

print(min(num1, num2))

Measured memory_bytes: 14468
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;

const int MOD = 1000000007;
const int INF = 1000000000;

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


struct edge{
    int to; ll cost;
    edge(int To, ll Cost) : to(To), cost(Cost){};
};


int V; //頂点数
vector<vector<edge>> G;
vector<ll> d; //sからの距離

void dfs(int v, int par, ll dep){
    d[v] = dep;
    for(auto& e: G[v]){
        if(e.to == par) continue;
        dfs(e.to, v, dep + e.cost);
    }
}

int main(){
    int n; cin >> n;
    G.resize(n); d.resize(n, 0);
    REP(i, n-1){
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        G[a].PB(edge(b, c)); G[b].PB(edge(a, c));
    }
    int q, k; cin >> q >> k;
    --k;
    dfs(k, -1, 0);
    REP(i, q){
        int x, y; cin >> x >> y;
        --x; --y;
        cout << d[x] + d[y] << "\n";
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string S; cin >> S;
    set<char> s;
    for(int i = 0; i < (int)S.size(); i++) s.insert(S[i]);
    if(s.size() != S.size()) cout << "no" << endl;
    else cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;
using std::complex;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

inline ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

inline ll min(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
ll n, m;

ll L, R;
ll ans = 1e9;
int main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin >> L >> R;
    for (ll i = L; i <= min(R, L + 2019); i++)
    {
        for (ll j = i + 1; j <= min(R, L + 2019); j++)
        {
            ans = min(ans, i * j % 2019);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;
int n ,k ,r ,s ,p ;
bool is[N] ;
string str ;
long long ans ;
int main(){
    cin >> n >> k >> r >> s >> p ;
    cin >> str ;
    for(int i=0;i<str.size();++i){
        if(i>=k && is[i-k] && str[i]==str[i-k]) continue ;
        is[i] = 1 ;
        if(str[i]=='r') ans += p ;
        if(str[i]=='s') ans += r ;
        if(str[i]=='p') ans += s ;
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstring>

const int NMAX = 107;

using namespace std;

char s1[NMAX], s2[NMAX], s3[NMAX];

int main(){
    cin >> s1;
    cin >> s2;
    cin >> s3;
    int p1 = 0, p2 = 0, p3 = 0, n1, n2, n3;
    n1 = strlen(s1);
    s1[n1] = 'a';
    n2 = strlen(s2);
    s2[n2] = 'b';
    n3 = strlen(s3);
    s3[n3] = 'c';
    char ch = s1[0];
    ++p1;
    while(p1 <= n1 && p2 <= n2 && p3 <= n3) {
        int ind = ch - 'a' + 1;
        if(ind == 1) {
            ch = s1[p1];
            ++p1;
        }
        if(ind == 2) {
            ch = s2[p2];
            ++p2;
        }
        if(ind == 3) {
            ch = s3[p3];
            ++p3;
        }
    }
    if(p1 == n1 + 1) {
        cout << 'A';
    }
    if(p2 == n2 + 1) {
        cout << 'B';
    }
    if(p3 == n3 + 1) {
        cout << 'C';
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//ArrayList<String> word = new ArrayList<String>();
		String[] words;
		int wordCount = 0;
		String W = scan.nextLine();
		String T = "";
		
		
		
	
		while(true) {
			T = scan.nextLine();
			if(T.equals("END_OF_TEXT")) break;
			words = T.toLowerCase().split(" ");
			for (int j = 0; j < words.length; j++) {
				if(words[j].equals(W)){
					wordCount++;
				}
			}
			
		}
		
		
		System.out.println(wordCount);
		
		
	}
	

}

Measured memory_bytes: 17168
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;


int main() {
	long long  r; cin >> r;
	cout << 3 * r*r << endl;

}





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

typedef long long ll;
ll mod = 1000000007;

bool flag=true;

int main(){

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

    int n;
    cin >> n;
    int a[n];

    for(int i=0; i<n; i++) cin >> a[i];
    int x=0,y=0;

    vector<vector<ll>> dp(n,vector<ll>(n,0));

    for(int l=n-1; l>=0; l--){
        for(int r=l; r<n; r++){
            if(l==r) dp[l][r]=a[l];
            else{
                dp[l][r] = max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<'\n';

    return 0;
}


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

int main(){
  int i,n,l,max=0,sum=0;
  cin>>n;
  for(i=0;i<n;i++){
	cin>>l;
    sum+=l;
    if(l>max){
		max=l;
    }
  }

  if(2*max<sum){
	printf("Yes");
  }else{
	printf("No");
  }
}
  


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

using namespace std;

long long DP[10000];

int f(int h, int coins, int n, int as[], int bs[])
{
    if (h<=0)
    {
        return coins;
    }
    else if(DP[h])
        return coins+DP[h];
    else
    {
        int mini = INT_MAX;
        for (int i=0;i<n;i++)
        {
            int value = f(h-as[i], coins+bs[i], n, as, bs)-coins;
            if (value<mini)
                mini=value;
        }
        DP[h] = mini;
        return coins+mini;
    }
}

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

    int h, n;
    cin>>h>>n;
    int as[n], bs[n];
    for (int i=0;i<n;i++)
        cin>>as[i]>>bs[i];
    cout<<f(h, 0, n, as, bs)<<endl;

}


Measured memory_bytes: 1152